diff options
Diffstat (limited to '')
-rw-r--r-- | include/libbb.h | 27 | ||||
-rw-r--r-- | include/mingw.h | 438 | ||||
-rw-r--r-- | include/platform.h | 40 |
3 files changed, 504 insertions, 1 deletions
diff --git a/include/libbb.h b/include/libbb.h index 68a7cf002..2850b1d5a 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -112,6 +112,13 @@ | |||
112 | # include <arpa/inet.h> | 112 | # include <arpa/inet.h> |
113 | #elif defined __APPLE__ | 113 | #elif defined __APPLE__ |
114 | # include <netinet/in.h> | 114 | # include <netinet/in.h> |
115 | #elif ENABLE_PLATFORM_MINGW32 | ||
116 | # ifndef WINVER | ||
117 | # define WINVER 0x0501 | ||
118 | # endif | ||
119 | # include <winsock2.h> | ||
120 | # include <ws2tcpip.h> | ||
121 | # undef s_addr | ||
115 | #else | 122 | #else |
116 | # include <arpa/inet.h> | 123 | # include <arpa/inet.h> |
117 | # if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) | 124 | # if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) |
@@ -136,7 +143,9 @@ | |||
136 | 143 | ||
137 | /* Some libc's forget to declare these, do it ourself */ | 144 | /* Some libc's forget to declare these, do it ourself */ |
138 | 145 | ||
146 | #if !ENABLE_PLATFORM_MINGW32 | ||
139 | extern char **environ; | 147 | extern char **environ; |
148 | #endif | ||
140 | #if defined(__GLIBC__) && __GLIBC__ < 2 | 149 | #if defined(__GLIBC__) && __GLIBC__ < 2 |
141 | int vdprintf(int d, const char *format, va_list ap); | 150 | int vdprintf(int d, const char *format, va_list ap); |
142 | #endif | 151 | #endif |
@@ -149,6 +158,10 @@ int klogctl(int type, char *b, int len); | |||
149 | # define BUFSIZ 4096 | 158 | # define BUFSIZ 4096 |
150 | #endif | 159 | #endif |
151 | 160 | ||
161 | /* Can't use ENABLE_PLATFORM_MINGW32 because it's also called by host compiler */ | ||
162 | #if ENABLE_PLATFORM_MINGW32 | ||
163 | # include "mingw.h" | ||
164 | #endif | ||
152 | 165 | ||
153 | /* Busybox does not use threads, we can speed up stdio. */ | 166 | /* Busybox does not use threads, we can speed up stdio. */ |
154 | #ifdef HAVE_UNLOCKED_STDIO | 167 | #ifdef HAVE_UNLOCKED_STDIO |
@@ -830,6 +843,9 @@ char *safe_gethostname(void) FAST_FUNC; | |||
830 | char* str_tolower(char *str) FAST_FUNC; | 843 | char* str_tolower(char *str) FAST_FUNC; |
831 | 844 | ||
832 | char *utoa(unsigned n) FAST_FUNC; | 845 | char *utoa(unsigned n) FAST_FUNC; |
846 | #if ENABLE_PLATFORM_MINGW32 | ||
847 | # define itoa bb_itoa | ||
848 | #endif | ||
833 | char *itoa(int n) FAST_FUNC; | 849 | char *itoa(int n) FAST_FUNC; |
834 | /* Returns a pointer past the formatted number, does NOT null-terminate */ | 850 | /* Returns a pointer past the formatted number, does NOT null-terminate */ |
835 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; | 851 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; |
@@ -1596,6 +1612,9 @@ typedef struct procps_status_t { | |||
1596 | #if ENABLE_FEATURE_TOP_SMP_PROCESS | 1612 | #if ENABLE_FEATURE_TOP_SMP_PROCESS |
1597 | int last_seen_on_cpu; | 1613 | int last_seen_on_cpu; |
1598 | #endif | 1614 | #endif |
1615 | #if ENABLE_PLATFORM_MINGW32 | ||
1616 | HANDLE snapshot; | ||
1617 | #endif | ||
1599 | } procps_status_t; | 1618 | } procps_status_t; |
1600 | /* flag bits for procps_scan(xx, flags) calls */ | 1619 | /* flag bits for procps_scan(xx, flags) calls */ |
1601 | enum { | 1620 | enum { |
@@ -1634,7 +1653,11 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC; | |||
1634 | procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; | 1653 | procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; |
1635 | /* Format cmdline (up to col chars) into char buf[size] */ | 1654 | /* Format cmdline (up to col chars) into char buf[size] */ |
1636 | /* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ | 1655 | /* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ |
1656 | #if !ENABLE_PLATFORM_MINGW32 | ||
1637 | void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; | 1657 | void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; |
1658 | #else | ||
1659 | #define read_cmdline(buf, size, pid, comm) snprintf(buf, size, "[%s]", comm) | ||
1660 | #endif | ||
1638 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; | 1661 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; |
1639 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; | 1662 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; |
1640 | int starts_with_cpu(const char *str) FAST_FUNC; | 1663 | int starts_with_cpu(const char *str) FAST_FUNC; |
@@ -1770,7 +1793,11 @@ extern const char bb_path_wtmp_file[] ALIGN1; | |||
1770 | #define bb_path_motd_file "/etc/motd" | 1793 | #define bb_path_motd_file "/etc/motd" |
1771 | 1794 | ||
1772 | #define bb_dev_null "/dev/null" | 1795 | #define bb_dev_null "/dev/null" |
1796 | #if ENABLE_PLATFORM_MINGW32 | ||
1797 | #define bb_busybox_exec_path get_busybox_exec_path() | ||
1798 | #else | ||
1773 | extern const char bb_busybox_exec_path[] ALIGN1; | 1799 | extern const char bb_busybox_exec_path[] ALIGN1; |
1800 | #endif | ||
1774 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, | 1801 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, |
1775 | * but I want to save a few bytes here */ | 1802 | * but I want to save a few bytes here */ |
1776 | extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ | 1803 | 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..090dd1776 --- /dev/null +++ b/include/mingw.h | |||
@@ -0,0 +1,438 @@ | |||
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 | /* | ||
17 | * arpa/inet.h | ||
18 | */ | ||
19 | static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); } | ||
20 | #define ntohl git_ntohl | ||
21 | int inet_aton(const char *cp, struct in_addr *inp); | ||
22 | |||
23 | /* | ||
24 | * fcntl.h | ||
25 | */ | ||
26 | #define F_DUPFD 0 | ||
27 | #define F_GETFD 1 | ||
28 | #define F_SETFD 2 | ||
29 | #define F_GETFL 3 | ||
30 | #define F_SETFL 3 | ||
31 | #define FD_CLOEXEC 0x1 | ||
32 | #define O_NONBLOCK 04000 | ||
33 | |||
34 | /* | ||
35 | * grp.h | ||
36 | */ | ||
37 | |||
38 | struct group { | ||
39 | char *gr_name; | ||
40 | char *gr_passwd; | ||
41 | gid_t gr_gid; | ||
42 | char **gr_mem; | ||
43 | }; | ||
44 | IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); | ||
45 | IMPL(getgrgid,struct group *,NULL,gid_t gid UNUSED_PARAM); | ||
46 | NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); | ||
47 | static inline void endgrent(void) {} | ||
48 | |||
49 | /* | ||
50 | * limits.h | ||
51 | */ | ||
52 | #define NAME_MAX 255 | ||
53 | #define MAXSYMLINKS 20 | ||
54 | |||
55 | /* | ||
56 | * netdb.h | ||
57 | */ | ||
58 | |||
59 | typedef int sa_family_t; | ||
60 | |||
61 | /* | ||
62 | * linux/un.h | ||
63 | */ | ||
64 | struct sockaddr_un { | ||
65 | sa_family_t sun_family; | ||
66 | char sun_path[1]; /* to make compiler happy, don't bother */ | ||
67 | }; | ||
68 | |||
69 | /* | ||
70 | * pwd.h | ||
71 | */ | ||
72 | struct passwd { | ||
73 | char *pw_name; | ||
74 | char *pw_gecos; | ||
75 | char *pw_dir; | ||
76 | char *pw_shell; | ||
77 | uid_t pw_uid; | ||
78 | gid_t pw_gid; | ||
79 | }; | ||
80 | |||
81 | IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM); | ||
82 | struct passwd *getpwuid(int uid); | ||
83 | static inline void setpwent(void) {} | ||
84 | static inline void endpwent(void) {} | ||
85 | IMPL(getpwent_r,int,ENOENT,struct passwd *pwbuf UNUSED_PARAM,char *buf UNUSED_PARAM,size_t buflen UNUSED_PARAM,struct passwd **pwbufp UNUSED_PARAM); | ||
86 | |||
87 | /* | ||
88 | * signal.h | ||
89 | */ | ||
90 | #define SIGHUP 1 | ||
91 | #define SIGQUIT 3 | ||
92 | #define SIGKILL 9 | ||
93 | #define SIGUSR1 10 | ||
94 | #define SIGUSR2 12 | ||
95 | #define SIGPIPE 13 | ||
96 | #define SIGALRM 14 | ||
97 | #define SIGCHLD 17 | ||
98 | #define SIGCONT 18 | ||
99 | #define SIGSTOP 19 | ||
100 | #define SIGTSTP 20 | ||
101 | #define SIGTTIN 21 | ||
102 | #define SIGTTOU 22 | ||
103 | #define SIGXCPU 24 | ||
104 | #define SIGXFSZ 25 | ||
105 | #define SIGVTALRM 26 | ||
106 | #define SIGWINCH 28 | ||
107 | |||
108 | #define SIG_UNBLOCK 1 | ||
109 | |||
110 | typedef void (__cdecl *sighandler_t)(int); | ||
111 | struct sigaction { | ||
112 | sighandler_t sa_handler; | ||
113 | unsigned sa_flags; | ||
114 | int sa_mask; | ||
115 | }; | ||
116 | #define sigemptyset(x) (void)0 | ||
117 | #define SA_RESTART 0 | ||
118 | |||
119 | int sigaction(int sig, struct sigaction *in, struct sigaction *out); | ||
120 | sighandler_t mingw_signal(int sig, sighandler_t handler); | ||
121 | NOIMPL(sigfillset,int *mask UNUSED_PARAM); | ||
122 | NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); | ||
123 | NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM); | ||
124 | |||
125 | #define signal mingw_signal | ||
126 | /* | ||
127 | * stdio.h | ||
128 | */ | ||
129 | #undef fseeko | ||
130 | #define fseeko(f,o,w) fseek(f,o,w) | ||
131 | |||
132 | int fdprintf(int fd, const char *format, ...); | ||
133 | FILE* mingw_fopen(const char *filename, const char *mode); | ||
134 | int mingw_rename(const char*, const char*); | ||
135 | #define fopen mingw_fopen | ||
136 | #define rename mingw_rename | ||
137 | |||
138 | FILE *mingw_popen(const char *cmd, const char *mode); | ||
139 | int mingw_pclose(FILE *fd); | ||
140 | #undef popen | ||
141 | #undef pclose | ||
142 | #define popen mingw_popen | ||
143 | #define pclose mingw_pclose | ||
144 | |||
145 | #define setlinebuf(fd) setvbuf(fd, (char *) NULL, _IOLBF, 0) | ||
146 | |||
147 | /* | ||
148 | * ANSI emulation wrappers | ||
149 | */ | ||
150 | |||
151 | int winansi_putchar(int c); | ||
152 | int winansi_puts(const char *s); | ||
153 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | ||
154 | int winansi_fputs(const char *str, FILE *stream); | ||
155 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); | ||
156 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); | ||
157 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); | ||
158 | int winansi_write(int fd, const void *buf, size_t count); | ||
159 | int winansi_read(int fd, void *buf, size_t count); | ||
160 | int winansi_getc(FILE *stream); | ||
161 | #define putchar winansi_putchar | ||
162 | #define puts winansi_puts | ||
163 | #define fwrite winansi_fwrite | ||
164 | #define fputs winansi_fputs | ||
165 | #define vprintf(...) winansi_vfprintf(stdout, __VA_ARGS__) | ||
166 | #define printf(...) winansi_printf(__VA_ARGS__) | ||
167 | #define fprintf(...) winansi_fprintf(__VA_ARGS__) | ||
168 | #define write winansi_write | ||
169 | #define read winansi_read | ||
170 | #define getc winansi_getc | ||
171 | |||
172 | int winansi_get_terminal_width_height(struct winsize *win); | ||
173 | |||
174 | /* | ||
175 | * stdlib.h | ||
176 | */ | ||
177 | #define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */ | ||
178 | #define WEXITSTATUS(x) ((x) & 0xff) | ||
179 | #define WIFSIGNALED(x) ((unsigned)(x) > 259) | ||
180 | #define WTERMSIG(x) ((x) & 0x7f) | ||
181 | #define WCOREDUMP(x) 0 | ||
182 | |||
183 | int mingw_system(const char *cmd); | ||
184 | #define system mingw_system | ||
185 | |||
186 | int clearenv(void); | ||
187 | char *mingw_getenv(const char *name); | ||
188 | char *mingw_mktemp(char *template); | ||
189 | int mkstemp(char *template); | ||
190 | char *realpath(const char *path, char *resolved_path); | ||
191 | int setenv(const char *name, const char *value, int replace); | ||
192 | void unsetenv(const char *env); | ||
193 | |||
194 | #define getenv mingw_getenv | ||
195 | #define mktemp mingw_mktemp | ||
196 | |||
197 | /* | ||
198 | * string.h | ||
199 | */ | ||
200 | void *mempcpy(void *dest, const void *src, size_t n); | ||
201 | |||
202 | /* | ||
203 | * sys/ioctl.h | ||
204 | */ | ||
205 | |||
206 | #define TIOCGWINSZ 0x5413 | ||
207 | |||
208 | int ioctl(int fd, int code, ...); | ||
209 | |||
210 | /* | ||
211 | * sys/socket.h | ||
212 | */ | ||
213 | #define hstrerror strerror | ||
214 | |||
215 | int mingw_socket(int domain, int type, int protocol); | ||
216 | int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz); | ||
217 | |||
218 | 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); | ||
219 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); | ||
220 | NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); | ||
221 | |||
222 | #define socket mingw_socket | ||
223 | #define connect mingw_connect | ||
224 | #define sendto mingw_sendto | ||
225 | #define listen mingw_listen | ||
226 | #define bind mingw_bind | ||
227 | |||
228 | /* | ||
229 | * sys/stat.h | ||
230 | */ | ||
231 | #define S_ISUID 04000 | ||
232 | #define S_ISGID 02000 | ||
233 | #define S_ISVTX 01000 | ||
234 | #ifndef S_IRWXU | ||
235 | #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) | ||
236 | #endif | ||
237 | #define S_IRWXG (S_IRWXU >> 3) | ||
238 | #define S_IRWXO (S_IRWXG >> 3) | ||
239 | |||
240 | #define S_IFSOCK 0140000 | ||
241 | #define S_IFLNK 0120000 /* Symbolic link */ | ||
242 | #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK) | ||
243 | #define S_ISSOCK(x) 0 | ||
244 | |||
245 | #define S_IRGRP (S_IRUSR >> 3) | ||
246 | #define S_IWGRP (S_IWUSR >> 3) | ||
247 | #define S_IXGRP (S_IXUSR >> 3) | ||
248 | #define S_IROTH (S_IRGRP >> 3) | ||
249 | #define S_IWOTH (S_IWGRP >> 3) | ||
250 | #define S_IXOTH (S_IXGRP >> 3) | ||
251 | |||
252 | IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); | ||
253 | NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
254 | int mingw_mkdir(const char *path, int mode); | ||
255 | #define mkdir mingw_mkdir | ||
256 | |||
257 | #if ENABLE_LFS | ||
258 | # define off_t off64_t | ||
259 | #endif | ||
260 | #undef lseek | ||
261 | #define lseek _lseeki64 | ||
262 | |||
263 | typedef int nlink_t; | ||
264 | typedef int blksize_t; | ||
265 | typedef off_t blkcnt_t; | ||
266 | |||
267 | struct mingw_stat { | ||
268 | dev_t st_dev; | ||
269 | ino_t st_ino; | ||
270 | mode_t st_mode; | ||
271 | nlink_t st_nlink; | ||
272 | uid_t st_uid; | ||
273 | gid_t st_gid; | ||
274 | dev_t st_rdev; | ||
275 | off_t st_size; | ||
276 | time_t st_atime; | ||
277 | time_t st_mtime; | ||
278 | time_t st_ctime; | ||
279 | blksize_t st_blksize; | ||
280 | blkcnt_t st_blocks; | ||
281 | }; | ||
282 | |||
283 | int mingw_lstat(const char *file_name, struct mingw_stat *buf); | ||
284 | int mingw_stat(const char *file_name, struct mingw_stat *buf); | ||
285 | int mingw_fstat(int fd, struct mingw_stat *buf); | ||
286 | #undef lstat | ||
287 | #undef stat | ||
288 | #undef fstat | ||
289 | #define lstat mingw_lstat | ||
290 | #define stat mingw_stat | ||
291 | #define fstat mingw_fstat | ||
292 | |||
293 | /* | ||
294 | * sys/sysmacros.h | ||
295 | */ | ||
296 | #define makedev(a,b) 0*(a)*(b) /* avoid unused warning */ | ||
297 | #define minor(x) 0 | ||
298 | #define major(x) 0 | ||
299 | |||
300 | /* | ||
301 | * sys/time.h | ||
302 | */ | ||
303 | #ifndef _TIMESPEC_DEFINED | ||
304 | #define _TIMESPEC_DEFINED | ||
305 | struct timespec { | ||
306 | time_t tv_sec; | ||
307 | long int tv_nsec; | ||
308 | }; | ||
309 | #endif | ||
310 | struct itimerval { | ||
311 | struct timeval it_value, it_interval; | ||
312 | }; | ||
313 | #define ITIMER_REAL 0 | ||
314 | |||
315 | int setitimer(int type, struct itimerval *in, struct itimerval *out); | ||
316 | |||
317 | /* | ||
318 | * sys/wait.h | ||
319 | */ | ||
320 | #define WNOHANG 1 | ||
321 | #define WUNTRACED 2 | ||
322 | int waitpid(pid_t pid, int *status, unsigned options); | ||
323 | |||
324 | /* | ||
325 | * time.h | ||
326 | */ | ||
327 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | ||
328 | struct tm *localtime_r(const time_t *timep, struct tm *result); | ||
329 | char *strptime(const char *s, const char *format, struct tm *tm); | ||
330 | size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm *tm); | ||
331 | int stime(time_t *t); | ||
332 | |||
333 | #define strftime mingw_strftime | ||
334 | |||
335 | /* | ||
336 | * times.h | ||
337 | */ | ||
338 | #define clock_t long | ||
339 | |||
340 | struct tms { | ||
341 | clock_t tms_utime; /* user CPU time */ | ||
342 | clock_t tms_stime; /* system CPU time */ | ||
343 | clock_t tms_cutime; /* user CPU time of children */ | ||
344 | clock_t tms_cstime; /* system CPU time of children */ | ||
345 | }; | ||
346 | |||
347 | clock_t times(struct tms *buf); | ||
348 | |||
349 | /* | ||
350 | * unistd.h | ||
351 | */ | ||
352 | #define PIPE_BUF 8192 | ||
353 | |||
354 | #define _SC_CLK_TCK 2 | ||
355 | |||
356 | IMPL(alarm,unsigned int,0,unsigned int seconds UNUSED_PARAM); | ||
357 | IMPL(chown,int,0,const char *path UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
358 | NOIMPL(chroot,const char *root UNUSED_PARAM); | ||
359 | int mingw_dup2 (int fd, int fdto); | ||
360 | char *mingw_getcwd(char *pointer, int len); | ||
361 | |||
362 | |||
363 | IMPL(getgid,int,1,void); | ||
364 | NOIMPL(getgroups,int n UNUSED_PARAM,gid_t *groups UNUSED_PARAM); | ||
365 | IMPL(getppid,int,1,void); | ||
366 | IMPL(getegid,int,1,void); | ||
367 | IMPL(geteuid,int,1,void); | ||
368 | NOIMPL(getsid,pid_t pid UNUSED_PARAM); | ||
369 | IMPL(getuid,int,1,void); | ||
370 | int fcntl(int fd, int cmd, ...); | ||
371 | #define fork() -1 | ||
372 | IMPL(fsync,int,0,int fd UNUSED_PARAM); | ||
373 | int kill(pid_t pid, int sig); | ||
374 | int link(const char *oldpath, const char *newpath); | ||
375 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); | ||
376 | int mingw_open (const char *filename, int oflags, ...); | ||
377 | int pipe(int filedes[2]); | ||
378 | NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); | ||
379 | NOIMPL(setgid,gid_t gid UNUSED_PARAM); | ||
380 | NOIMPL(setegid,gid_t gid UNUSED_PARAM); | ||
381 | NOIMPL(setsid,void); | ||
382 | NOIMPL(setuid,uid_t gid UNUSED_PARAM); | ||
383 | NOIMPL(seteuid,uid_t gid UNUSED_PARAM); | ||
384 | unsigned int sleep(unsigned int seconds); | ||
385 | NOIMPL(symlink,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM); | ||
386 | static inline void sync(void) {} | ||
387 | long sysconf(int name); | ||
388 | NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARAM); | ||
389 | int mingw_unlink(const char *pathname); | ||
390 | NOIMPL(vfork,void); | ||
391 | int mingw_access(const char *name, int mode); | ||
392 | |||
393 | #define dup2 mingw_dup2 | ||
394 | #define getcwd mingw_getcwd | ||
395 | #define lchown chown | ||
396 | #define open mingw_open | ||
397 | #define unlink mingw_unlink | ||
398 | |||
399 | #undef access | ||
400 | #define access mingw_access | ||
401 | |||
402 | /* | ||
403 | * utime.h | ||
404 | */ | ||
405 | int utimes(const char *file_name, const struct timeval times[2]); | ||
406 | |||
407 | /* | ||
408 | * MinGW specific | ||
409 | */ | ||
410 | #define is_dir_sep(c) ((c) == '/' || (c) == '\\') | ||
411 | #define PRIuMAX "I64u" | ||
412 | |||
413 | pid_t mingw_spawn(char **argv); | ||
414 | int mingw_execv(const char *cmd, const char *const *argv); | ||
415 | int mingw_execvp(const char *cmd, const char *const *argv); | ||
416 | int mingw_execve(const char *cmd, const char *const *argv, const char *const *envp); | ||
417 | pid_t mingw_spawn_applet(int mode, const char *applet, const char *const *argv, const char *const *envp); | ||
418 | pid_t mingw_spawn_1(int mode, const char *cmd, const char *const *argv, const char *const *envp); | ||
419 | #define execvp mingw_execvp | ||
420 | #define execve mingw_execve | ||
421 | #define execv mingw_execv | ||
422 | |||
423 | const char * next_path_sep(const char *path); | ||
424 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') | ||
425 | #define is_absolute_path(path) ((path)[0] == '/' || has_dos_drive_prefix(path)) | ||
426 | |||
427 | /* | ||
428 | * helpers | ||
429 | */ | ||
430 | |||
431 | char **copy_environ(const char *const *env); | ||
432 | void free_environ(char **env); | ||
433 | char **env_setenv(char **env, const char *name); | ||
434 | |||
435 | const char *get_busybox_exec_path(void); | ||
436 | void init_winsock(void); | ||
437 | |||
438 | char *file_is_win32_executable(const char *p); | ||
diff --git a/include/platform.h b/include/platform.h index 09c7ccd9c..e2b61592e 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> |
@@ -396,6 +413,25 @@ typedef unsigned smalluint; | |||
396 | # endif | 413 | # endif |
397 | #endif | 414 | #endif |
398 | 415 | ||
416 | #if ENABLE_PLATFORM_MINGW32 | ||
417 | # undef HAVE_DPRINTF | ||
418 | # undef HAVE_GETLINE | ||
419 | # undef HAVE_MEMRCHR | ||
420 | # undef HAVE_MKDTEMP | ||
421 | # undef HAVE_SETBIT | ||
422 | # undef HAVE_STPCPY | ||
423 | # undef HAVE_STRCASESTR | ||
424 | # undef HAVE_STRCHRNUL | ||
425 | # undef HAVE_STRSEP | ||
426 | # undef HAVE_STRSIGNAL | ||
427 | # undef HAVE_STRVERSCMP | ||
428 | #if !defined(__MINGW64_VERSION_MAJOR) | ||
429 | # undef HAVE_VASPRINTF | ||
430 | #endif | ||
431 | # undef HAVE_UNLOCKED_STDIO | ||
432 | # undef HAVE_UNLOCKED_LINE_OPS | ||
433 | #endif | ||
434 | |||
399 | #if defined(__WATCOMC__) | 435 | #if defined(__WATCOMC__) |
400 | # undef HAVE_DPRINTF | 436 | # undef HAVE_DPRINTF |
401 | # undef HAVE_GETLINE | 437 | # undef HAVE_GETLINE |
@@ -493,6 +529,7 @@ extern int dprintf(int fd, const char *format, ...); | |||
493 | #endif | 529 | #endif |
494 | 530 | ||
495 | #ifndef HAVE_MEMRCHR | 531 | #ifndef HAVE_MEMRCHR |
532 | #include <stddef.h> | ||
496 | extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; | 533 | extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; |
497 | #endif | 534 | #endif |
498 | 535 | ||
@@ -535,6 +572,7 @@ extern int usleep(unsigned) FAST_FUNC; | |||
535 | #endif | 572 | #endif |
536 | 573 | ||
537 | #ifndef HAVE_VASPRINTF | 574 | #ifndef HAVE_VASPRINTF |
575 | # include <stdarg.h> | ||
538 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; | 576 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; |
539 | #endif | 577 | #endif |
540 | 578 | ||