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