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