From 58fce4c9cbe54a5393fbe8c78970fdbc0da0f8f7 Mon Sep 17 00:00:00 2001 From: verdant Date: Thu, 23 Jul 2026 18:54:04 +0800 Subject: Add path normalization Add a path_normalize() helper function to remove trailing slashes from directory paths, preventing potential issues with duplicate slashes in file operations. --- main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index ee7a199..550cb40 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,18 @@ #include "version.h" #include "wm.h" +static void path_normalize(char *path) +{ + if (path == NULL) + return; + + size_t len = strlen(path); + while (len > 1 && path[len - 1] == '/') { + path[len - 1] = '\0'; + len--; + } +} + int main(int argc, char **argv) { if (argc > 1 && @@ -50,6 +62,7 @@ int main(int argc, char **argv) snprintf(f->cwd, sizeof(f->cwd), "%s", argv[1]); log_write(LOG_INFO, "f->cwd = %s", f->cwd); log_write(LOG_INFO, "argv[1] = %s", argv[1]); + path_normalize(f->cwd); } else { fm_getcwd(f); } -- cgit v1.2.3