1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-25 22:46:05 +03:00

added proper warn/warnx/err/errx

This commit is contained in:
Erik Ekman 2009-01-25 19:34:33 +00:00 committed by Erik Ekman
parent adc80adff7
commit b43e97aeb0
3 changed files with 49 additions and 7 deletions

View File

@ -222,5 +222,49 @@ inet_aton(const char *cp, struct in_addr *inp)
inp->s_addr = inet_addr(cp); inp->s_addr = inet_addr(cp);
return inp->s_addr != INADDR_ANY; 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 #endif

View File

@ -77,6 +77,11 @@ int check_topdomain(char *);
#ifdef WINDOWS32 #ifdef WINDOWS32
int inet_aton(const char *cp, struct in_addr *inp); 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
#endif #endif

View File

@ -19,13 +19,6 @@
typedef unsigned int in_addr_t; 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 <windows.h> #include <windows.h>
#include <windns.h> #include <windns.h>
#include <winsock.h> #include <winsock.h>