aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bb_archive.h10
-rw-r--r--include/libbb.h46
-rw-r--r--include/mingw.h484
-rw-r--r--include/platform.h41
4 files changed, 577 insertions, 4 deletions
diff --git a/include/bb_archive.h b/include/bb_archive.h
index d3762415f..c118fa7ec 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 9aba71949..61ceb6085 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/* klogctl is in libc's klog.h, but we cheat and not #include that */ 178/* klogctl is in libc's klog.h, but we cheat and not #include that */
171int klogctl(int type, char *b, int len); 179int klogctl(int type, char *b, int len);
172#ifndef PATH_MAX 180#ifndef PATH_MAX
@@ -176,6 +184,9 @@ int klogctl(int type, char *b, int len);
176# define BUFSIZ 4096 184# define BUFSIZ 4096
177#endif 185#endif
178 186
187#if ENABLE_PLATFORM_MINGW32
188# include "mingw.h"
189#endif
179 190
180/* Busybox does not use threads, we can speed up stdio. */ 191/* Busybox does not use threads, we can speed up stdio. */
181#ifdef HAVE_UNLOCKED_STDIO 192#ifdef HAVE_UNLOCKED_STDIO
@@ -238,6 +249,13 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
238 : ((T)1 << (sizeof(T)*8-1)) \ 249 : ((T)1 << (sizeof(T)*8-1)) \
239 ) 250 )
240 251
252#if ENABLE_PLATFORM_MINGW32 && \
253 (!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO)
254#define LL_FMT "I64"
255#else
256#define LL_FMT "ll"
257#endif
258
241/* Large file support */ 259/* Large file support */
242/* Note that CONFIG_LFS=y forces bbox to be built with all common ops 260/* Note that CONFIG_LFS=y forces bbox to be built with all common ops
243 * (stat, lseek etc) mapped to "largefile" variants by libc. 261 * (stat, lseek etc) mapped to "largefile" variants by libc.
@@ -263,7 +281,7 @@ typedef unsigned long long uoff_t;
263# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX) 281# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
264# define BB_STRTOOFF bb_strtoull 282# define BB_STRTOOFF bb_strtoull
265# define STRTOOFF strtoull 283# define STRTOOFF strtoull
266# define OFF_FMT "ll" 284# define OFF_FMT LL_FMT
267# endif 285# endif
268#else 286#else
269/* CONFIG_LFS is off */ 287/* CONFIG_LFS is off */
@@ -510,6 +528,7 @@ enum {
510 + (1LL << SIGUSR2) 528 + (1LL << SIGUSR2)
511 + 0), 529 + 0),
512}; 530};
531#if !ENABLE_PLATFORM_MINGW32
513void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; 532void bb_signals(int sigs, void (*f)(int)) FAST_FUNC;
514/* Unlike signal() and bb_signals, sets handler with sigaction() 533/* Unlike signal() and bb_signals, sets handler with sigaction()
515 * and in a way that while signal handler is run, no other signals 534 * and in a way that while signal handler is run, no other signals
@@ -527,6 +546,10 @@ void sig_unblock(int sig) FAST_FUNC;
527int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC; 546int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC;
528/* SIG_BLOCK/SIG_UNBLOCK all signals: */ 547/* SIG_BLOCK/SIG_UNBLOCK all signals: */
529int sigprocmask_allsigs(int how) FAST_FUNC; 548int sigprocmask_allsigs(int how) FAST_FUNC;
549#else
550#define bb_signals(s, f)
551#define kill_myself_with_sig(s)
552#endif
530/* Standard handler which just records signo */ 553/* Standard handler which just records signo */
531extern smallint bb_got_signal; 554extern smallint bb_got_signal;
532void record_signo(int signo); /* not FAST_FUNC! */ 555void record_signo(int signo); /* not FAST_FUNC! */
@@ -606,7 +629,7 @@ char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
606int xsocket(int domain, int type, int protocol) FAST_FUNC; 629int xsocket(int domain, int type, int protocol) FAST_FUNC;
607void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; 630void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
608void xlisten(int s, int backlog) FAST_FUNC; 631void xlisten(int s, int backlog) FAST_FUNC;
609void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; 632void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC;
610ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 633ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
611 socklen_t tolen) FAST_FUNC; 634 socklen_t tolen) FAST_FUNC;
612 635
@@ -941,6 +964,9 @@ char *safe_gethostname(void) FAST_FUNC;
941char* str_tolower(char *str) FAST_FUNC; 964char* str_tolower(char *str) FAST_FUNC;
942 965
943char *utoa(unsigned n) FAST_FUNC; 966char *utoa(unsigned n) FAST_FUNC;
967#if ENABLE_PLATFORM_MINGW32
968# define itoa bb_itoa
969#endif
944char *itoa(int n) FAST_FUNC; 970char *itoa(int n) FAST_FUNC;
945/* Returns a pointer past the formatted number, does NOT null-terminate */ 971/* Returns a pointer past the formatted number, does NOT null-terminate */
946char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; 972char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC;
@@ -1116,6 +1142,9 @@ int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
1116extern int find_applet_by_name(const char *name) FAST_FUNC; 1142extern int find_applet_by_name(const char *name) FAST_FUNC;
1117extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; 1143extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
1118#endif 1144#endif
1145#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_NOFORK
1146extern int long_running_applet(int applet_no) FAST_FUNC;
1147#endif
1119 1148
1120/* Helpers for daemonization. 1149/* Helpers for daemonization.
1121 * 1150 *
@@ -1199,7 +1228,7 @@ extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
1199 * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0 1228 * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0
1200 * (to interpret it as if optreset was set). 1229 * (to interpret it as if optreset was set).
1201 */ 1230 */
1202#ifdef __GLIBC__ 1231#if defined(__GLIBC__) || ENABLE_PLATFORM_MINGW32
1203#define GETOPT_RESET() (optind = 0) 1232#define GETOPT_RESET() (optind = 0)
1204#else /* BSD style */ 1233#else /* BSD style */
1205#define GETOPT_RESET() (optind = 1) 1234#define GETOPT_RESET() (optind = 1)
@@ -1776,6 +1805,9 @@ typedef struct procps_status_t {
1776#if ENABLE_FEATURE_TOP_SMP_PROCESS 1805#if ENABLE_FEATURE_TOP_SMP_PROCESS
1777 int last_seen_on_cpu; 1806 int last_seen_on_cpu;
1778#endif 1807#endif
1808#if ENABLE_PLATFORM_MINGW32
1809 HANDLE snapshot;
1810#endif
1779} procps_status_t; 1811} procps_status_t;
1780/* flag bits for procps_scan(xx, flags) calls */ 1812/* flag bits for procps_scan(xx, flags) calls */
1781enum { 1813enum {
@@ -1814,7 +1846,11 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC;
1814procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; 1846procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC;
1815/* Format cmdline (up to col chars) into char buf[size] */ 1847/* Format cmdline (up to col chars) into char buf[size] */
1816/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ 1848/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */
1849#if !ENABLE_PLATFORM_MINGW32
1817void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; 1850void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC;
1851#else
1852#define read_cmdline(buf, size, pid, comm) snprintf(buf, size, "[%s]", comm)
1853#endif
1818pid_t *find_pid_by_name(const char* procName) FAST_FUNC; 1854pid_t *find_pid_by_name(const char* procName) FAST_FUNC;
1819pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; 1855pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC;
1820int starts_with_cpu(const char *str) FAST_FUNC; 1856int starts_with_cpu(const char *str) FAST_FUNC;
@@ -1958,7 +1994,11 @@ extern const char bb_path_wtmp_file[] ALIGN1;
1958#define bb_path_motd_file "/etc/motd" 1994#define bb_path_motd_file "/etc/motd"
1959 1995
1960#define bb_dev_null "/dev/null" 1996#define bb_dev_null "/dev/null"
1997#if ENABLE_PLATFORM_MINGW32
1998#define bb_busybox_exec_path get_busybox_exec_path()
1999#else
1961extern const char bb_busybox_exec_path[] ALIGN1; 2000extern const char bb_busybox_exec_path[] ALIGN1;
2001#endif
1962/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, 2002/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
1963 * but I want to save a few bytes here */ 2003 * but I want to save a few bytes here */
1964extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ 2004extern 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..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);
diff --git a/include/platform.h b/include/platform.h
index b81c59d4e..749169b0c 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
@@ -131,7 +140,7 @@
131 140
132/* Make all declarations hidden (-fvisibility flag only affects definitions) */ 141/* Make all declarations hidden (-fvisibility flag only affects definitions) */
133/* (don't include system headers after this until corresponding pop!) */ 142/* (don't include system headers after this until corresponding pop!) */
134#if __GNUC_PREREQ(4,1) && !defined(__CYGWIN__) 143#if __GNUC_PREREQ(4,1) && !defined(__CYGWIN__) && !ENABLE_PLATFORM_MINGW32
135# define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma("GCC visibility push(hidden)") 144# define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma("GCC visibility push(hidden)")
136# define POP_SAVED_FUNCTION_VISIBILITY _Pragma("GCC visibility pop") 145# define POP_SAVED_FUNCTION_VISIBILITY _Pragma("GCC visibility pop")
137#else 146#else
@@ -160,6 +169,14 @@
160# define bswap_64 __bswap64 169# define bswap_64 __bswap64
161# define bswap_32 __bswap32 170# define bswap_32 __bswap32
162# define bswap_16 __bswap16 171# define bswap_16 __bswap16
172# define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN)
173#elif ENABLE_PLATFORM_MINGW32
174# define __BIG_ENDIAN 0
175# define __LITTLE_ENDIAN 1
176# define __BYTE_ORDER __LITTLE_ENDIAN
177# define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0xFF) << 8))
178# define bswap_32(x) ((bswap_16(((x) & 0xFFFF0000L) >> 16)) | (bswap_16((x) & 0xFFFFL) << 16))
179# define bswap_64(x) ((bswap_32(((x) & 0xFFFFFFFF00000000LL) >> 32)) | (bswap_32((x) & 0xFFFFFFFFLL) << 32))
163#else 180#else
164# include <byteswap.h> 181# include <byteswap.h>
165# include <endian.h> 182# include <endian.h>
@@ -419,6 +436,26 @@ typedef unsigned smalluint;
419# endif 436# endif
420#endif 437#endif
421 438
439#if ENABLE_PLATFORM_MINGW32
440# undef HAVE_DPRINTF
441# undef HAVE_GETLINE
442# undef HAVE_MEMRCHR
443# undef HAVE_MKDTEMP
444# undef HAVE_SETBIT
445# undef HAVE_STPCPY
446# undef HAVE_STRCASESTR
447# undef HAVE_STRCHRNUL
448# undef HAVE_STRSEP
449# undef HAVE_STRSIGNAL
450# undef HAVE_STRVERSCMP
451#if !defined(__MINGW64_VERSION_MAJOR)
452# undef HAVE_VASPRINTF
453#endif
454# undef HAVE_UNLOCKED_STDIO
455# undef HAVE_UNLOCKED_LINE_OPS
456# undef HAVE_PRINTF_PERCENTM
457#endif
458
422#if defined(__WATCOMC__) 459#if defined(__WATCOMC__)
423# undef HAVE_DPRINTF 460# undef HAVE_DPRINTF
424# undef HAVE_GETLINE 461# undef HAVE_GETLINE
@@ -533,6 +570,7 @@ extern int dprintf(int fd, const char *format, ...);
533#endif 570#endif
534 571
535#ifndef HAVE_MEMRCHR 572#ifndef HAVE_MEMRCHR
573#include <stddef.h>
536extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; 574extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC;
537#endif 575#endif
538 576
@@ -592,6 +630,7 @@ extern int usleep(unsigned) FAST_FUNC;
592#endif 630#endif
593 631
594#ifndef HAVE_VASPRINTF 632#ifndef HAVE_VASPRINTF
633# include <stdarg.h>
595extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; 634extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
596#endif 635#endif
597 636