diff options
| author | verdant <im@verdant.ee> | 2026-07-23 18:54:04 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-07-23 18:54:04 +0800 |
| commit | 58fce4c9cbe54a5393fbe8c78970fdbc0da0f8f7 (patch) | |
| tree | f521bed561fecdf8c4300139d4374d7a6ad103a0 /main.c | |
| parent | 117e143c6feccfc90b1d3fa9c026a11e0fefe453 (diff) | |
| download | sf-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.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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); } |
