* doc/posix-functions/isatty.texi: Mention the MSVC problem.
* lib/isatty.c: Include <errno.h>, msvc-inval.h.
(_isatty_nothrow): New function.
(isatty): Use it instead of _isatty.
(IsConsoleHandle): Add comment, from Paolo Bonzini.
* lib/poll.c (IsConsoleHandle): Likewise.
* lib/select.c (IsConsoleHandle): Likewise.
* m4/isatty.m4 (gl_FUNC_ISATTY): Fix comment. Reported by Eli Zaretskii.
(gl_PREREQ_ISATTY): New macro.
* modules/isatty (Depends-on): Add msvc-inval.
(configure.ac): Invoke gl_PREREQ_ISATTY.
+2012-01-03 Bruno Haible <bruno@clisp.org>
+
+ isatty: Support for MSVC 9.
+ * doc/posix-functions/isatty.texi: Mention the MSVC problem.
+ * lib/isatty.c: Include <errno.h>, msvc-inval.h.
+ (_isatty_nothrow): New function.
+ (isatty): Use it instead of _isatty.
+ (IsConsoleHandle): Add comment, from Paolo Bonzini.
+ * lib/poll.c (IsConsoleHandle): Likewise.
+ * lib/select.c (IsConsoleHandle): Likewise.
+ * m4/isatty.m4 (gl_FUNC_ISATTY): Fix comment. Reported by Eli Zaretskii.
+ (gl_PREREQ_ISATTY): New macro.
+ * modules/isatty (Depends-on): Add msvc-inval.
+ (configure.ac): Invoke gl_PREREQ_ISATTY.
+
2012-01-03 Jim Meyering <meyering@redhat.com>
maint.mk: remove temporary transition aid from over 1.5 years ago
@item
On native Windows, this function also returns true for character devices such
as @file{NUL}.
+@item
+This function crashes when invoked with invalid arguments on some platforms:
+MSVC 9.
@end itemize
Portability problems not fixed by Gnulib:
/* This replacement is enabled on native Windows. */
+#include <errno.h>
+
/* Get declarations of the Win32 API functions. */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include "msvc-inval.h"
+
/* 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) (((long) (h) & 3) == 3)
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static inline int
+_isatty_nothrow (int fd)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = _isatty (fd);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = -1;
+ errno = EBADF;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#else
+# define _isatty_nothrow _isatty
+#endif
+
int
isatty (int fd)
{
/* _isatty (fd) tests whether GetFileType of the handle is FILE_TYPE_CHAR. */
- if (_isatty (fd))
+ if (_isatty_nothrow (fd))
{
HANDLE h = (HANDLE) _get_osfhandle (fd);
return IsConsoleHandle (h);
#ifdef WIN32_NATIVE
+/* 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) (((long) (h) & 3) == 3)
static BOOL
#define PIPE_BUF 512
#endif
+/* 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) (((long) (h) & 3) == 3)
static BOOL
-# isatty.m4 serial 1
+# isatty.m4 serial 2
dnl Copyright (C) 2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
- dnl On native Windows, the system's isatty() returns true for pipes and
- dnl for the NUL device.
+ dnl On native Windows, the system's isatty(), defined as an alias of _isatty()
+ dnl in the "oldnames" library, returns true for the NUL device.
case $host_os in
mingw*) REPLACE_ISATTY=1 ;;
esac
])
+
+# Prerequisites of lib/isatty.c.
+AC_DEFUN([gl_PREREQ_ISATTY], [
+ AC_REQUIRE([AC_C_INLINE])
+])
Depends-on:
unistd
+msvc-inval [test $REPLACE_ISATTY = 1]
msvc-nothrow [test $REPLACE_ISATTY = 1]
configure.ac:
gl_FUNC_ISATTY
if test $REPLACE_ISATTY = 1; then
AC_LIBOBJ([isatty])
+ gl_PREREQ_ISATTY
fi
gl_UNISTD_MODULE_INDICATOR([isatty])