Implement warn()

This commit is contained in:
Emil Mikulic 2006-07-21 08:43:09 +00:00
parent 2d4fbd38cd
commit c3166bf1d0

View File

@ -51,7 +51,6 @@ static const int debug = 1;
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <grp.h> #include <grp.h>
#include <libutil.h>
#include <pwd.h> #include <pwd.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
@ -69,37 +68,14 @@ static const int debug = 1;
#define INADDR_NONE -1 #define INADDR_NONE -1
#endif #endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux) #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux)
#include <err.h> #include <err.h>
#else #else
/* --------------------------------------------------------------------------- /* err - prints "error: format: strerror(errno)" to stderr and exit()s with
* errx - prints "error: [...]\n" to stderr and exit()s with [code] * the given code.
*
* Replacement for the BSD errx() which is usually in <err.h>
*/ */
static void errx(const int code, const char *format, ...) static void
{ err(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 <err.h>
*/
static void err(const int code, const char *format, ...)
{ {
va_list va; va_list va;
@ -108,13 +84,37 @@ static void err(const int code, const char *format, ...)
vfprintf(stderr, format, va); vfprintf(stderr, format, va);
fprintf(stderr, ": %s\n", strerror(errno)); fprintf(stderr, ": %s\n", strerror(errno));
va_end(va); va_end(va);
exit(code); 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 #endif
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.56 * LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.56
* Copyright (c) 1991, 1993 * Copyright (c) 1991, 1993
@ -122,7 +122,6 @@ static void err(const int code, const char *format, ...)
* *
* Under a BSD license. * Under a BSD license.
*/ */
#define LIST_HEAD(name, type) \ #define LIST_HEAD(name, type) \
struct name { \ struct name { \
struct type *lh_first; /* first element */ \ struct type *lh_first; /* first element */ \