UUIDGEN(2)
β¨ UUIDGEN(2) β¨
okay bestie, welcome to the system calls manual π this one's called uuidgen and it lives in section 2, so it's a syscall, not some lil command-line tool (that's a different page, we'll get there). buckle up π
π NAME π
uuidgen β generate universally unique identifiers π
π LIBRARY π
Standard C Library (libc, -lc) π«Ά
π¦ SYNOPSIS π¦
#include <sys/uuid.h>
int
uuidgen(struct uuid *store, int count);
π DESCRIPTION π
so like. the uuidgen() system call generates count universally unique identifiers (UUIDs, bestie) and writes them into the buffer that store points at. they're generated according to the syntax and semantics of the DCE version 1 variant of universally unique identifiers β and yeah, there's a whole deeper breakdown of the identifiers down below, we're getting there, don't rush me π
when there's no IEEE 802 address available for the node field? a random multicast address gets generated for each invocation of the system call. and per the algorithm for generating time-based UUIDs, that also forces a new random clock sequence, which just makes the identifier even more likely to be unique. it's giving "we did our best and our best is very good actually" β¨
when multiple identifiers are generated, uuidgen() produces a set that is dense β meaning there is no identifier that is larger than the smallest identifier in the set and smaller than the largest identifier in the set and that is not already in the set. no gaps, no crumbs, fully contiguous, periodt π
universally unique identifiers β also known as globally unique identifiers (GUIDs), iykyk β have a binary representation of 128 bits. the grouping and meaning of those bits is described by this structure, plus the field descriptions that follow it:
struct uuid {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_version;
uint8_t clock_seq_hi_and_reserved;
uint8_t clock_seq_low;
uint8_t node[_UUID_NODE_LEN];
};
time_lowβ the least significant 32 bits of a 60-bit timestamp. this field is stored in the native byte-order. πtime_midβ the least significant 16 bits of the most significant 28 bits of the 60-bit timestamp. stored in the native byte-order.time_hi_and_versionβ the most significant 12 bits of the 60-bit timestamp, multiplexed with a 4-bit version number. the version number is stored in the most significant 4 bits of the 16-bit field. stored in the native byte-order.clock_seq_hi_and_reservedβ the most significant 6 bits of a 14-bit sequence number, multiplexed with a 2-bit variant value. heads up: the width of the variant value is determined by the variant itself. identifiers generated byuuidgen()have variant value 10b. the variant value is stored in the most significant bits of the field.clock_seq_lowβ the least significant 8 bits of a 14-bit sequence number.nodeβ the 6-byte IEEE 802 (MAC) address of one of the interfaces of the node. if no such interface exists, a random multi-cast address is used instead.
and here's the tea π«: the binary representation is sensitive to byte ordering. any multi-byte field is to be stored in the local or native byte-order, and identifiers must be converted when transmitted to hosts that do not agree on the byte-order. the specification does not document what this means in concrete terms though, and it's otherwise beyond the scope of this system call. so like. good luck, bestie π
π« RETURN VALUES π«
upon successful completion, the value 0 is returned. otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic. π
π₯ ERRORS π₯
the uuidgen() system call can fail with:
[EFAULT]β the buffer pointed to bystorecould not be written to, for any or all identifiers. π[EINVAL]β thecountargument is less than1or larger than the hard upper limit of2048.
π SEE ALSO π
πΈ STANDARDS πΈ
the identifiers are represented and generated in conformance with the DCE 1.1 RPC specification. the uuidgen() system call is itself not part of the specification. it's the icon that wasn't on the original guest list, and honestly? still slayed π
β HISTORY β
the uuidgen() system call first appeared in FreeBSD 5.0. β¨
and that's the whole page, bestie!! this one's from Debian, May 26, 2002 β yes it's older than us, and no, we're not gonna say anything about it π«Ά go forth and generate those UUIDs, you're gonna eat π ππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2002 Marcel Moolenaar
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms