From: Baptiste Daroussin Date: Thu, 5 Jan 2023 08:38:52 +0000 (+0100) Subject: mlmmj-list: simple modernization of the code no change expected X-Git-Tag: RELEASE_1_4_0_a2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf172e98104794bc411276da7e41a86417d2a13a;p=thirdparty%2Fmlmmj.git mlmmj-list: simple modernization of the code no change expected --- diff --git a/src/mlmmj-list.c b/src/mlmmj-list.c index def45e3b..bd38a1e2 100644 --- a/src/mlmmj-list.c +++ b/src/mlmmj-list.c @@ -49,7 +49,7 @@ static void print_help(const char *prg) } static int -dumpcount(int fd, int *count) +dumpcount(int fd, size_t *count) { FILE *f; char *line = NULL; @@ -74,15 +74,16 @@ dumpcount(int fd, int *count) int main(int argc, char **argv) { - int opt, count = 0, docount = 0; + int opt; + size_t count = 0; + bool docount = false; const char *listdir = NULL; const char *subfile = NULL; const char *subdir; DIR *dirp; struct dirent *dp; enum subtype typesub = SUB_NORMAL; - int subdirfd = -1; - int listfd; + int subdirfd = -1, listfd, fd; while ((opt = getopt(argc, argv, "cdhmnosVL:")) != -1) { switch(opt) { @@ -135,30 +136,23 @@ int main(int argc, char **argv) if(dirp == NULL) errx(EXIT_FAILURE, "Could not opendir(%s);", subdir); while((dp = readdir(dirp)) != NULL) { - int fd; if((strcmp(dp->d_name, "..") == 0) || (strcmp(dp->d_name, ".") == 0)) continue; fd = openat(subdirfd, dp->d_name, O_RDONLY|O_CLOEXEC); - if(docount) - dumpcount(fd, &count); - else - dumpcount(fd, NULL); + dumpcount(fd, docount ? &count : NULL); close(fd); } closedir(dirp); } else { - int fd = openat(listfd, subfile, O_RDONLY|O_CLOEXEC); - if(docount) - dumpcount(fd, &count); - else - dumpcount(fd, NULL); + fd = openat(listfd, subfile, O_RDONLY|O_CLOEXEC); + dumpcount(fd, docount ? &count : NULL); close(fd); } - if(docount) - printf("%d\n", count); + if (docount) + printf("%zu\n", count); return 0; }