1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 /* When we include libgen.h because we need dirname() we immediately
10 * undefine basename() since libgen.h defines it as a macro to the
11 * POSIX version which is really broken. We prefer GNU basename(). */
15 #include "alloc-util.h"
16 #include "extract-word.h"
19 #include "glob-util.h"
22 #include "nulstr-util.h"
23 #include "parse-util.h"
24 #include "path-util.h"
25 #include "stat-util.h"
26 #include "string-util.h"
28 #include "time-util.h"
31 int path_split_and_make_absolute(const char *p
, char ***ret
) {
38 l
= strv_split(p
, ":");
42 r
= path_strv_make_absolute_cwd(l
);
52 char *path_make_absolute(const char *p
, const char *prefix
) {
55 /* Makes every item in the list an absolute path by prepending
56 * the prefix, if specified and necessary */
58 if (path_is_absolute(p
) || isempty(prefix
))
61 return path_join(prefix
, p
);
64 int safe_getcwd(char **ret
) {
67 cwd
= get_current_dir_name();
69 return negative_errno();
71 /* Let's make sure the directory is really absolute, to protect us from the logic behind
82 int path_make_absolute_cwd(const char *p
, char **ret
) {
89 /* Similar to path_make_absolute(), but prefixes with the
90 * current working directory. */
92 if (path_is_absolute(p
))
95 _cleanup_free_
char *cwd
= NULL
;
97 r
= safe_getcwd(&cwd
);
101 c
= path_join(cwd
, p
);
110 int path_make_relative(const char *from
, const char *to
, char **ret
) {
111 _cleanup_free_
char *result
= NULL
;
121 /* Strips the common part, and adds ".." elements as necessary. */
123 if (!path_is_absolute(from
) || !path_is_absolute(to
))
127 r
= path_find_first_component(&from
, true, &f
);
131 k
= path_find_first_component(&to
, true, &t
);
138 /* from and to are equivalent. */
139 result
= strdup(".");
143 /* 'to' is inside of 'from'. */
148 path_simplify(result
);
150 if (!path_is_valid(result
))
154 *ret
= TAKE_PTR(result
);
158 if (r
!= k
|| !strneq(f
, t
, r
))
162 /* If we're here, then "from_dir" has one or more elements that need to
163 * be replaced with "..". */
165 for (n_parents
= 1;; n_parents
++) {
166 /* If this includes ".." we can't do a simple series of "..". */
167 r
= path_find_first_component(&from
, false, &f
);
174 if (isempty(t
) && n_parents
* 3 > PATH_MAX
)
175 /* PATH_MAX is counted *with* the trailing NUL byte */
178 result
= new(char, n_parents
* 3 + !isempty(t
) + strlen_ptr(t
));
182 for (p
= result
; n_parents
> 0; n_parents
--)
183 p
= mempcpy(p
, "../", 3);
186 /* Remove trailing slash and terminate string. */
188 *ret
= TAKE_PTR(result
);
194 path_simplify(result
);
196 if (!path_is_valid(result
))
199 *ret
= TAKE_PTR(result
);
203 char* path_startswith_strv(const char *p
, char **set
) {
206 STRV_FOREACH(s
, set
) {
207 t
= path_startswith(p
, *s
);
215 int path_strv_make_absolute_cwd(char **l
) {
219 /* Goes through every item in the string list and makes it
220 * absolute. This works in place and won't rollback any
221 * changes on failure. */
226 r
= path_make_absolute_cwd(*s
, &t
);
231 free_and_replace(*s
, t
);
237 char **path_strv_resolve(char **l
, const char *root
) {
246 /* Goes through every item in the string list and canonicalize
247 * the path. This works in place and won't rollback any
248 * changes on failure. */
251 _cleanup_free_
char *orig
= NULL
;
254 if (!path_is_absolute(*s
)) {
261 t
= path_join(root
, orig
);
269 r
= chase_symlinks(t
, root
, 0, &u
, NULL
);
287 x
= path_startswith(u
, root
);
289 /* restore the slash if it was lost */
290 if (!startswith(x
, "/"))
301 /* canonicalized path goes outside of
302 * prefix, keep the original path instead */
303 free_and_replace(u
, orig
);
319 char **path_strv_resolve_uniq(char **l
, const char *root
) {
324 if (!path_strv_resolve(l
, root
))
330 char *path_simplify(char *path
) {
331 bool add_slash
= false;
337 /* Removes redundant inner and trailing slashes. Also removes unnecessary dots.
338 * Modifies the passed string in-place.
340 * ///foo//./bar/. becomes /foo/bar
341 * .//./foo//./bar/. becomes foo/bar
347 if (path_is_absolute(path
))
350 for (const char *p
= f
;;) {
353 r
= path_find_first_component(&p
, true, &e
);
361 /* if path is invalid, then refuse to simplify remaining part. */
362 memmove(f
, p
, strlen(p
) + 1);
372 /* Special rule, if we stripped everything, we need a "." for the current directory. */
380 int path_simplify_and_warn(
384 const char *filename
,
386 const char *lvalue
) {
388 bool fatal
= flag
& PATH_CHECK_FATAL
;
390 assert(!FLAGS_SET(flag
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_RELATIVE
));
392 if (!utf8_is_valid(path
))
393 return log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, path
);
395 if (flag
& (PATH_CHECK_ABSOLUTE
| PATH_CHECK_RELATIVE
)) {
398 absolute
= path_is_absolute(path
);
400 if (!absolute
&& (flag
& PATH_CHECK_ABSOLUTE
))
401 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
402 "%s= path is not absolute%s: %s",
403 lvalue
, fatal
? "" : ", ignoring", path
);
405 if (absolute
&& (flag
& PATH_CHECK_RELATIVE
))
406 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
407 "%s= path is absolute%s: %s",
408 lvalue
, fatal
? "" : ", ignoring", path
);
413 if (!path_is_valid(path
))
414 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
415 "%s= path has invalid length (%zu bytes)%s.",
416 lvalue
, strlen(path
), fatal
? "" : ", ignoring");
418 if (!path_is_normalized(path
))
419 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
420 "%s= path is not normalized%s: %s",
421 lvalue
, fatal
? "" : ", ignoring", path
);
426 char *path_startswith_full(const char *path
, const char *prefix
, bool accept_dot_dot
) {
430 /* Returns a pointer to the start of the first component after the parts matched by
432 * - both paths are absolute or both paths are relative,
434 * - each component in prefix in turn matches a component in path at the same position.
435 * An empty string will be returned when the prefix and path are equivalent.
437 * Returns NULL otherwise.
440 if ((path
[0] == '/') != (prefix
[0] == '/'))
447 r
= path_find_first_component(&path
, accept_dot_dot
, &p
);
451 k
= path_find_first_component(&prefix
, accept_dot_dot
, &q
);
456 return (char*) (p
?: path
);
461 if (!strneq(p
, q
, r
))
466 int path_compare(const char *a
, const char *b
) {
469 /* Order NULL before non-NULL */
474 /* A relative path and an absolute path must not compare as equal.
475 * Which one is sorted before the other does not really matter.
476 * Here a relative path is ordered before an absolute path. */
477 r
= CMP(path_is_absolute(a
), path_is_absolute(b
));
485 j
= path_find_first_component(&a
, true, &aa
);
486 k
= path_find_first_component(&b
, true, &bb
);
488 if (j
< 0 || k
< 0) {
489 /* When one of paths is invalid, order invalid path after valid one. */
490 r
= CMP(j
< 0, k
< 0);
494 /* fallback to use strcmp() if both paths are invalid. */
498 /* Order prefixes first: "/foo" before "/foo/bar" */
507 /* Alphabetical sort: "/foo/aaa" before "/foo/b" */
508 r
= memcmp(aa
, bb
, MIN(j
, k
));
512 /* Sort "/foo/a" before "/foo/aaa" */
519 bool path_equal_or_files_same(const char *a
, const char *b
, int flags
) {
520 return path_equal(a
, b
) || files_same(a
, b
, flags
) > 0;
523 bool path_equal_filename(const char *a
, const char *b
) {
524 _cleanup_free_
char *a_basename
= NULL
, *b_basename
= NULL
;
530 r
= path_extract_filename(a
, &a_basename
);
532 log_debug_errno(r
, "Failed to parse basename of %s: %m", a
);
535 r
= path_extract_filename(b
, &b_basename
);
537 log_debug_errno(r
, "Failed to parse basename of %s: %m", b
);
541 return path_equal(a_basename
, b_basename
);
544 char* path_extend_internal(char **x
, ...) {
551 /* Joins all listed strings until the sentinel and places a "/" between them unless the strings end/begin
552 * already with one so that it is unnecessary. Note that slashes which are already duplicate won't be
553 * removed. The string returned is hence always equal to or longer than the sum of the lengths of each
556 * The first argument may be an already allocated string that is extended via realloc() if
557 * non-NULL. path_extend() and path_join() are macro wrappers around this function, making use of the
558 * first parameter to distinguish the two operations.
560 * Note: any listed empty string is simply skipped. This can be useful for concatenating strings of which some
565 * path_join("foo", "bar") → "foo/bar"
566 * path_join("foo/", "bar") → "foo/bar"
567 * path_join("", "foo", "", "bar", "") → "foo/bar" */
569 sz
= old_sz
= x
? strlen_ptr(*x
) : 0;
571 while ((p
= va_arg(ap
, char*)) != POINTER_MAX
) {
578 if (sz
> SIZE_MAX
- add
) { /* overflow check */
587 nx
= realloc(x
? *x
: NULL
, GREEDY_ALLOC_ROUND_UP(sz
+1));
594 slash
= nx
[old_sz
-1] == '/';
597 slash
= true; /* no need to generate a slash anymore */
603 while ((p
= va_arg(ap
, char*)) != POINTER_MAX
) {
607 if (!slash
&& p
[0] != '/')
611 slash
= endswith(p
, "/");
618 static int check_x_access(const char *path
, int *ret_fd
) {
619 _cleanup_close_
int fd
= -1;
622 /* We need to use O_PATH because there may be executables for which we have only exec
623 * permissions, but not read (usually suid executables). */
624 fd
= open(path
, O_PATH
|O_CLOEXEC
);
628 r
= fd_verify_regular(fd
);
632 r
= access_fd(fd
, X_OK
);
637 *ret_fd
= TAKE_FD(fd
);
642 int find_executable_full(const char *name
, bool use_path_envvar
, char **ret_filename
, int *ret_fd
) {
644 const char *p
= NULL
;
649 _cleanup_close_
int fd
= -1;
651 r
= check_x_access(name
, ret_fd
? &fd
: NULL
);
656 r
= path_make_absolute_cwd(name
, ret_filename
);
662 *ret_fd
= TAKE_FD(fd
);
668 /* Plain getenv, not secure_getenv, because we want to actually allow the user to pick the
674 last_error
= -ENOENT
;
676 /* Resolve a single-component name to a full path */
678 _cleanup_free_
char *element
= NULL
;
679 _cleanup_close_
int fd
= -1;
681 r
= extract_first_word(&p
, &element
, ":", EXTRACT_RELAX
|EXTRACT_DONT_COALESCE_SEPARATORS
);
687 if (!path_is_absolute(element
))
690 if (!path_extend(&element
, name
))
693 r
= check_x_access(element
, ret_fd
? &fd
: NULL
);
695 /* PATH entries which we don't have access to are ignored, as per tradition. */
703 *ret_filename
= path_simplify(TAKE_PTR(element
));
705 *ret_fd
= TAKE_FD(fd
);
713 bool paths_check_timestamp(const char* const* paths
, usec_t
*timestamp
, bool update
) {
714 bool changed
= false, originally_unset
;
715 const char* const* i
;
722 originally_unset
= *timestamp
== 0;
724 STRV_FOREACH(i
, paths
) {
728 if (stat(*i
, &stats
) < 0)
731 u
= timespec_load(&stats
.st_mtim
);
737 log_debug(originally_unset
? "Loaded timestamp for '%s'." : "Timestamp of '%s' changed.", *i
);
739 /* update timestamp */
750 static int executable_is_good(const char *executable
) {
751 _cleanup_free_
char *p
= NULL
, *d
= NULL
;
754 r
= find_executable(executable
, &p
);
760 /* An fsck that is linked to /bin/true is a non-existent fsck */
762 r
= readlink_malloc(p
, &d
);
763 if (r
== -EINVAL
) /* not a symlink */
768 return !PATH_IN_SET(d
, "true"
774 int fsck_exists(const char *fstype
) {
779 if (streq(fstype
, "auto"))
782 checker
= strjoina("fsck.", fstype
);
783 return executable_is_good(checker
);
786 char* dirname_malloc(const char *path
) {
787 char *d
, *dir
, *dir2
;
807 static const char *skip_slash_or_dot(const char *p
) {
808 for (; !isempty(p
); p
++) {
811 if (startswith(p
, "./")) {
820 int path_find_first_component(const char **p
, bool accept_dot_dot
, const char **ret
) {
821 const char *q
, *first
, *end_first
, *next
;
826 /* When a path is input, then returns the pointer to the first component and its length, and
827 * move the input pointer to the next component or nul. This skips both over any '/'
828 * immediately *before* and *after* the first component before returning.
831 * Input: p: "//.//aaa///bbbbb/cc"
832 * Output: p: "bbbbb///cc"
833 * ret: "aaa///bbbbb/cc"
834 * return value: 3 (== strlen("aaa"))
837 * Output: p: (pointer to NUL)
839 * return value: 3 (== strlen("aaa"))
841 * Input: p: "/", ".", ""
842 * Output: p: (pointer to NUL)
851 * Input: p: "(too long component)"
852 * Output: return value: -EINVAL
854 * (when accept_dot_dot is false)
855 * Input: p: "//..//aaa///bbbbb/cc"
856 * Output: return value: -EINVAL
861 first
= skip_slash_or_dot(q
);
862 if (isempty(first
)) {
868 if (streq(first
, ".")) {
875 end_first
= strchrnul(first
, '/');
876 len
= end_first
- first
;
880 if (!accept_dot_dot
&& len
== 2 && first
[0] == '.' && first
[1] == '.')
883 next
= skip_slash_or_dot(end_first
);
885 *p
= next
+ streq(next
, ".");
891 static const char *skip_slash_or_dot_backward(const char *path
, const char *q
) {
894 for (; q
>= path
; q
--) {
897 if (q
> path
&& strneq(q
- 1, "/.", 2))
904 int path_find_last_component(const char *path
, bool accept_dot_dot
, const char **next
, const char **ret
) {
905 const char *q
, *last_end
, *last_begin
;
908 /* Similar to path_find_first_component(), but search components from the end.
911 * Input: path: "//.//aaa///bbbbb/cc//././"
913 * Output: next: "/cc//././"
915 * return value: 2 (== strlen("cc"))
917 * Input: path: "//.//aaa///bbbbb/cc//././"
919 * Output: next: "///bbbbb/cc//././"
920 * ret: "bbbbb/cc//././"
921 * return value: 5 (== strlen("bbbbb"))
923 * Input: path: "/", ".", "", or NULL
924 * Output: next: equivalent to path
928 * Input: path: "(too long component)"
929 * Output: return value: -EINVAL
931 * (when accept_dot_dot is false)
932 * Input: path: "//..//aaa///bbbbb/cc/..//"
933 * Output: return value: -EINVAL
945 if (*next
< path
|| *next
> path
+ strlen(path
))
952 if (!IN_SET(**next
, '\0', '/'))
956 q
= path
+ strlen(path
) - 1;
958 q
= skip_slash_or_dot_backward(path
, q
);
959 if ((q
< path
) || /* the root directory */
960 (q
== path
&& *q
== '.')) { /* path is "." or "./" */
970 while (q
>= path
&& *q
!= '/')
974 len
= last_end
- last_begin
;
978 if (!accept_dot_dot
&& len
== 2 && strneq(last_begin
, "..", 2))
982 q
= skip_slash_or_dot_backward(path
, q
);
994 const char *last_path_component(const char *path
) {
996 /* Finds the last component of the path, preserving the optional trailing slash that signifies a directory.
1009 * Also, the empty string is mapped to itself.
1011 * This is different than basename(), which returns "" when a trailing slash is present.
1013 * This always succeeds (except if you pass NULL in which case it returns NULL, too).
1021 l
= k
= strlen(path
);
1022 if (l
== 0) /* special case — an empty string */
1025 while (k
> 0 && path
[k
-1] == '/')
1028 if (k
== 0) /* the root directory */
1029 return path
+ l
- 1;
1031 while (k
> 0 && path
[k
-1] != '/')
1037 int path_extract_filename(const char *path
, char **ret
) {
1038 _cleanup_free_
char *a
= NULL
;
1039 const char *c
, *next
= NULL
;
1042 /* Extracts the filename part (i.e. right-most component) from a path, i.e. string that passes
1043 * filename_is_valid(). A wrapper around last_path_component(), but eats up trailing
1046 * -EINVAL → if the path is not valid
1047 * -EADDRNOTAVAIL → if only a directory was specified, but no filename, i.e. the root dir
1048 * itself or "." is specified
1049 * -ENOMEM → no memory
1051 * Returns >= 0 on success. If the input path has a trailing slash, returns O_DIRECTORY, to
1052 * indicate the referenced file must be a directory.
1054 * This function guarantees to return a fully valid filename, i.e. one that passes
1055 * filename_is_valid() – this means "." and ".." are not accepted. */
1057 if (!path_is_valid(path
))
1060 r
= path_find_last_component(path
, false, &next
, &c
);
1063 if (r
== 0) /* root directory */
1064 return -EADDRNOTAVAIL
;
1071 return strlen(c
) > (size_t)r
? O_DIRECTORY
: 0;
1074 int path_extract_directory(const char *path
, char **ret
) {
1075 _cleanup_free_
char *a
= NULL
;
1076 const char *c
, *next
= NULL
;
1079 /* The inverse of path_extract_filename(), i.e. returns the directory path prefix. Returns:
1081 * -EINVAL → if the path is not valid
1082 * -EDESTADDRREQ → if no directory was specified in the passed in path, i.e. only a filename was passed
1083 * -EADDRNOTAVAIL → if the passed in parameter had no filename but did have a directory, i.e.
1084 * the root dir itself or "." was specified
1085 * -ENOMEM → no memory (surprise!)
1087 * This function guarantees to return a fully valid path, i.e. one that passes path_is_valid().
1090 r
= path_find_last_component(path
, false, &next
, &c
);
1093 if (r
== 0) /* empty or root */
1094 return isempty(path
) ? -EINVAL
: -EADDRNOTAVAIL
;
1096 if (*path
!= '/') /* filename only */
1097 return -EDESTADDRREQ
;
1106 a
= strndup(path
, next
- path
);
1112 if (!path_is_valid(a
))
1119 bool filename_is_valid(const char *p
) {
1125 if (dot_or_dot_dot(p
))
1128 e
= strchrnul(p
, '/');
1132 if (e
- p
> NAME_MAX
) /* NAME_MAX is counted *without* the trailing NUL byte */
1138 bool path_is_valid_full(const char *p
, bool accept_dot_dot
) {
1142 for (const char *e
= p
;;) {
1145 r
= path_find_first_component(&e
, accept_dot_dot
, NULL
);
1149 if (e
- p
>= PATH_MAX
) /* Already reached the maximum length for a path? (PATH_MAX is counted
1150 * *with* the trailing NUL byte) */
1152 if (*e
== 0) /* End of string? Yay! */
1157 bool path_is_normalized(const char *p
) {
1158 if (!path_is_safe(p
))
1161 if (streq(p
, ".") || startswith(p
, "./") || endswith(p
, "/.") || strstr(p
, "/./"))
1164 if (strstr(p
, "//"))
1170 char *file_in_same_dir(const char *path
, const char *filename
) {
1177 /* This removes the last component of path and appends
1178 * filename, unless the latter is absolute anyway or the
1181 if (path_is_absolute(filename
))
1182 return strdup(filename
);
1184 e
= strrchr(path
, '/');
1186 return strdup(filename
);
1188 k
= strlen(filename
);
1189 ret
= new(char, (e
+ 1 - path
) + k
+ 1);
1193 memcpy(mempcpy(ret
, path
, e
+ 1 - path
), filename
, k
+ 1);
1197 bool hidden_or_backup_file(const char *filename
) {
1202 if (filename
[0] == '.' ||
1203 streq(filename
, "lost+found") ||
1204 streq(filename
, "aquota.user") ||
1205 streq(filename
, "aquota.group") ||
1206 endswith(filename
, "~"))
1209 p
= strrchr(filename
, '.');
1213 /* Please, let's not add more entries to the list below. If external projects think it's a good idea to come up
1214 * with always new suffixes and that everybody else should just adjust to that, then it really should be on
1215 * them. Hence, in future, let's not add any more entries. Instead, let's ask those packages to instead adopt
1216 * one of the generic suffixes/prefixes for hidden files or backups, possibly augmented with an additional
1217 * string. Specifically: there's now:
1219 * The generic suffixes "~" and ".bak" for backup files
1220 * The generic prefix "." for hidden files
1222 * Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old", ".foopkg-dist"
1223 * or so registered, let's refuse that and ask them to use ".foopkg.new", ".foopkg.old" or ".foopkg~" instead.
1226 return STR_IN_SET(p
+ 1,
1246 bool is_device_path(const char *path
) {
1248 /* Returns true on paths that likely refer to a device, either by path in sysfs or to something in /dev */
1250 return PATH_STARTSWITH_SET(path
, "/dev/", "/sys/");
1253 bool valid_device_node_path(const char *path
) {
1255 /* Some superficial checks whether the specified path is a valid device node path, all without looking at the
1256 * actual device node. */
1258 if (!PATH_STARTSWITH_SET(path
, "/dev/", "/run/systemd/inaccessible/"))
1261 if (endswith(path
, "/")) /* can't be a device node if it ends in a slash */
1264 return path_is_normalized(path
);
1267 bool valid_device_allow_pattern(const char *path
) {
1270 /* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
1273 if (STARTSWITH_SET(path
, "block-", "char-"))
1276 return valid_device_node_path(path
);
1279 int systemd_installation_has_version(const char *root
, unsigned minimal_version
) {
1280 const char *pattern
;
1283 /* Try to guess if systemd installation is later than the specified version. This
1284 * is hacky and likely to yield false negatives, particularly if the installation
1285 * is non-standard. False positives should be relatively rare.
1288 NULSTR_FOREACH(pattern
,
1289 /* /lib works for systems without usr-merge, and for systems with a sane
1290 * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary
1291 * for Gentoo which does a merge without making /lib a symlink.
1293 "lib/systemd/libsystemd-shared-*.so\0"
1294 "lib64/systemd/libsystemd-shared-*.so\0"
1295 "usr/lib/systemd/libsystemd-shared-*.so\0"
1296 "usr/lib64/systemd/libsystemd-shared-*.so\0") {
1298 _cleanup_strv_free_
char **names
= NULL
;
1299 _cleanup_free_
char *path
= NULL
;
1302 path
= path_join(root
, pattern
);
1306 r
= glob_extend(&names
, path
, 0);
1312 assert_se(c
= endswith(path
, "*.so"));
1313 *c
= '\0'; /* truncate the glob part */
1315 STRV_FOREACH(name
, names
) {
1316 /* This is most likely to run only once, hence let's not optimize anything. */
1320 t
= startswith(*name
, path
);
1324 t2
= endswith(t
, ".so");
1328 t2
[0] = '\0'; /* truncate the suffix */
1330 r
= safe_atou(t
, &version
);
1332 log_debug_errno(r
, "Found libsystemd shared at \"%s.so\", but failed to parse version: %m", *name
);
1336 log_debug("Found libsystemd shared at \"%s.so\", version %u (%s).",
1338 version
>= minimal_version
? "OK" : "too old");
1339 if (version
>= minimal_version
)
1347 bool dot_or_dot_dot(const char *path
) {
1357 return path
[2] == 0;
1360 bool empty_or_root(const char *path
) {
1362 /* For operations relative to some root directory, returns true if the specified root directory is redundant,
1363 * i.e. either / or NULL or the empty string or any equivalent. */
1368 return path_equal(path
, "/");
1371 bool path_strv_contains(char **l
, const char *path
) {
1375 if (path_equal(*i
, path
))
1381 bool prefixed_path_strv_contains(char **l
, const char *path
) {
1384 STRV_FOREACH(i
, l
) {
1390 if (path_equal(j
, path
))