From cd45ad4acfeaab286176154d8b23b0364dd6c4f0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 2 May 2021 10:01:32 +0200 Subject: [PATCH] glib-aux: add nm_uuid_unparse() --- src/libnm-glib-aux/nm-uuid.c | 25 +++++++++++++++++++++++++ src/libnm-glib-aux/nm-uuid.h | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 38d9826a3a..485dd4d611 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -3,3 +3,28 @@ #include "libnm-glib-aux/nm-default-glib.h" #include "nm-uuid.h" + +/*****************************************************************************/ + +char * +nm_uuid_unparse_case(const NMUuid *uuid, char out_str[static 37], gboolean upper_case) +{ + char *s; + int i; + + nm_assert(uuid); + nm_assert(out_str); + + s = out_str; + for (i = 0; i < 16; i++) { + const guint8 c = uuid->uuid[i]; + + if (NM_IN_SET(i, 4, 6, 8, 10)) + *(s++) = '-'; + *(s++) = nm_hexchar(c >> 4, upper_case); + *(s++) = nm_hexchar(c, upper_case); + } + *s = '\0'; + + return out_str; +} diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index dea52b94ce..bfae517132 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -7,4 +7,12 @@ typedef struct _NMUuid { guint8 uuid[16]; } NMUuid; +char *nm_uuid_unparse_case(const NMUuid *uuid, char out_str[static 37], gboolean upper_case); + +static inline char * +nm_uuid_unparse(const NMUuid *uuid, char out_str[static 37]) +{ + return nm_uuid_unparse_case(uuid, out_str, FALSE); +} + #endif /* __NM_UUID_H__ */