path-util: tighten path_extract_filename()

Let's tighten the logic behind path_extract_filename() a bit: first of
all, refuse all cases of invalid paths with -EINVAL. More importantly
though return a recognizable error when a valid path is specified that
does not contain any filename. Specifically, "/" will now result in
-EADDRNOTAVAIL.

This changes API, but none of the existing callers care about the return
value, hence the change should be fine.
This commit is contained in:
Lennart Poettering
2021-02-02 23:16:38 +00:00
committed by Luca Boccassi
parent 23cfef7bb1
commit 3cdcbdd32f
2 changed files with 16 additions and 15 deletions
+3 -3
View File
@@ -578,9 +578,9 @@ static void test_path_extract_filename(void) {
test_path_extract_filename_one(NULL, NULL, -EINVAL);
test_path_extract_filename_one("a/b/c", "c", 0);
test_path_extract_filename_one("a/b/c/", "c", 0);
test_path_extract_filename_one("/", NULL, -EINVAL);
test_path_extract_filename_one("//", NULL, -EINVAL);
test_path_extract_filename_one("///", NULL, -EINVAL);
test_path_extract_filename_one("/", NULL, -EADDRNOTAVAIL);
test_path_extract_filename_one("//", NULL, -EADDRNOTAVAIL);
test_path_extract_filename_one("///", NULL, -EADDRNOTAVAIL);
test_path_extract_filename_one(".", NULL, -EINVAL);
test_path_extract_filename_one("./.", NULL, -EINVAL);
test_path_extract_filename_one("././", NULL, -EINVAL);