aboutsummaryrefslogtreecommitdiffstats
path: root/log.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-03-12 14:02:39 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2015-03-12 14:02:39 +0100
commit03e9f2891d17643e603f3fd5f88dc61556e38802 (patch)
tree6dbdbad916543b0ebb95a4da0bf28d5247a26a78 /log.c
parent9ba3489123c6de58f70fc05379644c2ccedbe870 (diff)
downloadnldev-03e9f2891d17643e603f3fd5f88dc61556e38802.tar.bz2
nldev-03e9f2891d17643e603f3fd5f88dc61556e38802.tar.xz
move edie, die and dbg functions to log.c
So it can be reused by the handler.
Diffstat (limited to 'log.c')
-rw-r--r--log.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/log.c b/log.c
new file mode 100644
index 0000000..ef518cd
--- /dev/null
+++ b/log.c
@@ -0,0 +1,48 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "log.h"
+
+int dodebug = 0;
+
+void
+edie(char *fmt, ...)
+{
+ va_list fmtargs;
+
+ va_start(fmtargs, fmt);
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+ fprintf(stderr, ": ");
+
+ perror(NULL);
+
+ exit(1);
+}
+
+void
+die(char *fmt, ...)
+{
+ va_list fmtargs;
+
+ va_start(fmtargs, fmt);
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+
+ exit(1);
+}
+
+void
+dbg(char *fmt, ...)
+{
+ va_list fmtargs;
+
+ if (dodebug) {
+ fprintf(stderr, "%s: ", argv0);
+ va_start(fmtargs, fmt);
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+ fprintf(stderr, "\n");
+ }
+}