diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2012-07-29 16:36:40 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2012-07-29 16:36:40 +0300 |
commit | 7a7aff46c959aa4f2f885fa52b93137e409aa6b9 (patch) | |
tree | 5c42448510c6c273335ad9ece8a0da5961967a38 /extension/readdir.c | |
parent | 82816b279615b27f7c4f87349a8c830a96939d8c (diff) | |
parent | a02d28a4829917a98c6620f4f14864b68d707d41 (diff) | |
download | egawk-7a7aff46c959aa4f2f885fa52b93137e409aa6b9.tar.gz egawk-7a7aff46c959aa4f2f885fa52b93137e409aa6b9.tar.bz2 egawk-7a7aff46c959aa4f2f885fa52b93137e409aa6b9.zip |
Merge branch 'extgawk' of ssh://git.sv.gnu.org/srv/git/gawk into extgawk
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", |