From: Alejandro Colomar Date: Wed, 23 Jul 2025 12:23:11 +0000 (+0200) Subject: lib/io/syslog.h: SYSLOGE[C](): Add macros X-Git-Tag: 4.20.0-rc3~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b4adbe6387ae8d95dbe0bd547a157492842bea12;p=thirdparty%2Fshadow.git lib/io/syslog.h: SYSLOGE[C](): Add macros like the fprintf(3) wrappers, these print an error message. SYSLOGE() uses errno, and SYSLOGEC() uses an errno-like error code. This time we need to be careful to name the local copy of errno differently than within SYSLOG() --which we call--. Let's use a double underscore. In the future, C might have function literals (similar to lambdas), which will solve this issue. Signed-off-by: Alejandro Colomar --- diff --git a/lib/io/syslog.h b/lib/io/syslog.h index 323941c70..8a3ea4556 100644 --- a/lib/io/syslog.h +++ b/lib/io/syslog.h @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -56,6 +57,24 @@ #define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY) +// SYSLOGE - system log errno +#define SYSLOGE(prio, fmt, ...) do \ +{ \ + int e__; \ + \ + e__ = errno; \ + SYSLOGEC(prio, e__, fmt __VA_OPT__(,) __VA_ARGS__); \ + errno = e__; \ +} while (0) + + +// SYSLOGEC - system log errno code +#define SYSLOGEC(prio, e, fmt, ...) do \ +{ \ + SYSLOG(prio, "" fmt ": %s" __VA_OPT__(,) __VA_ARGS__, strerror(e)); \ +} while (0) + + // system log C-locale #define SYSLOG_C(...) do \ { \