diff options
author | davidg <davidg> | 2000-07-18 02:16:31 (GMT) |
---|---|---|
committer | davidg <davidg> | 2000-07-18 02:16:31 (GMT) |
commit | 058c128660f07f5e5a13e99dcbec3ff6f738a1a7 (patch) | |
tree | 37a16ff5c8310eeef4af1c32c45e836e01c44ae4 | |
parent | e58ac604378b855c137c05576fd796df952cb349 (diff) | |
download | tcl-058c128660f07f5e5a13e99dcbec3ff6f738a1a7.zip tcl-058c128660f07f5e5a13e99dcbec3ff6f738a1a7.tar.gz tcl-058c128660f07f5e5a13e99dcbec3ff6f738a1a7.tar.bz2 |
Win2K OS bug with GetStdHandle(STD_OUTPUT_HANDLE) returning
0x00010001 instead of INVALID_HANDLE_VALUE for WinMain apps.
Added a new test case to catch it.
-rw-r--r-- | win/tclWinChan.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/win/tclWinChan.c b/win/tclWinChan.c index 70bf804..f40d361 100644 --- a/win/tclWinChan.c +++ b/win/tclWinChan.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinChan.c,v 1.10 2000/04/20 01:30:20 hobbs Exp $ + * RCS: @(#) $Id: tclWinChan.c,v 1.11 2000/07/18 02:16:31 davidg Exp $ */ #include "tclWinInt.h" @@ -970,6 +970,9 @@ TclpGetDefaultStdChannel(type) int mode; char *bufMode; DWORD handleId; /* Standard handle to retrieve. */ + char dummyBuff[1]; /* Buffer for the WriteFile test */ + DWORD dummyWritten; /* Required parameter for WriteFile */ + switch (type) { case TCL_STDIN: @@ -999,15 +1002,26 @@ TclpGetDefaultStdChannel(type) * is not a console mode application, even though this is not a valid * handle. */ - + if ((handle == INVALID_HANDLE_VALUE) || (handle == 0)) { - return NULL; + return (Tcl_Channel) NULL; } - + + /* + * Win2K BUG: GetStdHandle(STD_OUTPUT_HANDLE) can return what appears + * to be a valid handle. Do an extra test with WriteFile() "touching" + * the handle. + */ + + if ((type == TCL_STDOUT) + && !WriteFile(handle, dummyBuff, 0, &dummyWritten, NULL)) { + return (Tcl_Channel) NULL; + } + channel = Tcl_MakeFileChannel(handle, mode); if (channel == NULL) { - return NULL; + return (Tcl_Channel) NULL; } /* |