blob: 2c79dfbdc4274cb5b51706cb04be1193b0868796 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Ambroise Vincent602b7f52019-02-11 14:13:43 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <stdio.h>
9#include <string.h>
10#include <uuid_utils.h>
11
12/* Format string to print a UUID */
Ambroise Vincent602b7f52019-02-11 14:13:43 +000013static const char *uuid_str_fmt = "{ 0x%08x, 0x%04x, 0x%04x, 0x%02x, 0x%02x, "
14 "0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x }";
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020015
16
17unsigned int is_uuid_null(const uuid_t *uuid)
18{
19 const uuid_t uuid_null = {0};
20
21 return memcmp(uuid, &uuid_null, sizeof(uuid_t)) == 0;
22}
23
24char *uuid_to_str(const uuid_t *uuid, char *str)
25{
26 assert(uuid != NULL);
27 assert(str != NULL);
28
29 snprintf(str, UUID_STR_SIZE, uuid_str_fmt,
30 uuid->time_low, uuid->time_mid, uuid->time_hi_and_version,
31 uuid->clock_seq_hi_and_reserved, uuid->clock_seq_low,
32 uuid->node[0], uuid->node[1], uuid->node[2], uuid->node[3],
33 uuid->node[4], uuid->node[5]);
34
35 return str;
36}
37
38unsigned int uuid_equal(const uuid_t *uuid1, const uuid_t *uuid2)
39{
40 return memcmp(uuid1, uuid2, sizeof(uuid_t)) == 0;
41}
42
43uuid_t *make_uuid_from_4words(uuid_t *uuid,
44 uint32_t w0,
45 uint32_t w1,
46 uint32_t w2,
47 uint32_t w3)
48{
49 uint32_t *uuid32;
50
51 assert(uuid != NULL);
52
53 uuid32 = (uint32_t *) uuid;
54 uuid32[0] = w0;
55 uuid32[1] = w1;
56 uuid32[2] = w2;
57 uuid32[3] = w3;
58
59 return uuid;
60}