Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 05b1bac | 2018-09-04 12:00:08 -0600 | [diff] [blame] | 2 | |
| 3 | #ifndef _UUID_H_ |
| 4 | #define _UUID_H_ |
| 5 | |
| 6 | #include <string.h> |
| 7 | |
Nico Huber | 2e6a0f8 | 2019-10-24 15:01:33 +0200 | [diff] [blame] | 8 | #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 | */ |
| 22 | int parse_uuid(uint8_t *uuid, const char *uuid_str); |
| 23 | |
Marshall Dawson | 05b1bac | 2018-09-04 12:00:08 -0600 | [diff] [blame] | 24 | typedef 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 | |
| 35 | static inline int guidcmp(const guid_t *guid1, const guid_t *guid2) |
| 36 | { |
| 37 | return memcmp(guid1, guid2, sizeof(guid_t)); |
| 38 | } |
| 39 | |
| 40 | static 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_ */ |