>From be21e1a1d3ffa0b3baa073bdb4b04c80af7f7bee
From: Ori Bernstein <[email protected]>
Date: Sun, 22 Mar 2020 18:08:23 -0700
Subject: [PATCH] portability fixes for plan9
this fixes 3 issues:
- First off, the plan 9 C compilers don't handle GNU style varargs,
so we switch over to c99 style.
- Second, the __attribute((format, printf) is a GNU C extension,
so we only define it for GNU C. For plan 9, we use the varargck
pragma to do the same thing.
- Third, 0 length arrays aren't portable, so we use C99 flexible
array members.
diff -urN a/include/nslog/nslog.h b/include/nslog/nslog.h
--- a/include/nslog/nslog.h Sun Feb 23 01:49:32 2020
+++ b/include/nslog/nslog.h Sun Mar 22 18:08:23 2020
@@ -17,6 +17,13 @@
#include <stdarg.h>
+#if defined(__GNUC__)
+# define PRINTF(fmt, args) __attribute__ ((format (printf, 2, 3)))
+#elif defined(_PLAN9)
+# pragma varargck nslog__log argpos 2
+# define PRINTF(pos, args)
+#endif
+
/**
* Log levels
*
@@ -181,7 +188,7 @@
* \param logmsg The log message itself (printf format string)
* \param args The arguments for the log message
*/
-#define NSLOG(catname, level, logmsg, args...) \
+#define NSLOG(catname, level, ...) \
do { \
if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \
static nslog_entry_context_t _nslog_ctx = { \
@@ -193,7 +200,7 @@
sizeof(__PRETTY_FUNCTION__) - 1, \
__LINE__, \
}; \
- nslog__log(&_nslog_ctx, logmsg, ##args); \
+ nslog__log(&_nslog_ctx, __VA_ARGS__); \
} \
} while(0)
@@ -209,7 +216,7 @@
*/
void nslog__log(nslog_entry_context_t *ctx,
const char *pattern,
- ...) __attribute__ ((format (printf, 2, 3)));
+ ...) PRINTF(2, 3);
/**
* Log error types
diff -urN a/src/core.c b/src/core.c
--- a/src/core.c Sun Feb 23 01:49:32 2020
+++ b/src/core.c Sun Mar 22 18:08:23 2020
@@ -19,7 +19,7 @@
static struct nslog_cork_chain {
struct nslog_cork_chain *next;
nslog_entry_context_t context;
- char message[0]; /* NUL terminated */
+ char message[]; /* NUL terminated */
} *nslog__cork_chain = NULL, *nslog__cork_chain_last = NULL;
static nslog_callback nslog__cb = NULL;