1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<refentry id="sd_path_lookup" xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>sd_path_lookup</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>sd_path_lookup</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>sd_path_lookup</refname>
<refname>sd_path_lookup_strv</refname>
<refpurpose>Query well-known file system paths</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include <systemd/sd-path.h></funcsynopsisinfo>
<!-- note: individual constants are not added as <refname>s, there's just too many -->
<funcsynopsisinfo><token>enum</token> {
<constant>SD_PATH_TEMPORARY</constant>,
<constant>SD_PATH_TEMPORARY_LARGE</constant>,
<constant>SD_PATH_SYSTEM_BINARIES</constant>,
<constant>SD_PATH_SYSTEM_INCLUDE</constant>,
<constant>SD_PATH_SYSTEM_LIBRARY_PRIVATE</constant>,
<constant>SD_PATH_SYSTEM_LIBRARY_ARCH</constant>,
<constant>SD_PATH_SYSTEM_SHARED</constant>,
<constant>SD_PATH_SYSTEM_CONFIGURATION_FACTORY</constant>,
<constant>SD_PATH_SYSTEM_STATE_FACTORY</constant>,
<constant>SD_PATH_SYSTEM_CONFIGURATION</constant>,
<constant>SD_PATH_SYSTEM_RUNTIME</constant>,
<constant>SD_PATH_SYSTEM_RUNTIME_LOGS</constant>,
<constant>SD_PATH_SYSTEM_STATE_PRIVATE</constant>,
<constant>SD_PATH_SYSTEM_STATE_LOGS</constant>,
<constant>SD_PATH_SYSTEM_STATE_CACHE</constant>,
<constant>SD_PATH_SYSTEM_STATE_SPOOL</constant>,
<constant>SD_PATH_USER_BINARIES</constant>,
<constant>SD_PATH_USER_LIBRARY_PRIVATE</constant>,
<constant>SD_PATH_USER_LIBRARY_ARCH</constant>,
<constant>SD_PATH_USER_SHARED</constant>,
<constant>SD_PATH_USER_CONFIGURATION</constant>,
<constant>SD_PATH_USER_RUNTIME</constant>,
<constant>SD_PATH_USER_STATE_CACHE</constant>,
<constant>SD_PATH_USER</constant>,
<constant>SD_PATH_USER_DOCUMENTS</constant>,
<constant>SD_PATH_USER_MUSIC</constant>,
<constant>SD_PATH_USER_PICTURES</constant>,
<constant>SD_PATH_USER_VIDEOS</constant>,
<constant>SD_PATH_USER_DOWNLOAD</constant>,
<constant>SD_PATH_USER_PUBLIC</constant>,
<constant>SD_PATH_USER_TEMPLATES</constant>,
<constant>SD_PATH_USER_DESKTOP</constant>,
<constant>SD_PATH_SEARCH_BINARIES</constant>,
<constant>SD_PATH_SEARCH_BINARIES_DEFAULT</constant>,
<constant>SD_PATH_SEARCH_LIBRARY_PRIVATE</constant>,
<constant>SD_PATH_SEARCH_LIBRARY_ARCH</constant>,
<constant>SD_PATH_SEARCH_SHARED</constant>,
<constant>SD_PATH_SEARCH_CONFIGURATION_FACTORY</constant>,
<constant>SD_PATH_SEARCH_STATE_FACTORY</constant>,
<constant>SD_PATH_SEARCH_CONFIGURATION</constant>,
<constant>SD_PATH_SYSTEMD_UTIL_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_UNIT_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_PRESET_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_CONF_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_CONF_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH</constant>,
<constant>SD_PATH_SYSTEMD_USER_UNIT_PATH</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH</constant>,
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_PATH</constant>,
<constant>SD_PATH_SYSTEMD_SLEEP_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SHUTDOWN_DIR</constant>,
<constant>SD_PATH_TMPFILES_DIR</constant>,
<constant>SD_PATH_SYSUSERS_DIR</constant>,
<constant>SD_PATH_SYSCTL_DIR</constant>,
<constant>SD_PATH_BINFMT_DIR</constant>,
<constant>SD_PATH_MODULES_LOAD_DIR</constant>,
<constant>SD_PATH_CATALOG_DIR</constant>,
<constant>SD_PATH_SYSTEMD_NETWORK_PATH</constant>,
};</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>sd_path_lookup</function></funcdef>
<paramdef>uint64_t <parameter>type</parameter></paramdef>
<paramdef>const char *<parameter>suffix</parameter></paramdef>
<paramdef>char **<parameter>paths</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_path_lookup_strv</function></funcdef>
<paramdef>uint64_t <parameter>type</parameter></paramdef>
<paramdef>const char *<parameter>suffix</parameter></paramdef>
<paramdef>char ***<parameter>paths</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_path_lookup()</function> and <function>sd_bus_path_lookup_strv()</function> return a
single path or set of file system paths specified by the argument <parameter>type</parameter>. In case of
<function>sd_path_lookup()</function> a single <constant>NUL</constant>-terminated string is returned.
When <parameter>type</parameter> specifies a set of paths, they are concatenated using
<literal>:</literal> as a separator (as is traditionally done for e.g. <varname>$PATH</varname> or
<varname>$LD_LIBRARY_PATH</varname>). In case of <function>sd_path_lookup_strv()</function> a
<constant>NULL</constant>-terminated array of strings is returned (strv). If suffix
<parameter>suffix</parameter> is given, it is concatenated to each of the paths after a slash
(<literal>/</literal>). All returned paths are absolute.</para>
<para>For paths which refer to user directories, the relevant XDG standard is followed, with support for
environment variables like <varname>$XDG_DOCUMENTS_DIR</varname>, <varname>$XDG_DESKTOP_DIR</varname>,
..., and explicit configuration in <filename>/etc/xdg/user-dirs.conf</filename> or
<filename>${XDG_CONFIG_HOME}/user-dirs.dirs</filename>. See
<ulink url="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">
XDG Base Directory Specification</ulink> for details.</para>
<para><citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry> is
a wrapper around <function>sd_path_lookup()</function> and allows the same set of paths to be queried.
</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>On success, <function>sd_path_lookup()</function> and <function>sd_path_lookup_strv()</function>
return a non-negative integer. On failure, a negative errno-style error number is returned by either
function.</para>
<para>The returned string or string array (strv) must be
<citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>'d by the
caller.</para>
<refsect2 id='errors'>
<title>Errors</title>
<para>Returned errors may indicate the following problems:</para>
<variablelist>
<varlistentry>
<term><constant>-EOPNOTSUPP</constant></term>
<listitem><para>Unknown identifier <parameter>type</parameter>.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-EINVAL</constant></term>
<listitem><para>Output argument is <constant>NULL</constant>.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENXIO</constant></term>
<listitem><para>Query failed because of an undefined environment variable (e.g. for
<constant>SD_PATH_USER_RUNTIME</constant> when <varname>$XDG_RUNTIME_DIR</varname> is not
defined).</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENOMEM</constant></term>
<listitem><para>Memory allocation failed.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>
<refsect1>
<title>Examples</title>
<refsect2>
<title>Look up the location of ~/Documents</title>
<programlisting><xi:include href="path-documents.c" parse="text" /></programlisting>
<para>Note that the default answer of <filename index='false'>$HOME/Documents</filename> may be
overridden by <filename index='false'>user-dirs.conf</filename> or
<varname>$XDG_DOCUMENTS_DIR</varname>.</para>
</refsect2>
</refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>
|