summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-20 19:43:23 +0200
committerThomas Haller <thaller@redhat.com>2020-06-26 09:29:52 +0200
commit069be33fbdc0a6f925795b9ac7bdc7712b9799ba (patch)
treeedb08ff877d81d9b13b7868a311cfe35109d768c
parentd53abfd9898e33d375693837cc491168a986b450 (diff)
downloadNetworkManager-069be33fbdc0a6f925795b9ac7bdc7712b9799ba.tar.gz
shared: add nm_hexchar() helper
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c3
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h11
2 files changed, 14 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 48635df343..8290016448 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -23,6 +23,9 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMUtilsNamedValue, value_ptr) == sizeof (const
/*****************************************************************************/
+const char _nm_hexchar_table_lower[16] = "0123456789abcdef";
+const char _nm_hexchar_table_upper[16] = "0123456789ABCDEF";
+
const void *const _NM_PTRARRAY_EMPTY[1] = { NULL };
/*****************************************************************************/
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 589275739c..43b8288b0a 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1809,6 +1809,17 @@ int nm_utils_getpagesize (void);
/*****************************************************************************/
+extern const char _nm_hexchar_table_lower[16];
+extern const char _nm_hexchar_table_upper[16];
+
+static inline char
+nm_hexchar (int x, gboolean upper_case)
+{
+ return upper_case
+ ? _nm_hexchar_table_upper[x & 15]
+ : _nm_hexchar_table_lower[x & 15];
+}
+
char *nm_utils_bin2hexstr_full (gconstpointer addr,
gsize length,
char delimiter,