gnutls-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gnutls branch, master, updated. gnutls_3_0_3-52-gc75a4df


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_3_0_3-52-gc75a4df
Date: Mon, 03 Oct 2011 16:14:17 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=c75a4dfa301eb5aafe519a92e48598d1e94470b0

The branch, master has been updated
       via  c75a4dfa301eb5aafe519a92e48598d1e94470b0 (commit)
      from  1f86b82c7a33d37f85ba3bb372bd45d249bed2a3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c75a4dfa301eb5aafe519a92e48598d1e94470b0
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 18:13:11 2011 +0200

    Added new gnulib.

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                               |    4 +
 gl/Makefile.am                           |   58 +++++++-
 gl/error.c                               |    2 +
 gl/float.c                               |    2 +-
 gl/float.in.h                            |   16 ++-
 gl/fstat.c                               |   82 +++++++++++
 gl/{tests/test-pathmax.c => itold.c}     |   20 +--
 gl/lseek.c                               |    2 +
 gl/m4/close.m4                           |   33 +++++
 gl/m4/dup2.m4                            |    5 +-
 gl/m4/fdopen.m4                          |   49 +++++++
 gl/m4/float_h.m4                         |   53 +++++++-
 gl/m4/fstat.m4                           |   28 ++++
 gl/m4/gnulib-cache.m4                    |   20 ++-
 gl/m4/gnulib-common.m4                   |   25 ++++-
 gl/m4/gnulib-comp.m4                     |   83 ++++++++++--
 gl/m4/{memxor.m4 => msvc-nothrow.m4}     |    8 +-
 gl/m4/pathmax.m4                         |   32 ++++-
 gl/m4/stdio_h.m4                         |    4 +-
 gl/m4/sys_stat_h.m4                      |    5 +-
 gl/m4/unistd_h.m4                        |    6 +-
 gl/math.in.h                             |    8 +
 gl/msvc-inval.c                          |  130 +++++++++++++++++
 gl/msvc-inval.h                          |  223 ++++++++++++++++++++++++++++++
 gl/{asprintf.c => msvc-nothrow.c}        |   42 ++++--
 gl/msvc-nothrow.h                        |   44 ++++++
 gl/opendir.c                             |    6 +-
 gl/sockets.c                             |    1 +
 gl/sockets.h                             |    2 +
 gl/stdio.in.h                            |   20 +++
 gl/strings.in.h                          |    5 +
 gl/sys_stat.in.h                         |   26 +++-
 gl/tests/Makefile.am                     |   79 +++++++++--
 gl/{closedir.c => tests/close.c}         |   64 +++++----
 gl/tests/dup2.c                          |   84 ++++++------
 gl/tests/{test-fdopen.c => fdopen.c}     |   75 ++++++----
 gl/tests/msvc-inval.c                    |   69 ---------
 gl/tests/msvc-inval.h                    |  167 ----------------------
 gl/tests/{test-fstat.c => test-close.c}  |   16 +--
 gl/tests/test-dup2.c                     |    2 +
 gl/tests/test-fgetc.c                    |   12 ++
 gl/tests/{test-fgetc.c => test-fputc.c}  |   48 ++++---
 gl/tests/{test-fgetc.c => test-fread.c}  |   31 +++-
 gl/tests/{test-fgetc.c => test-fwrite.c} |   51 ++++---
 gl/unistd.in.h                           |   44 +++++--
 gl/w32sock.h                             |    5 +-
 maint.mk                                 |   18 ++-
 47 files changed, 1305 insertions(+), 504 deletions(-)
 create mode 100644 gl/fstat.c
 copy gl/{tests/test-pathmax.c => itold.c} (70%)
 create mode 100644 gl/m4/close.m4
 create mode 100644 gl/m4/fdopen.m4
 create mode 100644 gl/m4/fstat.m4
 copy gl/m4/{memxor.m4 => msvc-nothrow.m4} (58%)
 create mode 100644 gl/msvc-inval.c
 create mode 100644 gl/msvc-inval.h
 copy gl/{asprintf.c => msvc-nothrow.c} (56%)
 create mode 100644 gl/msvc-nothrow.h
 copy gl/{closedir.c => tests/close.c} (55%)
 copy gl/tests/{test-fdopen.c => fdopen.c} (51%)
 delete mode 100644 gl/tests/msvc-inval.c
 delete mode 100644 gl/tests/msvc-inval.h
 copy gl/tests/{test-fstat.c => test-close.c} (78%)
 copy gl/tests/{test-fgetc.c => test-fputc.c} (55%)
 copy gl/tests/{test-fgetc.c => test-fread.c} (67%)
 copy gl/tests/{test-fgetc.c => test-fwrite.c} (51%)

diff --git a/.gitignore b/.gitignore
index 61c3951..d8532ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -526,3 +526,7 @@ gl/tests/test-ftello4
 gl/tests/test-pathmax
 gl/tests/test-sys_types
 tests/mini-deflate
+gl/tests/test-close
+gl/tests/test-fputc
+gl/tests/test-fwrite
+gl/tests/test-fread
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 93e68b2..a21b65d 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -2,10 +2,22 @@
 ## Process this file with automake to produce Makefile.in.
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
@@ -292,6 +304,7 @@ float.h: float.in.h $(top_builddir)/config.status
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
+             -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              < $(srcdir)/float.in.h; \
        } > address@hidden && \
        mv address@hidden $@
@@ -301,9 +314,9 @@ float.h: $(top_builddir)/config.status
 endif
 MOSTLYCLEANFILES += float.h float.h-t
 
-EXTRA_DIST += float.c float.in.h
+EXTRA_DIST += float.c float.in.h itold.c
 
-EXTRA_libgnu_la_SOURCES += float.c
+EXTRA_libgnu_la_SOURCES += float.c itold.c
 
 ## end   gnulib module float
 
@@ -358,6 +371,15 @@ EXTRA_DIST += fseterr.h stdio-impl.h
 
 ## end   gnulib module fseterr
 
+## begin gnulib module fstat
+
+
+EXTRA_DIST += fstat.c
+
+EXTRA_libgnu_la_SOURCES += fstat.c
+
+## end   gnulib module fstat
+
 ## begin gnulib module ftell
 
 
@@ -654,6 +676,7 @@ math.h: math.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
              -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
              -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
+             -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
              -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \
              -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
@@ -716,6 +739,24 @@ libgnu_la_SOURCES += minmax.h
 
 ## end   gnulib module minmax
 
+## begin gnulib module msvc-inval
+
+
+EXTRA_DIST += msvc-inval.c msvc-inval.h
+
+EXTRA_libgnu_la_SOURCES += msvc-inval.c
+
+## end   gnulib module msvc-inval
+
+## begin gnulib module msvc-nothrow
+
+
+EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h
+
+EXTRA_libgnu_la_SOURCES += msvc-nothrow.c
+
+## end   gnulib module msvc-nothrow
+
 ## begin gnulib module netdb
 
 BUILT_SOURCES += netdb.h
@@ -1127,6 +1168,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
              -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \
              -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \
+             -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \
              -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \
              -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \
              -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \
@@ -1197,6 +1239,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
              -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
              -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
+             -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \
              -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
              -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
@@ -1600,6 +1643,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNU
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
              -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \
+             -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \
              -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
              -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \
              -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
@@ -1836,8 +1880,10 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
+             -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \
              -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \
              -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \
+             -e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \
              -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \
              -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \
              -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \
diff --git a/gl/error.c b/gl/error.c
index 7482baa..5ebe8bf 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -92,6 +92,8 @@ extern void __error_at_line (int status, int errnum, const 
char *file_name,
 /* Get declarations of the Win32 API functions.  */
 #  define WIN32_LEAN_AND_MEAN
 #  include <windows.h>
+/* Get _get_osfhandle.  */
+#  include "msvc-nothrow.h"
 # endif
 
 /* The gnulib override of fcntl is not needed in this file.  */
diff --git a/gl/float.c b/gl/float.c
index c453d6d..b05b40c 100644
--- a/gl/float.c
+++ b/gl/float.c
@@ -20,7 +20,7 @@
 /* Specification.  */
 #include <float.h>
 
-#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 
106) && defined __GNUC__
+#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined 
__linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
 const union gl_long_double_union gl_LDBL_MAX =
   { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
 #elif defined __i386__
diff --git a/gl/float.in.h b/gl/float.in.h
index 57b7bc9..d5b2258 100644
--- a/gl/float.in.h
+++ b/gl/float.in.h
@@ -109,7 +109,8 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 #endif
 
 /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
-   wrong.  */
+   wrong.
+   On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong.  */
 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 
106) && defined __GNUC__
 # undef LDBL_MIN_EXP
 # define LDBL_MIN_EXP DBL_MIN_EXP
@@ -117,6 +118,8 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
 # undef LDBL_MIN
 # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 
2^-1022 */
+#endif
+#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined 
__linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
 # undef LDBL_MAX
 /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF 
}.
    It is not easy to define:
@@ -170,5 +173,16 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 # endif
 #endif
 
+#if @REPLACE_ITOLD@
+/* Pull in a function that fixes the 'int' to 'long double' conversion
+   of glibc 2.7.  */
+extern
+# ifdef __cplusplus
+"C"
+# endif
+void _Qp_itoq (long double *, int);
+static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
+#endif
+
 #endif /* address@hidden@_FLOAT_H */
 #endif /* address@hidden@_FLOAT_H */
