aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cftw.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/cftw.c b/cftw.c
index d11cb87..2990888 100644
--- a/cftw.c
+++ b/cftw.c
@@ -14,7 +14,6 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
{
int ret = -1;
DIR *const d = opendir(dirpath);
- struct dirent *de;
if (!d)
{
@@ -22,8 +21,19 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
goto end;
}
- while ((de = readdir(d)))
+ for (;;)
{
+ errno = 0;
+ struct dirent *const de = readdir(d);
+
+ if (errno)
+ {
+ fprintf(stderr, "%s: readdir(3): %s\n", __func__, strerror(errno));
+ goto end;
+ }
+ else if (!de)
+ break;
+
const char *const path = de->d_name;
if (!strcmp(path, ".") || !strcmp(path, ".."))