summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashok <ashok>2015-03-19 10:41:28 (GMT)
committerashok <ashok>2015-03-19 10:41:28 (GMT)
commitdf856f976bd0ae1e57e1b1c2ed112f918d4a64bc (patch)
tree0a7ea0d1c876137d2d7a16277e68913f99d7e13d
parente54038086f492625fa4870aa220ad7b4b746b87d (diff)
downloadtcl-df856f976bd0ae1e57e1b1c2ed112f918d4a64bc.zip
tcl-df856f976bd0ae1e57e1b1c2ed112f918d4a64bc.tar.gz
tcl-df856f976bd0ae1e57e1b1c2ed112f918d4a64bc.tar.bz2
Ticket [e66e444440]. Modified ReadConsoleBytes to handle Ctrl-C / Ctrl-Break
and not return 0 bytes indicating EOF for those cases.
-rw-r--r--win/tclWinConsole.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c
index 63150ef..7380003 100644
--- a/win/tclWinConsole.c
+++ b/win/tclWinConsole.c
@@ -220,8 +220,20 @@ ReadConsoleBytes(
BOOL result;
int tcharsize = sizeof(TCHAR);
- result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars,
- NULL);
+ /*
+ * If user types a Ctrl-Break or Ctrl-C, ReadConsole will return
+ * success with ntchars == 0 and GetLastError() will be
+ * ERROR_OPERATION_ABORTED. We do not want to treat this case
+ * as EOF so we will loop around again. If no Ctrl signal handlers
+ * have been established, the default signal OS handler in a separate
+ * thread will terminate the program. If a Ctrl signal handler
+ * has been established (through an extension for example), it
+ * will run and take whatever action it deems appropriate.
+ */
+ do {
+ result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars,
+ NULL);
+ } while (result && ntchars == 0 && GetLastError() == ERROR_OPERATION_ABORTED);
if (nbytesread != NULL) {
*nbytesread = ntchars * tcharsize;
}