mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-21 23:56:57 +02:00
err: Add err(), warn(), errx() and warnx() familiy of functions
Some systems such as Windows or musl-libc based ones do not have these BSD extensions. In addition libbsd itself is making use of the warnx() functions, so we better provide these interfaces in case they are missing.
This commit is contained in:
76
src/err.c
76
src/err.c
@@ -26,6 +26,9 @@
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@@ -73,3 +76,76 @@ errc(int status, int code, const char *format, ...)
|
||||
verrc(status, code, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||
void
|
||||
vwarn(const char *format, va_list ap)
|
||||
{
|
||||
vwarnc(errno, format, ap);
|
||||
}
|
||||
|
||||
void
|
||||
warn(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vwarnc(errno, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
vwarnx(const char *format, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format)
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
warnx(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vwarnx(format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
verr(int status, const char *format, va_list ap)
|
||||
{
|
||||
verrc(status, errno, format, ap);
|
||||
}
|
||||
|
||||
void
|
||||
err(int status, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
verrc(status, errno, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
verrx(int eval, const char *format, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format)
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void
|
||||
errx(int eval, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
verrx(eval, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user