From c3166bf1d0387c1abe2bf47e15e10874bf7215a3 Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Fri, 21 Jul 2006 08:43:09 +0000 Subject: [PATCH] Implement warn() --- trunk/darkhttpd.c | 63 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/trunk/darkhttpd.c b/trunk/darkhttpd.c index bf114d3..6ddb2f6 100644 --- a/trunk/darkhttpd.c +++ b/trunk/darkhttpd.c @@ -51,7 +51,6 @@ static const int debug = 1; #include #include #include -#include #include #include #include @@ -69,37 +68,14 @@ static const int debug = 1; #define INADDR_NONE -1 #endif - - #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux) #include #else -/* --------------------------------------------------------------------------- - * errx - prints "error: [...]\n" to stderr and exit()s with [code] - * - * Replacement for the BSD errx() which is usually in +/* err - prints "error: format: strerror(errno)" to stderr and exit()s with + * the given code. */ -static void errx(const int code, const char *format, ...) -{ - va_list va; - - va_start(va, format); - fprintf(stderr, "error: "); - vfprintf(stderr, format, va); - fprintf(stderr, "\n"); - va_end(va); - - exit(code); -} - - - -/* --------------------------------------------------------------------------- - * err - prints "error: [...]: strerror\n" to stderr and exit()s with [code] - * - * Replacement for the BSD err() which is usually in - */ -static void err(const int code, const char *format, ...) +static void +err(const int code, const char *format, ...) { va_list va; @@ -108,13 +84,37 @@ static void err(const int code, const char *format, ...) vfprintf(stderr, format, va); fprintf(stderr, ": %s\n", strerror(errno)); va_end(va); - exit(code); } + +/* errx - err without the strerror */ +static void +errx(const int code, const char *format, ...) +{ + va_list va; + + va_start(va, format); + fprintf(stderr, "error: "); + vfprintf(stderr, format, va); + fprintf(stderr, "\n"); + va_end(va); + exit(code); +} + +/* warn - err without the exit */ +static void +warn(const char *format, ...) +{ + va_list va; + + va_start(va, format); + fprintf(stderr, "warning: "); + vfprintf(stderr, format, va); + fprintf(stderr, ": %s\n", strerror(errno)); + va_end(va); +} #endif - - /* --------------------------------------------------------------------------- * LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.56 * Copyright (c) 1991, 1993 @@ -122,7 +122,6 @@ static void err(const int code, const char *format, ...) * * Under a BSD license. */ - #define LIST_HEAD(name, type) \ struct name { \ struct type *lh_first; /* first element */ \