summaryrefslogtreecommitdiff
path: root/lib/printfrr.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-03-26 18:11:21 +0100
committerDavid Lamparter <equinox@diac24.net>2021-03-30 22:32:59 +0200
commitcb4928ce77c089ae521301776ed90e994c29800c (patch)
tree3e595e3b458c3abed63c485eac59cfb229fdb3a7 /lib/printfrr.h
parent2d9a4e2931e4f20c6bc49b09956a1e350664e3f2 (diff)
lib: add `FMT_NSTD()` for non-standard printf exts
... to suppress the warnings when using something that isn't quite ISO C compatible and would otherwise cause compiler warnings from `-Wformat`. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/printfrr.h')
-rw-r--r--lib/printfrr.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/printfrr.h b/lib/printfrr.h
index 9dd20f0a8f..8245a664b3 100644
--- a/lib/printfrr.h
+++ b/lib/printfrr.h
@@ -251,6 +251,31 @@ static inline ssize_t bputch(struct fbuf *buf, char ch)
return 1;
}
+/* when using non-ISO-C compatible extension specifiers... */
+
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#define FMT_NSTD_BEGIN
+#define FMT_NSTD_END
+#else /* !_FRR_ATTRIBUTE_PRINTFRR */
+#define FMT_NSTD_BEGIN \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wformat\"") \
+ /* end */
+#define FMT_NSTD_END \
+ _Pragma("GCC diagnostic pop") \
+ /* end */
+#endif
+
+#define FMT_NSTD(expr) \
+ ({ \
+ typeof(expr) _v; \
+ FMT_NSTD_BEGIN \
+ _v = expr; \
+ FMT_NSTD_END \
+ _v; \
+ }) \
+ /* end */
+
#ifdef __cplusplus
}
#endif