[Top][All Lists]

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

isatty fails on Windows 8

From: Michael Goffioul
Subject: isatty fails on Windows 8
Date: Thu, 20 Dec 2012 19:02:03 -0500


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.

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.


[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]