aboutsummaryrefslogtreecommitdiff
path: root/include/mingw.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/mingw.h')
-rw-r--r--include/mingw.h482
1 files changed, 482 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h
new file mode 100644
index 000000000..569c2c704
--- /dev/null
+++ b/include/mingw.h
@@ -0,0 +1,482 @@
1
2#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; }
3#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; }
4
5/*
6 * sys/types.h
7 */
8typedef int gid_t;
9typedef int uid_t;
10#ifndef _WIN64
11typedef int pid_t;
12#else
13typedef __int64 pid_t;
14#endif
15
16#define DEFAULT_UID 1000
17#define DEFAULT_GID 1000
18
19/*
20 * arpa/inet.h
21 */
22static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); }
23#define ntohl git_ntohl
24int inet_aton(const char *cp, struct in_addr *inp);
25int inet_pton(int af, const char *src, void *dst);
26
27/*
28 * fcntl.h
29 */
30#define F_DUPFD 0
31#define F_GETFD 1
32#define F_SETFD 2
33#define F_GETFL 3
34#define F_SETFL 3
35#define FD_CLOEXEC 0x1
36#define O_NONBLOCK 04000
37
38/*
39 * grp.h
40 */
41
42struct group {
43 char *gr_name;
44 char *gr_passwd;
45 gid_t gr_gid;
46 char **gr_mem;
47};
48IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM);
49struct group *getgrgid(gid_t gid);
50NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM);
51static inline void endgrent(void) {}
52int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);
53
54/*
55 * limits.h
56 */
57#define NAME_MAX 255
58#define MAXSYMLINKS 20
59
60/*
61 * netdb.h
62 */
63
64typedef int sa_family_t;
65
66/*
67 * linux/un.h
68 */
69struct sockaddr_un {
70 sa_family_t sun_family;
71 char sun_path[1]; /* to make compiler happy, don't bother */
72};
73
74/*
75 * pwd.h
76 */
77struct passwd {
78 char *pw_name;
79 char *pw_passwd;
80 char *pw_gecos;
81 char *pw_dir;
82 char *pw_shell;
83 uid_t pw_uid;
84 gid_t pw_gid;
85};
86
87struct passwd *getpwnam(const char *name);
88struct passwd *getpwuid(uid_t uid);
89static inline void setpwent(void) {}
90static inline void endpwent(void) {}
91IMPL(getpwent_r,int,ENOENT,struct passwd *pwbuf UNUSED_PARAM,char *buf UNUSED_PARAM,size_t buflen UNUSED_PARAM,struct passwd **pwbufp UNUSED_PARAM);
92IMPL(getpwent,struct passwd *,NULL,void)
93
94/*
95 * signal.h
96 */
97#define SIGHUP 1
98#define SIGQUIT 3
99#define SIGKILL 9
100#define SIGUSR1 10
101#define SIGUSR2 12
102#define SIGPIPE 13
103#define SIGALRM 14
104#define SIGCHLD 17
105#define SIGCONT 18
106#define SIGSTOP 19
107#define SIGTSTP 20
108#define SIGTTIN 21
109#define SIGTTOU 22
110#define SIGXCPU 24
111#define SIGXFSZ 25
112#define SIGVTALRM 26
113#define SIGWINCH 28
114
115#define SIG_UNBLOCK 1
116
117typedef void (__cdecl *sighandler_t)(int);
118struct sigaction {
119 sighandler_t sa_handler;
120 unsigned sa_flags;
121 int sa_mask;
122};
123#define sigemptyset(x) (void)0
124#define SA_RESTART 0
125
126NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM);
127NOIMPL(sigfillset,int *mask UNUSED_PARAM);
128NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM);
129NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM);
130
131/*
132 * stdio.h
133 */
134#undef fseeko
135#define fseeko(f,o,w) fseek(f,o,w)
136
137int fdprintf(int fd, const char *format, ...);
138FILE* mingw_fopen(const char *filename, const char *mode);
139int mingw_rename(const char*, const char*);
140#define fopen mingw_fopen
141#define rename mingw_rename
142
143FILE *mingw_popen(const char *cmd, const char *mode);
144int mingw_popen_fd(const char *cmd, const char *mode, int fd0, pid_t *pid);
145int mingw_pclose(FILE *fd);
146#undef popen
147#undef pclose
148#define popen mingw_popen
149#define pclose mingw_pclose
150
151#define setlinebuf(fd) setvbuf(fd, (char *) NULL, _IOLBF, 0)
152
153/*
154 * ANSI emulation wrappers
155 */
156
157void move_cursor_row(int n);
158void reset_screen(void);
159int winansi_putchar(int c);
160int winansi_puts(const char *s);
161size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
162int winansi_fputs(const char *str, FILE *stream);
163int winansi_vfprintf(FILE *stream, const char *format, va_list list);
164int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
165int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3)));
166int winansi_write(int fd, const void *buf, size_t count);
167int winansi_read(int fd, void *buf, size_t count);
168int winansi_getc(FILE *stream);
169#define putchar winansi_putchar
170#define puts winansi_puts
171#define fwrite winansi_fwrite
172#define fputs winansi_fputs
173#define vprintf(...) winansi_vfprintf(stdout, __VA_ARGS__)
174#define printf(...) winansi_printf(__VA_ARGS__)
175#define fprintf(...) winansi_fprintf(__VA_ARGS__)
176#define write winansi_write
177#define read winansi_read
178#define getc winansi_getc
179
180int winansi_get_terminal_width_height(struct winsize *win);
181
182/*
183 * stdlib.h
184 */
185#define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
186#define WEXITSTATUS(x) ((x) & 0xff)
187#define WIFSIGNALED(x) ((unsigned)(x) > 259)
188#define WTERMSIG(x) ((x) & 0x7f)
189#define WCOREDUMP(x) 0
190
191int mingw_system(const char *cmd);
192#define system mingw_system
193
194int clearenv(void);
195char *mingw_getenv(const char *name);
196int mingw_putenv(const char *env);
197char *mingw_mktemp(char *template);
198int mkstemp(char *template);
199char *realpath(const char *path, char *resolved_path);
200int setenv(const char *name, const char *value, int replace);
201#if ENABLE_SAFE_ENV
202int unsetenv(const char *env);
203#else
204void unsetenv(const char *env);
205#endif
206
207#define getenv mingw_getenv
208#if ENABLE_SAFE_ENV
209#define putenv mingw_putenv
210#endif
211#define mktemp mingw_mktemp
212
213/*
214 * string.h
215 */
216void *mempcpy(void *dest, const void *src, size_t n);
217
218/*
219 * strings.h
220 */
221int ffs(int i);
222
223/*
224 * sys/ioctl.h
225 */
226
227#define TIOCGWINSZ 0x5413
228
229int ioctl(int fd, int code, ...);
230
231/*
232 * sys/socket.h
233 */
234#define hstrerror strerror
235
236#define SHUT_WR SD_SEND
237
238int mingw_socket(int domain, int type, int protocol);
239int mingw_connect(int sockfd, const struct sockaddr *sa, size_t sz);
240int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz);
241int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen);
242int mingw_shutdown(int sockfd, int how);
243int mingw_listen(int sockfd, int backlog);
244int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz);
245int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
246 struct timeval *timeout);
247
248NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM);
249
250#define socket mingw_socket
251#define connect mingw_connect
252#define sendto mingw_sendto
253#define listen mingw_listen
254#define bind mingw_bind
255#define setsockopt mingw_setsockopt
256#define shutdown mingw_shutdown
257#define accept mingw_accept
258#define select mingw_select
259
260/*
261 * sys/stat.h
262 */
263#define S_ISUID 04000
264#define S_ISGID 02000
265#define S_ISVTX 01000
266#ifndef S_IRWXU
267#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
268#endif
269#define S_IRWXG (S_IRWXU >> 3)
270#define S_IRWXO (S_IRWXG >> 3)
271
272#define S_IFSOCK 0140000
273#define S_IFLNK 0120000 /* Symbolic link */
274#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
275#define S_ISSOCK(x) 0
276
277#define S_IRGRP (S_IRUSR >> 3)
278#define S_IWGRP (S_IWUSR >> 3)
279#define S_IXGRP (S_IXUSR >> 3)
280#define S_IROTH (S_IRGRP >> 3)
281#define S_IWOTH (S_IWGRP >> 3)
282#define S_IXOTH (S_IXGRP >> 3)
283
284IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM);
285NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM);
286int mingw_mkdir(const char *path, int mode);
287int mingw_chmod(const char *path, int mode);
288
289#define mkdir mingw_mkdir
290#define chmod mingw_chmod
291
292#if ENABLE_LFS && !defined(__MINGW64_VERSION_MAJOR)
293# define off_t off64_t
294#endif
295
296typedef int nlink_t;
297typedef int blksize_t;
298typedef off_t blkcnt_t;
299
300struct mingw_stat {
301 dev_t st_dev;
302 ino_t st_ino;
303 mode_t st_mode;
304 nlink_t st_nlink;
305 uid_t st_uid;
306 gid_t st_gid;
307 dev_t st_rdev;
308 off_t st_size;
309 time_t st_atime;
310 time_t st_mtime;
311 time_t st_ctime;
312 blksize_t st_blksize;
313 blkcnt_t st_blocks;
314};
315
316int mingw_lstat(const char *file_name, struct mingw_stat *buf);
317int mingw_stat(const char *file_name, struct mingw_stat *buf);
318int mingw_fstat(int fd, struct mingw_stat *buf);
319#undef lstat
320#undef stat
321#undef fstat
322#define lstat mingw_lstat
323#define stat mingw_stat
324#define fstat mingw_fstat
325
326/*
327 * sys/sysmacros.h
328 */
329#define makedev(a,b) 0*(a)*(b) /* avoid unused warning */
330#define minor(x) 0
331#define major(x) 0
332
333/*
334 * sys/time.h
335 */
336#ifndef _TIMESPEC_DEFINED
337#define _TIMESPEC_DEFINED
338struct timespec {
339 time_t tv_sec;
340 long int tv_nsec;
341};
342#endif
343
344/*
345 * sys/wait.h
346 */
347#define WNOHANG 1
348#define WUNTRACED 2
349int waitpid(pid_t pid, int *status, int options);
350
351/*
352 * time.h
353 */
354struct tm *gmtime_r(const time_t *timep, struct tm *result);
355struct tm *localtime_r(const time_t *timep, struct tm *result);
356char *strptime(const char *s, const char *format, struct tm *tm);
357size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm *tm);
358int stime(time_t *t);
359
360#define strftime mingw_strftime
361
362/*
363 * times.h
364 */
365#define clock_t long
366
367struct tms {
368 clock_t tms_utime; /* user CPU time */
369 clock_t tms_stime; /* system CPU time */
370 clock_t tms_cutime; /* user CPU time of children */
371 clock_t tms_cstime; /* system CPU time of children */
372};
373
374clock_t times(struct tms *buf);
375
376/*
377 * unistd.h
378 */
379#define PIPE_BUF 8192
380
381#define _SC_CLK_TCK 2
382
383IMPL(alarm,unsigned int,0,unsigned int seconds UNUSED_PARAM);
384IMPL(chown,int,0,const char *path UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM);
385NOIMPL(chroot,const char *root UNUSED_PARAM);
386NOIMPL(fchdir,int fd UNUSED_PARAM);
387int mingw_dup2 (int fd, int fdto);
388char *mingw_getcwd(char *pointer, int len);
389off_t mingw_lseek(int fd, off_t offset, int whence);
390
391
392IMPL(getgid,int,DEFAULT_GID,void);
393int getgroups(int n, gid_t *groups);
394IMPL(getppid,int,1,void);
395IMPL(getegid,int,DEFAULT_GID,void);
396IMPL(geteuid,int,DEFAULT_UID,void);
397NOIMPL(getsid,pid_t pid UNUSED_PARAM);
398IMPL(getuid,int,DEFAULT_UID,void);
399int getlogin_r(char *buf, size_t len);
400int fcntl(int fd, int cmd, ...);
401#define fork() -1
402IMPL(fsync,int,0,int fd UNUSED_PARAM);
403int kill(pid_t pid, int sig);
404int link(const char *oldpath, const char *newpath);
405NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM);
406int mingw_open (const char *filename, int oflags, ...);
407int pipe(int filedes[2]);
408NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM);
409NOIMPL(setgid,gid_t gid UNUSED_PARAM);
410NOIMPL(setegid,gid_t gid UNUSED_PARAM);
411NOIMPL(setsid,void);
412NOIMPL(setuid,uid_t gid UNUSED_PARAM);
413NOIMPL(seteuid,uid_t gid UNUSED_PARAM);
414unsigned int sleep(unsigned int seconds);
415NOIMPL(symlink,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM);
416static inline void sync(void) {}
417long sysconf(int name);
418NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARAM);
419int mingw_unlink(const char *pathname);
420NOIMPL(vfork,void);
421int mingw_access(const char *name, int mode);
422int mingw_rmdir(const char *name);
423
424#define dup2 mingw_dup2
425#define getcwd mingw_getcwd
426#define lchown chown
427#define open mingw_open
428#define unlink mingw_unlink
429#define rmdir mingw_rmdir
430#undef lseek
431#define lseek mingw_lseek
432
433#undef access
434#define access mingw_access
435
436/*
437 * utime.h
438 */
439int utimes(const char *file_name, const struct timeval times[2]);
440
441/*
442 * dirent.h
443 */
444DIR *mingw_opendir(const char *path);
445#define opendir mingw_opendir
446
447/*
448 * MinGW specific
449 */
450#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
451#ifndef PRIuMAX
452#define PRIuMAX "I64u"
453#endif
454
455pid_t FAST_FUNC mingw_spawn(char **argv);
456intptr_t FAST_FUNC mingw_spawn_proc(char **argv);
457int mingw_execv(const char *cmd, const char *const *argv);
458int mingw_execvp(const char *cmd, const char *const *argv);
459int mingw_execve(const char *cmd, const char *const *argv, const char *const *envp);
460#define spawn mingw_spawn
461#define execvp mingw_execvp
462#define execve mingw_execve
463#define execv mingw_execv
464
465const char * next_path_sep(const char *path);
466#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
467#define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path))
468
469/*
470 * helpers
471 */
472
473char **copy_environ(const char *const *env);
474void free_environ(char **env);
475char **env_setenv(char **env, const char *name);
476
477const char *get_busybox_exec_path(void);
478void init_winsock(void);
479
480char *file_is_win32_executable(const char *p);
481
482int err_win_to_posix(DWORD winerr);