diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bb_archive.h | 10 | ||||
-rw-r--r-- | include/libbb.h | 46 | ||||
-rw-r--r-- | include/mingw.h | 484 | ||||
-rw-r--r-- | include/platform.h | 41 |
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 | |||
5 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 15 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
6 | 16 | ||
7 | enum { | 17 | enum { |
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 | ||
169 | extern char **environ; | 176 | extern 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 */ |
171 | int klogctl(int type, char *b, int len); | 179 | int 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 | ||
513 | void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; | 532 | void 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; | |||
527 | int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC; | 546 | int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC; |
528 | /* SIG_BLOCK/SIG_UNBLOCK all signals: */ | 547 | /* SIG_BLOCK/SIG_UNBLOCK all signals: */ |
529 | int sigprocmask_allsigs(int how) FAST_FUNC; | 548 | int 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 */ |
531 | extern smallint bb_got_signal; | 554 | extern smallint bb_got_signal; |
532 | void record_signo(int signo); /* not FAST_FUNC! */ | 555 | void record_signo(int signo); /* not FAST_FUNC! */ |
@@ -606,7 +629,7 @@ char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC; | |||
606 | int xsocket(int domain, int type, int protocol) FAST_FUNC; | 629 | int xsocket(int domain, int type, int protocol) FAST_FUNC; |
607 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; | 630 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; |
608 | void xlisten(int s, int backlog) FAST_FUNC; | 631 | void xlisten(int s, int backlog) FAST_FUNC; |
609 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; | 632 | void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC; |
610 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | 633 | ssize_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; | |||
941 | char* str_tolower(char *str) FAST_FUNC; | 964 | char* str_tolower(char *str) FAST_FUNC; |
942 | 965 | ||
943 | char *utoa(unsigned n) FAST_FUNC; | 966 | char *utoa(unsigned n) FAST_FUNC; |
967 | #if ENABLE_PLATFORM_MINGW32 | ||
968 | # define itoa bb_itoa | ||
969 | #endif | ||
944 | char *itoa(int n) FAST_FUNC; | 970 | char *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 */ |
946 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; | 972 | char *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; | |||
1116 | extern int find_applet_by_name(const char *name) FAST_FUNC; | 1142 | extern int find_applet_by_name(const char *name) FAST_FUNC; |
1117 | extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; | 1143 | extern 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 | ||
1146 | extern 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 */ |
1781 | enum { | 1813 | enum { |
@@ -1814,7 +1846,11 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC; | |||
1814 | procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; | 1846 | procps_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 | ||
1817 | void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; | 1850 | void 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 | ||
1818 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; | 1854 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; |
1819 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; | 1855 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; |
1820 | int starts_with_cpu(const char *str) FAST_FUNC; | 1856 | int 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 | ||
1961 | extern const char bb_busybox_exec_path[] ALIGN1; | 2000 | extern 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 */ |
1964 | extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ | 2004 | extern 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 | */ | ||
8 | typedef int gid_t; | ||
9 | typedef int uid_t; | ||
10 | #ifndef _WIN64 | ||
11 | typedef int pid_t; | ||
12 | #else | ||
13 | typedef __int64 pid_t; | ||
14 | #endif | ||
15 | |||
16 | #define DEFAULT_UID 1000 | ||
17 | #define DEFAULT_GID 1000 | ||
18 | |||
19 | /* | ||
20 | * arpa/inet.h | ||
21 | */ | ||
22 | static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); } | ||
23 | #define ntohl git_ntohl | ||
24 | int inet_aton(const char *cp, struct in_addr *inp); | ||
25 | int 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 | |||
43 | struct group { | ||
44 | char *gr_name; | ||
45 | char *gr_passwd; | ||
46 | gid_t gr_gid; | ||
47 | char **gr_mem; | ||
48 | }; | ||
49 | IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); | ||
50 | struct group *getgrgid(gid_t gid); | ||
51 | NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); | ||
52 | static inline void endgrent(void) {} | ||
53 | int 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 | |||
65 | typedef int sa_family_t; | ||
66 | |||
67 | /* | ||
68 | * linux/un.h | ||
69 | */ | ||
70 | struct 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 | */ | ||
78 | struct 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 | |||
88 | struct passwd *getpwnam(const char *name); | ||
89 | struct passwd *getpwuid(uid_t uid); | ||
90 | static inline void setpwent(void) {} | ||
91 | static inline void endpwent(void) {} | ||
92 | IMPL(getpwent_r,int,ENOENT,struct passwd *pwbuf UNUSED_PARAM,char *buf UNUSED_PARAM,size_t buflen UNUSED_PARAM,struct passwd **pwbufp UNUSED_PARAM); | ||
93 | IMPL(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 | |||
118 | typedef void (__cdecl *sighandler_t)(int); | ||
119 | struct 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 | |||
127 | NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM); | ||
128 | NOIMPL(sigfillset,int *mask UNUSED_PARAM); | ||
129 | NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); | ||
130 | NOIMPL(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 | |||
138 | int fdprintf(int fd, const char *format, ...); | ||
139 | FILE* mingw_fopen(const char *filename, const char *mode); | ||
140 | int mingw_rename(const char*, const char*); | ||
141 | #define fopen mingw_fopen | ||
142 | #define rename mingw_rename | ||
143 | |||
144 | FILE *mingw_popen(const char *cmd, const char *mode); | ||
145 | int mingw_popen_fd(const char *cmd, const char *mode, int fd0, pid_t *pid); | ||
146 | int 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 | |||
158 | void move_cursor_row(int n); | ||
159 | void reset_screen(void); | ||
160 | int winansi_putchar(int c); | ||
161 | int winansi_puts(const char *s); | ||
162 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | ||
163 | int winansi_fputs(const char *str, FILE *stream); | ||
164 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); | ||
165 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); | ||
166 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); | ||
167 | int winansi_write(int fd, const void *buf, size_t count); | ||
168 | int winansi_read(int fd, void *buf, size_t count); | ||
169 | int 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 | |||
182 | int 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 | |||
193 | int mingw_system(const char *cmd); | ||
194 | #define system mingw_system | ||
195 | |||
196 | int clearenv(void); | ||
197 | char *mingw_getenv(const char *name); | ||
198 | int mingw_putenv(const char *env); | ||
199 | char *mingw_mktemp(char *template); | ||
200 | int mkstemp(char *template); | ||
201 | char *realpath(const char *path, char *resolved_path); | ||
202 | int setenv(const char *name, const char *value, int replace); | ||
203 | #if ENABLE_SAFE_ENV | ||
204 | int unsetenv(const char *env); | ||
205 | #else | ||
206 | void 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 | */ | ||
218 | void *mempcpy(void *dest, const void *src, size_t n); | ||
219 | |||
220 | /* | ||
221 | * strings.h | ||
222 | */ | ||
223 | int ffs(int i); | ||
224 | |||
225 | /* | ||
226 | * sys/ioctl.h | ||
227 | */ | ||
228 | |||
229 | #define TIOCGWINSZ 0x5413 | ||
230 | |||
231 | int ioctl(int fd, int code, ...); | ||
232 | |||
233 | /* | ||
234 | * sys/socket.h | ||
235 | */ | ||
236 | #define hstrerror strerror | ||
237 | |||
238 | #define SHUT_WR SD_SEND | ||
239 | |||
240 | int mingw_socket(int domain, int type, int protocol); | ||
241 | int mingw_connect(int sockfd, const struct sockaddr *sa, size_t sz); | ||
242 | int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz); | ||
243 | int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen); | ||
244 | int mingw_shutdown(int sockfd, int how); | ||
245 | int mingw_listen(int sockfd, int backlog); | ||
246 | int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz); | ||
247 | int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, | ||
248 | struct timeval *timeout); | ||
249 | |||
250 | NOIMPL(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 | |||
286 | IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); | ||
287 | NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
288 | int mingw_mkdir(const char *path, int mode); | ||
289 | int 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 | |||
298 | typedef int nlink_t; | ||
299 | typedef int blksize_t; | ||
300 | typedef off_t blkcnt_t; | ||
301 | |||
302 | struct 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 | |||
318 | int mingw_lstat(const char *file_name, struct mingw_stat *buf); | ||
319 | int mingw_stat(const char *file_name, struct mingw_stat *buf); | ||
320 | int 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 | ||
340 | struct timespec { | ||
341 | time_t tv_sec; | ||
342 | long int tv_nsec; | ||
343 | }; | ||
344 | #endif | ||
345 | |||
346 | int nanosleep(const struct timespec *req, struct timespec *rem); | ||
347 | |||
348 | /* | ||
349 | * sys/wait.h | ||
350 | */ | ||
351 | #define WNOHANG 1 | ||
352 | #define WUNTRACED 2 | ||
353 | int waitpid(pid_t pid, int *status, int options); | ||
354 | |||
355 | /* | ||
356 | * time.h | ||
357 | */ | ||
358 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | ||
359 | struct tm *localtime_r(const time_t *timep, struct tm *result); | ||
360 | char *strptime(const char *s, const char *format, struct tm *tm); | ||
361 | size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm *tm); | ||
362 | int stime(time_t *t); | ||
363 | |||
364 | #define strftime mingw_strftime | ||
365 | |||
366 | /* | ||
367 | * times.h | ||
368 | */ | ||
369 | #define clock_t long | ||
370 | |||
371 | struct 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 | |||
378 | clock_t times(struct tms *buf); | ||
379 | |||
380 | /* | ||
381 | * unistd.h | ||
382 | */ | ||
383 | #define PIPE_BUF 8192 | ||
384 | |||
385 | #define _SC_CLK_TCK 2 | ||
386 | |||
387 | IMPL(alarm,unsigned int,0,unsigned int seconds UNUSED_PARAM); | ||
388 | IMPL(chown,int,0,const char *path UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
389 | NOIMPL(chroot,const char *root UNUSED_PARAM); | ||
390 | NOIMPL(fchdir,int fd UNUSED_PARAM); | ||
391 | int mingw_dup2 (int fd, int fdto); | ||
392 | char *mingw_getcwd(char *pointer, int len); | ||
393 | off_t mingw_lseek(int fd, off_t offset, int whence); | ||
394 | |||
395 | |||
396 | IMPL(getgid,int,DEFAULT_GID,void); | ||
397 | int getgroups(int n, gid_t *groups); | ||
398 | IMPL(getppid,int,1,void); | ||
399 | IMPL(getegid,int,DEFAULT_GID,void); | ||
400 | IMPL(geteuid,int,DEFAULT_UID,void); | ||
401 | NOIMPL(getsid,pid_t pid UNUSED_PARAM); | ||
402 | IMPL(getuid,int,DEFAULT_UID,void); | ||
403 | int getlogin_r(char *buf, size_t len); | ||
404 | int fcntl(int fd, int cmd, ...); | ||
405 | #define fork() -1 | ||
406 | IMPL(fsync,int,0,int fd UNUSED_PARAM); | ||
407 | int kill(pid_t pid, int sig); | ||
408 | int link(const char *oldpath, const char *newpath); | ||
409 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); | ||
410 | int mingw_open (const char *filename, int oflags, ...); | ||
411 | int pipe(int filedes[2]); | ||
412 | NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); | ||
413 | NOIMPL(setgid,gid_t gid UNUSED_PARAM); | ||
414 | NOIMPL(setegid,gid_t gid UNUSED_PARAM); | ||
415 | NOIMPL(setsid,void); | ||
416 | NOIMPL(setuid,uid_t gid UNUSED_PARAM); | ||
417 | NOIMPL(seteuid,uid_t gid UNUSED_PARAM); | ||
418 | unsigned int sleep(unsigned int seconds); | ||
419 | NOIMPL(symlink,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM); | ||
420 | static inline void sync(void) {} | ||
421 | long sysconf(int name); | ||
422 | NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARAM); | ||
423 | int mingw_unlink(const char *pathname); | ||
424 | NOIMPL(vfork,void); | ||
425 | int mingw_access(const char *name, int mode); | ||
426 | int 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 | */ | ||
443 | int utimes(const char *file_name, const struct timeval times[2]); | ||
444 | |||
445 | /* | ||
446 | * dirent.h | ||
447 | */ | ||
448 | DIR *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 | |||
457 | pid_t FAST_FUNC mingw_spawn(char **argv); | ||
458 | intptr_t FAST_FUNC mingw_spawn_proc(char **argv); | ||
459 | int mingw_execv(const char *cmd, const char *const *argv); | ||
460 | int mingw_execvp(const char *cmd, const char *const *argv); | ||
461 | int 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 | |||
467 | const 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 | |||
475 | char **copy_environ(const char *const *env); | ||
476 | void free_environ(char **env); | ||
477 | char **env_setenv(char **env, const char *name); | ||
478 | |||
479 | const char *get_busybox_exec_path(void); | ||
480 | void init_winsock(void); | ||
481 | |||
482 | char *file_is_win32_executable(const char *p); | ||
483 | |||
484 | int 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> | ||
536 | extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; | 574 | extern 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> | ||
595 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; | 634 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; |
596 | #endif | 635 | #endif |
597 | 636 | ||