diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-14 17:37:07 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-14 18:12:32 +0100 |
commit | fed599bb6f95e692b5f66ab3c497562bef64472c (patch) | |
tree | 3932078154cfb2fb66d32a97c706e4e8a8506c57 | |
parent | b2ff18692f0eec7b21e72340bfd96e744790bf14 (diff) | |
download | NetworkManager-fed599bb6f95e692b5f66ab3c497562bef64472c.tar.gz |
shared: add nm_strdup_maybe_a() helper macro
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 10 |
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. |