]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd-id128.xml
Merge pull request #17732 from yuwata/core-use-synthetic_errno
[thirdparty/systemd.git] / man / sd-id128.xml
CommitLineData
12355095 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
12355095 5
6a70f3aa 6<refentry id="sd-id128"
798d3a52
ZJS
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>sd-id128</title>
11 <productname>systemd</productname>
798d3a52
ZJS
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>sd-id128</refentrytitle>
16 <manvolnum>3</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>sd-id128</refname>
21 <refname>sd_id128_t</refname>
22 <refname>SD_ID128_MAKE</refname>
2b044526 23 <refname>SD_ID128_MAKE_STR</refname>
3dbea941 24 <refname>SD_ID128_NULL</refname>
798d3a52
ZJS
25 <refname>SD_ID128_CONST_STR</refname>
26 <refname>SD_ID128_FORMAT_STR</refname>
38df8d3f 27 <refname>SD_ID128_UUID_FORMAT_STR</refname>
798d3a52
ZJS
28 <refname>SD_ID128_FORMAT_VAL</refname>
29 <refname>sd_id128_equal</refname>
3dbea941 30 <refname>sd_id128_is_null</refname>
798d3a52
ZJS
31 <refpurpose>APIs for processing 128-bit IDs</refpurpose>
32 </refnamediv>
33
34 <refsynopsisdiv>
35 <funcsynopsis>
36 <funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
37 </funcsynopsis>
38
39 <cmdsynopsis>
40 <command>pkg-config --cflags --libs libsystemd</command>
41 </cmdsynopsis>
42
43 </refsynopsisdiv>
44
45 <refsect1>
46 <title>Description</title>
47
48 <para><filename>sd-id128.h</filename> provides APIs to process and
49 generate 128-bit ID values. The 128-bit ID values processed and
50 generated by these APIs are a generalization of OSF UUIDs as
51 defined by <ulink url="https://tools.ietf.org/html/rfc4122">RFC
52 4122</ulink> but use a simpler string format. These functions
53 impose no structure on the used IDs, much unlike OSF UUIDs or
54 Microsoft GUIDs, but are fully compatible with those types of IDs.
55 </para>
56
57 <para>See
58 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
59 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>
60 and
61 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
62 for more information about the implemented functions.</para>
63
64 <para>A 128-bit ID is implemented as the following
65 union type:</para>
66
67 <programlisting>typedef union sd_id128 {
3dbea941
LP
68 uint8_t bytes[16];
69 uint64_t qwords[2];
12355095
LP
70} sd_id128_t;</programlisting>
71
798d3a52
ZJS
72 <para>This union type allows accessing the 128-bit ID as 16
73 separate bytes or two 64-bit words. It is generally safer to
74 access the ID components by their 8-bit array to avoid endianness
75 issues. This union is intended to be passed call-by-value (as
76 opposed to call-by-reference) and may be directly manipulated by
77 clients.</para>
78
79 <para>A couple of macros are defined to denote and decode 128-bit
80 IDs:</para>
81
82 <para><function>SD_ID128_MAKE()</function> may be used to denote a
83 constant 128-bit ID in source code. A commonly used idiom is to
84 assign a name to a 128-bit ID using this macro:</para>
85
86 <programlisting>#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)</programlisting>
87
6b44ad0b
YW
88 <para><constant>SD_ID128_NULL</constant> may be used to refer to the 128bit ID consisting of only
89 <constant>NUL</constant> bytes.</para>
3dbea941 90
2b044526
ZJS
91 <para><function>SD_ID128_MAKE_STR()</function> is similar to <function>SD_ID128_MAKE()</function>, but creates a
92 <type>const char*</type> expression that can be conveniently used in message formats and such:</para>
93
94 <programlisting>#include &lt;stdio.h&gt;
95#define SD_MESSAGE_COREDUMP_STR SD_ID128_MAKE_STR(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
96
97int main(int argc, char **argv) {
98 puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
99}
100 </programlisting>
101
798d3a52
ZJS
102 <para><function>SD_ID128_CONST_STR()</function> may be used to
103 convert constant 128-bit IDs into constant strings for output. The
104 following example code will output the string
105 "fc2e22bc6ee647b6b90729ab34a250b1":</para>
106 <programlisting>int main(int argc, char *argv[]) {
2b044526 107 puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
183de6d7
LP
108}</programlisting>
109
725d9713
YW
110 <para><constant>SD_ID128_FORMAT_STR</constant> and <function>SD_ID128_FORMAT_VAL()</function> may
111 be used to format a 128-bit ID in a
798d3a52
ZJS
112 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
113 format string, as shown in the following example:</para>
114
115 <programlisting>int main(int argc, char *argv[]) {
3dbea941
LP
116 sd_id128_t id;
117 id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
118 printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
119 return 0;
12355095
LP
120}</programlisting>
121
725d9713
YW
122 <para><constant>SD_ID128_UUID_FORMAT_STR</constant> is similar to
123 <constant>SD_ID128_FORMAT_STR</constant> but includes separating hyphens to conform to the
38df8d3f
ZJS
124 "<ulink url="https://en.wikipedia.org/wiki/Universally_unique_identifier#Format">canonical representation</ulink>".
125 </para>
126
798d3a52 127 <para>Use <function>sd_id128_equal()</function> to compare two 128-bit IDs:</para>
12355095 128
798d3a52 129 <programlisting>int main(int argc, char *argv[]) {
3dbea941
LP
130 sd_id128_t a, b, c;
131 a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
132 b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
133 c = a;
134 assert(sd_id128_equal(a, c));
135 assert(!sd_id128_equal(a, b));
136 return 0;
137}</programlisting>
138
6b44ad0b
YW
139 <para>Use <function>sd_id128_is_null()</function> to check if an 128bit ID consists of only
140 <constant>NUL</constant> bytes:</para>
3dbea941
LP
141
142 <programlisting>int main(int argc, char *argv[]) {
143 assert(sd_id128_is_null(SD_ID128_NULL));
12355095
LP
144}</programlisting>
145
798d3a52 146 <para>Note that new, randomized IDs may be generated with
b9d016d6
LP
147 <citerefentry><refentrytitle>systemd-id128</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
148 <command>new</command> command.</para>
798d3a52
ZJS
149 </refsect1>
150
151 <xi:include href="libsystemd-pkgconfig.xml" />
152
153 <refsect1>
154 <title>See Also</title>
155 <para>
156 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
157 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
163 <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
164 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
165 </para>
166 </refsect1>
12355095
LP
167
168</refentry>