p2 = path_startswith(path, *dir);
if (p2) {
/* Our new entry has higher priority */
- t = path_join(strempty(root), path);
+ t = path_join(root, path);
if (!t)
return log_oom();
/* … we are not there yet, let's continue */
}
- t = path_join(strempty(root), path);
+ t = path_join(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(strempty(root), replacement);
+ p = path_join(root, replacement);
if (!p)
return log_oom();
}
bool slash;
size_t sz;
- assert(first);
-
- /* Joins all listed strings until NULL and places an "/" between them unless the strings end/begin already with
- * one so that it is unnecessary. Note that "/" which are already duplicate won't be removed. The string
- * returned is hence always equal or longer than the sum of the lengths of each individual string.
+ /* Joins all listed strings until the sentinel and places a "/" between them unless the strings end/begin
+ * already with one so that it is unnecessary. Note that slashes which are already duplicate won't be
+ * removed. The string returned is hence always equal to or longer than the sum of the lengths of each
+ * individual string.
*
* Note: any listed empty string is simply skipped. This can be useful for concatenating strings of which some
* are optional.
* path_join("foo/", "bar") → "foo/bar"
* path_join("", "foo", "", "bar", "") → "foo/bar" */
- sz = strlen(first);
+ sz = strlen_ptr(first);
va_start(ap, first);
- while ((p = va_arg(ap, char*))) {
-
- if (*p == 0) /* Skip empty items */
- continue;
-
- sz += 1 + strlen(p);
- }
+ while ((p = va_arg(ap, char*)) != (const char*) -1)
+ if (!isempty(p))
+ sz += 1 + strlen(p);
va_end(ap);
joined = new(char, sz + 1);
if (!joined)
return NULL;
- if (first[0] != 0) {
+ if (!isempty(first)) {
q = stpcpy(joined, first);
slash = endswith(first, "/");
} else {
}
va_start(ap, first);
- while ((p = va_arg(ap, char*))) {
-
- if (*p == 0) /* Skip empty items */
+ while ((p = va_arg(ap, char*)) != (const char*) -1) {
+ if (isempty(p))
continue;
if (!slash && p[0] != '/')
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_internal(const char *first, ...) _sentinel_;
-#define path_join(x, ...) path_join_internal(x, __VA_ARGS__, NULL)
+char* path_join_internal(const char *first, ...);
+#define path_join(x, ...) path_join_internal(x, __VA_ARGS__, (const char*) -1)
char* path_simplify(char *path, bool kill_dots);
case ACTION_UPDATE_CATALOG: {
_cleanup_free_ char *database;
- database = path_join(strempty(arg_root), CATALOG_DATABASE);
+ database = path_join(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(strempty(root), hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin");
+ hwdb_bin = path_join(root, hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin");
if (!hwdb_bin)
return -ENOMEM;
if (r < 0)
return log_error_errno(r, "Failed to query file list: %m");
- path = path_join(strempty(root), "/etc", name);
+ path = path_join(root, "/etc", name);
if (!path)
return log_oom();
if (found_native && streq(verb, "is-enabled"))
continue;
- p = path_join(strempty(arg_root), SYSTEM_SYSVINIT_PATH, name);
+ p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name);
if (!p)
return log_oom();
test_join("/c", "", "/", "c");
test_join("/", "", "/", NULL);
+ test_join("/a/b/c", NULL, "/a/b", "/c");
+ test_join("a/b/c", NULL, "a/b", "c");
+ test_join("/a/b/c", NULL, "/a/b", "c");
+ test_join("/c", NULL, "/", "c");
+ test_join("/", NULL, "/", NULL);
+
test_join("", "", NULL);
+ test_join("", NULL, "");
+ test_join("", NULL, NULL);
test_join("foo/bar", "foo", "bar");
test_join("foo/bar", "", "foo", "bar");
+ test_join("foo/bar", NULL, "foo", NULL, "bar");
test_join("foo/bar", "", "foo", "", "bar", "");
test_join("foo/bar", "", "", "", "", "foo", "", "", "", "bar", "", "", "");