path-util.c revision b7def684941808600c344f0be7a2b9fcdda97e0f
0075453649960d576af62968ed97edb682a5c5ccAllan Foster/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
0075453649960d576af62968ed97edb682a5c5ccAllan Foster This file is part of systemd.
0075453649960d576af62968ed97edb682a5c5ccAllan Foster Copyright 2010-2012 Lennart Poettering
0075453649960d576af62968ed97edb682a5c5ccAllan Foster systemd is free software; you can redistribute it and/or modify it
0075453649960d576af62968ed97edb682a5c5ccAllan Foster under the terms of the GNU Lesser General Public License as published by
0075453649960d576af62968ed97edb682a5c5ccAllan Foster the Free Software Foundation; either version 2.1 of the License, or
0075453649960d576af62968ed97edb682a5c5ccAllan Foster (at your option) any later version.
0075453649960d576af62968ed97edb682a5c5ccAllan Foster systemd is distributed in the hope that it will be useful, but
0075453649960d576af62968ed97edb682a5c5ccAllan Foster WITHOUT ANY WARRANTY; without even the implied warranty of
0075453649960d576af62968ed97edb682a5c5ccAllan Foster MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0075453649960d576af62968ed97edb682a5c5ccAllan Foster Lesser General Public License for more details.
0075453649960d576af62968ed97edb682a5c5ccAllan Foster You should have received a copy of the GNU Lesser General Public License
0075453649960d576af62968ed97edb682a5c5ccAllan Foster along with systemd; If not, see <http://www.gnu.org/licenses/>.
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterbool path_is_absolute(const char *p) {
0075453649960d576af62968ed97edb682a5c5ccAllan Foster return p[0] == '/';
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterbool is_path(const char *p) {
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterchar *path_get_file_name(const char *p) {
0075453649960d576af62968ed97edb682a5c5ccAllan Foster return r + 1;
0075453649960d576af62968ed97edb682a5c5ccAllan Foster return (char*) p;
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterint path_get_parent(const char *path, char **_r) {
0075453649960d576af62968ed97edb682a5c5ccAllan Foster bool slash = false;
0075453649960d576af62968ed97edb682a5c5ccAllan Foster for (e = path; *e; e++) {
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterchar **path_split_and_make_absolute(const char *p) {
0075453649960d576af62968ed97edb682a5c5ccAllan Fosterchar *path_make_absolute(const char *p, const char *prefix) {
assert(p);
return strdup(p);
char *path_make_absolute_cwd(const char *p) {
char *cwd, *r;
assert(p);
if (path_is_absolute(p))
return strdup(p);
return NULL;
char **path_strv_make_absolute_cwd(char **l) {
STRV_FOREACH(s, l) {
if (!(t = path_make_absolute_cwd(*s)))
return NULL;
free(*s);
char **path_strv_canonicalize(char **l) {
bool enomem = false;
if (strv_isempty(l))
STRV_FOREACH(s, l) {
t = path_make_absolute_cwd(*s);
free(*s);
enomem = true;
errno = 0;
u = canonicalize_file_name(t);
free(t);
enomem = true;
l[k] = NULL;
if (enomem)
return NULL;
char **path_strv_remove_empty(char **l) {
return NULL;
if (dir_is_empty(*f) > 0) {
free(*f);
*t = NULL;
bool slash = false;
slash = true;
if (slash) {
slash = false;
return path;
size_t a, b;
if (*prefix == 0)
if (*path == 0)
path += a;
prefix += b;
bool path_equal(const char *a, const char *b) {
assert(a);
assert(b);
size_t j, k;
if (memcmp(a, b, j) != 0)
struct stat a, b;
char *parent;
if (allow_symlink)
r = stat(t, &a);
r = lstat(t, &a);
return -errno;
return -errno;
return -errno;