diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2012-11-25 21:54:48 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2012-11-25 21:54:48 +0200 |
commit | 9a9ff61bbd952c1263b55f82a269da5b09289a6b (patch) | |
tree | 4bc31b31d0bec6d27f77e55f1a88f50534fa6ed4 /posix/gawkmisc.c | |
parent | dbabe5a569ad82a9faeb2f121e387ec6399f9dcb (diff) | |
parent | 7af1da783175273a26609911c3a95975ed0f5c13 (diff) | |
download | egawk-9a9ff61bbd952c1263b55f82a269da5b09289a6b.tar.gz egawk-9a9ff61bbd952c1263b55f82a269da5b09289a6b.tar.bz2 egawk-9a9ff61bbd952c1263b55f82a269da5b09289a6b.zip |
Merge branch 'master' into array-iface
Diffstat (limited to 'posix/gawkmisc.c')
-rw-r--r-- | posix/gawkmisc.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index acc3c9d5..90bf1c38 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -26,6 +26,7 @@ char quote = '\''; char *defpath = DEFPATH; +char *deflibpath = DEFLIBPATH; char envsep = ':'; #ifndef INVALID_HANDLE @@ -92,8 +93,8 @@ optimal_bufsize(int fd, struct stat *stb) { char *val; static size_t env_val = 0; - static short first = TRUE; - static short exact = FALSE; + static bool first = true; + static bool exact = false; /* force all members to zero in case OS doesn't use all of them. */ memset(stb, '\0', sizeof(struct stat)); @@ -103,11 +104,11 @@ optimal_bufsize(int fd, struct stat *stb) fatal("can't stat fd %d (%s)", fd, strerror(errno)); if (first) { - first = FALSE; + first = false; if ((val = getenv("AWKBUFSIZE")) != NULL) { if (strcmp(val, "exact") == 0) - exact = TRUE; + exact = true; else if (isdigit((unsigned char) *val)) { for (; *val && isdigit((unsigned char) *val); val++) env_val = (env_val * 10) + *val - '0'; @@ -203,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 awk_input_buf_t *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 |