summaryrefslogtreecommitdiff
path: root/libutil
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2023-04-13 17:56:14 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2023-04-13 17:56:14 +0200
commit9d3b555393735e08c27b04a8b616f2736afe26de (patch)
treef483cb50a59547fdc8b03ef01dfefb8123b0292b /libutil
downloadabase-9d3b555393735e08c27b04a8b616f2736afe26de.tar.gz
abase-9d3b555393735e08c27b04a8b616f2736afe26de.tar.bz2
created initial layout and a dummy more.c
Diffstat (limited to 'libutil')
-rw-r--r--libutil/eprintf.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/libutil/eprintf.c b/libutil/eprintf.c
new file mode 100644
index 0000000..673523e
--- /dev/null
+++ b/libutil/eprintf.c
@@ -0,0 +1,59 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../util.h"
+
+char *argv0;
+
+static void xvprintf(const char *, va_list);
+
+void
+eprintf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ xvprintf(fmt, ap);
+ va_end(ap);
+
+ exit(1);
+}
+
+void
+enprintf(int status, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ xvprintf(fmt, ap);
+ va_end(ap);
+
+ exit(status);
+}
+
+void
+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 (argv0 && strncmp(fmt, "usage", strlen("usage")))
+ fprintf(stderr, "%s: ", argv0);
+
+ vfprintf(stderr, fmt, ap);
+
+ if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ }
+}