fix syntax error for macro substituting a function call
[git-cheetah/kirill.git] / compat / mingw.h
blob866e675ea98627b77885f5ee459074a795764a6d
1 #include <winsock2.h>
3 /*
4 * things that are not available in header files
5 */
7 #ifndef _PID_T_
8 typedef int pid_t;
9 #endif
11 #define hstrerror strerror
13 #define S_IFLNK 0120000 /* Symbolic link */
14 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
15 #define S_ISSOCK(x) 0
16 #define S_IRGRP 0
17 #define S_IWGRP 0
18 #define S_IXGRP 0
19 #define S_ISGID 0
20 #define S_IROTH 0
21 #define S_IXOTH 0
23 #define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
24 #define WEXITSTATUS(x) ((x) & 0xff)
25 #define WIFSIGNALED(x) ((unsigned)(x) > 259)
27 #define SIGKILL 0
28 #define SIGCHLD 0
29 #define SIGPIPE 0
30 #define SIGHUP 0
31 #define SIGQUIT 0
32 #define SIGALRM 100
34 #define F_GETFD 1
35 #define F_SETFD 2
36 #define FD_CLOEXEC 0x1
38 struct passwd {
39 char *pw_name;
40 char *pw_gecos;
41 char *pw_dir;
44 #ifdef __GNUC__
45 /* in MSVC, it's defined in winsock2.h */
46 struct pollfd {
47 int fd; /* file descriptor */
48 short events; /* requested events */
49 short revents; /* returned events */
51 #define POLLIN 1
52 #define POLLHUP 2
53 #endif /* __GNUC__ */
55 typedef void (__cdecl *sig_handler_t)(int);
56 struct sigaction {
57 sig_handler_t sa_handler;
58 unsigned sa_flags;
60 #define sigemptyset(x) (void)0
61 #define SA_RESTART 0
63 struct itimerval {
64 struct timeval it_value, it_interval;
66 #define ITIMER_REAL 0
69 * trivial stubs
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)
83 { return 0; }
84 static inline int fsync(int fd)
85 { return 0; }
86 static inline int getppid(void)
87 { return 1; }
88 static inline void sync(void)
90 static inline int getuid()
91 { return 1; }
92 static inline struct passwd *getpwnam(const char *name)
93 { return NULL; }
94 static inline int fcntl(int fd, int cmd, long arg)
96 if (cmd == F_GETFD || cmd == F_SETFD)
97 return 0;
98 errno = EINVAL;
99 return -1;
103 * simple adaptors
106 static inline int mingw_mkdir(const char *path, int mode)
108 return mkdir(path);
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)
122 if (options == 0)
123 return _cwait(status, pid, 0);
124 errno = EINVAL;
125 return -1;
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.
173 struct mingw_stat {
174 unsigned st_mode;
175 time_t st_mtime, st_atime, st_ctime;
176 unsigned st_dev, st_ino, st_uid, st_gid;
177 size_t st_size;
178 size_t st_blocks;
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
207 #ifndef _MSC_VER
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__)
215 #endif
218 * git specific compatibility
221 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
222 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
223 #define PATH_SEP ';'
224 #define PRIuMAX "I64u"
226 void mingw_open_html(const char *path);
227 #define open_html mingw_open_html
230 * helpers
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)