On 06/09/2014 04:16 PM, Michael Goffioul wrote:
> On Mon, Jun 9, 2014 at 11:03 AM, Eli Zaretskii <e...@gnu.org 
> <mailto:e...@gnu.org>> wrote:
> 
>     > Date: Mon, 09 Jun 2014 09:33:18 +0100
>     > From: Pádraig Brady <p...@draigbrady.com>
>     > Cc: bug-gnulib@gnu.org <mailto:bug-gnulib@gnu.org>
>     >
>     > It's an optimized test rather than an optimization for isatty() itself.
>     > Without this call the isatty() replacement is moot because the
>     > reason it exists on mingw is to double check the handle as there
>     > true is returned for the NUL device.
> 
>     Indeed, that's the main reason why just isatty is not enough.
> 
>     > > More importantly, it breaks on Windows 8, where all handles are 
> multiples of 4.  The result is a false negative, and an unclean output from a 
> freshly compiled glib.
>     >
>     > Ugh fair enough. So it seems these lower 2 bits are still significant,
>     > just not used for tagging consoles any more?
>     > So is isatty(nul_handle) still returning true there?
>     > If not, then we could use a direct test of isatty(nul_handle)
>     > to enable the replacement.
>     > Note also the replacement is useful on "MSVC 9" to avoid an
>     > exception for isatty(invalid_handle), which we'd have to consider.
> 
>     You can call one of the console functions to test if a handle is
>     connected to a console.  E.g., GetConsoleMode for the input handle and
>     GetConsoleScreenBufferInfo for output.  These functions fail when the
>     handle is not a console handle.
> 
> 
> See the following threads, with problem reporting and solution testing:
> http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00092.html
> http://lists.gnu.org/archive/html/bug-gnulib/2013-01/msg00007.html

Thanks for the defails and double follow up Micheal.
I'll apply the attached later.

thanks,
Pádraig.

>From a008d625b7854d2c08c6606d90f6f2f48263f973 Mon Sep 17 00:00:00 2001
From: Michael Goffioul <michael.goffi...@gmail.com>
Date: Mon, 9 Jun 2014 17:07:44 +0100
Subject: [PATCH] isatty: fix to work on windows 8

* lib/isatty.c (IsConsoleHandle): Change from testing the lower
2 bits of the handle to the more expensive but accurate syscall.
---
 ChangeLog    |    6 ++++++
 lib/isatty.c |    8 +++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 53be01f..fbb05bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-06-09  Michael Goffioul  <michael.goffi...@gmail.com>
+
+	isatty: fix to work on windows 8
+	* lib/isatty.c (IsConsoleHandle): Change from testing the lower
+	2 bits of the handle to the more expensive but accurate syscall.
+
 2014-06-07  Paul Eggert  <egg...@cs.ucla.edu>
 
 	maint: fix typo in fdl.texi
diff --git a/lib/isatty.c b/lib/isatty.c
index e38bc9d..7180ead 100644
--- a/lib/isatty.c
+++ b/lib/isatty.c
@@ -32,9 +32,11 @@
 /* Get _get_osfhandle().  */
 #include "msvc-nothrow.h"
 
-/* Optimized test whether a HANDLE refers to a console.
-   See <http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00065.html>.  */
-#define IsConsoleHandle(h) (((intptr_t) (h) & 3) == 3)
+static BOOL IsConsoleHandle (HANDLE h)
+{
+  DWORD mode;
+  return GetConsoleMode (h, &mode) != 0;
+}
 
 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
 static int
-- 
1.7.7.6

Reply via email to