xref: /aosp_15_r20/external/coreboot/src/include/uuid.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _UUID_H_
4 #define _UUID_H_
5 
6 #include <string.h>
7 #include <stdint.h>
8 
9 #define UUID_LEN	16
10 #define UUID_STRLEN	36
11 
12 /*
13  * Parses a canonical UUID string into the common byte representation
14  * where the first three words are interpreted as little endian:
15  *
16  * The UUID
17  *   "00112233-4455-6677-8899-aabbccddeeff"
18  * is stored as
19  *   33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff
20  *
21  * Returns negative value on error, 0 on success.
22  */
23 int parse_uuid(uint8_t *uuid, const char *uuid_str);
24 
25 typedef struct {
26 	uint8_t b[16];
27 } __packed guid_t;
28 
29 #define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)		\
30 ((guid_t)								\
31 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
32    (b) & 0xff, ((b) >> 8) & 0xff,					\
33    (c) & 0xff, ((c) >> 8) & 0xff,					\
34    (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
35 
guidcmp(const guid_t * guid1,const guid_t * guid2)36 static inline int guidcmp(const guid_t *guid1, const guid_t *guid2)
37 {
38 	return memcmp(guid1, guid2, sizeof(guid_t));
39 }
40 
guidcpy(guid_t * dest,const guid_t * src)41 static inline guid_t *guidcpy(guid_t *dest, const guid_t *src)
42 {
43 	return (guid_t *)memcpy(dest, src, sizeof(guid_t));
44 }
45 
46 #endif /* _UUID_H_ */
47