Now the function returns an empty string when given an empty string.
Not sure if this is the best option (maybe this should be an error?),
but at least the behaviour is well defined.
unsigned l, k;
l = k = strlen(path);
+ if (l == 0) /* special case — an empty string */
+ return path;
+
while (k > 0 && path[k-1] == '/')
k--;
assert_se(streq(last_path_component("././/"), ".//"));
assert_se(streq(last_path_component("/foo/a"), "a"));
assert_se(streq(last_path_component("/foo/a/"), "a/"));
+ assert_se(streq(last_path_component(""), ""));
}
static void test_filename_is_valid(void) {