libc/dirname: Handle the consecutive '/' correctly
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I8387aca067e91724fb4656cd7af59bbd626ceffa
This commit is contained in:
parent
5a6e08e281
commit
6d8d5af345
|
@ -94,18 +94,23 @@ FAR char *dirname(FAR char *path)
|
|||
p = strrchr(path, '/');
|
||||
if (p)
|
||||
{
|
||||
/* Handle the case where the only '/' in the string is the at the
|
||||
* beginning of the path.
|
||||
*/
|
||||
|
||||
if (p == path)
|
||||
do
|
||||
{
|
||||
return "/";
|
||||
/* Handle the case where the only '/' in the string is the at the
|
||||
* beginning of the path.
|
||||
*/
|
||||
|
||||
if (p == path)
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
/* No, the directory component is the substring before the '/'. */
|
||||
|
||||
*p-- = '\0';
|
||||
}
|
||||
while (*p == '/');
|
||||
|
||||
/* No, the directory component is the substring before the '/'. */
|
||||
|
||||
*p = '\0';
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue