aboutsummaryrefslogtreecommitdiff
path: root/include/libbb.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libbb.h')
-rw-r--r--include/libbb.h72
1 files changed, 44 insertions, 28 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a6ecac932..e776951f0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -51,6 +51,20 @@
51#include <termios.h> 51#include <termios.h>
52#include <time.h> 52#include <time.h>
53#include <sys/param.h> 53#include <sys/param.h>
54#include <pwd.h>
55#include <grp.h>
56#if ENABLE_FEATURE_SHADOWPASSWDS
57# if !ENABLE_USE_BB_SHADOW
58/* If using busybox's shadow implementation, do not include the shadow.h
59 * header as the toolchain may not provide it at all.
60 */
61# include <shadow.h>
62# endif
63#endif
64#if defined(ANDROID) || defined(__ANDROID__)
65# define endpwent() ((void)0)
66# define endgrent() ((void)0)
67#endif
54#ifdef HAVE_MNTENT_H 68#ifdef HAVE_MNTENT_H
55# include <mntent.h> 69# include <mntent.h>
56#endif 70#endif
@@ -80,16 +94,6 @@
80#ifdef DMALLOC 94#ifdef DMALLOC
81# include <dmalloc.h> 95# include <dmalloc.h>
82#endif 96#endif
83#include <pwd.h>
84#include <grp.h>
85#if ENABLE_FEATURE_SHADOWPASSWDS
86# if !ENABLE_USE_BB_SHADOW
87/* If using busybox's shadow implementation, do not include the shadow.h
88 * header as the toolchain may not provide it at all.
89 */
90# include <shadow.h>
91# endif
92#endif
93/* Just in case libc doesn't define some of these... */ 97/* Just in case libc doesn't define some of these... */
94#ifndef _PATH_PASSWD 98#ifndef _PATH_PASSWD
95#define _PATH_PASSWD "/etc/passwd" 99#define _PATH_PASSWD "/etc/passwd"
@@ -224,7 +228,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
224# if ULONG_MAX > 0xffffffff 228# if ULONG_MAX > 0xffffffff
225/* "long" is long enough on this system */ 229/* "long" is long enough on this system */
226typedef unsigned long uoff_t; 230typedef unsigned long uoff_t;
227# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX) 231# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
228/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */ 232/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
229# define BB_STRTOOFF bb_strtoul 233# define BB_STRTOOFF bb_strtoul
230# define STRTOOFF strtoul 234# define STRTOOFF strtoul
@@ -233,7 +237,7 @@ typedef unsigned long uoff_t;
233# else 237# else
234/* "long" is too short, need "long long" */ 238/* "long" is too short, need "long long" */
235typedef unsigned long long uoff_t; 239typedef unsigned long long uoff_t;
236# define XATOOFF(a) xatoull_range(a, 0, LLONG_MAX) 240# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
237# define BB_STRTOOFF bb_strtoull 241# define BB_STRTOOFF bb_strtoull
238# define STRTOOFF strtoull 242# define STRTOOFF strtoull
239# define OFF_FMT "ll" 243# define OFF_FMT "ll"
@@ -250,7 +254,7 @@ typedef unsigned long uoff_t;
250# define OFF_FMT "l" 254# define OFF_FMT "l"
251# else 255# else
252typedef unsigned long uoff_t; 256typedef unsigned long uoff_t;
253# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX) 257# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
254# define BB_STRTOOFF bb_strtoul 258# define BB_STRTOOFF bb_strtoul
255# define STRTOOFF strtol 259# define STRTOOFF strtol
256# define OFF_FMT "l" 260# define OFF_FMT "l"
@@ -258,6 +262,12 @@ typedef unsigned long uoff_t;
258#endif 262#endif
259/* scary. better ideas? (but do *test* them first!) */ 263/* scary. better ideas? (but do *test* them first!) */
260#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1))) 264#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
265/* Users report bionic to use 32-bit off_t even if LARGEFILE support is requested.
266 * We misdetected that. Don't let it build:
267 */
268struct BUG_off_t_size_is_misdetected {
269 char BUG_off_t_size_is_misdetected[sizeof(off_t) == sizeof(uoff_t) ? 1 : -1];
270};
261 271
262/* Some useful definitions */ 272/* Some useful definitions */
263#undef FALSE 273#undef FALSE
@@ -321,7 +331,7 @@ extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC;
321 331
322//TODO: supply a pointer to char[11] buffer (avoid statics)? 332//TODO: supply a pointer to char[11] buffer (avoid statics)?
323extern const char *bb_mode_string(mode_t mode) FAST_FUNC; 333extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
324extern int is_directory(const char *name, int followLinks, struct stat *statBuf) FAST_FUNC; 334extern int is_directory(const char *name, int followLinks) FAST_FUNC;
325enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */ 335enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
326 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */ 336 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */
327 FILEUTILS_DEREFERENCE = 1 << 1, /* !-d */ 337 FILEUTILS_DEREFERENCE = 1 << 1, /* !-d */
@@ -571,12 +581,7 @@ enum {
571 * and if kernel doesn't support it, fall back to IPv4. 581 * and if kernel doesn't support it, fall back to IPv4.
572 * This is useful if you plan to bind to resulting local lsa. 582 * This is useful if you plan to bind to resulting local lsa.
573 */ 583 */
574#if ENABLE_FEATURE_IPV6
575int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC; 584int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC;
576#else
577int xsocket_type(len_and_sockaddr **lsap, int sock_type) FAST_FUNC;
578#define xsocket_type(lsap, af, sock_type) xsocket_type((lsap), (sock_type))
579#endif
580int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC; 585int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC;
581/* Create server socket bound to bindaddr:port. bindaddr can be NULL, 586/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
582 * numeric IP ("N.N.N.N") or numeric IPv6 address, 587 * numeric IP ("N.N.N.N") or numeric IPv6 address,
@@ -721,17 +726,23 @@ extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
721extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 726extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
722/* Never returns NULL */ 727/* Never returns NULL */
723extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 728extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
724/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ 729
725#if ENABLE_FEATURE_SEAMLESS_LZMA \ 730#define SEAMLESS_COMPRESSION (0 \
731 || ENABLE_FEATURE_SEAMLESS_XZ \
732 || ENABLE_FEATURE_SEAMLESS_LZMA \
726 || ENABLE_FEATURE_SEAMLESS_BZ2 \ 733 || ENABLE_FEATURE_SEAMLESS_BZ2 \
727 || ENABLE_FEATURE_SEAMLESS_GZ \ 734 || ENABLE_FEATURE_SEAMLESS_GZ \
728 /* || ENABLE_FEATURE_SEAMLESS_Z */ 735 || ENABLE_FEATURE_SEAMLESS_Z)
729extern void setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) FAST_FUNC; 736
730#else 737#if SEAMLESS_COMPRESSION
731# define setup_unzip_on_fd(...) ((void)0) 738/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
732#endif 739extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
733/* Autodetects .gz etc */ 740/* Autodetects .gz etc */
734extern int open_zipped(const char *fname) FAST_FUNC; 741extern int open_zipped(const char *fname) FAST_FUNC;
742#else
743# define setup_unzip_on_fd(...) (0)
744# define open_zipped(fname) open((fname), O_RDONLY);
745#endif
735extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 746extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
736 747
737extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; 748extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
@@ -982,6 +993,7 @@ enum {
982 DAEMON_DEVNULL_STDIO = 2, 993 DAEMON_DEVNULL_STDIO = 2,
983 DAEMON_CLOSE_EXTRA_FDS = 4, 994 DAEMON_CLOSE_EXTRA_FDS = 4,
984 DAEMON_ONLY_SANITIZE = 8, /* internal use */ 995 DAEMON_ONLY_SANITIZE = 8, /* internal use */
996 DAEMON_DOUBLE_FORK = 16, /* double fork to avoid controlling tty */
985}; 997};
986#if BB_MMU 998#if BB_MMU
987 enum { re_execed = 0 }; 999 enum { re_execed = 0 };
@@ -990,6 +1002,9 @@ enum {
990# define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) 1002# define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus)
991#else 1003#else
992 extern bool re_execed; 1004 extern bool re_execed;
1005 /* Note: re_exec() and fork_or_rexec() do argv[0][0] |= 0x80 on NOMMU!
1006 * _Parent_ needs to undo it if it doesn't want to have argv[0] mangled.
1007 */
993 void re_exec(char **argv) NORETURN FAST_FUNC; 1008 void re_exec(char **argv) NORETURN FAST_FUNC;
994 pid_t fork_or_rexec(char **argv) FAST_FUNC; 1009 pid_t fork_or_rexec(char **argv) FAST_FUNC;
995 int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC; 1010 int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC;
@@ -1197,13 +1212,14 @@ enum {
1197 PARSE_MIN_DIE = 0x00100000, // die if < min tokens found 1212 PARSE_MIN_DIE = 0x00100000, // die if < min tokens found
1198 // keep a copy of current line 1213 // keep a copy of current line
1199 PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D, 1214 PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D,
1200// PARSE_ESCAPE = 0x00400000, // process escape sequences in tokens 1215 PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char
1201 // NORMAL is: 1216 // NORMAL is:
1202 // * remove leading and trailing delimiters and collapse 1217 // * remove leading and trailing delimiters and collapse
1203 // multiple delimiters into one 1218 // multiple delimiters into one
1204 // * warn and continue if less than mintokens delimiters found 1219 // * warn and continue if less than mintokens delimiters found
1205 // * grab everything into last token 1220 // * grab everything into last token
1206 PARSE_NORMAL = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY, 1221 // * comments are recognized even if they aren't the first char
1222 PARSE_NORMAL = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY | PARSE_EOL_COMMENTS,
1207}; 1223};
1208typedef struct parser_t { 1224typedef struct parser_t {
1209 FILE *fp; 1225 FILE *fp;