From: Alejandro Colomar Date: Wed, 23 Jul 2025 12:19:52 +0000 (+0200) Subject: lib/io/fprintf.h: fprinte(): Add macro X-Git-Tag: 4.20.0-rc3~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bb39793716a2466aa1f477e4634e9d86532df80;p=thirdparty%2Fshadow.git lib/io/fprintf.h: fprinte(): Add macro fprinte() is like fprintec(), but uses errno instead of an error code. It is implemented as a macro so that it can read the value in errno before evaluating any of its arguments, thus not corrupting it. It also preserves errno so that the error can be printed more than once. This is useful because we often print to stderr or log_get_logfd(), and immediately after print to the system log with syslog(3). Signed-off-by: Alejandro Colomar --- diff --git a/lib/io/fprintf.h b/lib/io/fprintf.h index 356d72151..3848d7c84 100644 --- a/lib/io/fprintf.h +++ b/lib/io/fprintf.h @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -15,6 +16,17 @@ #include "attr.h" +// fprinte - FILE* print errno +#define fprinte(stream, ...) do \ +{ \ + int e__; \ + \ + e__ = errno; \ + fprintec(stream, e__, __VA_ARGS__); \ + errno = e__; \ +} while (0) + + format_attr(printf, 3, 4) inline int fprintec(FILE *restrict stream, int e, const char *restrict fmt, ...);