aboutsummaryrefslogtreecommitdiffstats
path: root/posix/gawkmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'posix/gawkmisc.c')
-rw-r--r--posix/gawkmisc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c
index 3baf852e..87a6747c 100644
--- a/posix/gawkmisc.c
+++ b/posix/gawkmisc.c
@@ -204,6 +204,31 @@ os_isdir(int fd)
return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode));
}
+/* os_isreadable --- fd can be read from */
+
+int
+os_isreadable(int fd)
+{
+ struct stat sbuf;
+
+ if (fstat(fd, &sbuf) != 0)
+ return false;
+
+ switch (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;
+ default:
+ return false;
+ }
+}
+
/* os_is_setuid --- true if running setuid root */
int