summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-06 16:05:26 +0100
committerThomas Haller <thaller@redhat.com>2020-11-09 17:25:24 +0100
commitc4d981959eac8c3beeecba8e8436ebda707f553c (patch)
treed4888b24f64830d2ad80b55f37fc74fba56c6070
parentac626c689251409fb4731071e0208b12e30d80df (diff)
downloadNetworkManager-c4d981959eac8c3beeecba8e8436ebda707f553c.tar.gz
shared: add nm_utils_strdup_reset_take() helper
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index e8aba6104c..1e2c482549 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -2204,6 +2204,25 @@ nm_utils_strdup_reset(char **dst, const char *src)
return TRUE;
}
+static inline gboolean
+nm_utils_strdup_reset_take(char **dst, char *src)
+{
+ char *old;
+
+ nm_assert(dst);
+ nm_assert(src != *dst);
+
+ if (nm_streq0(*dst, src)) {
+ if (src)
+ g_free(src);
+ return FALSE;
+ }
+ old = *dst;
+ *dst = src;
+ g_free(old);
+ return TRUE;
+}
+
void nm_indirect_g_free(gpointer arg);
/*****************************************************************************/