diff --git a/awk.h b/awk.h index cb7c4990..49986949 100644 --- a/awk.h +++ b/awk.h @@ -960,6 +960,7 @@ typedef struct iobuf { IOP_AT_EOF = 2, IOP_CLOSED = 4, IOP_AT_START = 8, + IOP_IS_SOCK = 16, } flag; } IOBUF; @@ -1601,6 +1602,7 @@ extern void os_arg_fixup(int *argcp, char ***argvp); 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_issock(int fd); extern int os_isdir(int fd); extern int os_isreadable(const awk_input_buf_t *iobuf, bool *isdir); extern int os_is_setuid(void); diff --git a/io.c b/io.c index 91c94d9b..fd62f878 100644 --- a/io.c +++ b/io.c @@ -3466,6 +3466,8 @@ iop_finish(IOBUF *iop) if (os_isatty(iop->public.fd)) iop->flag |= IOP_IS_TTY; + else if (os_issock(iop->public.fd)) + iop->flag |= IOP_IS_SOCK; 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) @@ -3759,7 +3761,7 @@ again: */ /* succession of tests is easier to trace in GDB. */ - if (RSre->maybe_long) { + if (RSre->maybe_long && (iop->flag & (IOP_IS_TTY|IOP_IS_SOCK)) == 0) { char *matchend = iop->off + reend; if (iop->dataend - matchend < RS->stlen) diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index d2e33f41..92124be7 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -273,6 +273,16 @@ os_isatty(int fd) return isatty(fd); } +/* os_issock --- return true if fd is a socket */ + +int +os_issock(int fd) +{ + struct stat sbuf; + + return (fstat(fd, & sbuf) >= 0 && S_ISSOCK(sbuf.st_mode)); +} + /* files_are_same --- return true if files are identical */ int