[hackers] [sbase] Refactor eprintf.c || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 21 Dec 2015 10:34:18 +0100 (CET)

commit 94e92d9cc0bd21ec23d1303d8c0e05e0fb521057
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Dec 21 09:28:44 2015 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Dec 21 09:34:13 2015 +0000

    Refactor eprintf.c
    
    When we move the exit() out of venprintf(), we can reuse it for
    weprintf(), which basically had duplicate code.
    I also renamed venprintf() to xvprintf (extended vprintf) so it's
    more obvious what it actually does.

diff --git a/libutil/eprintf.c b/libutil/eprintf.c
index 4d8f726..6230c66 100644
--- a/libutil/eprintf.c
+++ b/libutil/eprintf.c
_AT_@ -8,7 +8,7 @@
 
 char *argv0;
 
-static void venprintf(int, const char *, va_list);
+static void xvprintf(const char *, va_list);
 
 void
 eprintf(const char *fmt, ...)
_AT_@ -16,8 +16,10 @@ eprintf(const char *fmt, ...)
         va_list ap;
 
         va_start(ap, fmt);
- venprintf(1, fmt, ap);
+ xvprintf(fmt, ap);
         va_end(ap);
+
+ exit(1);
 }
 
 void
_AT_@ -26,22 +28,8 @@ enprintf(int status, const char *fmt, ...)
         va_list ap;
 
         va_start(ap, fmt);
- venprintf(status, fmt, ap);
+ xvprintf(fmt, ap);
         va_end(ap);
-}
-
-void
-venprintf(int status, const char *fmt, va_list ap)
-{
- if (strncmp(fmt, "usage", strlen("usage")))
- fprintf(stderr, "%s: ", argv0);
-
- vfprintf(stderr, fmt, ap);
-
- if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
- fputc(' ', stderr);
- perror(NULL);
- }
 
         exit(status);
 }
_AT_@ -51,12 +39,18 @@ weprintf(const char *fmt, ...)
 {
         va_list ap;
 
+ va_start(ap, fmt);
+ xvprintf(fmt, ap);
+ va_end(ap);
+}
+
+void
+xvprintf(const char *fmt, va_list ap)
+{
         if (strncmp(fmt, "usage", strlen("usage")))
                 fprintf(stderr, "%s: ", argv0);
 
- va_start(ap, fmt);
         vfprintf(stderr, fmt, ap);
- va_end(ap);
 
         if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
                 fputc(' ', stderr);
Received on Mon Dec 21 2015 - 10:34:18 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 21 2015 - 10:36:32 CET