diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-14 17:37:07 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-15 09:36:30 +0100 |
commit | e884ef39ed7dbfe21ab8db74aa22e23750ce648e (patch) | |
tree | 558af72c9ae02b51b004ec697e0283524cef667f /shared/nm-glib-aux/nm-macros-internal.h | |
parent | a1d9a7922874fc972a13b2a117b8e057eaf819af (diff) | |
download | NetworkManager-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.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. |