summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-08 16:55:03 +0200
committerThomas Haller <thaller@redhat.com>2020-09-08 12:40:27 +0200
commit3ac2ded9b71715ef1d7e84991b1e9a6111a2ff84 (patch)
tree2e418a75814cd56dfcd4723cc522a05c815c7603
parentd95e69f3dd611b26c7963d7292d2ad44a9d612d2 (diff)
downloadNetworkManager-3ac2ded9b71715ef1d7e84991b1e9a6111a2ff84.tar.gz
shared: add nm_utils_buf_utf8safe_escape_cp() helper
(cherry picked from commit 393bc8c8f66a852e04e2328675bdb0a26066cd0b) (cherry picked from commit 10b0260d1931a768877da103515c891ee6a7abf9) (cherry picked from commit ff8ba801f32504c87af7a0f977a47d2118898e78)
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c11
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 1c672d2c70..7462d02bee 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -2114,6 +2114,17 @@ nm_utils_buf_utf8safe_escape_bytes (GBytes *bytes, NMUtilsStrUtf8SafeFlags flags
return nm_utils_buf_utf8safe_escape (p, l, flags, to_free);
}
+char *
+nm_utils_buf_utf8safe_escape_cp (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags)
+{
+ const char *s_const;
+ char *s;
+
+ s_const = nm_utils_buf_utf8safe_escape (buf, buflen, flags, &s);
+ nm_assert (!s || s == s_const);
+ return s ?: g_strdup (s_const);
+}
+
/*****************************************************************************/
const char *
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index e0b6adafdd..fd1453db93 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -889,6 +889,7 @@ typedef enum {
} NMUtilsStrUtf8SafeFlags;
const char *nm_utils_buf_utf8safe_escape (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags, char **to_free);
+char *nm_utils_buf_utf8safe_escape_cp (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags);
const char *nm_utils_buf_utf8safe_escape_bytes (GBytes *bytes, NMUtilsStrUtf8SafeFlags flags, char **to_free);
gconstpointer nm_utils_buf_utf8safe_unescape (const char *str, gsize *out_len, gpointer *to_free);