bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isatty fails on Windows 8


From: Paolo Bonzini
Subject: Re: isatty fails on Windows 8
Date: Sun, 23 Dec 2012 21:18:56 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Il 21/12/2012 01:02, Michael Goffioul ha scritto:
> Hi,
> 
> We've got a bug report in octave [1] that seems to indicate that
> gnulib's replacement of isatty is incorrect on Windows 8 (it's fine up
> to Windows 7). Looking at the implementation, it first calls the Windows
> _isatty version, then checks the last 2 bits of the handle associated
> with the file descriptor, based on the assumption described in [2] (a
> console HANDLE is not a multiple of 4). It seems that this last
> assumption is not valid anymore on Windows 8.

Ouch, my fault.

Using GetConsoleMode
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms683167%28v=vs.85%29.aspx)
would be good I think.

BOOL IsConsoleHandle(HANDLE h)
{
    DWORD mode;
    return GetConsoleMode(h, &mode) == 0;
}

Paolo

> I provided the bug reporter with a simple program to test on Windows 8,
> and console HANDLE seems to be a multiple of 4 now. The test program is
> the following:
> 
> =====================
> 
> #include <io.h>
> #include <stdio.h>
> 
> #define IsConsoleHandle(h) (((long) (h) & 3) == 3)
> 
> int main (int argc, char **argv)
> {
>   printf ("isatty (stdin): %d\n", isatty (fileno (stdin)));
>   printf ("IsConsoleHandle (stdin): %d\n",
>           IsConsoleHandle (_get_osfhandle (fileno (stdin))));
>   printf ("isatty (stdout): %d\n", isatty (fileno (stdout)));
>   printf ("IsConsoleHandle (stdout): %d\n",
>           IsConsoleHandle (_get_osfhandle (fileno (stdout))));
> 
>   return 0;
> }
> 
> =====================
> 
> The output of the test code above on Windows 8 is:
> 
> isatty (stdin): 64 
> IsConsoleHandle (stdin): 0 
> isatty (stdout): 64 
> IsConsoleHandle (stdout): 0
> 
> The macro IsConsoleHandle is copied from gnulib's isatty.c. This macro
> seems invalid on Windows 8.
> 
> Michael.
> 
> [1] http://savannah.gnu.org/bugs/?37623 (comment #!! and above)
> [2] http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00065.html
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]