multiprogress.h: Use a macro to mark `printf'-like functions.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 25 Mar 2022 18:52:31 +0000 (18:52 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Mar 2022 18:52:31 +0000 (18:52 +0000)
Rather than using `__attribute__' directly.

multiprogress.h

index e6f96f8..4a0d114 100644 (file)
 #include <stdio.h>
 #include <sys/time.h>
 
+/*----- Compiler-specific magic -------------------------------------------*/
+
+#if (defined(__GNUC__) && (__GNUC__ > 2 ||                             \
+                          (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))) ||  \
+    (defined(__clang__) && (__clang_major__ > 3 || \
+                           (__clang_major__ == 3 && __clang_minor__ >= 3)))
+#  define MULTIPROGRESS__PRINTF_LIKE(farg, aarg)                       \
+       __attribute__((format(printf, farg, aarg)))
+#else
+#  define MULTIPROGRESS__PRINTF_LIKE(farg, aarg)
+#endif
+
 /*----- Data structures ---------------------------------------------------*/
 
 struct progress_ttyinfo {
@@ -165,10 +177,10 @@ extern int progress_vputleft(struct progress_render_state */*render*/,
                             const char */*fmt*/, va_list /*ap*/);
 extern int progress_vputright(struct progress_render_state */*render*/,
                              const char */*fmt*/, va_list /*ap*/);
-__attribute__((format(printf, 2, 3)))
+MULTIPROGRESS__PRINTF_LIKE(2, 3)
 extern int progress_putleft(struct progress_render_state */*render*/,
                            const char */*fmt*/, ...);
-__attribute__((format(printf, 2, 3)))
+MULTIPROGRESS__PRINTF_LIKE(2, 3)
 extern int progress_putright(struct progress_render_state */*render*/,
                             const char */*fmt*/, ...);
        /* Format the `printf'-style string FMT with the supplied arguments