commit: 7b5f49a107df7eb8b0c8550de63da2fe993608c1
parent 0133f3fd11fb4e6e83b6da99217c46a1aee0cfb1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 4 Nov 2024 02:13:51 +0100
lib/fs: Skip trailing slashes in static_basename
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/fs.c b/lib/fs.c
@@ -18,11 +18,17 @@
#endif
char *
-static_basename(char *path)
+static_basename(char *p)
{
- char *sep = strrchr(path, '/');
+ if(!p || !*p) return p;
- return (sep == NULL) ? path : sep + 1;
+ size_t i = strlen(p) - 1;
+ for(; i && p[i] == '/'; i--)
+ ;
+ for(; i && p[i - 1] != '/'; i--)
+ ;
+
+ return p + i;
}
char *