SD\_PATH\_LOOKUP(3) sd\_path\_lookup SD\_PATH\_LOOKUP(3)

.SH "NAME" sd\_path\_lookup, sd\_path\_lookup\_strv - Query well-known file system paths

.SH "SYNOPSIS"

```
#include <systemd/sd-path.h>
```

```
enum {


        SD_PATH_TEMPORARY,


        SD_PATH_TEMPORARY_LARGE,


        SD_PATH_SYSTEM_BINARIES,


        SD_PATH_SYSTEM_INCLUDE,


        SD_PATH_SYSTEM_LIBRARY_PRIVATE,


        SD_PATH_SYSTEM_LIBRARY_ARCH,


        SD_PATH_SYSTEM_SHARED,


        SD_PATH_SYSTEM_CONFIGURATION_FACTORY,


        SD_PATH_SYSTEM_STATE_FACTORY,


        SD_PATH_SYSTEM_CONFIGURATION,


        SD_PATH_SYSTEM_SEARCH_CONFIGURATION,


        SD_PATH_SYSTEM_RUNTIME,


        SD_PATH_SYSTEM_RUNTIME_LOGS,


        SD_PATH_SYSTEM_STATE_PRIVATE,


        SD_PATH_SYSTEM_STATE_LOGS,


        SD_PATH_SYSTEM_STATE_CACHE,


        SD_PATH_SYSTEM_STATE_SPOOL,


        SD_PATH_USER_BINARIES,


        SD_PATH_USER_LIBRARY_PRIVATE,


        SD_PATH_USER_LIBRARY_ARCH,


        SD_PATH_USER_SHARED,


        SD_PATH_USER_CONFIGURATION,


        SD_PATH_USER_RUNTIME,


        SD_PATH_USER_STATE_PRIVATE,


        SD_PATH_USER_STATE_CACHE,


        SD_PATH_USER,


        SD_PATH_USER_DOCUMENTS,


        SD_PATH_USER_MUSIC,


        SD_PATH_USER_PICTURES,


        SD_PATH_USER_VIDEOS,


        SD_PATH_USER_DOWNLOAD,


        SD_PATH_USER_PUBLIC,


        SD_PATH_USER_TEMPLATES,


        SD_PATH_USER_DESKTOP,


        SD_PATH_USER_PROJECTS,


        SD_PATH_SEARCH_BINARIES,


        SD_PATH_SEARCH_BINARIES_DEFAULT,


        SD_PATH_SEARCH_LIBRARY_PRIVATE,


        SD_PATH_SEARCH_LIBRARY_ARCH,


        SD_PATH_SEARCH_SHARED,


        SD_PATH_SEARCH_CONFIGURATION_FACTORY,


        SD_PATH_SEARCH_STATE_FACTORY,


        SD_PATH_SEARCH_CONFIGURATION,


        SD_PATH_SYSTEMD_UTIL,


        SD_PATH_SYSTEMD_SYSTEM_UNIT,


        SD_PATH_SYSTEMD_SYSTEM_PRESET,


        SD_PATH_SYSTEMD_USER_UNIT,


        SD_PATH_SYSTEMD_USER_PRESET,


        SD_PATH_SYSTEMD_SYSTEM_CONF,


        SD_PATH_SYSTEMD_USER_CONF,


        SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT,


        SD_PATH_SYSTEMD_SEARCH_USER_UNIT,


        SD_PATH_SYSTEMD_SYSTEM_GENERATOR,


        SD_PATH_SYSTEMD_USER_GENERATOR,


        SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR,


        SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR,


        SD_PATH_SYSTEMD_SLEEP,


        SD_PATH_SYSTEMD_SHUTDOWN,


        SD_PATH_TMPFILES,


        SD_PATH_SYSUSERS,


        SD_PATH_SYSCTL,


        SD_PATH_BINFMT,


        SD_PATH_MODULES_LOAD,


        SD_PATH_CATALOG,


        SD_PATH_SYSTEMD_SEARCH_NETWORK,


        SD_PATH_SYSTEMD_SYSTEM_ENVIRONMENT_GENERATOR,


        SD_PATH_SYSTEMD_USER_ENVIRONMENT_GENERATOR,


        SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR,


        SD_PATH_SYSTEMD_SEARCH_USER_ENVIRONMENT_GENERATOR,
};
```

