diff options
| author | ashok <ashok> | 2015-03-19 10:41:28 (GMT) |
|---|---|---|
| committer | ashok <ashok> | 2015-03-19 10:41:28 (GMT) |
| commit | 50426ba9c5cb0fa954959ab5b810695b6bf20111 (patch) | |
| tree | 0a7ea0d1c876137d2d7a16277e68913f99d7e13d | |
| parent | 0e5a1e2642d9893498118c3367c62e390f1d482d (diff) | |
| download | tcl-50426ba9c5cb0fa954959ab5b810695b6bf20111.zip tcl-50426ba9c5cb0fa954959ab5b810695b6bf20111.tar.gz tcl-50426ba9c5cb0fa954959ab5b810695b6bf20111.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.c | 16 |
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; } |
