summaryrefslogtreecommitdiff
path: root/src/NetworkManagerUtils.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-04 16:28:29 +0100
committerThomas Haller <thaller@redhat.com>2015-12-04 16:28:43 +0100
commit531f07b06a73e0d6308278e36f3ede57748ac4f7 (patch)
tree61c918aa4b65385cf2ec4a8c91c8b11b77662643 /src/NetworkManagerUtils.h
parent7a4b88d3e4500cfa75822b7b961cf4a42b9311f3 (diff)
downloadNetworkManager-531f07b06a73e0d6308278e36f3ede57748ac4f7.tar.gz
utils: add NM_UTILS_FLAGS2STR_DEFINE() macro
Make it neater to implement a nm_utils_flags2str() function.
Diffstat (limited to 'src/NetworkManagerUtils.h')
-rw-r--r--src/NetworkManagerUtils.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index a88f3afa08..f620ff01d5 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -203,6 +203,21 @@ typedef struct {
#define NM_UTILS_FLAGS2STR(f, n) { .flag = f, .name = ""n, }
+#define NM_UTILS_FLAGS2STR_DEFINE(fcn_name, flags_type, ...) \
+const char * \
+fcn_name (flags_type flags, char *buf, gsize len) \
+{ \
+ static const NMUtilsFlags2StrDesc descs[] = { \
+ __VA_ARGS__ \
+ }; \
+ G_STATIC_ASSERT (sizeof (flags_type) <= sizeof (unsigned)); \
+ return nm_utils_flags2str (descs, G_N_ELEMENTS (descs), flags, buf, len); \
+};
+
+#define NM_UTILS_FLAGS2STR_DEFINE_STATIC(fcn_name, flags_type, ...) \
+static \
+NM_UTILS_FLAGS2STR_DEFINE (fcn_name, flags_type, __VA_ARGS__)
+
const char *nm_utils_flags2str (const NMUtilsFlags2StrDesc *descs,
gsize n_descs,
unsigned flags,