]> sigrok.org Git - libsigrok.git/commitdiff
libsigrok-internal.h: factor out logger decl's printf format attribute
authorGerhard Sittig <redacted>
Fri, 6 Oct 2023 16:00:37 +0000 (18:00 +0200)
committerGerhard Sittig <redacted>
Sat, 7 Oct 2023 13:36:09 +0000 (15:36 +0200)
Provide a common ATTR_FMT_PRINTF() macro which hides individual
platforms' details. Use it in one common sr_log() declaration.

This also allows re-use in other locations across the project.

src/libsigrok-internal.h

index e5033085b78c8f8e0d499d99c49fb7cad62249df..c2c324c420917d5bb01ef8df268270d120e4cab1 100644 (file)
@@ -1678,17 +1678,20 @@ struct drv_context {
 
 /*--- log.c -----------------------------------------------------------------*/
 
 
 /*--- log.c -----------------------------------------------------------------*/
 
+/* Provide a macro for other source code locations to re-use. */
 #if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
 /*
  * On MinGW, we need to specify the gnu_printf format flavor or GCC
  * will assume non-standard Microsoft printf syntax.
  */
 #if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
 /*
  * On MinGW, we need to specify the gnu_printf format flavor or GCC
  * will assume non-standard Microsoft printf syntax.
  */
-SR_PRIV int sr_log(int loglevel, const char *format, ...)
-               __attribute__((__format__ (__gnu_printf__, 2, 3)));
+#define ATTR_FMT_PRINTF(fmt_pos, arg_pos) \
+               __attribute__((__format__ (__gnu_printf__, fmt_pos, arg_pos)))
 #else
 #else
-SR_PRIV int sr_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3);
+#define ATTR_FMT_PRINTF(fmt_pos, arg_pos)      G_GNUC_PRINTF(fmt_pos, arg_pos)
 #endif
 
 #endif
 
+SR_PRIV int sr_log(int loglevel, const char *format, ...) ATTR_FMT_PRINTF(2, 3);
+
 /* Message logging helpers with subsystem-specific prefix string. */
 #define sr_spew(...)   sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
 #define sr_dbg(...)    sr_log(SR_LOG_DBG,  LOG_PREFIX ": " __VA_ARGS__)
 /* Message logging helpers with subsystem-specific prefix string. */
 #define sr_spew(...)   sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
 #define sr_dbg(...)    sr_log(SR_LOG_DBG,  LOG_PREFIX ": " __VA_ARGS__)