summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2023-12-14 12:41:18 -0800
committerArnold D. Robbins <arnold@skeeve.com>2023-12-14 12:41:18 -0800
commit8c6674cb1c2b28e69bdb3a3897aa4584c25afcc4 (patch)
treee3f8751da01f574a0556e2b0b8d7baaaf47ca431
parent4652ea8b8523aa46d2a7b220f73bf9d7a096d9e8 (diff)
parente5d9a0d273a1c082cd9df4bcb508c1e5dc07dc65 (diff)
downloadgawk-8c6674cb1c2b28e69bdb3a3897aa4584c25afcc4.tar.gz
Merge branch 'master' into feature/minrx
-rw-r--r--ChangeLog5
-rw-r--r--io.c16
-rw-r--r--pc/ChangeLog5
-rw-r--r--pc/gawkmisc.pc9
4 files changed, 27 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a1f42e..4a3d20d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/io.c b/io.c
index c595c00..3ffac79 100644
--- a/io.c
+++ b/io.c
@@ -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)