Skip to content

Commit

Permalink
Add copy function
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Orru <[email protected]>
  • Loading branch information
sorru94 committed Oct 3, 2024
1 parent 81279e0 commit 45c85d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/zephyr/sys/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/uuid/uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 45c85d4

Please sign in to comment.