logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: d813350977e45c9f130f7d62593011f5535ee7a4
parent f61758ada83cd313f92ab9e46862ce59dc6abaac
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 15 Sep 2025 05:12:44 +0200

libutils/err.c: save errno before calling fprintf

Diffstat:

Mlibutils/err.c8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libutils/err.c b/libutils/err.c @@ -6,19 +6,22 @@ #include "err.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> void utils_vwarn(const char *fmt, va_list ap) { + int err = errno; fprintf(stderr, "%s: warning: ", argv0); if(fmt) { vfprintf(stderr, fmt, ap); fputs(": ", stderr); } - perror(NULL); + fputs(strerror(err), stderr); } void @@ -32,13 +35,14 @@ utils_vwarnx(const char *fmt, va_list ap) _Noreturn void utils_verr(int status, const char *fmt, va_list ap) { + int err = errno; fprintf(stderr, "%s: error: ", argv0); if(fmt) { vfprintf(stderr, fmt, ap); fputs(": ", stderr); } - perror(NULL); + fputs(strerror(err), stderr); exit(status); }