aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-12-09 22:11:01 +0200
committerArnold D. Robbins <arnold@skeeve.com>2012-12-09 22:11:01 +0200
commitae9e583a257264f4580d07354e79aac63db72695 (patch)
tree5a03a771ec6588c0dede291c56df8ec9cb783f7a /io.c
parenta5a114bf6c6f2efdcd7889ebf0d7f9f3ec235a74 (diff)
parentd283194601bc7cb7c071317a8d53a89a3cbac40d (diff)
downloadegawk-ae9e583a257264f4580d07354e79aac63db72695.tar.gz
egawk-ae9e583a257264f4580d07354e79aac63db72695.tar.bz2
egawk-ae9e583a257264f4580d07354e79aac63db72695.zip
Merge branch 'master' into array-iface
Diffstat (limited to 'io.c')
-rw-r--r--io.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/io.c b/io.c
index b5c25f54..7559b41f 100644
--- a/io.c
+++ b/io.c
@@ -290,12 +290,12 @@ binmode(const char *mode)
{
switch (mode[0]) {
case 'r':
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
mode = "rb";
break;
case 'w':
case 'a':
- if ((BINMODE & 2) != 0)
+ if ((BINMODE & BINMODE_OUTPUT) != 0)
mode = (mode[0] == 'w' ? "wb" : "ab");
break;
}
@@ -733,7 +733,7 @@ redirect(NODE *redir_exp, int redirtype, int *errflg)
* we've gotten EOF from a child input pipeline, it's
* a good bet that the child has died. So recover it.
*/
- if ((rp->flag & RED_EOF) && redirtype == redirect_pipein) {
+ if ((rp->flag & RED_EOF) != 0 && redirtype == redirect_pipein) {
if (rp->pid != -1)
wait_any(0);
}
@@ -779,7 +779,7 @@ redirect(NODE *redir_exp, int redirtype, int *errflg)
save_rp = rp;
while (rp->output.fp == NULL && rp->iop == NULL) {
- if (! new_rp && rp->flag & RED_EOF) {
+ if (! new_rp && (rp->flag & RED_EOF) != 0) {
/*
* Encountered EOF on file or pipe -- must be cleared
* by explicit close() before reading more
@@ -1114,7 +1114,7 @@ close_rp(struct redirect *rp, two_way_close_type how)
} else if ((rp->flag & (RED_PIPE|RED_WRITE)) == (RED_PIPE|RED_WRITE)) {
/* write to pipe */
status = pclose(rp->output.fp);
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
rp->output.fp = NULL;
@@ -1233,12 +1233,12 @@ flush_io()
}
for (rp = red_head; rp != NULL; rp = rp->next)
/* flush both files and pipes, what the heck */
- if ((rp->flag & RED_WRITE) && rp->output.fp != NULL) {
+ if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) {
if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaque)) {
- if (rp->flag & RED_PIPE)
+ if ((rp->flag & RED_PIPE) != 0)
warning(_("pipe flush of `%s' failed (%s)."),
rp->value, strerror(errno));
- else if (rp->flag & RED_TWOWAY)
+ else if ((rp->flag & RED_TWOWAY) != 0)
warning(_("co-process flush of pipe to `%s' failed (%s)."),
rp->value, strerror(errno));
else
@@ -1697,7 +1697,7 @@ two_way_open(const char *str, struct redirect *rp)
if (! no_ptys && pty_vs_pipe(str)) {
static bool initialized = false;
static char first_pty_letter;
-#ifdef HAVE_GRANTPT
+#if defined(HAVE_GRANTPT) && ! defined(HAVE_POSIX_OPENPT)
static int have_dev_ptmx;
#endif
char slavenam[32];
@@ -1714,7 +1714,7 @@ two_way_open(const char *str, struct redirect *rp)
if (! initialized) {
initialized = true;
-#ifdef HAVE_GRANTPT
+#if defined(HAVE_GRANTPT) && ! defined(HAVE_POSIX_OPENPT)
have_dev_ptmx = (stat("/dev/ptmx", & statb) >= 0);
#endif
i = 0;
@@ -1729,8 +1729,13 @@ two_way_open(const char *str, struct redirect *rp)
}
#ifdef HAVE_GRANTPT
+#ifdef HAVE_POSIX_OPENPT
+ {
+ master = posix_openpt(O_RDWR|O_NOCTTY);
+#else
if (have_dev_ptmx) {
master = open("/dev/ptmx", O_RDWR);
+#endif
if (master >= 0) {
char *tem;
@@ -2255,7 +2260,7 @@ gawk_popen(const char *cmd, struct redirect *rp)
os_restore_mode(fileno(stdin));
current = popen(cmd, binmode("r"));
- if ((BINMODE & 1) != 0)
+ if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
if (current == NULL)
return NULL;
@@ -3558,9 +3563,9 @@ pty_vs_pipe(const char *command)
return false;
val = in_PROCINFO(command, "pty", NULL);
if (val) {
- if (val->flags & MAYBE_NUM)
+ if ((val->flags & MAYBE_NUM) != 0)
(void) force_number(val);
- if (val->flags & NUMBER)
+ if ((val->flags & NUMBER) != 0)
return ! iszero(val);
else
return (val->stlen != 0);