"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "io.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

io.c  (gawk-5.0.1.tar.xz):io.c  (gawk-5.1.0.tar.xz)
/* /*
* io.c --- routines for dealing with input and output and records * io.c --- routines for dealing with input and output and records
*/ */
/* /*
* Copyright (C) 1986, 1988, 1989, 1991-2018, * Copyright (C) 1986, 1988, 1989, 1991-2020,
* the Free Software Foundation, Inc. * the Free Software Foundation, Inc.
* *
* This file is part of GAWK, the GNU implementation of the * This file is part of GAWK, the GNU implementation of the
* AWK Programming Language. * AWK Programming Language.
* *
* GAWK is free software; you can redistribute it and/or modify * GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
skipping to change at line 427 skipping to change at line 427
errcode = iop->errcode; errcode = iop->errcode;
valid = iop->valid; valid = iop->valid;
errno = 0; errno = 0;
update_ERRNO_int(errcode); update_ERRNO_int(errcode);
iop_close(iop); iop_close(iop);
*curfile = NULL; *curfile = NULL;
if (! valid && errcode == EISDIR && ! do_traditional) { if (! valid && errcode == EISDIR && ! do_traditional) {
warning(_("command line argument `%s' is a directory: ski pped"), fname); warning(_("command line argument `%s' is a directory: ski pped"), fname);
return; /* read next file */ return; /* read next file */
} }
fatal(_("cannot open file `%s' for reading (%s)"), fatal(_("cannot open file `%s' for reading: %s"),
fname, strerror(errcode)); fname, strerror(errcode));
} }
} }
/* nextfile --- move to the next input data file */ /* nextfile --- move to the next input data file */
/* /*
* Return value > 0 ----> run BEGINFILE block * Return value > 0 ----> run BEGINFILE block
* *curfile = NULL ----> hit EOF, run ENDFILE block * *curfile = NULL ----> hit EOF, run ENDFILE block
*/ */
skipping to change at line 544 skipping to change at line 544
fname = "-"; fname = "-";
iop = iop_alloc(fileno(stdin), fname, 0); iop = iop_alloc(fileno(stdin), fname, 0);
*curfile = iop_finish(iop); *curfile = iop_finish(iop);
if (iop->public.fd == INVALID_HANDLE) { if (iop->public.fd == INVALID_HANDLE) {
errcode = errno; errcode = errno;
errno = 0; errno = 0;
update_ERRNO_int(errno); update_ERRNO_int(errno);
(void) iop_close(iop); (void) iop_close(iop);
*curfile = NULL; *curfile = NULL;
fatal(_("cannot open file `%s' for reading (%s)"), fatal(_("cannot open file `%s' for reading: %s"),
fname, strerror(errcode)); fname, strerror(errcode));
} }
return ++i; /* run beginfile block */ return ++i; /* run beginfile block */
} }
return -1; /* end of input, run end block or Op_atexit */ return -1; /* end of input, run end block or Op_atexit */
} }
/* set_FNR --- update internal FNR from awk variable */ /* set_FNR --- update internal FNR from awk variable */
skipping to change at line 673 skipping to change at line 673
if (iop->public.fd != INVALID_HANDLE) { if (iop->public.fd != INVALID_HANDLE) {
if (iop->public.fd == fileno(stdin) if (iop->public.fd == fileno(stdin)
|| iop->public.fd == fileno(stdout) || iop->public.fd == fileno(stdout)
|| iop->public.fd == fileno(stderr)) || iop->public.fd == fileno(stderr))
ret = remap_std_file(iop->public.fd); ret = remap_std_file(iop->public.fd);
else else
ret = closemaybesocket(iop->public.fd); ret = closemaybesocket(iop->public.fd);
} }
if (ret == -1) if (ret == -1)
warning(_("close of fd %d (`%s') failed (%s)"), iop->public.fd, warning(_("close of fd %d (`%s') failed: %s"), iop->public.fd,
iop->public.name, strerror(errno)); iop->public.name, strerror(errno));
/* /*
* Be careful -- $0 may still reference the buffer even though * Be careful -- $0 may still reference the buffer even though
* an explicit close is being done; in the future, maybe we * an explicit close is being done; in the future, maybe we
* can do this a bit better. * can do this a bit better.
*/ */
if (iop->buf) { if (iop->buf) {
if ((fields_arr[0]->stptr >= iop->buf) if ((fields_arr[0]->stptr >= iop->buf)
&& (fields_arr[0]->stptr < (iop->buf + iop->size))) { && (fields_arr[0]->stptr < (iop->buf + iop->size))) {
NODE *t; NODE *t;
skipping to change at line 909 skipping to change at line 909
os_restore_mode(fileno(stdin)); os_restore_mode(fileno(stdin));
set_sigpipe_to_default(); set_sigpipe_to_default();
/* /*
* Don't check failure_fatal; see input pipe below. * Don't check failure_fatal; see input pipe below.
* Note that the failure happens upon failure to fork, * Note that the failure happens upon failure to fork,
* using a non-existant program will still succeed the * using a non-existant program will still succeed the
* popen(). * popen().
*/ */
if ((rp->output.fp = popen(str, binmode("w"))) == NULL) if ((rp->output.fp = popen(str, binmode("w"))) == NULL)
fatal(_("can't open pipe `%s' for output (%s)"), fatal(_("cannot open pipe `%s' for output: %s"),
str, strerror(errno)); str, strerror(errno));
ignore_sigpipe(); ignore_sigpipe();
/* set close-on-exec */ /* set close-on-exec */
os_close_on_exec(fileno(rp->output.fp), str, "pipe", "to" ); os_close_on_exec(fileno(rp->output.fp), str, "pipe", "to" );
rp->flag |= RED_NOBUF; rp->flag |= RED_NOBUF;
break; break;
case redirect_pipein: case redirect_pipein:
if (extfd >= 0) { if (extfd >= 0) {
warning(_("get_file cannot create pipe `%s' with fd %d"), str, extfd); warning(_("get_file cannot create pipe `%s' with fd %d"), str, extfd);
return NULL; return NULL;
} }
direction = "from"; direction = "from";
if (gawk_popen(str, rp) == NULL) if (gawk_popen(str, rp) == NULL)
fatal(_("can't open pipe `%s' for input (%s)"), fatal(_("cannot open pipe `%s' for input: %s"),
str, strerror(errno)); str, strerror(errno));
break; break;
case redirect_input: case redirect_input:
direction = "from"; direction = "from";
fd = (extfd >= 0) ? extfd : devopen(str, binmode("r")); fd = (extfd >= 0) ? extfd : devopen(str, binmode("r"));
if (fd == INVALID_HANDLE && errno == EISDIR) { if (fd == INVALID_HANDLE && errno == EISDIR) {
*errflg = EISDIR; *errflg = EISDIR;
/* do not free rp, saving it for reuse (save_rp = rp) */ /* do not free rp, saving it for reuse (save_rp = rp) */
return NULL; return NULL;
} }
skipping to change at line 959 skipping to change at line 959
return NULL; return NULL;
} }
#endif #endif
direction = "to/from"; direction = "to/from";
if (! two_way_open(str, rp, extfd)) { if (! two_way_open(str, rp, extfd)) {
if (! failure_fatal || is_non_fatal_redirect(str, explen)) { if (! failure_fatal || is_non_fatal_redirect(str, explen)) {
*errflg = errno; *errflg = errno;
/* do not free rp, saving it for reuse (s ave_rp = rp) */ /* do not free rp, saving it for reuse (s ave_rp = rp) */
return NULL; return NULL;
} else } else
fatal(_("can't open two way pipe `%s' for input/output (%s)"), fatal(_("cannot open two way pipe `%s' fo r input/output: %s"),
str, strerror(errno)); str, strerror(errno));
} }
break; break;
default: default:
cant_happen(); cant_happen();
} }
if (mode != NULL) { if (mode != NULL) {
errno = 0; errno = 0;
rp->output.mode = mode; rp->output.mode = mode;
skipping to change at line 1046 skipping to change at line 1046
* *
* 12/2014: Take nonfatal settings in PROCINFO in to account. * 12/2014: Take nonfatal settings in PROCINFO in to account.
*/ */
if (errflg != NULL) if (errflg != NULL)
*errflg = errno; *errflg = errno;
if (failure_fatal && ! is_non_fatal_redirect(str, explen) && if (failure_fatal && ! is_non_fatal_redirect(str, explen) &&
(redirtype == redirect_output (redirtype == redirect_output
|| redirtype == redirect_append)) { || redirtype == redirect_append)) {
/* multiple messages make life easier for translators */ /* multiple messages make life easier for translators */
if (*direction == 'f') if (*direction == 'f')
fatal(_("can't redirect from `%s' (%s)"), fatal(_("cannot redirect from `%s ': %s"),
str, strerror(errno)); str, strerror(errno));
else else
fatal(_("can't redirect to `%s' ( %s)"), fatal(_("cannot redirect to `%s': %s"),
str, strerror(errno)); str, strerror(errno));
} else { } else {
/* do not free rp, saving it for reuse (s ave_rp = rp) */ /* do not free rp, saving it for reuse (s ave_rp = rp) */
return NULL; return NULL;
} }
} }
} }
} }
if (new_rp) { if (new_rp) {
skipping to change at line 1167 skipping to change at line 1167
/* now work back up through the list */ /* now work back up through the list */
for (rp = rplast; rp != NULL; rp = rp->prev) { for (rp = rplast; rp != NULL; rp = rp->prev) {
/* don't close standard files! */ /* don't close standard files! */
if (rp->output.fp == NULL || rp->output.fp == stderr || rp->outpu t.fp == stdout) if (rp->output.fp == NULL || rp->output.fp == stderr || rp->outpu t.fp == stdout)
continue; continue;
if ((rp->flag & (RED_FILE|RED_WRITE)) == (RED_FILE|RED_WRITE)) { if ((rp->flag & (RED_FILE|RED_WRITE)) == (RED_FILE|RED_WRITE)) {
rp->flag |= RED_USED; rp->flag |= RED_USED;
errno = 0; errno = 0;
if (rp->output.gawk_fclose(rp->output.fp, rp->output.opaq ue) != 0) if (rp->output.gawk_fclose(rp->output.fp, rp->output.opaq ue) != 0)
warning(_("close of `%s' failed (%s)."), warning(_("close of `%s' failed: %s."),
rp->value, strerror(errno)); rp->value, strerror(errno));
rp->output.fp = NULL; rp->output.fp = NULL;
break; break;
} }
} }
if (rp == NULL) if (rp == NULL)
/* surely this is the only reason ??? */ /* surely this is the only reason ??? */
fatal(_("too many pipes or input files open")); fatal(_("too many pipes or input files open"));
} }
skipping to change at line 1340 skipping to change at line 1340
char *s = strerror(save_errno); char *s = strerror(save_errno);
/* /*
* BWK's awk, as far back as SVR4 (1989) would check * BWK's awk, as far back as SVR4 (1989) would check
* and warn about the status of close. However, when * and warn about the status of close. However, when
* we did this we got too many complaints, so we moved * we did this we got too many complaints, so we moved
* it to be under lint control. * it to be under lint control.
*/ */
if (do_lint) { if (do_lint) {
if ((rp->flag & RED_PIPE) != 0) if ((rp->flag & RED_PIPE) != 0)
lintwarn(_("failure status (%d) on pipe close of `%s' (%s)"), lintwarn(_("failure status (%d) on pipe close of `%s': %s"),
status, rp->value, s); status, rp->value, s);
else else
lintwarn(_("failure status (%d) on file close of `%s' (%s)"), lintwarn(_("failure status (%d) on file close of `%s': %s"),
status, rp->value, s); status, rp->value, s);
} }
if (! do_traditional) { if (! do_traditional) {
/* set ERRNO too so that program can get at it */ /* set ERRNO too so that program can get at it */
update_ERRNO_int(save_errno); update_ERRNO_int(save_errno);
} }
} }
checkwarn: checkwarn:
skipping to change at line 1415 skipping to change at line 1415
if (errno == EPIPE) if (errno == EPIPE)
die_via_sigpipe(); die_via_sigpipe();
else else
fatal(fp == stdout fatal(fp == stdout
? _("fflush: cannot flush standard output : %s") ? _("fflush: cannot flush standard output : %s")
: _("fflush: cannot flush standard error: %s"), : _("fflush: cannot flush standard error: %s"),
strerror(errno)); strerror(errno));
} else { } else {
update_ERRNO_int(errno); update_ERRNO_int(errno);
warning(fp == stdout warning(fp == stdout
? _("error writing standard output (%s)") ? _("error writing standard output: %s")
: _("error writing standard error (%s)"), : _("error writing standard error: %s"),
strerror(errno)); strerror(errno));
} }
return false; return false;
} }
return true; return true;
} }
/* flush_io --- flush all open output files */ /* flush_io --- flush all open output files */
skipping to change at line 1454 skipping to change at line 1454
/* flush both files and pipes, what the heck */ /* flush both files and pipes, what the heck */
if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) { if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) {
if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaq ue) != 0) { if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaq ue) != 0) {
update_ERRNO_int(errno); update_ERRNO_int(errno);
if (is_non_fatal_redirect(rp->value, strlen(rp->v alue))) if (is_non_fatal_redirect(rp->value, strlen(rp->v alue)))
messagefunc = r_warning; messagefunc = r_warning;
if ((rp->flag & RED_PIPE) != 0) if ((rp->flag & RED_PIPE) != 0)
messagefunc(_("pipe flush of `%s' failed (%s)."), messagefunc(_("pipe flush of `%s' failed: %s."),
rp->value, strerror(errno)); rp->value, strerror(errno));
else if ((rp->flag & RED_TWOWAY) != 0) else if ((rp->flag & RED_TWOWAY) != 0)
messagefunc(_("co-process flush of pipe t o `%s' failed (%s)."), messagefunc(_("co-process flush of pipe t o `%s' failed: %s."),
rp->value, strerror(errno)); rp->value, strerror(errno));
else else
messagefunc(_("file flush of `%s' failed (%s)."), messagefunc(_("file flush of `%s' failed: %s."),
rp->value, strerror(errno)); rp->value, strerror(errno));
status++; status++;
} }
} }
} }
if (status != 0) if (status != 0)
status = -1; /* canonicalize it */ status = -1; /* canonicalize it */
return status; return status;
} }
skipping to change at line 1505 skipping to change at line 1505
* them, we just flush them, and do that across the board. * them, we just flush them, and do that across the board.
*/ */
*stdio_problem = false; *stdio_problem = false;
/* we don't warn about stdout/stderr if EPIPE, but we do error exit */ /* we don't warn about stdout/stderr if EPIPE, but we do error exit */
if (fflush(stdout) != 0) { if (fflush(stdout) != 0) {
#ifdef __MINGW32__ #ifdef __MINGW32__
if (errno == 0 || errno == EINVAL) if (errno == 0 || errno == EINVAL)
w32_maybe_set_errno(); w32_maybe_set_errno();
#endif #endif
if (errno != EPIPE) if (errno != EPIPE)
warning(_("error writing standard output (%s)"), strerror (errno)); warning(_("error writing standard output: %s"), strerror( errno));
else else
*got_EPIPE = true; *got_EPIPE = true;
status++; status++;
*stdio_problem = true; *stdio_problem = true;
} }
if (fflush(stderr) != 0) { if (fflush(stderr) != 0) {
#ifdef __MINGW32__ #ifdef __MINGW32__
if (errno == 0 || errno == EINVAL) if (errno == 0 || errno == EINVAL)
w32_maybe_set_errno(); w32_maybe_set_errno();
#endif #endif
if (errno != EPIPE) if (errno != EPIPE)
warning(_("error writing standard error (%s)"), strerror( errno)); warning(_("error writing standard error: %s"), strerror(e rrno));
else else
*got_EPIPE = true; *got_EPIPE = true;
status++; status++;
*stdio_problem = true; *stdio_problem = true;
} }
return status; return status;
} }
/* str2mode --- convert a string mode to an integer mode */ /* str2mode --- convert a string mode to an integer mode */
skipping to change at line 2012 skipping to change at line 2012
if ((slave = open(slavenam, O_RDWR)) < 0) { if ((slave = open(slavenam, O_RDWR)) < 0) {
close(master); close(master);
fatal(_("could not open `%s', mode `%s'"), fatal(_("could not open `%s', mode `%s'"),
slavenam, "r+"); slavenam, "r+");
} }
push_pty_line_disciplines(slave); push_pty_line_disciplines(slave);
set_slave_pty_attributes(slave); set_slave_pty_attributes(slave);
if (close(master) == -1) if (close(master) == -1)
fatal(_("close of master pty failed (%s)"), strerror(errn o)); fatal(_("close of master pty failed: %s"), strerror(errno ));
if (close(1) == -1) if (close(1) == -1)
fatal(_("close of stdout in child failed (%s)"), fatal(_("close of stdout in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(slave) != 1) if (dup(slave) != 1)
fatal(_("moving slave pty to stdout in child failed (dup: %s)"), strerror(errno)); fatal(_("moving slave pty to stdout in child failed (dup: %s)"), strerror(errno));
if (close(0) == -1) if (close(0) == -1)
fatal(_("close of stdin in child failed (%s)"), fatal(_("close of stdin in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(slave) != 0) if (dup(slave) != 0)
fatal(_("moving slave pty to stdin in child failed (dup: %s)"), strerror(errno)); fatal(_("moving slave pty to stdin in child failed (dup: %s)"), strerror(errno));
if (close(slave)) if (close(slave))
fatal(_("close of slave pty failed (%s)"), strerror(errno )); fatal(_("close of slave pty failed: %s"), strerror(errno) );
/* stderr does NOT get dup'ed onto child's stdout */ /* stderr does NOT get dup'ed onto child's stdout */
set_sigpipe_to_default(); set_sigpipe_to_default();
execl("/bin/sh", "sh", "-c", command, NULL); execl("/bin/sh", "sh", "-c", command, NULL);
_exit(errno == ENOENT ? 127 : 126); _exit(errno == ENOENT ? 127 : 126);
case -1: case -1:
save_errno = errno; save_errno = errno;
skipping to change at line 2064 skipping to change at line 2064
switch (*pid = fork()) { switch (*pid = fork()) {
case 0: case 0:
/* Child process */ /* Child process */
setsid(); setsid();
#ifdef TIOCSCTTY #ifdef TIOCSCTTY
ioctl(slave, TIOCSCTTY, 0); ioctl(slave, TIOCSCTTY, 0);
#endif #endif
if (close(master) == -1) if (close(master) == -1)
fatal(_("close of master pty failed (%s)"), strerror(errn o)); fatal(_("close of master pty failed: %s"), strerror(errno ));
if (close(1) == -1) if (close(1) == -1)
fatal(_("close of stdout in child failed (%s)"), fatal(_("close of stdout in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(slave) != 1) if (dup(slave) != 1)
fatal(_("moving slave pty to stdout in child failed (dup: %s)"), strerror(errno)); fatal(_("moving slave pty to stdout in child failed (dup: %s)"), strerror(errno));
if (close(0) == -1) if (close(0) == -1)
fatal(_("close of stdin in child failed (%s)"), fatal(_("close of stdin in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(slave) != 0) if (dup(slave) != 0)
fatal(_("moving slave pty to stdin in child failed (dup: %s)"), strerror(errno)); fatal(_("moving slave pty to stdin in child failed (dup: %s)"), strerror(errno));
if (close(slave)) if (close(slave))
fatal(_("close of slave pty failed (%s)"), strerror(errno )); fatal(_("close of slave pty failed: %s"), strerror(errno) );
/* stderr does NOT get dup'ed onto child's stdout */ /* stderr does NOT get dup'ed onto child's stdout */
signal(SIGPIPE, SIG_DFL); signal(SIGPIPE, SIG_DFL);
execl("/bin/sh", "sh", "-c", command, NULL); execl("/bin/sh", "sh", "-c", command, NULL);
_exit(errno == ENOENT ? 127 : 126); _exit(errno == ENOENT ? 127 : 126);
case -1: case -1:
save_errno = errno; save_errno = errno;
skipping to change at line 2098 skipping to change at line 2098
close(slave); close(slave);
errno = save_errno; errno = save_errno;
return false; return false;
} }
/* parent */ /* parent */
if (close(slave) != 0) { if (close(slave) != 0) {
close(master); close(master);
(void) kill(*pid, SIGKILL); (void) kill(*pid, SIGKILL);
fatal(_("close of slave pty failed (%s)"), strerror(errno)); fatal(_("close of slave pty failed: %s"), strerror(errno));
} }
return true; return true;
#endif #endif
} }
#endif /* defined(HAVE_TERMIOS_H) */ #endif /* defined(HAVE_TERMIOS_H) */
/* two_way_open --- open a two way communications channel */ /* two_way_open --- open a two way communications channel */
skipping to change at line 2413 skipping to change at line 2413
if ((pid = fork()) < 0) { if ((pid = fork()) < 0) {
save_errno = errno; save_errno = errno;
close(ptoc[0]); close(ptoc[1]); close(ptoc[0]); close(ptoc[1]);
close(ctop[0]); close(ctop[1]); close(ctop[0]); close(ctop[1]);
errno = save_errno; errno = save_errno;
return false; return false;
} }
if (pid == 0) { /* child */ if (pid == 0) { /* child */
if (close(1) == -1) if (close(1) == -1)
fatal(_("close of stdout in child failed (%s)"), fatal(_("close of stdout in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(ctop[1]) != 1) if (dup(ctop[1]) != 1)
fatal(_("moving pipe to stdout in child failed (dup: %s)" ), strerror(errno)); fatal(_("moving pipe to stdout in child failed (dup: %s)" ), strerror(errno));
if (close(0) == -1) if (close(0) == -1)
fatal(_("close of stdin in child failed (%s)"), fatal(_("close of stdin in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(ptoc[0]) != 0) if (dup(ptoc[0]) != 0)
fatal(_("moving pipe to stdin in child failed (dup: %s)") , strerror(errno)); fatal(_("moving pipe to stdin in child failed (dup: %s)") , strerror(errno));
if ( close(ptoc[0]) == -1 || close(ptoc[1]) == -1 if ( close(ptoc[0]) == -1 || close(ptoc[1]) == -1
|| close(ctop[0]) == -1 || close(ctop[1]) == -1) || close(ctop[0]) == -1 || close(ctop[1]) == -1)
fatal(_("close of pipe failed (%s)"), strerror(errno)); fatal(_("close of pipe failed: %s"), strerror(errno));
/* stderr does NOT get dup'ed onto child's stdout */ /* stderr does NOT get dup'ed onto child's stdout */
set_sigpipe_to_default(); set_sigpipe_to_default();
execl("/bin/sh", "sh", "-c", str, NULL); execl("/bin/sh", "sh", "-c", str, NULL);
_exit(errno == ENOENT ? 127 : 126); _exit(errno == ENOENT ? 127 : 126);
} }
#endif /* NOT __EMX__, NOT __MINGW32__ */ #endif /* NOT __EMX__, NOT __MINGW32__ */
/* parent */ /* parent */
if ((BINMODE & BINMODE_INPUT) != 0) if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(ctop[0], O_BINARY); os_setbinmode(ctop[0], O_BINARY);
skipping to change at line 2613 skipping to change at line 2613
/* /*
* We used to wait for any children to synchronize input and output, * We used to wait for any children to synchronize input and output,
* but this could cause gawk to hang when it is started in a pipeline * but this could cause gawk to hang when it is started in a pipeline
* and thus has a child process feeding it input (shell dependent). * and thus has a child process feeding it input (shell dependent).
* *
* (void) wait_any(0); // wait for outstanding processes * (void) wait_any(0); // wait for outstanding processes
*/ */
if (pipe(p) < 0) if (pipe(p) < 0)
fatal(_("cannot open pipe `%s' (%s)"), cmd, strerror(errno)); fatal(_("cannot open pipe `%s': %s"), cmd, strerror(errno));
#if defined(__EMX__) || defined(__MINGW32__) #if defined(__EMX__) || defined(__MINGW32__)
rp->iop = NULL; rp->iop = NULL;
save_stdout = dup(1); /* save stdout */ save_stdout = dup(1); /* save stdout */
if (save_stdout == -1) { if (save_stdout == -1) {
close(p[0]); close(p[0]);
close(p[1]); close(p[1]);
return NULL; /* failed */ return NULL; /* failed */
} }
skipping to change at line 2657 skipping to change at line 2657
close(1); close(1);
if (dup(save_stdout) != 1) { if (dup(save_stdout) != 1) {
close(p[0]); close(p[0]);
fatal(_("restoring stdout in parent process failed")); fatal(_("restoring stdout in parent process failed"));
} }
close(save_stdout); close(save_stdout);
#else /* NOT __EMX__, NOT __MINGW32__ */ #else /* NOT __EMX__, NOT __MINGW32__ */
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
if (close(1) == -1) if (close(1) == -1)
fatal(_("close of stdout in child failed (%s)"), fatal(_("close of stdout in child failed: %s"),
strerror(errno)); strerror(errno));
if (dup(p[1]) != 1) if (dup(p[1]) != 1)
fatal(_("moving pipe to stdout in child failed (dup: %s)" ), strerror(errno)); fatal(_("moving pipe to stdout in child failed (dup: %s)" ), strerror(errno));
if (close(p[0]) == -1 || close(p[1]) == -1) if (close(p[0]) == -1 || close(p[1]) == -1)
fatal(_("close of pipe failed (%s)"), strerror(errno)); fatal(_("close of pipe failed: %s"), strerror(errno));
set_sigpipe_to_default(); set_sigpipe_to_default();
execl("/bin/sh", "sh", "-c", cmd, NULL); execl("/bin/sh", "sh", "-c", cmd, NULL);
_exit(errno == ENOENT ? 127 : 126); _exit(errno == ENOENT ? 127 : 126);
} }
#endif /* NOT __EMX__, NOT __MINGW32__ */ #endif /* NOT __EMX__, NOT __MINGW32__ */
if (pid == -1) { if (pid == -1) {
close(p[0]); close(p[1]); close(p[0]); close(p[1]);
fatal(_("cannot create child process for `%s' (fork: %s)"), cmd, strerror(errno)); fatal(_("cannot create child process for `%s' (fork: %s)"), cmd, strerror(errno));
} }
rp->pid = pid; rp->pid = pid;
#if !defined(__EMX__) && !defined(__MINGW32__) #if !defined(__EMX__) && !defined(__MINGW32__)
if (close(p[1]) == -1) { if (close(p[1]) == -1) {
close(p[0]); close(p[0]);
fatal(_("close of pipe failed (%s)"), strerror(errno)); fatal(_("close of pipe failed: %s"), strerror(errno));
} }
#endif #endif
os_close_on_exec(p[0], cmd, "pipe", "from"); os_close_on_exec(p[0], cmd, "pipe", "from");
if ((BINMODE & BINMODE_INPUT) != 0) if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(p[0], O_BINARY); os_setbinmode(p[0], O_BINARY);
rp->iop = iop_alloc(p[0], cmd, 0); rp->iop = iop_alloc(p[0], cmd, 0);
find_input_parser(rp->iop); find_input_parser(rp->iop);
iop_finish(rp->iop); iop_finish(rp->iop);
if (! rp->iop->valid) { if (! rp->iop->valid) {
if (! do_traditional && rp->iop->errcode != 0) if (! do_traditional && rp->iop->errcode != 0)
skipping to change at line 4062 skipping to change at line 4062
* Please do not remerge the if condition; hinders memory deallocation * Please do not remerge the if condition; hinders memory deallocation
* in case of fatal error in make_regexp. * in case of fatal error in make_regexp.
*/ */
refree(RS_re[0]); /* NULL argument is ok */ refree(RS_re[0]); /* NULL argument is ok */
refree(RS_re[1]); refree(RS_re[1]);
RS_re[0] = RS_re[1] = RS_regexp = NULL; RS_re[0] = RS_re[1] = RS_regexp = NULL;
if (RS->stlen == 0) { if (RS->stlen == 0) {
RS_is_null = true; RS_is_null = true;
matchrec = rsnullscan; matchrec = rsnullscan;
} else if (RS->stlen > 1 && ! do_traditional) { } else if ((RS->stlen > 1 || (RS->flags & REGEX) != 0) && ! do_traditiona l) {
static bool warned = false; static bool warned = false;
RS_re[0] = make_regexp(RS->stptr, RS->stlen, false, true, true); RS_re[0] = make_regexp(RS->stptr, RS->stlen, false, true, true);
RS_re[1] = make_regexp(RS->stptr, RS->stlen, true, true, true); RS_re[1] = make_regexp(RS->stptr, RS->stlen, true, true, true);
RS_regexp = RS_re[IGNORECASE]; RS_regexp = RS_re[IGNORECASE];
matchrec = rsrescan; matchrec = rsrescan;
if (do_lint_extensions && ! warned) { if (do_lint_extensions && ! warned) {
lintwarn(_("multicharacter value of `RS' is a gawk extens ion")); lintwarn(_("multicharacter value of `RS' is a gawk extens ion"));
 End of changes. 35 change blocks. 
36 lines changed or deleted 36 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)