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
+16
View File
@@ -85,6 +85,22 @@ static inline char* path_simplify(char *path) {
return path_simplify_full(path, 0);
}
static inline int path_simplify_alloc(const char *path, char **ret) {
assert(ret);
if (!path) {
*ret = NULL;
return 0;
}
char *t = strdup(path);
if (!t)
return -ENOMEM;
*ret = path_simplify(t);
return 0;
}
static inline bool path_equal_ptr(const char *a, const char *b) {
return !!a == !!b && (!a || path_equal(a, b));
}