Ignore:
Timestamp:
Dec 31, 2012, 1:34:36 PM (13 years ago)
Author:
dmik
Message:

kernel32: Use console input/output mode only if handle is attached to a real console.

Previously it would use this mode (which reads/writes directly to the attached VIO window)
for all character devices (e.g. NUL) which was clearly wrong.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/console.cpp

    r22051 r22055  
    455455               rc));
    456456
     457  ULONG type = 0, attr = 0;
     458
     459  // Below, to distinguish console from other character devices (e.g. NUL)
     460  // we use the undocumented device attr field of DosQueryHType(). For CON
     461  // it returns 0x8083 here, for NUL -- 0x8084. We need to distinguish because
     462  // we only use the console classes if the handle is a real console.
     463
    457464  /***********************************************************************
    458465   * initialize stdin handle                                             *
    459466   ***********************************************************************/
    460   hStandardIn = GetStdHandle(STD_INPUT_HANDLE);
    461   dwType = GetFileType(hStandardIn);
    462   if (dwType == FILE_TYPE_CHAR) {               /* is handle not redirected ? */
     467  if (DosQueryHType(0, &type, &attr) == 0 && type == 1 && (attr & 0xF) == 0x03) {
    463468    hStandardIn = HMCreateFile("CONIN$",
    464469                               GENERIC_READ | GENERIC_WRITE,
     
    475480   * initialize stdout handle                                            *
    476481   ***********************************************************************/
    477   hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE);
    478   dwType = GetFileType(hStandardOut);
    479   if (dwType == FILE_TYPE_CHAR) {               /* is handle redirected ? */
     482  if (DosQueryHType(1, &type, &attr) == 0 && type == 1 && (attr & 0xF) == 0x03) {
    480483    hStandardOut = HMCreateFile("CONOUT$",
    481484                                GENERIC_READ | GENERIC_WRITE,
     
    492495   * initialize stderr handle                                            *
    493496   ***********************************************************************/
    494   hStandardError = GetStdHandle(STD_ERROR_HANDLE);
    495   dwType = GetFileType(hStandardError);
    496   if (dwType == FILE_TYPE_CHAR) {               /* is handle redirected ? */
     497  if (DosQueryHType(2, &type, &attr) == 0 && type == 1 && (attr & 0xF) == 0x03) {
    497498    hStandardError = HMCreateFile("CONOUT$",
    498499                                  GENERIC_READ | GENERIC_WRITE,
Note: See TracChangeset for help on using the changeset viewer.