Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/include/libbb.h
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/include/libbb.h
r3232 r3621 21 21 #include <setjmp.h> 22 22 #include <signal.h> 23 #include <paths.h> 23 24 #if defined __UCLIBC__ /* TODO: and glibc? */ 24 25 /* use inlined versions of these: */ … … 33 34 #include <stddef.h> 34 35 #include <string.h> 35 /* There are two incompatible basename's, let not use them! */36 /* There are two incompatible basename's, let's not use them! */ 36 37 /* See the dirname/basename man page for details */ 37 38 #include <libgen.h> /* dirname,basename */ 38 39 #undef basename 39 40 #define basename dont_use_basename 40 #include < sys/poll.h>41 #include <poll.h> 41 42 #include <sys/ioctl.h> 42 43 #include <sys/mman.h> … … 85 86 #endif 86 87 #if ENABLE_FEATURE_UTMP 87 # include <utmp.h> 88 # if defined __UCLIBC__ && ( \ 89 (UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 32) \ 90 && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 34) \ 91 && defined __UCLIBC_HAS_UTMPX__ \ 92 ) || ( \ 93 UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 34) \ 94 ) \ 95 ) 96 # include <utmpx.h> 97 # elif defined __UCLIBC__ 98 # include <utmp.h> 99 # define utmpx utmp 100 # define setutxent setutent 101 # define endutxent endutent 102 # define getutxent getutent 103 # define getutxid getutid 104 # define getutxline getutline 105 # define pututxline pututline 106 # define utmpxname utmpname 107 # define updwtmpx updwtmp 108 # define _PATH_UTMPX _PATH_UTMP 109 # else 110 # include <utmp.h> 111 # include <utmpx.h> 112 # if defined _PATH_UTMP && !defined _PATH_UTMPX 113 # define _PATH_UTMPX _PATH_UTMP 114 # endif 115 # endif 88 116 #endif 89 117 #if ENABLE_LOCALE_SUPPORT … … 115 143 #else 116 144 # include <arpa/inet.h> 117 # if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) 118 /* We #define socklen_t *after* includes, otherwise we get 119 * typedef redefinition errors from system headers 120 * (in case "is it defined already" detection above failed) 121 */ 122 # define socklen_t bb_socklen_t 123 typedef unsigned socklen_t; 124 # endif 145 //This breaks on bionic: 146 //# if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) 147 ///* We #define socklen_t *after* includes, otherwise we get 148 // * typedef redefinition errors from system headers 149 // * (in case "is it defined already" detection above failed) 150 // */ 151 //# define socklen_t bb_socklen_t 152 // typedef unsigned socklen_t; 153 //# endif 154 //if this is still needed, add a fix along the lines of 155 // ifdef SPECIFIC_BROKEN_LIBC_CHECK / typedef socklen_t / endif 156 //in platform.h instead! 125 157 #endif 126 158 #ifndef HAVE_CLEARENV … … 320 352 extern const char *bb_mode_string(mode_t mode) FAST_FUNC; 321 353 extern int is_directory(const char *name, int followLinks) FAST_FUNC; 322 enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them.*/354 enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */ 323 355 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */ 324 356 FILEUTILS_DEREFERENCE = 1 << 1, /* !-d */ … … 330 362 FILEUTILS_DEREF_SOFTLINK = 1 << 7, /* -L */ 331 363 FILEUTILS_DEREFERENCE_L0 = 1 << 8, /* -H */ 364 /* -a = -pdR (mapped in cp.c) */ 365 /* -r = -dR (mapped in cp.c) */ 366 /* -P = -d (mapped in cp.c) */ 367 FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */ 368 FILEUTILS_UPDATE = 1 << 13, /* -u */ 332 369 #if ENABLE_SELINUX 333 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 9, /* -c */ 334 FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10, 335 #endif 336 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11, 370 FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */ 371 #endif 372 FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */ 373 /* 374 * Hole. cp may have some bits set here, 375 * they should not affect remove_file()/copy_file() 376 */ 377 #if ENABLE_SELINUX 378 FILEUTILS_SET_SECURITY_CONTEXT = 1 << 30, 379 #endif 380 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31, 337 381 }; 338 #define FILEUTILS_CP_OPTSTR "pdRfilsLH " IF_SELINUX("c")382 #define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c") 339 383 extern int remove_file(const char *path, int flags) FAST_FUNC; 340 384 /* NB: without FILEUTILS_RECUR in flags, it will basically "cat" … … 387 431 /* NB: can violate const-ness (similarly to strchr) */ 388 432 char *last_char_is(const char *s, int c) FAST_FUNC; 389 390 void ndelay_on(int fd) FAST_FUNC; 391 void ndelay_off(int fd) FAST_FUNC; 433 const char* endofname(const char *name) FAST_FUNC; 434 char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; 435 char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; 436 437 int ndelay_on(int fd) FAST_FUNC; 438 int ndelay_off(int fd) FAST_FUNC; 392 439 void close_on_exec_on(int fd) FAST_FUNC; 393 440 void xdup2(int, int) FAST_FUNC; … … 461 508 void xsetgid(gid_t gid) FAST_FUNC; 462 509 void xsetuid(uid_t uid) FAST_FUNC; 510 void xsetegid(gid_t egid) FAST_FUNC; 511 void xseteuid(uid_t euid) FAST_FUNC; 463 512 void xchdir(const char *path) FAST_FUNC; 513 void xfchdir(int fd) FAST_FUNC; 464 514 void xchroot(const char *path) FAST_FUNC; 465 515 void xsetenv(const char *key, const char *value) FAST_FUNC; … … 469 519 void xstat(const char *pathname, struct stat *buf) FAST_FUNC; 470 520 void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC; 521 int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC; 522 int open_or_warn(const char *pathname, int flags) FAST_FUNC; 523 int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; 471 524 int xopen(const char *pathname, int flags) FAST_FUNC; 472 525 int xopen_nonblocking(const char *pathname) FAST_FUNC; 473 int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; 474 int open_or_warn(const char *pathname, int flags) FAST_FUNC; 475 int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC; 526 int xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) FAST_FUNC; 476 527 int open_or_warn_stdin(const char *pathname) FAST_FUNC; 477 528 int xopen_stdin(const char *pathname) FAST_FUNC; … … 483 534 484 535 uoff_t FAST_FUNC get_volume_size_in_bytes(int fd, 485 486 487 536 const char *override, 537 unsigned override_units, 538 int extend); 488 539 489 540 void xpipe(int filedes[2]) FAST_FUNC; … … 523 574 void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC; 524 575 time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC; 525 576 char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC; 577 char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC; 526 578 527 579 int xsocket(int domain, int type, int protocol) FAST_FUNC; … … 531 583 ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 532 584 socklen_t tolen) FAST_FUNC; 585 586 int setsockopt_int(int fd, int level, int optname, int optval) FAST_FUNC; 587 int setsockopt_1(int fd, int level, int optname) FAST_FUNC; 588 int setsockopt_SOL_SOCKET_int(int fd, int optname, int optval) FAST_FUNC; 589 int setsockopt_SOL_SOCKET_1(int fd, int optname) FAST_FUNC; 533 590 /* SO_REUSEADDR allows a server to rebind to an address that is already 534 591 * "in use" by old connections to e.g. previous server instance which is … … 538 595 * Turn it on before you call bind(). */ 539 596 void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */ 597 int setsockopt_keepalive(int fd) FAST_FUNC; 540 598 int setsockopt_broadcast(int fd) FAST_FUNC; 541 599 int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC; … … 643 701 char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; 644 702 char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC; 703 void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC; 645 704 void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; 646 705 char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; 647 706 char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; 707 unsigned count_strstr(const char *str, const char *sub) FAST_FUNC; 708 char *xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl) FAST_FUNC; 648 709 /* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc. 649 710 * But potentially slow, don't use in one-billion-times loops */ … … 652 713 int bb_putchar_stderr(char ch) FAST_FUNC; 653 714 char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC; 715 char *auto_string(char *str) FAST_FUNC; 654 716 // gcc-4.1.1 still isn't good enough at optimizing it 655 717 // (+200 bytes compared to macro) … … 677 739 enum { PRINTABLE_META = 0x100 }; 678 740 void fputc_printable(int ch, FILE *file) FAST_FUNC; 741 /* Return a string that is the printable representation of character ch. 742 * Buffer must hold at least four characters. */ 743 enum { 744 VISIBLE_ENDLINE = 1 << 0, 745 VISIBLE_SHOW_TABS = 1 << 1, 746 }; 747 void visible(unsigned ch, char *buf, int flags) FAST_FUNC; 679 748 680 749 /* dmalloc will redefine these to it's own implementation. It is safe … … 697 766 698 767 extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; 699 extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count , int loop_on_EINTR) FAST_FUNC;768 extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC; 700 769 // NB: will return short read on error, not -1, 701 770 // if some data was read before error occurred … … 716 785 extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 717 786 787 #if defined(ARG_MAX) && (ARG_MAX >= 60*1024 || !defined(_SC_ARG_MAX)) 788 /* Use _constant_ maximum if: defined && (big enough || no variable one exists) */ 789 # define bb_arg_max() ((unsigned)ARG_MAX) 790 #elif defined(_SC_ARG_MAX) 791 /* Else use variable one (a bit more expensive) */ 792 unsigned bb_arg_max(void) FAST_FUNC; 793 #else 794 /* If all else fails */ 795 # define bb_arg_max() ((unsigned)(32 * 1024)) 796 #endif 797 unsigned bb_clk_tck(void) FAST_FUNC; 798 718 799 #define SEAMLESS_COMPRESSION (0 \ 719 800 || ENABLE_FEATURE_SEAMLESS_XZ \ … … 725 806 #if SEAMLESS_COMPRESSION 726 807 /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ 727 extern int setup_unzip_on_fd(int fd, int fail_if_not_ detected) FAST_FUNC;808 extern int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; 728 809 /* Autodetects .gz etc */ 729 extern int open_zipped(const char *fname) FAST_FUNC; 810 extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; 811 extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 730 812 #else 731 813 # define setup_unzip_on_fd(...) (0) 732 # define open_zipped(fname )open((fname), O_RDONLY);733 # endif734 extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 814 # define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY); 815 # define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) 816 #endif 735 817 736 818 extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; … … 807 889 char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC; 808 890 /* Intelligent formatters of bignums */ 809 voidsmart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC;810 voidsmart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC;891 char *smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC; 892 char *smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC; 811 893 /* If block_size == 0, display size without fractional part, 812 894 * else display (size * block_size) with one decimal digit. … … 831 913 unsigned mult; 832 914 }; 915 extern const struct suffix_mult bkm_suffixes[]; 916 #define km_suffixes (bkm_suffixes + 1) 917 extern const struct suffix_mult cwbkMG_suffixes[]; 918 #define kMG_suffixes (cwbkMG_suffixes + 3) 919 833 920 #include "xatonum.h" 834 921 /* Specialized: */ … … 854 941 /* wrapper: allows string to contain numeric uid or gid */ 855 942 unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC; 856 /* from chpst. Does not die, returns 0 on failure */857 943 struct bb_uidgid_t { 858 944 uid_t uid; 859 945 gid_t gid; 860 946 }; 861 /* always sets uid and gid */862 int get_uidgid(struct bb_uidgid_t*, const char* , int numeric_ok) FAST_FUNC;863 /* always sets uid and gid , allows numeric; exits on failure */947 /* always sets uid and gid; returns 0 on failure */ 948 int get_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; 949 /* always sets uid and gid; exits on failure */ 864 950 void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; 865 951 /* chown-like handling of "user[:[group]" */ … … 890 976 void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); 891 977 void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); 978 void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid); 892 979 #else 893 980 # define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0) 894 981 # define update_utmp(pid, new_type, tty_name, username, hostname) ((void)0) 895 #endif 896 897 898 int execable_file(const char *name) FAST_FUNC; 899 char *find_execable(const char *filename, char **PATHp) FAST_FUNC; 900 int exists_execable(const char *filename) FAST_FUNC; 982 # define update_utmp_DEAD_PROCESS(pid) ((void)0) 983 #endif 984 985 986 int file_is_executable(const char *name) FAST_FUNC; 987 char *find_executable(const char *filename, char **PATHp) FAST_FUNC; 988 int executable_exists(const char *filename) FAST_FUNC; 901 989 902 990 /* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff), … … 915 1003 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__) 916 1004 #endif 917 int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; 918 919 /* xvfork() can't be a _function_, return after vfork mangles stack 1005 void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; 1006 void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC; 1007 1008 /* xvfork() can't be a _function_, return after vfork in child mangles stack 920 1009 * in the parent. It must be a macro. */ 921 1010 #define xvfork() \ … … 929 1018 pid_t xfork(void) FAST_FUNC; 930 1019 #endif 1020 void xvfork_parent_waits_and_exits(void) FAST_FUNC; 931 1021 932 1022 /* NOMMU friendy fork+exec: */ … … 945 1035 */ 946 1036 int wait4pid(pid_t pid) FAST_FUNC; 1037 int wait_for_exitstatus(pid_t pid) FAST_FUNC; 947 1038 /* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */ 948 1039 int spawn_and_wait(char **argv) FAST_FUNC; … … 1058 1149 }; 1059 1150 extern const char *msg_eol; 1151 extern smallint syslog_level; 1060 1152 extern smallint logmode; 1061 extern int die_sleep;1062 1153 extern uint8_t xfunc_error_retval; 1063 extern jmp_buf die_jmp;1154 extern void (*die_func)(void); 1064 1155 extern void xfunc_die(void) NORETURN FAST_FUNC; 1065 1156 extern void bb_show_usage(void) NORETURN FAST_FUNC; … … 1074 1165 extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; 1075 1166 extern void bb_perror_nomsg(void) FAST_FUNC; 1076 extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;1077 1167 extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC; 1168 extern void bb_logenv_override(void) FAST_FUNC; 1078 1169 1079 1170 /* We need to export XXX_main from libbusybox … … 1108 1199 1109 1200 /* Networking */ 1110 int create_icmp_socket(void) FAST_FUNC;1111 int create_icmp6_socket(void) FAST_FUNC;1112 /* interface.c */1113 1201 /* This structure defines protocol families and their handlers. */ 1114 1202 struct aftype { … … 1139 1227 extern smallint interface_opt_a; 1140 1228 int display_interfaces(char *ifname) FAST_FUNC; 1229 int in_ether(const char *bufp, struct sockaddr *sap) FAST_FUNC; 1141 1230 #if ENABLE_FEATURE_HWIB 1142 1231 int in_ib(const char *bufp, struct sockaddr *sap) FAST_FUNC; … … 1151 1240 #ifndef BUILD_INDIVIDUAL 1152 1241 extern int find_applet_by_name(const char *name) FAST_FUNC; 1153 /* Returns only if applet is not found. */1154 extern void run_applet_and_exit(const char *name, char **argv) FAST_FUNC;1155 1242 extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; 1156 1243 #endif … … 1184 1271 int bb_ask_confirmation(void) FAST_FUNC; 1185 1272 1186 int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC; 1273 /* Returns -1 if input is invalid. current_mode is a base for e.g. "u+rw" */ 1274 int bb_parse_mode(const char* s, unsigned cur_mode) FAST_FUNC; 1187 1275 1188 1276 /* … … 1240 1328 char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; 1241 1329 1330 #ifndef LOGIN_FAIL_DELAY 1242 1331 #define LOGIN_FAIL_DELAY 3 1332 #endif 1243 1333 extern void bb_do_delay(int seconds) FAST_FUNC; 1244 1334 extern void change_identity(const struct passwd *pw) FAST_FUNC; … … 1262 1352 #endif 1263 1353 extern void selinux_or_die(void) FAST_FUNC; 1264 1265 1266 /* systemd support */1267 #define SD_LISTEN_FDS_START 31268 int sd_listen_fds(void);1269 1354 1270 1355 … … 1288 1373 #define SETUP_ENV_TO_TMP (1 << 2) 1289 1374 #define SETUP_ENV_NO_CHDIR (1 << 4) 1290 extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1291 extern int correct_password(const struct passwd *pw) FAST_FUNC; 1375 void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1376 void nuke_str(char *str) FAST_FUNC; 1377 int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC; 1378 int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; 1379 int ask_and_check_password(const struct passwd *pw) FAST_FUNC; 1292 1380 /* Returns a malloced string */ 1293 1381 #if !ENABLE_USE_BB_CRYPT … … 1332 1420 /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ 1333 1421 int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC; 1422 int get_terminal_width(int fd) FAST_FUNC; 1334 1423 1335 1424 int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC; … … 1435 1524 # if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0 1436 1525 # define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) 1437 unsigned size_from_HISTFILESIZE(const char *hp) ;1526 unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; 1438 1527 # else 1439 1528 # define MAX_HISTORY 0 … … 1477 1566 */ 1478 1567 int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC; 1568 void show_history(const line_input_t *st) FAST_FUNC; 1479 1569 # if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT 1480 1570 void save_history(line_input_t *st); … … 1689 1779 uoff_t totalsize) FAST_FUNC; 1690 1780 1781 unsigned ubi_devnum_from_devname(const char *str) FAST_FUNC; 1782 int ubi_get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC; 1783 1691 1784 1692 1785 extern const char *applet_name; … … 1712 1805 extern const char bb_msg_you_must_be_root[] ALIGN1; 1713 1806 extern const char bb_msg_requires_arg[] ALIGN1; 1714 extern const char bb_msg_invalid_arg [] ALIGN1;1807 extern const char bb_msg_invalid_arg_to[] ALIGN1; 1715 1808 extern const char bb_msg_standard_input[] ALIGN1; 1716 1809 extern const char bb_msg_standard_output[] ALIGN1; … … 1741 1834 1742 1835 extern const int const_int_0; 1743 extern const int const_int_1; 1744 1745 1746 /* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */ 1747 enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) }; 1748 extern char bb_common_bufsiz1[COMMON_BUFSIZE]; 1836 //extern const int const_int_1; 1837 1749 1838 /* This struct is deliberately not defined. */ 1750 1839 /* See docs/keep_data_small.txt */ … … 1759 1848 (*(struct globals**)&ptr_to_globals) = (void*)(x); \ 1760 1849 barrier(); \ 1850 } while (0) 1851 #define FREE_PTR_TO_GLOBALS() do { \ 1852 if (ENABLE_FEATURE_CLEAN_UP) { \ 1853 free(ptr_to_globals); \ 1854 } \ 1761 1855 } while (0) 1762 1856 … … 1801 1895 # define VC_5 "/dev/vc/5" 1802 1896 # define VC_FORMAT "/dev/vc/%d" 1803 # define LOOP_FORMAT "/dev/loop/% d"1897 # define LOOP_FORMAT "/dev/loop/%u" 1804 1898 # define LOOP_NAMESIZE (sizeof("/dev/loop/") + sizeof(int)*3 + 1) 1805 1899 # define LOOP_NAME "/dev/loop/" … … 1814 1908 # define VC_5 "/dev/tty5" 1815 1909 # define VC_FORMAT "/dev/tty%d" 1816 # define LOOP_FORMAT "/dev/loop% d"1910 # define LOOP_FORMAT "/dev/loop%u" 1817 1911 # define LOOP_NAMESIZE (sizeof("/dev/loop") + sizeof(int)*3 + 1) 1818 1912 # define LOOP_NAME "/dev/loop" … … 1822 1916 1823 1917 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) 1918 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 1824 1919 1825 1920 … … 1907 2002 1908 2003 2004 /* Simple unit-testing framework */ 2005 2006 typedef void (*bbunit_testfunc)(void); 2007 2008 struct bbunit_listelem { 2009 const char* name; 2010 bbunit_testfunc testfunc; 2011 }; 2012 2013 void bbunit_registertest(struct bbunit_listelem* test); 2014 void bbunit_settestfailed(void); 2015 2016 #define BBUNIT_DEFINE_TEST(NAME) \ 2017 static void bbunit_##NAME##_test(void); \ 2018 static struct bbunit_listelem bbunit_##NAME##_elem = { \ 2019 .name = #NAME, \ 2020 .testfunc = bbunit_##NAME##_test, \ 2021 }; \ 2022 static void INIT_FUNC bbunit_##NAME##_register(void) \ 2023 { \ 2024 bbunit_registertest(&bbunit_##NAME##_elem); \ 2025 } \ 2026 static void bbunit_##NAME##_test(void) 2027 2028 /* 2029 * Both 'goto bbunit_end' and 'break' are here only to get rid 2030 * of compiler warnings. 2031 */ 2032 #define BBUNIT_ENDTEST \ 2033 do { \ 2034 goto bbunit_end; \ 2035 bbunit_end: \ 2036 break; \ 2037 } while (0) 2038 2039 #define BBUNIT_PRINTASSERTFAIL \ 2040 do { \ 2041 bb_error_msg( \ 2042 "[ERROR] Assertion failed in file %s, line %d", \ 2043 __FILE__, __LINE__); \ 2044 } while (0) 2045 2046 #define BBUNIT_ASSERTION_FAILED \ 2047 do { \ 2048 bbunit_settestfailed(); \ 2049 goto bbunit_end; \ 2050 } while (0) 2051 2052 /* 2053 * Assertions. 2054 * For now we only offer assertions which cause tests to fail 2055 * immediately. In the future 'expects' might be added too - 2056 * similar to those offered by the gtest framework. 2057 */ 2058 #define BBUNIT_ASSERT_EQ(EXPECTED, ACTUAL) \ 2059 do { \ 2060 if ((EXPECTED) != (ACTUAL)) { \ 2061 BBUNIT_PRINTASSERTFAIL; \ 2062 bb_error_msg("[ERROR] '%s' isn't equal to '%s'", \ 2063 #EXPECTED, #ACTUAL); \ 2064 BBUNIT_ASSERTION_FAILED; \ 2065 } \ 2066 } while (0) 2067 2068 #define BBUNIT_ASSERT_NOTEQ(EXPECTED, ACTUAL) \ 2069 do { \ 2070 if ((EXPECTED) == (ACTUAL)) { \ 2071 BBUNIT_PRINTASSERTFAIL; \ 2072 bb_error_msg("[ERROR] '%s' is equal to '%s'", \ 2073 #EXPECTED, #ACTUAL); \ 2074 BBUNIT_ASSERTION_FAILED; \ 2075 } \ 2076 } while (0) 2077 2078 #define BBUNIT_ASSERT_NOTNULL(PTR) \ 2079 do { \ 2080 if ((PTR) == NULL) { \ 2081 BBUNIT_PRINTASSERTFAIL; \ 2082 bb_error_msg("[ERROR] '%s' is NULL!", #PTR); \ 2083 BBUNIT_ASSERTION_FAILED; \ 2084 } \ 2085 } while (0) 2086 2087 #define BBUNIT_ASSERT_NULL(PTR) \ 2088 do { \ 2089 if ((PTR) != NULL) { \ 2090 BBUNIT_PRINTASSERTFAIL; \ 2091 bb_error_msg("[ERROR] '%s' is not NULL!", #PTR); \ 2092 BBUNIT_ASSERTION_FAILED; \ 2093 } \ 2094 } while (0) 2095 2096 #define BBUNIT_ASSERT_FALSE(STATEMENT) \ 2097 do { \ 2098 if ((STATEMENT)) { \ 2099 BBUNIT_PRINTASSERTFAIL; \ 2100 bb_error_msg("[ERROR] Statement '%s' evaluated to true!", \ 2101 #STATEMENT); \ 2102 BBUNIT_ASSERTION_FAILED; \ 2103 } \ 2104 } while (0) 2105 2106 #define BBUNIT_ASSERT_TRUE(STATEMENT) \ 2107 do { \ 2108 if (!(STATEMENT)) { \ 2109 BBUNIT_PRINTASSERTFAIL; \ 2110 bb_error_msg("[ERROR] Statement '%s' evaluated to false!", \ 2111 #STATEMENT); \ 2112 BBUNIT_ASSERTION_FAILED; \ 2113 } \ 2114 } while (0) 2115 2116 #define BBUNIT_ASSERT_STREQ(STR1, STR2) \ 2117 do { \ 2118 if (strcmp(STR1, STR2) != 0) { \ 2119 BBUNIT_PRINTASSERTFAIL; \ 2120 bb_error_msg("[ERROR] Strings '%s' and '%s' " \ 2121 "are not the same", STR1, STR2); \ 2122 BBUNIT_ASSERTION_FAILED; \ 2123 } \ 2124 } while (0) 2125 2126 #define BBUNIT_ASSERT_STRNOTEQ(STR1, STR2) \ 2127 do { \ 2128 if (strcmp(STR1, STR2) == 0) { \ 2129 BBUNIT_PRINTASSERTFAIL; \ 2130 bb_error_msg("[ERROR] Strings '%s' and '%s' " \ 2131 "are the same, but were " \ 2132 "expected to differ", STR1, STR2); \ 2133 BBUNIT_ASSERTION_FAILED; \ 2134 } \ 2135 } while (0) 2136 2137 1909 2138 POP_SAVED_FUNCTION_VISIBILITY 1910 2139
Note:
See TracChangeset
for help on using the changeset viewer.