From 3fa6f02daabc1bf2cc21f7854c4af990627a8863 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 4 Nov 2016 09:48:28 +0200 Subject: Improve behavior on MS-Windows when stdout is redirected to a pipe. --- ChangeLog | 7 +++++++ builtin.c | 4 ++++ nonposix.h | 1 + pc/ChangeLog | 5 +++++ pc/gawkmisc.pc | 26 +++++++++++++++++++++++--- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bed030f..ecd371ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-11-04 Eli Zaretskii + + * builtin.c (efwrite) [__MINGW32__]: Call w32_maybe_set_errno if + errno is not set or set to EINVAL. + + * nonposix.h (w32_maybe_set_errno) [__MINGW32__]: Add prototype. + 2016-10-26 Arnold D. Robbins * io.c (init_awkpath): Set max path len for leading separator. diff --git a/builtin.c b/builtin.c index 0163b81c..18c01f6e 100644 --- a/builtin.c +++ b/builtin.c @@ -125,6 +125,10 @@ efwrite(const void *ptr, return; wrerror: +#ifdef __MINGW32__ + if (errno == 0 || errno == EINVAL) + w32_maybe_set_errno(); +#endif /* die silently on EPIPE to stdout */ if (fp == stdout && errno == EPIPE) gawk_exit(EXIT_FATAL); diff --git a/nonposix.h b/nonposix.h index 3aae512c..b3497891 100644 --- a/nonposix.h +++ b/nonposix.h @@ -55,6 +55,7 @@ unsigned int getegid (void); /* gawkmisc.pc */ int unsetenv (const char *); int setenv (const char *, const char *, int); +void w32_maybe_set_errno (void); #endif /* __MINGW32__ */ #if defined(VMS) || defined(__DJGPP__) || defined(__MINGW32__) diff --git a/pc/ChangeLog b/pc/ChangeLog index 7ba5fd9c..1ff3bb1f 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,8 @@ +2016-11-04 Eli Zaretskii + + * gawkmisc.pc (w32_maybe_set_errno) [__MINGW32__]: New function, + to correct errno when it is not set to a useful value. + 2016-09-24 Eli Zaretskii Fix compilation warnings on MinGW with the latest runtime. diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc index 9939fb48..817e8167 100644 --- a/pc/gawkmisc.pc +++ b/pc/gawkmisc.pc @@ -1,6 +1,4 @@ -/* - * gawkmisc.c --- miscellaneous gawk routines that are OS specific. - */ +/* gawkmisc.c --- miscellaneous gawk routines that are OS specific. -*-C-*- */ /* * Copyright (C) 1986, 1988, 1989, 1991 - 2003, 2012, 2016 @@ -897,6 +895,28 @@ w32_status_to_termsig (unsigned status) return SIGTERM; } +void +w32_maybe_set_errno (void) +{ + DWORD w32err = GetLastError (); + + switch (w32err) + { + /* When stdout is redirected to a pipe, and the program that + reads the pipe (e.g., a pager) exits, Windows doesn't set + errno to a useful value. Help it DTRT. */ + case ERROR_BAD_PIPE: + case ERROR_PIPE_BUSY: + case ERROR_NO_DATA: + case ERROR_PIPE_NOT_CONNECTED: + errno = EPIPE; + break; + default: + errno = EINVAL; + break; + } +} + #endif /* __MINGW32__ */ #if defined(__DJGPP__) || defined(__MINGW32__) || defined(__EMX__) -- cgit v1.2.3 From e886bf34a4e42095824a2b14c40cb19efa80390f Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 31 Oct 2016 21:52:43 +0200 Subject: Fix some valgrind errors. --- ChangeLog | 6 ++++++ io.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ecd371ba..7d3b0f0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ * nonposix.h (w32_maybe_set_errno) [__MINGW32__]: Add prototype. +2016-10-31 Arnold D. Robbins + + Fix valgrind issues. + + * io.c (init_awkpath): Need to allocate max_path+3 pointers. + 2016-10-26 Arnold D. Robbins * io.c (init_awkpath): Set max path len for leading separator. diff --git a/io.c b/io.c index ab4029e1..2dbc07a6 100644 --- a/io.c +++ b/io.c @@ -2607,8 +2607,9 @@ init_awkpath(path_info *pi) if (*p == envsep) max_path++; - emalloc(pi->awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); - memset(pi->awkpath, 0, (max_path + 1) * sizeof(char *)); + // +3 --> 2 for null entries at front and end of path, 1 for NULL end of list + emalloc(pi->awkpath, char **, (max_path + 3) * sizeof(char *), "init_awkpath"); + memset(pi->awkpath, 0, (max_path + 3) * sizeof(char *)); start = path; i = 0; -- cgit v1.2.3