From 03e9f2891d17643e603f3fd5f88dc61556e38802 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 12 Mar 2015 14:02:39 +0100 Subject: move edie, die and dbg functions to log.c So it can be reused by the handler. --- Makefile | 2 +- log.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ log.h | 10 ++++++++++ nldev.c | 44 ++------------------------------------------ 4 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 log.c create mode 100644 log.h diff --git a/Makefile b/Makefile index 54cab33..e28138f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include config.mk SRC = ${NAME}.c -OBJ = ${SRC:.c=.o} +OBJ = ${SRC:.c=.o} log.o all: options ${NAME} 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 +#include + +#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"); + } +} diff --git a/log.h b/log.h new file mode 100644 index 0000000..949ecce --- /dev/null +++ b/log.h @@ -0,0 +1,10 @@ + +#include + +#include "arg.h" + +void edie(char *fmt, ...); +void die(char *fmt, ...); +void dbg(char *fmt, ...); + +extern int dodebug; diff --git a/nldev.c b/nldev.c index 72c9656..eab53ff 100644 --- a/nldev.c +++ b/nldev.c @@ -22,51 +22,11 @@ #include #include "arg.h" +#include "log.h" char *argv0; int listfd = -1; -int dofork = 0, 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"); - } -} +int dofork = 0; void disableoom(void) -- cgit v1.2.3