1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
.\"
.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2014 Andrew Stormont.
.\" Copyright 2021 Oxide Computer Company
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.Dd November 30, 2021
.Dt UUID_CLEAR 3UUID
.Os
.Sh NAME
.Nm uuid_clear ,
.Nm uuid_compare ,
.Nm uuid_copy ,
.Nm uuid_generate ,
.Nm uuid_generate_random ,
.Nm uuid_generate_time ,
.Nm uuid_is_null ,
.Nm uuid_parse ,
.Nm uuid_time ,
.Nm uuid_unparse ,
.Nm uuid_unparse_lower ,
.Nm uuid_unparse_upper
.Nd universally unique identifier (UUID) operations
.Sh LIBRARY
.Lb libuuid
.Sh SYNOPSIS
.In uuid/uuid.h
.Ft void
.Fo uuid_clear
.Fa "uuid_t uu"
.Fc
.Ft int
.Fo uuid_compare
.Fa "uuid_t uu1"
.Fa "uuid_t uu2"
.Fc
.Ft void
.Fo uuid_copy
.Fa "uuid_t dst"
.Fa "uuid_t src"
.Fc
.Ft void
.Fo uuid_generate
.Fa "uuid_t out"
.Fc
.Ft void
.Fo uuid_generate_random
.Fa "uuid_t out"
.Fc
.Ft void
.Fo uuid_generate_time
.Fa "uuid_t out"
.Fc
.Ft int
.Fo uuid_is_null
.Fa "uuid_t uu"
.Fc
.Ft int
.Fo uuid_parse
.Fa "char *int"
.Fa "uuid_t uu"
.Fc
.Ft time_t
.Fo uuid_time
.Fa "uuid_t uu"
.Fa "struct timeval *ret_tv"
.Fc
.Ft void
.Fo uuid_unparse
.Fa "uuid_t uu"
.Fa "char *out"
.Fc
.Ft void
.Fo uuid_unparse_lower
.Fa "uuid_t uu"
.Fa "char *out"
.Fc
.Ft void
.Fo uuid_unparse_upper
.Fa "uuid_t uu"
.Fa "char *out"
.Fc
.Sh DESCRIPTION
The
.Fn uuid_clear
function sets the value of the specified universally unique identifier
.Pq UUID
variable
.Fa uu
to the NULL value.
.Pp
The
.Fn uuid_compare
function compares the two specified UUID variables
.Fa uu1
and
.Fa uu2
to each other.
It returns an integer less than, equal to, or greater than zero if
.Fa uu1
is found to be, respectively, lexicographically less than, equal, or greater
than
.Fa uu2 .
.Pp
The
.Fn uuid_copy
function copies the UUID variable
.Fa src
to
.Fa dst .
.Pp
The
.Fn uuid_generate
and
.Fn uuid_generate_random
functions create a new UUID that is generated based on high-quality randomness
utilizing the
.Xr arc4random 3C
function.
These correspond to a DCE version 4 UUID.
On some implementations it is possible that the
.Fn uuid_generate
function will fall back to generating a version 1 UUID.
While in our current implementation this is not possible, applications should
not assume a guaranteed format when calling the
.Fn uuid_generate
function.
.Pp
The
.Fn uuid_generate_time
function uses the current time and the local Ethernet MAC address
.Pq if available, otherwise a MAC address is fabricated
that corresponds to a DCE version 1 UUID.
If the UUID is not guaranteed to be unique, the multicast bit is set
.Pq the high-order bit of octet number 10 .
.Pp
The
.Fn uuid_is_null
function compares the value of the specified UUID variable
.Fa uu
to the NULL value.
If the value is equal to the NULL UUID,
.Sy 1
is returned.
Otherwise
.Sy 0
is returned.
.Pp
The
.Fn uuid_parse
function converts the UUID string specified by
.Fa in
to the internal
.Vt uuid_t
format.
The input UUID is a string of the form
.Sy cefa7a9c-1dd2-11b2-8350-880020adbeef .
In
.Xr printf 3C
format, the string is
.Dq Sy %08x-%04x-%04x-%04x-%012x ,
36 bytes plus the trailing null character.
If the input string is parsed successfully,
.Sy 0
is returned and the UUID is stored in the location pointed to by
.Fa uu .
Otherwise
.Sy -1
is returned.
.Pp
The
.Fn uuid_time
function extracts the time at which the specified UUID
.Fa uu
was created.
Since the UUID creation time is encoded within the UUID, this function can
reasonably be expected to extract the creation time only for UUIDs created with
the
.Fn uuid_generate_time
function.
The time at which the UUID was created, in seconds since January 1, 1970 GMT
.Pq the epoch ,
is returned
.Po
see
.Xr time 2
.Pc .
The time at which the UUID was created, in seconds and microseconds since the
epoch is also stored in the location pointed to by
.Fa ret_tv
.Po
see
.Xr gettimeofday 3C
.Pc .
.Pp
The
.Fn uuid_unparse
and
.Fn uuid_unparse_lower
functions convert the specified UUID
.Fa uu
from the internal binary format to a lower case string of the length defined in
the
.In uuid/uuid.h
macro,
.Dv UUID_PRINTABLE_STRING_LENGTH ,
which includes the trailing null character.
The resulting value is stored in the character string pointed to by
.Fa out .
.Pp
The uuid_unparse_upper
function converts the specified UUID
.Fa uu
from the internal binary format to a upper case string of the length defined in
the
.In uuid/uuid.h
macro,
.Dv UUID_PRINTABLE_STRING_LENGTH ,
which includes the trailing null character.
The resulting value is stored in the character string pointed to by
.Fa out .
.Sh INTERFACE STABILITY
.Sy Evolving
.Sh MT-LEVEL
.Sy Safe
.Sh SEE ALSO
.Xr time 2 ,
.Xr arc4random 3C ,
.Xr gettimeofday 3C ,
.Xr printf 3C ,
.Xr libuuid 3LIB ,
.Xr attributes 7
|