util/enmasse: fix double /

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-07-10 20:30:47 +00:00 committed by sin
parent f67320ce93
commit ba8ca986a4

View File

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