]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright (C) 1996, 1997, 1998 Theodore Ts'o. | |
11fdf7f2 TL |
3 | */ |
4 | /** | |
5 | * @file | |
6 | * | |
7 | * UUID related functions originally from libuuid | |
8 | */ | |
9 | ||
10 | #ifndef _RTE_UUID_H_ | |
11 | #define _RTE_UUID_H_ | |
12 | ||
13 | #ifdef __cplusplus | |
14 | extern "C" { | |
15 | #endif | |
16 | ||
17 | #include <stdbool.h> | |
18 | ||
19 | /** | |
9f95a23c | 20 | * Struct describing a Universal Unique Identifier |
11fdf7f2 TL |
21 | */ |
22 | typedef unsigned char rte_uuid_t[16]; | |
23 | ||
24 | /** | |
25 | * Helper for defining UUID values for id tables. | |
26 | */ | |
27 | #define RTE_UUID_INIT(a, b, c, d, e) { \ | |
28 | ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, \ | |
29 | ((a) >> 8) & 0xff, (a) & 0xff, \ | |
30 | ((b) >> 8) & 0xff, (b) & 0xff, \ | |
31 | ((c) >> 8) & 0xff, (c) & 0xff, \ | |
32 | ((d) >> 8) & 0xff, (d) & 0xff, \ | |
33 | ((e) >> 40) & 0xff, ((e) >> 32) & 0xff, \ | |
34 | ((e) >> 24) & 0xff, ((e) >> 16) & 0xff, \ | |
35 | ((e) >> 8) & 0xff, (e) & 0xff \ | |
36 | } | |
37 | ||
38 | /** | |
39 | * Test if UUID is all zeros. | |
40 | * | |
41 | * @param uu | |
42 | * The uuid to check. | |
43 | * @return | |
44 | * true if uuid is NULL value, false otherwise | |
45 | */ | |
46 | bool rte_uuid_is_null(const rte_uuid_t uu); | |
47 | ||
48 | /** | |
49 | * Copy uuid. | |
50 | * | |
51 | * @param dst | |
52 | * Destination uuid | |
53 | * @param src | |
54 | * Source uuid | |
55 | */ | |
56 | static inline void rte_uuid_copy(rte_uuid_t dst, const rte_uuid_t src) | |
57 | { | |
58 | memcpy(dst, src, sizeof(rte_uuid_t)); | |
59 | } | |
60 | ||
61 | /** | |
62 | * Compare two UUID's | |
63 | * | |
64 | * @param a | |
65 | * A UUID to compare | |
66 | * @param b | |
67 | * A UUID to compare | |
68 | * @return | |
69 | * returns an integer less than, equal to, or greater than zero if UUID a is | |
70 | * is less than, equal, or greater than UUID b. | |
71 | */ | |
72 | int rte_uuid_compare(const rte_uuid_t a, const rte_uuid_t b); | |
73 | ||
74 | /** | |
75 | * Extract UUID from string | |
76 | * | |
77 | * @param in | |
78 | * Pointer to string of characters to convert | |
79 | * @param uu | |
80 | * Destination UUID | |
81 | * @return | |
9f95a23c | 82 | * Returns 0 on success, and -1 if string is not a valid UUID. |
11fdf7f2 TL |
83 | */ |
84 | int rte_uuid_parse(const char *in, rte_uuid_t uu); | |
85 | ||
86 | /** | |
87 | * Convert UUID to string | |
88 | * | |
89 | * @param uu | |
90 | * UUID to format | |
91 | * @param out | |
92 | * Resulting string buffer | |
93 | * @param len | |
94 | * Sizeof the available string buffer | |
95 | */ | |
96 | #define RTE_UUID_STRLEN (36 + 1) | |
97 | void rte_uuid_unparse(const rte_uuid_t uu, char *out, size_t len); | |
98 | ||
99 | #ifdef __cplusplus | |
100 | } | |
101 | #endif | |
102 | ||
103 | #endif /* RTE_UUID_H */ |