4 * things that are not available in header files
8 #define hstrerror strerror
10 #define S_IFLNK 0120000 /* Symbolic link */
11 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
20 #define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
21 #define WEXITSTATUS(x) ((x) & 0xff)
22 #define WIFSIGNALED(x) ((unsigned)(x) > 259)
33 #define FD_CLOEXEC 0x1
42 int fd; /* file descriptor */
43 short events; /* requested events */
44 short revents; /* returned events */
49 typedef void (__cdecl *sig_handler_t)(int);
51 sig_handler_t sa_handler;
54 #define sigemptyset(x) (void)0
58 struct timeval it_value, it_interval;
66 static inline int readlink(const char *path, char *buf, size_t bufsiz)
67 { errno = ENOSYS; return -1; }
68 static inline int symlink(const char *oldpath, const char *newpath)
69 { errno = ENOSYS; return -1; }
70 static inline int link(const char *oldpath, const char *newpath)
71 { errno = ENOSYS; return -1; }
72 static inline int fchmod(int fildes, mode_t mode)
73 { errno = ENOSYS; return -1; }
74 static inline int fork(void)
75 { errno = ENOSYS; return -1; }
76 static inline unsigned int alarm(unsigned int seconds)
78 static inline int fsync(int fd)
80 static inline int getppid(void)
82 static inline void sync(void)
84 static inline int getuid()
86 static inline struct passwd *getpwnam(const char *name)
88 static inline int fcntl(int fd, int cmd, long arg)
90 if (cmd == F_GETFD || cmd == F_SETFD)
100 static inline int mingw_mkdir(const char *path, int mode)
104 #define mkdir mingw_mkdir
106 static inline int mingw_unlink(const char *pathname)
108 /* read-only files cannot be removed */
109 chmod(pathname, 0666);
110 return unlink(pathname);
112 #define unlink mingw_unlink
114 static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
117 return _cwait(status, pid, 0);
123 * implementations of missing functions
126 int pipe(int filedes[2]);
127 unsigned int sleep (unsigned int seconds);
128 int mkstemp(char *template);
129 int gettimeofday(struct timeval *tv, void *tz);
130 int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
131 struct tm *gmtime_r(const time_t *timep, struct tm *result);
132 struct tm *localtime_r(const time_t *timep, struct tm *result);
133 int getpagesize(void); /* defined in MinGW's libgcc.a */
134 struct passwd *getpwuid(int uid);
135 int setitimer(int type, struct itimerval *in, struct itimerval *out);
136 int sigaction(int sig, struct sigaction *in, struct sigaction *out);
139 * replacements of existing functions
142 int mingw_open (const char *filename, int oflags, ...);
143 #define open mingw_open
145 char *mingw_getcwd(char *pointer, int len);
146 #define getcwd mingw_getcwd
148 char *mingw_getenv(const char *name);
149 #define getenv mingw_getenv
151 struct hostent *mingw_gethostbyname(const char *host);
152 #define gethostbyname mingw_gethostbyname
154 int mingw_socket(int domain, int type, int protocol);
155 #define socket mingw_socket
157 int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
158 #define connect mingw_connect
160 int mingw_rename(const char*, const char*);
161 #define rename mingw_rename
163 /* Use mingw_lstat() instead of lstat()/stat() and
164 * mingw_fstat() instead of fstat() on Windows.
166 int mingw_lstat(const char *file_name, struct stat *buf);
167 int mingw_fstat(int fd, struct stat *buf);
168 #define fstat mingw_fstat
169 #define lstat mingw_lstat
170 #define stat(x,y) mingw_lstat(x,y)
172 int mingw_utime(const char *file_name, const struct utimbuf *times);
173 #define utime mingw_utime
175 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
176 void mingw_execvp(const char *cmd, char *const *argv);
177 #define execvp mingw_execvp
179 static inline unsigned int git_ntohl(unsigned int x)
180 { return (unsigned int)ntohl(x); }
181 #define ntohl git_ntohl
183 sig_handler_t mingw_signal(int sig, sig_handler_t handler);
184 #define signal mingw_signal
187 * ANSI emulation wrappers
190 int winansi_fputs(const char *str, FILE *stream);
191 int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
192 int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3)));
193 #define fputs winansi_fputs
194 #define printf(...) winansi_printf(__VA_ARGS__)
195 #define fprintf(...) winansi_fprintf(__VA_ARGS__)
198 * git specific compatibility
201 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
202 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
204 #define PRIuMAX "I64u"
206 void mingw_open_html(const char *path);
207 #define open_html mingw_open_html
213 char **copy_environ(void);
214 void free_environ(char **env);
215 char **env_setenv(char **env, const char *name);
218 * A replacement of main() that ensures that argv[0] has a path
221 #define main(c,v) dummy_decl_mingw_main(); \
222 static int mingw_main(); \
223 int main(int argc, const char **argv) \
225 argv[0] = xstrdup(_pgmptr); \
226 return mingw_main(argc, argv); \
228 static int mingw_main(c,v)