diff options
Diffstat (limited to 'src/libc/err.c')
-rw-r--r-- | src/libc/err.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libc/err.c b/src/libc/err.c new file mode 100644 index 0000000..7a220fe --- /dev/null +++ b/src/libc/err.c @@ -0,0 +1,50 @@ +#include <err.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +_Noreturn void err(int ret, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + vwarn(fmt, args); + va_end(args); + exit(ret); +} + +_Noreturn void errx(int ret, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + vwarnx(fmt, args); + va_end(args); + exit(ret); +} + +void warn(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + vwarn(fmt, args); + va_end(args); +} + +void warnx(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + vwarnx(fmt, args); + va_end(args); +} + +void vwarn(const char *fmt, va_list args) { + fprintf(stderr, "%s: ", getprogname()); + if (fmt) { + vfprintf(stderr, fmt, args); + fprintf(stderr, ": "); + } + fprintf(stderr, "%s\n", strerror(errno)); +} + +void vwarnx(const char *fmt, va_list args) { + fprintf(stderr, "%s: ", getprogname()); + if (fmt) vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} |