summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-11-07 20:57:50 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-11-07 20:57:50 +0200
commitbfa38f60f445595a37f5d9dbfb93b4379945d0f5 (patch)
tree7aaab48314c4d605399101c09f5beda44c2c7ab6
parent99fb2a4c290eaf98d9b44d05908579b8423c0940 (diff)
parented5e0e468ca758d963b5370ec83f56725087d4f4 (diff)
downloadgawk-bfa38f60f445595a37f5d9dbfb93b4379945d0f5.tar.gz
Merge branch 'master' into feature/typed-regex
-rw-r--r--ChangeLog7
-rw-r--r--builtin.c4
-rw-r--r--nonposix.h1
-rw-r--r--pc/ChangeLog5
-rw-r--r--pc/gawkmisc.pc26
5 files changed, 40 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index fa1ddbce..986b8561 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-11-04 Eli Zaretskii <eliz@gnu.org>
+
+ * 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-11-01 Arnold D. Robbins <arnold@skeeve.com>
* eval.c (flags2str): Add NO_EXT_SET and NUMCONSTSTR.
diff --git a/builtin.c b/builtin.c
index 21d135b5..a7fe6312 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 0a1c24c8..cbc4f499 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 2b4b1183..49ce73fa 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-04 Eli Zaretskii <eliz@gnu.org>
+
+ * gawkmisc.pc (w32_maybe_set_errno) [__MINGW32__]: New function,
+ to correct errno when it is not set to a useful value.
+
2016-10-23 Arnold D. Robbins <arnold@skeeve.com>
* General: Remove trailing whitespace from all relevant files.
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__)