From: Mark Whitley Date: Tue, 5 Dec 2000 19:27:13 +0000 (-0000) Subject: Applied patch from Matt Kraai to add v*error functions for handling vararg X-Git-Tag: 0_48~72 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cf61fe14aebf2b5f753261afdb9e03167b31a843;p=oweals%2Fbusybox.git Applied patch from Matt Kraai to add v*error functions for handling vararg lists in a safe 'n sane fashion. --- diff --git a/utility.c b/utility.c index 7c41ab8fb..eb3338302 100644 --- a/utility.c +++ b/utility.c @@ -84,36 +84,35 @@ extern void usage(const char *usage) exit(EXIT_FAILURE); } -extern void errorMsg(const char *s, ...) +static void verrorMsg(const char *s, va_list p) { - va_list p; - - va_start(p, s); fflush(stdout); fprintf(stderr, "%s: ", applet_name); vfprintf(stderr, s, p); - va_end(p); fflush(stderr); } -extern void fatalError(const char *s, ...) +extern void errorMsg(const char *s, ...) { va_list p; va_start(p, s); - fflush(stdout); - fprintf(stderr, "%s: ", applet_name); - vfprintf(stderr, s, p); + verrorMsg(s, p); va_end(p); - fflush(stderr); - exit(EXIT_FAILURE); } -extern void perrorMsg(const char *s, ...) +extern void fatalError(const char *s, ...) { va_list p; va_start(p, s); + verrorMsg(s, p); + va_end(p); + exit(EXIT_FAILURE); +} + +static void vperrorMsg(const char *s, va_list p) +{ fflush(stdout); fprintf(stderr, "%s: ", applet_name); if (s && *s) { @@ -121,24 +120,25 @@ extern void perrorMsg(const char *s, ...) fputs(": ", stderr); } fprintf(stderr, "%s\n", strerror(errno)); - va_end(p); fflush(stderr); } +extern void perrorMsg(const char *s, ...) +{ + va_list p; + + va_start(p, s); + vperrorMsg(s, p); + va_end(p); +} + extern void fatalPerror(const char *s, ...) { va_list p; va_start(p, s); - fflush(stdout); - fprintf(stderr, "%s: ", applet_name); - if (s && *s) { - vfprintf(stderr, s, p); - fputs(": ", stderr); - } - fprintf(stderr, "%s\n", strerror(errno)); + vperrorMsg(s, p); va_end(p); - fflush(stderr); exit(EXIT_FAILURE); }