1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "alloc-util.h"
11 #include "path-util.h"
12 #include "process-util.h"
14 #include "stat-util.h"
15 #include "string-util.h"
18 #include "tmpfile-util.h"
22 log_info("DEFAULT_PATH=%s", DEFAULT_PATH
);
23 log_info("DEFAULT_USER_PATH=%s", DEFAULT_USER_PATH
);
27 assert_se(path_is_absolute("/"));
28 assert_se(!path_is_absolute("./"));
30 assert_se(is_path("/dir"));
31 assert_se(is_path("a/b"));
32 assert_se(!is_path("."));
34 assert_se(streq(basename("./aa/bb/../file.da."), "file.da."));
35 assert_se(streq(basename("/aa///.file"), ".file"));
36 assert_se(streq(basename("/aa///file..."), "file..."));
37 assert_se(streq(basename("file.../"), ""));
39 assert_se(PATH_IN_SET("/bin", "/", "/bin", "/foo"));
40 assert_se(PATH_IN_SET("/bin", "/bin"));
41 assert_se(PATH_IN_SET("/bin", "/foo/bar", "/bin"));
42 assert_se(PATH_IN_SET("/", "/", "/", "/foo/bar"));
43 assert_se(!PATH_IN_SET("/", "/abc", "/def"));
45 assert_se(path_equal_ptr(NULL
, NULL
));
46 assert_se(path_equal_ptr("/a", "/a"));
47 assert_se(!path_equal_ptr("/a", "/b"));
48 assert_se(!path_equal_ptr("/a", NULL
));
49 assert_se(!path_equal_ptr(NULL
, "/a"));
51 assert_se(path_equal_filename("/a/c", "/b/c"));
52 assert_se(path_equal_filename("/a", "/a"));
53 assert_se(!path_equal_filename("/a/b", "/a/c"));
54 assert_se(!path_equal_filename("/b", "/c"));
57 static void test_path_simplify_one(const char *in
, const char *out
) {
62 log_debug("/* test_path_simplify(%s) → %s (expected: %s) */", in
, p
, out
);
63 assert_se(streq(p
, out
));
67 _cleanup_free_
char *hoge
= NULL
, *hoge_out
= NULL
;
68 char foo
[NAME_MAX
* 2];
70 test_path_simplify_one("", "");
71 test_path_simplify_one("aaa/bbb////ccc", "aaa/bbb/ccc");
72 test_path_simplify_one("//aaa/.////ccc", "/aaa/ccc");
73 test_path_simplify_one("///", "/");
74 test_path_simplify_one("///.//", "/");
75 test_path_simplify_one("///.//.///", "/");
76 test_path_simplify_one("////.././///../.", "/../..");
77 test_path_simplify_one(".", ".");
78 test_path_simplify_one("./", ".");
79 test_path_simplify_one(".///.//./.", ".");
80 test_path_simplify_one(".///.//././/", ".");
81 test_path_simplify_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.",
82 "/aaa/.bbb/../c./d.dd/..eeee");
83 test_path_simplify_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
84 "/aaa/.bbb/../c./d.dd/..eeee/..");
85 test_path_simplify_one(".//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
86 "aaa/.bbb/../c./d.dd/..eeee/..");
87 test_path_simplify_one("..//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
88 "../aaa/.bbb/../c./d.dd/..eeee/..");
90 memset(foo
, 'a', sizeof(foo
) -1);
93 test_path_simplify_one(foo
, foo
);
95 hoge
= strjoin("/", foo
);
97 test_path_simplify_one(hoge
, hoge
);
100 hoge
= strjoin("a////.//././//./b///././/./c/////././//./", foo
, "//.//////d/e/.//f/");
103 hoge_out
= strjoin("a/b/c/", foo
, "//.//////d/e/.//f/");
106 test_path_simplify_one(hoge
, hoge_out
);
109 static void test_path_compare_one(const char *a
, const char *b
, int expected
) {
112 assert_se(path_compare(a
, a
) == 0);
113 assert_se(path_compare(b
, b
) == 0);
115 r
= path_compare(a
, b
);
116 assert_se((r
> 0) == (expected
> 0) && (r
< 0) == (expected
< 0));
117 r
= path_compare(b
, a
);
118 assert_se((r
< 0) == (expected
> 0) && (r
> 0) == (expected
< 0));
120 assert_se(path_equal(a
, a
) == 1);
121 assert_se(path_equal(b
, b
) == 1);
122 assert_se(path_equal(a
, b
) == (expected
== 0));
123 assert_se(path_equal(b
, a
) == (expected
== 0));
127 test_path_compare_one("/goo", "/goo", 0);
128 test_path_compare_one("/goo", "/goo", 0);
129 test_path_compare_one("//goo", "/goo", 0);
130 test_path_compare_one("//goo/////", "/goo", 0);
131 test_path_compare_one("goo/////", "goo", 0);
132 test_path_compare_one("/goo/boo", "/goo//boo", 0);
133 test_path_compare_one("//goo/boo", "/goo/boo//", 0);
134 test_path_compare_one("//goo/././//./boo//././//", "/goo/boo//.", 0);
135 test_path_compare_one("/.", "//.///", 0);
136 test_path_compare_one("/x", "x/", 1);
137 test_path_compare_one("x/", "/", -1);
138 test_path_compare_one("/x/./y", "x/y", 1);
139 test_path_compare_one("/x/./y", "/x/y", 0);
140 test_path_compare_one("/x/./././y", "/x/y/././.", 0);
141 test_path_compare_one("./x/./././y", "./x/y/././.", 0);
142 test_path_compare_one(".", "./.", 0);
143 test_path_compare_one(".", "././.", 0);
144 test_path_compare_one("./..", ".", 1);
145 test_path_compare_one("x/.y", "x/y", -1);
146 test_path_compare_one("foo", "/foo", -1);
147 test_path_compare_one("/foo", "/foo/bar", -1);
148 test_path_compare_one("/foo/aaa", "/foo/b", -1);
149 test_path_compare_one("/foo/aaa", "/foo/b/a", -1);
150 test_path_compare_one("/foo/a", "/foo/aaa", -1);
151 test_path_compare_one("/foo/a/b", "/foo/aaa", -1);
154 TEST(path_equal_root
) {
155 /* Nail down the details of how path_equal("/", ...) works. */
157 assert_se(path_equal("/", "/"));
158 assert_se(path_equal("/", "//"));
160 assert_se(path_equal("/", "/./"));
161 assert_se(!path_equal("/", "/../"));
163 assert_se(!path_equal("/", "/.../"));
165 /* Make sure that files_same works as expected. */
167 assert_se(files_same("/", "/", 0) > 0);
168 assert_se(files_same("/", "/", AT_SYMLINK_NOFOLLOW
) > 0);
169 assert_se(files_same("/", "//", 0) > 0);
170 assert_se(files_same("/", "//", AT_SYMLINK_NOFOLLOW
) > 0);
172 assert_se(files_same("/", "/./", 0) > 0);
173 assert_se(files_same("/", "/./", AT_SYMLINK_NOFOLLOW
) > 0);
174 assert_se(files_same("/", "/../", 0) > 0);
175 assert_se(files_same("/", "/../", AT_SYMLINK_NOFOLLOW
) > 0);
177 assert_se(files_same("/", "/.../", 0) == -ENOENT
);
178 assert_se(files_same("/", "/.../", AT_SYMLINK_NOFOLLOW
) == -ENOENT
);
180 /* The same for path_equal_or_files_same. */
182 assert_se(path_equal_or_files_same("/", "/", 0));
183 assert_se(path_equal_or_files_same("/", "/", AT_SYMLINK_NOFOLLOW
));
184 assert_se(path_equal_or_files_same("/", "//", 0));
185 assert_se(path_equal_or_files_same("/", "//", AT_SYMLINK_NOFOLLOW
));
187 assert_se(path_equal_or_files_same("/", "/./", 0));
188 assert_se(path_equal_or_files_same("/", "/./", AT_SYMLINK_NOFOLLOW
));
189 assert_se(path_equal_or_files_same("/", "/../", 0));
190 assert_se(path_equal_or_files_same("/", "/../", AT_SYMLINK_NOFOLLOW
));
192 assert_se(!path_equal_or_files_same("/", "/.../", 0));
193 assert_se(!path_equal_or_files_same("/", "/.../", AT_SYMLINK_NOFOLLOW
));
196 TEST(find_executable_full
) {
198 char* test_file_name
;
199 _cleanup_close_
int fd
= -1;
200 char fn
[] = "/tmp/test-XXXXXX";
202 assert_se(find_executable_full("sh", NULL
, NULL
, true, &p
, NULL
) == 0);
204 assert_se(streq(basename(p
), "sh"));
207 assert_se(find_executable_full("sh", NULL
, NULL
, false, &p
, NULL
) == 0);
209 assert_se(streq(basename(p
), "sh"));
212 _cleanup_free_
char *oldpath
= NULL
;
215 assert_se(oldpath
= strdup(p
));
217 assert_se(unsetenv("PATH") == 0);
219 assert_se(find_executable_full("sh", NULL
, NULL
, true, &p
, NULL
) == 0);
221 assert_se(streq(basename(p
), "sh"));
224 assert_se(find_executable_full("sh", NULL
, NULL
, false, &p
, NULL
) == 0);
226 assert_se(streq(basename(p
), "sh"));
230 assert_se(setenv("PATH", oldpath
, true) >= 0);
232 assert_se((fd
= mkostemp_safe(fn
)) >= 0);
233 assert_se(fchmod(fd
, 0755) >= 0);
235 test_file_name
= basename(fn
);
237 assert_se(find_executable_full(test_file_name
, NULL
, STRV_MAKE("/doesnotexist", "/tmp", "/bin"), false, &p
, NULL
) == 0);
239 assert_se(streq(p
, fn
));
243 assert_se(find_executable_full(test_file_name
, NULL
, STRV_MAKE("/doesnotexist", "/tmp", "/bin"), false, &p
, NULL
) == -ENOENT
);
246 TEST(find_executable
) {
249 assert_se(find_executable("/bin/sh", &p
) == 0);
251 assert_se(path_equal(p
, "/bin/sh"));
254 assert_se(find_executable(saved_argv
[0], &p
) == 0);
256 assert_se(endswith(p
, "/test-path-util"));
257 assert_se(path_is_absolute(p
));
260 assert_se(find_executable("sh", &p
) == 0);
262 assert_se(endswith(p
, "/sh"));
263 assert_se(path_is_absolute(p
));
266 assert_se(find_executable("/bin/touch", &p
) == 0);
267 assert_se(streq(p
, "/bin/touch"));
270 assert_se(find_executable("touch", &p
) == 0);
271 assert_se(path_is_absolute(p
));
272 assert_se(streq(basename(p
), "touch"));
275 assert_se(find_executable("xxxx-xxxx", &p
) == -ENOENT
);
276 assert_se(find_executable("/some/dir/xxxx-xxxx", &p
) == -ENOENT
);
277 assert_se(find_executable("/proc/filesystems", &p
) == -EACCES
);
280 static void test_find_executable_exec_one(const char *path
) {
281 _cleanup_free_
char *t
= NULL
;
282 _cleanup_close_
int fd
= -1;
286 r
= find_executable_full(path
, NULL
, NULL
, false, &t
, &fd
);
288 log_info_errno(r
, "%s: %s → %s: %d/%m", __func__
, path
, t
?: "-", fd
);
290 assert_se(fd
> STDERR_FILENO
);
291 assert_se(path_is_absolute(t
));
292 if (path_is_absolute(path
))
293 assert_se(streq(t
, path
));
298 r
= fexecve_or_execve(fd
, t
, STRV_MAKE(t
, "--version"), STRV_MAKE(NULL
));
299 log_error_errno(r
, "[f]execve: %m");
303 assert_se(wait_for_terminate_and_check(t
, pid
, WAIT_LOG
) == 0);
306 TEST(find_executable_exec
) {
307 test_find_executable_exec_one("touch");
308 test_find_executable_exec_one("/bin/touch");
310 _cleanup_free_
char *script
= NULL
;
311 assert_se(get_testdata_dir("test-path-util/script.sh", &script
) >= 0);
312 test_find_executable_exec_one(script
);
316 static const char* const values
[] = {
329 PATH_FOREACH_PREFIX_MORE(s
, "/a/b/c/d") {
330 log_error("---%s---", s
);
331 assert_se(streq(s
, values
[i
++]));
333 assert_se(values
[i
] == NULL
);
336 PATH_FOREACH_PREFIX(s
, "/a/b/c/d") {
337 log_error("---%s---", s
);
338 assert_se(streq(s
, values
[i
++]));
340 assert_se(values
[i
] == NULL
);
343 PATH_FOREACH_PREFIX_MORE(s
, "////a////b////c///d///////")
344 assert_se(streq(s
, values
[i
++]));
345 assert_se(values
[i
] == NULL
);
348 PATH_FOREACH_PREFIX(s
, "////a////b////c///d///////")
349 assert_se(streq(s
, values
[i
++]));
350 assert_se(values
[i
] == NULL
);
352 PATH_FOREACH_PREFIX(s
, "////")
353 assert_not_reached();
356 PATH_FOREACH_PREFIX_MORE(s
, "////") {
358 assert_se(streq(s
, ""));
363 PATH_FOREACH_PREFIX(s
, "")
364 assert_not_reached();
367 PATH_FOREACH_PREFIX_MORE(s
, "") {
369 assert_se(streq(s
, ""));
375 #define test_join(expected, ...) { \
376 _cleanup_free_ char *z = NULL; \
377 z = path_join(__VA_ARGS__); \
378 log_debug("got \"%s\", expected \"%s\"", z, expected); \
379 assert_se(streq(z, expected)); \
382 test_join("/root/a/b/c", "/root", "/a/b", "/c");
383 test_join("/root/a/b/c", "/root", "a/b", "c");
384 test_join("/root/a/b/c", "/root", "/a/b", "c");
385 test_join("/root/c", "/root", "/", "c");
386 test_join("/root/", "/root", "/", NULL
);
388 test_join("/a/b/c", "", "/a/b", "/c");
389 test_join("a/b/c", "", "a/b", "c");
390 test_join("/a/b/c", "", "/a/b", "c");
391 test_join("/c", "", "/", "c");
392 test_join("/", "", "/", NULL
);
394 test_join("/a/b/c", NULL
, "/a/b", "/c");
395 test_join("a/b/c", NULL
, "a/b", "c");
396 test_join("/a/b/c", NULL
, "/a/b", "c");
397 test_join("/c", NULL
, "/", "c");
398 test_join("/", NULL
, "/", NULL
);
400 test_join("", "", NULL
);
401 test_join("", NULL
, "");
402 test_join("", NULL
, NULL
);
404 test_join("foo/bar", "foo", "bar");
405 test_join("foo/bar", "", "foo", "bar");
406 test_join("foo/bar", NULL
, "foo", NULL
, "bar");
407 test_join("foo/bar", "", "foo", "", "bar", "");
408 test_join("foo/bar", "", "", "", "", "foo", "", "", "", "bar", "", "", "");
410 test_join("//foo///bar//", "", "/", "", "/foo/", "", "/", "", "/bar/", "", "/", "");
411 test_join("/foo/bar/", "/", "foo", "/", "bar", "/");
412 test_join("foo/bar/baz", "foo", "bar", "baz");
413 test_join("foo/bar/baz", "foo/", "bar", "/baz");
414 test_join("foo//bar//baz", "foo/", "/bar/", "/baz");
415 test_join("//foo////bar////baz//", "//foo/", "///bar/", "///baz//");
419 _cleanup_free_
char *p
= NULL
;
421 assert_se(path_extend(&p
, "foo", "bar", "baz") == p
);
422 assert_se(streq(p
, "foo/bar/baz"));
424 assert_se(path_extend(&p
, "foo", "bar", "baz") == p
);
425 assert_se(streq(p
, "foo/bar/baz/foo/bar/baz"));
428 assert_se(path_extend(&p
, "foo") == p
);
429 assert_se(streq(p
, "foo"));
431 assert_se(path_extend(&p
, "/foo") == p
);
432 assert_se(streq(p
, "foo/foo"));
433 assert_se(path_extend(&p
, "/waaaah/wahhh//") == p
);
434 assert_se(streq(p
, "foo/foo/waaaah/wahhh//")); /* path_extend() does not drop redundant slashes */
435 assert_se(path_extend(&p
, "/aaa/bbb/") == p
);
436 assert_se(streq(p
, "foo/foo/waaaah/wahhh///aaa/bbb/")); /* but not add an extra slash */
438 assert_se(free_and_strdup(&p
, "/") >= 0);
439 assert_se(path_extend(&p
, "foo") == p
);
440 assert_se(streq(p
, "/foo"));
444 /* Ensure we use a sane default for PATH. */
445 assert_se(unsetenv("PATH") == 0);
447 /* fsck.minix is provided by util-linux and will probably exist. */
448 assert_se(fsck_exists("minix") == 1);
450 assert_se(fsck_exists("AbCdE") == 0);
451 assert_se(fsck_exists("/../bin/") == 0);
454 static void test_path_make_relative_one(const char *from
, const char *to
, const char *expected
) {
455 _cleanup_free_
char *z
= NULL
;
458 log_info("/* %s(%s, %s) */", __func__
, from
, to
);
460 r
= path_make_relative(from
, to
, &z
);
461 assert_se((r
>= 0) == !!expected
);
462 assert_se(streq_ptr(z
, expected
));
465 TEST(path_make_relative
) {
466 test_path_make_relative_one("some/relative/path", "/some/path", NULL
);
467 test_path_make_relative_one("/some/path", "some/relative/path", NULL
);
468 test_path_make_relative_one("/some/dotdot/../path", "/some/path", NULL
);
470 test_path_make_relative_one("/", "/", ".");
471 test_path_make_relative_one("/", "/some/path", "some/path");
472 test_path_make_relative_one("/some/path", "/some/path", ".");
473 test_path_make_relative_one("/some/path", "/some/path/in/subdir", "in/subdir");
474 test_path_make_relative_one("/some/path", "/", "../..");
475 test_path_make_relative_one("/some/path", "/some/other/path", "../other/path");
476 test_path_make_relative_one("/some/path/./dot", "/some/further/path", "../../further/path");
477 test_path_make_relative_one("//extra.//.//./.slashes//./won't////fo.ol///anybody//", "/././/extra././/.slashes////ar.e/.just/././.fine///", "../../../ar.e/.just/.fine");
480 TEST(path_strv_resolve
) {
481 char tmp_dir
[] = "/tmp/test-path-util-XXXXXX";
482 _cleanup_strv_free_
char **search_dirs
= NULL
;
483 _cleanup_strv_free_
char **absolute_dirs
= NULL
;
486 assert_se(mkdtemp(tmp_dir
) != NULL
);
488 search_dirs
= strv_new("/dir1", "/dir2", "/dir3");
489 assert_se(search_dirs
);
490 STRV_FOREACH(d
, search_dirs
) {
491 char *p
= path_join(tmp_dir
, *d
);
493 assert_se(strv_push(&absolute_dirs
, p
) == 0);
496 assert_se(mkdir(absolute_dirs
[0], 0700) == 0);
497 assert_se(mkdir(absolute_dirs
[1], 0700) == 0);
498 assert_se(symlink("dir2", absolute_dirs
[2]) == 0);
500 path_strv_resolve(search_dirs
, tmp_dir
);
501 assert_se(streq(search_dirs
[0], "/dir1"));
502 assert_se(streq(search_dirs
[1], "/dir2"));
503 assert_se(streq(search_dirs
[2], "/dir2"));
505 assert_se(rm_rf(tmp_dir
, REMOVE_ROOT
|REMOVE_PHYSICAL
) == 0);
508 static void test_path_startswith_one(const char *path
, const char *prefix
, const char *skipped
, const char *expected
) {
511 log_debug("/* %s(%s, %s) */", __func__
, path
, prefix
);
513 p
= path_startswith(path
, prefix
);
514 assert_se(streq_ptr(p
, expected
));
516 q
= strjoina(skipped
, p
);
517 assert_se(streq(q
, path
));
518 assert_se(p
== path
+ strlen(skipped
));
522 TEST(path_startswith
) {
523 test_path_startswith_one("/foo/bar/barfoo/", "/foo", "/foo/", "bar/barfoo/");
524 test_path_startswith_one("/foo/bar/barfoo/", "/foo/", "/foo/", "bar/barfoo/");
525 test_path_startswith_one("/foo/bar/barfoo/", "/", "/", "foo/bar/barfoo/");
526 test_path_startswith_one("/foo/bar/barfoo/", "////", "/", "foo/bar/barfoo/");
527 test_path_startswith_one("/foo/bar/barfoo/", "/foo//bar/////barfoo///", "/foo/bar/barfoo/", "");
528 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfoo////", "/foo/bar/barfoo/", "");
529 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar///barfoo/", "/foo/bar/barfoo/", "");
530 test_path_startswith_one("/foo/bar/barfoo/", "/foo////bar/barfoo/", "/foo/bar/barfoo/", "");
531 test_path_startswith_one("/foo/bar/barfoo/", "////foo/bar/barfoo/", "/foo/bar/barfoo/", "");
532 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfoo", "/foo/bar/barfoo/", "");
534 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfooa/", NULL
, NULL
);
535 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfooa", NULL
, NULL
);
536 test_path_startswith_one("/foo/bar/barfoo/", "", NULL
, NULL
);
537 test_path_startswith_one("/foo/bar/barfoo/", "/bar/foo", NULL
, NULL
);
538 test_path_startswith_one("/foo/bar/barfoo/", "/f/b/b/", NULL
, NULL
);
539 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfo", NULL
, NULL
);
540 test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/bar", NULL
, NULL
);
541 test_path_startswith_one("/foo/bar/barfoo/", "/fo", NULL
, NULL
);
544 static void test_prefix_root_one(const char *r
, const char *p
, const char *expected
) {
545 _cleanup_free_
char *s
= NULL
;
548 assert_se(s
= path_join(r
, p
));
549 assert_se(path_equal_ptr(s
, expected
));
551 t
= prefix_roota(r
, p
);
553 assert_se(path_equal_ptr(t
, expected
));
557 test_prefix_root_one("/", "/foo", "/foo");
558 test_prefix_root_one(NULL
, "/foo", "/foo");
559 test_prefix_root_one("", "/foo", "/foo");
560 test_prefix_root_one("///", "/foo", "/foo");
561 test_prefix_root_one("/", "////foo", "/foo");
562 test_prefix_root_one(NULL
, "////foo", "/foo");
563 test_prefix_root_one("/", "foo", "/foo");
564 test_prefix_root_one("", "foo", "foo");
565 test_prefix_root_one(NULL
, "foo", "foo");
567 test_prefix_root_one("/foo", "/bar", "/foo/bar");
568 test_prefix_root_one("/foo", "bar", "/foo/bar");
569 test_prefix_root_one("foo", "bar", "foo/bar");
570 test_prefix_root_one("/foo/", "/bar", "/foo/bar");
571 test_prefix_root_one("/foo/", "//bar", "/foo/bar");
572 test_prefix_root_one("/foo///", "//bar", "/foo/bar");
575 TEST(file_in_same_dir
) {
578 t
= file_in_same_dir("/", "a");
579 assert_se(streq(t
, "/a"));
582 t
= file_in_same_dir("/", "/a");
583 assert_se(streq(t
, "/a"));
586 t
= file_in_same_dir("", "a");
587 assert_se(streq(t
, "a"));
590 t
= file_in_same_dir("a/", "a");
591 assert_se(streq(t
, "a/a"));
594 t
= file_in_same_dir("bar/foo", "bar");
595 assert_se(streq(t
, "bar/bar"));
599 static void test_path_find_first_component_one(
605 log_debug("/* %s(\"%s\", accept_dot_dot=%s) */", __func__
, strnull(path
), yes_no(accept_dot_dot
));
607 for (const char *p
= path
;;) {
611 r
= path_find_first_component(&p
, accept_dot_dot
, &e
);
615 assert_se(p
== path
+ strlen_ptr(path
));
621 assert_se(strv_isempty(expected
));
626 assert_se(strcspn(e
, "/") == (size_t) r
);
627 assert_se(strlen_ptr(*expected
) == (size_t) r
);
628 assert_se(strneq(e
, *expected
++, r
));
632 TEST(path_find_first_component
) {
633 _cleanup_free_
char *hoge
= NULL
;
634 char foo
[NAME_MAX
* 2];
636 test_path_find_first_component_one(NULL
, false, NULL
, 0);
637 test_path_find_first_component_one("", false, NULL
, 0);
638 test_path_find_first_component_one("/", false, NULL
, 0);
639 test_path_find_first_component_one(".", false, NULL
, 0);
640 test_path_find_first_component_one("./", false, NULL
, 0);
641 test_path_find_first_component_one("./.", false, NULL
, 0);
642 test_path_find_first_component_one("..", false, NULL
, -EINVAL
);
643 test_path_find_first_component_one("/..", false, NULL
, -EINVAL
);
644 test_path_find_first_component_one("./..", false, NULL
, -EINVAL
);
645 test_path_find_first_component_one("////./././//.", false, NULL
, 0);
646 test_path_find_first_component_one("a/b/c", false, STRV_MAKE("a", "b", "c"), 0);
647 test_path_find_first_component_one("././//.///aa/bbb//./ccc", false, STRV_MAKE("aa", "bbb", "ccc"), 0);
648 test_path_find_first_component_one("././//.///aa/.../../bbb//./ccc/.", false, STRV_MAKE("aa", "..."), -EINVAL
);
649 test_path_find_first_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", false, STRV_MAKE("aaa", ".bbb"), -EINVAL
);
650 test_path_find_first_component_one("a/foo./b", false, STRV_MAKE("a", "foo.", "b"), 0);
652 test_path_find_first_component_one(NULL
, true, NULL
, 0);
653 test_path_find_first_component_one("", true, NULL
, 0);
654 test_path_find_first_component_one("/", true, NULL
, 0);
655 test_path_find_first_component_one(".", true, NULL
, 0);
656 test_path_find_first_component_one("./", true, NULL
, 0);
657 test_path_find_first_component_one("./.", true, NULL
, 0);
658 test_path_find_first_component_one("..", true, STRV_MAKE(".."), 0);
659 test_path_find_first_component_one("/..", true, STRV_MAKE(".."), 0);
660 test_path_find_first_component_one("./..", true, STRV_MAKE(".."), 0);
661 test_path_find_first_component_one("////./././//.", true, NULL
, 0);
662 test_path_find_first_component_one("a/b/c", true, STRV_MAKE("a", "b", "c"), 0);
663 test_path_find_first_component_one("././//.///aa/bbb//./ccc", true, STRV_MAKE("aa", "bbb", "ccc"), 0);
664 test_path_find_first_component_one("././//.///aa/.../../bbb//./ccc/.", true, STRV_MAKE("aa", "...", "..", "bbb", "ccc"), 0);
665 test_path_find_first_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", true, STRV_MAKE("aaa", ".bbb", "..", "c.", "d.dd", "..eeee"), 0);
666 test_path_find_first_component_one("a/foo./b", true, STRV_MAKE("a", "foo.", "b"), 0);
668 memset(foo
, 'a', sizeof(foo
) -1);
671 test_path_find_first_component_one(foo
, false, NULL
, -EINVAL
);
672 test_path_find_first_component_one(foo
, true, NULL
, -EINVAL
);
674 hoge
= strjoin("a/b/c/", foo
, "//d/e/.//f/");
677 test_path_find_first_component_one(hoge
, false, STRV_MAKE("a", "b", "c"), -EINVAL
);
678 test_path_find_first_component_one(hoge
, true, STRV_MAKE("a", "b", "c"), -EINVAL
);
681 static void test_path_find_last_component_one(
687 log_debug("/* %s(\"%s\", accept_dot_dot=%s) */", __func__
, strnull(path
), yes_no(accept_dot_dot
));
689 for (const char *next
= NULL
;;) {
693 r
= path_find_last_component(path
, accept_dot_dot
, &next
, &e
);
696 assert_se(next
== path
);
700 assert_se(strv_isempty(expected
));
705 assert_se(strcspn(e
, "/") == (size_t) r
);
706 assert_se(strlen_ptr(*expected
) == (size_t) r
);
707 assert_se(strneq(e
, *expected
++, r
));
711 TEST(path_find_last_component
) {
712 _cleanup_free_
char *hoge
= NULL
;
713 char foo
[NAME_MAX
* 2];
715 test_path_find_last_component_one(NULL
, false, NULL
, 0);
716 test_path_find_last_component_one("", false, NULL
, 0);
717 test_path_find_last_component_one("/", false, NULL
, 0);
718 test_path_find_last_component_one(".", false, NULL
, 0);
719 test_path_find_last_component_one("./", false, NULL
, 0);
720 test_path_find_last_component_one("./.", false, NULL
, 0);
721 test_path_find_last_component_one("..", false, NULL
, -EINVAL
);
722 test_path_find_last_component_one("/..", false, NULL
, -EINVAL
);
723 test_path_find_last_component_one("./..", false, NULL
, -EINVAL
);
724 test_path_find_last_component_one("////./././//.", false, NULL
, 0);
725 test_path_find_last_component_one("a/b/c", false, STRV_MAKE("c", "b", "a"), 0);
726 test_path_find_last_component_one("././//.///aa./.bbb//./ccc/././/", false, STRV_MAKE("ccc", ".bbb", "aa."), 0);
727 test_path_find_last_component_one("././//.///aa/../.../bbb//./ccc/.", false, STRV_MAKE("ccc", "bbb", "..."), -EINVAL
);
728 test_path_find_last_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", false, STRV_MAKE("..eeee", "d.dd", "c."), -EINVAL
);
730 test_path_find_last_component_one(NULL
, true, NULL
, 0);
731 test_path_find_last_component_one("", true, NULL
, 0);
732 test_path_find_last_component_one("/", true, NULL
, 0);
733 test_path_find_last_component_one(".", true, NULL
, 0);
734 test_path_find_last_component_one("./", true, NULL
, 0);
735 test_path_find_last_component_one("./.", true, NULL
, 0);
736 test_path_find_last_component_one("..", true, STRV_MAKE(".."), 0);
737 test_path_find_last_component_one("/..", true, STRV_MAKE(".."), 0);
738 test_path_find_last_component_one("./..", true, STRV_MAKE(".."), 0);
739 test_path_find_last_component_one("////./././//.", true, NULL
, 0);
740 test_path_find_last_component_one("a/b/c", true, STRV_MAKE("c", "b", "a"), 0);
741 test_path_find_last_component_one("././//.///aa./.bbb//./ccc/././/", true, STRV_MAKE("ccc", ".bbb", "aa."), 0);
742 test_path_find_last_component_one("././//.///aa/../.../bbb//./ccc/.", true, STRV_MAKE("ccc", "bbb", "...", "..", "aa"), 0);
743 test_path_find_last_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", true, STRV_MAKE("..eeee", "d.dd", "c.", "..", ".bbb", "aaa"), 0);
745 memset(foo
, 'a', sizeof(foo
) -1);
748 test_path_find_last_component_one(foo
, false, NULL
, -EINVAL
);
749 test_path_find_last_component_one(foo
, true, NULL
, -EINVAL
);
751 hoge
= strjoin(foo
, "/a/b/c/");
754 test_path_find_last_component_one(hoge
, false, STRV_MAKE("c", "b", "a"), -EINVAL
);
755 test_path_find_last_component_one(hoge
, true, STRV_MAKE("c", "b", "a"), -EINVAL
);
758 TEST(last_path_component
) {
759 assert_se(last_path_component(NULL
) == NULL
);
760 assert_se(streq(last_path_component("a/b/c"), "c"));
761 assert_se(streq(last_path_component("a/b/c/"), "c/"));
762 assert_se(streq(last_path_component("/"), "/"));
763 assert_se(streq(last_path_component("//"), "/"));
764 assert_se(streq(last_path_component("///"), "/"));
765 assert_se(streq(last_path_component("."), "."));
766 assert_se(streq(last_path_component("./."), "."));
767 assert_se(streq(last_path_component("././"), "./"));
768 assert_se(streq(last_path_component("././/"), ".//"));
769 assert_se(streq(last_path_component("/foo/a"), "a"));
770 assert_se(streq(last_path_component("/foo/a/"), "a/"));
771 assert_se(streq(last_path_component(""), ""));
772 assert_se(streq(last_path_component("a"), "a"));
773 assert_se(streq(last_path_component("a/"), "a/"));
774 assert_se(streq(last_path_component("/a"), "a"));
775 assert_se(streq(last_path_component("/a/"), "a/"));
778 static void test_path_extract_filename_one(const char *input
, const char *output
, int ret
) {
779 _cleanup_free_
char *k
= NULL
;
782 r
= path_extract_filename(input
, &k
);
783 log_info_errno(r
, "%s → %s/%m [expected: %s/%s]",
785 strnull(k
), /* strerror(r) is printed via %m, to avoid that the two strerror()'s overwrite each other's buffers */
786 strnull(output
), ret
< 0 ? strerror_safe(ret
) : "-");
787 assert_se(streq_ptr(k
, output
));
791 TEST(path_extract_filename
) {
792 test_path_extract_filename_one(NULL
, NULL
, -EINVAL
);
793 test_path_extract_filename_one("a/b/c", "c", 0);
794 test_path_extract_filename_one("a/b/c/", "c", O_DIRECTORY
);
795 test_path_extract_filename_one("/", NULL
, -EADDRNOTAVAIL
);
796 test_path_extract_filename_one("//", NULL
, -EADDRNOTAVAIL
);
797 test_path_extract_filename_one("///", NULL
, -EADDRNOTAVAIL
);
798 test_path_extract_filename_one("/.", NULL
, -EADDRNOTAVAIL
);
799 test_path_extract_filename_one(".", NULL
, -EADDRNOTAVAIL
);
800 test_path_extract_filename_one("./", NULL
, -EADDRNOTAVAIL
);
801 test_path_extract_filename_one("./.", NULL
, -EADDRNOTAVAIL
);
802 test_path_extract_filename_one("././", NULL
, -EADDRNOTAVAIL
);
803 test_path_extract_filename_one("././/", NULL
, -EADDRNOTAVAIL
);
804 test_path_extract_filename_one("/foo/a", "a", 0);
805 test_path_extract_filename_one("/foo/a/", "a", O_DIRECTORY
);
806 test_path_extract_filename_one("", NULL
, -EINVAL
);
807 test_path_extract_filename_one("a", "a", 0);
808 test_path_extract_filename_one("a/", "a", O_DIRECTORY
);
809 test_path_extract_filename_one("a/././//.", "a", O_DIRECTORY
);
810 test_path_extract_filename_one("/a", "a", 0);
811 test_path_extract_filename_one("/a/", "a", O_DIRECTORY
);
812 test_path_extract_filename_one("/a//./.", "a", O_DIRECTORY
);
813 test_path_extract_filename_one("/////////////a/////////////", "a", O_DIRECTORY
);
814 test_path_extract_filename_one("//./a/.///b./././.c//./d//.", "d", O_DIRECTORY
);
815 test_path_extract_filename_one("xx/.", "xx", O_DIRECTORY
);
816 test_path_extract_filename_one("xx/..", NULL
, -EINVAL
);
817 test_path_extract_filename_one("..", NULL
, -EINVAL
);
818 test_path_extract_filename_one("/..", NULL
, -EINVAL
);
819 test_path_extract_filename_one("../", NULL
, -EINVAL
);
822 static void test_path_extract_directory_one(const char *input
, const char *output
, int ret
) {
823 _cleanup_free_
char *k
= NULL
;
826 r
= path_extract_directory(input
, &k
);
827 log_info_errno(r
, "%s → %s/%m [expected: %s/%s]",
829 strnull(k
), /* we output strerror_safe(r) via %m here, since otherwise the error buffer might be overwritten twice */
830 strnull(output
), strerror_safe(ret
));
831 assert_se(streq_ptr(k
, output
));
834 /* Extra safety check: let's make sure that if we split out the filename too (and it works) the
835 * joined parts are identical to the original again */
837 _cleanup_free_
char *f
= NULL
;
839 r
= path_extract_filename(input
, &f
);
841 _cleanup_free_
char *j
= NULL
;
843 assert_se(j
= path_join(k
, f
));
844 assert_se(path_equal(input
, j
));
849 TEST(path_extract_directory
) {
850 test_path_extract_directory_one(NULL
, NULL
, -EINVAL
);
851 test_path_extract_directory_one("a/b/c", "a/b", 0);
852 test_path_extract_directory_one("a/b/c/", "a/b", 0);
853 test_path_extract_directory_one("/", NULL
, -EADDRNOTAVAIL
);
854 test_path_extract_directory_one("//", NULL
, -EADDRNOTAVAIL
);
855 test_path_extract_directory_one("///", NULL
, -EADDRNOTAVAIL
);
856 test_path_extract_directory_one("/.", NULL
, -EADDRNOTAVAIL
);
857 test_path_extract_directory_one(".", NULL
, -EADDRNOTAVAIL
);
858 test_path_extract_directory_one("./", NULL
, -EADDRNOTAVAIL
);
859 test_path_extract_directory_one("./.", NULL
, -EADDRNOTAVAIL
);
860 test_path_extract_directory_one("././", NULL
, -EADDRNOTAVAIL
);
861 test_path_extract_directory_one("././/", NULL
, -EADDRNOTAVAIL
);
862 test_path_extract_directory_one("/foo/a", "/foo", 0);
863 test_path_extract_directory_one("/foo/a/", "/foo", 0);
864 test_path_extract_directory_one("", NULL
, -EINVAL
);
865 test_path_extract_directory_one("a", NULL
, -EDESTADDRREQ
);
866 test_path_extract_directory_one("a/", NULL
, -EDESTADDRREQ
);
867 test_path_extract_directory_one("a/././//.", NULL
, -EDESTADDRREQ
);
868 test_path_extract_directory_one("/a", "/", 0);
869 test_path_extract_directory_one("/a/", "/", 0);
870 test_path_extract_directory_one("/a//./.", "/", 0);
871 test_path_extract_directory_one("/////////////a/////////////", "/", 0);
872 test_path_extract_directory_one("//./a/.///b./././.c//./d//.", "/a/b./.c", 0);
873 test_path_extract_directory_one("xx/.", NULL
, -EDESTADDRREQ
);
874 test_path_extract_directory_one("xx/..", NULL
, -EINVAL
);
875 test_path_extract_directory_one("..", NULL
, -EINVAL
);
876 test_path_extract_directory_one("/..", NULL
, -EINVAL
);
877 test_path_extract_directory_one("../", NULL
, -EINVAL
);
880 TEST(filename_is_valid
) {
881 char foo
[NAME_MAX
+2];
883 assert_se(!filename_is_valid(""));
884 assert_se(!filename_is_valid("/bar/foo"));
885 assert_se(!filename_is_valid("/"));
886 assert_se(!filename_is_valid("."));
887 assert_se(!filename_is_valid(".."));
888 assert_se(!filename_is_valid("bar/foo"));
889 assert_se(!filename_is_valid("bar/foo/"));
890 assert_se(!filename_is_valid("bar//"));
892 memset(foo
, 'a', sizeof(foo
) - 1);
895 assert_se(!filename_is_valid(foo
));
897 assert_se(filename_is_valid("foo_bar-333"));
898 assert_se(filename_is_valid("o.o"));
901 static void test_path_is_valid_and_safe_one(const char *p
, bool ret
) {
902 log_debug("/* %s(\"%s\") */", __func__
, strnull(p
));
904 assert_se(path_is_valid(p
) == ret
);
906 ret
= !streq(p
, "..") &&
907 !startswith(p
, "../") &&
908 !endswith(p
, "/..") &&
910 assert_se(path_is_safe(p
) == ret
);
913 TEST(path_is_valid_and_safe
) {
914 char foo
[PATH_MAX
+2];
917 test_path_is_valid_and_safe_one("", false);
918 test_path_is_valid_and_safe_one("/bar/foo", true);
919 test_path_is_valid_and_safe_one("/bar/foo/", true);
920 test_path_is_valid_and_safe_one("/bar/foo/", true);
921 test_path_is_valid_and_safe_one("//bar//foo//", true);
922 test_path_is_valid_and_safe_one("/", true);
923 test_path_is_valid_and_safe_one("/////", true);
924 test_path_is_valid_and_safe_one("/////.///.////...///..//.", true);
925 test_path_is_valid_and_safe_one(".", true);
926 test_path_is_valid_and_safe_one("..", true);
927 test_path_is_valid_and_safe_one("bar/foo", true);
928 test_path_is_valid_and_safe_one("bar/foo/", true);
929 test_path_is_valid_and_safe_one("bar//", true);
931 memset(foo
, 'a', sizeof(foo
) -1);
934 test_path_is_valid_and_safe_one(foo
, false);
936 c
= strjoina("/xxx/", foo
, "/yyy");
937 test_path_is_valid_and_safe_one(c
, false);
939 test_path_is_valid_and_safe_one("foo_bar-333", true);
940 test_path_is_valid_and_safe_one("o.o", true);
943 TEST(hidden_or_backup_file
) {
944 assert_se(hidden_or_backup_file(".hidden"));
945 assert_se(hidden_or_backup_file("..hidden"));
946 assert_se(!hidden_or_backup_file("hidden."));
948 assert_se(hidden_or_backup_file("backup~"));
949 assert_se(hidden_or_backup_file(".backup~"));
951 assert_se(hidden_or_backup_file("lost+found"));
952 assert_se(hidden_or_backup_file("aquota.user"));
953 assert_se(hidden_or_backup_file("aquota.group"));
955 assert_se(hidden_or_backup_file("test.rpmnew"));
956 assert_se(hidden_or_backup_file("test.dpkg-old"));
957 assert_se(hidden_or_backup_file("test.dpkg-remove"));
958 assert_se(hidden_or_backup_file("test.swp"));
960 assert_se(!hidden_or_backup_file("test.rpmnew."));
961 assert_se(!hidden_or_backup_file("test.dpkg-old.foo"));
964 TEST(systemd_installation_has_version
) {
966 const unsigned versions
[] = {0, 231, PROJECT_VERSION
, 999};
969 log_info("/* %s */", __func__
);
971 for (i
= 0; i
< ELEMENTSOF(versions
); i
++) {
972 r
= systemd_installation_has_version(saved_argv
[1], versions
[i
]);
974 log_info("%s has systemd >= %u: %s",
975 saved_argv
[1] ?: "Current installation", versions
[i
], yes_no(r
));
979 TEST(skip_dev_prefix
) {
980 assert_se(streq(skip_dev_prefix("/"), "/"));
981 assert_se(streq(skip_dev_prefix("/dev"), ""));
982 assert_se(streq(skip_dev_prefix("/dev/"), ""));
983 assert_se(streq(skip_dev_prefix("/dev/foo"), "foo"));
984 assert_se(streq(skip_dev_prefix("/dev/foo/bar"), "foo/bar"));
985 assert_se(streq(skip_dev_prefix("//dev"), ""));
986 assert_se(streq(skip_dev_prefix("//dev//"), ""));
987 assert_se(streq(skip_dev_prefix("/dev///foo"), "foo"));
988 assert_se(streq(skip_dev_prefix("///dev///foo///bar"), "foo///bar"));
989 assert_se(streq(skip_dev_prefix("//foo"), "//foo"));
990 assert_se(streq(skip_dev_prefix("foo"), "foo"));
993 TEST(empty_or_root
) {
994 assert_se(empty_or_root(NULL
));
995 assert_se(empty_or_root(""));
996 assert_se(empty_or_root("/"));
997 assert_se(empty_or_root("//"));
998 assert_se(empty_or_root("///"));
999 assert_se(empty_or_root("/////////////////"));
1000 assert_se(!empty_or_root("xxx"));
1001 assert_se(!empty_or_root("/xxx"));
1002 assert_se(!empty_or_root("/xxx/"));
1003 assert_se(!empty_or_root("//yy//"));
1006 TEST(path_startswith_set
) {
1007 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo/bar", "/zzz"), ""));
1008 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo/", "/zzz"), "bar"));
1009 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo", "/zzz"), "bar"));
1010 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/", "/zzz"), "foo/bar"));
1011 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "", "/zzz"), NULL
));
1013 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar2", "/foo/quux", "/foo/bar", "/zzz"), NULL
));
1014 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar2", "/foo/quux", "/foo/", "/zzz"), "bar2"));
1015 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar2", "/foo/quux", "/foo", "/zzz"), "bar2"));
1016 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar2", "/foo/quux", "/", "/zzz"), "foo/bar2"));
1017 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar2", "/foo/quux", "", "/zzz"), NULL
));
1019 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "/foo/bar", "/zzz"), NULL
));
1020 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "/foo/", "/zzz"), NULL
));
1021 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "/foo", "/zzz"), NULL
));
1022 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "/", "/zzz"), "foo2/bar"));
1023 assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "", "/zzz"), NULL
));
1026 TEST(path_startswith_strv
) {
1027 assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo/bar", "/zzz")), ""));
1028 assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo/", "/zzz")), "bar"));
1029 assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo", "/zzz")), "bar"));
1030 assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/", "/zzz")), "foo/bar"));
1031 assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "", "/zzz")), NULL
));
1033 assert_se(streq_ptr(path_startswith_strv("/foo/bar2", STRV_MAKE("/foo/quux", "/foo/bar", "/zzz")), NULL
));
1034 assert_se(streq_ptr(path_startswith_strv("/foo/bar2", STRV_MAKE("/foo/quux", "/foo/", "/zzz")), "bar2"));
1035 assert_se(streq_ptr(path_startswith_strv("/foo/bar2", STRV_MAKE("/foo/quux", "/foo", "/zzz")), "bar2"));
1036 assert_se(streq_ptr(path_startswith_strv("/foo/bar2", STRV_MAKE("/foo/quux", "/", "/zzz")), "foo/bar2"));
1037 assert_se(streq_ptr(path_startswith_strv("/foo/bar2", STRV_MAKE("/foo/quux", "", "/zzz")), NULL
));
1039 assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "/foo/bar", "/zzz")), NULL
));
1040 assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "/foo/", "/zzz")), NULL
));
1041 assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "/foo", "/zzz")), NULL
));
1042 assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "/", "/zzz")), "foo2/bar"));
1043 assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "", "/zzz")), NULL
));
1047 log_info("PATH_MAX=%zu\n"
1048 "FILENAME_MAX=%zu\n"
1051 (size_t) FILENAME_MAX
,
1054 assert_cc(FILENAME_MAX
== PATH_MAX
);
1057 DEFINE_TEST_MAIN(LOG_DEBUG
);