summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-11-14 22:40:40 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-11-14 22:40:40 -0500
commita7e08e893eb796637ca2c53cd32a529f453ace12 (patch)
tree73f6bdc3e00baab465b5b90e963af94391f6d984 /bftw.c
parent196cf9f617ca17acec75eafbcd9e5e7989752dcb (diff)
downloadbfs-a7e08e893eb796637ca2c53cd32a529f453ace12.tar.xz
Check for readdir() errors everywhere.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/bftw.c b/bftw.c
index 630c643..e2bfcc6 100644
--- a/bftw.c
+++ b/bftw.c
@@ -22,6 +22,7 @@
#include "bftw.h"
#include "dstring.h"
+#include "util.h"
#include <assert.h>
#include <dirent.h>
#include <errno.h>
@@ -868,19 +869,6 @@ static struct dircache_entry *bftw_add(struct bftw_state *state, const char *nam
}
/**
- * readdir() wrapper that makes error handling cleaner.
- */
-static int bftw_readdir(DIR *dir, struct dirent **de) {
- errno = 0;
- *de = readdir(dir);
- if (!*de && errno != 0) {
- return -1;
- } else {
- return 0;
- }
-}
-
-/**
* Push a new entry onto the queue.
*/
static int bftw_push(struct bftw_state *state, const char *name) {
@@ -1016,7 +1004,7 @@ int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void
while (true) {
struct dirent *de;
- if (bftw_readdir(dir, &de) != 0) {
+ if (xreaddir(dir, &de) != 0) {
goto dir_error;
}
if (!de) {