]> git.ipfire.org Git - thirdparty/git.git/blame - compat/mingw.h
Merge branch 'maint-1.6.2' into maint-1.6.3
[thirdparty/git.git] / compat / mingw.h
CommitLineData
f4626df5
JS
1#include <winsock2.h>
2
3/*
4 * things that are not available in header files
5 */
6
7typedef int pid_t;
8#define hstrerror strerror
9
10#define S_IFLNK 0120000 /* Symbolic link */
11#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
12#define S_ISSOCK(x) 0
13#define S_IRGRP 0
14#define S_IWGRP 0
15#define S_IXGRP 0
16#define S_ISGID 0
17#define S_IROTH 0
18#define S_IXOTH 0
19
20#define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
21#define WEXITSTATUS(x) ((x) & 0xff)
22#define WIFSIGNALED(x) ((unsigned)(x) > 259)
23
d2825065
JS
24#define SIGHUP 1
25#define SIGQUIT 3
26#define SIGKILL 9
27#define SIGPIPE 13
28#define SIGALRM 14
29#define SIGCHLD 17
f4626df5
JS
30
31#define F_GETFD 1
32#define F_SETFD 2
33#define FD_CLOEXEC 0x1
34
35struct passwd {
36 char *pw_name;
37 char *pw_gecos;
38 char *pw_dir;
39};
40
41struct pollfd {
42 int fd; /* file descriptor */
43 short events; /* requested events */
44 short revents; /* returned events */
45};
46#define POLLIN 1
47#define POLLHUP 2
48
49typedef void (__cdecl *sig_handler_t)(int);
50struct sigaction {
51 sig_handler_t sa_handler;
52 unsigned sa_flags;
53};
54#define sigemptyset(x) (void)0
55#define SA_RESTART 0
56
57struct itimerval {
58 struct timeval it_value, it_interval;
59};
60#define ITIMER_REAL 0
61
f4626df5
JS
62/*
63 * trivial stubs
64 */
65
66static inline int readlink(const char *path, char *buf, size_t bufsiz)
67{ errno = ENOSYS; return -1; }
68static inline int symlink(const char *oldpath, const char *newpath)
69{ errno = ENOSYS; return -1; }
f4626df5
JS
70static inline int fchmod(int fildes, mode_t mode)
71{ errno = ENOSYS; return -1; }
72static inline int fork(void)
73{ errno = ENOSYS; return -1; }
74static inline unsigned int alarm(unsigned int seconds)
75{ return 0; }
76static inline int fsync(int fd)
77{ return 0; }
78static inline int getppid(void)
79{ return 1; }
80static inline void sync(void)
81{}
82static inline int getuid()
83{ return 1; }
84static inline struct passwd *getpwnam(const char *name)
85{ return NULL; }
86static inline int fcntl(int fd, int cmd, long arg)
87{
88 if (cmd == F_GETFD || cmd == F_SETFD)
89 return 0;
90 errno = EINVAL;
91 return -1;
92}
93
94/*
95 * simple adaptors
96 */
97
98static inline int mingw_mkdir(const char *path, int mode)
99{
100 return mkdir(path);
101}
102#define mkdir mingw_mkdir
103
132a6e90
JS
104static inline int mingw_unlink(const char *pathname)
105{
106 /* read-only files cannot be removed */
107 chmod(pathname, 0666);
108 return unlink(pathname);
109}
110#define unlink mingw_unlink
111
f4626df5
JS
112static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
113{
114 if (options == 0)
115 return _cwait(status, pid, 0);
116 errno = EINVAL;
117 return -1;
118}
119
f4626df5
JS
120/*
121 * implementations of missing functions
122 */
123
897bb8cb 124int pipe(int filedes[2]);
f4626df5
JS
125unsigned int sleep (unsigned int seconds);
126int mkstemp(char *template);
127int gettimeofday(struct timeval *tv, void *tz);
128int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
129struct tm *gmtime_r(const time_t *timep, struct tm *result);
130struct tm *localtime_r(const time_t *timep, struct tm *result);
131int getpagesize(void); /* defined in MinGW's libgcc.a */
132struct passwd *getpwuid(int uid);
133int setitimer(int type, struct itimerval *in, struct itimerval *out);
134int sigaction(int sig, struct sigaction *in, struct sigaction *out);
7be401e0 135int link(const char *oldpath, const char *newpath);
80ba074f 136
25fe217b
JS
137/*
138 * replacements of existing functions
139 */
140
3e4a1ba0
JS
141int mingw_open (const char *filename, int oflags, ...);
142#define open mingw_open
143
25fe217b
JS
144char *mingw_getcwd(char *pointer, int len);
145#define getcwd mingw_getcwd
146
6fd6aec4
JS
147char *mingw_getenv(const char *name);
148#define getenv mingw_getenv
149
746fb857
JS
150struct hostent *mingw_gethostbyname(const char *host);
151#define gethostbyname mingw_gethostbyname
152
153int mingw_socket(int domain, int type, int protocol);
154#define socket mingw_socket
155
156int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
157#define connect mingw_connect
158
ea9e98c3
JS
159int mingw_rename(const char*, const char*);
160#define rename mingw_rename
161
b130a72b
JL
162#ifdef USE_WIN32_MMAP
163int mingw_getpagesize(void);
164#define getpagesize mingw_getpagesize
165#endif
166
5411bdc4
MSO
167/* Use mingw_lstat() instead of lstat()/stat() and
168 * mingw_fstat() instead of fstat() on Windows.
169 */
1d4e4cd4
JS
170#define off_t off64_t
171#define stat _stati64
172#define lseek _lseeki64
180964f0
JS
173int mingw_lstat(const char *file_name, struct stat *buf);
174int mingw_fstat(int fd, struct stat *buf);
5411bdc4
MSO
175#define fstat mingw_fstat
176#define lstat mingw_lstat
d5e31235 177#define _stati64(x,y) mingw_lstat(x,y)
5411bdc4 178
7c0ffa1c
JS
179int mingw_utime(const char *file_name, const struct utimbuf *times);
180#define utime mingw_utime
181
7e5d7768 182pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
f1a4dfb8
JS
183void mingw_execvp(const char *cmd, char *const *argv);
184#define execvp mingw_execvp
185
cd800eec
SP
186static inline unsigned int git_ntohl(unsigned int x)
187{ return (unsigned int)ntohl(x); }
188#define ntohl git_ntohl
189
6072fc31
JS
190sig_handler_t mingw_signal(int sig, sig_handler_t handler);
191#define signal mingw_signal
192
c09df8a7
PH
193/*
194 * ANSI emulation wrappers
195 */
196
197int winansi_fputs(const char *str, FILE *stream);
198int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
199int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3)));
200#define fputs winansi_fputs
201#define printf(...) winansi_printf(__VA_ARGS__)
202#define fprintf(...) winansi_fprintf(__VA_ARGS__)
203
80ba074f
JS
204/*
205 * git specific compatibility
206 */
207
25fe217b
JS
208#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
209#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
80ba074f 210#define PATH_SEP ';'
82f8d969 211#define PRIuMAX "I64u"
ba26f296 212
4804aabc
SP
213void mingw_open_html(const char *path);
214#define open_html mingw_open_html
215
ba26f296
JS
216/*
217 * helpers
218 */
219
220char **copy_environ(void);
221void free_environ(char **env);
222char **env_setenv(char **env, const char *name);
35eeef47
JS
223
224/*
225 * A replacement of main() that ensures that argv[0] has a path
226 */
227
22537765
SP
228#define main(c,v) dummy_decl_mingw_main(); \
229static int mingw_main(); \
230int main(int argc, const char **argv) \
35eeef47 231{ \
35eeef47
JS
232 argv[0] = xstrdup(_pgmptr); \
233 return mingw_main(argc, argv); \
234} \
235static int mingw_main(c,v)