mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
path-util: document a few other special cases for last_path_component()
This commit is contained in:
parent
342f6f80f5
commit
8460289f35
@ -715,16 +715,23 @@ char* dirname_malloc(const char *path) {
|
||||
}
|
||||
|
||||
const char *last_path_component(const char *path) {
|
||||
/* Finds the last component of the path, preserving the
|
||||
* optional trailing slash that signifies a directory.
|
||||
|
||||
/* Finds the last component of the path, preserving the optional trailing slash that signifies a directory.
|
||||
*
|
||||
* a/b/c → c
|
||||
* a/b/c/ → c/
|
||||
* x → x
|
||||
* x/ → x/
|
||||
* /y → y
|
||||
* /y/ → y/
|
||||
* / → /
|
||||
* // → /
|
||||
* /foo/a → a
|
||||
* /foo/a/ → a/
|
||||
* This is different than basename, which returns "" when
|
||||
* a trailing slash is present.
|
||||
*
|
||||
* Also, the empty string is mapped to itself.
|
||||
*
|
||||
* This is different than basename(), which returns "" when a trailing slash is present.
|
||||
*/
|
||||
|
||||
unsigned l, k;
|
||||
|
@ -399,6 +399,10 @@ static void test_last_path_component(void) {
|
||||
assert_se(streq(last_path_component("/foo/a"), "a"));
|
||||
assert_se(streq(last_path_component("/foo/a/"), "a/"));
|
||||
assert_se(streq(last_path_component(""), ""));
|
||||
assert_se(streq(last_path_component("a"), "a"));
|
||||
assert_se(streq(last_path_component("a/"), "a/"));
|
||||
assert_se(streq(last_path_component("/a"), "a"));
|
||||
assert_se(streq(last_path_component("/a/"), "a/"));
|
||||
}
|
||||
|
||||
static void test_filename_is_valid(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user