sd-path.c revision 9a00f57a5ba7ed431e6bac8d8b36518708503b4e
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence This file is part of systemd.
4c1132f34493327abc632196f5876a89aa573687Bob Halley Copyright 2014 Lennart Poettering
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence systemd is free software; you can redistribute it and/or modify it
15a44745412679c30a6d022733925af70a38b715David Lawrence under the terms of the GNU Lesser General Public License as published by
15a44745412679c30a6d022733925af70a38b715David Lawrence the Free Software Foundation; either version 2.1 of the License, or
15a44745412679c30a6d022733925af70a38b715David Lawrence (at your option) any later version.
15a44745412679c30a6d022733925af70a38b715David Lawrence systemd is distributed in the hope that it will be useful, but
15a44745412679c30a6d022733925af70a38b715David Lawrence WITHOUT ANY WARRANTY; without even the implied warranty of
15a44745412679c30a6d022733925af70a38b715David Lawrence MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15a44745412679c30a6d022733925af70a38b715David Lawrence Lesser General Public License for more details.
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington You should have received a copy of the GNU Lesser General Public License
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence along with systemd; If not, see <http://www.gnu.org/licenses/>.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleystatic int from_environment(const char *envname, const char *fallback, const char **ret) {
2f2e3e1c38aabeef784566870d885adfa7f00a48David Lawrence const char *e;
a0d172f105ac277a9e56e1b61e6863d279f2ff75Andreas Gustafssonstatic int from_home_dir(const char *envname, const char *suffix, char **buffer, const char **ret) {
if (envname) {
const char *e = NULL;
if (e && path_is_absolute(e)) {
*ret = e;
r = get_home_dir(&h);
if (!cc)
return -ENOMEM;
size_t n;
goto fallback;
return -errno;
char *cc;
r = get_home_dir(&h);
if (!cc)
return -ENOMEM;
} else if (path_is_absolute(p)) {
char *copy;
if (!copy)
return -ENOMEM;
char *cc;
r = get_home_dir(&h);
if (!cc)
return -ENOMEM;
switch (type) {
case SD_PATH_TEMPORARY:
case SD_PATH_TEMPORARY_LARGE:
case SD_PATH_SYSTEM_BINARIES:
case SD_PATH_SYSTEM_INCLUDE:
case SD_PATH_SYSTEM_SHARED:
case SD_PATH_SYSTEM_RUNTIME:
case SD_PATH_USER_BINARIES:
case SD_PATH_USER_SHARED:
case SD_PATH_USER_RUNTIME:
case SD_PATH_USER_STATE_CACHE:
case SD_PATH_USER:
case SD_PATH_USER_DOCUMENTS:
case SD_PATH_USER_MUSIC:
case SD_PATH_USER_PICTURES:
case SD_PATH_USER_VIDEOS:
case SD_PATH_USER_DOWNLOAD:
case SD_PATH_USER_PUBLIC:
case SD_PATH_USER_TEMPLATES:
case SD_PATH_USER_DESKTOP:
return -ENOTSUP;
const char *ret;
if (!buffer)
return -ENOMEM;
if (!suffix) {
if (!buffer) {
if (!buffer)
return -ENOMEM;
if (!cc)
return -ENOMEM;
static int search_from_environment(
char ***list,
const char *env_home,
const char *home_suffix,
const char *env_search,
bool env_search_sufficient,
const char *first, ...) {
char *h = NULL;
char **l = NULL;
if (env_search) {
return -ENOMEM;
if (env_search_sufficient) {
*list = l;
if (!l && first) {
return -ENOMEM;
if (env_home) {
if (e && path_is_absolute(e)) {
h = strdup(e);
strv_free(l);
return -ENOMEM;
if (!h && home_suffix) {
if (e && path_is_absolute(e)) {
strv_free(l);
return -ENOMEM;
r = strv_consume_prepend(&l, h);
strv_free(l);
return -ENOMEM;
*list = l;
switch(type) {
case SD_PATH_SEARCH_BINARIES:
NULL,
#ifdef HAVE_SPLIT_USR
NULL);
NULL,
NULL,
#ifdef HAVE_SPLIT_USR
NULL);
NULL,
#ifdef HAVE_SPLIT_USR
NULL);
case SD_PATH_SEARCH_SHARED:
NULL);
NULL,
NULL,
NULL,
NULL);
NULL,
NULL,
NULL,
NULL);
NULL);
return -ENOTSUP;
free(p);
return -ENOMEM;
*paths = l;
if (!suffix) {
*paths = l;
strv_free(l);
return -ENOMEM;
STRV_FOREACH(i, l) {
strv_free(l);
strv_free(n);
return -ENOMEM;
*j = NULL;
*paths = n;