mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
libc/dirname: Handle the consecutive '/' correctly
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I8387aca067e91724fb4656cd7af59bbd626ceffa
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user