4 * things that are not available in header files
11 #define hstrerror strerror
13 #define S_IFLNK 0120000 /* Symbolic link */
14 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
23 #define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
24 #define WEXITSTATUS(x) ((x) & 0xff)
25 #define WIFSIGNALED(x) ((unsigned)(x) > 259)
36 #define FD_CLOEXEC 0x1
45 /* in MSVC, it's defined in winsock2.h */
47 int fd
; /* file descriptor */
48 short events
; /* requested events */
49 short revents
; /* returned events */
55 typedef void (__cdecl
*sig_handler_t
)(int);
57 sig_handler_t sa_handler
;
60 #define sigemptyset(x) (void)0
64 struct timeval it_value
, it_interval
;
72 static inline int readlink(const char *path
, char *buf
, size_t bufsiz
)
73 { errno
= ENOSYS
; return -1; }
74 static inline int symlink(const char *oldpath
, const char *newpath
)
75 { errno
= ENOSYS
; return -1; }
76 static inline int link(const char *oldpath
, const char *newpath
)
77 { errno
= ENOSYS
; return -1; }
78 static inline int fchmod(int fildes
, mode_t mode
)
79 { errno
= ENOSYS
; return -1; }
80 static inline int fork(void)
81 { errno
= ENOSYS
; return -1; }
82 static inline unsigned int alarm(unsigned int seconds
)
84 static inline int fsync(int fd
)
86 static inline int getppid(void)
88 static inline void sync(void)
90 static inline int getuid()
92 static inline struct passwd
*getpwnam(const char *name
)
94 static inline int fcntl(int fd
, int cmd
, long arg
)
96 if (cmd
== F_GETFD
|| cmd
== F_SETFD
)
106 static inline int mingw_mkdir(const char *path
, int mode
)
110 #define mkdir mingw_mkdir
112 static inline int mingw_unlink(const char *pathname
)
114 /* read-only files cannot be removed */
115 chmod(pathname
, 0666);
116 return unlink(pathname
);
118 #define unlink mingw_unlink
120 static inline int waitpid(pid_t pid
, unsigned *status
, unsigned options
)
123 return _cwait(status
, pid
, 0);
129 * implementations of missing functions
132 int pipe(int filedes
[2]);
133 unsigned int sleep (unsigned int seconds
);
134 int mkstemp(char *template);
135 int gettimeofday(struct timeval
*tv
, void *tz
);
136 int poll(struct pollfd
*ufds
, unsigned int nfds
, int timeout
);
137 struct tm
*gmtime_r(const time_t *timep
, struct tm
*result
);
138 struct tm
*localtime_r(const time_t *timep
, struct tm
*result
);
139 int getpagesize(void); /* defined in MinGW's libgcc.a */
140 struct passwd
*getpwuid(int uid
);
141 int setitimer(int type
, struct itimerval
*in
, struct itimerval
*out
);
142 int sigaction(int sig
, struct sigaction
*in
, struct sigaction
*out
);
145 * replacements of existing functions
148 int mingw_open (const char *filename
, int oflags
, ...);
149 #define open mingw_open
151 char *mingw_getcwd(char *pointer
, int len
);
152 #define getcwd mingw_getcwd
154 char *mingw_getenv(const char *name
);
155 #define getenv mingw_getenv
157 struct hostent
*mingw_gethostbyname(const char *host
);
158 #define gethostbyname mingw_gethostbyname
160 int mingw_socket(int domain
, int type
, int protocol
);
161 #define socket mingw_socket
163 int mingw_connect(int sockfd
, struct sockaddr
*sa
, size_t sz
);
164 #define connect mingw_connect
166 int mingw_rename(const char*, const char*);
167 #define rename mingw_rename
169 /* Use mingw_lstat() instead of lstat()/stat() and
170 * mingw_fstat() instead of fstat() on Windows.
171 * struct stat is redefined because it lacks the st_blocks member.
175 time_t st_mtime
, st_atime
, st_ctime
;
176 unsigned st_dev
, st_ino
, st_uid
, st_gid
;
180 int mingw_lstat(const char *file_name
, struct mingw_stat
*buf
);
181 int mingw_fstat(int fd
, struct mingw_stat
*buf
);
182 #define fstat mingw_fstat
183 #define lstat mingw_lstat
184 #define stat mingw_stat
185 static inline int mingw_stat(const char *file_name
, struct mingw_stat
*buf
)
186 { return mingw_lstat(file_name
, buf
); }
188 int mingw_utime(const char *file_name
, const struct utimbuf
*times
);
189 #define utime mingw_utime
191 pid_t
mingw_spawnvpe(const char *cmd
, const char **argv
, char **env
);
192 pid_t
mingw_spawnvpe_cwd(const char *cmd
, const char **argv
, char **env
,
193 const char *working_directory
);
194 void mingw_execvp(const char *cmd
, char *const *argv
);
195 #define execvp mingw_execvp
197 static inline unsigned int git_ntohl(unsigned int x
)
198 { return (unsigned int)ntohl(x
); }
199 #define ntohl git_ntohl
201 sig_handler_t
mingw_signal(int sig
, sig_handler_t handler
);
202 #define signal mingw_signal
205 * ANSI emulation wrappers
208 /* Until va_copy available is MSVC */
209 int winansi_fputs(const char *str
, FILE *stream
);
210 int winansi_printf(const char *format
, ...) __attribute__((format (printf
, 1, 2)));
211 int winansi_fprintf(FILE *stream
, const char *format
, ...) __attribute__((format (printf
, 2, 3)));
212 #define fputs winansi_fputs
213 #define printf(...) winansi_printf(__VA_ARGS__)
214 #define fprintf(...) winansi_fprintf(__VA_ARGS__)
218 * git specific compatibility
221 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
222 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
224 #define PRIuMAX "I64u"
226 void mingw_open_html(const char *path
);
227 #define open_html mingw_open_html
233 char **copy_environ(void);
234 void free_environ(char **env
);
235 char **env_setenv(char **env
, const char *name
);
238 * A replacement of main() that ensures that argv[0] has a path
241 #define main(c,v) dummy_decl_mingw_main(); \
242 static int mingw_main(); \
243 int main(int argc, const char **argv) \
245 argv[0] = xstrdup(_pgmptr); \
246 return mingw_main(argc, argv); \
248 static int mingw_main(c,v)