aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-04 20:20:15 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-04 20:20:15 +0200
commit77d0498b6c7c52772dbcc3ce53edadf5b9505430 (patch)
tree540d23e43ed403a067021f102b9f8a3768be3d55
parentd6815bf78f37500bc378fdd406387ee6ef869d46 (diff)
downloadmblaze-77d0498b6c7c52772dbcc3ce53edadf5b9505430.tar.gz
seq: fix message number reporting when using iterdir
-rw-r--r--seq.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/seq.c b/seq.c
index c71a666..fd541b3 100644
--- a/seq.c
+++ b/seq.c
@@ -315,17 +315,19 @@ blaze822_seq_next(char *map, char *range, struct blaze822_seq_iter *iter)
return r;
}
-static void
+static long
iterdir(char *dir, void (*cb)(char *))
{
DIR *fd, *fd2;
struct dirent *d;
+ long i = 0;
+
fd = opendir(dir);
if (!fd) {
if (errno == ENOTDIR)
cb(dir);
- return;
+ return 1;
}
char sub[PATH_MAX];
@@ -348,8 +350,11 @@ iterdir(char *dir, void (*cb)(char *))
else
snprintf(sub, sizeof sub, "%s/%s", dir, d->d_name);
cb(sub);
+ i++;
}
closedir(fd);
+
+ return i;
}
int
@@ -376,8 +381,7 @@ blaze822_loop(int argc, char *argv[], void (*cb)(char *))
int j = 0;
for (i = 0; i < argc; i++) {
if (strchr(argv[i], '/')) { // a file name
- iterdir(argv[i], cb);
- j++;
+ j += iterdir(argv[i], cb);
} else {
while ((line = blaze822_seq_next(map, argv[i], &iter))) {
cb(line);