From 5ecd0fc61a1a292426538fcb1e791342e04953b5 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 6 Mar 2024 16:41:59 +0100 Subject: Genesis --- lib/errors/cerr.c | 14 ++++++++++++++ lib/errors/cerrx.c | 14 ++++++++++++++ lib/errors/err.c | 14 ++++++++++++++ lib/errors/errx.c | 14 ++++++++++++++ lib/errors/setprogname.c | 12 ++++++++++++ lib/errors/vwarn.c | 15 +++++++++++++++ lib/errors/vwarnx.c | 12 ++++++++++++ lib/errors/warn.c | 12 ++++++++++++ lib/errors/warnx.c | 12 ++++++++++++ 9 files changed, 119 insertions(+) create mode 100644 lib/errors/cerr.c create mode 100644 lib/errors/cerrx.c create mode 100644 lib/errors/err.c create mode 100644 lib/errors/errx.c create mode 100644 lib/errors/setprogname.c create mode 100644 lib/errors/vwarn.c create mode 100644 lib/errors/vwarnx.c create mode 100644 lib/errors/warn.c create mode 100644 lib/errors/warnx.c (limited to 'lib/errors') diff --git a/lib/errors/cerr.c b/lib/errors/cerr.c new file mode 100644 index 0000000..bf5a98d --- /dev/null +++ b/lib/errors/cerr.c @@ -0,0 +1,14 @@ +#include +#include + +#include "errors.h" + +void +cerr(int code, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); + exit(code); +} diff --git a/lib/errors/cerrx.c b/lib/errors/cerrx.c new file mode 100644 index 0000000..b614f47 --- /dev/null +++ b/lib/errors/cerrx.c @@ -0,0 +1,14 @@ +#include +#include + +#include "errors.h" + +void +cerrx(int code, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); + exit(code); +} diff --git a/lib/errors/err.c b/lib/errors/err.c new file mode 100644 index 0000000..906e661 --- /dev/null +++ b/lib/errors/err.c @@ -0,0 +1,14 @@ +#include +#include + +#include "errors.h" + +void +err(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); + exit(EXIT_FAILURE); +} diff --git a/lib/errors/errx.c b/lib/errors/errx.c new file mode 100644 index 0000000..1fd55af --- /dev/null +++ b/lib/errors/errx.c @@ -0,0 +1,14 @@ +#include +#include + +#include "errors.h" + +void +errx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); + exit(EXIT_FAILURE); +} diff --git a/lib/errors/setprogname.c b/lib/errors/setprogname.c new file mode 100644 index 0000000..ab2de3e --- /dev/null +++ b/lib/errors/setprogname.c @@ -0,0 +1,12 @@ +#include + +#include "errors.h" + +const char *__mlib_errors_progname; + +void +setprogname(const char *s) +{ + const char *p = strrchr(s, '/'); + __mlib_errors_progname = p ? p + 1 : s; +} diff --git a/lib/errors/vwarn.c b/lib/errors/vwarn.c new file mode 100644 index 0000000..bc6bd16 --- /dev/null +++ b/lib/errors/vwarn.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +#include "errors.h" + +void +vwarn(const char *fmt, va_list ap) +{ + int save = errno; + fprintf(stderr, "%s: ", progname()); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": %s\n", strerror(save)); +} diff --git a/lib/errors/vwarnx.c b/lib/errors/vwarnx.c new file mode 100644 index 0000000..72d8fa7 --- /dev/null +++ b/lib/errors/vwarnx.c @@ -0,0 +1,12 @@ +#include +#include + +#include "errors.h" + +void +vwarnx(const char *fmt, va_list ap) +{ + fprintf(stderr, "%s: ", progname()); + vfprintf(stderr, fmt, ap); + fputc('\n', stderr); +} diff --git a/lib/errors/warn.c b/lib/errors/warn.c new file mode 100644 index 0000000..78f3e36 --- /dev/null +++ b/lib/errors/warn.c @@ -0,0 +1,12 @@ +#include + +#include "errors.h" + +void +warn(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); +} diff --git a/lib/errors/warnx.c b/lib/errors/warnx.c new file mode 100644 index 0000000..ea50299 --- /dev/null +++ b/lib/errors/warnx.c @@ -0,0 +1,12 @@ +#include + +#include "errors.h" + +void +warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); +} -- cgit v1.2.3