aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/bb_archive.h10
-rw-r--r--include/libbb.h32
-rw-r--r--include/mingw.h482
-rw-r--r--include/platform.h40
4 files changed, 562 insertions, 2 deletions
diff --git a/include/bb_archive.h b/include/bb_archive.h
index 2b9c5f04c..9bbf59bb8 100644
--- a/include/bb_archive.h
+++ b/include/bb_archive.h
@@ -2,6 +2,16 @@
2#ifndef UNARCHIVE_H 2#ifndef UNARCHIVE_H
3#define UNARCHIVE_H 1 3#define UNARCHIVE_H 1
4 4
5#if !defined(BB_ARCHIVE_PUBLIC) && ENABLE_PLATFORM_MINGW32
6/* treat mingw as a non-MMU platform */
7#undef BB_MMU
8#undef USE_FOR_NOMMU
9#undef USE_FOR_MMU
10#define BB_MMU 0
11#define USE_FOR_NOMMU(...) __VA_ARGS__
12#define USE_FOR_MMU(...)
13#endif
14
5PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 15PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
6 16
7enum { 17enum {
diff --git a/include/libbb.h b/include/libbb.h
index abdc8c2b8..0b9cfb585 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -138,6 +138,12 @@
138# include <arpa/inet.h> 138# include <arpa/inet.h>
139#elif defined __APPLE__ 139#elif defined __APPLE__
140# include <netinet/in.h> 140# include <netinet/in.h>
141#elif ENABLE_PLATFORM_MINGW32
142# ifndef WINVER
143# define WINVER 0x0501
144# endif
145# include <winsock2.h>
146# include <ws2tcpip.h>
141#else 147#else
142# include <arpa/inet.h> 148# include <arpa/inet.h>
143//This breaks on bionic: 149//This breaks on bionic:
@@ -166,7 +172,9 @@
166 172
167/* Some libc's forget to declare these, do it ourself */ 173/* Some libc's forget to declare these, do it ourself */
168 174
175#if !ENABLE_PLATFORM_MINGW32
169extern char **environ; 176extern char **environ;
177#endif
170#if defined(__GLIBC__) && __GLIBC__ < 2 178#if defined(__GLIBC__) && __GLIBC__ < 2
171int vdprintf(int d, const char *format, va_list ap); 179int vdprintf(int d, const char *format, va_list ap);
172#endif 180#endif
@@ -179,6 +187,9 @@ int klogctl(int type, char *b, int len);
179# define BUFSIZ 4096 187# define BUFSIZ 4096
180#endif 188#endif
181 189
190#if ENABLE_PLATFORM_MINGW32
191# include "mingw.h"
192#endif
182 193
183/* Busybox does not use threads, we can speed up stdio. */ 194/* Busybox does not use threads, we can speed up stdio. */
184#ifdef HAVE_UNLOCKED_STDIO 195#ifdef HAVE_UNLOCKED_STDIO
@@ -490,6 +501,7 @@ enum {
490 + (1LL << SIGUSR2) 501 + (1LL << SIGUSR2)
491 + 0), 502 + 0),
492}; 503};
504#if !ENABLE_PLATFORM_MINGW32
493void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; 505void bb_signals(int sigs, void (*f)(int)) FAST_FUNC;
494/* Unlike signal() and bb_signals, sets handler with sigaction() 506/* Unlike signal() and bb_signals, sets handler with sigaction()
495 * and in a way that while signal handler is run, no other signals 507 * and in a way that while signal handler is run, no other signals
@@ -507,6 +519,10 @@ void sig_unblock(int sig) FAST_FUNC;
507int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC; 519int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC;
508/* SIG_BLOCK/SIG_UNBLOCK all signals: */ 520/* SIG_BLOCK/SIG_UNBLOCK all signals: */
509int sigprocmask_allsigs(int how) FAST_FUNC; 521int sigprocmask_allsigs(int how) FAST_FUNC;
522#else
523#define bb_signals(s, f)
524#define kill_myself_with_sig(s)
525#endif
510/* Standard handler which just records signo */ 526/* Standard handler which just records signo */
511extern smallint bb_got_signal; 527extern smallint bb_got_signal;
512void record_signo(int signo); /* not FAST_FUNC! */ 528void record_signo(int signo); /* not FAST_FUNC! */
@@ -586,7 +602,7 @@ char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
586int xsocket(int domain, int type, int protocol) FAST_FUNC; 602int xsocket(int domain, int type, int protocol) FAST_FUNC;
587void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; 603void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
588void xlisten(int s, int backlog) FAST_FUNC; 604void xlisten(int s, int backlog) FAST_FUNC;
589void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; 605void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC;
590ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 606ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
591 socklen_t tolen) FAST_FUNC; 607 socklen_t tolen) FAST_FUNC;
592 608
@@ -890,6 +906,9 @@ char *safe_gethostname(void) FAST_FUNC;
890char* str_tolower(char *str) FAST_FUNC; 906char* str_tolower(char *str) FAST_FUNC;
891 907
892char *utoa(unsigned n) FAST_FUNC; 908char *utoa(unsigned n) FAST_FUNC;
909#if ENABLE_PLATFORM_MINGW32
910# define itoa bb_itoa
911#endif
893char *itoa(int n) FAST_FUNC; 912char *itoa(int n) FAST_FUNC;
894/* Returns a pointer past the formatted number, does NOT null-terminate */ 913/* Returns a pointer past the formatted number, does NOT null-terminate */
895char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; 914char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC;
@@ -1664,6 +1683,9 @@ typedef struct procps_status_t {
1664#if ENABLE_FEATURE_TOP_SMP_PROCESS 1683#if ENABLE_FEATURE_TOP_SMP_PROCESS
1665 int last_seen_on_cpu; 1684 int last_seen_on_cpu;
1666#endif 1685#endif
1686#if ENABLE_PLATFORM_MINGW32
1687 HANDLE snapshot;
1688#endif
1667} procps_status_t; 1689} procps_status_t;
1668/* flag bits for procps_scan(xx, flags) calls */ 1690/* flag bits for procps_scan(xx, flags) calls */
1669enum { 1691enum {
@@ -1702,7 +1724,11 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC;
1702procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; 1724procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC;
1703/* Format cmdline (up to col chars) into char buf[size] */ 1725/* Format cmdline (up to col chars) into char buf[size] */
1704/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ 1726/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */
1727#if !ENABLE_PLATFORM_MINGW32
1705void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; 1728void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC;
1729#else
1730#define read_cmdline(buf, size, pid, comm) snprintf(buf, size, "[%s]", comm)
1731#endif
1706pid_t *find_pid_by_name(const char* procName) FAST_FUNC; 1732pid_t *find_pid_by_name(const char* procName) FAST_FUNC;
1707pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; 1733pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC;
1708int starts_with_cpu(const char *str) FAST_FUNC; 1734int starts_with_cpu(const char *str) FAST_FUNC;
@@ -1842,7 +1868,11 @@ extern const char bb_path_wtmp_file[] ALIGN1;
1842#define bb_path_motd_file "/etc/motd" 1868#define bb_path_motd_file "/etc/motd"
1843 1869
1844#define bb_dev_null "/dev/null" 1870#define bb_dev_null "/dev/null"
1871#if ENABLE_PLATFORM_MINGW32
1872#define bb_busybox_exec_path get_busybox_exec_path()
1873#else
1845extern const char bb_busybox_exec_path[] ALIGN1; 1874extern const char bb_busybox_exec_path[] ALIGN1;
1875#endif
1846/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, 1876/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
1847 * but I want to save a few bytes here */ 1877 * but I want to save a few bytes here */
1848extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ 1878extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
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);
diff --git a/include/platform.h b/include/platform.h
index c987d418c..94368539e 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -7,6 +7,15 @@
7#ifndef BB_PLATFORM_H 7#ifndef BB_PLATFORM_H
8#define BB_PLATFORM_H 1 8#define BB_PLATFORM_H 1
9 9
10#if ENABLE_PLATFORM_MINGW32
11# if !defined(__MINGW32__) /* HOSTCC is called */
12# undef ENABLE_PLATFORM_MINGW32
13# endif
14#else
15# if defined(__MINGW32__)
16# error "You must select target platform MS Windows, or it won't build"
17# endif
18#endif
10 19
11/* Convenience macros to test the version of gcc. */ 20/* Convenience macros to test the version of gcc. */
12#undef __GNUC_PREREQ 21#undef __GNUC_PREREQ
@@ -119,7 +128,7 @@
119 128
120/* Make all declarations hidden (-fvisibility flag only affects definitions) */ 129/* Make all declarations hidden (-fvisibility flag only affects definitions) */
121/* (don't include system headers after this until corresponding pop!) */ 130/* (don't include system headers after this until corresponding pop!) */
122#if __GNUC_PREREQ(4,1) && !defined(__CYGWIN__) 131#if __GNUC_PREREQ(4,1) && !defined(__CYGWIN__) && !ENABLE_PLATFORM_MINGW32
123# define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma("GCC visibility push(hidden)") 132# define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma("GCC visibility push(hidden)")
124# define POP_SAVED_FUNCTION_VISIBILITY _Pragma("GCC visibility pop") 133# define POP_SAVED_FUNCTION_VISIBILITY _Pragma("GCC visibility pop")
125#else 134#else
@@ -148,6 +157,14 @@
148# define bswap_64 __bswap64 157# define bswap_64 __bswap64
149# define bswap_32 __bswap32 158# define bswap_32 __bswap32
150# define bswap_16 __bswap16 159# define bswap_16 __bswap16
160# define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN)
161#elif ENABLE_PLATFORM_MINGW32
162# define __BIG_ENDIAN 0
163# define __LITTLE_ENDIAN 1
164# define __BYTE_ORDER __LITTLE_ENDIAN
165# define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0xFF) << 8))
166# define bswap_32(x) ((bswap_16(((x) & 0xFFFF0000L) >> 16)) | (bswap_16((x) & 0xFFFFL) << 16))
167# define bswap_64(x) ((bswap_32(((x) & 0xFFFFFFFF00000000LL) >> 32)) | (bswap_32((x) & 0xFFFFFFFFLL) << 32))
151#else 168#else
152# include <byteswap.h> 169# include <byteswap.h>
153# include <endian.h> 170# include <endian.h>
@@ -400,6 +417,25 @@ typedef unsigned smalluint;
400# endif 417# endif
401#endif 418#endif
402 419
420#if ENABLE_PLATFORM_MINGW32
421# undef HAVE_DPRINTF
422# undef HAVE_GETLINE
423# undef HAVE_MEMRCHR
424# undef HAVE_MKDTEMP
425# undef HAVE_SETBIT
426# undef HAVE_STPCPY
427# undef HAVE_STRCASESTR
428# undef HAVE_STRCHRNUL
429# undef HAVE_STRSEP
430# undef HAVE_STRSIGNAL
431# undef HAVE_STRVERSCMP
432#if !defined(__MINGW64_VERSION_MAJOR)
433# undef HAVE_VASPRINTF
434#endif
435# undef HAVE_UNLOCKED_STDIO
436# undef HAVE_UNLOCKED_LINE_OPS
437#endif
438
403#if defined(__WATCOMC__) 439#if defined(__WATCOMC__)
404# undef HAVE_DPRINTF 440# undef HAVE_DPRINTF
405# undef HAVE_GETLINE 441# undef HAVE_GETLINE
@@ -511,6 +547,7 @@ extern int dprintf(int fd, const char *format, ...);
511#endif 547#endif
512 548
513#ifndef HAVE_MEMRCHR 549#ifndef HAVE_MEMRCHR
550#include <stddef.h>
514extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; 551extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC;
515#endif 552#endif
516 553
@@ -570,6 +607,7 @@ extern int usleep(unsigned) FAST_FUNC;
570#endif 607#endif
571 608
572#ifndef HAVE_VASPRINTF 609#ifndef HAVE_VASPRINTF
610# include <stdarg.h>
573extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; 611extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
574#endif 612#endif
575 613