sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit ba8ca986a4c5c0e8ad419e7237da5b8dedd6002c
parent f67320ce937c21b85b4e0bfb1ee4c3e21e9801fb
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 10 Jul 2014 20:30:47 +0000

util/enmasse: fix double /

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mutil/enmasse.c | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/util/enmasse.c b/util/enmasse.c @@ -12,13 +12,13 @@ void enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) { char *buf, *dir; - int i; + int i, len; long size; struct stat st; + size_t dlen; if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) { fnck(argv[0], argv[1], fn); - return; } else { dir = (argc == 1) ? "." : argv[--argc]; @@ -26,9 +26,14 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) apathmax(&buf, &size); for(i = 0; i < argc; i++) { - if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) >= size) { + dlen = strlen(dir); + if(dlen > 0 && dir[dlen - 1] == '/') + len = snprintf(buf, size, "%s%s", dir, basename(argv[i])); + else + len = snprintf(buf, size, "%s/%s", dir, basename(argv[i])); + if(len < 0 || len >= size) { eprintf("%s/%s: filename too long\n", dir, - basename(argv[i])); + basename(argv[i])); } fnck(argv[i], buf, fn); }