Merge commit 'junio/next' into next
[git/platforms/storm.git] / compat / mingw.h
blob0e18b78b14f00371226c1ae53b88ddc4ae016cfb
1 #include <winsock2.h>
3 /*
4 * things that are not available in header files
5 */
7 typedef int pid_t;
8 #define hstrerror strerror
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
20 #define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
21 #define WEXITSTATUS(x) ((x) & 0xff)
22 #define WIFSIGNALED(x) ((unsigned)(x) > 259)
24 #define SIGKILL 0
25 #define SIGCHLD 0
26 #define SIGPIPE 0
27 #define SIGALRM 100
29 #define F_GETFD 1
30 #define F_SETFD 2
31 #define FD_CLOEXEC 0x1
33 struct passwd {
34 char *pw_name;
35 char *pw_gecos;
36 char *pw_dir;
39 struct pollfd {
40 int fd; /* file descriptor */
41 short events; /* requested events */
42 short revents; /* returned events */
44 #define POLLIN 1
45 #define POLLHUP 2
47 typedef void (__cdecl *sig_handler_t)(int);
48 struct sigaction {
49 sig_handler_t sa_handler;
50 unsigned sa_flags;
52 #define sigemptyset(x) (void)0
53 #define SA_RESTART 0
55 struct itimerval {
56 struct timeval it_value, it_interval;
58 #define ITIMER_REAL 0
61 * trivial stubs
64 static inline int readlink(const char *path, char *buf, size_t bufsiz)
65 { errno = ENOSYS; return -1; }
66 static inline int symlink(const char *oldpath, const char *newpath)
67 { errno = ENOSYS; return -1; }
68 static inline int link(const char *oldpath, const char *newpath)
69 { errno = ENOSYS; return -1; }
70 static inline int fchmod(int fildes, mode_t mode)
71 { errno = ENOSYS; return -1; }
72 static inline int fork(void)
73 { errno = ENOSYS; return -1; }
74 static inline unsigned int alarm(unsigned int seconds)
75 { return 0; }
76 static inline int fsync(int fd)
77 { return 0; }
78 static inline int getppid(void)
79 { return 1; }
80 static inline void sync(void)
82 static inline int getuid()
83 { return 1; }
84 static inline struct passwd *getpwnam(const char *name)
85 { return NULL; }
86 static inline int fcntl(int fd, int cmd, long arg)
88 if (cmd == F_GETFD || cmd == F_SETFD)
89 return 0;
90 errno = EINVAL;
91 return -1;
95 * simple adaptors
98 static inline int mingw_mkdir(const char *path, int mode)
100 return mkdir(path);
102 #define mkdir mingw_mkdir
104 static inline int mingw_unlink(const char *pathname)
106 /* read-only files cannot be removed */
107 chmod(pathname, 0666);
108 return unlink(pathname);
110 #define unlink mingw_unlink
112 static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
114 if (options == 0)
115 return _cwait(status, pid, 0);
116 errno = EINVAL;
117 return -1;
121 * implementations of missing functions
124 int pipe(int filedes[2]);
125 unsigned int sleep (unsigned int seconds);
126 int mkstemp(char *template);
127 int gettimeofday(struct timeval *tv, void *tz);
128 int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
129 struct tm *gmtime_r(const time_t *timep, struct tm *result);
130 struct tm *localtime_r(const time_t *timep, struct tm *result);
131 int getpagesize(void); /* defined in MinGW's libgcc.a */
132 struct passwd *getpwuid(int uid);
133 int setitimer(int type, struct itimerval *in, struct itimerval *out);
134 int sigaction(int sig, struct sigaction *in, struct sigaction *out);
137 * replacements of existing functions
140 int mingw_open (const char *filename, int oflags, ...);
141 #define open mingw_open
143 char *mingw_getcwd(char *pointer, int len);
144 #define getcwd mingw_getcwd
146 struct hostent *mingw_gethostbyname(const char *host);
147 #define gethostbyname mingw_gethostbyname
149 int mingw_socket(int domain, int type, int protocol);
150 #define socket mingw_socket
152 int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
153 #define connect mingw_connect
155 int mingw_rename(const char*, const char*);
156 #define rename mingw_rename
158 /* Use mingw_lstat() instead of lstat()/stat() and
159 * mingw_fstat() instead of fstat() on Windows.
160 * struct stat is redefined because it lacks the st_blocks member.
162 struct mingw_stat {
163 unsigned st_mode;
164 time_t st_mtime, st_atime, st_ctime;
165 unsigned st_dev, st_ino, st_uid, st_gid;
166 size_t st_size;
167 size_t st_blocks;
169 int mingw_lstat(const char *file_name, struct mingw_stat *buf);
170 int mingw_fstat(int fd, struct mingw_stat *buf);
171 #define fstat mingw_fstat
172 #define lstat mingw_lstat
173 #define stat mingw_stat
174 static inline int mingw_stat(const char *file_name, struct mingw_stat *buf)
175 { return mingw_lstat(file_name, buf); }
177 int mingw_utime(const char *file_name, const struct utimbuf *times);
178 #define utime mingw_utime
180 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
181 void mingw_execvp(const char *cmd, char *const *argv);
182 #define execvp mingw_execvp
184 static inline unsigned int git_ntohl(unsigned int x)
185 { return (unsigned int)ntohl(x); }
186 #define ntohl git_ntohl
188 sig_handler_t mingw_signal(int sig, sig_handler_t handler);
189 #define signal mingw_signal
192 * git specific compatibility
195 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
196 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
197 #define PATH_SEP ';'
198 #define PRIuMAX "I64u"
201 * helpers
204 char **copy_environ(void);
205 void free_environ(char **env);
206 char **env_setenv(char **env, const char *name);