From cc36baa5c7a5573d1a6da4e5c8bee9a116a29535 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 Sep 2022 14:59:07 +0200 Subject: [PATCH] glib-aux: add nm_str_truncate() helper --- src/libnm-glib-aux/nm-macros-internal.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index f2a4461e2e..fe873d0e59 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -495,6 +495,17 @@ nm_strdup_not_empty(const char *str) return !nm_str_is_empty(str) ? g_strdup(str) : NULL; } +static inline char * +nm_str_truncate(char *str) +{ + /* This is trivial, and is only useful in a macro, to + * ensure that we access the macro argument only once. */ + nm_assert(str); + + str[0] = '\0'; + return str; +} + static inline char * nm_str_realloc(char *str) {