Move nowarn_snprintf.h to lib/
[fio.git] / lib / nowarn_snprintf.h
diff --git a/lib/nowarn_snprintf.h b/lib/nowarn_snprintf.h
new file mode 100644 (file)
index 0000000..5c0f4d4
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef _NOWARN_SNPRINTF_H_
+#define _NOWARN_SNPRINTF_H_
+
+#include <stdio.h>
+#include <stdarg.h>
+
+static inline int nowarn_snprintf(char *str, size_t size, const char *format,
+                                 ...)
+{
+       va_list args;
+
+       va_start(args, format);
+#if __GNUC__ -0 >= 8
+#pragma GCC diagnostic push "-Wformat-truncation"
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+#endif
+       return vsnprintf(str, size, format, args);
+#if __GNUC__ -0 >= 8
+#pragma GCC diagnostic pop "-Wformat-truncation"
+#endif
+       va_end(args);
+}
+
+#endif