diff --git a/gl/fstat.c b/gl/fstat.c
new file mode 100644
index 0000000..db5b17c
--- /dev/null
+++ b/gl/fstat.c
@@ -0,0 +1,82 @@
+/* fstat() replacement.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+   the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
+   rpl_fstat.  */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+/* Get the original definition of fstat.  It might be defined as a macro.  */
+#include <sys/types.h>
+#include <sys/stat.h>
+#undef __need_system_sys_stat_h
+
+static inline int
+orig_fstat (int fd, struct stat *buf)
+{
+  return fstat (fd, buf);
+}
+
+/* Specification.  */
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
+   eliminates this include because of the preliminary #include <sys/stat.h>
+   above.  */
+#include "sys/stat.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static inline int
+fstat_nothrow (int fd, struct stat *buf)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = orig_fstat (fd, buf);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define fstat_nothrow orig_fstat
+#endif
+
+int
+rpl_fstat (int fd, struct stat *buf)
+{
+#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
+  /* Handle the case when rpl_open() used a dummy file descriptor to work
+     around an open() that can't normally visit directories.  */
+  const char *name = _gl_directory_name (fd);
+  if (name != NULL)
+    return stat (name, buf);
+#endif
+
+  return fstat_nothrow (fd, buf);
+}
diff --git a/gl/tests/test-pathmax.c b/gl/itold.c
similarity index 70%
copy from gl/tests/test-pathmax.c
copy to gl/itold.c
index 96a1364..0236f33 100644
--- a/gl/tests/test-pathmax.c
+++ b/gl/itold.c
@@ -1,5 +1,6 @@
-/* Test of "pathmax.h".
+/* Replacement for 'int' to 'long double' conversion routine.
    Copyright (C) 2011 Free Software Foundation, Inc.
+   Written by Bruno Haible <address@hidden>, 2011.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -14,19 +15,14 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Written by Bruno Haible <address@hidden>, 2011.  */
-
 #include <config.h>
 
-#include "pathmax.h"
-
-/* Check that PATH_MAX is a constant if it is defined.  */
-#ifdef PATH_MAX
-int a = PATH_MAX;
-#endif
+/* Specification.  */
+#include <float.h>
 
-int
-main (void)
+void
+_Qp_itoq (long double *result, int a)
 {
-  return 0;
+  /* Convert from 'int' to 'double', then from 'double' to 'long double'.  */
+  *result = (double) a;
 }
diff --git a/gl/lseek.c b/gl/lseek.c
index 8339044..8c9834f 100644
--- a/gl/lseek.c
+++ b/gl/lseek.c
@@ -24,6 +24,8 @@
 /* Windows platforms.  */
 /* Get GetFileType.  */
 # include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 #else
 # include <sys/stat.h>
 #endif
diff --git a/gl/m4/close.m4 b/gl/m4/close.m4
new file mode 100644
index 0000000..f860a32
--- /dev/null
+++ b/gl/m4/close.m4
@@ -0,0 +1,33 @@
+# close.m4 serial 8
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_CLOSE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_CLOSE=1
+  fi
+  m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
+    gl_PREREQ_SYS_H_WINSOCK2
+    if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
+      dnl Even if the 'socket' module is not used here, another part of the
+      dnl application may use it and pass file descriptors that refer to
+      dnl sockets to the close() function. So enable the support for sockets.
+      REPLACE_CLOSE=1
+    fi
+  ])
+  dnl Replace close() for supporting the gnulib-defined fchdir() function,
+  dnl to keep fchdir's bookkeeping up-to-date.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    if test $REPLACE_CLOSE = 0; then
+      gl_TEST_FCHDIR
+      if test $HAVE_FCHDIR = 0; then
+        REPLACE_CLOSE=1
+      fi
+    fi
+  ])
+])
diff --git a/gl/m4/dup2.m4 b/gl/m4/dup2.m4
index 5c2cc96..cd9d254 100644
--- a/gl/m4/dup2.m4
+++ b/gl/m4/dup2.m4
@@ -1,4 +1,4 @@
-#serial 14
+#serial 16
 dnl Copyright (C) 2002, 2005, 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -71,3 +71,6 @@ AC_DEFUN([gl_FUNC_DUP2],
     fi
   ])
 ])
+
+# Prerequisites of lib/dup2.c.
+AC_DEFUN([gl_PREREQ_DUP2], [])
diff --git a/gl/m4/fdopen.m4 b/gl/m4/fdopen.m4
new file mode 100644
index 0000000..8cae2fc
--- /dev/null
+++ b/gl/m4/fdopen.m4
@@ -0,0 +1,49 @@
+# fdopen.m4 serial 2
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FDOPEN],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_FDOPEN=1
+  else
+    dnl Test whether fdopen() sets errno when it fails due to a bad fd 
argument.
+    AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works],
+      [
+        AC_RUN_IFELSE(
+          [AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <errno.h>
+int
+main (void)
+{
+  FILE *fp;
+  errno = 0;
+  fp = fdopen (-1, "r");
+  if (fp != NULL)
+    return 1;
+  if (errno == 0)
+    return 2;
+  return 0;
+}]])],
+          [gl_cv_func_fdopen_works=yes],
+          [gl_cv_func_fdopen_works=no],
+          [case "$host_os" in
+             mingw*) gl_cv_func_fdopen_works="guessing no" ;;
+             *)      gl_cv_func_fdopen_works="guessing yes" ;;
+           esac
+          ])
+      ])
+    case "$gl_cv_func_fdopen_works" in
+      *no) REPLACE_FDOPEN=1 ;;
+    esac
+  fi
+])
+
+dnl Prerequisites of lib/fdopen.c.
+AC_DEFUN([gl_PREREQ_FDOPEN], [])
diff --git a/gl/m4/float_h.m4 b/gl/m4/float_h.m4
index 261f1ac..0420e06 100644
--- a/gl/m4/float_h.m4
+++ b/gl/m4/float_h.m4
@@ -1,4 +1,4 @@
-# float_h.m4 serial 7
+# float_h.m4 serial 9
 dnl Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,17 +33,66 @@ changequote([,])dnl
           ;;
       esac
       ;;
+    linux*)
+      case "$host_cpu" in
+        powerpc*)
+          FLOAT_H=float.h
+          ;;
+      esac
+      ;;
   esac
   case "$host_os" in
-    aix* | freebsd*)
+    aix* | freebsd* | linux*)
       if test -n "$FLOAT_H"; then
         REPLACE_FLOAT_LDBL=1
       fi
       ;;
   esac
+
+  dnl Test against glibc-2.7 Linux/SPARC64 bug.
+  REPLACE_ITOLD=0
+  AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works],
+    [gl_cv_func_itold_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+int i = -1;
+volatile long double ld;
+int main ()
+{
+  ld += i * 1.0L;
+  if (ld > 0)
+    return 1;
+  return 0;
+}]])],
+        [gl_cv_func_itold_works=yes],
+        [gl_cv_func_itold_works=no],
+        [case "$host" in
+           sparc*-*-linux*)
+             AC_EGREP_CPP([yes],
+               [#if defined __LP64__ || defined __arch64__
+                yes
+                #endif],
+               [gl_cv_func_itold_works="guessing no"],
+               [gl_cv_func_itold_works="guessing yes"])
+             ;;
+           *) gl_cv_func_itold_works="guessing yes" ;;
+         esac
+        ])
+    ])
+  case "$gl_cv_func_itold_works" in
+    *no)
+      REPLACE_ITOLD=1
+      dnl We add the workaround to <float.h> but also to <math.h>,
+      dnl to increase the chances that the fix function gets pulled in.
+      FLOAT_H=float.h
+      ;;
+  esac
+
   if test -n "$FLOAT_H"; then
     gl_NEXT_HEADERS([float.h])
   fi
   AC_SUBST([FLOAT_H])
   AM_CONDITIONAL([GL_GENERATE_FLOAT_H], [test -n "$FLOAT_H"])
+  AC_SUBST([REPLACE_ITOLD])
 ])
