]>
Commit | Line | Data |
---|---|---|
12355095 LP |
1 | <?xml version='1.0'?> <!--*-nxml-*--> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
12355095 LP |
4 | |
5 | <!-- | |
572eb058 ZJS |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
12355095 LP |
8 | This file is part of systemd. |
9 | ||
10 | Copyright 2012 Lennart Poettering | |
11 | ||
12 | systemd is free software; you can redistribute it and/or modify it | |
13 | under the terms of the GNU Lesser General Public License as published by | |
14 | the Free Software Foundation; either version 2.1 of the License, or | |
15 | (at your option) any later version. | |
16 | ||
17 | systemd is distributed in the hope that it will be useful, but | |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | Lesser General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU Lesser General Public License | |
23 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
24 | --> | |
25 | ||
26 | <refentry id="sd_id128_to_string"> | |
27 | ||
798d3a52 ZJS |
28 | <refentryinfo> |
29 | <title>sd_id128_to_string</title> | |
30 | <productname>systemd</productname> | |
31 | ||
32 | <authorgroup> | |
33 | <author> | |
34 | <contrib>Developer</contrib> | |
35 | <firstname>Lennart</firstname> | |
36 | <surname>Poettering</surname> | |
37 | <email>lennart@poettering.net</email> | |
38 | </author> | |
39 | </authorgroup> | |
40 | </refentryinfo> | |
41 | ||
42 | <refmeta> | |
43 | <refentrytitle>sd_id128_to_string</refentrytitle> | |
44 | <manvolnum>3</manvolnum> | |
45 | </refmeta> | |
46 | ||
47 | <refnamediv> | |
48 | <refname>sd_id128_to_string</refname> | |
49 | <refname>sd_id128_from_string</refname> | |
50 | <refpurpose>Format or parse 128-bit IDs as strings</refpurpose> | |
51 | </refnamediv> | |
52 | ||
53 | <refsynopsisdiv> | |
54 | <funcsynopsis> | |
55 | <funcsynopsisinfo>#include <systemd/sd-id128.h></funcsynopsisinfo> | |
56 | ||
57 | <funcprototype> | |
58 | <funcdef>char *<function>sd_id128_to_string</function></funcdef> | |
59 | <paramdef>sd_id128_t <parameter>id</parameter>, char <parameter>s</parameter>[33]</paramdef> | |
60 | </funcprototype> | |
61 | ||
62 | <funcprototype> | |
63 | <funcdef>int <function>sd_id128_from_string</function></funcdef> | |
64 | <paramdef>const char *<parameter>s</parameter>, sd_id128_t *<parameter>ret</parameter></paramdef> | |
65 | </funcprototype> | |
66 | ||
67 | </funcsynopsis> | |
68 | </refsynopsisdiv> | |
69 | ||
70 | <refsect1> | |
71 | <title>Description</title> | |
72 | ||
73 | <para><function>sd_id128_to_string()</function> formats a 128-bit | |
74 | ID as a character string. It expects the ID and a string array | |
75 | capable of storing 33 characters. The ID will be formatted as 32 | |
76 | lowercase hexadecimal digits and be terminated by a | |
77 | <constant>NUL</constant> byte.</para> | |
78 | ||
9ca8d434 LP |
79 | <para><function>sd_id128_from_string()</function> implements the reverse operation: it takes a 33 character string |
80 | with 32 hexadecimal digits (either lowercase or uppercase, terminated by <constant>NUL</constant>) and parses them | |
81 | back into a 128-bit ID returned in <parameter>ret</parameter>. Alternatively, this call can also parse a | |
82 | 37-character string with a 128-bit ID formatted as RFC UUID. If <parameter>ret</parameter> is passed as NULL the | |
83 | function will validate the passed ID string, but not actually return it in parsed form.</para> | |
798d3a52 ZJS |
84 | |
85 | <para>For more information about the <literal>sd_id128_t</literal> | |
86 | type see | |
87 | <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
88 | Note that these calls operate the same way on all architectures, | |
89 | i.e. the results do not depend on endianness.</para> | |
90 | ||
91 | <para>When formatting a 128-bit ID into a string, it is often | |
92 | easier to use a format string for | |
93 | <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
94 | This is easily done using the | |
95 | <function>SD_ID128_FORMAT_STR</function> and | |
96 | <function>SD_ID128_FORMAT_VAL()</function> macros. For more | |
97 | information see | |
98 | <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> | |
99 | </refsect1> | |
100 | ||
101 | <refsect1> | |
102 | <title>Return Value</title> | |
103 | ||
104 | <para><function>sd_id128_to_string()</function> always succeeds | |
105 | and returns a pointer to the string array passed in. | |
106 | <function>sd_id128_from_string</function> returns 0 on success, in | |
107 | which case <parameter>ret</parameter> is filled in, or a negative | |
108 | errno-style error code.</para> | |
109 | </refsect1> | |
110 | ||
111 | <refsect1> | |
112 | <title>Notes</title> | |
113 | ||
114 | <para>The <function>sd_id128_to_string()</function> and | |
115 | <function>sd_id128_from_string()</function> interfaces are | |
116 | available as a shared library, which can be compiled and linked to | |
117 | with the | |
118 | <literal>libsystemd</literal> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
119 | file.</para> | |
120 | </refsect1> | |
121 | ||
122 | <refsect1> | |
123 | <title>See Also</title> | |
124 | ||
125 | <para> | |
126 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
127 | <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
128 | <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
129 | </para> | |
130 | </refsect1> | |
12355095 LP |
131 | |
132 | </refentry> |