summaryrefslogtreecommitdiff
path: root/shared/nm-glib-aux/nm-macros-internal.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-01-14 17:37:07 +0100
committerThomas Haller <thaller@redhat.com>2021-01-15 09:36:30 +0100
commite884ef39ed7dbfe21ab8db74aa22e23750ce648e (patch)
tree558af72c9ae02b51b004ec697e0283524cef667f /shared/nm-glib-aux/nm-macros-internal.h
parenta1d9a7922874fc972a13b2a117b8e057eaf819af (diff)
downloadNetworkManager-e884ef39ed7dbfe21ab8db74aa22e23750ce648e.tar.gz
shared: add nm_strdup_maybe_a() helper macro
Diffstat (limited to 'shared/nm-glib-aux/nm-macros-internal.h')
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 4ce787ad1d..113a67a0d2 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -1612,6 +1612,16 @@ _nm_strndup_a_step(char *s, const char *str, gsize len)
_nm_strndup_a_step(_s_snd, _str_snd, _len_snd); \
})
+#define nm_strdup_maybe_a(alloca_maxlen, str, out_str_free) \
+ ({ \
+ const char *const _str_snd = (str); \
+ \
+ (char *) nm_memdup_maybe_a(alloca_maxlen, \
+ _str_snd, \
+ _str_snd ? strlen(_str_snd) + 1u : 0u, \
+ out_str_free); \
+ })
+
/*****************************************************************************/
/* generic macro to convert an int to a (heap allocated) string.