From c8f7eca0eb6327e8b8ea066af55183a135818fe1 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 23 Jun 2019 10:07:49 -0400 Subject: util: Filter out . and .. in xreaddir() --- eval.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index a455a58..d2eea03 100644 --- a/eval.c +++ b/eval.c @@ -423,25 +423,13 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) { goto done; } - ret = true; - - while (true) { - struct dirent *de; - if (xreaddir(dir, &de) != 0) { - eval_report_error(state); - goto done_dir; - } - if (!de) { - break; - } - - if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { - ret = false; - break; - } + struct dirent *de; + if (xreaddir(dir, &de) == 0) { + ret = !de; + } else { + eval_report_error(state); } - done_dir: closedir(dir); } else { const struct bfs_stat *statbuf = eval_stat(state); @@ -1282,14 +1270,9 @@ static int infer_fdlimit(const struct cmdline *cmdline) { // Account for 'dir' itself nopen = -1; - while (true) { - struct dirent *de; - if (xreaddir(dir, &de) != 0 || !de) { - break; - } - if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { - ++nopen; - } + struct dirent *de; + while (xreaddir(dir, &de) == 0 && de) { + ++nopen; } closedir(dir); -- cgit v1.2.3