commit 94e92d9cc0bd21ec23d1303d8c0e05e0fb521057
parent 6135cad495e562b0d3108942ca8de2b285699e0e
Author: FRIGN <dev@frign.de>
Date: Mon, 21 Dec 2015 09:28:44 +0100
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.
Diffstat:
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/libutil/eprintf.c b/libutil/eprintf.c
@@ -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, ...)
@@ -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
@@ -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);
}
@@ -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);