diff options
Diffstat (limited to 'extension/readdir.c')
-rw-r--r-- | extension/readdir.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/extension/readdir.c b/extension/readdir.c index c2b6cbda..2818d601 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -130,10 +130,8 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int *errcode) /* * The caller sets *errcode to 0, so we should set it only if an - * error occurs. Except that the compiler complains that it - * is unused, so we set it anyways. + * error occurs. */ - *errcode = 0; /* keep the compiler happy */ if (out == NULL || iobuf == NULL || iobuf->opaque == NULL) return EOF; @@ -141,9 +139,15 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int *errcode) set_RT((awk_value_t *) & null_val); the_dir = (open_directory_t *) iobuf->opaque; dp = the_dir->dp; + /* + * Initialize errno, since readdir does not set it to zero on EOF. + */ + errno = 0; dirent = readdir(dp); - if (dirent == NULL) + if (dirent == NULL) { + *errcode = errno; /* in case there was an error */ return EOF; + } if (do_ftype) sprintf(the_dir->buf, "%ld/%s/%s", |