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