path-util: move empty_or_root_to_null() from chase.c
And rename it to empty_or_root_harder_to_null(), as it also checks if the input path effectively points to the root by calling path_is_root(). This also adds simple test cases for the function.
This commit is contained in:
@@ -1406,6 +1406,27 @@ const char* empty_to_root(const char *path) {
|
||||
return isempty(path) ? "/" : path;
|
||||
}
|
||||
|
||||
int empty_or_root_harder_to_null(const char **path) {
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
|
||||
/* This nullifies the input path when the path is empty or points to "/". */
|
||||
|
||||
if (empty_or_root(*path)) {
|
||||
*path = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = path_is_root(*path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
*path = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool path_strv_contains(char * const *l, const char *path) {
|
||||
assert(path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user