VirtualBox

Changeset 57597 in vbox


Ignore:
Timestamp:
Sep 2, 2015 3:09:12 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
102458
Message:

IPRT/fileio-win.cpp: Fixed support for RTFileQueryInfo() in combination with (pseudo) handles like stdin, stdout and stderr on Win7 and earlier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r57358 r57597  
    824824     * Query file info.
    825825     */
     826    HANDLE hHandle = (HANDLE)RTFileToNative(hFile);
     827
    826828    BY_HANDLE_FILE_INFORMATION Data;
    827     if (!GetFileInformationByHandle((HANDLE)RTFileToNative(hFile), &Data))
     829    if (!GetFileInformationByHandle(hHandle, &Data))
    828830    {
    829831        DWORD dwErr = GetLastError();
     
    831833         * everything else is fine here ... */
    832834        if (dwErr == ERROR_INVALID_HANDLE)
    833             return RTErrConvertFromWin32(dwErr);
     835        {
     836            /*
     837             * On Windows 7 or earlier certain standard handles such as
     838             * stin, stdout and stderr were ring-3 pseudo handles which the
     839             * kernel didn't know about.
     840             *
     841             * So simply ignore the ERROR_INVALID_HANDLE in that case to not
     842             * break other parts which rely on this function.
     843             */
     844            OSVERSIONINFOEX OSInfoEx = { 0 };
     845            OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     846
     847            bool fIgnoreError = false;
     848
     849            /* Windows 7 or  earlier? */
     850            if (   GetVersionEx((LPOSVERSIONINFO) &OSInfoEx)
     851                && (OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT)
     852                && (OSInfoEx.dwMajorVersion <= 6)
     853                && (OSInfoEx.dwMajorVersion <= 1))
     854            {
     855                /* Do we want to query file information for one of the pseudo handles? Then skip. */
     856                if (   hHandle == GetStdHandle(STD_INPUT_HANDLE)
     857                    || hHandle == GetStdHandle(STD_OUTPUT_HANDLE)
     858                    || hHandle == GetStdHandle(STD_ERROR_HANDLE))
     859                {
     860                    fIgnoreError = true;
     861                }
     862            }
     863
     864            if (!fIgnoreError)
     865                return RTErrConvertFromWin32(dwErr);
     866        }
    834867        RT_ZERO(Data);
    835868        Data.dwFileAttributes = RTFS_DOS_NT_DEVICE;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette