Commit | Line | Data |
---|---|---|
4d599388 FD |
1 | /* |
2 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com> | |
4 | * | |
5 | * SPDX-License-Identifier: LGPL-2.1-only | |
6 | * | |
7 | */ | |
8 | ||
9 | #include <linux/module.h> | |
10 | #include <lttng/uuid.h> | |
11 | ||
12 | int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out) | |
13 | { | |
14 | int ret = 0; | |
15 | lttng_uuid uuid_scan; | |
16 | ||
17 | if ((str_in == NULL) || (uuid_out == NULL)) { | |
18 | ret = -1; | |
19 | goto end; | |
20 | } | |
21 | ||
22 | if (strnlen(str_in, LTTNG_UUID_STR_LEN) != LTTNG_UUID_STR_LEN - 1) { | |
23 | ret = -1; | |
24 | goto end; | |
25 | } | |
26 | ||
27 | /* Scan to a temporary location in case of a partial match. */ | |
28 | if (sscanf(str_in, LTTNG_UUID_FMT, LTTNG_UUID_SCAN_VALUES(uuid_scan)) != | |
29 | LTTNG_UUID_LEN) { | |
30 | ret = -1; | |
31 | } | |
32 | ||
33 | memcpy(uuid_out, uuid_scan, LTTNG_UUID_LEN); | |
34 | end: | |
35 | return ret; | |
36 | } |