From 00a1382175020c51c564bde0173c31892a0a0877 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 29 Oct 2017 22:08:32 +0100 Subject: [PATCH] mlist: use a static buffer, clean up control flow --- mlist.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mlist.c b/mlist.c index ddc23c9..01c0f7a 100644 --- a/mlist.c +++ b/mlist.c @@ -105,15 +105,15 @@ struct linux_dirent64 { char d_name[]; /* Filename (null-terminated) */ }; #define BUF_SIZE 1024000 +char buf[BUF_SIZE]; void listdir(char *dir) { int fd; ssize_t nread; - char buf[BUF_SIZE]; + ssize_t bpos; struct linux_dirent64 *d; - int bpos; fd = open(dir, O_RDONLY | O_DIRECTORY); if (fd == -1) { @@ -131,15 +131,13 @@ listdir(char *dir) if (nread == 0) break; - for (bpos = 0; bpos < nread; ) { + for (bpos = 0; bpos < nread; bpos += d->d_reclen) { d = (struct linux_dirent64 *)(buf + bpos); if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN) - goto next; + continue; if (d->d_name[0] == '.') - goto next; + continue; list(dir, d->d_name); -next: - bpos += d->d_reclen; } }