.\" .\" 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