diff options
author | Thomas Haller <thaller@redhat.com> | 2016-11-08 17:39:26 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-11-09 12:07:33 +0100 |
commit | e36f6a7e52737aedafed6ba55b0cc224eca7ac52 (patch) | |
tree | a6a6fa983ebe5ef1adda564ac9c5522c8202e154 | |
parent | 37bf6432134ca8ea3a2b6a15d035ff4721feb887 (diff) | |
download | NetworkManager-e36f6a7e52737aedafed6ba55b0cc224eca7ac52.tar.gz |
libnm: add nm_utils_uuid_generate_buf() util
-rw-r--r-- | libnm-core/nm-core-internal.h | 8 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 24 |
2 files changed, 25 insertions, 7 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 8fba357167..1b4c469420 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -194,6 +194,14 @@ char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_t char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED; +char *nm_utils_uuid_generate_buf_ (char *buf); +#define nm_utils_uuid_generate_buf(buf) \ + ({ \ + G_STATIC_ASSERT (sizeof (buf) == G_N_ELEMENTS (buf) && sizeof (buf) >= 37); \ + nm_utils_uuid_generate_buf_ (buf); \ + }) +#define nm_utils_uuid_generate_a() (nm_utils_uuid_generate_buf_ (g_alloca (37))) + void _nm_dbus_errors_init (void); extern gboolean _nm_utils_is_manager_process; diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index cfd97149ca..41b6304c82 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2147,24 +2147,34 @@ next: /*****************************************************************************/ /** - * nm_utils_uuid_generate: + * nm_utils_uuid_generate_buf_: + * @buf: input buffer, must contain at least 37 bytes * - * Returns: a newly allocated UUID suitable for use as the #NMSettingConnection - * object's #NMSettingConnection:id: property. Should be freed with g_free() + * Returns: generates a new random UUID, writes it to @buf and returns @buf. **/ char * -nm_utils_uuid_generate (void) +nm_utils_uuid_generate_buf_ (char *buf) { uuid_t uuid; - char *buf; - buf = g_malloc0 (37); uuid_generate_random (uuid); - uuid_unparse_lower (uuid, &buf[0]); + uuid_unparse_lower (uuid, buf); return buf; } /** + * nm_utils_uuid_generate: + * + * Returns: a newly allocated UUID suitable for use as the #NMSettingConnection + * object's #NMSettingConnection:id: property. Should be freed with g_free() + **/ +char * +nm_utils_uuid_generate (void) +{ + return nm_utils_uuid_generate_buf_ (g_malloc (37)); +} + +/** * nm_utils_uuid_generate_from_string: * @s: a string to use as the seed for the UUID * @slen: if negative, treat @s as zero terminated C string. |