1SD_ID128_TO_STRING(3) sd_id128_to_string SD_ID128_TO_STRING(3)
2
3
4
6 sd_id128_to_string, SD_ID128_TO_STRING, SD_ID128_STRING_MAX,
7 sd_id128_to_uuid_string, SD_ID128_TO_UUID_STRING,
8 SD_ID128_UUID_STRING_MAX, sd_id128_from_string - Format or parse
9 128-bit IDs as strings
10
12 #include <systemd/sd-id128.h>
13
14 #define SD_ID128_STRING_MAX 33U
15
16 #define SD_ID128_UUID_STRING_MAX 37U
17
18 #define SD_ID128_TO_STRING(id) ...
19
20 #define SD_ID128_TO_UUID_STRING(id) ...
21
22 char
23 *sd_id128_to_string(sd_id128_t id, char s[static SD_ID128_STRING_MAX]);
24
25 char
26 *sd_id128_uuid_string(sd_id128_t id, char s[static SD_ID128_UUID_STRING_MAX]);
27
28 int sd_id128_from_string(const char *s, sd_id128_t *ret);
29
31 sd_id128_to_string() formats a 128-bit ID as a character string. It
32 expects the ID and a string array capable of storing 33 characters
33 (SD_ID128_STRING_MAX). The ID will be formatted as 32 lowercase
34 hexadecimal digits and be terminated by a NUL byte.
35
36 SD_ID128_TO_STRING() is a macro that wraps sd_id128_to_string() and
37 passes an appropriately sized buffer as second argument, allocated as
38 C99 compound literal. Each use will thus implicitly acquire a suitable
39 buffer on the stack which remains valid until the end of the current
40 code block. This is usually the simplest way to acquire a string
41 representation of a 128-bit ID in a buffer that is valid in the current
42 code block.
43
44 sd_id128_to_uuid_string() and SD_ID128_TO_UUID_STRING() are similar to
45 these two functions/macros, but format the 128-bit values as RFC4122
46 UUIDs, i.e. a series of 36 lowercase hexadeciaml digits and dashes,
47 terminated by a NUL byte.
48
49 sd_id128_from_string() implements the reverse operation: it takes a 33
50 character string with 32 hexadecimal digits (either lowercase or
51 uppercase, terminated by NUL) and parses them back into a 128-bit ID
52 returned in ret. Alternatively, this call can also parse a 37-character
53 string with a 128-bit ID formatted as RFC UUID. If ret is passed as
54 NULL the function will validate the passed ID string, but not actually
55 return it in parsed form.
56
57 Note that when formatting and parsing 36 character UUIDs this is done
58 strictly in Big Endian byte order, i.e. according to RFC4122[1] Variant
59 1 rules, even if the UUID encodes a different variant. This matches
60 behaviour in various other Linux userspace tools. It's probably wise to
61 avoid UUIDs of other variant types.
62
63 For more information about the "sd_id128_t" type see sd-id128(3). Note
64 that these calls operate the same way on all architectures, i.e. the
65 results do not depend on endianness.
66
67 When formatting a 128-bit ID into a string, it is often easier to use a
68 format string for printf(3). This is easily done using the
69 SD_ID128_FORMAT_STR and SD_ID128_FORMAT_VAL() macros. For more
70 information see sd-id128(3).
71
73 sd_id128_to_string() always succeeds and returns a pointer to the
74 string array passed in. sd_id128_from_string() returns 0 on success,
75 in which case ret is filled in, or a negative errno-style error code.
76
78 Functions described here are available as a shared library, which can
79 be compiled against and linked to with the libsystemd pkg-config(1)
80 file.
81
82 The code described here uses getenv(3), which is declared to be not
83 multi-thread-safe. This means that the code calling the functions
84 described here must not call setenv(3) from a parallel thread. It is
85 recommended to only do calls to setenv() from an early phase of the
86 program when no other threads have been started.
87
89 systemd(1), sd-id128(3), printf(3)
90
92 1. RFC4122
93 https://tools.ietf.org/html/rfc4122
94
95
96
97systemd 254 SD_ID128_TO_STRING(3)