5 * things that are not available in header files
10 #define hstrerror strerror
12 #define S_IFLNK 0120000 /* Symbolic link */
13 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
22 #define WIFEXITED(x) 1
23 #define WIFSIGNALED(x) 0
24 #define WEXITSTATUS(x) ((x) & 0xff)
25 #define WTERMSIG(x) SIGTERM
36 #define FD_CLOEXEC 0x1
44 extern char *getpass(const char *prompt
);
48 int fd
; /* file descriptor */
49 short events
; /* requested events */
50 short revents
; /* returned events */
56 typedef void (__cdecl
*sig_handler_t
)(int);
58 sig_handler_t sa_handler
;
61 #define sigemptyset(x) (void)0
65 struct timeval it_value
, it_interval
;
73 static inline int readlink(const char *path
, char *buf
, size_t bufsiz
)
74 { errno
= ENOSYS
; return -1; }
75 static inline int symlink(const char *oldpath
, const char *newpath
)
76 { errno
= ENOSYS
; return -1; }
77 static inline int fchmod(int fildes
, mode_t mode
)
78 { errno
= ENOSYS
; return -1; }
79 static inline pid_t
fork(void)
80 { errno
= ENOSYS
; return -1; }
81 static inline unsigned int alarm(unsigned int seconds
)
83 static inline int fsync(int fd
)
84 { return _commit(fd
); }
85 static inline pid_t
getppid(void)
87 static inline void sync(void)
89 static inline uid_t
getuid(void)
91 static inline struct passwd
*getpwnam(const char *name
)
93 static inline int fcntl(int fd
, int cmd
, ...)
95 if (cmd
== F_GETFD
|| cmd
== F_SETFD
)
100 /* bash cannot reliably detect negative return codes as failure */
101 #define exit(code) exit((code) & 0xff)
107 static inline int mingw_mkdir(const char *path
, int mode
)
111 #define mkdir mingw_mkdir
113 static inline int mingw_unlink(const char *pathname
)
115 /* read-only files cannot be removed */
116 chmod(pathname
, 0666);
117 return unlink(pathname
);
119 #define unlink mingw_unlink
121 static inline pid_t
waitpid(pid_t pid
, int *status
, unsigned options
)
124 return _cwait(status
, pid
, 0);
130 #include <openssl/ssl.h>
131 static inline int mingw_SSL_set_fd(SSL
*ssl
, int fd
)
133 return SSL_set_fd(ssl
, _get_osfhandle(fd
));
135 #define SSL_set_fd mingw_SSL_set_fd
137 static inline int mingw_SSL_set_rfd(SSL
*ssl
, int fd
)
139 return SSL_set_rfd(ssl
, _get_osfhandle(fd
));
141 #define SSL_set_rfd mingw_SSL_set_rfd
143 static inline int mingw_SSL_set_wfd(SSL
*ssl
, int fd
)
145 return SSL_set_wfd(ssl
, _get_osfhandle(fd
));
147 #define SSL_set_wfd mingw_SSL_set_wfd
151 * implementations of missing functions
154 int pipe(int filedes
[2]);
155 unsigned int sleep (unsigned int seconds
);
156 int mkstemp(char *template);
157 int gettimeofday(struct timeval
*tv
, void *tz
);
158 int poll(struct pollfd
*ufds
, unsigned int nfds
, int timeout
);
159 struct tm
*gmtime_r(const time_t *timep
, struct tm
*result
);
160 struct tm
*localtime_r(const time_t *timep
, struct tm
*result
);
161 int getpagesize(void); /* defined in MinGW's libgcc.a */
162 struct passwd
*getpwuid(uid_t uid
);
163 int setitimer(int type
, struct itimerval
*in
, struct itimerval
*out
);
164 int sigaction(int sig
, struct sigaction
*in
, struct sigaction
*out
);
165 int link(const char *oldpath
, const char *newpath
);
168 * replacements of existing functions
171 int mingw_open (const char *filename
, int oflags
, ...);
172 #define open mingw_open
174 ssize_t
mingw_write(int fd
, const void *buf
, size_t count
);
175 #define write mingw_write
177 FILE *mingw_fopen (const char *filename
, const char *otype
);
178 #define fopen mingw_fopen
180 FILE *mingw_freopen (const char *filename
, const char *otype
, FILE *stream
);
181 #define freopen mingw_freopen
183 char *mingw_getcwd(char *pointer
, int len
);
184 #define getcwd mingw_getcwd
186 char *mingw_getenv(const char *name
);
187 #define getenv mingw_getenv
189 struct hostent
*mingw_gethostbyname(const char *host
);
190 #define gethostbyname mingw_gethostbyname
192 void mingw_freeaddrinfo(struct addrinfo
*res
);
193 #define freeaddrinfo mingw_freeaddrinfo
195 int mingw_getaddrinfo(const char *node
, const char *service
,
196 const struct addrinfo
*hints
, struct addrinfo
**res
);
197 #define getaddrinfo mingw_getaddrinfo
199 int mingw_getnameinfo(const struct sockaddr
*sa
, socklen_t salen
,
200 char *host
, DWORD hostlen
, char *serv
, DWORD servlen
,
202 #define getnameinfo mingw_getnameinfo
204 int mingw_socket(int domain
, int type
, int protocol
);
205 #define socket mingw_socket
207 int mingw_connect(int sockfd
, struct sockaddr
*sa
, size_t sz
);
208 #define connect mingw_connect
210 int mingw_rename(const char*, const char*);
211 #define rename mingw_rename
213 #if defined(USE_WIN32_MMAP) || defined(_MSC_VER)
214 int mingw_getpagesize(void);
215 #define getpagesize mingw_getpagesize
218 /* Use mingw_lstat() instead of lstat()/stat() and
219 * mingw_fstat() instead of fstat() on Windows.
221 #define off_t off64_t
222 #define lseek _lseeki64
223 #ifndef ALREADY_DECLARED_STAT_FUNCS
224 #define stat _stati64
225 int mingw_lstat(const char *file_name
, struct stat
*buf
);
226 int mingw_fstat(int fd
, struct stat
*buf
);
227 #define fstat mingw_fstat
228 #define lstat mingw_lstat
229 #define _stati64(x,y) mingw_lstat(x,y)
232 int mingw_utime(const char *file_name
, const struct utimbuf
*times
);
233 #define utime mingw_utime
235 pid_t
mingw_spawnvpe(const char *cmd
, const char **argv
, char **env
,
237 int fhin
, int fhout
, int fherr
);
238 void mingw_execvp(const char *cmd
, char *const *argv
);
239 #define execvp mingw_execvp
241 static inline unsigned int git_ntohl(unsigned int x
)
242 { return (unsigned int)ntohl(x
); }
243 #define ntohl git_ntohl
245 sig_handler_t
mingw_signal(int sig
, sig_handler_t handler
);
246 #define signal mingw_signal
249 * ANSI emulation wrappers
252 int winansi_fputs(const char *str
, FILE *stream
);
253 int winansi_printf(const char *format
, ...) __attribute__((format (printf
, 1, 2)));
254 int winansi_fprintf(FILE *stream
, const char *format
, ...) __attribute__((format (printf
, 2, 3)));
255 #define fputs winansi_fputs
256 #define printf(...) winansi_printf(__VA_ARGS__)
257 #define fprintf(...) winansi_fprintf(__VA_ARGS__)
260 * git specific compatibility
263 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
264 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
266 #define PRIuMAX "I64u"
268 void mingw_open_html(const char *path
);
269 #define open_html mingw_open_html
275 char **make_augmented_environ(const char *const *vars
);
276 void free_environ(char **env
);
279 * A replacement of main() that ensures that argv[0] has a path
280 * and that default fmode and std(in|out|err) are in binary mode
283 #define main(c,v) dummy_decl_mingw_main(); \
284 static int mingw_main(); \
285 int main(int argc, const char **argv) \
287 _fmode = _O_BINARY; \
288 _setmode(_fileno(stdin), _O_BINARY); \
289 _setmode(_fileno(stdout), _O_BINARY); \
290 _setmode(_fileno(stderr), _O_BINARY); \
291 argv[0] = xstrdup(_pgmptr); \
292 return mingw_main(argc, argv); \
294 static int mingw_main(c,v)
296 #ifndef NO_MINGW_REPLACE_READDIR
298 * A replacement of readdir, to ensure that it reads the file type at
299 * the same time. This avoid extra unneeded lstats in git on MinGW
312 long d_ino
; /* Always zero. */
314 unsigned short d_reclen
; /* Always zero. */
315 unsigned char d_type
; /* Reimplementation adds this */
317 unsigned short d_namlen
; /* Length of name in d_name. */
318 char d_name
[FILENAME_MAX
]; /* File name. */
320 #define dirent mingw_dirent
321 #define readdir(x) mingw_readdir(x)
322 struct dirent
*mingw_readdir(DIR *dir
);
323 #endif // !NO_MINGW_REPLACE_READDIR
326 * Used by Pthread API implementation for Windows
328 extern int err_win_to_posix(DWORD winerr
);