blob: f6e3450558983cedb9f1d2484d44c555fa49f5cb [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>
7
Nico Huber2e6a0f82019-10-24 15:01:33 +02008#define UUID_LEN 16
9#define UUID_STRLEN 36
10
11/*
12 * Parses a canonical UUID string into the common byte representation
13 * where the first three words are interpreted as little endian:
14 *
15 * The UUID
16 * "00112233-4455-6677-8899-aabbccddeeff"
17 * is stored as
18 * 33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff
19 *
20 * Returns negative value on error, 0 on success.
21 */
22int parse_uuid(uint8_t *uuid, const char *uuid_str);
23
Marshall Dawson05b1bac2018-09-04 12:00:08 -060024typedef struct {
25 uint8_t b[16];
26} __packed guid_t;
27
28#define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
29((guid_t) \
30{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
31 (b) & 0xff, ((b) >> 8) & 0xff, \
32 (c) & 0xff, ((c) >> 8) & 0xff, \
33 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
34
35static inline int guidcmp(const guid_t *guid1, const guid_t *guid2)
36{
37 return memcmp(guid1, guid2, sizeof(guid_t));
38}
39
40static inline guid_t *guidcpy(guid_t *dest, const guid_t *src)
41{
42 return (guid_t *)memcpy(dest, src, sizeof(guid_t));
43}
44
45#endif /* _UUID_H_ */