summaryrefslogtreecommitdiff
path: root/os_compat.c
diff options
context:
space:
mode:
authorRobert Norris <rw_norris@hotmail.com>2017-03-05 18:43:33 +0000
committerFred Wright <fw@fwright.net>2017-03-05 13:43:14 -0800
commit9f870a11218d0bc6364d6b333fd878106746adf9 (patch)
tree2e69141ae377dcb27c09fa7771b61fd30272fc43 /os_compat.c
parenta32c93f5c70af935e4ff02e19959da65f078d166 (diff)
downloadgpsd-9f870a11218d0bc6364d6b333fd878106746adf9.tar.gz
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 <fw@fwright.net>
Diffstat (limited to 'os_compat.c')
-rw-r--r--os_compat.c30
1 files changed, 30 insertions, 0 deletions
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 <stdarg.h>
+#include <stdio.h>
+/*
+ * 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