From 549694bc88a7345c10551d13017fa8a0eccb8619 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 9 Dec 2012 20:02:07 +0200 Subject: Change BINMODE to use symbolic values. --- io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index c57aef2a..efdec065 100644 --- a/io.c +++ b/io.c @@ -233,12 +233,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; } @@ -1017,7 +1017,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->fp); - if ((BINMODE & 1) != 0) + if ((BINMODE & BINMODE_INPUT) != 0) os_setbinmode(fileno(stdin), O_BINARY); rp->fp = NULL; @@ -2134,7 +2134,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; -- cgit v1.2.3 From 134fa0445295460d897661ee18027c645b2baa73 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 9 Dec 2012 21:35:46 +0200 Subject: Use posix_openpt() if available. --- io.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index efdec065..4b658950 100644 --- a/io.c +++ b/io.c @@ -1598,7 +1598,7 @@ two_way_open(const char *str, struct redirect *rp) if (! no_ptys && pty_vs_pipe(str)) { static int 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]; @@ -1615,7 +1615,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; @@ -1630,8 +1630,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; -- cgit v1.2.3 From d283194601bc7cb7c071317a8d53a89a3cbac40d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 9 Dec 2012 22:04:10 +0200 Subject: Make bitflag checking consistent everywhere. --- io.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 5dbeadf7..7559b41f 100644 --- a/io.c +++ b/io.c @@ -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 @@ -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 @@ -3563,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); -- cgit v1.2.3