libc/dirname: Handle the consecutive '/' correctly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I8387aca067e91724fb4656cd7af59bbd626ceffa
This commit is contained in:
Xiang Xiao 2021-06-23 02:03:46 +08:00 committed by Abdelatif Guettouche
parent 5a6e08e281
commit 6d8d5af345

View File

@ -93,6 +93,8 @@ FAR char *dirname(FAR char *path)
p = strrchr(path, '/');
if (p)
{
do
{
/* Handle the case where the only '/' in the string is the at the
* beginning of the path.
@ -105,7 +107,10 @@ FAR char *dirname(FAR char *path)
/* No, the directory component is the substring before the '/'. */
*p = '\0';
*p-- = '\0';
}
while (*p == '/');
return path;
}