path-util: make iterator for path_find_last_component() always finish with the beginning of the buffer

This commit is contained in:
Yu Watanabe
2023-04-10 09:30:14 +09:00
parent a0d3e0ec79
commit 3a7ba9f6b9
+8
View File
@@ -901,6 +901,8 @@ static const char *skip_slash_or_dot_backward(const char *path, const char *q) {
continue;
if (q > path && strneq(q - 1, "/.", 2))
continue;
if (q == path && *q == '.')
continue;
break;
}
return q;
@@ -925,6 +927,12 @@ int path_find_last_component(const char *path, bool accept_dot_dot, const char *
* ret: "bbbbb/cc//././"
* return value: 5 (== strlen("bbbbb"))
*
* Input: path: "//.//aaa///bbbbb/cc//././"
* next: "///bbbbb/cc//././"
* Output: next: "//.//aaa///bbbbb/cc//././" (next == path)
* ret: "aaa///bbbbb/cc//././"
* return value: 3 (== strlen("aaa"))
*
* Input: path: "/", ".", "", or NULL
* Output: next: equivalent to path
* ret: NULL