tree-wide: add path_simplify_alloc() and use it

path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.

In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.

In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-09-22 08:13:34 +02:00
parent 7902df1263
commit 660087dc9c
13 changed files with 84 additions and 124 deletions
+4 -6
View File
@@ -132,11 +132,9 @@ int path_make_relative(const char *from, const char *to, char **ret) {
return -ENOMEM;
} else {
/* 'to' is inside of 'from'. */
result = strdup(t);
if (!result)
return -ENOMEM;
path_simplify(result);
r = path_simplify_alloc(t, &result);
if (r < 0)
return r;
if (!path_is_valid(result))
return -EINVAL;
@@ -346,7 +344,7 @@ char** path_strv_resolve_uniq(char **l, const char *root) {
char* path_simplify_full(char *path, PathSimplifyFlags flags) {
bool add_slash = false, keep_trailing_slash, absolute, beginning = true;
char *f = ASSERT_PTR(path);
char *f = path;
int r;
/* Removes redundant inner and trailing slashes. Also removes unnecessary dots.