From 45c85d401136cf621436617fde82a215b595e138 Mon Sep 17 00:00:00 2001 From: Simone Orru Date: Thu, 3 Oct 2024 15:22:47 +0200 Subject: [PATCH] Add copy function Signed-off-by: Simone Orru --- include/zephyr/sys/uuid.h | 11 +++++++++++ lib/uuid/uuid.c | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/include/zephyr/sys/uuid.h b/include/zephyr/sys/uuid.h index 3a84703713409a..fbb657ebf179a2 100644 --- a/include/zephyr/sys/uuid.h +++ b/include/zephyr/sys/uuid.h @@ -75,6 +75,17 @@ int uuid_generate_v4(uuid_t out); */ int uuid_generate_v5(const uuid_t namespace, const void *data, size_t data_size, uuid_t out); +/** + * @brief Copy an UUID into another UUID. + * + * @param dst Destination for the copy. + * @param src Source for the copy. + * + * @retval 0 The UUID has been correctly copied in @p dst + * @retval -EINVAL @p dst or @p src are not acceptable + */ +int uuid_copy(uuid_t dst, const uuid_t src); + /** * @brief Create a uuid_t from a binary (big-endian) formatted UUID. * diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index bd6ae57c3ad13f..26c2b966fc16de 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -136,6 +136,15 @@ int uuid_generate_v5(const uuid_t namespace, const void *data, size_t data_size, } #endif +int uuid_copy(uuid_t dst, const uuid_t src) +{ + if ((dst == NULL) || (src == NULL)) { + return -EINVAL; + } + memcpy(dst, src, UUID_SIZE); + return 0; +} + int uuid_from_buffer(const uint8_t data[UUID_SIZE], uuid_t out) { if ((data == NULL) || (out == NULL)) {