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 >