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 <alx@kernel.org>
#include "config.h"
+#include <errno.h>
#include <locale.h>
#include <stddef.h>
#include <stdlib.h>
#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 \
{ \