aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h69
1 files changed, 37 insertions, 32 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6956aaf7b..6731adfe3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -285,7 +285,7 @@ extern void sig_catch(int,void (*)(int));
285//#define sig_uncatch(s) (sig_catch((s), SIG_DFL)) 285//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
286extern void sig_block(int); 286extern void sig_block(int);
287extern void sig_unblock(int); 287extern void sig_unblock(int);
288/* UNUSED: extern void sig_blocknone(void);*/ 288/* UNUSED: extern void sig_blocknone(void); */
289extern void sig_pause(void); 289extern void sig_pause(void);
290 290
291#define wait_crashed(w) ((w) & 127) 291#define wait_crashed(w) ((w) & 127)
@@ -294,7 +294,6 @@ extern void sig_pause(void);
294#define wait_stopped(w) (((w) & 127) == 127) 294#define wait_stopped(w) (((w) & 127) == 127)
295 295
296 296
297
298void xsetgid(gid_t gid); 297void xsetgid(gid_t gid);
299void xsetuid(uid_t uid); 298void xsetuid(uid_t uid);
300void xchdir(const char *path); 299void xchdir(const char *path);
@@ -343,7 +342,7 @@ int xsocket_stream(len_and_sockaddr **lsap);
343/* Create server socket bound to bindaddr:port. bindaddr can be NULL, 342/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
344 * numeric IP ("N.N.N.N") or numeric IPv6 address, 343 * numeric IP ("N.N.N.N") or numeric IPv6 address,
345 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT"). 344 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
346 * If there is no suffix, port argument is used */ 345 * Only if there is no suffix, port argument is used */
347int create_and_bind_stream_or_die(const char *bindaddr, int port); 346int create_and_bind_stream_or_die(const char *bindaddr, int port);
348int create_and_bind_dgram_or_die(const char *bindaddr, int port); 347int create_and_bind_dgram_or_die(const char *bindaddr, int port);
349/* Create client TCP socket connected to peer:port. Peer cannot be NULL. 348/* Create client TCP socket connected to peer:port. Peer cannot be NULL.
@@ -412,9 +411,9 @@ extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf,
412//int LONE_DASH(const char *s) { return s[0] == '-' && !s[1]; } 411//int LONE_DASH(const char *s) { return s[0] == '-' && !s[1]; }
413//static ATTRIBUTE_ALWAYS_INLINE 412//static ATTRIBUTE_ALWAYS_INLINE
414//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; } 413//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; }
415#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1]) 414#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1])
416#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) 415#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
417#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) 416#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
418#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1]) 417#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1])
419 418
420/* dmalloc will redefine these to it's own implementation. It is safe 419/* dmalloc will redefine these to it's own implementation. It is safe
@@ -456,14 +455,17 @@ extern FILE *fopen_or_warn(const char *filename, const char *mode);
456extern FILE *fopen_or_warn_stdin(const char *filename); 455extern FILE *fopen_or_warn_stdin(const char *filename);
457 456
458 457
459extern char *utoa(unsigned n); 458char *utoa(unsigned n);
460extern char *itoa(int n); 459char *itoa(int n);
461/* Returns a pointer past the formatted number, does NOT null-terminate */ 460/* Returns a pointer past the formatted number, does NOT null-terminate */
462extern char *utoa_to_buf(unsigned n, char *buf, unsigned buflen); 461char *utoa_to_buf(unsigned n, char *buf, unsigned buflen);
463extern char *itoa_to_buf(int n, char *buf, unsigned buflen); 462char *itoa_to_buf(int n, char *buf, unsigned buflen);
464extern void smart_ulltoa5(unsigned long long ul, char buf[5]); 463void smart_ulltoa5(unsigned long long ul, char buf[5]);
465/* Put a string of hex bytes (ala "1b"), return advanced pointer */ 464//TODO: provide pointer to buf (avoid statics)?
466extern char *bin2hex(char *buf, const char *cp, int count); 465const char *make_human_readable_str(unsigned long long size,
466 unsigned long block_size, unsigned long display_unit);
467/* Put a string of hex bytes ("1b2e66fe"...), return advanced pointer */
468char *bin2hex(char *buf, const char *cp, int count);
467 469
468struct suffix_mult { 470struct suffix_mult {
469 const char *suffix; 471 const char *suffix;
@@ -580,16 +582,20 @@ extern uint32_t option_mask32;
580extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); 582extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
581 583
582 584
583typedef struct llist_s { 585typedef struct llist_t {
584 char *data; 586 char *data;
585 struct llist_s *link; 587 struct llist_t *link;
586} llist_t; 588} llist_t;
587extern void llist_add_to(llist_t **old_head, void *data); 589void llist_add_to(llist_t **old_head, void *data);
588extern void llist_add_to_end(llist_t **list_head, void *data); 590void llist_add_to_end(llist_t **list_head, void *data);
589extern void *llist_pop(llist_t **elm); 591void *llist_pop(llist_t **elm);
590extern void llist_unlink(llist_t **head, llist_t *elm); 592void llist_unlink(llist_t **head, llist_t *elm);
591extern void llist_free(llist_t *elm, void (*freeit)(void *data)); 593void llist_free(llist_t *elm, void (*freeit)(void *data));
592extern llist_t* llist_rev(llist_t *list); 594llist_t *llist_rev(llist_t *list);
595/* BTW, surprisingly, changing API to
596 * llist_t *llist_add_to(llist_t *old_head, void *data)
597 * etc does not result in smaller code... */
598
593 599
594#if ENABLE_FEATURE_PIDFILE 600#if ENABLE_FEATURE_PIDFILE
595int write_pidfile(const char *path); 601int write_pidfile(const char *path);
@@ -674,10 +680,6 @@ extern int del_loop(const char *device);
674extern int set_loop(char **device, const char *file, unsigned long long offset); 680extern int set_loop(char **device, const char *file, unsigned long long offset);
675 681
676 682
677//TODO: provide pointer to buf (avoid statics)?
678const char *make_human_readable_str(unsigned long long size,
679 unsigned long block_size, unsigned long display_unit);
680
681//TODO: pass buf pointer or return allocated buf (avoid statics)? 683//TODO: pass buf pointer or return allocated buf (avoid statics)?
682char *bb_askpass(int timeout, const char * prompt); 684char *bb_askpass(int timeout, const char * prompt);
683int bb_ask_confirmation(void); 685int bb_ask_confirmation(void);
@@ -725,14 +727,14 @@ extern void print_login_issue(const char *issue_file, const char *tty);
725extern void print_login_prompt(void); 727extern void print_login_prompt(void);
726 728
727 729
728extern int get_terminal_width_height(const int fd, int *width, int *height); 730int get_terminal_width_height(const int fd, int *width, int *height);
729 731
730char *is_in_ino_dev_hashtable(const struct stat *statbuf); 732char *is_in_ino_dev_hashtable(const struct stat *statbuf);
731void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); 733void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
732void reset_ino_dev_hashtable(void); 734void reset_ino_dev_hashtable(void);
733#ifdef __GLIBC__ 735#ifdef __GLIBC__
734/* At least glibc has horrendously large inline for this, so wrap it */ 736/* At least glibc has horrendously large inline for this, so wrap it */
735extern unsigned long long bb_makedev(unsigned int major, unsigned int minor); 737unsigned long long bb_makedev(unsigned int major, unsigned int minor);
736#undef makedev 738#undef makedev
737#define makedev(a,b) bb_makedev(a,b) 739#define makedev(a,b) bb_makedev(a,b)
738#endif 740#endif
@@ -745,7 +747,7 @@ extern unsigned long long bb_makedev(unsigned int major, unsigned int minor);
745#else 747#else
746#define MAX_HISTORY 0 748#define MAX_HISTORY 0
747#endif 749#endif
748struct line_input_t { 750typedef struct line_input_t {
749 int flags; 751 int flags;
750 const char *path_lookup; 752 const char *path_lookup;
751#if MAX_HISTORY 753#if MAX_HISTORY
@@ -754,7 +756,7 @@ struct line_input_t {
754 USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;) 756 USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;)
755 char *history[MAX_HISTORY + 1]; 757 char *history[MAX_HISTORY + 1];
756#endif 758#endif
757}; 759} line_input_t;
758enum { 760enum {
759 DO_HISTORY = 1 * (MAX_HISTORY > 0), 761 DO_HISTORY = 1 * (MAX_HISTORY > 0),
760 SAVE_HISTORY = 2 * (MAX_HISTORY > 0) * ENABLE_FEATURE_EDITING_SAVEHISTORY, 762 SAVE_HISTORY = 2 * (MAX_HISTORY > 0) * ENABLE_FEATURE_EDITING_SAVEHISTORY,
@@ -764,7 +766,6 @@ enum {
764 WITH_PATH_LOOKUP = 0x20, 766 WITH_PATH_LOOKUP = 0x20,
765 FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION, 767 FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
766}; 768};
767typedef struct line_input_t line_input_t;
768line_input_t *new_line_input_t(int flags); 769line_input_t *new_line_input_t(int flags);
769int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state); 770int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state);
770#else 771#else
@@ -798,7 +799,7 @@ typedef struct {
798 /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */ 799 /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */
799 char state[4]; 800 char state[4];
800 char comm[COMM_LEN]; 801 char comm[COMM_LEN];
801// user/group? - use passwd/group parsing functions 802 /* user/group? - use passwd/group parsing functions */
802} procps_status_t; 803} procps_status_t;
803enum { 804enum {
804 PSSCAN_PID = 1 << 0, 805 PSSCAN_PID = 1 << 0,
@@ -902,18 +903,22 @@ extern const char bb_dev_null[];
902extern const int const_int_0; 903extern const int const_int_0;
903extern const int const_int_1; 904extern const int const_int_1;
904 905
906
905#ifndef BUFSIZ 907#ifndef BUFSIZ
906#define BUFSIZ 4096 908#define BUFSIZ 4096
907#endif 909#endif
910// TODO: provide hard guarantees on minimum size of bb_common_bufsiz1
908extern char bb_common_bufsiz1[BUFSIZ+1]; 911extern char bb_common_bufsiz1[BUFSIZ+1];
909/* This struct is deliberately not defined. */ 912/* This struct is deliberately not defined. */
910/* See docs/keep_data_small.txt */ 913/* See docs/keep_data_small.txt */
911struct globals; 914struct globals;
912/* Magic prevents this from going into rodata */ 915/* '*const' ptr makes gcc optimize code much better.
913/* If you want to assign a value, use PTR_TO_GLOBALS = xxx */ 916 * Magic prevents ptr_to_globals from going into rodata
917 * If you want to assign a value, use PTR_TO_GLOBALS = xxx */
914extern struct globals *const ptr_to_globals; 918extern struct globals *const ptr_to_globals;
915#define PTR_TO_GLOBALS (*(struct globals**)&ptr_to_globals) 919#define PTR_TO_GLOBALS (*(struct globals**)&ptr_to_globals)
916 920
921
917/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, 922/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
918 * use bb_default_login_shell and following defines. 923 * use bb_default_login_shell and following defines.
919 * If you change LIBBB_DEFAULT_LOGIN_SHELL, 924 * If you change LIBBB_DEFAULT_LOGIN_SHELL,