aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-06-06 03:36:45 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-06-06 03:48:51 +0200
commit6e9ce3a25b438a94ad870ba85dd8c9bf8a28e043 (patch)
tree548ece97aed1f51397621137af1371a709d83da2
parent6adf1c44adb61a04bf37eb78eb5df5c4302bd768 (diff)
downloadslcl-6e9ce3a25b438a94ad870ba85dd8c9bf8a28e043.tar.gz
ctfw.c: Avoid trailing forward slash
Otherwise, this would generate strings such as "directory//resource" if dirpath contained a trailing slash, which could be problematic for users relying on ctfw.
-rw-r--r--cftw.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/cftw.c b/cftw.c
index c4986fd..d11cb87 100644
--- a/cftw.c
+++ b/cftw.c
@@ -29,12 +29,13 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
if (!strcmp(path, ".") || !strcmp(path, ".."))
continue;
+ const char *const sep = dirpath[strlen(dirpath) - 1] == '/' ? "" : "/";
struct stat sb;
struct dynstr d;
dynstr_init(&d);
- if (dynstr_append(&d, "%s/%s", dirpath, path))
+ if (dynstr_append(&d, "%s%s%s", dirpath, sep, path))
{
fprintf(stderr, "%s: dynstr_append failed\n", __func__);
return -1;