aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-23 18:54:04 +0800
committerverdant <im@verdant.ee>2026-07-23 18:54:04 +0800
commit58fce4c9cbe54a5393fbe8c78970fdbc0da0f8f7 (patch)
treef521bed561fecdf8c4300139d4374d7a6ad103a0 /main.c
parent117e143c6feccfc90b1d3fa9c026a11e0fefe453 (diff)
downloadsf-58fce4c9cbe54a5393fbe8c78970fdbc0da0f8f7.tar.gz
sf-58fce4c9cbe54a5393fbe8c78970fdbc0da0f8f7.zip
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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c13
1 files changed, 13 insertions, 0 deletions
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);
}