diff --git a/gl/m4/fstat.m4 b/gl/m4/fstat.m4
new file mode 100644
index 0000000..0daea88
--- /dev/null
+++ b/gl/m4/fstat.m4
@@ -0,0 +1,28 @@
+# fstat.m4 serial 1
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FSTAT],
+[
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_FSTAT=1
+  fi
+  dnl Replace fstat() for supporting the gnulib-defined open() on directories.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    gl_TEST_FCHDIR
+    if test $HAVE_FCHDIR = 0 \
+       && test "$gl_cv_func_open_directory_works" != yes; then
+      REPLACE_FSTAT=1
+    fi
+  ])
+])
+
+# Prerequisites of lib/fstat.c.
+AC_DEFUN([gl_PREREQ_FSTAT],
+[
+  AC_REQUIRE([AC_C_INLINE])
+])
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 950e51b..6e88fda 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -1,9 +1,21 @@
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 8fc448f..7d83299 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 30
+# gnulib-common.m4 serial 31
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -211,6 +211,29 @@ m4_ifndef([AS_VAR_IF],
 [m4_define([AS_VAR_IF],
 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
 
+# gl_PROG_CC_C99
+# Modifies the value of the shell variable CC in an attempt to make $CC
+# understand ISO C99 source code.
+# This is like AC_PROG_CC_C99, except that
+# - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60,
+# - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00367.html>,
+#   but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00441.html>.
+# Remaining problems:
+# - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
+#   to CC twice
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00431.html>.
+# - AC_PROG_CC_STDC is likely to change when C1X is an ISO standard.
+AC_DEFUN([gl_PROG_CC_C99],
+[
+  dnl Change that version number to the minimum Autoconf version that supports
+  dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
+  m4_version_prereq([9.0],
+    [AC_REQUIRE([AC_PROG_CC_C99])],
+    [AC_REQUIRE([AC_PROG_CC_STDC])])
+])
+
 # gl_PROG_AR_RANLIB
 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 0660eb7..91cb09d 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -1,10 +1,22 @@
 # DO NOT EDIT! GENERATED AUTOMATICALLY!
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
@@ -40,6 +52,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module c-ctype:
   # Code from module c-ctype-tests:
   # Code from module clock-time:
+  # Code from module close:
+  # Code from module close-tests:
   # Code from module closedir:
   # Code from module crypto/hmac-md5:
   # Code from module crypto/hmac-md5-tests:
@@ -62,6 +76,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module fcntl-h:
   # Code from module fcntl-h-tests:
   # Code from module fd-hook:
+  # Code from module fdopen:
   # Code from module fdopen-tests:
   # Code from module fgetc-tests:
   # Code from module filename:
@@ -70,6 +85,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module fpieee:
   AC_REQUIRE([gl_FP_IEEE])
   # Code from module fpucw:
+  # Code from module fputc-tests:
+  # Code from module fread-tests:
   # Code from module frexp-nolibm:
   # Code from module frexp-nolibm-tests:
   # Code from module frexpl-nolibm:
@@ -81,6 +98,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module fseeko-tests:
   # Code from module fseterr:
   # Code from module fseterr-tests:
+  # Code from module fstat:
   # Code from module fstat-tests:
   # Code from module ftell:
   # Code from module ftell-tests:
@@ -89,6 +107,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module ftello-tests:
   # Code from module func:
   # Code from module func-tests:
+  # Code from module fwrite-tests:
   # Code from module getcwd-lgpl:
   # Code from module getcwd-lgpl-tests:
   # Code from module getdelim:
@@ -145,6 +164,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module memxor:
   # Code from module minmax:
   # Code from module msvc-inval:
+  # Code from module msvc-nothrow:
   # Code from module multiarch:
   # Code from module netdb:
   # Code from module netdb-tests:
@@ -194,9 +214,9 @@ AC_DEFUN([gl_EARLY],
   # Code from module stdarg:
   dnl Some compilers (e.g., AIX 5.3 cc) need to be in c99 mode
   dnl for the builtin va_copy to work.  With Autoconf 2.60 or later,
-  dnl AC_PROG_CC_STDC arranges for this.  With older Autoconf AC_PROG_CC_STDC
+  dnl gl_PROG_CC_C99 arranges for this.  With older Autoconf gl_PROG_CC_C99
   dnl shouldn't hurt, though installers are on their own to set c99 mode.
-  AC_REQUIRE([AC_PROG_CC_STDC])
+  gl_PROG_CC_C99
   # Code from module stdbool:
   # Code from module stdbool-tests:
   # Code from module stddef:
@@ -325,6 +345,9 @@ gl_FLOAT_H
 if test $REPLACE_FLOAT_LDBL = 1; then
   AC_LIBOBJ([float])
 fi
+if test $REPLACE_ITOLD = 1; then
+  AC_LIBOBJ([itold])
+fi
 gl_FUNC_FREXP_NO_LIBM
 if test $gl_func_frexp_no_libm != yes; then
   AC_LIBOBJ([frexp])
@@ -345,6 +368,12 @@ if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
   AC_LIBOBJ([fseeko])
 fi
 gl_STDIO_MODULE_INDICATOR([fseeko])
+gl_FUNC_FSTAT
+if test $REPLACE_FSTAT = 1; then
+  AC_LIBOBJ([fstat])
+  gl_PREREQ_FSTAT
+fi
+gl_SYS_STAT_MODULE_INDICATOR([fstat])
 gl_FUNC_FTELL
 if test $REPLACE_FTELL = 1; then
   AC_LIBOBJ([ftell])
@@ -467,6 +496,14 @@ fi
 gl_STRING_MODULE_INDICATOR([mempcpy])
 gl_MEMXOR
 gl_MINMAX
+gl_MSVC_INVAL
+if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+  AC_LIBOBJ([msvc-inval])
+fi
+gl_MSVC_NOTHROW
+if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+  AC_LIBOBJ([msvc-nothrow])
+fi
 gl_MULTIARCH
 gl_HEADER_NETDB
 gl_HEADER_NETINET_IN
@@ -666,14 +703,26 @@ changequote([, ])dnl
   AC_SUBST([gltests_WITNESS])
   gl_module_indicator_condition=$gltests_WITNESS
   m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition])
+gl_FUNC_CLOSE
+if test $REPLACE_CLOSE = 1; then
+  AC_LIBOBJ([close])
+fi
+gl_UNISTD_MODULE_INDICATOR([close])
 gl_FUNC_DUP2
 if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then
   AC_LIBOBJ([dup2])
+  gl_PREREQ_DUP2
 fi
 gl_UNISTD_MODULE_INDICATOR([dup2])
 gl_ENVIRON
 gl_UNISTD_MODULE_INDICATOR([environ])
 gl_FCNTL_H
+gl_FUNC_FDOPEN
+if test $REPLACE_FDOPEN = 1; then
+  AC_LIBOBJ([fdopen])
+  gl_PREREQ_FDOPEN
+fi
+gl_STDIO_MODULE_INDICATOR([fdopen])
 gl_FUNC_UNGETC_WORKS
 gl_FUNC_UNGETC_WORKS
 gl_FUNC_UNGETC_WORKS
@@ -705,10 +754,6 @@ dnl Check for prerequisites for memory fence checks.
 gl_FUNC_MMAP_ANON
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
 AC_CHECK_FUNCS_ONCE([mprotect])
-gl_MSVC_INVAL
-if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
-  AC_LIBOBJ([msvc-inval])
-fi
 gl_FUNC_OPEN
 if test $REPLACE_OPEN = 1; then
   AC_LIBOBJ([open])
@@ -905,6 +950,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/fseeko.c
   lib/fseterr.c
   lib/fseterr.h
+  lib/fstat.c
   lib/ftell.c
   lib/ftello.c
   lib/getdelim.c
@@ -929,6 +975,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/isnanf.c
   lib/isnanl-nolibm.h
   lib/isnanl.c
+  lib/itold.c
   lib/lseek.c
   lib/malloc.c
   lib/math.in.h
@@ -941,6 +988,10 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/memxor.c
   lib/memxor.h
   lib/minmax.h
+  lib/msvc-inval.c
+  lib/msvc-inval.h
+  lib/msvc-nothrow.c
+  lib/msvc-nothrow.h
   lib/netdb.in.h
   lib/netinet_in.in.h
   lib/opendir.c
@@ -1021,6 +1072,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/argp.m4
   m4/byteswap.m4
   m4/clock_time.m4
+  m4/close.m4
   m4/closedir.m4
   m4/codeset.m4
   m4/dirent_h.m4
@@ -1037,12 +1089,14 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/extensions.m4
   m4/fcntl-o.m4
   m4/fcntl_h.m4
+  m4/fdopen.m4
   m4/float_h.m4
   m4/fpieee.m4
   m4/frexp.m4
   m4/frexpl.m4
   m4/fseek.m4
   m4/fseeko.m4
+  m4/fstat.m4
   m4/ftell.m4
   m4/ftello.m4
   m4/func.m4
@@ -1098,6 +1152,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/mmap-anon.m4
   m4/mode_t.m4
   m4/msvc-inval.m4
+  m4/msvc-nothrow.m4
   m4/multiarch.m4
   m4/netdb_h.m4
   m4/netinet_in_h.m4
@@ -1186,6 +1241,7 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-binary-io.sh
   tests/test-byteswap.c
   tests/test-c-ctype.c
+  tests/test-close.c
   tests/test-dirent.c
   tests/test-dup2.c
   tests/test-environ.c
@@ -1195,6 +1251,8 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-fgetc.c
   tests/test-float.c
   tests/test-fprintf-posix.h
+  tests/test-fputc.c
+  tests/test-fread.c
   tests/test-frexp.c
   tests/test-frexpl.c
   tests/test-fseek.c
@@ -1220,6 +1278,7 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-ftello4.c
   tests/test-ftello4.sh
   tests/test-func.c
+  tests/test-fwrite.c
   tests/test-getcwd-lgpl.c
   tests/test-getdelim.c
   tests/test-getline.c
@@ -1302,8 +1361,10 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-wchar.c
   tests/zerosize-ptr.h
   tests=lib/binary-io.h
+  tests=lib/close.c
   tests=lib/dup2.c
   tests=lib/fcntl.in.h
+  tests=lib/fdopen.c
   tests=lib/getcwd-lgpl.c
   tests=lib/getpagesize.c
   tests=lib/ignore-value.h
@@ -1312,8 +1373,6 @@ AC_DEFUN([gl_FILE_LIST], [
   tests=lib/malloca.c
   tests=lib/malloca.h
   tests=lib/malloca.valgrind
-  tests=lib/msvc-inval.c
-  tests=lib/msvc-inval.h
   tests=lib/open.c
   tests=lib/pathmax.h
   tests=lib/putenv.c
diff --git a/gl/m4/memxor.m4 b/gl/m4/msvc-nothrow.m4
similarity index 58%
copy from gl/m4/memxor.m4
copy to gl/m4/msvc-nothrow.m4
index 10c3313..b2f6bb4 100644
--- a/gl/m4/memxor.m4
+++ b/gl/m4/msvc-nothrow.m4
@@ -1,10 +1,10 @@
-# memxor.m4 serial 4
-dnl Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
+# msvc-nothrow.m4 serial 1
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
-AC_DEFUN([gl_MEMXOR],
+AC_DEFUN([gl_MSVC_NOTHROW],
 [
-  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_MSVC_INVAL])
 ])
diff --git a/gl/m4/pathmax.m4 b/gl/m4/pathmax.m4
index 0856722..4913fa0 100644
--- a/gl/m4/pathmax.m4
+++ b/gl/m4/pathmax.m4
@@ -1,4 +1,4 @@
-# pathmax.m4 serial 9
+# pathmax.m4 serial 10
 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2011 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -10,3 +10,33 @@ AC_DEFUN([gl_PATHMAX],
   dnl Prerequisites of lib/pathmax.h.
   AC_CHECK_HEADERS_ONCE([sys/param.h])
 ])
+
+# Expands to a piece of C program that defines PATH_MAX in the same way as
+# "pathmax.h" will do.
+AC_DEFUN([gl_PATHMAX_SNIPPET], [[
+/* Arrange to define PATH_MAX, like "pathmax.h" does. */
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <limits.h>
+#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
+# include <sys/param.h>
+#endif
+#if !defined PATH_MAX && defined MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+#endif
+#ifdef __hpux
+# undef PATH_MAX
+# define PATH_MAX 1024
+#endif
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef PATH_MAX
+# define PATH_MAX 260
+#endif
+]])
+
+# Prerequisites of gl_PATHMAX_SNIPPET.
+AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
+[
+  AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
+])
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index 988e025..39bf80e 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 39
+# stdio_h.m4 serial 40
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -91,6 +91,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
 [
   GNULIB_DPRINTF=0;              AC_SUBST([GNULIB_DPRINTF])
   GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
+  GNULIB_FDOPEN=0;               AC_SUBST([GNULIB_FDOPEN])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
   GNULIB_FGETC=0;                AC_SUBST([GNULIB_FGETC])
   GNULIB_FGETS=0;                AC_SUBST([GNULIB_FGETS])
@@ -161,6 +162,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_VDPRINTF=1;               AC_SUBST([HAVE_VDPRINTF])
   REPLACE_DPRINTF=0;             AC_SUBST([REPLACE_DPRINTF])
   REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
+  REPLACE_FDOPEN=0;              AC_SUBST([REPLACE_FDOPEN])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
   REPLACE_FOPEN=0;               AC_SUBST([REPLACE_FOPEN])
   REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
diff --git a/gl/m4/sys_stat_h.m4 b/gl/m4/sys_stat_h.m4
index a3e46ca..83ebac6 100644
--- a/gl/m4/sys_stat_h.m4
+++ b/gl/m4/sys_stat_h.m4
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 25   -*- Autoconf -*-
+# sys_stat_h.m4 serial 26   -*- Autoconf -*-
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,7 +33,7 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
-    ]], [fchmodat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
+    ]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
     mknod mknodat stat utimensat])
 ]) # gl_HEADER_SYS_STAT_H
 
