diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/ChangeLog | 14 | ||||
-rw-r--r-- | posix/gawkmisc.c | 28 |
2 files changed, 42 insertions, 0 deletions
diff --git a/posix/ChangeLog b/posix/ChangeLog index bf36414f..982f6bd7 100644 --- a/posix/ChangeLog +++ b/posix/ChangeLog @@ -1,3 +1,17 @@ +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 + set to true if fd is for a directory. + +2012-07-26 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.c (os_isreadable): New function. + 2012-05-11 Arnold D. Robbins <arnold@skeeve.com> * gawkmisc.c: Use `bool', `true', and `false' everywhere. diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index 3baf852e..ebcee8a0 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -204,6 +204,34 @@ os_isdir(int fd) return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode)); } +/* os_isreadable --- fd can be read from */ + +int +os_isreadable(const IOBUF_PUBLIC *iobuf, bool *isdir) +{ + *isdir = false; + + if (iobuf->fd == INVALID_HANDLE) + return false; + + switch (iobuf->sbuf.st_mode & S_IFMT) { + case S_IFREG: + case S_IFCHR: /* ttys, /dev/null, .. */ +#ifdef S_IFSOCK + case S_IFSOCK: +#endif +#ifdef S_IFIFO + case S_IFIFO: +#endif + return true; + case S_IFDIR: + *isdir = true; + /* fall through */ + default: + return false; + } +} + /* os_is_setuid --- true if running setuid root */ int |