about summary refs log tree commit diff
path: root/mlist.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-10-29 22:08:32 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-10-29 22:08:32 +0100
commit00a1382175020c51c564bde0173c31892a0a0877 (patch)
tree07341b0c11e9e8dcfd0d3a2417d3b6ddd496a622 /mlist.c
parent4e7a5c5ab6dcdc18a83ac388cb9c44146c035f8e (diff)
downloadmblaze-00a1382175020c51c564bde0173c31892a0a0877.tar.gz
mblaze-00a1382175020c51c564bde0173c31892a0a0877.tar.xz
mblaze-00a1382175020c51c564bde0173c31892a0a0877.zip
mlist: use a static buffer, clean up control flow
Diffstat (limited to 'mlist.c')
-rw-r--r--mlist.c12
1 files 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;
 		}
 	}