diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c index 4193eca77f60..c536767f1a6b 100644 --- a/lib/libc/gen/err.c +++ b/lib/libc/gen/err.c @@ -161,6 +161,9 @@ warnc(int code, const char *fmt, ...) void vwarnc(int code, const char *fmt, va_list ap) { + static int saved_errno; + + saved_errno = errno; if (err_file == NULL) err_set_file(NULL); fprintf(err_file, "%s: ", _getprogname()); @@ -169,6 +172,7 @@ vwarnc(int code, const char *fmt, va_list ap) fprintf(err_file, ": "); } fprintf(err_file, "%s\n", strerror(code)); + errno = saved_errno; } void @@ -183,10 +187,14 @@ warnx(const char *fmt, ...) void vwarnx(const char *fmt, va_list ap) { + static int saved_errno; + + saved_errno = errno; if (err_file == NULL) err_set_file(NULL); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); + errno = saved_errno; }