summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2023-12-14 12:40:36 -0800
committerArnold D. Robbins <arnold@skeeve.com>2023-12-14 12:40:36 -0800
commit8d8becf1aeb9de2989a7660fd86fb72fb3878281 (patch)
treea9a5c21aca0c3398f497541cdcbad92d9977fb47
parent3accba0532dc8525430ef766483bbe8202156aec (diff)
parente5d9a0d273a1c082cd9df4bcb508c1e5dc07dc65 (diff)
downloadgawk-8d8becf1aeb9de2989a7660fd86fb72fb3878281.tar.gz
Merge branch 'master' into feature/cpp-compile
-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 3127a5f..0b673f9 100644
--- a/io.c
+++ b/io.c
@@ -800,6 +800,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"));
@@ -982,15 +983,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)