diff options
| author | Arnold D. Robbins <arnold@skeeve.com> | 2023-12-14 12:40:22 -0800 |
|---|---|---|
| committer | Arnold D. Robbins <arnold@skeeve.com> | 2023-12-14 12:40:22 -0800 |
| commit | 58c5a7a10736d752adfa410090c80e5121c0f523 (patch) | |
| tree | d588c3cd281af60eebba36de4b4abaad35002aec | |
| parent | 8089046ec19b7fcbb420efcccf12237fd14755a8 (diff) | |
| parent | e5d9a0d273a1c082cd9df4bcb508c1e5dc07dc65 (diff) | |
| download | gawk-58c5a7a10736d752adfa410090c80e5121c0f523.tar.gz | |
Merge branch 'master' into porting
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | io.c | 16 | ||||
| -rw-r--r-- | pc/ChangeLog | 5 | ||||
| -rw-r--r-- | pc/gawkmisc.pc | 9 |
4 files changed, 27 insertions, 8 deletions
@@ -1,3 +1,8 @@ +2023-12-12 Eli Zaretskii <eliz@gnu.org> + + * io.c (redirect_string): Check registered parsers before failing + due to EISDIR. + 2023-12-02 Arnold D. Robbins <arnold@skeeve.com> * debug.c (print_array): Fix printing of multidimensional arrays. @@ -797,6 +797,7 @@ redirect_string(const char *str, size_t explen, bool not_string, static struct redirect *save_rp = NULL; /* hold onto rp that should * be freed for reuse */ + int save_errno; if (do_sandbox) fatal(_("redirection not allowed in sandbox mode")); @@ -979,15 +980,20 @@ redirect_string(const char *str, size_t explen, bool not_string, case redirect_input: direction = "from"; fd = (extfd >= 0) ? extfd : devopen(str, binmode("r")); - if (fd == INVALID_HANDLE && errno == EISDIR) { - *errflg = EISDIR; - /* do not free rp, saving it for reuse (save_rp = rp) */ - return NULL; - } + save_errno = errno; + /* don't fail before letting registered + parsers a chance to take control */ rp->iop = iop_alloc(fd, str, errno); find_input_parser(rp->iop); iop_finish(rp->iop); if (! rp->iop->valid) { + if (fd == INVALID_HANDLE && save_errno == EISDIR) { + *errflg = EISDIR; + iop_close(rp->iop); + rp->iop = NULL; + /* do not free rp, saving it for reuse (save_rp = rp) */ + return NULL; + } if (! do_traditional && rp->iop->errcode != 0) update_ERRNO_int(rp->iop->errcode); iop_close(rp->iop); diff --git a/pc/ChangeLog b/pc/ChangeLog index 1f88340..fd3c949 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,8 @@ +2023-12-12 Eli Zaretskii <eliz@gnu.org> + + * gawkmisc.pc (optimal_bufsize): Return DEFBLKSIZE for directories + "opened" by the readdir extension. + 2023-12-02 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Regenerated. diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc index 131aace..221c869 100644 --- a/pc/gawkmisc.pc +++ b/pc/gawkmisc.pc @@ -106,9 +106,6 @@ optimal_bufsize(fd, stb) int fd; struct stat *stb; { - /* force all members to zero in case OS doesn't use all of them. */ - memset(stb, '\0', sizeof(struct stat)); - /* * DOS doesn't have the file system block size in the * stat structure. So we have to make some sort of reasonable @@ -117,6 +114,12 @@ struct stat *stb; */ #define DEFBLKSIZE BUFSIZ + if (S_ISDIR(stb->st_mode)) + return DEFBLKSIZE; + + /* force all members to zero in case OS doesn't use all of them. */ + memset(stb, '\0', sizeof(struct stat)); + if (fstat(fd, stb) == -1) fatal("can't stat fd %d (%s)", fd, strerror(errno)); if (S_ISREG(stb->st_mode) |
