path_equal already works with NULL pointers.
return 0;
}
-static inline bool path_equal_ptr(const char *a, const char *b) {
- return !!a == !!b && (!a || path_equal(a, b));
-}
-
/* Note: the search terminates on the first NULL item. */
#define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
* When looking under root_dir, we can't expect /dev/ to be mounted,
* so let's see if the path is a (possibly dangling) symlink to /dev/null. */
- if (path_equal_ptr(path_startswith(fn, root ?: "/"), "dev/null"))
+ if (path_equal(path_startswith(fn, root ?: "/"), "dev/null"))
return true;
r = chase_and_stat(fn, root, CHASE_PREFIX_ROOT, NULL, &st);
* to inherit the $TERM set for PID 1. This is useful for containers so that the $TERM the
* container manager passes to PID 1 ends up all the way in the console login shown. */
- if (path_equal_ptr(tty_path, "/dev/console") && getppid() == 1)
+ if (path_equal(tty_path, "/dev/console") && getppid() == 1)
term = getenv("TERM");
else if (tty_path && in_charset(skip_dev_prefix(tty_path), ALPHANUMERICAL)) {
_cleanup_free_ char *key = NULL;
return 0;
/* Do not try to merge initrd credentials into foreign credentials directories */
- if (!path_equal_ptr(creds_dir, SYSTEM_CREDENTIALS_DIRECTORY)) {
+ if (!path_equal(creds_dir, SYSTEM_CREDENTIALS_DIRECTORY)) {
log_debug("Not importing initrd credentials, as foreign $CREDENTIALS_DIRECTORY has been set.");
return 0;
}
/* Fragment paths should also be equal as a custom fragment for a specific template instance
* wouldn't necessarily lead to infinite recursion. */
- if (!path_equal_ptr(u->fragment_path, fragment_path))
+ if (!path_equal(u->fragment_path, fragment_path))
return false;
if (!contains_instance_specifier_superset(format))
return -errno;
/* The kernels sets HOME=/ for init. Let's undo this. */
- if (path_equal_ptr(getenv("HOME"), "/"))
+ if (path_equal(getenv("HOME"), "/"))
assert_se(unsetenv("HOME") == 0);
return 0;
if (r < 0)
return r;
- return path_equal_ptr(parent, lp->generator) ||
- path_equal_ptr(parent, lp->generator_early) ||
- path_equal_ptr(parent, lp->generator_late);
+ return path_equal(parent, lp->generator) ||
+ path_equal(parent, lp->generator_early) ||
+ path_equal(parent, lp->generator_late);
}
static int path_is_transient(const LookupPaths *lp, const char *path) {
if (r < 0)
return r;
- return path_equal_ptr(parent, lp->transient);
+ return path_equal(parent, lp->transient);
}
static int path_is_control(const LookupPaths *lp, const char *path) {
if (r < 0)
return r;
- return path_equal_ptr(parent, lp->persistent_control) ||
- path_equal_ptr(parent, lp->runtime_control);
+ return path_equal(parent, lp->persistent_control) ||
+ path_equal(parent, lp->runtime_control);
}
static int path_is_config(const LookupPaths *lp, const char *path, bool check_parent) {
path = parent;
}
- return path_equal_ptr(path, lp->persistent_config) ||
- path_equal_ptr(path, lp->runtime_config);
+ return path_equal(path, lp->persistent_config) ||
+ path_equal(path, lp->runtime_config);
}
static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_parent) {
path = parent;
}
- return path_equal_ptr(path, lp->runtime_config) ||
- path_equal_ptr(path, lp->generator) ||
- path_equal_ptr(path, lp->generator_early) ||
- path_equal_ptr(path, lp->generator_late) ||
- path_equal_ptr(path, lp->transient) ||
- path_equal_ptr(path, lp->runtime_control);
+ return path_equal(path, lp->runtime_config) ||
+ path_equal(path, lp->generator) ||
+ path_equal(path, lp->generator_early) ||
+ path_equal(path, lp->generator_late) ||
+ path_equal(path, lp->transient) ||
+ path_equal(path, lp->runtime_control);
}
static int path_is_vendor_or_generator(const LookupPaths *lp, const char *path) {
if (r > 0) {
/* We found symlinks in this dir? Yay! Let's see where precisely it is enabled. */
- if (path_equal_ptr(*p, lp->persistent_config)) {
+ if (path_equal(*p, lp->persistent_config)) {
/* This is the best outcome, let's return it immediately. */
*state = UNIT_FILE_ENABLED;
return 1;
enabled_at_all = true;
} else if (same_name_link) {
- if (path_equal_ptr(*p, lp->persistent_config))
+ if (path_equal(*p, lp->persistent_config))
same_name_link_config = true;
else {
r = path_is_runtime(lp, *p, false);
const char *a_shell = pick_shell(a),
*b_shell = pick_shell(b);
- if (!path_equal_ptr(a_shell, b_shell) &&
+ if (!path_equal(a_shell, b_shell) &&
!(is_nologin_shell(a_shell) && is_nologin_shell(b_shell))) {
_cleanup_free_ char *pa = NULL, *pb = NULL;
}
TEST(path) {
- assert_se(path_is_absolute("/"));
+ assert_se( path_is_absolute("/"));
assert_se(!path_is_absolute("./"));
assert_se(streq(basename("./aa/bb/../file.da."), "file.da."));
assert_se(streq(basename("/aa///file..."), "file..."));
assert_se(streq(basename("file.../"), ""));
- assert_se(PATH_IN_SET("/bin", "/", "/bin", "/foo"));
- assert_se(PATH_IN_SET("/bin", "/bin"));
- assert_se(PATH_IN_SET("/bin", "/foo/bar", "/bin"));
- assert_se(PATH_IN_SET("/", "/", "/", "/foo/bar"));
+ assert_se( PATH_IN_SET("/bin", "/", "/bin", "/foo"));
+ assert_se( PATH_IN_SET("/bin", "/bin"));
+ assert_se( PATH_IN_SET("/bin", "/foo/bar", "/bin"));
+ assert_se( PATH_IN_SET("/", "/", "/", "/foo/bar"));
assert_se(!PATH_IN_SET("/", "/abc", "/def"));
- assert_se(path_equal_ptr(NULL, NULL));
- assert_se(path_equal_ptr("/a", "/a"));
- assert_se(!path_equal_ptr("/a", "/b"));
- assert_se(!path_equal_ptr("/a", NULL));
- assert_se(!path_equal_ptr(NULL, "/a"));
+ assert_se( path_equal(NULL, NULL));
+ assert_se( path_equal("/a", "/a"));
+ assert_se(!path_equal("/a", "/b"));
+ assert_se(!path_equal("/a", NULL));
+ assert_se(!path_equal(NULL, "/a"));
+ assert_se(!path_equal("a", NULL));
+ assert_se(!path_equal(NULL, "a"));
}
TEST(is_path) {
const char *t;
assert_se(s = path_join(r, p));
- assert_se(path_equal_ptr(s, expected));
+ assert_se(path_equal(s, expected));
t = prefix_roota(r, p);
assert_se(t);
- assert_se(path_equal_ptr(t, expected));
+ assert_se(path_equal(t, expected));
}
TEST(prefix_root) {