summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-01-05 15:55:54 +0100
committerThomas Haller <thaller@redhat.com>2021-01-08 15:24:43 +0100
commitef776e255dfd201bf27dea0d2ad0f3436cda778a (patch)
tree06f887a77d36be091f6dccf598aad6da9a3ed613
parentfc6475bbf7b17f0c9ac9b44f9acfbb9cbd62c9bd (diff)
downloadNetworkManager-ef776e255dfd201bf27dea0d2ad0f3436cda778a.tar.gz
shared: add nm_g_bytes_new_from_str() helper
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c15
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index ac922c0125..5bab4bd2f2 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -364,6 +364,21 @@ again:
return b;
}
+GBytes *
+nm_g_bytes_new_from_str(const char *str)
+{
+ gsize l;
+
+ if (!str)
+ return NULL;
+
+ /* the returned array is guaranteed to have a trailing '\0'
+ * character *after* the length. */
+
+ l = strlen(str);
+ return g_bytes_new_take(nm_memdup(str, l + 1u), l);
+}
+
/**
* nm_utils_gbytes_equals:
* @bytes: (allow-none): a #GBytes array to compare. Note that
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 5a9a4b0069..fe61459f5f 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -319,6 +319,8 @@ nm_utils_is_separator(const char c)
GBytes *nm_gbytes_get_empty(void);
+GBytes *nm_g_bytes_new_from_str(const char *str);
+
static inline gboolean
nm_gbytes_equal0(GBytes *a, GBytes *b)
{