You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/06/24 12:21:10 UTC
[incubator-nuttx] 02/02: libc/dirname: Handle the consecutive '/'
correctly
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 6d8d5af345a0053031aef301e4e97c381f8dee29
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jun 23 02:03:46 2021 +0800
libc/dirname: Handle the consecutive '/' correctly
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: I8387aca067e91724fb4656cd7af59bbd626ceffa
---
libs/libc/libgen/lib_dirname.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/libs/libc/libgen/lib_dirname.c b/libs/libc/libgen/lib_dirname.c
index a48ebb6..2fdfc5b 100644
--- a/libs/libc/libgen/lib_dirname.c
+++ b/libs/libc/libgen/lib_dirname.c
@@ -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.
+ */
- /* No, the directory component is the substring before the '/'. */
+ if (p == path)
+ {
+ return "/";
+ }
+
+ /* No, the directory component is the substring before the '/'. */
+
+ *p-- = '\0';
+ }
+ while (*p == '/');
- *p = '\0';
return path;
}