aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--awk.h5
-rw-r--r--extension/ChangeLog3
-rw-r--r--extension/readdir.c6
-rw-r--r--extension/rwarray.c2
-rw-r--r--gawkapi.h4
-rw-r--r--io.c11
-rw-r--r--pc/ChangeLog7
-rw-r--r--pc/gawkmisc.pc9
-rw-r--r--posix/ChangeLog5
-rw-r--r--posix/gawkmisc.c8
-rw-r--r--vms/ChangeLog7
-rw-r--r--vms/gawkmisc.vms9
13 files changed, 47 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index f0f5ff2b..ca35fafa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,13 @@
* gawkapi.c (api_sym_update): For an array, pass the new cookie
back out to the extension.
+ * awk.h (IOBUF): Move struct stat into IOBUF_PUBLIC.
+ (os_isreadable): Change to take an IOBUF_PUBLIC.
+ * gawkapi.h (IOBUF_PUBLIC): Received struct stat.
+ (INVALID_HANDLE): Moves to here.
+ * io.c (iop_alloc): Stat the fd and fill in stat buf.
+ (iop_finish): Use passed in stat info.
+
2012-08-01 Arnold D. Robbins <arnold@skeeve.com>
* io.c (iop_finish): New function.
diff --git a/awk.h b/awk.h
index 52c6ac4a..e7998626 100644
--- a/awk.h
+++ b/awk.h
@@ -889,7 +889,6 @@ typedef struct exp_instruction {
typedef struct iobuf {
IOBUF_PUBLIC public; /* exposed to extensions */
- struct stat sbuf; /* stat buf */
char *buf; /* start data buffer */
char *off; /* start of current record in buffer */
char *dataend; /* first byte in buffer to hold new data,
@@ -1533,7 +1532,7 @@ extern int os_devopen(const char *name, int flag);
extern void os_close_on_exec(int fd, const char *name, const char *what, const char *dir);
extern int os_isatty(int fd);
extern int os_isdir(int fd);
-extern int os_isreadable(int fd, bool *isdir);
+extern int os_isreadable(const IOBUF_PUBLIC *iobuf, bool *isdir);
extern int os_is_setuid(void);
extern int os_setbinmode(int fd, int mode);
extern void os_restore_mode(int fd);
@@ -1694,8 +1693,6 @@ extern uintmax_t adjust_uint(uintmax_t n);
#define adjust_uint(n) (n)
#endif
-#define INVALID_HANDLE (-1)
-
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 6b7c2bce..22b72019 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -8,6 +8,9 @@
* stack.h, stack.c: New files.
* Makefile.am: Update list of files.
+ * readdir.c (dir_can_take_file): Use members in iobuf.
+ * rwarray.c (do_writea): Initialize fp to NULL.
+
2012-08-03 Andrew J. Schorr <aschorr@telemetry-investments.com>
* readdir.c (dir_get_record): Fix for systems where ino_t is
diff --git a/extension/readdir.c b/extension/readdir.c
index 2c25a95b..c28764e8 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -184,14 +184,10 @@ dir_close(struct iobuf_public *iobuf)
static int
dir_can_take_file(const IOBUF_PUBLIC *iobuf)
{
- struct stat sbuf;
- int fd;
-
if (iobuf == NULL)
return 0;
- fd = iobuf->fd;
- return (fd >= 0 && fstat(fd, & sbuf) >= 0 && S_ISDIR(sbuf.st_mode));
+ return (iobuf->fd != INVALID_HANDLE && S_ISDIR(iobuf->sbuf.st_mode));
}
/*
diff --git a/extension/rwarray.c b/extension/rwarray.c
index e45a499e..0eca9779 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -93,7 +93,7 @@ static awk_value_t *
do_writea(int nargs, awk_value_t *result)
{
awk_value_t filename, array;
- FILE *fp;
+ FILE *fp = NULL;
uint32_t major = MAJOR;
uint32_t minor = MINOR;
diff --git a/gawkapi.h b/gawkapi.h
index f345d07a..b516787a 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -100,6 +100,7 @@ extern "C" {
typedef struct iobuf_public {
const char *name; /* filename */
int fd; /* file descriptor */
+#define INVALID_HANDLE (-1)
void *opaque; /* private data for input parsers */
/*
* The get_record function is called to read the next record of data.
@@ -127,6 +128,9 @@ typedef struct iobuf_public {
* Gawk itself will close the fd unless close_func sets it to -1.
*/
void (*close_func)(struct iobuf_public *);
+
+ /* put last, for alignment. bleah */
+ struct stat sbuf; /* stat buf */
} IOBUF_PUBLIC;
diff --git a/io.c b/io.c
index d37c0b32..589abbf4 100644
--- a/io.c
+++ b/io.c
@@ -2734,6 +2734,9 @@ iop_alloc(int fd, const char *name, int errno_val)
iop->valid = false;
iop->errcode = errno_val;
+ if (fd != INVALID_HANDLE)
+ fstat(fd, & iop->public.sbuf);
+
return iop;
}
@@ -2743,10 +2746,9 @@ static IOBUF *
iop_finish(IOBUF *iop)
{
bool isdir = false;
- struct stat sbuf;
if (iop->public.fd != INVALID_HANDLE) {
- if (os_isreadable(iop->public.fd, & isdir))
+ if (os_isreadable(& iop->public, & isdir))
iop->valid = true;
else {
if (isdir)
@@ -2769,9 +2771,8 @@ iop_finish(IOBUF *iop)
if (os_isatty(iop->public.fd))
iop->flag |= IOP_IS_TTY;
- iop->readsize = iop->size = optimal_bufsize(iop->public.fd, & sbuf);
- iop->sbuf = sbuf;
- if (do_lint && S_ISREG(sbuf.st_mode) && sbuf.st_size == 0)
+ iop->readsize = iop->size = optimal_bufsize(iop->public.fd, & iop->public.sbuf);
+ if (do_lint && S_ISREG(iop->public.sbuf.st_mode) && iop->public.sbuf.st_size == 0)
lintwarn(_("data file `%s' is empty"), iop->public.name);
iop->errcode = errno = 0;
iop->count = iop->scanoff = 0;
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 28dfb72b..57ffabe6 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,6 +1,11 @@
+2012-08-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawkmisc.pc (os_isreadable): Take IOBUF_PUBLIC instead of fd and
+ use passed in info.
+
2012-07-29 Arnold D. Robbins <arnold@skeeve.com>
- * gawkmisc.c (os_isreadable): Add isdir pointer parameter to be
+ * gawkmisc.pc (os_isreadable): Add isdir pointer parameter to be
set to true if fd is for a directory.
2012-07-26 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc
index d79a3207..e2f114e4 100644
--- a/pc/gawkmisc.pc
+++ b/pc/gawkmisc.pc
@@ -235,16 +235,11 @@ int fd;
/* os_isreadable --- fd can be read from */
int
-os_isreadable(int fd, bool *isdir)
+os_isreadable(const IOBUF_PUBLIC *iobuf, bool *isdir)
{
- struct stat sbuf;
-
*isdir = false;
- if (fstat(fd, &sbuf) != 0)
- return false;
-
- switch (sbuf.st_mode & S_IFMT) {
+ switch (iobuf->sbuf.st_mode & S_IFMT) {
case S_IFREG:
case S_IFCHR: /* ttys, /dev/null, .. */
#ifdef S_IFSOCK
diff --git a/posix/ChangeLog b/posix/ChangeLog
index d49ff49e..982f6bd7 100644
--- a/posix/ChangeLog
+++ b/posix/ChangeLog
@@ -1,3 +1,8 @@
+2012-08-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawkmisc.pc (os_isreadable): Take IOBUF_PUBLIC instead of fd and
+ use passed in info.
+
2012-07-29 Arnold D. Robbins <arnold@skeeve.com>
* gawkmisc.c (os_isreadable): Add isdir pointer parameter to be
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c
index a5c3a619..ebcee8a0 100644
--- a/posix/gawkmisc.c
+++ b/posix/gawkmisc.c
@@ -207,16 +207,14 @@ os_isdir(int fd)
/* os_isreadable --- fd can be read from */
int
-os_isreadable(int fd, bool *isdir)
+os_isreadable(const IOBUF_PUBLIC *iobuf, bool *isdir)
{
- struct stat sbuf;
-
*isdir = false;
- if (fstat(fd, &sbuf) != 0)
+ if (iobuf->fd == INVALID_HANDLE)
return false;
- switch (sbuf.st_mode & S_IFMT) {
+ switch (iobuf->sbuf.st_mode & S_IFMT) {
case S_IFREG:
case S_IFCHR: /* ttys, /dev/null, .. */
#ifdef S_IFSOCK
diff --git a/vms/ChangeLog b/vms/ChangeLog
index f65274f9..725a223b 100644
--- a/vms/ChangeLog
+++ b/vms/ChangeLog
@@ -1,6 +1,11 @@
+2012-08-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawkmisc.pc (os_isreadable): Take IOBUF_PUBLIC instead of fd and
+ use passed in info.
+
2012-07-29 Arnold D. Robbins <arnold@skeeve.com>
- * gawkmisc.c (os_isreadable): Add isdir pointer parameter to be
+ * gawkmisc.vms (os_isreadable): Add isdir pointer parameter to be
set to true if fd is for a directory.
2012-07-26 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/vms/gawkmisc.vms b/vms/gawkmisc.vms
index 773b3556..0ca3e0bf 100644
--- a/vms/gawkmisc.vms
+++ b/vms/gawkmisc.vms
@@ -147,16 +147,11 @@ int fd;
/* os_isreadable --- fd can be read from */
int
-os_isreadable(int fd, bool *isdir)
+os_isreadable(const IOBUF_PUBLIC *iobuf, bool *isdir)
{
- struct stat sbuf;
-
*isdir = false;
- if (fstat(fd, &sbuf) != 0)
- return false;
-
- switch (sbuf.st_mode & S_IFMT) {
+ switch (iobuf->sbuf.st_mode & S_IFMT) {
case S_IFREG:
case S_IFCHR: /* ttys, /dev/null, .. */
#ifdef S_IFSOCK