[PATCH nft 7/8] utils: add _NFT_PRAGMA_WARNING_DISABLE()/_NFT_PRAGMA_WARNING_REENABLE helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Taken from libnl3 ([1]), which is LGPL-2.1-only licensed.

[1] https://github.com/thom311/libnl/blob/main/include/base/nl-base-utils.h#L44
---
 include/utils.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/include/utils.h b/include/utils.h
index 873147fb54ec..9475bbbee6a0 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -9,6 +9,47 @@
 #include <list.h>
 #include <gmputil.h>
 
+/*****************************************************************************/
+
+#define _NFT_STRINGIFY_ARG(contents) #contents
+#define _NFT_STRINGIFY(macro_or_string) _NFT_STRINGIFY_ARG(macro_or_string)
+
+/*****************************************************************************/
+
+#if defined(__GNUC__)
+#define _NFT_PRAGMA_WARNING_DO(warning) \
+	_NFT_STRINGIFY(GCC diagnostic ignored warning)
+#elif defined(__clang__)
+#define _NFT_PRAGMA_WARNING_DO(warning) \
+	_NFT_STRINGIFY(clang diagnostic ignored warning)
+#endif
+
+#if defined(__GNUC__) && \
+	(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#define _NFT_PRAGMA_WARNING_DISABLE(warning)                 \
+	_Pragma("GCC diagnostic push")                       \
+		_Pragma(_NFT_PRAGMA_WARNING_DO("-Wpragmas")) \
+			_Pragma(_NFT_PRAGMA_WARNING_DO(warning))
+#elif defined(__clang__)
+#define _NFT_PRAGMA_WARNING_DISABLE(warning)                                \
+	_Pragma("clang diagnostic push")                                    \
+		_Pragma(_NFT_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
+			_Pragma(_NFT_PRAGMA_WARNING_DO(warning))
+#else
+#define _NFT_PRAGMA_WARNING_DISABLE(warning)
+#endif
+
+#if defined(__GNUC__) && \
+	(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#define _NFT_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop")
+#elif defined(__clang__)
+#define _NFT_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop")
+#else
+#define _NFT_PRAGMA_WARNING_REENABLE
+#endif
+
+/*****************************************************************************/
+
 #ifdef HAVE_VISIBILITY_HIDDEN
 #       define __visible        __attribute__((visibility("default")))
 #       define EXPORT_SYMBOL(x) typeof(x) (x) __visible;
-- 
2.41.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux