if (!dir)
return -ENOMEM;
- c = path_join_many(dir, with_instance ?: name);
+ c = path_join(dir, with_instance ?: name);
if (!c)
return -ENOMEM;
p2 = path_startswith(path, *dir);
if (p2) {
/* Our new entry has higher priority */
- t = path_join_many(strempty(root), path);
+ t = path_join(strempty(root), path);
if (!t)
return log_oom();
/* … we are not there yet, let's continue */
}
- t = path_join_many(strempty(root), path);
+ t = path_join(strempty(root), path);
if (!t)
return log_oom();
if (r < 0)
return log_error_errno(r, "Failed to extend config file list: %m");
- p = path_join_many(strempty(root), replacement);
+ p = path_join(strempty(root), replacement);
if (!p)
return log_oom();
}
if (r < 0)
return r;
- c = path_join_many(cwd, p);
+ c = path_join(cwd, p);
}
if (!c)
return -ENOMEM;
return path_equal(a, b) || files_same(a, b, flags) > 0;
}
-char* path_join_many_internal(const char *first, ...) {
+char* path_join_internal(const char *first, ...) {
char *joined, *q;
const char *p;
va_list ap;
*
* Examples:
*
- * path_join_many("foo", "bar") → "foo/bar"
- * path_join_many("foo/", "bar") → "foo/bar"
- * path_join_many("", "foo", "", "bar", "") → "foo/bar" */
+ * path_join("foo", "bar") → "foo/bar"
+ * path_join("foo/", "bar") → "foo/bar"
+ * path_join("", "foo", "", "bar", "") → "foo/bar" */
sz = strlen(first);
va_start(ap, first);
int path_compare(const char *a, const char *b) _pure_;
bool path_equal(const char *a, const char *b) _pure_;
bool path_equal_or_files_same(const char *a, const char *b, int flags);
-char* path_join_many_internal(const char *first, ...) _sentinel_;
-#define path_join_many(x, ...) path_join_many_internal(x, __VA_ARGS__, NULL)
+char* path_join_internal(const char *first, ...) _sentinel_;
+#define path_join(x, ...) path_join_internal(x, __VA_ARGS__, NULL)
char* path_simplify(char *path, bool kill_dots);
if (r < 0)
return r;
- path = abspath = path_join_many(p, path);
+ path = abspath = path_join(p, path);
if (!path)
return -ENOMEM;
}
case ACTION_UPDATE_CATALOG: {
_cleanup_free_ char *database;
- database = path_join_many(strempty(arg_root), CATALOG_DATABASE);
+ database = path_join(strempty(arg_root), CATALOG_DATABASE);
if (!database) {
r = log_oom();
goto finish;
log_debug("strings dedup'ed: %8zu bytes (%8zu)",
trie->strings->dedup_len, trie->strings->dedup_count);
- hwdb_bin = path_join_many(strempty(root), hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin");
+ hwdb_bin = path_join(strempty(root), hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin");
if (!hwdb_bin)
return -ENOMEM;
N = argc - 1;
fnames = argv + 1;
} else {
- pkts_glob = path_join_many(get_testdata_dir(), "test-resolve/*.pkts");
+ pkts_glob = path_join(get_testdata_dir(), "test-resolve/*.pkts");
assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;
STRV_FOREACH(p, paths->search_path) {
char *path;
- path = path_join_many(*p, dropin_dir_name);
+ path = path_join(*p, dropin_dir_name);
if (!path)
return -ENOMEM;
STRV_FOREACH(p, paths->search_path) {
char *path;
- path = path_join_many(*p, dropin_template_dir_name);
+ path = path_join(*p, dropin_template_dir_name);
if (!path)
return -ENOMEM;
if (r < 0)
return log_error_errno(r, "Failed to query file list: %m");
- path = path_join_many(strempty(root), "/etc", name);
+ path = path_join(strempty(root), "/etc", name);
if (!path)
return log_oom();
assert_se(readlink_and_make_absolute("/proc/self/exe", &s) >= 0);
dirname(s);
- envpath = path_join_many(s, "systemd-runtest.env");
+ envpath = path_join(s, "systemd-runtest.env");
if (load_env_file_pairs(NULL, envpath, &pairs) < 0)
return;
_cleanup_free_ char *path = NULL, *lpath = NULL;
int r;
- path = path_join_many(*p, unit_name);
+ path = path_join(*p, unit_name);
if (!path)
return log_oom();
return -EINVAL;
}
- kernel = path_join_many(where, e->kernel);
+ kernel = path_join(where, e->kernel);
if (!strv_isempty(e->initrd))
- initrd = path_join_many(where, *e->initrd);
+ initrd = path_join(where, *e->initrd);
options = strv_join(e->options, " ");
if (!options)
return log_oom();
if (found_native && streq(verb, "is-enabled"))
continue;
- p = path_join_many(strempty(arg_root), SYSTEM_SYSVINIT_PATH, name);
+ p = path_join(strempty(arg_root), SYSTEM_SYSVINIT_PATH, name);
if (!p)
return log_oom();
return log_tests_skipped("cgroupfs not available");
assert_se(runtime_dir = setup_fake_runtime_dir());
- test_execute_path = path_join_many(get_testdata_dir(), "test-execute");
+ test_execute_path = path_join(get_testdata_dir(), "test-execute");
assert_se(set_unit_path(test_execute_path) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
_cleanup_free_ char *journal_data_path = NULL;
int r;
- journal_data_path = path_join_many(get_testdata_dir(), "journal-data/journal-1.txt");
+ journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt");
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
_cleanup_free_ char *journal_data_path = NULL;
int r;
- journal_data_path = path_join_many(get_testdata_dir(), "journal-data/journal-2.txt");
+ journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt");
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
/* file mountpoints */
assert_se(mkdtemp(tmp_dir) != NULL);
- file1 = path_join_many(tmp_dir, "file1");
+ file1 = path_join(tmp_dir, "file1");
assert_se(file1);
- file2 = path_join_many(tmp_dir, "file2");
+ file2 = path_join(tmp_dir, "file2");
assert_se(file2);
fd = open(file1, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
assert_se(fd > 0);
fd = open(file2, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
assert_se(fd > 0);
close(fd);
- link1 = path_join_many(tmp_dir, "link1");
+ link1 = path_join(tmp_dir, "link1");
assert_se(link1);
assert_se(symlink("file1", link1) == 0);
- link2 = path_join_many(tmp_dir, "link2");
+ link2 = path_join(tmp_dir, "link2");
assert_se(link1);
assert_se(symlink("file2", link2) == 0);
assert_se(path_is_mount_point(link1, NULL, 0) == 0);
/* directory mountpoints */
- dir1 = path_join_many(tmp_dir, "dir1");
+ dir1 = path_join(tmp_dir, "dir1");
assert_se(dir1);
assert_se(mkdir(dir1, 0755) == 0);
- dirlink1 = path_join_many(tmp_dir, "dirlink1");
+ dirlink1 = path_join(tmp_dir, "dirlink1");
assert_se(dirlink1);
assert_se(symlink("dir1", dirlink1) == 0);
- dirlink1file = path_join_many(tmp_dir, "dirlink1file");
+ dirlink1file = path_join(tmp_dir, "dirlink1file");
assert_se(dirlink1file);
assert_se(symlink("dirlink1/file", dirlink1file) == 0);
- dir2 = path_join_many(tmp_dir, "dir2");
+ dir2 = path_join(tmp_dir, "dir2");
assert_se(dir2);
assert_se(mkdir(dir2, 0755) == 0);
assert_se(path_is_mount_point(dirlink1, NULL, 0) == 0);
/* file in subdirectory mountpoints */
- dir1file = path_join_many(dir1, "file");
+ dir1file = path_join(dir1, "file");
assert_se(dir1file);
fd = open(dir1file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
assert_se(fd > 0);
assert_se(rlt == 1);
/* dirs */
- dir2file = path_join_many(dir2, "file");
+ dir2file = path_join(dir2, "file");
assert_se(dir2file);
fd = open(dir2file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
assert_se(fd > 0);
static void test_path_join(void) {
-#define test_join(root, path, rest, expected) { \
+#define test_join(expected, ...) { \
_cleanup_free_ char *z = NULL; \
- z = path_join_many(strempty(root), path, rest); \
+ z = path_join(__VA_ARGS__); \
+ log_debug("got \"%s\", expected \"%s\"", z, expected); \
assert_se(streq(z, expected)); \
}
- test_join("/root", "/a/b", "/c", "/root/a/b/c");
- test_join("/root", "a/b", "c", "/root/a/b/c");
- test_join("/root", "/a/b", "c", "/root/a/b/c");
- test_join("/root", "/", "c", "/root/c");
- test_join("/root", "/", NULL, "/root/");
-
- test_join(NULL, "/a/b", "/c", "/a/b/c");
- test_join(NULL, "a/b", "c", "a/b/c");
- test_join(NULL, "/a/b", "c", "/a/b/c");
- test_join(NULL, "/", "c", "/c");
- test_join(NULL, "/", NULL, "/");
+ test_join("/root/a/b/c", "/root", "/a/b", "/c");
+ test_join("/root/a/b/c", "/root", "a/b", "c");
+ test_join("/root/a/b/c", "/root", "/a/b", "c");
+ test_join("/root/c", "/root", "/", "c");
+ test_join("/root/", "/root", "/", NULL);
+
+ test_join("/a/b/c", "", "/a/b", "/c");
+ test_join("a/b/c", "", "a/b", "c");
+ test_join("/a/b/c", "", "/a/b", "c");
+ test_join("/c", "", "/", "c");
+ test_join("/", "", "/", NULL);
+
+ test_join("", "", NULL);
+
+ test_join("foo/bar", "foo", "bar");
+ test_join("foo/bar", "", "foo", "bar");
+ test_join("foo/bar", "", "foo", "", "bar", "");
+ test_join("foo/bar", "", "", "", "", "foo", "", "", "", "bar", "", "", "");
+
+ test_join("//foo///bar//", "", "/", "", "/foo/", "", "/", "", "/bar/", "", "/", "");
+ test_join("/foo/bar/", "/", "foo", "/", "bar", "/");
+ test_join("foo/bar/baz", "foo", "bar", "baz");
+ test_join("foo/bar/baz", "foo/", "bar", "/baz");
+ test_join("foo//bar//baz", "foo/", "/bar/", "/baz");
+ test_join("//foo////bar////baz//", "//foo/", "///bar/", "///baz//");
}
static void test_fsck_exists(void) {
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "", "/zzz"), NULL));
}
-static void test_path_join_many(void) {
- char *j;
-
- assert_se(streq_ptr(j = path_join_many("", NULL), ""));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("foo", NULL), "foo"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("foo", "bar"), "foo/bar"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("", "foo", "", "bar", ""), "foo/bar"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("", "", "", "", "foo", "", "", "", "bar", "", "", ""), "foo/bar"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("", "/", "", "/foo/", "", "/", "", "/bar/", "", "/", ""), "//foo///bar//"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("/", "foo", "/", "bar", "/"), "/foo/bar/"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("foo", "bar", "baz"), "foo/bar/baz"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("foo/", "bar", "/baz"), "foo/bar/baz"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("foo/", "/bar/", "/baz"), "foo//bar//baz"));
- free(j);
-
- assert_se(streq_ptr(j = path_join_many("//foo/", "///bar/", "///baz//"), "//foo////bar////baz//"));
- free(j);
-}
-
int main(int argc, char **argv) {
test_setup_logging(LOG_DEBUG);
test_skip_dev_prefix();
test_empty_or_root();
test_path_startswith_set();
- test_path_join_many();
test_systemd_installation_has_version(argv[1]); /* NULL is OK */
test_setup_logging(LOG_INFO);
- test_path = path_join_many(get_testdata_dir(), "test-path");
+ test_path = path_join(get_testdata_dir(), "test-path");
assert_se(set_unit_path(test_path) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
if (fname)
- fname = testdata_fname = path_join_many(get_testdata_dir(), fname);
+ fname = testdata_fname = path_join(get_testdata_dir(), fname);
LIST_HEAD_INIT(mp_list_head);
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
if (fname)
- fname = testdata_fname = path_join_many(get_testdata_dir(), fname);
+ fname = testdata_fname = path_join(get_testdata_dir(), fname);
LIST_HEAD_INIT(mp_list_head);
assert_se(swap_list_get(fname, &mp_list_head) >= 0);
else {
_cleanup_free_ char *de_path = NULL;
- de_path = path_join_many(path, de->d_name);
+ de_path = path_join(path, de->d_name);
if (!de_path)
q = log_oom();
else
if (!path_is_absolute(argv[0])) {
char *program;
- program = path_join_many(UDEVLIBEXECDIR, argv[0]);
+ program = path_join(UDEVLIBEXECDIR, argv[0]);
if (!program)
return log_oom();
return log_device_debug_errno(dev, r, "Failed to get id_filename: %m");
util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
- dirname = path_join_many("/run/udev/links/", name_enc);
+ dirname = path_join("/run/udev/links/", name_enc);
if (!dirname)
return log_oom();
- filename = path_join_many(dirname, id_filename);
+ filename = path_join(dirname, id_filename);
if (!filename)
return log_oom();
if (arg_dry_run)
continue;
- filename = path_join_many(syspath, "uevent");
+ filename = path_join(syspath, "uevent");
if (!filename)
return log_oom();
assert(ret);
if (prefix && !path_startswith(id, prefix)) {
- buf = path_join_many(prefix, id);
+ buf = path_join(prefix, id);
if (!buf)
return -ENOMEM;
id = buf;