Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/include/libbb.h


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/include/libbb.h

    r3232 r3621  
    2121#include <setjmp.h>
    2222#include <signal.h>
     23#include <paths.h>
    2324#if defined __UCLIBC__ /* TODO: and glibc? */
    2425/* use inlined versions of these: */
     
    3334#include <stddef.h>
    3435#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! */
    3637/* See the dirname/basename man page for details */
    3738#include <libgen.h> /* dirname,basename */
    3839#undef basename
    3940#define basename dont_use_basename
    40 #include <sys/poll.h>
     41#include <poll.h>
    4142#include <sys/ioctl.h>
    4243#include <sys/mman.h>
     
    8586#endif
    8687#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
    88116#endif
    89117#if ENABLE_LOCALE_SUPPORT
     
    115143#else
    116144# 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!
    125157#endif
    126158#ifndef HAVE_CLEARENV
     
    320352extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
    321353extern 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. */
     354enum {  /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */
    323355    FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */
    324356    FILEUTILS_DEREFERENCE     = 1 << 1, /* !-d */
     
    330362    FILEUTILS_DEREF_SOFTLINK  = 1 << 7, /* -L */
    331363    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 */
    332369#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,
    337381};
    338 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
     382#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c")
    339383extern int remove_file(const char *path, int flags) FAST_FUNC;
    340384/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
     
    387431/* NB: can violate const-ness (similarly to strchr) */
    388432char *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;
     433const char* endofname(const char *name) FAST_FUNC;
     434char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
     435char *is_suffixed_with(const char *string, const char *key) FAST_FUNC;
     436
     437int ndelay_on(int fd) FAST_FUNC;
     438int ndelay_off(int fd) FAST_FUNC;
    392439void close_on_exec_on(int fd) FAST_FUNC;
    393440void xdup2(int, int) FAST_FUNC;
     
    461508void xsetgid(gid_t gid) FAST_FUNC;
    462509void xsetuid(uid_t uid) FAST_FUNC;
     510void xsetegid(gid_t egid) FAST_FUNC;
     511void xseteuid(uid_t euid) FAST_FUNC;
    463512void xchdir(const char *path) FAST_FUNC;
     513void xfchdir(int fd) FAST_FUNC;
    464514void xchroot(const char *path) FAST_FUNC;
    465515void xsetenv(const char *key, const char *value) FAST_FUNC;
     
    469519void xstat(const char *pathname, struct stat *buf) FAST_FUNC;
    470520void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC;
     521int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC;
     522int open_or_warn(const char *pathname, int flags) FAST_FUNC;
     523int xopen3(const char *pathname, int flags, int mode) FAST_FUNC;
    471524int xopen(const char *pathname, int flags) FAST_FUNC;
    472525int 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;
     526int xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) FAST_FUNC;
    476527int open_or_warn_stdin(const char *pathname) FAST_FUNC;
    477528int xopen_stdin(const char *pathname) FAST_FUNC;
     
    483534
    484535uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
    485                 const char *override,
    486                 unsigned override_units,
    487                 int extend);
     536        const char *override,
     537        unsigned override_units,
     538        int extend);
    488539
    489540void xpipe(int filedes[2]) FAST_FUNC;
     
    523574void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC;
    524575time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC;
    525 
     576char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
     577char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
    526578
    527579int xsocket(int domain, int type, int protocol) FAST_FUNC;
     
    531583ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
    532584                socklen_t tolen) FAST_FUNC;
     585
     586int setsockopt_int(int fd, int level, int optname, int optval) FAST_FUNC;
     587int setsockopt_1(int fd, int level, int optname) FAST_FUNC;
     588int setsockopt_SOL_SOCKET_int(int fd, int optname, int optval) FAST_FUNC;
     589int setsockopt_SOL_SOCKET_1(int fd, int optname) FAST_FUNC;
    533590/* SO_REUSEADDR allows a server to rebind to an address that is already
    534591 * "in use" by old connections to e.g. previous server instance which is
     
    538595 * Turn it on before you call bind(). */
    539596void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */
     597int setsockopt_keepalive(int fd) FAST_FUNC;
    540598int setsockopt_broadcast(int fd) FAST_FUNC;
    541599int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC;
     
    643701char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
    644702char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
     703void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
    645704void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
    646705char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
    647706char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
     707unsigned count_strstr(const char *str, const char *sub) FAST_FUNC;
     708char *xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl) FAST_FUNC;
    648709/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
    649710 * But potentially slow, don't use in one-billion-times loops */
     
    652713int bb_putchar_stderr(char ch) FAST_FUNC;
    653714char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC;
     715char *auto_string(char *str) FAST_FUNC;
    654716// gcc-4.1.1 still isn't good enough at optimizing it
    655717// (+200 bytes compared to macro)
     
    677739enum { PRINTABLE_META = 0x100 };
    678740void 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. */
     743enum {
     744    VISIBLE_ENDLINE   = 1 << 0,
     745    VISIBLE_SHOW_TABS = 1 << 1,
     746};
     747void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
    679748
    680749/* dmalloc will redefine these to it's own implementation. It is safe
     
    697766
    698767extern 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;
     768extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
    700769// NB: will return short read on error, not -1,
    701770// if some data was read before error occurred
     
    716785extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    717786
     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) */
     792unsigned bb_arg_max(void) FAST_FUNC;
     793#else
     794/* If all else fails */
     795# define bb_arg_max() ((unsigned)(32 * 1024))
     796#endif
     797unsigned bb_clk_tck(void) FAST_FUNC;
     798
    718799#define SEAMLESS_COMPRESSION (0 \
    719800 || ENABLE_FEATURE_SEAMLESS_XZ \
     
    725806#if SEAMLESS_COMPRESSION
    726807/* 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;
     808extern int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC;
    728809/* Autodetects .gz etc */
    729 extern int open_zipped(const char *fname) FAST_FUNC;
     810extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC;
     811extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    730812#else
    731813# define setup_unzip_on_fd(...) (0)
    732 # define open_zipped(fname)     open((fname), O_RDONLY);
    733 #endif
    734 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
    735817
    736818extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
     
    807889char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC;
    808890/* Intelligent formatters of bignums */
    809 void smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC;
    810 void smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC;
     891char *smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC;
     892char *smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC;
    811893/* If block_size == 0, display size without fractional part,
    812894 * else display (size * block_size) with one decimal digit.
     
    831913    unsigned mult;
    832914};
     915extern const struct suffix_mult bkm_suffixes[];
     916#define km_suffixes (bkm_suffixes + 1)
     917extern const struct suffix_mult cwbkMG_suffixes[];
     918#define kMG_suffixes (cwbkMG_suffixes + 3)
     919
    833920#include "xatonum.h"
    834921/* Specialized: */
     
    854941/* wrapper: allows string to contain numeric uid or gid */
    855942unsigned 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 */
    857943struct bb_uidgid_t {
    858944    uid_t uid;
    859945    gid_t gid;
    860946};
    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 */
     948int get_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
     949/* always sets uid and gid; exits on failure */
    864950void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
    865951/* chown-like handling of "user[:[group]" */
     
    890976void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
    891977void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
     978void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid);
    892979#else
    893980# define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0)
    894981# 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
     986int file_is_executable(const char *name) FAST_FUNC;
     987char *find_executable(const char *filename, char **PATHp) FAST_FUNC;
     988int executable_exists(const char *filename) FAST_FUNC;
    901989
    902990/* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff),
     
    9151003#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__)
    9161004#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
     1005void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
     1006void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
     1007
     1008/* xvfork() can't be a _function_, return after vfork in child mangles stack
    9201009 * in the parent. It must be a macro. */
    9211010#define xvfork() \
     
    9291018pid_t xfork(void) FAST_FUNC;
    9301019#endif
     1020void xvfork_parent_waits_and_exits(void) FAST_FUNC;
    9311021
    9321022/* NOMMU friendy fork+exec: */
     
    9451035 */
    9461036int wait4pid(pid_t pid) FAST_FUNC;
     1037int wait_for_exitstatus(pid_t pid) FAST_FUNC;
    9471038/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
    9481039int spawn_and_wait(char **argv) FAST_FUNC;
     
    10581149};
    10591150extern const char *msg_eol;
     1151extern smallint syslog_level;
    10601152extern smallint logmode;
    1061 extern int die_sleep;
    10621153extern uint8_t xfunc_error_retval;
    1063 extern jmp_buf die_jmp;
     1154extern void (*die_func)(void);
    10641155extern void xfunc_die(void) NORETURN FAST_FUNC;
    10651156extern void bb_show_usage(void) NORETURN FAST_FUNC;
     
    10741165extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
    10751166extern void bb_perror_nomsg(void) FAST_FUNC;
    1076 extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
    10771167extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
     1168extern void bb_logenv_override(void) FAST_FUNC;
    10781169
    10791170/* We need to export XXX_main from libbusybox
     
    11081199
    11091200/* Networking */
    1110 int create_icmp_socket(void) FAST_FUNC;
    1111 int create_icmp6_socket(void) FAST_FUNC;
    1112 /* interface.c */
    11131201/* This structure defines protocol families and their handlers. */
    11141202struct aftype {
     
    11391227extern smallint interface_opt_a;
    11401228int display_interfaces(char *ifname) FAST_FUNC;
     1229int in_ether(const char *bufp, struct sockaddr *sap) FAST_FUNC;
    11411230#if ENABLE_FEATURE_HWIB
    11421231int in_ib(const char *bufp, struct sockaddr *sap) FAST_FUNC;
     
    11511240#ifndef BUILD_INDIVIDUAL
    11521241extern 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;
    11551242extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
    11561243#endif
     
    11841271int bb_ask_confirmation(void) FAST_FUNC;
    11851272
    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" */
     1274int bb_parse_mode(const char* s, unsigned cur_mode) FAST_FUNC;
    11871275
    11881276/*
     
    12401328char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
    12411329
     1330#ifndef LOGIN_FAIL_DELAY
    12421331#define LOGIN_FAIL_DELAY 3
     1332#endif
    12431333extern void bb_do_delay(int seconds) FAST_FUNC;
    12441334extern void change_identity(const struct passwd *pw) FAST_FUNC;
     
    12621352#endif
    12631353extern void selinux_or_die(void) FAST_FUNC;
    1264 
    1265 
    1266 /* systemd support */
    1267 #define SD_LISTEN_FDS_START 3
    1268 int sd_listen_fds(void);
    12691354
    12701355
     
    12881373#define SETUP_ENV_TO_TMP    (1 << 2)
    12891374#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;
     1375void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
     1376void nuke_str(char *str) FAST_FUNC;
     1377int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
     1378int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
     1379int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
    12921380/* Returns a malloced string */
    12931381#if !ENABLE_USE_BB_CRYPT
     
    13321420/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
    13331421int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
     1422int get_terminal_width(int fd) FAST_FUNC;
    13341423
    13351424int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
     
    14351524# if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0
    14361525#  define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
    1437 unsigned size_from_HISTFILESIZE(const char *hp);
     1526unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC;
    14381527# else
    14391528#  define MAX_HISTORY 0
     
    14771566 */
    14781567int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC;
     1568void show_history(const line_input_t *st) FAST_FUNC;
    14791569# if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
    14801570void save_history(line_input_t *st);
     
    16891779            uoff_t totalsize) FAST_FUNC;
    16901780
     1781unsigned ubi_devnum_from_devname(const char *str) FAST_FUNC;
     1782int ubi_get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC;
     1783
    16911784
    16921785extern const char *applet_name;
     
    17121805extern const char bb_msg_you_must_be_root[] ALIGN1;
    17131806extern const char bb_msg_requires_arg[] ALIGN1;
    1714 extern const char bb_msg_invalid_arg[] ALIGN1;
     1807extern const char bb_msg_invalid_arg_to[] ALIGN1;
    17151808extern const char bb_msg_standard_input[] ALIGN1;
    17161809extern const char bb_msg_standard_output[] ALIGN1;
     
    17411834
    17421835extern 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
    17491838/* This struct is deliberately not defined. */
    17501839/* See docs/keep_data_small.txt */
     
    17591848    (*(struct globals**)&ptr_to_globals) = (void*)(x); \
    17601849    barrier(); \
     1850} while (0)
     1851#define FREE_PTR_TO_GLOBALS() do { \
     1852    if (ENABLE_FEATURE_CLEAN_UP) { \
     1853        free(ptr_to_globals); \
     1854    } \
    17611855} while (0)
    17621856
     
    18011895# define VC_5 "/dev/vc/5"
    18021896# define VC_FORMAT "/dev/vc/%d"
    1803 # define LOOP_FORMAT "/dev/loop/%d"
     1897# define LOOP_FORMAT "/dev/loop/%u"
    18041898# define LOOP_NAMESIZE (sizeof("/dev/loop/") + sizeof(int)*3 + 1)
    18051899# define LOOP_NAME "/dev/loop/"
     
    18141908# define VC_5 "/dev/tty5"
    18151909# define VC_FORMAT "/dev/tty%d"
    1816 # define LOOP_FORMAT "/dev/loop%d"
     1910# define LOOP_FORMAT "/dev/loop%u"
    18171911# define LOOP_NAMESIZE (sizeof("/dev/loop") + sizeof(int)*3 + 1)
    18181912# define LOOP_NAME "/dev/loop"
     
    18221916
    18231917#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
     1918#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
    18241919
    18251920
     
    19072002
    19082003
     2004/* Simple unit-testing framework */
     2005
     2006typedef void (*bbunit_testfunc)(void);
     2007
     2008struct bbunit_listelem {
     2009    const char* name;
     2010    bbunit_testfunc testfunc;
     2011};
     2012
     2013void bbunit_registertest(struct bbunit_listelem* test);
     2014void 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
    19092138POP_SAVED_FUNCTION_VISIBILITY
    19102139
Note: See TracChangeset for help on using the changeset viewer.