aboutsummaryrefslogtreecommitdiff
path: root/include/libbb.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libbb.h')
-rw-r--r--include/libbb.h69
1 files changed, 67 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 33766e989..9da94638b 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -139,6 +139,12 @@
139# include <arpa/inet.h> 139# include <arpa/inet.h>
140#elif defined __APPLE__ 140#elif defined __APPLE__
141# include <netinet/in.h> 141# include <netinet/in.h>
142#elif ENABLE_PLATFORM_MINGW32
143# ifndef WINVER
144# define WINVER 0x0501
145# endif
146# include <winsock2.h>
147# include <ws2tcpip.h>
142#else 148#else
143# include <arpa/inet.h> 149# include <arpa/inet.h>
144//This breaks on bionic: 150//This breaks on bionic:
@@ -178,7 +184,9 @@
178 184
179/* Some libc's forget to declare these, do it ourself */ 185/* Some libc's forget to declare these, do it ourself */
180 186
187#if !ENABLE_PLATFORM_MINGW32
181extern char **environ; 188extern char **environ;
189#endif
182/* klogctl is in libc's klog.h, but we cheat and not #include that */ 190/* klogctl is in libc's klog.h, but we cheat and not #include that */
183int klogctl(int type, char *b, int len); 191int klogctl(int type, char *b, int len);
184#ifndef PATH_MAX 192#ifndef PATH_MAX
@@ -188,6 +196,9 @@ int klogctl(int type, char *b, int len);
188# define BUFSIZ 4096 196# define BUFSIZ 4096
189#endif 197#endif
190 198
199#if ENABLE_PLATFORM_MINGW32
200# include "mingw.h"
201#endif
191 202
192/* Busybox does not use threads, we can speed up stdio. */ 203/* Busybox does not use threads, we can speed up stdio. */
193#ifdef HAVE_UNLOCKED_STDIO 204#ifdef HAVE_UNLOCKED_STDIO
@@ -250,6 +261,13 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
250 : ((T)1 << (sizeof(T)*8-1)) \ 261 : ((T)1 << (sizeof(T)*8-1)) \
251 ) 262 )
252 263
264#if ENABLE_PLATFORM_MINGW32 && \
265 (!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO)
266#define LL_FMT "I64"
267#else
268#define LL_FMT "ll"
269#endif
270
253/* Large file support */ 271/* Large file support */
254/* Note that CONFIG_LFS=y forces bbox to be built with all common ops 272/* Note that CONFIG_LFS=y forces bbox to be built with all common ops
255 * (stat, lseek etc) mapped to "largefile" variants by libc. 273 * (stat, lseek etc) mapped to "largefile" variants by libc.
@@ -275,7 +293,7 @@ typedef unsigned long long uoff_t;
275# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX) 293# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
276# define BB_STRTOOFF bb_strtoull 294# define BB_STRTOOFF bb_strtoull
277# define STRTOOFF strtoull 295# define STRTOOFF strtoull
278# define OFF_FMT "ll" 296# define OFF_FMT LL_FMT
279# endif 297# endif
280#else 298#else
281/* CONFIG_LFS is off */ 299/* CONFIG_LFS is off */
@@ -513,20 +531,37 @@ enum {
513 * Dance around with long long to guard against that... 531 * Dance around with long long to guard against that...
514 */ 532 */
515 BB_FATAL_SIGS = (int)(0 533 BB_FATAL_SIGS = (int)(0
534#ifdef SIGHUP
516 + (1LL << SIGHUP) 535 + (1LL << SIGHUP)
536#endif
517 + (1LL << SIGINT) 537 + (1LL << SIGINT)
518 + (1LL << SIGTERM) 538 + (1LL << SIGTERM)
519 + (1LL << SIGPIPE) // Write to pipe with no readers 539 + (1LL << SIGPIPE) // Write to pipe with no readers
540#ifdef SIGQUIT
520 + (1LL << SIGQUIT) // Quit from keyboard 541 + (1LL << SIGQUIT) // Quit from keyboard
542#endif
521 + (1LL << SIGABRT) // Abort signal from abort(3) 543 + (1LL << SIGABRT) // Abort signal from abort(3)
544#ifdef SIGALRM
522 + (1LL << SIGALRM) // Timer signal from alarm(2) 545 + (1LL << SIGALRM) // Timer signal from alarm(2)
546#endif
547#ifdef SIGVTALRM
523 + (1LL << SIGVTALRM) // Virtual alarm clock 548 + (1LL << SIGVTALRM) // Virtual alarm clock
549#endif
550#ifdef SIGXCPU
524 + (1LL << SIGXCPU) // CPU time limit exceeded 551 + (1LL << SIGXCPU) // CPU time limit exceeded
552#endif
553#ifdef SIGXFSZ
525 + (1LL << SIGXFSZ) // File size limit exceeded 554 + (1LL << SIGXFSZ) // File size limit exceeded
555#endif
556#ifdef SIGUSR1
526 + (1LL << SIGUSR1) // Yes kids, these are also fatal! 557 + (1LL << SIGUSR1) // Yes kids, these are also fatal!
558#endif
559#ifdef SIGUSR1
527 + (1LL << SIGUSR2) 560 + (1LL << SIGUSR2)
561#endif
528 + 0), 562 + 0),
529}; 563};
564#if !ENABLE_PLATFORM_MINGW32
530void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; 565void bb_signals(int sigs, void (*f)(int)) FAST_FUNC;
531/* Unlike signal() and bb_signals, sets handler with sigaction() 566/* Unlike signal() and bb_signals, sets handler with sigaction()
532 * and in a way that while signal handler is run, no other signals 567 * and in a way that while signal handler is run, no other signals
@@ -546,6 +581,10 @@ int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC;
546int sigprocmask_allsigs(int how) FAST_FUNC; 581int sigprocmask_allsigs(int how) FAST_FUNC;
547/* Return old set in the same set: */ 582/* Return old set in the same set: */
548int sigprocmask2(int how, sigset_t *set) FAST_FUNC; 583int sigprocmask2(int how, sigset_t *set) FAST_FUNC;
584#else
585#define bb_signals(s, f)
586#define kill_myself_with_sig(s)
587#endif
549/* Standard handler which just records signo */ 588/* Standard handler which just records signo */
550extern smallint bb_got_signal; 589extern smallint bb_got_signal;
551void record_signo(int signo); /* not FAST_FUNC! */ 590void record_signo(int signo); /* not FAST_FUNC! */
@@ -625,7 +664,7 @@ char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
625int xsocket(int domain, int type, int protocol) FAST_FUNC; 664int xsocket(int domain, int type, int protocol) FAST_FUNC;
626void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; 665void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
627void xlisten(int s, int backlog) FAST_FUNC; 666void xlisten(int s, int backlog) FAST_FUNC;
628void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; 667void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC;
629ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 668ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
630 socklen_t tolen) FAST_FUNC; 669 socklen_t tolen) FAST_FUNC;
631 670
@@ -1132,6 +1171,7 @@ void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
1132 1171
1133/* xvfork() can't be a _function_, return after vfork in child mangles stack 1172/* xvfork() can't be a _function_, return after vfork in child mangles stack
1134 * in the parent. It must be a macro. */ 1173 * in the parent. It must be a macro. */
1174#if !ENABLE_PLATFORM_MINGW32
1135#define xvfork() \ 1175#define xvfork() \
1136({ \ 1176({ \
1137 pid_t bb__xvfork_pid = vfork(); \ 1177 pid_t bb__xvfork_pid = vfork(); \
@@ -1139,6 +1179,9 @@ void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
1139 bb_perror_msg_and_die("vfork"); \ 1179 bb_perror_msg_and_die("vfork"); \
1140 bb__xvfork_pid; \ 1180 bb__xvfork_pid; \
1141}) 1181})
1182#else
1183#define xvfork() vfork()
1184#endif
1142#if BB_MMU 1185#if BB_MMU
1143pid_t xfork(void) FAST_FUNC; 1186pid_t xfork(void) FAST_FUNC;
1144#endif 1187#endif
@@ -1683,9 +1726,15 @@ int bb_xioctl(int fd, unsigned request, void *argp) FAST_FUNC;
1683#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) 1726#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
1684#endif 1727#endif
1685 1728
1729#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA
1686char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; 1730char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC;
1687void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; 1731void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC;
1688void reset_ino_dev_hashtable(void) FAST_FUNC; 1732void reset_ino_dev_hashtable(void) FAST_FUNC;
1733#else
1734#define add_to_ino_dev_hashtable(s, n) (void)0
1735#define is_in_ino_dev_hashtable(s) NULL
1736#define reset_ino_dev_hashtable()
1737#endif
1689#ifdef __GLIBC__ 1738#ifdef __GLIBC__
1690/* At least glibc has horrendously large inline for this, so wrap it */ 1739/* At least glibc has horrendously large inline for this, so wrap it */
1691unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; 1740unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC;
@@ -1860,7 +1909,11 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
1860 void (*cb)(struct smaprec *, void *), void *data); 1909 void (*cb)(struct smaprec *, void *), void *data);
1861 1910
1862typedef struct procps_status_t { 1911typedef struct procps_status_t {
1912#if !ENABLE_PLATFORM_MINGW32
1863 DIR *dir; 1913 DIR *dir;
1914#else
1915 HANDLE snapshot;
1916#endif
1864 IF_FEATURE_SHOW_THREADS(DIR *task_dir;) 1917 IF_FEATURE_SHOW_THREADS(DIR *task_dir;)
1865 uint8_t shift_pages_to_bytes; 1918 uint8_t shift_pages_to_bytes;
1866 uint8_t shift_pages_to_kb; 1919 uint8_t shift_pages_to_kb;
@@ -2084,12 +2137,24 @@ extern const char bb_path_wtmp_file[] ALIGN1;
2084#define bb_path_motd_file "/etc/motd" 2137#define bb_path_motd_file "/etc/motd"
2085 2138
2086#define bb_dev_null "/dev/null" 2139#define bb_dev_null "/dev/null"
2140#if ENABLE_PLATFORM_MINGW32
2141#define bb_busybox_exec_path get_busybox_exec_path()
2142extern char bb_comm[];
2143extern char bb_command_line[];
2144#else
2087extern const char bb_busybox_exec_path[] ALIGN1; 2145extern const char bb_busybox_exec_path[] ALIGN1;
2146#endif
2088/* allow default system PATH to be extended via CFLAGS */ 2147/* allow default system PATH to be extended via CFLAGS */
2089#ifndef BB_ADDITIONAL_PATH 2148#ifndef BB_ADDITIONAL_PATH
2090#define BB_ADDITIONAL_PATH "" 2149#define BB_ADDITIONAL_PATH ""
2091#endif 2150#endif
2151#if !ENABLE_PLATFORM_MINGW32
2092#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH 2152#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH
2153#define PATH_SEP ':'
2154#else
2155#define BB_PATH_ROOT_PATH "PATH=/sbin;/usr/sbin;/bin;/usr/bin" BB_ADDITIONAL_PATH
2156#define PATH_SEP ';'
2157#endif
2093extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ 2158extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
2094#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) 2159#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
2095/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, 2160/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,