]> git.proxmox.com Git - systemd.git/blame - man/SD_ID128_MAKE.html
Imported Upstream version 220
[systemd.git] / man / SD_ID128_MAKE.html
CommitLineData
663996b3
MS
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd-id128</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
2 a.headerlink {
3 color: #c60f0f;
4 font-size: 0.8em;
5 padding: 0 4px 0 4px;
6 text-decoration: none;
7 visibility: hidden;
8 }
9
10 a.headerlink:hover {
11 background-color: #c60f0f;
12 color: white;
13 }
14
15 h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
16 visibility: visible;
17 }
18 </style><a href="index.html">Index </a>·
19 <a href="systemd.directives.html">Directives </a>·
20 <a href="../python-systemd/index.html">Python </a>·
21 <a href="../libudev/index.html">libudev </a>·
e3bff60a 22 <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 220</span><hr><div class="refentry"><a name="sd-id128"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd-id128, sd_id128_t, SD_ID128_MAKE, SD_ID128_CONST_STR, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL, sd_id128_equal — APIs for processing 128-bit IDs</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-id128.h&gt;</pre></div><div class="cmdsynopsis"><p><code class="command">pkg-config --cflags --libs libsystemd</code> </p></div></div><div class="refsect1"><a name="idm140538944672128"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="filename">sd-id128.h</code> provides APIs to process and
e735f4d4
MP
23 generate 128-bit ID values. The 128-bit ID values processed and
24 generated by these APIs are a generalization of OSF UUIDs as
25 defined by <a class="ulink" href="https://tools.ietf.org/html/rfc4122" target="_top">RFC
26 4122</a> but use a simpler string format. These functions
27 impose no structure on the used IDs, much unlike OSF UUIDs or
28 Microsoft GUIDs, but are fully compatible with those types of IDs.
29 </p><p>See
30 <a href="sd_id128_to_string.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_to_string</span>(3)</span></a>,
31 <a href="sd_id128_randomize.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_randomize</span>(3)</span></a>
32 and
33 <a href="sd_id128_get_machine.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_get_machine</span>(3)</span></a>
34 for more information about the implemented functions.</p><p>A 128-bit ID is implemented as the following
35 union type:</p><pre class="programlisting">typedef union sd_id128 {
36 uint8_t bytes[16];
37 uint64_t qwords[2];
38} sd_id128_t;</pre><p>This union type allows accessing the 128-bit ID as 16
39 separate bytes or two 64-bit words. It is generally safer to
40 access the ID components by their 8-bit array to avoid endianness
41 issues. This union is intended to be passed call-by-value (as
42 opposed to call-by-reference) and may be directly manipulated by
43 clients.</p><p>A couple of macros are defined to denote and decode 128-bit
44 IDs:</p><p><code class="function">SD_ID128_MAKE()</code> may be used to denote a
45 constant 128-bit ID in source code. A commonly used idiom is to
46 assign a name to a 128-bit ID using this macro:</p><pre class="programlisting">#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)</pre><p><code class="function">SD_ID128_CONST_STR()</code> may be used to
47 convert constant 128-bit IDs into constant strings for output. The
48 following example code will output the string
49 "fc2e22bc6ee647b6b90729ab34a250b1":</p><pre class="programlisting">int main(int argc, char *argv[]) {
50 puts(SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
663996b3 51}</pre><p><code class="function">SD_ID128_FORMAT_STR</code> and
e735f4d4
MP
52 <code class="function">SD_ID128_FORMAT_VAL()</code> may be used to format a
53 128-bit ID in a
54 <a href="http://man7.org/linux/man-pages/man3/printf.3.html"><span class="citerefentry"><span class="refentrytitle">printf</span>(3)</span></a>
55 format string, as shown in the following example:</p><pre class="programlisting">int main(int argc, char *argv[]) {
56 sd_id128_t id;
57 id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
58 printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
59 return 0;
14228c0d 60}</pre><p>Use <code class="function">sd_id128_equal()</code> to compare two 128-bit IDs:</p><pre class="programlisting">int main(int argc, char *argv[]) {
e735f4d4
MP
61 sd_id128_t a, b, c;
62 a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
63 b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
64 c = a;
65 assert(sd_id128_equal(a, c));
66 assert(!sd_id128_equal(a, b));
67 return 0;
68}</pre><p>Note that new, randomized IDs may be generated with
69 <a href="journalctl.html"><span class="citerefentry"><span class="refentrytitle">journalctl</span>(1)</span></a>'s
e3bff60a 70 <code class="option">--new-id</code> option.</p></div><div class="refsect1"><a name="idm140538937363120"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p><a name="pkgconfig-text"></a>These APIs are implemented as a shared
60f067b4 71 library, which can be compiled and linked to with the
5eef597e 72 <code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
e3bff60a 73 file.</p></div><div class="refsect1"><a name="idm140538940038128"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
e735f4d4
MP
74 <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
75 <a href="sd_id128_to_string.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_to_string</span>(3)</span></a>,
76 <a href="sd_id128_randomize.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_randomize</span>(3)</span></a>,
77 <a href="sd_id128_get_machine.html"><span class="citerefentry"><span class="refentrytitle">sd_id128_get_machine</span>(3)</span></a>,
78 <a href="http://man7.org/linux/man-pages/man3/printf.3.html"><span class="citerefentry"><span class="refentrytitle">printf</span>(3)</span></a>,
79 <a href="journalctl.html"><span class="citerefentry"><span class="refentrytitle">journalctl</span>(1)</span></a>,
80 <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(7)</span></a>,
81 <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>,
82 <a href="machine-id.html"><span class="citerefentry"><span class="refentrytitle">machine-id</span>(5)</span></a>
83 </p></div></div></body></html>