.HP 456u **int sd\_path\_lookup(uint64\_t type, const char \*suffix, char \*\*paths);**

.HP 576u **int sd\_path\_lookup\_strv(uint64\_t type, const char \*suffix, char \*\*\*paths);**

.SH "DESCRIPTION"

.PP **sd\_path\_lookup()** and **sd\_bus\_path\_lookup\_strv()** return a single path or set of file system paths specified by the argument *type*. In case of **sd\_path\_lookup()** a single **NUL**-terminated string is returned. When *type* specifies a set of paths, they are concatenated using : as a separator (as is traditionally done for e.g. *$PATH* or *$LD\_LIBRARY\_PATH*). In case of **sd\_path\_lookup\_strv()** a **NULL**-terminated array of strings is returned (strv). If suffix *suffix* is given, it is concatenated to each of the paths after a slash (/). All returned paths are absolute.

.PP For paths which refer to user directories, the relevant XDG standard is followed, with support for environment variables like *$XDG\_DOCUMENTS\_DIR*, *$XDG\_DESKTOP\_DIR*, ..., and explicit configuration in /etc/xdg/user-dirs.conf or ${XDG\_CONFIG\_HOME}/user-dirs.dirs. See **XDG Base Directory Specification**\[1] for details.

.PP [**systemd-path**(1)](/man/os/systemd/systemd-path.1) is a wrapper around **sd\_path\_lookup()** and allows the same set of paths to be queried.

.SH "RETURN VALUE"

.PP On success, **sd\_path\_lookup()** and **sd\_path\_lookup\_strv()** return a non-negative integer. On failure, a negative errno-style error number is returned by either function.

.PP The returned string or string array (strv) must be [**free**(3)](/man/os/systemd/free.3)'d by the caller.

.SS "Errors"

.PP Returned errors may indicate the following problems:

.PP **-EOPNOTSUPP**

Unknown identifier *type*.

Added in version 246.

.RE

.PP **-EINVAL**

Output argument is **NULL**.

Added in version 246.

.RE

.PP **-ENXIO**

Query failed because of an undefined environment variable (e.g. for **SD\_PATH\_USER\_RUNTIME** when *$XDG\_RUNTIME\_DIR* is not defined).

Added in version 246.

.RE

.PP **-ENOMEM**

Memory allocation failed.

Added in version 246.

.RE

.SH "EXAMPLES"

.SS "Look up the location of ~/Documents"

```
/* SPDX-License-Identifier: MIT-0 */
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-path.h>
int main(void) {


  int r;


  char *t;


  r = sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t);


  if (r < 0)


    return EXIT_FAILURE;


  printf("~/Documents: %s\n", t);


  free(t);


  return EXIT_SUCCESS;
}
```

.PP Note that the default answer of $HOME/Documents may be overridden by user-dirs.conf or *$XDG\_DOCUMENTS\_DIR*.

.SH "NOTES"

.PP Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/man/os/systemd/pkg-config.1) file.

.PP The code described here uses [**getenv**(3)](/man/os/systemd/getenv.3), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/man/os/systemd/setenv.3) from a parallel thread. It is recommended to only do calls to **setenv()** from an early phase of the program when no other threads have been started.

.SH "HISTORY"

.PP **sd\_path\_lookup()** and **sd\_path\_lookup\_strv()** were added in version 246.

.SH "SEE ALSO"

.PP [**systemd**(1)](/man/os/systemd/systemd.1), [**sd-path**(3)](/man/os/systemd/sd-path.3), [**systemd-path**(1)](/man/os/systemd/systemd-path.1)

# [NOTES](#NOTES)

1\.

XDG Base Directory Specification

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

systemd 262.2

---

Document: sd_path_lookup(3) from systemd 262.2-r1 (Chainguard OS)
Source: https://github.com/systemd/systemd
