From b43e97aeb03f5b528a773f7e9286a7e31a5a1cba Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 25 Jan 2009 19:34:33 +0000 Subject: [PATCH] added proper warn/warnx/err/errx --- src/common.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/common.h | 5 +++++ src/windows.h | 7 ------- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/common.c b/src/common.c index 2bf7b07..fc12e80 100644 --- a/src/common.c +++ b/src/common.c @@ -222,5 +222,49 @@ inet_aton(const char *cp, struct in_addr *inp) inp->s_addr = inet_addr(cp); return inp->s_addr != INADDR_ANY; } + +void +warn(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + if (fmt) fprintf(stderr, fmt, list); + fprintf(stderr, "%s\n", strerror(errno)); + va_end(list); +} + +void +warnx(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + if (fmt) fprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + va_end(list); +} + +void +err(int eval, const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + warn(fmt, list); + va_end(list); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + warnx(fmt, list); + va_end(list); + exit(eval); +} #endif diff --git a/src/common.h b/src/common.h index 44b4b59..5daef40 100644 --- a/src/common.h +++ b/src/common.h @@ -77,6 +77,11 @@ int check_topdomain(char *); #ifdef WINDOWS32 int inet_aton(const char *cp, struct in_addr *inp); + +void err(int eval, const char *fmt, ...); +void warn(const char *fmt, ...); +void errx(int eval, const char *fmt, ...); +void warnx(const char *fmt, ...); #endif #endif diff --git a/src/windows.h b/src/windows.h index 8680679..57442f3 100644 --- a/src/windows.h +++ b/src/windows.h @@ -19,13 +19,6 @@ typedef unsigned int in_addr_t; -/* Bad err.h fix */ -#define warn printf -#define warnx printf -#define err(a, b, ...) do{printf("%s ", strerror(errno)); \ - printf(b, ## __VA_ARGS__); exit(a);}while(0) -#define errx(a, b, ...) do{printf(b, ## __VA_ARGS__); exit(a);}while(0) - #include #include #include