shared: add nm_g_bytes_new_from_str() helper

This commit is contained in:
Thomas Haller
2021-01-05 15:55:54 +01:00
parent fc6475bbf7
commit ef776e255d
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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)
{