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) 1
21 #define WIFSIGNALED(x) 0
22 #define WEXITSTATUS(x) ((x) & 0xff)
23 #define WTERMSIG(x) SIGTERM
34 #define FD_CLOEXEC 0x1
42 extern char *getpass(const char *prompt
);
45 int fd
; /* file descriptor */
46 short events
; /* requested events */
47 short revents
; /* returned events */
52 typedef void (__cdecl
*sig_handler_t
)(int);
54 sig_handler_t sa_handler
;
57 #define sigemptyset(x) (void)0
61 struct timeval it_value
, it_interval
;
69 static inline int readlink(const char *path
, char *buf
, size_t bufsiz
)
70 { errno
= ENOSYS
; return -1; }
71 static inline int symlink(const char *oldpath
, const char *newpath
)
72 { errno
= ENOSYS
; return -1; }
73 static inline int fchmod(int fildes
, mode_t mode
)
74 { errno
= ENOSYS
; return -1; }
75 static inline int fork(void)
76 { errno
= ENOSYS
; return -1; }
77 static inline unsigned int alarm(unsigned int seconds
)
79 static inline int fsync(int fd
)
81 static inline int getppid(void)
83 static inline void sync(void)
85 static inline int getuid()
87 static inline struct passwd
*getpwnam(const char *name
)
89 static inline int fcntl(int fd
, int cmd
, long arg
)
91 if (cmd
== F_GETFD
|| cmd
== F_SETFD
)
96 /* bash cannot reliably detect negative return codes as failure */
97 #define exit(code) exit((code) & 0xff)
103 static inline int mingw_mkdir(const char *path
, int mode
)
107 #define mkdir mingw_mkdir
109 static inline int mingw_unlink(const char *pathname
)
111 /* read-only files cannot be removed */
112 chmod(pathname
, 0666);
113 return unlink(pathname
);
115 #define unlink mingw_unlink
117 static inline int waitpid(pid_t pid
, int *status
, unsigned options
)
120 return _cwait(status
, pid
, 0);
126 * implementations of missing functions
129 int pipe(int filedes
[2]);
130 unsigned int sleep (unsigned int seconds
);
131 int mkstemp(char *template);
132 int gettimeofday(struct timeval
*tv
, void *tz
);
133 int poll(struct pollfd
*ufds
, unsigned int nfds
, int timeout
);
134 struct tm
*gmtime_r(const time_t *timep
, struct tm
*result
);
135 struct tm
*localtime_r(const time_t *timep
, struct tm
*result
);
136 int getpagesize(void); /* defined in MinGW's libgcc.a */
137 struct passwd
*getpwuid(int uid
);
138 int setitimer(int type
, struct itimerval
*in
, struct itimerval
*out
);
139 int sigaction(int sig
, struct sigaction
*in
, struct sigaction
*out
);
140 int link(const char *oldpath
, const char *newpath
);
143 * replacements of existing functions
146 int mingw_open (const char *filename
, int oflags
, ...);
147 #define open mingw_open
149 char *mingw_getcwd(char *pointer
, int len
);
150 #define getcwd mingw_getcwd
152 char *mingw_getenv(const char *name
);
153 #define getenv mingw_getenv
155 struct hostent
*mingw_gethostbyname(const char *host
);
156 #define gethostbyname mingw_gethostbyname
158 int mingw_socket(int domain
, int type
, int protocol
);
159 #define socket mingw_socket
161 int mingw_connect(int sockfd
, struct sockaddr
*sa
, size_t sz
);
162 #define connect mingw_connect
164 int mingw_rename(const char*, const char*);
165 #define rename mingw_rename
167 #ifdef USE_WIN32_MMAP
168 int mingw_getpagesize(void);
169 #define getpagesize mingw_getpagesize
172 /* Use mingw_lstat() instead of lstat()/stat() and
173 * mingw_fstat() instead of fstat() on Windows.
175 #define off_t off64_t
176 #define stat _stati64
177 #define lseek _lseeki64
178 int mingw_lstat(const char *file_name
, struct stat
*buf
);
179 int mingw_fstat(int fd
, struct stat
*buf
);
180 #define fstat mingw_fstat
181 #define lstat mingw_lstat
182 #define _stati64(x,y) mingw_lstat(x,y)
184 int mingw_utime(const char *file_name
, const struct utimbuf
*times
);
185 #define utime mingw_utime
187 pid_t
mingw_spawnvpe(const char *cmd
, const char **argv
, char **env
);
188 void mingw_execvp(const char *cmd
, char *const *argv
);
189 #define execvp mingw_execvp
191 static inline unsigned int git_ntohl(unsigned int x
)
192 { return (unsigned int)ntohl(x
); }
193 #define ntohl git_ntohl
195 sig_handler_t
mingw_signal(int sig
, sig_handler_t handler
);
196 #define signal mingw_signal
199 * ANSI emulation wrappers
202 int winansi_fputs(const char *str
, FILE *stream
);
203 int winansi_printf(const char *format
, ...) __attribute__((format (printf
, 1, 2)));
204 int winansi_fprintf(FILE *stream
, const char *format
, ...) __attribute__((format (printf
, 2, 3)));
205 #define fputs winansi_fputs
206 #define printf(...) winansi_printf(__VA_ARGS__)
207 #define fprintf(...) winansi_fprintf(__VA_ARGS__)
210 * git specific compatibility
213 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
214 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
216 #define PRIuMAX "I64u"
218 void mingw_open_html(const char *path
);
219 #define open_html mingw_open_html
225 char **make_augmented_environ(const char *const *vars
);
226 void free_environ(char **env
);
229 * A replacement of main() that ensures that argv[0] has a path
232 #define main(c,v) dummy_decl_mingw_main(); \
233 static int mingw_main(); \
234 int main(int argc, const char **argv) \
236 argv[0] = xstrdup(_pgmptr); \
237 return mingw_main(argc, argv); \
239 static int mingw_main(c,v)
241 #ifndef NO_MINGW_REPLACE_READDIR
243 * A replacement of readdir, to ensure that it reads the file type at
244 * the same time. This avoid extra unneeded lstats in git on MinGW
257 long d_ino
; /* Always zero. */
259 unsigned short d_reclen
; /* Always zero. */
260 unsigned char d_type
; /* Reimplementation adds this */
262 unsigned short d_namlen
; /* Length of name in d_name. */
263 char d_name
[FILENAME_MAX
]; /* File name. */
265 #define dirent mingw_dirent
266 #define readdir(x) mingw_readdir(x)
267 struct dirent
*mingw_readdir(DIR *dir
);
268 #endif // !NO_MINGW_REPLACE_READDIR