From 9f870a11218d0bc6364d6b333fd878106746adf9 Mon Sep 17 00:00:00 2001 From: Robert Norris Date: Sun, 5 Mar 2017 18:43:33 +0000 Subject: OS syslog compatibility fallback. Mainly for Windows systems which doesn't have syslog(). Implement simple fallback to print to stderr, rather than a more complicated use of Windows Event Log. Also basic fallbacks for openlog() and closelog() which don't really do anything. TESTED: Functions build on Windows cross build 'scons build-all check' passes on Linux Signed-off-by: Fred Wright --- os_compat.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'os_compat.c') diff --git a/os_compat.c b/os_compat.c index fa4d85b2..8c117379 100644 --- a/os_compat.c +++ b/os_compat.c @@ -130,6 +130,36 @@ int os_daemon(int nochdir, int noclose) /* Provide BSD strlcat()/strlcpy() on platforms that don't have it */ +#ifndef HAVE_SYSLOG_H +#include "compiler.h" +#include +#include +/* + * Minimal syslog() fallback to print to stderr + * + */ +PRINTF_FUNC(2, 3) void syslog(int priority UNUSED, const char *format, ...) +{ + /* ATM ignore priority (i.e. don't even both prepending to output) */ + char buf[BUFSIZ]; + va_list ap; + va_start(ap, format); + /* Always append a new line to the message */ + (void)vsnprintf(buf, sizeof(buf) - 2, format, ap); + (void)fprintf(stderr, "%s\n", buf); + va_end(ap); +} + +void openlog (const char *__ident UNUSED, int __option UNUSED, int __facility UNUSED) +{ + (void)fprintf(stderr, "Warning openlog() not available\n"); +} + +void closelog (void) +{ +} +#endif /* !HAVE_SYSLOG_H */ + /* * These versions use memcpy and strlen() because they are often * heavily optimized down to assembler level. Thus, likely to be -- cgit v1.2.1