[Libguestfs] [PATCH nbdkit v2 2/2] include: Only use attribute((format)) on GCC or Clang.

Richard W.M. Jones rjones at redhat.com
Wed Jan 2 20:14:41 UTC 2019


Allow [in theory at least - it's not tested] the public API header
files to be consumed by a compiler which doesn't support
attribute((format)), a non-standard C extension.

Note that we still require GCC or Clang for compiling nbdkit.
---
 include/nbdkit-common.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/nbdkit-common.h b/include/nbdkit-common.h
index 27f6ed1..36fce20 100644
--- a/include/nbdkit-common.h
+++ b/include/nbdkit-common.h
@@ -45,6 +45,13 @@
 extern "C" {
 #endif
 
+#if defined(__GNUC__) || defined(__clang__)
+#define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos) \
+  __attribute__((__format__ (__printf__, fmtpos, argpos)))
+#else
+#define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos)
+#endif
+
 #define NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS     0
 #define NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS    1
 #define NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS        2
@@ -57,11 +64,9 @@ extern "C" {
 #define NBDKIT_FUA_EMULATE    1
 #define NBDKIT_FUA_NATIVE     2
 
-extern void nbdkit_error (const char *msg, ...)
-  __attribute__((__format__ (__printf__, 1, 2)));
+extern void nbdkit_error (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
 extern void nbdkit_verror (const char *msg, va_list args);
-extern void nbdkit_debug (const char *msg, ...)
-  __attribute__((__format__ (__printf__, 1, 2)));
+extern void nbdkit_debug (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
 extern void nbdkit_vdebug (const char *msg, va_list args);
 
 extern char *nbdkit_absolute_path (const char *path);
-- 
2.19.2




More information about the Libguestfs mailing list