From 5be0113b0953e109d25f0621be37d58ee85f74d4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 8 Jun 2020 16:55:03 +0200 Subject: [PATCH] shared: add nm_utils_buf_utf8safe_escape_cp() helper (cherry picked from commit 393bc8c8f66a852e04e2328675bdb0a26066cd0b) (cherry picked from commit 10b0260d1931a768877da103515c891ee6a7abf9) (cherry picked from commit ff8ba801f32504c87af7a0f977a47d2118898e78) (cherry picked from commit 5838f827072fc774d3efec1b2262a36714543aa9) --- shared/nm-glib-aux/nm-shared-utils.c | 11 +++++++++++ shared/nm-glib-aux/nm-shared-utils.h | 1 + 2 files changed, 12 insertions(+) diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 62753dc06e..c8ba114f8d 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -2095,6 +2095,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 e069366afc..7e83078672 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -860,6 +860,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);