blob: c38b0fe46972e38f916c4fc3dfebdf876fdf1a88 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawson05b1bac2018-09-04 12:00:08 -06002
3#ifndef _UUID_H_
4#define _UUID_H_
5
6#include <string.h>
Raul E Rangel3b8284f2020-05-27 20:40:59 -06007#include <stdint.h>
Marshall Dawson05b1bac2018-09-04 12:00:08 -06008
Nico Huber2e6a0f82019-10-24 15:01:33 +02009#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 */
23int parse_uuid(uint8_t *uuid, const char *uuid_str);
24
Marshall Dawson05b1bac2018-09-04 12:00:08 -060025typedef 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
36static inline int guidcmp(const guid_t *guid1, const guid_t *guid2)
37{
38 return memcmp(guid1, guid2, sizeof(guid_t));
39}
40
41static 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_ */