@@ -50,6 +50,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
   GNULIB_FCHMODAT=0;    AC_SUBST([GNULIB_FCHMODAT])
+  GNULIB_FSTAT=0;       AC_SUBST([GNULIB_FSTAT])
   GNULIB_FSTATAT=0;     AC_SUBST([GNULIB_FSTATAT])
   GNULIB_FUTIMENS=0;    AC_SUBST([GNULIB_FUTIMENS])
   GNULIB_LCHMOD=0;      AC_SUBST([GNULIB_LCHMOD])
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index 720e0fd..57c8094 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 59
+# unistd_h.m4 serial 61
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,7 +39,7 @@ AC_DEFUN([gl_UNISTD_H],
 #  include <io.h>
 # endif
 #endif
-    ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
+    ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat
     fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups
     gethostname getlogin getlogin_r getpagesize getusershell setusershell
     endusershell group_member lchown link linkat lseek pipe pipe2 pread pwrite
@@ -58,8 +58,10 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
 
 AC_DEFUN([gl_UNISTD_H_DEFAULTS],
 [
+  GNULIB_CHDIR=0;                AC_SUBST([GNULIB_CHDIR])
   GNULIB_CHOWN=0;                AC_SUBST([GNULIB_CHOWN])
   GNULIB_CLOSE=0;                AC_SUBST([GNULIB_CLOSE])
+  GNULIB_DUP=0;                  AC_SUBST([GNULIB_DUP])
   GNULIB_DUP2=0;                 AC_SUBST([GNULIB_DUP2])
   GNULIB_DUP3=0;                 AC_SUBST([GNULIB_DUP3])
   GNULIB_ENVIRON=0;              AC_SUBST([GNULIB_ENVIRON])
diff --git a/gl/math.in.h b/gl/math.in.h
index afbc9cb..f82d03c 100644
--- a/gl/math.in.h
+++ b/gl/math.in.h
@@ -67,6 +67,14 @@ _GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - 
"       \
    : rpl_ ## func ## l (value))
 
 
+#if @REPLACE_ITOLD@
+/* Pull in a function that fixes the 'int' to 'long double' conversion
+   of glibc 2.7.  */
+_GL_EXTERN_C void _Qp_itoq (long double *, int);
+static void (*_gl_math_fix_itold) (long double *, int) = _Qp_itoq;
+#endif
+
+
 /* POSIX allows platforms that don't support NAN.  But all major
    machines in the past 15 years have supported something close to
    IEEE NaN, so we define this unconditionally.  We also must define
diff --git a/gl/msvc-inval.c b/gl/msvc-inval.c
new file mode 100644
index 0000000..d10099e
--- /dev/null
+++ b/gl/msvc-inval.c
@@ -0,0 +1,130 @@
+/* Invalid parameter handler for MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "msvc-inval.h"
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+
+/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
+   declaration.  */
+# include <stdlib.h>
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+}
+
+# else
+
+/* Get declarations of the Win32 API functions.  */
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+
+#  if defined _MSC_VER
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+  RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+#  else
+
+/* An index to thread-local storage.  */
+static DWORD tls_index;
+static int tls_initialized /* = 0 */;
+
+/* Used as a fallback only.  */
+static struct gl_msvc_inval_per_thread not_per_thread;
+
+struct gl_msvc_inval_per_thread *
+gl_msvc_inval_current (void)
+{
+  if (!tls_initialized)
+    {
+      tls_index = TlsAlloc ();
+      tls_initialized = 1;
+    }
+  if (tls_index == TLS_OUT_OF_INDEXES)
+    /* TlsAlloc had failed.  */
+    return &not_per_thread;
+  else
+    {
+      struct gl_msvc_inval_per_thread *pointer =
+        (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
+      if (pointer == NULL)
+        {
+          /* First call.  Allocate a new 'struct gl_msvc_inval_per_thread'.  */
+          pointer =
+            (struct gl_msvc_inval_per_thread *)
+            malloc (sizeof (struct gl_msvc_inval_per_thread));
+          if (pointer == NULL)
+            /* Could not allocate memory.  Use the global storage.  */
+            pointer = &not_per_thread;
+          TlsSetValue (tls_index, pointer);
+        }
+      return pointer;
+    }
+}
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+  struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
+  if (current->restart_valid)
+    longjmp (current->restart, 1);
+  else
+    /* An invalid parameter notification from outside the gnulib code.
+       Give the caller a chance to intervene.  */
+    RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+#  endif
+
+# endif
+
+static int gl_msvc_inval_initialized /* = 0 */;
+
+void
+gl_msvc_inval_ensure_handler (void)
+{
+  if (gl_msvc_inval_initialized == 0)
+    {
+      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
+      gl_msvc_inval_initialized = 1;
+    }
+}
+
+#endif
diff --git a/gl/msvc-inval.h b/gl/msvc-inval.h
new file mode 100644
index 0000000..393272e
--- /dev/null
+++ b/gl/msvc-inval.h
@@ -0,0 +1,223 @@
+/* Invalid parameter handler for MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _MSVC_INVAL_H
+#define _MSVC_INVAL_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+   functions like fprintf(), dup2(), or close() crash when the caller passes
+   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
+   instead.
+   This file defines macros that turn such an invalid parameter notification
+   into a non-local exit.  An error code can then be produced at the target
+   of this exit.  You can thus write code like
+
+     TRY_MSVC_INVAL
+       {
+         <Code that can trigger an invalid parameter notification
+          but does not do 'return', 'break', 'continue', nor 'goto'.>
+       }
+     CATCH_MSVC_INVAL
+       {
+         <Code that handles an invalid parameter notification
+          but does not do 'return', 'break', 'continue', nor 'goto'.>
+       }
+     DONE_MSVC_INVAL;
+
+   This entire block expands to a single statement.
+
+   The handling of invalid parameters can be done in three ways:
+
+     * The default way, which is reasonable for programs (not libraries):
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
+
+     * The way for libraries that make "hairy" calls (like close(-1), or
+       fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
+
+     * The way for libraries that make no "hairy" calls:
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
+ */
+
+#define DEFAULT_HANDLING       0
+#define HAIRY_LIBRARY_HANDLING 1
+#define SANE_LIBRARY_HANDLING  2
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+/* A native Windows platform with the "invalid parameter handler" concept,
+   and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING.  */
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+/* Default handling.  */
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif
+
+/* Ensure that the invalid parameter handler in installed that just returns.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+#  ifdef __cplusplus
+}
+#  endif
+
+#  define TRY_MSVC_INVAL \
+     do                                                                        
\
+       {                                                                       
\
+         gl_msvc_inval_ensure_handler ();                                      
\
+         if (1)
+#  define CATCH_MSVC_INVAL \
+         else
+#  define DONE_MSVC_INVAL \
+       }                                                                       
\
+     while (0)
+
+# else
+/* Handling for hairy libraries.  */
+
+#  include <excpt.h>
+
+/* Gnulib can define its own status codes, as described in the page
+   "Raising Software Exceptions" on microsoft.com
+   <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
+   Our status codes are composed of
+     - 0xE0000000, mandatory for all user-defined status codes,
+     - 0x474E550, a API identifier ("GNU"),
+     - 0, 1, 2, ..., used to distinguish different status codes from the
+       same API.  */
+#  define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
+
+#  if defined _MSC_VER
+/* A compiler that supports __try/__except, as described in the page
+   "try-except statement" on microsoft.com
+   <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
+   With __try/__except, we can use the multithread-safe exception handling.  */
+
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
+/* Ensure that the invalid parameter handler in installed that raises a
+   software exception with code STATUS_GNULIB_INVALID_PARAMETER.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+#   ifdef __cplusplus
+}
+#   endif
+
+#   define TRY_MSVC_INVAL \
+      do                                                                       
\
+        {                                                                      
\
+          gl_msvc_inval_ensure_handler ();                                     
\
+          __try
+#   define CATCH_MSVC_INVAL \
+          __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER     
\
+                    ? EXCEPTION_EXECUTE_HANDLER                                
\
+                    : EXCEPTION_CONTINUE_SEARCH)
+#   define DONE_MSVC_INVAL \
+        }                                                                      
\
+      while (0)
+
+#  else
+/* Any compiler.
+   We can only use setjmp/longjmp.  */
+
+#   include <setjmp.h>
+
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
+struct gl_msvc_inval_per_thread
+{
+  /* The restart that will resume execution at the code between
+     CATCH_MSVC_INVAL and DONE_MSVC_INVAL.  It is enabled only between
+     TRY_MSVC_INVAL and CATCH_MSVC_INVAL.  */
+  jmp_buf restart;
+
+  /* Tells whether the contents of restart is valid.  */
+  int restart_valid;
+};
+
+/* Ensure that the invalid parameter handler in installed that passes
+   control to the gl_msvc_inval_restart if it is valid, or raises a
+   software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+/* Return a pointer to the per-thread data for the current thread.  */
+extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
+
+#   ifdef __cplusplus
+}
+#   endif
+
+#   define TRY_MSVC_INVAL \
+      do                                                                       
\
+        {                                                                      
\
+          struct gl_msvc_inval_per_thread *msvc_inval_current;                 
\
+          gl_msvc_inval_ensure_handler ();                                     
\
+          msvc_inval_current = gl_msvc_inval_current ();                       
\
+          /* First, initialize gl_msvc_inval_restart.  */                      
\
+          if (setjmp (msvc_inval_current->restart) == 0)                       
\
+            {                                                                  
\
+              /* Then, mark it as valid.  */                                   
\
+              msvc_inval_current->restart_valid = 1;
+#   define CATCH_MSVC_INVAL \
+              /* Execution completed.                                          
\
+                 Mark gl_msvc_inval_restart as invalid.  */                    
\
+              msvc_inval_current->restart_valid = 0;                           
\
+            }                                                                  
\
+          else                                                                 
\
+            {                                                                  
\
+              /* Execution triggered an invalid parameter notification.        
\
+                 Mark gl_msvc_inval_restart as invalid.  */                    
\
+              msvc_inval_current->restart_valid = 0;
+#   define DONE_MSVC_INVAL \
+            }                                                                  
\
+        }                                                                      
\
+      while (0)
+
+#  endif
+
+# endif
+
+#else
+/* A platform that does not need to the invalid parameter handler,
+   or when SANE_LIBRARY_HANDLING is desired.  */
+
+/* The braces here avoid GCC warnings like
+   "warning: suggest explicit braces to avoid ambiguous `else'".  */
+# define TRY_MSVC_INVAL \
+    do                                                                         
\
+      {                                                                        
\
+        if (1)
+# define CATCH_MSVC_INVAL \
+        else
+# define DONE_MSVC_INVAL \
+      }                                                                        
\
+    while (0)
+
+#endif
+
+#endif /* _MSVC_INVAL_H */
diff --git a/gl/asprintf.c b/gl/msvc-nothrow.c
similarity index 56%
copy from gl/asprintf.c
copy to gl/msvc-nothrow.c
index 2f13126..8965140 100644
--- a/gl/asprintf.c
+++ b/gl/msvc-nothrow.c
@@ -1,6 +1,6 @@
-/* Formatted output to strings.
-   Copyright (C) 1999, 2002, 2006-2007, 2009-2011 Free Software Foundation,
-   Inc.
+/* Wrappers that don't throw invalid parameter notifications
+   with MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,22 +19,32 @@
 #include <config.h>
 
 /* Specification.  */
-#ifdef IN_LIBASPRINTF
-# include "vasprintf.h"
-#else
-# include <stdio.h>
-#endif
+#include "msvc-nothrow.h"
+
+/* Get declarations of the Win32 API functions.  */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
 
-#include <stdarg.h>
+#include "msvc-inval.h"
 
-int
-asprintf (char **resultp, const char *format, ...)
+#undef _get_osfhandle
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+intptr_t
+_gl_nothrow_get_osfhandle (int fd)
 {
-  va_list args;
-  int result;
+  intptr_t result;
+
+  TRY_MSVC_INVAL
+    {
+      result = _get_osfhandle (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = (intptr_t) INVALID_HANDLE_VALUE;
+    }
+  DONE_MSVC_INVAL;
 
-  va_start (args, format);
-  result = vasprintf (resultp, format, args);
-  va_end (args);
   return result;
 }
+#endif
diff --git a/gl/msvc-nothrow.h b/gl/msvc-nothrow.h
new file mode 100644
index 0000000..462fb67
--- /dev/null
+++ b/gl/msvc-nothrow.h
@@ -0,0 +1,44 @@
+/* Wrappers that don't throw invalid parameter notifications
+   with MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _MSVC_NOTHROW_H
+#define _MSVC_NOTHROW_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+   functions like fprintf(), dup2(), or close() crash when the caller passes
+   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
+   instead.
+   This file defines wrappers that turn such an invalid parameter notification
+   into an error code.  */
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Get original declaration of _get_osfhandle.  */
+# include <io.h>
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+
+/* Override _get_osfhandle.  */
+extern intptr_t _gl_nothrow_get_osfhandle (int fd);
+#  define _get_osfhandle _gl_nothrow_get_osfhandle
+
+# endif
+
+#endif
+
+#endif /* _MSVC_NOTHROW_H */
diff --git a/gl/opendir.c b/gl/opendir.c
index 06c611f..20ae75e 100644
--- a/gl/opendir.c
+++ b/gl/opendir.c
@@ -20,6 +20,7 @@
 #include <dirent.h>
 
 #include <errno.h>
+#include <stddef.h>
 
 #if HAVE_OPENDIR
 
@@ -28,7 +29,6 @@
 
 #else
 
-# include <stddef.h>
 # include <stdlib.h>
 
 # include "dirent-private.h"
@@ -36,6 +36,10 @@
 
 #endif
 
+#if REPLACE_FCHDIR
+# include <unistd.h>
+#endif
+
 DIR *
 opendir (const char *dir_name)
 {
diff --git a/gl/sockets.c b/gl/sockets.c
index 53cb66e..39939b0 100644
--- a/gl/sockets.c
+++ b/gl/sockets.c
@@ -28,6 +28,7 @@
 # include <sys/socket.h>
 
 # include "fd-hook.h"
+# include "msvc-nothrow.h"
 
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
 # include "w32sock.h"
diff --git a/gl/sockets.h b/gl/sockets.h
index 93ae5d2..323f68c 100644
--- a/gl/sockets.h
+++ b/gl/sockets.h
@@ -36,6 +36,8 @@ int gl_sockets_cleanup (void);
 
 #include <sys/socket.h>
 
+#include "msvc-nothrow.h"
+
 static inline SOCKET
 gl_fd_to_handle (int fd)
 {
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 6917d25..ce00af5 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -170,6 +170,26 @@ _GL_WARN_ON_USE (fclose, "fclose is not always POSIX 
compliant - "
                  "use gnulib module fclose for portable POSIX compliance");
 #endif
 
+#if @GNULIB_FDOPEN@
+# if @REPLACE_FDOPEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fdopen
+#   define fdopen rpl_fdopen
+#  endif
+_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode)
+                                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
+# else
+_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
+# endif
+_GL_CXXALIASWARN (fdopen);
+#elif defined GNULIB_POSIXCHECK
+# undef fdopen
+/* Assume fdopen is always declared.  */
+_GL_WARN_ON_USE (fdopen, "fdopen on Win32 platforms is not POSIX compatible - "
+                 "use gnulib module fdopen for portability");
+#endif
+
 #if @GNULIB_FFLUSH@
 /* Flush all pending data on STREAM according to POSIX rules.  Both
    output and seekable input streams are supported.
diff --git a/gl/strings.in.h b/gl/strings.in.h
index 42600b9..8bb455e 100644
--- a/gl/strings.in.h
+++ b/gl/strings.in.h
@@ -37,6 +37,11 @@
 #ifndef address@hidden@_STRINGS_H
 #define address@hidden@_STRINGS_H
 
+#if ! @HAVE_DECL_STRNCASECMP@
+/* Get size_t.  */
+# include <stddef.h>
+#endif
+
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
index 43c15c3..77a7177 100644
--- a/gl/sys_stat.in.h
+++ b/gl/sys_stat.in.h
@@ -55,10 +55,11 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
-   headers that may declare mkdir().  */
+   headers that may declare mkdir().  Native Windows platforms declare mkdir
+   in <io.h> and/or <direct.h>, not in <unistd.h>.  */
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # include <io.h>     /* mingw32, mingw64 */
-# include <direct.h> /* mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
 #endif
 
 #ifndef S_IFIFO
@@ -318,16 +319,25 @@ _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
 #endif
 
 
-#if @REPLACE_FSTAT@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  define fstat rpl_fstat
-# endif
+#if @GNULIB_FSTAT@
+# if @REPLACE_FSTAT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fstat
+#   define fstat rpl_fstat
+#  endif
 _GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL 
((2)));
 _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
-#else
+# else
 _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
-#endif
+# endif
 _GL_CXXALIASWARN (fstat);
+#elif defined GNULIB_POSIXCHECK
+# undef fstat
+# if HAVE_RAW_DECL_FSTAT
+_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
+                 "use gnulib module fstat for portability");
+# endif
+#endif
 
 
 #if @GNULIB_FSTATAT@
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index ba41456..71cfb3f 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -2,10 +2,22 @@
 ## Process this file with automake to produce Makefile.in.
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
@@ -96,6 +108,23 @@ EXTRA_DIST += test-c-ctype.c macros.h
 
 ## end   gnulib module c-ctype-tests
 
+## begin gnulib module close
+
+
+EXTRA_DIST += close.c
+
+EXTRA_libtests_a_SOURCES += close.c
+
+## end   gnulib module close
+
+## begin gnulib module close-tests
+
+TESTS += test-close
+check_PROGRAMS += test-close
+EXTRA_DIST += test-close.c signature.h macros.h
+
+## end   gnulib module close-tests
+
 ## begin gnulib module crypto/hmac-md5-tests
 
 TESTS += test-hmac-md5
@@ -198,6 +227,15 @@ EXTRA_DIST += test-fcntl-h.c
 
 ## end   gnulib module fcntl-h-tests
 
+## begin gnulib module fdopen
+
+
+EXTRA_DIST += fdopen.c
+
+EXTRA_libtests_a_SOURCES += fdopen.c
+
+## end   gnulib module fdopen
+
 ## begin gnulib module fdopen-tests
 
 TESTS += test-fdopen
@@ -222,6 +260,22 @@ EXTRA_DIST += test-float.c macros.h
 
 ## end   gnulib module float-tests
 
+## begin gnulib module fputc-tests
+
+TESTS += test-fputc
+check_PROGRAMS += test-fputc
+EXTRA_DIST += test-fputc.c signature.h macros.h
+
+## end   gnulib module fputc-tests
+
+## begin gnulib module fread-tests
+
+TESTS += test-fread
+check_PROGRAMS += test-fread
+EXTRA_DIST += test-fread.c signature.h macros.h
+
+## end   gnulib module fread-tests
+
 ## begin gnulib module frexp-nolibm-tests
 
 TESTS += test-frexp-nolibm
@@ -299,6 +353,14 @@ EXTRA_DIST += test-func.c macros.h
 
 ## end   gnulib module func-tests
 
+## begin gnulib module fwrite-tests
+
+TESTS += test-fwrite
+check_PROGRAMS += test-fwrite
+EXTRA_DIST += test-fwrite.c signature.h macros.h
+
+## end   gnulib module fwrite-tests
+
 ## begin gnulib module getcwd-lgpl
 
 
@@ -519,15 +581,6 @@ EXTRA_DIST += test-memchr.c zerosize-ptr.h signature.h 
macros.h
 
 ## end   gnulib module memchr-tests
 
-## begin gnulib module msvc-inval
-
-
-EXTRA_DIST += msvc-inval.c msvc-inval.h
-
-EXTRA_libtests_a_SOURCES += msvc-inval.c
-
-## end   gnulib module msvc-inval
-
 ## begin gnulib module netdb-tests
 
 TESTS += test-netdb
diff --git a/gl/closedir.c b/gl/tests/close.c
similarity index 55%
copy from gl/closedir.c
copy to gl/tests/close.c
index 700d60e..c2197fe 100644
--- a/gl/closedir.c
+++ b/gl/tests/close.c
@@ -1,5 +1,5 @@
-/* Stop reading the entries of a directory.
-   Copyright (C) 2006-2011 Free Software Foundation, Inc.
+/* close replacement.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -17,47 +17,53 @@
 #include <config.h>
 
 /* Specification.  */
-#include <dirent.h>
+#include <unistd.h>
 
-#if HAVE_CLOSEDIR
+#include <errno.h>
 
-/* Override closedir(), to keep track of the open file descriptors.
-   Needed because there is a function dirfd().  */
+#include "fd-hook.h"
+#include "msvc-inval.h"
 
-#else
-
-# include <stdlib.h>
-
-# include "dirent-private.h"
+#undef close
 
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+close_nothrow (int fd)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = close (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define close_nothrow close
 #endif
 
+/* Override close() to call into other gnulib modules.  */
+
 int
-closedir (DIR *dirp)
+rpl_close (int fd)
 {
-# if REPLACE_FCHDIR
-  int fd = dirfd (dirp);
-# endif
-  int retval;
-
-#if HAVE_CLOSEDIR
-# undef closedir
-
-  retval = closedir (dirp);
-
+#if WINDOWS_SOCKETS
+  int retval = execute_all_close_hooks (close_nothrow, fd);
 #else
-
-  if (dirp->current != INVALID_HANDLE_VALUE)
-    FindClose (dirp->current);
-  free (dirp);
-
-  retval = 0;
-
+  int retval = close_nothrow (fd);
 #endif
 
 #if REPLACE_FCHDIR
   if (retval >= 0)
     _gl_unregister_fd (fd);
 #endif
+
   return retval;
 }
diff --git a/gl/tests/dup2.c b/gl/tests/dup2.c
index 234bdfe..790c98a 100644
--- a/gl/tests/dup2.c
+++ b/gl/tests/dup2.c
@@ -25,47 +25,39 @@
 #include <errno.h>
 #include <fcntl.h>
 
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the Win32 API functions.  */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-#endif
-
-#include "msvc-inval.h"
-
 #if HAVE_DUP2
 
 # undef dup2
 
-int
-rpl_dup2 (int fd, int desired_fd)
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* 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"
+
+static int
+ms_windows_dup2 (int fd, int desired_fd)
 {
   int result;
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
   /* If fd is closed, mingw hangs on dup2 (fd, fd).  If fd is open,
      dup2 (fd, fd) returns 0, but all further attempts to use fd in
      future dup2 calls will hang.  */
   if (fd == desired_fd)
     {
-      HANDLE handle;
-
-      TRY_MSVC_INVAL
-        {
-          handle = (HANDLE) _get_osfhandle (fd);
-        }
-      CATCH_MSVC_INVAL
-        {
-          handle = INVALID_HANDLE_VALUE;
-        }
-      DONE_MSVC_INVAL;
-
-      if (handle == INVALID_HANDLE_VALUE)
+      if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
         {
           errno = EBADF;
           return -1;
         }
       return fd;
     }
+
   /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
      http://bugs.winehq.org/show_bug.cgi?id=21289 */
   if (desired_fd < 0)
@@ -73,11 +65,6 @@ rpl_dup2 (int fd, int desired_fd)
       errno = EBADF;
       return -1;
     }
-# elif !defined __linux__
-  /* On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
-  if (fd == desired_fd)
-    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
-# endif
 
   TRY_MSVC_INVAL
     {
@@ -85,25 +72,38 @@ rpl_dup2 (int fd, int desired_fd)
     }
   CATCH_MSVC_INVAL
     {
-      result = -1;
       errno = EBADF;
+      result = -1;
     }
   DONE_MSVC_INVAL;
 
-# ifdef __linux__
-  /* Correct a Linux return value.
-     
<http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.30.y.git;a=commitdiff;h=2b79bc4f7ebbd5af3c8b867968f9f15602d5f802>
-   */
-  if (fd == desired_fd && result == (unsigned int) -EBADF)
-    {
-      errno = EBADF;
-      result = -1;
-    }
-# endif
   if (result == 0)
     result = desired_fd;
-  /* Correct a cygwin 1.5.x errno value.  */
-  else if (result == -1 && errno == EMFILE)
+
+  return result;
+}
+
+#  define dup2 ms_windows_dup2
+
+# endif
+
+int
+rpl_dup2 (int fd, int desired_fd)
+{
+  int result;
+
+# ifdef F_GETFL
+  /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
+     On Cygwin 1.5.x, dup2 (1, 1) returns 0.
+     On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
+  if (fd == desired_fd)
+    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
+# endif
+
+  result = dup2 (fd, desired_fd);
+
+  /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x.  */
+  if (result == -1 && errno == EMFILE)
     errno = EBADF;
 # if REPLACE_FCHDIR
   if (fd != desired_fd && result != -1)
diff --git a/gl/tests/test-fdopen.c b/gl/tests/fdopen.c
similarity index 51%
copy from gl/tests/test-fdopen.c
copy to gl/tests/fdopen.c
index 304e520..50c889b 100644
--- a/gl/tests/test-fdopen.c
+++ b/gl/tests/fdopen.c
@@ -1,4 +1,4 @@
-/* Test opening a stream with a file descriptor.
+/* Open a stream with a given file descriptor.
    Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -16,39 +16,54 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdio.h>
 
-#include "signature.h"
-SIGNATURE_CHECK (fdopen, FILE *, (int, const char *));
-
 #include <errno.h>
 
-#include "macros.h"
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#undef fdopen
 
-int
-main (void)
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static FILE *
+fdopen_nothrow (int fd, const char *mode)
 {
-  /* Test behaviour for invalid file descriptors.  */
-  {
-    FILE *fp;
-
-    errno = 0;
-    fp = fdopen (-1, "r");
-    if (fp == NULL)
-      ASSERT (errno == EBADF);
-    else
-      fclose (fp);
-  }
-  {
-    FILE *fp;
-
-    errno = 0;
-    fp = fdopen (99, "r");
-    if (fp == NULL)
-      ASSERT (errno == EBADF);
-    else
-      fclose (fp);
-  }
-
-  return 0;
+  FILE *result;
+
+  TRY_MSVC_INVAL
+    {
+      result = fdopen (fd, mode);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = NULL;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define fdopen_nothrow fdopen
+#endif
+
+FILE *
+rpl_fdopen (int fd, const char *mode)
+{
+  int saved_errno = errno;
+  FILE *fp;
+
+  errno = 0;
+  fp = fdopen_nothrow (fd, mode);
+  if (fp == NULL)
+    {
+      if (errno == 0)
+        errno = EBADF;
+    }
+  else
+    errno = saved_errno;
+
+  return fp;
 }
diff --git a/gl/tests/msvc-inval.c b/gl/tests/msvc-inval.c
deleted file mode 100644
index cff0796..0000000
--- a/gl/tests/msvc-inval.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Invalid parameter handler for MSVC runtime libraries.
-   Copyright (C) 2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "msvc-inval.h"
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-
-# ifdef STATUS_GNULIB_INVALID_PARAMETER
-
-/* Get declarations of the Win32 API functions.  */
-#  define WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-
-static void cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                   const wchar_t *function,
-                                   const wchar_t *file,
-                                   unsigned int line,
-                                   uintptr_t dummy)
-{
-  RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
-}
-
-static int gl_msvc_inval_initialized /* = 0 */;
-
-void
-gl_msvc_inval_ensure_handler (void)
-{
-  if (gl_msvc_inval_initialized == 0)
-    {
-      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
-      gl_msvc_inval_initialized = 1;
-    }
-}
-
-# else
-
-jmp_buf gl_msvc_inval_restart;
-
-void cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                   const wchar_t *function,
-                                   const wchar_t *file,
-                                   unsigned int line,
-                                   uintptr_t dummy)
-{
-  longjmp (gl_msvc_inval_restart, 1);
-}
-
-# endif
-
-#endif
diff --git a/gl/tests/msvc-inval.h b/gl/tests/msvc-inval.h
deleted file mode 100644
index 00d3a1e..0000000
--- a/gl/tests/msvc-inval.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Invalid parameter handler for MSVC runtime libraries.
-   Copyright (C) 2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _MSVC_INVAL_H
-#define _MSVC_INVAL_H
-
-/* With MSVC runtime libraries with the "invalid parameter handler" concept,
-   functions like fprintf(), dup2(), or close() crash when the caller passes
-   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
-   instead.
-   This file defines macros that turn such an invalid parameter notification
-   into a non-local exit.  An error code can then be produced at the target
-   of this exit.  You can thus write code like
-
-     TRY_MSVC_INVAL
-       {
-         <Code that can trigger an invalid parameter notification
-          but does not do 'return', 'break', 'continue', nor 'goto'.>
-       }
-     CATCH_MSVC_INVAL
-       {
-         <Code that handles an invalid parameter notification
-          but does not do 'return', 'break', 'continue', nor 'goto'.>
-       }
-     DONE_MSVC_INVAL;
-
-   This entire block expands to a single statement.
- */
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-/* A native Windows platform with the "invalid parameter handler" concept.  */
-
-/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
-   declaration.  */
-#include <stdlib.h>
-
-# if defined _MSC_VER
-/* A compiler that supports __try/__except, as described in the page
-   "try-except statement" on microsoft.com
-   <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
-   With __try/__except, we can use the multithread-safe exception handling.  */
-
-/* Gnulib can define its own status codes, as described in the page
-   "Raising Software Exceptions" on microsoft.com
-   <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
-   Our status codes are composed of
-     - 0xE0000000, mandatory for all user-defined status codes,
-     - 0x474E550, a API identifier ("GNU"),
-     - 0, 1, 2, ..., used to distinguish different status codes from the
-       same API.  */
-#  define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
-
-#  ifdef __cplusplus
-extern "C" {
-#  endif
-
-/* Ensure that the invalid parameter handler in installed that raises a
-   software exception with code STATUS_GNULIB_INVALID_PARAMETER.
-   Because we assume no other part of the program installs a different
-   invalid parameter handler, this solution is multithread-safe.  */
-extern void gl_msvc_inval_ensure_handler (void);
-
-#  ifdef __cplusplus
-}
-#  endif
-
-#  define TRY_MSVC_INVAL \
-     do                                                                        
\
-       {                                                                       
\
-         gl_msvc_inval_ensure_handler ();                                      
\
-         __try
-#  define CATCH_MSVC_INVAL \
-         __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER      
\
-                   ? EXCEPTION_EXECUTE_HANDLER                                 
\
-                   : EXCEPTION_CONTINUE_SEARCH)
-#  define DONE_MSVC_INVAL \
-       }                                                                       
\
-     while (0)
-
-# else
-/* Any compiler.
-   We can only use setjmp/longjmp.
-   Unfortunately, this is *not* multithread-safe.  */
-
-#  include <setjmp.h>
-
-#  ifdef __cplusplus
-extern "C" {
-#  endif
-
-/* The restart that will resume execution at the code between
-   CATCH_MSVC_INVAL and DONE_MSVC_INVAL.  It is enabled only between
-   TRY_MSVC_INVAL and CATCH_MSVC_INVAL.  */
-extern jmp_buf gl_msvc_inval_restart;
-
-/* The invalid parameter handler that unwinds the stack up to the
-   gl_msvc_inval_restart.  It is enabled only between TRY_MSVC_INVAL
-   and CATCH_MSVC_INVAL.  */
-extern void cdecl gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                                     const wchar_t *function,
-                                                     const wchar_t *file,
-                                                     unsigned int line,
-                                                     uintptr_t dummy);
-
-#  ifdef __cplusplus
-}
-#  endif
-
-#  define TRY_MSVC_INVAL \
-     do                                                                        
\
-       {                                                                       
\
-         _invalid_parameter_handler orig_handler;                              
\
-         /* First, initialize gl_msvc_inval_restart.  */                       
\
-         if (setjmp (gl_msvc_inval_restart) == 0)                              
\
-           {                                                                   
\
-             /* Then, enable gl_msvc_invalid_parameter_handler.  */            
\
-             orig_handler =                                                    
\
-               _set_invalid_parameter_handler 
(gl_msvc_invalid_parameter_handler);
-#  define CATCH_MSVC_INVAL \
-             /* Execution completed.                                           
\
-                Disable gl_msvc_invalid_parameter_handler.  */                 
\
-             _set_invalid_parameter_handler (orig_handler);                    
\
-           }                                                                   
\
-         else                                                                  
\
-           {                                                                   
\
-             /* Execution triggered an invalid parameter notification.         
\
-                Disable gl_msvc_invalid_parameter_handler.  */                 
\
-             _set_invalid_parameter_handler (orig_handler);
-#  define DONE_MSVC_INVAL \
-           }                                                                   
\
-       }                                                                       
\
-     while (0)
-
-# endif
-
-#else
-/* A platform that does not need to the invalid parameter handler.  */
-
-/* The braces here avoid GCC warnings like
-   "warning: suggest explicit braces to avoid ambiguous `else'".  */
-# define TRY_MSVC_INVAL \
-    do                                                                         
\
-      {                                                                        
\
-        if (1)
-# define CATCH_MSVC_INVAL \
-        else
-# define DONE_MSVC_INVAL \
-      }                                                                        
\
-    while (0)
-
-#endif
-
-#endif /* _MSVC_INVAL_H */
diff --git a/gl/tests/test-fstat.c b/gl/tests/test-close.c
similarity index 78%
copy from gl/tests/test-fstat.c
copy to gl/tests/test-close.c
index 6c120d9..2b87db1 100644
--- a/gl/tests/test-fstat.c
+++ b/gl/tests/test-close.c
@@ -1,4 +1,4 @@
-/* Tests of fstat() function.
+/* Test closing a file or socket.
    Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -16,31 +16,27 @@
 
 #include <config.h>
 
-#include <sys/stat.h>
+#include <unistd.h>
 
 #include "signature.h"
-SIGNATURE_CHECK (fstat, int, (int, struct stat *));
+SIGNATURE_CHECK (close, int, (int));
 
 #include <errno.h>
 
 #include "macros.h"
 
 int
-main (int argc, char *argv[])
+main (void)
 {
   /* Test behaviour for invalid file descriptors.  */
   {
-    struct stat statbuf;
-
     errno = 0;
-    ASSERT (fstat (-1, &statbuf) == -1);
+    ASSERT (close (-1) == -1);
     ASSERT (errno == EBADF);
   }
   {
-    struct stat statbuf;
-
     errno = 0;
-    ASSERT (fstat (99, &statbuf) == -1);
+    ASSERT (close (99) == -1);
     ASSERT (errno == EBADF);
   }
 
