diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 69 |
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)) |
286 | extern void sig_block(int); | 286 | extern void sig_block(int); |
287 | extern void sig_unblock(int); | 287 | extern void sig_unblock(int); |
288 | /* UNUSED: extern void sig_blocknone(void);*/ | 288 | /* UNUSED: extern void sig_blocknone(void); */ |
289 | extern void sig_pause(void); | 289 | extern 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 | |||
298 | void xsetgid(gid_t gid); | 297 | void xsetgid(gid_t gid); |
299 | void xsetuid(uid_t uid); | 298 | void xsetuid(uid_t uid); |
300 | void xchdir(const char *path); | 299 | void 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 */ |
347 | int create_and_bind_stream_or_die(const char *bindaddr, int port); | 346 | int create_and_bind_stream_or_die(const char *bindaddr, int port); |
348 | int create_and_bind_dgram_or_die(const char *bindaddr, int port); | 347 | int 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); | |||
456 | extern FILE *fopen_or_warn_stdin(const char *filename); | 455 | extern FILE *fopen_or_warn_stdin(const char *filename); |
457 | 456 | ||
458 | 457 | ||
459 | extern char *utoa(unsigned n); | 458 | char *utoa(unsigned n); |
460 | extern char *itoa(int n); | 459 | char *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 */ |
462 | extern char *utoa_to_buf(unsigned n, char *buf, unsigned buflen); | 461 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen); |
463 | extern char *itoa_to_buf(int n, char *buf, unsigned buflen); | 462 | char *itoa_to_buf(int n, char *buf, unsigned buflen); |
464 | extern void smart_ulltoa5(unsigned long long ul, char buf[5]); | 463 | void 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)? |
466 | extern char *bin2hex(char *buf, const char *cp, int count); | 465 | const 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 */ | ||
468 | char *bin2hex(char *buf, const char *cp, int count); | ||
467 | 469 | ||
468 | struct suffix_mult { | 470 | struct suffix_mult { |
469 | const char *suffix; | 471 | const char *suffix; |
@@ -580,16 +582,20 @@ extern uint32_t option_mask32; | |||
580 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); | 582 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); |
581 | 583 | ||
582 | 584 | ||
583 | typedef struct llist_s { | 585 | typedef 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; |
587 | extern void llist_add_to(llist_t **old_head, void *data); | 589 | void llist_add_to(llist_t **old_head, void *data); |
588 | extern void llist_add_to_end(llist_t **list_head, void *data); | 590 | void llist_add_to_end(llist_t **list_head, void *data); |
589 | extern void *llist_pop(llist_t **elm); | 591 | void *llist_pop(llist_t **elm); |
590 | extern void llist_unlink(llist_t **head, llist_t *elm); | 592 | void llist_unlink(llist_t **head, llist_t *elm); |
591 | extern void llist_free(llist_t *elm, void (*freeit)(void *data)); | 593 | void llist_free(llist_t *elm, void (*freeit)(void *data)); |
592 | extern llist_t* llist_rev(llist_t *list); | 594 | llist_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 |
595 | int write_pidfile(const char *path); | 601 | int write_pidfile(const char *path); |
@@ -674,10 +680,6 @@ extern int del_loop(const char *device); | |||
674 | extern int set_loop(char **device, const char *file, unsigned long long offset); | 680 | extern int set_loop(char **device, const char *file, unsigned long long offset); |
675 | 681 | ||
676 | 682 | ||
677 | //TODO: provide pointer to buf (avoid statics)? | ||
678 | const 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)? |
682 | char *bb_askpass(int timeout, const char * prompt); | 684 | char *bb_askpass(int timeout, const char * prompt); |
683 | int bb_ask_confirmation(void); | 685 | int bb_ask_confirmation(void); |
@@ -725,14 +727,14 @@ extern void print_login_issue(const char *issue_file, const char *tty); | |||
725 | extern void print_login_prompt(void); | 727 | extern void print_login_prompt(void); |
726 | 728 | ||
727 | 729 | ||
728 | extern int get_terminal_width_height(const int fd, int *width, int *height); | 730 | int get_terminal_width_height(const int fd, int *width, int *height); |
729 | 731 | ||
730 | char *is_in_ino_dev_hashtable(const struct stat *statbuf); | 732 | char *is_in_ino_dev_hashtable(const struct stat *statbuf); |
731 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); | 733 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); |
732 | void reset_ino_dev_hashtable(void); | 734 | void 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 */ |
735 | extern unsigned long long bb_makedev(unsigned int major, unsigned int minor); | 737 | unsigned 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 |
748 | struct line_input_t { | 750 | typedef 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; |
758 | enum { | 760 | enum { |
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 | }; |
767 | typedef struct line_input_t line_input_t; | ||
768 | line_input_t *new_line_input_t(int flags); | 769 | line_input_t *new_line_input_t(int flags); |
769 | int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state); | 770 | int 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; |
803 | enum { | 804 | enum { |
804 | PSSCAN_PID = 1 << 0, | 805 | PSSCAN_PID = 1 << 0, |
@@ -902,18 +903,22 @@ extern const char bb_dev_null[]; | |||
902 | extern const int const_int_0; | 903 | extern const int const_int_0; |
903 | extern const int const_int_1; | 904 | extern 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 | ||
908 | extern char bb_common_bufsiz1[BUFSIZ+1]; | 911 | extern 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 */ |
911 | struct globals; | 914 | struct 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 */ | ||
914 | extern struct globals *const ptr_to_globals; | 918 | extern 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, |