Import uuid.h from lttng-tools
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 9 Dec 2021 16:44:07 +0000 (11:44 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 15 Jul 2022 18:02:31 +0000 (14:02 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idbbb9be64fb30efd1fe9393e15d1c4973bcae33d

include/lttng/uuid.h [new file with mode: 0644]
src/Kbuild
src/lttng-uuid.c [new file with mode: 0644]

diff --git a/include/lttng/uuid.h b/include/lttng/uuid.h
new file mode 100644 (file)
index 0000000..76e3ce8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ */
+
+#ifndef LTTNG_UUID_H
+#define LTTNG_UUID_H
+
+/*
+ * Includes final \0.
+ */
+#define LTTNG_UUID_STR_LEN     37
+#define LTTNG_UUID_LEN         16
+#define LTTNG_UUID_VER         4
+
+#define LTTNG_UUID_FMT \
+       "%02hhx%02hhx%02hhx%02hhx-%02hhx" \
+       "%02hhx-%02hhx%02hhx-%02hhx%02hhx" \
+       "-%02hhx%02hhx%02hhx%02hhx%02hhx" \
+       "%02hhx"
+
+#define LTTNG_UUID_FMT_VALUES(uuid) \
+       (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], \
+       (uuid)[6], (uuid)[7], (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], \
+       (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15]
+
+#define LTTNG_UUID_SCAN_VALUES(uuid) \
+       &(uuid)[0], &(uuid)[1], &(uuid)[2], &(uuid)[3], &(uuid)[4], &(uuid)[5], \
+       &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \
+       &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15]
+
+typedef unsigned char lttng_uuid[LTTNG_UUID_LEN];
+
+int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out);
+
+#endif /* LTTNG_UUID_H */
index 4aba1cd7e9dc9de16483e926f1d11557925e6a1d..a4f6dddd620c23c04f45d30870a49b445c5b5235 100644 (file)
@@ -71,7 +71,7 @@ lttng-tracer-objs := lib/msgpack/msgpack.o \
                      lttng-context-need-reschedule.o \
                      lttng-calibrate.o \
                      lttng-context-hostname.o \
-                    lttng-context-callstack.o \
+                     lttng-context-callstack.o \
                      probes/lttng.o \
                      lttng-tracker-id.o \
                      lttng-bytecode.o lttng-bytecode-interpreter.o \
@@ -79,7 +79,8 @@ lttng-tracer-objs := lib/msgpack/msgpack.o \
                      lttng-bytecode-validator.o \
                      probes/lttng-probe-user.o \
                      lttng-tp-mempool.o \
-                     lttng-event-notifier-notification.o
+                     lttng-event-notifier-notification.o \
+                     lttng-uuid.o
 
 lttng-wrapper-objs := wrapper/page_alloc.o \
                       wrapper/random.o \
diff --git a/src/lttng-uuid.c b/src/lttng-uuid.c
new file mode 100644 (file)
index 0000000..151b2fe
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <linux/module.h>
+#include <lttng/uuid.h>
+
+int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out)
+{
+       int ret = 0;
+       lttng_uuid uuid_scan;
+
+       if ((str_in == NULL) || (uuid_out == NULL)) {
+               ret = -1;
+               goto end;
+       }
+
+       if (strnlen(str_in, LTTNG_UUID_STR_LEN) != LTTNG_UUID_STR_LEN - 1) {
+               ret = -1;
+               goto end;
+       }
+
+       /* Scan to a temporary location in case of a partial match. */
+       if (sscanf(str_in, LTTNG_UUID_FMT, LTTNG_UUID_SCAN_VALUES(uuid_scan)) !=
+                       LTTNG_UUID_LEN) {
+               ret = -1;
+       }
+
+       memcpy(uuid_out, uuid_scan, LTTNG_UUID_LEN);
+end:
+       return ret;
+}
This page took 0.028982 seconds and 5 git commands to generate.