libbb: new function bb_die_memory_exhausted
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 1 Apr 2018 17:59:37 +0000 (19:59 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 1 Apr 2018 17:59:37 +0000 (19:59 +0200)
function                                             old     new   delta
bb_die_memory_exhausted                                -      10     +10
xstrdup                                               28      23      -5
xsetenv                                               27      22      -5
xrealloc                                              32      27      -5
xputenv                                               22      17      -5
xmalloc                                               30      25      -5
xfdopen_helper                                        40      35      -5
xasprintf                                             44      39      -5
wget_main                                           2387    2382      -5
open_socket                                           54      49      -5
glob_brace                                           419     414      -5
bb_get_chunk_from_file                               146     141      -5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55)           Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/libarchive/data_extract_to_command.c
include/libbb.h
libbb/get_line_from_file.c
libbb/wfopen.c
libbb/xfuncs_printf.c
networking/wget.c
shell/hush.c

index 1114a95cb3b29546fdc93a9b92277edd6af4230d..0fcabb4a987b7a812aaac15eb6b3b94a2e1f71fb 100644 (file)
@@ -37,7 +37,7 @@ static const char *const tar_var[] = {
 static void xputenv(char *str)
 {
        if (putenv(str))
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
 }
 
 static void str2env(char *env[], int idx, const char *str)
index 309c58734dab4e550aa995f1e09c00b4cca26a67..ad1c7346fa9c9546c890310f4ef08beb2f45d5cf 100644 (file)
@@ -1277,20 +1277,21 @@ extern smallint syslog_level;
 extern smallint logmode;
 extern uint8_t xfunc_error_retval;
 extern void (*die_func)(void);
-extern void xfunc_die(void) NORETURN FAST_FUNC;
-extern void bb_show_usage(void) NORETURN FAST_FUNC;
-extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
-extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
-extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
-extern void bb_simple_perror_msg(const char *s) FAST_FUNC;
-extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
-extern void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
-extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
-extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
-extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
-extern void bb_perror_nomsg(void) FAST_FUNC;
-extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
-extern void bb_logenv_override(void) FAST_FUNC;
+void xfunc_die(void) NORETURN FAST_FUNC;
+void bb_show_usage(void) NORETURN FAST_FUNC;
+void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
+void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
+void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
+void bb_simple_perror_msg(const char *s) FAST_FUNC;
+void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
+void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
+void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
+void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
+void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
+void bb_perror_nomsg(void) FAST_FUNC;
+void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
+void bb_die_memory_exhausted(void) NORETURN FAST_FUNC;
+void bb_logenv_override(void) FAST_FUNC;
 
 /* We need to export XXX_main from libbusybox
  * only if we build "individual" binaries
index d100669379b770fb0c202997b699cf4bca57766d..f3d6c62039e969866e627e49ae90ab472d9b5ae9 100644 (file)
@@ -20,7 +20,7 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end)
                /* grow the line buffer as necessary */
                if (!(idx & 0xff)) {
                        if (idx == ((size_t)-1) - 0xff)
-                               bb_error_msg_and_die(bb_msg_memory_exhausted);
+                               bb_die_memory_exhausted();
                        linebuf = xrealloc(linebuf, idx + 0x100);
                }
                linebuf[idx++] = (char) ch;
index 20fe18b23326d9d941085c5c316bd6e4bf7d1bab..1c7f7f3d76a1ae01fe2415c3977886777769ad40 100644 (file)
@@ -42,7 +42,7 @@ static FILE* xfdopen_helper(unsigned fd_and_rw_bit)
 {
        FILE* fp = fdopen(fd_and_rw_bit >> 1, fd_and_rw_bit & 1 ? "w" : "r");
        if (!fp)
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
        return fp;
 }
 FILE* FAST_FUNC xfdopen_for_read(int fd)
index 2bc01ad10c6954a3077c99a33244ed42d300f1a1..7247c915b3c72c8e471dc7d9f8fb8fd7a185c334 100644 (file)
  * fail, so callers never need to check for errors.  If it returned, it
  * succeeded. */
 
+void FAST_FUNC bb_die_memory_exhausted(void)
+{
+       bb_error_msg_and_die(bb_msg_memory_exhausted);
+}
+
 #ifndef DMALLOC
 /* dmalloc provides variants of these that do abort() on failure.
  * Since dmalloc's prototypes overwrite the impls here as they are
@@ -44,7 +49,7 @@ void* FAST_FUNC xmalloc(size_t size)
 {
        void *ptr = malloc(size);
        if (ptr == NULL && size != 0)
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
        return ptr;
 }
 
@@ -55,7 +60,7 @@ void* FAST_FUNC xrealloc(void *ptr, size_t size)
 {
        ptr = realloc(ptr, size);
        if (ptr == NULL && size != 0)
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
        return ptr;
 }
 #endif /* DMALLOC */
@@ -79,7 +84,7 @@ char* FAST_FUNC xstrdup(const char *s)
        t = strdup(s);
 
        if (t == NULL)
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
 
        return t;
 }
@@ -327,14 +332,14 @@ char* FAST_FUNC xasprintf(const char *format, ...)
        va_end(p);
 
        if (r < 0)
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
        return string_ptr;
 }
 
 void FAST_FUNC xsetenv(const char *key, const char *value)
 {
        if (setenv(key, value, 1))
-               bb_error_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
 }
 
 /* Handles "VAR=VAL" strings, even those which are part of environ
index 8969310a42b7146a992e7112c6fc79e33d2accd6..12ee29a6fc23e6b2fac70c790a97648bff6967d6 100644 (file)
@@ -409,7 +409,7 @@ static FILE *open_socket(len_and_sockaddr *lsa)
        /* hopefully it understands what ESPIPE means... */
        fp = fdopen(fd, "r+");
        if (!fp)
-               bb_perror_msg_and_die(bb_msg_memory_exhausted);
+               bb_die_memory_exhausted();
 
        return fp;
 }
@@ -1114,7 +1114,7 @@ static void download_one_url(const char *url)
 # endif
                        sfp = fdopen(fd, "r+");
                        if (!sfp)
-                               bb_perror_msg_and_die(bb_msg_memory_exhausted);
+                               bb_die_memory_exhausted();
                        goto socket_opened;
                }
                sfp = open_socket(lsa);
index 1921932d1f2d472330f05d2884983a9dfe1effe7..8246b5fd87db2f7f49fda9221cb5a07c8df4bf0e 100644 (file)
@@ -3158,7 +3158,7 @@ static int glob_brace(char *pattern, o_string *o, int n)
                                return o_save_ptr_helper(o, n);
                        }
                        if (gr == GLOB_NOSPACE)
-                               bb_error_msg_and_die(bb_msg_memory_exhausted);
+                               bb_die_memory_exhausted();
                        /* GLOB_ABORTED? Only happens with GLOB_ERR flag,
                         * but we didn't specify it. Paranoia again. */
                        bb_error_msg_and_die("glob error %d on '%s'", gr, pattern);
@@ -3260,7 +3260,7 @@ static int perform_glob(o_string *o, int n)
                        goto literal;
                }
                if (gr == GLOB_NOSPACE)
-                       bb_error_msg_and_die(bb_msg_memory_exhausted);
+                       bb_die_memory_exhausted();
                /* GLOB_ABORTED? Only happens with GLOB_ERR flag,
                 * but we didn't specify it. Paranoia again. */
                bb_error_msg_and_die("glob error %d on '%s'", gr, pattern);