diff --git a/gl/tests/test-dup2.c b/gl/tests/test-dup2.c
index 37454e9..a14807a 100644
--- a/gl/tests/test-dup2.c
+++ b/gl/tests/test-dup2.c
@@ -36,6 +36,8 @@ SIGNATURE_CHECK (dup2, int, (int, int));
 /* Get declarations of the Win32 API functions.  */
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 #endif
 
 #include "macros.h"
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fgetc.c
index a4e1953..4df46fb 100644
--- a/gl/tests/test-fgetc.c
+++ b/gl/tests/test-fgetc.c
@@ -26,6 +26,8 @@ SIGNATURE_CHECK (fgetc, int, (FILE *));
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "msvc-inval.h"
+
 #include "macros.h"
 
 int
@@ -33,6 +35,13 @@ main (int argc, char **argv)
 {
   const char *filename = "test-fgetc.txt";
 
+  /* We don't have an fgetc() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
+
   /* Prepare a file.  */
   {
     const char text[] = "hello world";
@@ -51,6 +60,7 @@ main (int argc, char **argv)
     errno = 0;
     ASSERT (fgetc (fp) == EOF);
     ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
     fclose (fp);
   }
 
@@ -63,6 +73,7 @@ main (int argc, char **argv)
         errno = 0;
         ASSERT (fgetc (fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
@@ -73,6 +84,7 @@ main (int argc, char **argv)
         errno = 0;
         ASSERT (fgetc (fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fputc.c
similarity index 55%
copy from gl/tests/test-fgetc.c
copy to gl/tests/test-fputc.c
index a4e1953..03a3716 100644
--- a/gl/tests/test-fgetc.c
+++ b/gl/tests/test-fputc.c
@@ -1,4 +1,4 @@
-/* Test of fgetc() function.
+/* Test of fputc() function.
    Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -20,59 +20,65 @@
 #include <stdio.h>
 
 #include "signature.h"
-SIGNATURE_CHECK (fgetc, int, (FILE *));
+SIGNATURE_CHECK (fputc, int, (int, FILE *));
 
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "msvc-inval.h"
+
 #include "macros.h"
 
 int
 main (int argc, char **argv)
 {
-  const char *filename = "test-fgetc.txt";
+  const char *filename = "test-fputc.txt";
 
-  /* Prepare a file.  */
-  {
-    const char text[] = "hello world";
-    int fd = open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
-    ASSERT (fd >= 0);
-    ASSERT (write (fd, text, sizeof (text)) == sizeof (text));
-    ASSERT (close (fd) == 0);
-  }
+  /* We don't have an fputc() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
 
-  /* Test that fgetc() sets errno if someone else closes the stream
-     fd behind the back of stdio.  */
+  /* Test that fputc() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
   {
-    FILE *fp = fopen (filename, "r");
+    FILE *fp = fopen (filename, "w");
     ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
     ASSERT (close (fileno (fp)) == 0);
     errno = 0;
-    ASSERT (fgetc (fp) == EOF);
+    ASSERT (fputc ('x', fp) == EOF);
     ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
     fclose (fp);
   }
 
-  /* Test that fgetc() sets errno if the stream was constructed with
-     an invalid file descriptor.  */
+  /* Test that fputc() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
   {
-    FILE *fp = fdopen (-1, "r");
+    FILE *fp = fdopen (-1, "w");
     if (fp != NULL)
       {
+        setvbuf (fp, NULL, _IONBF, 0);
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fputc ('x', fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
   {
-    FILE *fp = fdopen (99, "r");
+    FILE *fp = fdopen (99, "w");
     if (fp != NULL)
       {
+        setvbuf (fp, NULL, _IONBF, 0);
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fputc ('x', fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fread.c
similarity index 67%
copy from gl/tests/test-fgetc.c
copy to gl/tests/test-fread.c
index a4e1953..e205c9e 100644
--- a/gl/tests/test-fgetc.c
+++ b/gl/tests/test-fread.c
@@ -1,4 +1,4 @@
-/* Test of fgetc() function.
+/* Test of fread() function.
    Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -20,18 +20,27 @@
 #include <stdio.h>
 
 #include "signature.h"
-SIGNATURE_CHECK (fgetc, int, (FILE *));
+SIGNATURE_CHECK (fread, size_t, (void *, size_t, size_t, FILE *));
 
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "msvc-inval.h"
+
 #include "macros.h"
 
 int
 main (int argc, char **argv)
 {
-  const char *filename = "test-fgetc.txt";
+  const char *filename = "test-fread.txt";
+
+  /* We don't have an fread() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
 
   /* Prepare a file.  */
   {
@@ -42,27 +51,31 @@ main (int argc, char **argv)
     ASSERT (close (fd) == 0);
   }
 
-  /* Test that fgetc() sets errno if someone else closes the stream
+  /* Test that fread() sets errno if someone else closes the stream
      fd behind the back of stdio.  */
   {
     FILE *fp = fopen (filename, "r");
+    char buf[5];
     ASSERT (fp != NULL);
     ASSERT (close (fileno (fp)) == 0);
     errno = 0;
-    ASSERT (fgetc (fp) == EOF);
+    ASSERT (fread (buf, 1, sizeof (buf), fp) == 0);
     ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
     fclose (fp);
   }
 
-  /* Test that fgetc() sets errno if the stream was constructed with
+  /* Test that fread() sets errno if the stream was constructed with
      an invalid file descriptor.  */
   {
     FILE *fp = fdopen (-1, "r");
     if (fp != NULL)
       {
+        char buf[1];
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fread (buf, 1, 1, fp) == 0);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
@@ -70,9 +83,11 @@ main (int argc, char **argv)
     FILE *fp = fdopen (99, "r");
     if (fp != NULL)
       {
+        char buf[1];
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fread (buf, 1, 1, fp) == 0);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fwrite.c
similarity index 51%
copy from gl/tests/test-fgetc.c
copy to gl/tests/test-fwrite.c
index a4e1953..76ed05c 100644
--- a/gl/tests/test-fgetc.c
+++ b/gl/tests/test-fwrite.c
@@ -1,4 +1,4 @@
-/* Test of fgetc() function.
+/* Test of fwrite() function.
    Copyright (C) 2011 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -20,59 +20,68 @@
 #include <stdio.h>
 
 #include "signature.h"
-SIGNATURE_CHECK (fgetc, int, (FILE *));
+SIGNATURE_CHECK (fwrite, size_t, (const void *, size_t, size_t, FILE *));
 
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "msvc-inval.h"
+
 #include "macros.h"
 
 int
 main (int argc, char **argv)
 {
-  const char *filename = "test-fgetc.txt";
+  const char *filename = "test-fwrite.txt";
 
-  /* Prepare a file.  */
-  {
-    const char text[] = "hello world";
-    int fd = open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
-    ASSERT (fd >= 0);
-    ASSERT (write (fd, text, sizeof (text)) == sizeof (text));
-    ASSERT (close (fd) == 0);
-  }
+  /* We don't have an fwrite() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
 
-  /* Test that fgetc() sets errno if someone else closes the stream
-     fd behind the back of stdio.  */
+  /* Test that fwrite() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
   {
-    FILE *fp = fopen (filename, "r");
+    FILE *fp = fopen (filename, "w");
+    char buf[5] = "world";
     ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
     ASSERT (close (fileno (fp)) == 0);
     errno = 0;
-    ASSERT (fgetc (fp) == EOF);
+    ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
     ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
     fclose (fp);
   }
 
-  /* Test that fgetc() sets errno if the stream was constructed with
-     an invalid file descriptor.  */
+  /* Test that fwrite() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
   {
-    FILE *fp = fdopen (-1, "r");
+    FILE *fp = fdopen (-1, "w");
     if (fp != NULL)
       {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
   {
-    FILE *fp = fdopen (99, "r");
+    FILE *fp = fdopen (99, "w");
     if (fp != NULL)
       {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
         errno = 0;
-        ASSERT (fgetc (fp) == EOF);
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
index 7df1ed0..77e5675 100644
--- a/gl/unistd.in.h
+++ b/gl/unistd.in.h
@@ -83,11 +83,13 @@
 # include <stdlib.h>
 #endif
 
-/* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
-#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
+/* Native Windows platforms declare chdir, getcwd, rmdir in
+   <io.h> and/or <direct.h>, not in <unistd.h>.  */
+#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \
+      || defined GNULIB_POSIXCHECK) \
      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
 # include <io.h>     /* mingw32, mingw64 */
-# include <direct.h> /* mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
 #endif
 
 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
@@ -231,6 +233,18 @@ _GL_WARN_ON_USE (access, "the access function is a 
security risk - "
 #endif
 
 
+#if @GNULIB_CHDIR@
+_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIASWARN (chdir);
+#elif defined GNULIB_POSIXCHECK
+# undef chdir
+# if HAVE_RAW_DECL_CHDIR
+_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
+                 "use gnulib module chdir for portability");
+# endif
+#endif
+
+
 #if @GNULIB_CHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
    to GID (if GID is not -1).  Follow symbolic links.
@@ -287,16 +301,24 @@ _GL_WARN_ON_USE (close, "close does not portably work on 
sockets - "
 #endif
 
 
-#if @REPLACE_DUP@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  define dup rpl_dup
-# endif
+#if @GNULIB_DUP@
+# if @REPLACE_DUP@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define dup rpl_dup
+#  endif
 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
-#else
+# else
 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
-#endif
+# endif
 _GL_CXXALIASWARN (dup);
+#elif defined GNULIB_POSIXCHECK
+# undef dup
+# if HAVE_RAW_DECL_DUP
+_GL_WARN_ON_USE (dup, "dup is unportable - "
+                 "use gnulib module dup for portability");
+# endif
+#endif
 
 
 #if @GNULIB_DUP2@
@@ -1155,7 +1177,7 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
 /* Read up to COUNT bytes from file descriptor FD into the buffer starting
    at BUF.  See the POSIX:2008 specification
    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>.  */
-# if @REPLACE_READ@ && @GNULIB_UNISTD_H_NONBLOCKING@
+# if @REPLACE_READ@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef read
 #   define read rpl_read
@@ -1427,7 +1449,7 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
    See the POSIX:2008 specification
    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>.  */
-# if @REPLACE_WRITE@ && (@GNULIB_UNISTD_H_NONBLOCKING@ || 
@GNULIB_UNISTD_H_SIGPIPE@)
+# if @REPLACE_WRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef write
 #   define write rpl_write
diff --git a/gl/w32sock.h b/gl/w32sock.h
index 651a76d..55280d6 100644
--- a/gl/w32sock.h
+++ b/gl/w32sock.h
@@ -22,9 +22,12 @@
 /* Get O_RDWR and O_BINARY.  */
 #include <fcntl.h>
 
-/* Get _get_osfhandle() and _open_osfhandle().  */
+/* Get _open_osfhandle().  */
 #include <io.h>
 
+/* Get _get_osfhandle().  */
+#include "msvc-nothrow.h"
+
 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
 #define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
 
diff --git a/maint.mk b/maint.mk
index 0137df1..51f617b 100644
--- a/maint.mk
+++ b/maint.mk
@@ -1079,16 +1079,20 @@ sc_makefile_path_separator_check:
        halt=$(msg)                                                     \
          $(_sc_search_regexp)
 
-# Check that `make alpha' will not fail at the end of the process.
+# Check that `make alpha' will not fail at the end of the process,
+# i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release)
+# and is read-only.
 writable-files:
-       if test -d $(release_archive_dir); then :; else                 \
-         for file in $(distdir).tar.gz                                 \
-                     $(release_archive_dir)/$(distdir).tar.gz; do      \
-           test -e $$file || continue;                                 \
-           test -w $$file                                              \
-             || { echo ERROR: $$file is not writable; fail=1; };       \
+       if test -d $(release_archive_dir); then                         \
+         for file in $(DIST_ARCHIVES); do                              \
+           for p in ./ $(release_archive_dir)/; do                     \
+             test -e $$p$$file || continue;                            \
+             test -w $$p$$file                                         \
+               || { echo ERROR: $$p$$file is not writable; fail=1; };  \
+           done;                                                       \
          done;                                                         \
          test "$$fail" && exit 1 || : ;                                \
+       else :;                                                         \
        fi
 
 v_etc_file = $(gnulib_dir)/lib/version-etc.c


hooks/post-receive
-- 
GNU gnutls



reply via email to

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