gnutls-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gnutls branch, gnutls_2_12_x, updated. gnutls_2_12_11-4-gecf42


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, gnutls_2_12_x, updated. gnutls_2_12_11-4-gecf42a3
Date: Mon, 03 Oct 2011 16:29:03 +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=ecf42a3686c853bf365424cd5bc168bfed9be29b

The branch, gnutls_2_12_x has been updated
       via  ecf42a3686c853bf365424cd5bc168bfed9be29b (commit)
       via  dc1b23d925ebce0e2500b7f568cc68d3e75595d2 (commit)
       via  63fcc4002aded7fed47fe19008c3ae96a18fbbd6 (commit)
      from  1ff921d2f8e3b4a9a4ac6317e6dcdcf3f472e5f2 (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 ecf42a3686c853bf365424cd5bc168bfed9be29b
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 18:29:20 2011 +0200

    backported valgrind updates.

commit dc1b23d925ebce0e2500b7f568cc68d3e75595d2
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:58:37 2011 +0200

    fixes in unused variables.

commit 63fcc4002aded7fed47fe19008c3ae96a18fbbd6
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:46:41 2011 +0200

    Added new gnulib.

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

Summary of changes:
 .gitignore                                         |   69 ++
 NEWS                                               |    8 +
 build-aux/compile                                  |  143 +++
 build-aux/gendocs.sh                               |    4 +-
 build-aux/useless-if-before-free                   |    6 +-
 build-aux/vc-list-files                            |   89 +-
 cfg.mk                                             |   14 +-
 doc/gendocs_template                               |   31 +-
 doc/lgpl-2.1.texi                                  |   16 +-
 gl/Makefile.am                                     | 1033 +++++++++++++------
 gl/accept.c                                        |   18 +-
 gl/alignof.h                                       |    2 +-
 gl/alloca.c                                        |   31 +-
 gl/arpa_inet.in.h                                  |   48 +-
 gl/bind.c                                          |   17 +-
 gl/close-hook.c                                    |   91 --
 gl/close-hook.h                                    |   72 --
 gl/close.c                                         |   35 +-
 gl/connect.c                                       |   29 +-
 gl/errno.in.h                                      |   20 +-
 gl/error.c                                         |    8 +-
 gl/fclose.c                                        |   47 -
 gl/fd-hook.c                                       |  116 +++
 gl/fd-hook.h                                       |  119 +++
 gl/float.c                                         |   33 +
 gl/float.in.h                                      |  135 +++-
 gl/fseek.c                                         |   30 +
 gl/fseeko.c                                        |   21 +-
 gl/fstat.c                                         |   82 ++
 gl/ftell.c                                         |   37 +
 gl/gai_strerror.c                                  |   21 +-
 gl/getpass.c                                       |   94 +-
 gl/gettimeofday.c                                  |    6 +-
 gl/glthread/lock.c                                 | 1058 ++++++++++++++++++++
 gl/glthread/lock.h                                 |  927 +++++++++++++++++
 gl/glthread/threadlib.c                            |   74 ++
 gl/inet_ntop.c                                     |   39 +-
 gl/inet_pton.c                                     |   37 +-
 gl/intprops.h                                      |  303 +++++-
 gl/itold.c                                         |   28 +
 gl/listen.c                                        |   17 +-
 gl/lseek.c                                         |    2 +
 gl/m4/alloca.m4                                    |   80 ++-
 gl/m4/arpa_inet_h.m4                               |   11 +-
 gl/m4/asm-underscore.m4                            |   48 -
 gl/m4/close.m4                                     |   27 +-
 gl/m4/dup2.m4                                      |   76 ++
 gl/m4/errno_h.m4                                   |    9 +-
 gl/m4/error.m4                                     |   17 +-
 gl/m4/extensions.m4                                |    7 +-
 gl/m4/fclose.m4                                    |   16 -
 gl/m4/fcntl-o.m4                                   |   15 +-
 gl/m4/fcntl_h.m4                                   |   25 +-
 gl/m4/fdopen.m4                                    |   49 +
 gl/m4/float_h.m4                                   |   85 ++-
 {lib/gl => gl}/m4/fpieee.m4                        |    0
 {lib/gl => gl}/m4/fseek.m4                         |    0
 gl/m4/fseeko.m4                                    |   68 +-
 gl/m4/fstat.m4                                     |   28 +
 {lib/gl => gl}/m4/ftell.m4                         |    0
 gl/m4/ftello.m4                                    |   10 +-
 gl/m4/ftruncate.m4                                 |   24 +
 gl/m4/getaddrinfo.m4                               |   63 +-
 gl/m4/getcwd.m4                                    |  133 +++
 gl/m4/getdelim.m4                                  |   16 +-
 gl/m4/getline.m4                                   |    7 +-
 gl/m4/getpagesize.m4                               |    3 +-
 gl/m4/getpass.m4                                   |   34 +-
 gl/m4/gettime.m4                                   |    4 +-
 gl/m4/gettimeofday.m4                              |   19 +-
 gl/m4/gnulib-cache.m4                              |   23 +-
 gl/m4/gnulib-common.m4                             |  150 +++-
 gl/m4/gnulib-comp.m4                               |  887 +++++++++++------
 gl/m4/include_next.m4                              |   45 +-
 gl/m4/inet_ntop.m4                                 |   66 +-
 gl/m4/inet_pton.m4                                 |   66 +-
 {lib/gl => gl}/m4/inttypes-pri.m4                  |    0
 {lib/gl => gl}/m4/inttypes.m4                      |    0
 gl/m4/ioctl.m4                                     |   15 +-
 gl/m4/largefile.m4                                 |  104 ++
 {lib/gl => gl}/m4/lock.m4                          |    0
 gl/m4/lseek.m4                                     |   23 +-
 gl/m4/lstat.m4                                     |   70 ++
 gl/m4/malloc.m4                                    |   12 +-
 gl/m4/manywarnings.m4                              |  180 +++--
 gl/m4/memchr.m4                                    |   20 +-
 gl/m4/mmap-anon.m4                                 |    8 +-
 gl/m4/mode_t.m4                                    |   26 +
 gl/m4/msvc-inval.m4                                |   19 +
 gl/m4/msvc-nothrow.m4                              |   10 +
 gl/m4/netdb_h.m4                                   |    5 +-
 gl/m4/netinet_in_h.m4                              |    3 +-
 gl/m4/open.m4                                      |   92 ++
 gl/m4/pathmax.m4                                   |   42 +
 gl/m4/perror.m4                                    |   46 +-
 gl/m4/pipe.m4                                      |    3 +-
 gl/m4/printf.m4                                    |  139 +++-
 gl/m4/read-file.m4                                 |    8 +-
 gl/m4/readline.m4                                  |    7 +-
 gl/m4/realloc.m4                                   |   12 +-
 gl/m4/select.m4                                    |   32 +-
 gl/m4/signal_h.m4                                  |   83 ++
 gl/m4/snprintf.m4                                  |   13 +-
 gl/m4/socklen.m4                                   |   50 +-
 gl/m4/sockpfaf.m4                                  |   28 +-
 gl/m4/ssize_t.m4                                   |   23 +
 gl/m4/stat.m4                                      |   68 ++
 gl/m4/stdarg.m4                                    |    9 +-
 gl/m4/stdbool.m4                                   |    3 +-
 gl/m4/stddef_h.m4                                  |    6 +-
 gl/m4/stdint.m4                                    |   13 +-
 gl/m4/stdio_h.m4                                   |   86 ++-
 gl/m4/stdlib_h.m4                                  |    6 +-
 gl/m4/strerror.m4                                  |   86 +-
 gl/m4/strerror_r.m4                                |  173 ++++
 gl/m4/string_h.m4                                  |   13 +-
 gl/m4/symlink.m4                                   |   43 +
 gl/m4/sys_ioctl_h.m4                               |    9 +-
 gl/m4/sys_select_h.m4                              |   21 +-
 gl/m4/sys_socket_h.m4                              |    8 +-
 gl/m4/sys_stat_h.m4                                |    8 +-
 gl/m4/sys_time_h.m4                                |    8 +-
 gl/m4/sys_types_h.m4                               |   21 +
 {lib/gl => gl}/m4/sys_uio_h.m4                     |    0
 gl/m4/thread.m4                                    |   18 +
 {lib/gl => gl}/m4/threadlib.m4                     |    0
 gl/m4/time_h.m4                                    |    2 +-
 gl/m4/unistd_h.m4                                  |  110 ++-
 gl/m4/valgrind-tests.m4                            |    4 +-
 gl/m4/vasnprintf.m4                                |    4 +-
 gl/m4/warn-on-use.m4                               |    8 +-
 gl/m4/warnings.m4                                  |   19 +-
 {lib/gl => gl}/m4/wchar_h.m4                       |    0
 gl/m4/yield.m4                                     |   19 +
 gl/malloc.c                                        |    5 +-
 gl/msvc-inval.c                                    |  130 +++
 gl/msvc-inval.h                                    |  223 ++++
 gl/msvc-nothrow.c                                  |   50 +
 gl/msvc-nothrow.h                                  |   44 +
 gl/netdb.in.h                                      |   78 ++-
 gl/netinet_in.in.h                                 |   10 +-
 gl/override/m4/valgrind-tests.m4.diff              |   11 +
 gl/override/tests/test-lseek.c.diff                |   15 -
 gl/perror.c                                        |   20 +-
 gl/realloc.c                                       |   14 +-
 gl/recv.c                                          |   17 +-
 gl/select.c                                        |    3 +-
 gl/send.c                                          |   17 +-
 gl/setsockopt.c                                    |   31 +-
 gl/shutdown.c                                      |   17 +-
 gl/signal.in.h                                     |  447 +++++++++
 gl/sockets.c                                       |   48 +-
 gl/sockets.h                                       |    2 +
 gl/stdarg.in.h                                     |   10 +-
 gl/stddef.in.h                                     |   14 +-
 gl/stdint.in.h                                     |  110 ++-
 gl/stdio-write.c                                   |  148 ---
 gl/stdio.in.h                                      |  366 ++++++--
 gl/stdlib.in.h                                     |   65 +-
 gl/strerror-override.c                             |  279 +++++
 gl/strerror-override.h                             |   52 +
 gl/strerror.c                                      |  358 +------
 gl/strerror_r.c                                    |  327 ++++++
 gl/string.in.h                                     |   59 +-
 gl/sys_select.in.h                                 |  194 ++++-
 gl/sys_socket.in.h                                 |   87 +-
 gl/sys_stat.in.h                                   |   58 +-
 gl/sys_time.in.h                                   |  105 ++-
 gl/sys_types.in.h                                  |   40 +
 gl/sys_uio.in.h                                    |   64 ++
 gl/tests/Makefile.am                               |  674 +++++++++++--
 gl/tests/dosname.h                                 |   53 +
 gl/tests/dummy.c                                   |   42 -
 gl/tests/dup2.c                                    |  157 +++
 gl/tests/fcntl.in.h                                |   31 +-
 gl/tests/fdopen.c                                  |   69 ++
 {lib/gl => gl}/tests/fpucw.h                       |    0
 gl/tests/ftruncate.c                               |   43 +
 gl/tests/getcwd-lgpl.c                             |  125 +++
 gl/tests/glthread/thread.c                         |  232 +++++
 gl/tests/glthread/thread.h                         |  400 ++++++++
 gl/tests/glthread/yield.h                          |  121 +++
 gl/tests/ignore-value.h                            |   62 ++
 gl/tests/init.sh                                   |   31 +-
 {lib/gl => gl}/tests/inttypes.in.h                 |    0
 gl/tests/ioctl.c                                   |   43 +-
 gl/tests/lstat.c                                   |   97 ++
 gl/tests/macros.h                                  |    4 +
 gl/tests/open.c                                    |  181 ++++
 gl/tests/pathmax.h                                 |   84 ++
 gl/tests/pipe.c                                    |   11 +-
 gl/tests/same-inode.h                              |   25 +
 gl/tests/stat.c                                    |  123 +++
 gl/tests/symlink.c                                 |   57 ++
 gl/tests/sys_ioctl.in.h                            |   10 +-
 gl/tests/test-accept.c                             |   54 +
 gl/tests/test-bind.c                               |   56 +
 gl/tests/test-close.c                              |   44 +
 gl/tests/test-connect.c                            |   58 ++
 gl/tests/test-dup2.c                               |  203 ++++
 gl/tests/test-fcntl-h.c                            |   87 ++-
 gl/tests/test-fdopen.c                             |   54 +
 gl/tests/test-fgetc.c                              |   96 ++
 gl/tests/test-float.c                              |  391 ++++++++
 gl/tests/test-fputc.c                              |   90 ++
 gl/tests/test-fread.c                              |   99 ++
 {lib/gl => gl}/tests/test-fseek.c                  |    0
 {lib/gl => gl}/tests/test-fseek.sh                 |    0
 {lib/gl => gl}/tests/test-fseek2.sh                |    0
 {lib/gl => gl}/tests/test-fseeko3.c                |    0
 {lib/gl => gl}/tests/test-fseeko3.sh               |    0
 gl/tests/test-fseeko4.c                            |   71 ++
 gl/tests/test-fseeko4.sh                           |    5 +
 gl/tests/test-fstat.c                              |   48 +
 {lib/gl => gl}/tests/test-ftell.c                  |    0
 {lib/gl => gl}/tests/test-ftell.sh                 |    0
 {lib/gl => gl}/tests/test-ftell2.sh                |    0
 {lib/gl => gl}/tests/test-ftell3.c                 |    0
 gl/tests/test-ftello4.c                            |   68 ++
 gl/tests/test-ftello4.sh                           |    5 +
 gl/tests/test-ftruncate.c                          |   59 ++
 gl/tests/test-ftruncate.sh                         |    3 +
 gl/tests/test-fwrite.c                             |   93 ++
 gl/tests/test-getaddrinfo.c                        |    2 +-
 gl/tests/test-getcwd-lgpl.c                        |  102 ++
 gl/tests/test-ignore-value.c                       |   84 ++
 {lib/gl => gl}/tests/test-intprops.c               |    0
 {lib/gl => gl}/tests/test-inttypes.c               |    0
 gl/tests/test-ioctl.c                              |   49 +
 gl/tests/test-listen.c                             |   47 +
 gl/tests/test-lock.c                               |  601 +++++++++++
 gl/tests/test-lseek.c                              |   18 +-
 gl/tests/test-lstat.c                              |   60 ++
 gl/tests/test-lstat.h                              |  116 +++
 gl/tests/test-open.c                               |   41 +
 gl/tests/test-open.h                               |   93 ++
 gl/tests/test-pathmax.c                            |   32 +
 gl/tests/test-perror.sh                            |   33 +-
 gl/tests/test-perror2.c                            |  137 +++
 gl/tests/test-pipe.c                               |    2 +
 gl/tests/test-recv.c                               |   49 +
 gl/tests/test-select.c                             |  369 +-------
 gl/tests/test-select.h                             |  436 ++++++++
 gl/tests/test-send.c                               |   49 +
 gl/tests/test-setsockopt.c                         |   53 +
 gl/tests/test-shutdown.c                           |   47 +
 gl/tests/test-signal-h.c                           |  129 +++
 gl/tests/test-snprintf.c                           |    8 +
 gl/tests/test-stat.c                               |   55 +
 gl/tests/test-stat.h                               |  100 ++
 gl/tests/test-strerror.c                           |   21 +-
 gl/tests/test-strerror_r.c                         |  182 ++++
 gl/tests/test-symlink.c                            |   47 +
 gl/tests/test-symlink.h                            |   95 ++
 gl/tests/test-sys_select.c                         |   20 +
 gl/tests/test-sys_socket.c                         |   18 +-
 gl/tests/test-sys_stat.c                           |   45 +-
 gl/tests/test-sys_types.c                          |   34 +
 {lib/gl => gl}/tests/test-sys_uio.c                |    0
 gl/tests/test-thread_create.c                      |   78 ++
 gl/tests/test-thread_self.c                        |   34 +
 gl/tests/test-time.c                               |    8 +-
 gl/tests/test-update-copyright.sh                  |    3 -
 gl/tests/test-verify.c                             |    4 +-
 {lib/gl => gl}/tests/test-wchar.c                  |    0
 gl/tests/w32sock.h                                 |    5 +-
 gl/time.in.h                                       |    4 +-
 gl/timespec.h                                      |   19 +
 gl/unistd.in.h                                     |  326 ++++---
 gl/vasnprintf.c                                    |    6 +-
 gl/verify.h                                        |  146 +++-
 gl/w32sock.h                                       |    5 +-
 gl/wchar.in.h                                      | 1006 +++++++++++++++++++
 lib/auth_srp.c                                     |    3 +-
 lib/build-aux/config.rpath                         |  136 ++-
 {build-aux => lib/build-aux}/snippet/_Noreturn.h   |    0
 {build-aux => lib/build-aux/snippet}/arg-nonnull.h |    0
 {build-aux => lib/build-aux/snippet}/c++defs.h     |    0
 {build-aux => lib/build-aux/snippet}/warn-on-use.h |    0
 lib/ext_session_ticket.c                           |    3 +-
 lib/gl/Makefile.am                                 |   88 ++-
 lib/gl/float.c                                     |    2 +-
 lib/gl/float.in.h                                  |   16 +-
 lib/gl/fstat.c                                     |   82 ++
 lib/gl/itold.c                                     |   28 +
 lib/gl/lseek.c                                     |    2 +
 lib/gl/m4/fcntl-o.m4                               |   15 +-
 lib/gl/m4/fcntl_h.m4                               |    8 +-
 lib/gl/m4/fdopen.m4                                |   49 +
 lib/gl/m4/float_h.m4                               |   53 +-
 lib/gl/m4/fstat.m4                                 |   28 +
 lib/gl/m4/gnulib-cache.m4                          |   20 +-
 lib/gl/m4/gnulib-common.m4                         |   72 ++-
 lib/gl/m4/gnulib-comp.m4                           |   84 ++-
 lib/gl/m4/iconv.m4                                 |    4 +-
 lib/gl/m4/include_next.m4                          |   33 +-
 lib/gl/m4/largefile.m4                             |   20 +-
 lib/gl/m4/lseek.m4                                 |   10 +-
 lib/gl/m4/msvc-inval.m4                            |   19 +
 lib/gl/m4/msvc-nothrow.m4                          |   10 +
 lib/gl/m4/printf.m4                                |  126 ++-
 lib/gl/m4/ssize_t.m4                               |   23 +
 lib/gl/m4/stdint.m4                                |    8 +
 lib/gl/m4/stdio_h.m4                               |    9 +-
 lib/gl/m4/strings_h.m4                             |    9 +-
 lib/gl/m4/sys_stat_h.m4                            |    8 +-
 lib/gl/m4/sys_types_h.m4                           |   21 +
 lib/gl/m4/time_h.m4                                |    2 +-
 lib/gl/m4/unistd_h.m4                              |   19 +-
 lib/gl/m4/vasnprintf.m4                            |    4 +-
 lib/gl/msvc-inval.c                                |  130 +++
 lib/gl/msvc-inval.h                                |  223 ++++
 lib/gl/msvc-nothrow.c                              |   50 +
 lib/gl/msvc-nothrow.h                              |   44 +
 lib/gl/sockets.c                                   |    1 +
 lib/gl/sockets.h                                   |    2 +
 lib/gl/stdio.in.h                                  |   38 +
 lib/gl/strings.in.h                                |    9 +-
 lib/gl/sys_stat.in.h                               |   32 +-
 lib/gl/sys_types.in.h                              |   40 +
 lib/gl/sys_uio.in.h                                |    2 +-
 lib/gl/tests/Makefile.am                           |   97 ++-
 lib/gl/tests/fdopen.c                              |   69 ++
 lib/gl/tests/init.sh                               |   19 +-
 lib/gl/tests/test-fcntl-h.c                        |    5 +
 lib/gl/tests/test-fdopen.c                         |   54 +
 lib/gl/tests/test-fgetc.c                          |   96 ++
 lib/gl/tests/test-float.c                          |    9 +-
 lib/gl/tests/test-fputc.c                          |   90 ++
 lib/gl/tests/test-fread.c                          |   99 ++
 lib/gl/tests/test-fseeko4.c                        |   71 ++
 lib/gl/tests/test-fseeko4.sh                       |    5 +
 lib/gl/tests/test-fstat.c                          |   48 +
 lib/gl/tests/test-ftello4.c                        |   68 ++
 lib/gl/tests/test-ftello4.sh                       |    5 +
 lib/gl/tests/test-fwrite.c                         |   93 ++
 lib/gl/tests/test-sys_socket.c                     |    4 +
 lib/gl/tests/test-sys_stat.c                       |   45 +-
 lib/gl/tests/test-sys_types.c                      |   34 +
 lib/gl/tests/test-time.c                           |    8 +-
 lib/gl/unistd.in.h                                 |  137 ++-
 lib/gl/w32sock.h                                   |    5 +-
 lib/gl/wchar.in.h                                  |   12 +
 lib/gnutls_compress.c                              |    6 +-
 lib/x509/common.c                                  |    3 -
 libextra/gl/gnulib.mk                              |   37 +-
 libextra/gl/hmac-md5.c                             |    4 +-
 libextra/gl/m4/extensions.m4                       |    7 +-
 libextra/gl/m4/gnulib-cache.m4                     |   23 +-
 libextra/gl/m4/gnulib-common.m4                    |  150 +++-
 libextra/gl/m4/gnulib-comp.m4                      |   39 +-
 libextra/gl/m4/hmac-md5.m4                         |   10 -
 libextra/gl/m4/md5.m4                              |    4 +-
 libextra/gl/m4/memxor.m4                           |    3 +-
 libextra/gl/memxor.c                               |    2 +-
 libextra/gl/memxor.h                               |    2 +-
 maint.mk                                           |  369 ++++++--
 tests/Makefile.am                                  |    2 +-
 tests/safe-renegotiation/Makefile.am               |    2 +-
 .../safe-renegotiation/suppressions.valgrind       |    0
 tests/{libgcrypt.supp => suppressions.valgrind}    |    0
 361 files changed, 21280 insertions(+), 3595 deletions(-)
 create mode 100755 build-aux/compile
 delete mode 100644 gl/close-hook.c
 delete mode 100644 gl/close-hook.h
 delete mode 100644 gl/fclose.c
 create mode 100644 gl/fd-hook.c
 create mode 100644 gl/fd-hook.h
 create mode 100644 gl/float.c
 create mode 100644 gl/fseek.c
 create mode 100644 gl/fstat.c
 create mode 100644 gl/ftell.c
 create mode 100644 gl/glthread/lock.c
 create mode 100644 gl/glthread/lock.h
 create mode 100644 gl/glthread/threadlib.c
 create mode 100644 gl/itold.c
 delete mode 100644 gl/m4/asm-underscore.m4
 create mode 100644 gl/m4/dup2.m4
 delete mode 100644 gl/m4/fclose.m4
 create mode 100644 gl/m4/fdopen.m4
 copy {lib/gl => gl}/m4/fpieee.m4 (100%)
 copy {lib/gl => gl}/m4/fseek.m4 (100%)
 create mode 100644 gl/m4/fstat.m4
 copy {lib/gl => gl}/m4/ftell.m4 (100%)
 create mode 100644 gl/m4/ftruncate.m4
 create mode 100644 gl/m4/getcwd.m4
 copy {lib/gl => gl}/m4/inttypes-pri.m4 (100%)
 copy {lib/gl => gl}/m4/inttypes.m4 (100%)
 create mode 100644 gl/m4/largefile.m4
 copy {lib/gl => gl}/m4/lock.m4 (100%)
 create mode 100644 gl/m4/lstat.m4
 create mode 100644 gl/m4/mode_t.m4
 create mode 100644 gl/m4/msvc-inval.m4
 create mode 100644 gl/m4/msvc-nothrow.m4
 create mode 100644 gl/m4/open.m4
 create mode 100644 gl/m4/pathmax.m4
 create mode 100644 gl/m4/signal_h.m4
 create mode 100644 gl/m4/ssize_t.m4
 create mode 100644 gl/m4/stat.m4
 create mode 100644 gl/m4/strerror_r.m4
 create mode 100644 gl/m4/symlink.m4
 create mode 100644 gl/m4/sys_types_h.m4
 copy {lib/gl => gl}/m4/sys_uio_h.m4 (100%)
 create mode 100644 gl/m4/thread.m4
 copy {lib/gl => gl}/m4/threadlib.m4 (100%)
 copy {lib/gl => gl}/m4/wchar_h.m4 (100%)
 create mode 100644 gl/m4/yield.m4
 create mode 100644 gl/msvc-inval.c
 create mode 100644 gl/msvc-inval.h
 create mode 100644 gl/msvc-nothrow.c
 create mode 100644 gl/msvc-nothrow.h
 create mode 100644 gl/override/m4/valgrind-tests.m4.diff
 delete mode 100644 gl/override/tests/test-lseek.c.diff
 create mode 100644 gl/signal.in.h
 delete mode 100644 gl/stdio-write.c
 create mode 100644 gl/strerror-override.c
 create mode 100644 gl/strerror-override.h
 create mode 100644 gl/strerror_r.c
 create mode 100644 gl/sys_types.in.h
 create mode 100644 gl/sys_uio.in.h
 create mode 100644 gl/tests/dosname.h
 delete mode 100644 gl/tests/dummy.c
 create mode 100644 gl/tests/dup2.c
 create mode 100644 gl/tests/fdopen.c
 copy {lib/gl => gl}/tests/fpucw.h (100%)
 create mode 100644 gl/tests/ftruncate.c
 create mode 100644 gl/tests/getcwd-lgpl.c
 create mode 100644 gl/tests/glthread/thread.c
 create mode 100644 gl/tests/glthread/thread.h
 create mode 100644 gl/tests/glthread/yield.h
 create mode 100644 gl/tests/ignore-value.h
 copy {lib/gl => gl}/tests/inttypes.in.h (100%)
 create mode 100644 gl/tests/lstat.c
 create mode 100644 gl/tests/open.c
 create mode 100644 gl/tests/pathmax.h
 create mode 100644 gl/tests/same-inode.h
 create mode 100644 gl/tests/stat.c
 create mode 100644 gl/tests/symlink.c
 create mode 100644 gl/tests/test-accept.c
 create mode 100644 gl/tests/test-bind.c
 create mode 100644 gl/tests/test-close.c
 create mode 100644 gl/tests/test-connect.c
 create mode 100644 gl/tests/test-dup2.c
 create mode 100644 gl/tests/test-fdopen.c
 create mode 100644 gl/tests/test-fgetc.c
 create mode 100644 gl/tests/test-float.c
 create mode 100644 gl/tests/test-fputc.c
 create mode 100644 gl/tests/test-fread.c
 copy {lib/gl => gl}/tests/test-fseek.c (100%)
 copy {lib/gl => gl}/tests/test-fseek.sh (100%)
 copy {lib/gl => gl}/tests/test-fseek2.sh (100%)
 copy {lib/gl => gl}/tests/test-fseeko3.c (100%)
 copy {lib/gl => gl}/tests/test-fseeko3.sh (100%)
 create mode 100644 gl/tests/test-fseeko4.c
 create mode 100755 gl/tests/test-fseeko4.sh
 create mode 100644 gl/tests/test-fstat.c
 copy {lib/gl => gl}/tests/test-ftell.c (100%)
 copy {lib/gl => gl}/tests/test-ftell.sh (100%)
 copy {lib/gl => gl}/tests/test-ftell2.sh (100%)
 copy {lib/gl => gl}/tests/test-ftell3.c (100%)
 create mode 100644 gl/tests/test-ftello4.c
 create mode 100755 gl/tests/test-ftello4.sh
 create mode 100644 gl/tests/test-ftruncate.c
 create mode 100755 gl/tests/test-ftruncate.sh
 create mode 100644 gl/tests/test-fwrite.c
 create mode 100644 gl/tests/test-getcwd-lgpl.c
 create mode 100644 gl/tests/test-ignore-value.c
 copy {lib/gl => gl}/tests/test-intprops.c (100%)
 copy {lib/gl => gl}/tests/test-inttypes.c (100%)
 create mode 100644 gl/tests/test-ioctl.c
 create mode 100644 gl/tests/test-listen.c
 create mode 100644 gl/tests/test-lock.c
 create mode 100644 gl/tests/test-lstat.c
 create mode 100644 gl/tests/test-lstat.h
 create mode 100644 gl/tests/test-open.c
 create mode 100644 gl/tests/test-open.h
 create mode 100644 gl/tests/test-pathmax.c
 create mode 100644 gl/tests/test-perror2.c
 create mode 100644 gl/tests/test-recv.c
 create mode 100644 gl/tests/test-select.h
 create mode 100644 gl/tests/test-send.c
 create mode 100644 gl/tests/test-setsockopt.c
 create mode 100644 gl/tests/test-shutdown.c
 create mode 100644 gl/tests/test-signal-h.c
 create mode 100644 gl/tests/test-stat.c
 create mode 100644 gl/tests/test-stat.h
 create mode 100644 gl/tests/test-strerror_r.c
 create mode 100644 gl/tests/test-symlink.c
 create mode 100644 gl/tests/test-symlink.h
 create mode 100644 gl/tests/test-sys_types.c
 copy {lib/gl => gl}/tests/test-sys_uio.c (100%)
 create mode 100644 gl/tests/test-thread_create.c
 create mode 100644 gl/tests/test-thread_self.c
 copy {lib/gl => gl}/tests/test-wchar.c (100%)
 create mode 100644 gl/wchar.in.h
 copy {build-aux => lib/build-aux}/snippet/_Noreturn.h (100%)
 rename {build-aux => lib/build-aux/snippet}/arg-nonnull.h (100%)
 rename {build-aux => lib/build-aux/snippet}/c++defs.h (100%)
 rename {build-aux => lib/build-aux/snippet}/warn-on-use.h (100%)
 create mode 100644 lib/gl/fstat.c
 create mode 100644 lib/gl/itold.c
 create mode 100644 lib/gl/m4/fdopen.m4
 create mode 100644 lib/gl/m4/fstat.m4
 create mode 100644 lib/gl/m4/msvc-inval.m4
 create mode 100644 lib/gl/m4/msvc-nothrow.m4
 create mode 100644 lib/gl/m4/ssize_t.m4
 create mode 100644 lib/gl/m4/sys_types_h.m4
 create mode 100644 lib/gl/msvc-inval.c
 create mode 100644 lib/gl/msvc-inval.h
 create mode 100644 lib/gl/msvc-nothrow.c
 create mode 100644 lib/gl/msvc-nothrow.h
 create mode 100644 lib/gl/sys_types.in.h
 create mode 100644 lib/gl/tests/fdopen.c
 create mode 100644 lib/gl/tests/test-fdopen.c
 create mode 100644 lib/gl/tests/test-fgetc.c
 create mode 100644 lib/gl/tests/test-fputc.c
 create mode 100644 lib/gl/tests/test-fread.c
 create mode 100644 lib/gl/tests/test-fseeko4.c
 create mode 100755 lib/gl/tests/test-fseeko4.sh
 create mode 100644 lib/gl/tests/test-fstat.c
 create mode 100644 lib/gl/tests/test-ftello4.c
 create mode 100755 lib/gl/tests/test-ftello4.sh
 create mode 100644 lib/gl/tests/test-fwrite.c
 create mode 100644 lib/gl/tests/test-sys_types.c
 delete mode 100644 libextra/gl/m4/hmac-md5.m4
 copy doc/reference/gnutls.types => 
tests/safe-renegotiation/suppressions.valgrind (100%)
 rename tests/{libgcrypt.supp => suppressions.valgrind} (100%)

diff --git a/.gitignore b/.gitignore
index d286453..eefc468 100644
--- a/.gitignore
+++ b/.gitignore
@@ -490,3 +490,72 @@ tests/x509paths/
 tests/x509self
 tests/x509sign-verify
 tests/x509signself
+doc/examples/ex-cert-select-pkcs11
+.dirstamp
+gl/signal.h
+gl/tests/inttypes.h
+gl/tests/test-accept
+gl/tests/test-bind
+gl/tests/test-close
+gl/tests/test-connect
+gl/tests/test-dup2
+gl/tests/test-fcntl-h
+gl/tests/test-fdopen
+gl/tests/test-fgetc
+gl/tests/test-float
+gl/tests/test-fputc
+gl/tests/test-fread
+gl/tests/test-fseek
+gl/tests/test-fseeko3
+gl/tests/test-fseeko4
+gl/tests/test-fstat
+gl/tests/test-ftell
+gl/tests/test-ftell3
+gl/tests/test-ftello4
+gl/tests/test-ftruncate
+gl/tests/test-fwrite
+gl/tests/test-getcwd-lgpl
+gl/tests/test-ignore-value
+gl/tests/test-intprops
+gl/tests/test-inttypes
+gl/tests/test-ioctl
+gl/tests/test-listen
+gl/tests/test-lock
+gl/tests/test-lstat
+gl/tests/test-open
+gl/tests/test-pathmax
+gl/tests/test-perror2
+gl/tests/test-pipe
+gl/tests/test-recv
+gl/tests/test-send
+gl/tests/test-setsockopt
+gl/tests/test-shutdown
+gl/tests/test-signal-h
+gl/tests/test-stat
+gl/tests/test-strerror_r
+gl/tests/test-symlink
+gl/tests/test-sys_types
+gl/tests/test-sys_uio
+gl/tests/test-thread_create
+gl/tests/test-thread_self
+lib/gl/tests/inttypes.h
+lib/gl/tests/test-fcntl-h
+lib/gl/tests/test-fdopen
+lib/gl/tests/test-fgetc
+lib/gl/tests/test-float
+lib/gl/tests/test-fputc
+lib/gl/tests/test-fread
+lib/gl/tests/test-fseek
+lib/gl/tests/test-fseeko3
+lib/gl/tests/test-fseeko4
+lib/gl/tests/test-fstat
+lib/gl/tests/test-ftell
+lib/gl/tests/test-ftell3
+lib/gl/tests/test-ftello4
+lib/gl/tests/test-fwrite
+lib/gl/tests/test-intprops
+lib/gl/tests/test-inttypes
+lib/gl/tests/test-sys_types
+lib/gl/tests/test-sys_uio
+tests/rng-fork
+tests/x509cert
diff --git a/NEWS b/NEWS
index 035ae47..9bbbe40 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,14 @@ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
               2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 See the end for copying conditions.
 
+Version 2.12.12 (unreleased)
+
+** gnulib: updated
+
+** API and ABI modifications:
+No changes since last version.
+
+
 Version 2.12.11 (released 2011-09-18)
 
 ** libgnutls: Memory leak fixes in credentials private key 
diff --git a/build-aux/compile b/build-aux/compile
new file mode 100755
index 0000000..c0096a7
--- /dev/null
+++ b/build-aux/compile
@@ -0,0 +1,143 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand `-c -o'.
+
+scriptversion=2009-10-06.20; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
+# Foundation, Inc.
+# Written by Tom Tromey <address@hidden>.
+#
+# 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 2, 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/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <address@hidden> or send patches to
+# <address@hidden>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand `-c -o'.
+Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file `INSTALL'.
+
+Report bugs to <address@hidden>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit $?
+    ;;
+esac
+
+ofile=
+cfile=
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+       # configure might choose to run compile as `compile cc -o foo foo.c'.
+       # So we strip `-o arg' only if arg is an object.
+       eat=1
+       case $2 in
+         *.o | *.obj)
+           ofile=$2
+           ;;
+         *)
+           set x "$@" -o "$2"
+           shift
+           ;;
+       esac
+       ;;
+      *.c)
+       cfile=$1
+       set x "$@" "$1"
+       shift
+       ;;
+      *)
+       set x "$@" "$1"
+       shift
+       ;;
+    esac
+  fi
+  shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+  # If no `-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # `.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use `[/\\:.-]' here to ensure that we don't use the same name
+# that we are using for the .o file.  Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
+while true; do
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/build-aux/gendocs.sh b/build-aux/gendocs.sh
index 34ef112..c8abd55 100755
--- a/build-aux/gendocs.sh
+++ b/build-aux/gendocs.sh
@@ -2,7 +2,7 @@
 # gendocs.sh -- generate a GNU manual in many formats.  This script is
 #   mentioned in maintain.texi.  See the help message below for usage details.
 
-scriptversion=2010-11-29.11
+scriptversion=2011-04-08.14
 
 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
 # Foundation, Inc.
@@ -305,10 +305,10 @@ if test -n "$docbook"; then
   docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
   mv $PACKAGE-db.xml "$outdir/"
 
+  split_html_db_dir=html_node_db
   cmd="${DOCBOOK2HTML} -o $split_html_db_dir \"${outdir}/$PACKAGE-db.xml\""
   echo "Generating docbook HTML... ($cmd)"
   eval "$cmd"
-  split_html_db_dir=html_node_db
   (
     cd ${split_html_db_dir} || exit 1
     tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index a6c228b..b8f5a26 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -4,7 +4,7 @@ eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
 # Detect instances of "if (p) free (p);".
 # Likewise "if (p != 0)", "if (0 != p)", or with NULL; and with braces.
 
-my $VERSION = '2011-01-09 01:39'; # UTC
+my $VERSION = '2011-04-20 13:43'; # UTC
 # The definition above must lie within the first 8 lines in order
 # for the Emacs time-stamp write hook (at end) to update it.
 # If you change this file with Emacs, please let the write hook
@@ -132,7 +132,7 @@ sub is_NULL ($)
           while ($line =~
               /\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\)
               #  1          2                  3
-               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)|
+               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;|
                 
\s*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg)
             {
               my $all = $1;
@@ -179,7 +179,7 @@ free=xfree
 git grep -l -z "$free *(" \
   | xargs -0 useless-if-before-free -l --name="$free" \
   | xargs -0 perl -0x3b -pi -e \
-   
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s'
+   
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\)\s*;)/$2/s'
 
 # Use the following to remove redundant uses of kfree inside braces.
 # Note that -0777 puts perl in slurp-whole-file mode;
diff --git a/build-aux/vc-list-files b/build-aux/vc-list-files
index 9bb6fe6..405e458 100755
--- a/build-aux/vc-list-files
+++ b/build-aux/vc-list-files
@@ -2,7 +2,7 @@
 # List version-controlled file names.
 
 # Print a version string.
-scriptversion=2010-04-23.22; # UTC
+scriptversion=2011-05-16.22; # UTC
 
 # Copyright (C) 2006-2011 Free Software Foundation, Inc.
 
@@ -30,7 +30,7 @@ scriptversion=2010-04-23.22; # UTC
 postprocess=
 case $1 in
   --help) cat <<EOF
-Usage: $0 [-C SRCDIR] [DIR]
+Usage: $0 [-C SRCDIR] [DIR...]
 
 Output a list of version-controlled files in DIR (default .), relative to
 SRCDIR (default .).  SRCDIR must be the top directory of a checkout.
@@ -61,53 +61,48 @@ EOF
     shift; shift ;;
 esac
 
-dir=
-case $# in
-  0) ;;
-  1) dir=$1 ;;
-  *) echo "$0: too many arguments" 1>&2
-     echo "Usage: $0 [-C srcdir] [DIR]" 1>&2; exit 1;;
-esac
-
-test "x$dir" = x && dir=.
-
-if test -d .git; then
-  test "x$dir" = x. \
-    && dir= sed_esc= \
-    || { dir="$dir/"; sed_esc=`echo "$dir"|env sed 's,\([\\/]\),\\\\\1,g'`; }
-  # Ignore git symlinks - either they point into the tree, in which case
-  # we don't need to visit the target twice, or they point somewhere
-  # else (often into a submodule), in which case the content does not
-  # belong to this package.
-  eval exec git ls-tree -r 'HEAD:"$dir"' \
-    \| sed -n '"s/^100[^       ]*./$sed_esc/p"' $postprocess
-elif test -d .hg; then
-  eval exec hg locate '"$dir/*"' $postprocess
-elif test -d .bzr; then
-  test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
-  eval exec bzr ls -R --versioned '"$dir"' $postprocess
-elif test -d CVS; then
-  test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
-  if test -x build-aux/cvsu; then
-    eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
-  elif (cvsu --help) >/dev/null 2>&1; then
-    eval cvsu --find --types=AFGM '"$dir"' $postprocess
+test $# = 0 && set .
+
+for dir
+do
+  if test -d .git; then
+    test "x$dir" = x. \
+      && dir= sed_esc= \
+      || { dir="$dir/"; sed_esc=`echo "$dir"|env sed 's,\([\\/]\),\\\\\1,g'`; }
+    # Ignore git symlinks - either they point into the tree, in which case
+    # we don't need to visit the target twice, or they point somewhere
+    # else (often into a submodule), in which case the content does not
+    # belong to this package.
+    eval exec git ls-tree -r 'HEAD:"$dir"' \
+      \| sed -n '"s/^100[^     ]*./$sed_esc/p"' $postprocess
+  elif test -d .hg; then
+    eval exec hg locate '"$dir/*"' $postprocess
+  elif test -d .bzr; then
+    test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
+    eval exec bzr ls -R --versioned '"$dir"' $postprocess
+  elif test -d CVS; then
+    test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
+    if test -x build-aux/cvsu; then
+      eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
+    elif (cvsu --help) >/dev/null 2>&1; then
+      eval cvsu --find --types=AFGM '"$dir"' $postprocess
+    else
+      eval awk -F/ \''{                        \
+          if (!$1 && $3 !~ /^-/) {     \
+            f=FILENAME;                        \
+            if (f ~ /CVS\/Entries$/)   \
+              f = substr(f, 1, length(f)-11); \
+            print f $2;                        \
+          }}'\''                               \
+        `find "$dir" -name Entries -print` /dev/null' $postprocess
+    fi
+  elif test -d .svn; then
+    eval exec svn list -R '"$dir"' $postprocess
   else
-    eval awk -F/ \''{                  \
-       if (!$1 && $3 !~ /^-/) {        \
-         f=FILENAME;                   \
-         if (f ~ /CVS\/Entries$/)      \
-           f = substr(f, 1, length(f)-11); \
-         print f $2;                   \
-       }}'\''                          \
-      `find "$dir" -name Entries -print` /dev/null' $postprocess
+    echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
+    exit 1
   fi
-elif test -d .svn; then
-  eval exec svn list -R '"$dir"' $postprocess
-else
-  echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
-  exit 1
-fi
+done
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
diff --git a/cfg.mk b/cfg.mk
index 20d6dd7..f3b41b2 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -63,17 +63,9 @@ bootstrap: autoreconf
 #Two runs the first should add the LGPL components and the
 #second the components used by src/ files.
 glimport:
-       gnulib-tool --m4-base gl/m4 --tests-base=gl/tests --libtool \
-       --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl \
-       --aux-dir=build-aux --with-tests --avoid=alignof-tests 
--avoid=lseek-tests \
-       --import crypto/hmac-md5 crypto/md5 extensions havelib lib-msvc-compat 
lib-symbol-versions \
-       byteswap c-ctype func gettext lib-msvc-compat lib-symbol-versions 
memmem-simple minmax \
-       netdb read-file snprintf sockets socklen stdint strcase strverscmp 
sys_socket sys_stat time_r unistd \
-       vasprintf vsnprintf manywarnings warnings netinet_in alloca getpass u64
-       gnulib-tool --m4-base gl/m4 --tests-base=gl/tests --libtool \
-       --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl \
-       --aux-dir=build-aux --with-tests --avoid=alignof-tests 
--avoid=lseek-tests \
-       --add-import progname version-etc timespec version-etc-fsf gettime 
valgrind-tests
+       gnulib-tool --m4-base gl/m4 --add-import
+       cd lib && gnulib-tool --m4-base gl/m4 --add-import
+       cd libextra && gnulib-tool --m4-base gl/m4 --add-import
 
 # Code Coverage
 
diff --git a/doc/gendocs_template b/doc/gendocs_template
index 5c860fd..4120d03 100644
--- a/doc/gendocs_template
+++ b/doc/gendocs_template
@@ -3,12 +3,6 @@
 <!--#include virtual="/server/banner.html" -->
 <h2>%%TITLE%%</h2>
 
-<!-- This document is in XML, and xhtml 1.0 -->
-<!-- Please make sure to properly nest your tags -->
-<!-- and ensure that your final document validates -->
-<!-- consistent with W3C xhtml 1.0 and CSS standards -->
-<!-- See validator.w3.org -->
-
 <address>Free Software Foundation</address>
 <address>last updated %%DATE%%</address>
 
@@ -73,29 +67,28 @@ this helps support FSF activities.</p>
 <p>(This page generated by the <a href="%%SCRIPTURL%%">%%SCRIPTNAME%%
 script</a>.)</p>
 
-<!-- If needed, change the copyright block at the bottom. In general, -->
-<!-- all pages on the GNU web server should have the section about    -->
-<!-- verbatim copying.  Please do NOT remove this without talking     -->
-<!-- with the webmasters first. -->
-<!-- Please make sure the copyright date is consistent with the document -->
-<!-- and that it is like this "2001, 2002" not this "2001-2002." -->
+<!-- If needed, change the copyright block at the bottom. In general,
+     all pages on the GNU web server should have the section about
+     verbatim copying.  Please do NOT remove this without talking
+     with the webmasters first.
+     Please make sure the copyright date is consistent with the document
+     and that it is like this: "2001, 2002", not this: "2001-2002". -->
 </div><!-- for id="content", starts in the include above -->
 <!--#include virtual="/server/footer.html" -->
 <div id="footer">
 
-<p>
-Please send FSF &amp; GNU inquiries to
+<p>Please send general FSF &amp; GNU inquiries to
 <a href="mailto:address@hidden";>&lt;address@hidden&gt;</a>.
 There are also <a href="/contact/">other ways to contact</a>
 the FSF.<br />
 Please send broken links and other corrections or suggestions to
-<a href="mailto:%%EMAIL%%";>&lt;%%EMAIL%%&gt;</a>.
-</p>
+<a href="mailto:%%EMAIL%%";>&lt;%%EMAIL%%&gt;</a>.</p>
 
-<p>Copyright &copy; 2010 Free Software Foundation, Inc.</p>
+<p>Copyright &copy; 2011 Free Software Foundation, Inc.</p>
 
-<p>Verbatim copying and distribution of this entire article is
-permitted in any medium, provided this notice is preserved.</p>
+<p>Verbatim copying and distribution of this entire article are
+permitted worldwide, without royalty, in any medium, provided this
+notice, and the copyright notice, are preserved.</p>
 
 </div>
 </div>
diff --git a/doc/lgpl-2.1.texi b/doc/lgpl-2.1.texi
index a2ba64b..ab03d6c 100644
--- a/doc/lgpl-2.1.texi
+++ b/doc/lgpl-2.1.texi
@@ -470,13 +470,7 @@ decision will be guided by the two goals of preserving the 
free status
 of all derivatives of our free software and of promoting the sharing
 and reuse of software generally.
 
address@hidden
address@hidden NO WARRANTY
address@hidden iftex
address@hidden
address@hidden NO WARRANTY
-
address@hidden ifinfo
address@hidden @b{NO WARRANTY}
 
 @item
 BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
@@ -502,13 +496,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 
POSSIBILITY OF SUCH
 DAMAGES.
 @end enumerate
 
address@hidden
address@hidden END OF TERMS AND CONDITIONS
address@hidden iftex
address@hidden
address@hidden END OF TERMS AND CONDITIONS
-
address@hidden ifinfo
address@hidden END OF TERMS AND CONDITIONS
 
 @page
 @subheading How to Apply These Terms to Your New Libraries
diff --git a/gl/Makefile.am b/gl/Makefile.am
index d70be60..5975f81 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -2,16 +2,28 @@
 ## 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.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --with-tests --libtool 
--macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect 
error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gettime gnupload gpl-3.0 
inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax 
perror pmccabe2html progname read-file readline recv select send setsockopt 
shutdown socket sockets sys_stat update-copyright valgrind-tests 
version-etc-fsf warnings
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --with-tests 
--no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept 
arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo 
getline getpass-gnu gettime gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 
listen maintainer-makefile manywarnings minmax perror pmccabe2html progname 
read-file readline recv select send setsockopt shutdown socket sockets sys_stat 
update-copyright valgrind-tests version-etc-fsf warnings
 
-AUTOMAKE_OPTIONS = 1.5 gnits
+AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
 
 SUBDIRS =
 noinst_HEADERS =
@@ -45,8 +57,10 @@ libgnu_la_LDFLAGS += $(INET_NTOP_LIB)
 libgnu_la_LDFLAGS += $(INET_PTON_LIB)
 libgnu_la_LDFLAGS += $(LIBSOCKET)
 libgnu_la_LDFLAGS += $(LIB_CLOCK_GETTIME)
+libgnu_la_LDFLAGS += $(LIB_SELECT)
 libgnu_la_LDFLAGS += $(LTLIBINTL)
 libgnu_la_LDFLAGS += $(LTLIBREADLINE)
+libgnu_la_LDFLAGS += $(LTLIBTHREAD)
 libgnu_la_LDFLAGS += $(SERVENT_LIB)
 
 ## begin gnulib module accept
@@ -68,12 +82,12 @@ EXTRA_DIST += alignof.h
 ## begin gnulib module alloca
 
 
+libgnu_la_LIBADD += @LTALLOCA@
+libgnu_la_DEPENDENCIES += @LTALLOCA@
 EXTRA_DIST += alloca.c
 
 EXTRA_libgnu_la_SOURCES += alloca.c
 
-libgnu_la_LIBADD += @LTALLOCA@
-libgnu_la_DEPENDENCIES += @LTALLOCA@
 ## end   gnulib module alloca
 
 ## begin gnulib module alloca-opt
@@ -82,62 +96,46 @@ BUILT_SOURCES += $(ALLOCA_H)
 
 # We need the following in order to create <alloca.h> when the system
 # doesn't have one that works with the given compiler.
-alloca.h: alloca.in.h
+if GL_GENERATE_ALLOCA_H
+alloca.h: alloca.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          cat $(srcdir)/alloca.in.h; \
        } > address@hidden && \
        mv -f address@hidden $@
+else
+alloca.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += alloca.h alloca.h-t
 
 EXTRA_DIST += alloca.in.h
 
 ## end   gnulib module alloca-opt
 
-## begin gnulib module arg-nonnull
-
-# The BUILT_SOURCES created by this Makefile snippet are not used via #include
-# statements but through direct file reference. Therefore this snippet must be
-# present in all Makefile.am that need it. This is ensured by the applicability
-# 'all' defined above.
-
-BUILT_SOURCES += arg-nonnull.h
-# The arg-nonnull.h that gets inserted into generated .h files is the same as
-# build-aux/arg-nonnull.h, except that it has the copyright header cut off.
-arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h
-       $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/GL_ARG_NONNULL/,$$p' \
-         < $(top_srcdir)/build-aux/arg-nonnull.h \
-         > address@hidden && \
-       mv address@hidden $@
-MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
-
-ARG_NONNULL_H=arg-nonnull.h
-
-EXTRA_DIST += $(top_srcdir)/build-aux/arg-nonnull.h
-
-## end   gnulib module arg-nonnull
-
 ## begin gnulib module arpa_inet
 
 BUILT_SOURCES += arpa/inet.h
 
 # We need the following in order to create <arpa/inet.h> when the system
 # doesn't have one.
-arpa/inet.h: arpa_inet.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H) $(ARG_NONNULL_H)
        $(AM_V_at)$(MKDIR_P) arpa
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
              -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \
              -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \
-             -e 's|@''GNULIB_INET_NTOP''@|$(GNULIB_INET_NTOP)|g' \
-             -e 's|@''GNULIB_INET_PTON''@|$(GNULIB_INET_PTON)|g' \
+             -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \
+             -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \
              -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
              -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
+             -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \
+             -e 's|@''REPLACE_INET_PTON''@|$(REPLACE_INET_PTON)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
@@ -160,30 +158,6 @@ EXTRA_libgnu_la_SOURCES += bind.c
 
 ## end   gnulib module bind
 
-## begin gnulib module c++defs
-
-# The BUILT_SOURCES created by this Makefile snippet are not used via #include
-# statements but through direct file reference. Therefore this snippet must be
-# present in all Makefile.am that need it. This is ensured by the applicability
-# 'all' defined above.
-
-BUILT_SOURCES += c++defs.h
-# The c++defs.h that gets inserted into generated .h files is the same as
-# build-aux/c++defs.h, except that it has the copyright header cut off.
-c++defs.h: $(top_srcdir)/build-aux/c++defs.h
-       $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/_GL_CXXDEFS/,$$p' \
-         < $(top_srcdir)/build-aux/c++defs.h \
-         > address@hidden && \
-       mv address@hidden $@
-MOSTLYCLEANFILES += c++defs.h c++defs.h-t
-
-CXXDEFS_H=c++defs.h
-
-EXTRA_DIST += $(top_srcdir)/build-aux/c++defs.h
-
-## end   gnulib module c++defs
-
 ## begin gnulib module c-ctype
 
 libgnu_la_SOURCES += c-ctype.h c-ctype.c
@@ -199,14 +173,6 @@ EXTRA_libgnu_la_SOURCES += close.c
 
 ## end   gnulib module close
 
-## begin gnulib module close-hook
-
-libgnu_la_SOURCES += close-hook.c
-
-EXTRA_DIST += close-hook.h
-
-## end   gnulib module close-hook
-
 ## begin gnulib module connect
 
 
@@ -222,10 +188,12 @@ BUILT_SOURCES += $(ERRNO_H)
 
 # We need the following in order to create <errno.h> when the system
 # doesn't have one that is POSIX compliant.
-errno.h: errno.in.h
+if GL_GENERATE_ERRNO_H
+errno.h: errno.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_ERRNO_H''@|$(NEXT_ERRNO_H)|g' \
@@ -238,6 +206,10 @@ errno.h: errno.in.h
              < $(srcdir)/errno.in.h; \
        } > address@hidden && \
        mv address@hidden $@
+else
+errno.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += errno.h errno.h-t
 
 EXTRA_DIST += errno.in.h
@@ -253,14 +225,13 @@ EXTRA_libgnu_la_SOURCES += error.c
 
 ## end   gnulib module error
 
-## begin gnulib module fclose
-
+## begin gnulib module fd-hook
 
-EXTRA_DIST += fclose.c
+libgnu_la_SOURCES += fd-hook.c
 
-EXTRA_libgnu_la_SOURCES += fclose.c
+EXTRA_DIST += fd-hook.h
 
-## end   gnulib module fclose
+## end   gnulib module fd-hook
 
 ## begin gnulib module float
 
@@ -268,22 +239,40 @@ BUILT_SOURCES += $(FLOAT_H)
 
 # We need the following in order to create <float.h> when the system
 # doesn't have one that works with the given compiler.
-float.h: float.in.h
+if GL_GENERATE_FLOAT_H
+float.h: float.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -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 $@
+else
+float.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += float.h float.h-t
 
-EXTRA_DIST += float.in.h
+EXTRA_DIST += float.c float.in.h itold.c
+
+EXTRA_libgnu_la_SOURCES += float.c itold.c
 
 ## end   gnulib module float
 
+## begin gnulib module fseek
+
+
+EXTRA_DIST += fseek.c
+
+EXTRA_libgnu_la_SOURCES += fseek.c
+
+## end   gnulib module fseek
+
 ## begin gnulib module fseeko
 
 
@@ -293,6 +282,24 @@ EXTRA_libgnu_la_SOURCES += fseeko.c
 
 ## end   gnulib module fseeko
 
+## begin gnulib module fstat
+
+
+EXTRA_DIST += fstat.c
+
+EXTRA_libgnu_la_SOURCES += fstat.c
+
+## end   gnulib module fstat
+
+## begin gnulib module ftell
+
+
+EXTRA_DIST += ftell.c
+
+EXTRA_libgnu_la_SOURCES += ftell.c
+
+## end   gnulib module ftell
+
 ## begin gnulib module ftello
 
 
@@ -353,10 +360,7 @@ libgnu_la_SOURCES += gettext.h
 
 ## begin gnulib module gettime
 
-
-EXTRA_DIST += gettime.c
-
-EXTRA_libgnu_la_SOURCES += gettime.c
+libgnu_la_SOURCES += gettime.c
 
 ## end   gnulib module gettime
 
@@ -427,6 +431,12 @@ EXTRA_libgnu_la_SOURCES += listen.c
 
 ## end   gnulib module listen
 
+## begin gnulib module lock
+
+libgnu_la_SOURCES += glthread/lock.h glthread/lock.c
+
+## end   gnulib module lock
+
 ## begin gnulib module lseek
 
 
@@ -466,26 +476,47 @@ 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
 
 # We need the following in order to create <netdb.h> when the system
 # doesn't have one that works with the given compiler.
-netdb.h: netdb.in.h $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
              -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
-             -e 's|@''GNULIB_GETADDRINFO''@|$(GNULIB_GETADDRINFO)|g' \
+             -e 's/@''GNULIB_GETADDRINFO''@/$(GNULIB_GETADDRINFO)/g' \
              -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
              -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
              -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
              -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
              -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
+             -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/netdb.in.h; \
@@ -503,11 +534,13 @@ BUILT_SOURCES += $(NETINET_IN_H)
 
 # We need the following in order to create <netinet/in.h> when the system
 # doesn't have one.
-netinet/in.h: netinet_in.in.h
+if GL_GENERATE_NETINET_IN_H
+netinet/in.h: netinet_in.in.h $(top_builddir)/config.status
        $(AM_V_at)$(MKDIR_P) netinet
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \
@@ -515,6 +548,10 @@ netinet/in.h: netinet_in.in.h
              < $(srcdir)/netinet_in.in.h; \
        } > address@hidden && \
        mv address@hidden $@
+else
+netinet/in.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t
 MOSTLYCLEANDIRS += netinet
 
@@ -546,10 +583,9 @@ libgnu_la_SOURCES += progname.h progname.c
 
 ## begin gnulib module read-file
 
+libgnu_la_SOURCES += read-file.c
 
-EXTRA_DIST += read-file.c read-file.h
-
-EXTRA_libgnu_la_SOURCES += read-file.c
+EXTRA_DIST += read-file.h
 
 ## end   gnulib module read-file
 
@@ -616,12 +652,135 @@ EXTRA_libgnu_la_SOURCES += shutdown.c
 
 ## end   gnulib module shutdown
 
+## begin gnulib module signal-h
+
+BUILT_SOURCES += signal.h
+
+# We need the following in order to create <signal.h> when the system
+# doesn't have a complete one.
+signal.h: signal.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \
+             -e 's|@''GNULIB_PTHREAD_SIGMASK''@|$(GNULIB_PTHREAD_SIGMASK)|g' \
+             -e 's|@''GNULIB_RAISE''@|$(GNULIB_RAISE)|g' \
+             -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' 
\
+             -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \
+             -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \
+             -e 
's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \
+             -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \
+             -e 's|@''HAVE_RAISE''@|$(HAVE_RAISE)|g' \
+             -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \
+             -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \
+             -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \
+             -e 
's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g'
 \
+             -e 
's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \
+             -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \
+             -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' 
\
+             -e 's|@''REPLACE_RAISE''@|$(REPLACE_RAISE)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/signal.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += signal.h signal.h-t
+
+EXTRA_DIST += signal.in.h
+
+## end   gnulib module signal-h
+
 ## begin gnulib module size_max
 
 libgnu_la_SOURCES += size_max.h
 
 ## end   gnulib module size_max
 
+## begin gnulib module snippet/_Noreturn
+
+# Because this Makefile snippet defines a variable used by other
+# gnulib Makefile snippets, it must be present in all Makefile.am that
+# need it. This is ensured by the applicability 'all' defined above.
+
+_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h
+
+## end   gnulib module snippet/_Noreturn
+
+## begin gnulib module snippet/arg-nonnull
+
+# The BUILT_SOURCES created by this Makefile snippet are not used via #include
+# statements but through direct file reference. Therefore this snippet must be
+# present in all Makefile.am that need it. This is ensured by the applicability
+# 'all' defined above.
+
+BUILT_SOURCES += arg-nonnull.h
+# The arg-nonnull.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut
+# off.
+arg-nonnull.h: $(top_srcdir)/build-aux/snippet/arg-nonnull.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/GL_ARG_NONNULL/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/arg-nonnull.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
+
+ARG_NONNULL_H=arg-nonnull.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h
+
+## end   gnulib module snippet/arg-nonnull
+
+## begin gnulib module snippet/c++defs
+
+# The BUILT_SOURCES created by this Makefile snippet are not used via #include
+# statements but through direct file reference. Therefore this snippet must be
+# present in all Makefile.am that need it. This is ensured by the applicability
+# 'all' defined above.
+
+BUILT_SOURCES += c++defs.h
+# The c++defs.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/c++defs.h, except that it has the copyright header cut off.
+c++defs.h: $(top_srcdir)/build-aux/snippet/c++defs.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/_GL_CXXDEFS/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/c++defs.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += c++defs.h c++defs.h-t
+
+CXXDEFS_H=c++defs.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h
+
+## end   gnulib module snippet/c++defs
+
+## begin gnulib module snippet/warn-on-use
+
+BUILT_SOURCES += warn-on-use.h
+# The warn-on-use.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut
+# off.
+warn-on-use.h: $(top_srcdir)/build-aux/snippet/warn-on-use.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/^.ifndef/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/warn-on-use.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
+
+WARN_ON_USE_H=warn-on-use.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h
+
+## end   gnulib module snippet/warn-on-use
+
 ## begin gnulib module snprintf
 
 
@@ -654,16 +813,22 @@ BUILT_SOURCES += $(STDARG_H)
 
 # We need the following in order to create <stdarg.h> when the system
 # doesn't have one that works with the given compiler.
-stdarg.h: stdarg.in.h
+if GL_GENERATE_STDARG_H
+stdarg.h: stdarg.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STDARG_H''@|$(NEXT_STDARG_H)|g' \
              < $(srcdir)/stdarg.in.h; \
        } > address@hidden && \
        mv address@hidden $@
+else
+stdarg.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += stdarg.h stdarg.h-t
 
 EXTRA_DIST += stdarg.in.h
@@ -676,12 +841,17 @@ BUILT_SOURCES += $(STDBOOL_H)
 
 # We need the following in order to create <stdbool.h> when the system
 # doesn't have one that works.
-stdbool.h: stdbool.in.h
+if GL_GENERATE_STDBOOL_H
+stdbool.h: stdbool.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; 
\
        } > address@hidden && \
        mv address@hidden $@
+else
+stdbool.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += stdbool.h stdbool.h-t
 
 EXTRA_DIST += stdbool.in.h
@@ -694,10 +864,12 @@ BUILT_SOURCES += $(STDDEF_H)
 
 # We need the following in order to create <stddef.h> when the system
 # doesn't have one that works with the given compiler.
-stddef.h: stddef.in.h
+if GL_GENERATE_STDDEF_H
+stddef.h: stddef.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
@@ -706,6 +878,10 @@ stddef.h: stddef.in.h
              < $(srcdir)/stddef.in.h; \
        } > address@hidden && \
        mv address@hidden $@
+else
+stddef.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += stddef.h stddef.h-t
 
 EXTRA_DIST += stddef.in.h
@@ -718,10 +894,12 @@ BUILT_SOURCES += $(STDINT_H)
 
 # We need the following in order to create <stdint.h> when the system
 # doesn't have one that works with the given compiler.
-stdint.h: stdint.in.h
+if GL_GENERATE_STDINT_H
+stdint.h: stdint.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
@@ -750,6 +928,10 @@ stdint.h: stdint.in.h
              < $(srcdir)/stdint.in.h; \
        } > address@hidden && \
        mv address@hidden $@
+else
+stdint.h: $(top_builddir)/config.status
+       rm -f $@
+endif
 MOSTLYCLEANFILES += stdint.h stdint.h-t
 
 EXTRA_DIST += stdint.in.h
@@ -762,54 +944,68 @@ BUILT_SOURCES += stdio.h
 
 # We need the following in order to create <stdio.h> when the system
 # doesn't have one that works with the given compiler.
-stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -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_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
-             -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \
-             -e 's|@''GNULIB_FPRINTF''@|$(GNULIB_FPRINTF)|g' \
-             -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_FPURGE''@|$(GNULIB_FPURGE)|g' \
-             -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
-             -e 's|@''GNULIB_FPUTS''@|$(GNULIB_FPUTS)|g' \
-             -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \
-             -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
-             -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
-             -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
-             -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
-             -e 's|@''GNULIB_FWRITE''@|$(GNULIB_FWRITE)|g' \
-             -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
-             -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
-             -e 's|@''GNULIB_OBSTACK_PRINTF''@|$(GNULIB_OBSTACK_PRINTF)|g' \
-             -e 
's|@''GNULIB_OBSTACK_PRINTF_POSIX''@|$(GNULIB_OBSTACK_PRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \
-             -e 's|@''GNULIB_POPEN''@|$(GNULIB_POPEN)|g' \
-             -e 's|@''GNULIB_PRINTF''@|$(GNULIB_PRINTF)|g' \
-             -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
-             -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
-             -e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \
-             -e 's|@''GNULIB_REMOVE''@|$(GNULIB_REMOVE)|g' \
-             -e 's|@''GNULIB_RENAME''@|$(GNULIB_RENAME)|g' \
-             -e 's|@''GNULIB_RENAMEAT''@|$(GNULIB_RENAMEAT)|g' \
-             -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
-             -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \
-             -e 's|@''GNULIB_TMPFILE''@|$(GNULIB_TMPFILE)|g' \
-             -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
-             -e 's|@''GNULIB_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \
-             -e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
-             -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_VPRINTF''@|$(GNULIB_VPRINTF)|g' \
-             -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
-             -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
-             -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|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' \
+             -e 's/@''GNULIB_FOPEN''@/$(GNULIB_FOPEN)/g' \
+             -e 's/@''GNULIB_FPRINTF''@/$(GNULIB_FPRINTF)/g' \
+             -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GNULIB_FPRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_FPURGE''@/$(GNULIB_FPURGE)/g' \
+             -e 's/@''GNULIB_FPUTC''@/$(GNULIB_FPUTC)/g' \
+             -e 's/@''GNULIB_FPUTS''@/$(GNULIB_FPUTS)/g' \
+             -e 's/@''GNULIB_FREAD''@/$(GNULIB_FREAD)/g' \
+             -e 's/@''GNULIB_FREOPEN''@/$(GNULIB_FREOPEN)/g' \
+             -e 's/@''GNULIB_FSCANF''@/$(GNULIB_FSCANF)/g' \
+             -e 's/@''GNULIB_FSEEK''@/$(GNULIB_FSEEK)/g' \
+             -e 's/@''GNULIB_FSEEKO''@/$(GNULIB_FSEEKO)/g' \
+             -e 's/@''GNULIB_FTELL''@/$(GNULIB_FTELL)/g' \
+             -e 's/@''GNULIB_FTELLO''@/$(GNULIB_FTELLO)/g' \
+             -e 's/@''GNULIB_FWRITE''@/$(GNULIB_FWRITE)/g' \
+             -e 's/@''GNULIB_GETC''@/$(GNULIB_GETC)/g' \
+             -e 's/@''GNULIB_GETCHAR''@/$(GNULIB_GETCHAR)/g' \
+             -e 's/@''GNULIB_GETDELIM''@/$(GNULIB_GETDELIM)/g' \
+             -e 's/@''GNULIB_GETLINE''@/$(GNULIB_GETLINE)/g' \
+             -e 's/@''GNULIB_GETS''@/$(GNULIB_GETS)/g' \
+             -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \
+             -e 
's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \
+             -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \
+             -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \
+             -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \
+             -e 's/@''GNULIB_PRINTF_POSIX''@/$(GNULIB_PRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_PUTC''@/$(GNULIB_PUTC)/g' \
+             -e 's/@''GNULIB_PUTCHAR''@/$(GNULIB_PUTCHAR)/g' \
+             -e 's/@''GNULIB_PUTS''@/$(GNULIB_PUTS)/g' \
+             -e 's/@''GNULIB_REMOVE''@/$(GNULIB_REMOVE)/g' \
+             -e 's/@''GNULIB_RENAME''@/$(GNULIB_RENAME)/g' \
+             -e 's/@''GNULIB_RENAMEAT''@/$(GNULIB_RENAMEAT)/g' \
+             -e 's/@''GNULIB_SCANF''@/$(GNULIB_SCANF)/g' \
+             -e 's/@''GNULIB_SNPRINTF''@/$(GNULIB_SNPRINTF)/g' \
+             -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GNULIB_SPRINTF_POSIX)/g' \
+             -e 
's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GNULIB_STDIO_H_NONBLOCKING)/g' \
+             -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \
+             -e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \
+             -e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \
+             -e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \
+             -e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \
+             -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_VFSCANF''@/$(GNULIB_VFSCANF)/g' \
+             -e 's/@''GNULIB_VSCANF''@/$(GNULIB_VSCANF)/g' \
+             -e 's/@''GNULIB_VPRINTF''@/$(GNULIB_VPRINTF)/g' \
+             -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \
+             -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \
              < $(srcdir)/stdio.in.h | \
          sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
              -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \
@@ -822,11 +1018,14 @@ stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
              -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \
              -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|g' \
+             -e 's|@''HAVE_PCLOSE''@|$(HAVE_PCLOSE)|g' \
+             -e 's|@''HAVE_POPEN''@|$(HAVE_POPEN)|g' \
              -e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \
              -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
              -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' \
@@ -847,6 +1046,7 @@ stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''REPLACE_RENAMEAT''@|$(REPLACE_RENAMEAT)|g' \
              -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
              -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
+             -e 
's|@''REPLACE_STDIO_READ_FUNCS''@|$(REPLACE_STDIO_READ_FUNCS)|g' \
              -e 
's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \
              -e 's|@''REPLACE_TMPFILE''@|$(REPLACE_TMPFILE)|g' \
              -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
@@ -863,9 +1063,7 @@ stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
        mv address@hidden $@
 MOSTLYCLEANFILES += stdio.h stdio.h-t
 
-EXTRA_DIST += stdio-write.c stdio.in.h
-
-EXTRA_libgnu_la_SOURCES += stdio-write.c
+EXTRA_DIST += stdio.in.h
 
 ## end   gnulib module stdio
 
@@ -875,39 +1073,43 @@ BUILT_SOURCES += stdlib.h
 
 # We need the following in order to create <stdlib.h> when the system
 # doesn't have one that works with the given compiler.
-stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
+  $(_NORETURN_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
-             -e 's|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
-             -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
-             -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
-             -e 
's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
-             -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
-             -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
-             -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
-             -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
-             -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-             -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
-             -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
-             -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-             -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
-             -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \
-             -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
-             -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
-             -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
-             -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \
-             -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
-             -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
-             -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \
-             -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \
-             -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
-             -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
-             -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
-             -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+             -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \
+             -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \
+             -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \
+             -e 
's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \
+             -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \
+             -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \
+             -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \
+             -e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \
+             -e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \
+             -e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \
+             -e 's/@''GNULIB_MKOSTEMP''@/$(GNULIB_MKOSTEMP)/g' \
+             -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \
+             -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \
+             -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \
+             -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \
+             -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \
+             -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \
+             -e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \
+             -e 's/@''GNULIB_REALPATH''@/$(GNULIB_REALPATH)/g' \
+             -e 's/@''GNULIB_RPMATCH''@/$(GNULIB_RPMATCH)/g' \
+             -e 's/@''GNULIB_SETENV''@/$(GNULIB_SETENV)/g' \
+             -e 's/@''GNULIB_STRTOD''@/$(GNULIB_STRTOD)/g' \
+             -e 's/@''GNULIB_STRTOLL''@/$(GNULIB_STRTOLL)/g' \
+             -e 's/@''GNULIB_STRTOULL''@/$(GNULIB_STRTOULL)/g' \
+             -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GNULIB_SYSTEM_POSIX)/g' \
+             -e 's/@''GNULIB_UNLOCKPT''@/$(GNULIB_UNLOCKPT)/g' \
+             -e 's/@''GNULIB_UNSETENV''@/$(GNULIB_UNSETENV)/g' \
+             -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \
              < $(srcdir)/stdlib.in.h | \
          sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
              -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
@@ -936,6 +1138,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
              -e 
's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
              -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
+             -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
              -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
              -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
              -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
@@ -943,7 +1146,9 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
              -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
              -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
+             -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _Noreturn/r $(_NORETURN_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
        } > address@hidden && \
@@ -963,56 +1168,79 @@ EXTRA_libgnu_la_SOURCES += strerror.c
 
 ## end   gnulib module strerror
 
+## begin gnulib module strerror-override
+
+
+EXTRA_DIST += strerror-override.c strerror-override.h
+
+EXTRA_libgnu_la_SOURCES += strerror-override.c
+
+## end   gnulib module strerror-override
+
+## begin gnulib module strerror_r-posix
+
+
+EXTRA_DIST += strerror_r.c
+
+EXTRA_libgnu_la_SOURCES += strerror_r.c
+
+## end   gnulib module strerror_r-posix
+
 ## begin gnulib module string
 
 BUILT_SOURCES += string.h
 
 # We need the following in order to create <string.h> when the system
 # doesn't have one that works with the given compiler.
-string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \
-             -e 's|@''GNULIB_MBSLEN''@|$(GNULIB_MBSLEN)|g' \
-             -e 's|@''GNULIB_MBSNLEN''@|$(GNULIB_MBSNLEN)|g' \
-             -e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \
-             -e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \
-             -e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \
-             -e 's|@''GNULIB_MBSCASECMP''@|$(GNULIB_MBSCASECMP)|g' \
-             -e 's|@''GNULIB_MBSNCASECMP''@|$(GNULIB_MBSNCASECMP)|g' \
-             -e 's|@''GNULIB_MBSPCASECMP''@|$(GNULIB_MBSPCASECMP)|g' \
-             -e 's|@''GNULIB_MBSCASESTR''@|$(GNULIB_MBSCASESTR)|g' \
-             -e 's|@''GNULIB_MBSCSPN''@|$(GNULIB_MBSCSPN)|g' \
-             -e 's|@''GNULIB_MBSPBRK''@|$(GNULIB_MBSPBRK)|g' \
-             -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \
-             -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \
-             -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \
-             -e 's|@''GNULIB_MEMCHR''@|$(GNULIB_MEMCHR)|g' \
-             -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \
-             -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \
-             -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \
-             -e 's|@''GNULIB_RAWMEMCHR''@|$(GNULIB_RAWMEMCHR)|g' \
-             -e 's|@''GNULIB_STPCPY''@|$(GNULIB_STPCPY)|g' \
-             -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \
-             -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \
-             -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \
-             -e 's|@''GNULIB_STRNCAT''@|$(GNULIB_STRNCAT)|g' \
-             -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \
-             -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \
-             -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \
-             -e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \
-             -e 's|@''GNULIB_STRSTR''@|$(GNULIB_STRSTR)|g' \
-             -e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \
-             -e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \
-             -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \
-             -e 's|@''GNULIB_STRERROR_R''@|$(GNULIB_STRERROR_R)|g' \
-             -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \
-             -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \
+             -e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \
+             -e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \
+             -e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \
+             -e 's/@''GNULIB_MBSNLEN''@/$(GNULIB_MBSNLEN)/g' \
+             -e 's/@''GNULIB_MBSCHR''@/$(GNULIB_MBSCHR)/g' \
+             -e 's/@''GNULIB_MBSRCHR''@/$(GNULIB_MBSRCHR)/g' \
+             -e 's/@''GNULIB_MBSSTR''@/$(GNULIB_MBSSTR)/g' \
+             -e 's/@''GNULIB_MBSCASECMP''@/$(GNULIB_MBSCASECMP)/g' \
+             -e 's/@''GNULIB_MBSNCASECMP''@/$(GNULIB_MBSNCASECMP)/g' \
+             -e 's/@''GNULIB_MBSPCASECMP''@/$(GNULIB_MBSPCASECMP)/g' \
+             -e 's/@''GNULIB_MBSCASESTR''@/$(GNULIB_MBSCASESTR)/g' \
+             -e 's/@''GNULIB_MBSCSPN''@/$(GNULIB_MBSCSPN)/g' \
+             -e 's/@''GNULIB_MBSPBRK''@/$(GNULIB_MBSPBRK)/g' \
+             -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \
+             -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \
+             -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \
+             -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \
+             -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \
+             -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \
+             -e 's/@''GNULIB_MEMRCHR''@/$(GNULIB_MEMRCHR)/g' \
+             -e 's/@''GNULIB_RAWMEMCHR''@/$(GNULIB_RAWMEMCHR)/g' \
+             -e 's/@''GNULIB_STPCPY''@/$(GNULIB_STPCPY)/g' \
+             -e 's/@''GNULIB_STPNCPY''@/$(GNULIB_STPNCPY)/g' \
+             -e 's/@''GNULIB_STRCHRNUL''@/$(GNULIB_STRCHRNUL)/g' \
+             -e 's/@''GNULIB_STRDUP''@/$(GNULIB_STRDUP)/g' \
+             -e 's/@''GNULIB_STRNCAT''@/$(GNULIB_STRNCAT)/g' \
+             -e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \
+             -e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \
+             -e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \
+             -e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \
+             -e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \
+             -e 's/@''GNULIB_STRCASESTR''@/$(GNULIB_STRCASESTR)/g' \
+             -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \
+             -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \
+             -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \
+             -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \
+             -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \
              < $(srcdir)/string.in.h | \
-         sed -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
+         sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
+             -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \
+             -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
              -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \
              -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
              -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
@@ -1035,6 +1263,7 @@ string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
              -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
              -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
+             -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \
              -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
              -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
              -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
@@ -1063,17 +1292,21 @@ BUILT_SOURCES += sys/select.h
 
 # We need the following in order to create <sys/select.h> when the system
 # doesn't have one that works with the given compiler.
-sys/select.h: sys_select.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
+sys/select.h: sys_select.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \
              -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \
-             -e 's|@''GNULIB_SELECT''@|$(GNULIB_SELECT)|g' \
+             -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \
+             -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \
              -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+             -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \
+             -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \
              -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
@@ -1093,31 +1326,32 @@ BUILT_SOURCES += sys/socket.h
 
 # We need the following in order to create <sys/socket.h> when the system
 # doesn't have one that works with the given compiler.
-sys/socket.h: sys_socket.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H) $(ARG_NONNULL_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
              -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
-             -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
-             -e 's|@''GNULIB_SOCKET''@|$(GNULIB_SOCKET)|g' \
-             -e 's|@''GNULIB_CONNECT''@|$(GNULIB_CONNECT)|g' \
-             -e 's|@''GNULIB_ACCEPT''@|$(GNULIB_ACCEPT)|g' \
-             -e 's|@''GNULIB_BIND''@|$(GNULIB_BIND)|g' \
-             -e 's|@''GNULIB_GETPEERNAME''@|$(GNULIB_GETPEERNAME)|g' \
-             -e 's|@''GNULIB_GETSOCKNAME''@|$(GNULIB_GETSOCKNAME)|g' \
-             -e 's|@''GNULIB_GETSOCKOPT''@|$(GNULIB_GETSOCKOPT)|g' \
-             -e 's|@''GNULIB_LISTEN''@|$(GNULIB_LISTEN)|g' \
-             -e 's|@''GNULIB_RECV''@|$(GNULIB_RECV)|g' \
-             -e 's|@''GNULIB_SEND''@|$(GNULIB_SEND)|g' \
-             -e 's|@''GNULIB_RECVFROM''@|$(GNULIB_RECVFROM)|g' \
-             -e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \
-             -e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \
-             -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
-             -e 's|@''GNULIB_ACCEPT4''@|$(GNULIB_ACCEPT4)|g' \
+             -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \
+             -e 's/@''GNULIB_SOCKET''@/$(GNULIB_SOCKET)/g' \
+             -e 's/@''GNULIB_CONNECT''@/$(GNULIB_CONNECT)/g' \
+             -e 's/@''GNULIB_ACCEPT''@/$(GNULIB_ACCEPT)/g' \
+             -e 's/@''GNULIB_BIND''@/$(GNULIB_BIND)/g' \
+             -e 's/@''GNULIB_GETPEERNAME''@/$(GNULIB_GETPEERNAME)/g' \
+             -e 's/@''GNULIB_GETSOCKNAME''@/$(GNULIB_GETSOCKNAME)/g' \
+             -e 's/@''GNULIB_GETSOCKOPT''@/$(GNULIB_GETSOCKOPT)/g' \
+             -e 's/@''GNULIB_LISTEN''@/$(GNULIB_LISTEN)/g' \
+             -e 's/@''GNULIB_RECV''@/$(GNULIB_RECV)/g' \
+             -e 's/@''GNULIB_SEND''@/$(GNULIB_SEND)/g' \
+             -e 's/@''GNULIB_RECVFROM''@/$(GNULIB_RECVFROM)/g' \
+             -e 's/@''GNULIB_SENDTO''@/$(GNULIB_SENDTO)/g' \
+             -e 's/@''GNULIB_SETSOCKOPT''@/$(GNULIB_SETSOCKOPT)/g' \
+             -e 's/@''GNULIB_SHUTDOWN''@/$(GNULIB_SHUTDOWN)/g' \
+             -e 's/@''GNULIB_ACCEPT4''@/$(GNULIB_ACCEPT4)/g' \
              -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
              -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
              -e 
's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
@@ -1143,26 +1377,28 @@ BUILT_SOURCES += sys/stat.h
 
 # We need the following in order to create <sys/stat.h> when the system
 # has one that is incomplete.
-sys/stat.h: sys_stat.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -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_FSTATAT''@|$(GNULIB_FSTATAT)|g' \
-             -e 's|@''GNULIB_FUTIMENS''@|$(GNULIB_FUTIMENS)|g' \
-             -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \
-             -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \
-             -e 's|@''GNULIB_MKDIRAT''@|$(GNULIB_MKDIRAT)|g' \
-             -e 's|@''GNULIB_MKFIFO''@|$(GNULIB_MKFIFO)|g' \
-             -e 's|@''GNULIB_MKFIFOAT''@|$(GNULIB_MKFIFOAT)|g' \
-             -e 's|@''GNULIB_MKNOD''@|$(GNULIB_MKNOD)|g' \
-             -e 's|@''GNULIB_MKNODAT''@|$(GNULIB_MKNODAT)|g' \
-             -e 's|@''GNULIB_STAT''@|$(GNULIB_STAT)|g' \
-             -e 's|@''GNULIB_UTIMENSAT''@|$(GNULIB_UTIMENSAT)|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' \
+             -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \
+             -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \
+             -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \
+             -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \
+             -e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \
+             -e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \
+             -e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \
+             -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \
              -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
              -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
              -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
@@ -1202,16 +1438,18 @@ BUILT_SOURCES += sys/time.h
 
 # We need the following in order to create <sys/time.h> when the system
 # doesn't have one that works with the given compiler.
-sys/time.h: sys_time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \
              -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
+             -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
              -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \
              -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
              -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
@@ -1227,24 +1465,83 @@ EXTRA_DIST += sys_time.in.h
 
 ## end   gnulib module sys_time
 
+## begin gnulib module sys_types
+
+BUILT_SOURCES += sys/types.h
+
+# We need the following in order to create <sys/types.h> when the system
+# doesn't have one that works with the given compiler.
+sys/types.h: sys_types.in.h $(top_builddir)/config.status
+       $(AM_V_at)$(MKDIR_P) sys
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \
+             < $(srcdir)/sys_types.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += sys/types.h sys/types.h-t
+
+EXTRA_DIST += sys_types.in.h
+
+## end   gnulib module sys_types
+
+## begin gnulib module sys_uio
+
+BUILT_SOURCES += sys/uio.h
+
+# We need the following in order to create <sys/uio.h> when the system
+# doesn't have one that works with the given compiler.
+sys/uio.h: sys_uio.in.h $(top_builddir)/config.status
+       $(AM_V_at)$(MKDIR_P) sys
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SYS_UIO_H''@|$(NEXT_SYS_UIO_H)|g' \
+             -e 's|@''HAVE_SYS_UIO_H''@|$(HAVE_SYS_UIO_H)|g' \
+             < $(srcdir)/sys_uio.in.h; \
+       } > address@hidden && \
+       mv -f address@hidden $@
+MOSTLYCLEANFILES += sys/uio.h sys/uio.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_uio.in.h
+
+## end   gnulib module sys_uio
+
+## begin gnulib module threadlib
+
+libgnu_la_SOURCES += glthread/threadlib.c
+
+EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
+
+## end   gnulib module threadlib
+
 ## begin gnulib module time
 
 BUILT_SOURCES += time.h
 
 # We need the following in order to create <time.h> when the system
 # doesn't have one that works with the given compiler.
-time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
-             -e 's|@''GNULIB_MKTIME''@|$(GNULIB_MKTIME)|g' \
-             -e 's|@''GNULIB_NANOSLEEP''@|$(GNULIB_NANOSLEEP)|g' \
-             -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \
-             -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \
-             -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \
+             -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
+             -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
+             -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
+             -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
+             -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
              -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
              -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
              -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
@@ -1281,55 +1578,62 @@ BUILT_SOURCES += unistd.h
 
 # We need the following in order to create an empty placeholder for
 # <unistd.h> when the system doesn't have one.
-unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -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_CHOWN''@|$(GNULIB_CHOWN)|g' \
-             -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
-             -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
-             -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \
-             -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
-             -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
-             -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \
-             -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
-             -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \
-             -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
-             -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
-             -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
-             -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
-             -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
-             -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \
-             -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
-             -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \
-             -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
-             -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
-             -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
-             -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
-             -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
-             -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \
-             -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
-             -e 's|@''GNULIB_PIPE''@|$(GNULIB_PIPE)|g' \
-             -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \
-             -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \
-             -e 's|@''GNULIB_PWRITE''@|$(GNULIB_PWRITE)|g' \
-             -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
-             -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \
-             -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \
-             -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
-             -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \
-             -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \
-             -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \
-             -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \
-             -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' 
\
-             -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \
-             -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \
-             -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \
-             -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|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' \
+             -e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \
+             -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \
+             -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \
+             -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \
+             -e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \
+             -e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \
+             -e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \
+             -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \
+             -e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \
+             -e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \
+             -e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \
+             -e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \
+             -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \
+             -e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \
+             -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \
+             -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \
+             -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \
+             -e 's/@''GNULIB_LCHOWN''@/$(GNULIB_LCHOWN)/g' \
+             -e 's/@''GNULIB_LINK''@/$(GNULIB_LINK)/g' \
+             -e 's/@''GNULIB_LINKAT''@/$(GNULIB_LINKAT)/g' \
+             -e 's/@''GNULIB_LSEEK''@/$(GNULIB_LSEEK)/g' \
+             -e 's/@''GNULIB_PIPE''@/$(GNULIB_PIPE)/g' \
+             -e 's/@''GNULIB_PIPE2''@/$(GNULIB_PIPE2)/g' \
+             -e 's/@''GNULIB_PREAD''@/$(GNULIB_PREAD)/g' \
+             -e 's/@''GNULIB_PWRITE''@/$(GNULIB_PWRITE)/g' \
+             -e 's/@''GNULIB_READ''@/$(GNULIB_READ)/g' \
+             -e 's/@''GNULIB_READLINK''@/$(GNULIB_READLINK)/g' \
+             -e 's/@''GNULIB_READLINKAT''@/$(GNULIB_READLINKAT)/g' \
+             -e 's/@''GNULIB_RMDIR''@/$(GNULIB_RMDIR)/g' \
+             -e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \
+             -e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \
+             -e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/g' \
+             -e 's/@''GNULIB_TTYNAME_R''@/$(GNULIB_TTYNAME_R)/g' \
+             -e 's/@''GNULIB_UNISTD_H_GETOPT''@/$(GNULIB_UNISTD_H_GETOPT)/g' \
+             -e 
's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GNULIB_UNISTD_H_NONBLOCKING)/g' \
+             -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GNULIB_UNISTD_H_SIGPIPE)/g' 
\
+             -e 's/@''GNULIB_UNLINK''@/$(GNULIB_UNLINK)/g' \
+             -e 's/@''GNULIB_UNLINKAT''@/$(GNULIB_UNLINKAT)/g' \
+             -e 's/@''GNULIB_USLEEP''@/$(GNULIB_USLEEP)/g' \
+             -e 's/@''GNULIB_WRITE''@/$(GNULIB_WRITE)/g' \
              < $(srcdir)/unistd.in.h | \
          sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
              -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
@@ -1338,6 +1642,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
              -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
              -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
+             -e 's|@''HAVE_FDATASYNC''@|$(HAVE_FDATASYNC)|g' \
              -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
              -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
              -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
@@ -1345,6 +1650,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
              -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
              -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
+             -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \
              -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
              -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
              -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
@@ -1361,6 +1667,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
              -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
              -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
+             -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
              -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' 
\
              -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
              -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
@@ -1385,6 +1692,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
              -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \
              -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
+             -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \
              -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
              -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
              -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
@@ -1439,7 +1747,8 @@ EXTRA_DIST += $(top_srcdir)/build-aux/vc-list-files
 
 ## begin gnulib module verify
 
-libgnu_la_SOURCES += verify.h
+
+EXTRA_DIST += verify.h
 
 ## end   gnulib module verify
 
@@ -1455,24 +1764,126 @@ libgnu_la_SOURCES += version-etc-fsf.c
 
 ## end   gnulib module version-etc-fsf
 
-## begin gnulib module warn-on-use
+## begin gnulib module wchar
 
-BUILT_SOURCES += warn-on-use.h
-# The warn-on-use.h that gets inserted into generated .h files is the same as
-# build-aux/warn-on-use.h, except that it has the copyright header cut off.
-warn-on-use.h: $(top_srcdir)/build-aux/warn-on-use.h
+BUILT_SOURCES += wchar.h
+
+# We need the following in order to create <wchar.h> when the system
+# version does not work standalone.
+wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/^.ifndef/,$$p' \
-         < $(top_srcdir)/build-aux/warn-on-use.h \
-         > address@hidden && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
+             -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
+             -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
+             -e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \
+             -e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \
+             -e 's/@''GNULIB_MBSINIT''@/$(GNULIB_MBSINIT)/g' \
+             -e 's/@''GNULIB_MBRTOWC''@/$(GNULIB_MBRTOWC)/g' \
+             -e 's/@''GNULIB_MBRLEN''@/$(GNULIB_MBRLEN)/g' \
+             -e 's/@''GNULIB_MBSRTOWCS''@/$(GNULIB_MBSRTOWCS)/g' \
+             -e 's/@''GNULIB_MBSNRTOWCS''@/$(GNULIB_MBSNRTOWCS)/g' \
+             -e 's/@''GNULIB_WCRTOMB''@/$(GNULIB_WCRTOMB)/g' \
+             -e 's/@''GNULIB_WCSRTOMBS''@/$(GNULIB_WCSRTOMBS)/g' \
+             -e 's/@''GNULIB_WCSNRTOMBS''@/$(GNULIB_WCSNRTOMBS)/g' \
+             -e 's/@''GNULIB_WCWIDTH''@/$(GNULIB_WCWIDTH)/g' \
+             -e 's/@''GNULIB_WMEMCHR''@/$(GNULIB_WMEMCHR)/g' \
+             -e 's/@''GNULIB_WMEMCMP''@/$(GNULIB_WMEMCMP)/g' \
+             -e 's/@''GNULIB_WMEMCPY''@/$(GNULIB_WMEMCPY)/g' \
+             -e 's/@''GNULIB_WMEMMOVE''@/$(GNULIB_WMEMMOVE)/g' \
+             -e 's/@''GNULIB_WMEMSET''@/$(GNULIB_WMEMSET)/g' \
+             -e 's/@''GNULIB_WCSLEN''@/$(GNULIB_WCSLEN)/g' \
+             -e 's/@''GNULIB_WCSNLEN''@/$(GNULIB_WCSNLEN)/g' \
+             -e 's/@''GNULIB_WCSCPY''@/$(GNULIB_WCSCPY)/g' \
+             -e 's/@''GNULIB_WCPCPY''@/$(GNULIB_WCPCPY)/g' \
+             -e 's/@''GNULIB_WCSNCPY''@/$(GNULIB_WCSNCPY)/g' \
+             -e 's/@''GNULIB_WCPNCPY''@/$(GNULIB_WCPNCPY)/g' \
+             -e 's/@''GNULIB_WCSCAT''@/$(GNULIB_WCSCAT)/g' \
+             -e 's/@''GNULIB_WCSNCAT''@/$(GNULIB_WCSNCAT)/g' \
+             -e 's/@''GNULIB_WCSCMP''@/$(GNULIB_WCSCMP)/g' \
+             -e 's/@''GNULIB_WCSNCMP''@/$(GNULIB_WCSNCMP)/g' \
+             -e 's/@''GNULIB_WCSCASECMP''@/$(GNULIB_WCSCASECMP)/g' \
+             -e 's/@''GNULIB_WCSNCASECMP''@/$(GNULIB_WCSNCASECMP)/g' \
+             -e 's/@''GNULIB_WCSCOLL''@/$(GNULIB_WCSCOLL)/g' \
+             -e 's/@''GNULIB_WCSXFRM''@/$(GNULIB_WCSXFRM)/g' \
+             -e 's/@''GNULIB_WCSDUP''@/$(GNULIB_WCSDUP)/g' \
+             -e 's/@''GNULIB_WCSCHR''@/$(GNULIB_WCSCHR)/g' \
+             -e 's/@''GNULIB_WCSRCHR''@/$(GNULIB_WCSRCHR)/g' \
+             -e 's/@''GNULIB_WCSCSPN''@/$(GNULIB_WCSCSPN)/g' \
+             -e 's/@''GNULIB_WCSSPN''@/$(GNULIB_WCSSPN)/g' \
+             -e 's/@''GNULIB_WCSPBRK''@/$(GNULIB_WCSPBRK)/g' \
+             -e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \
+             -e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \
+             -e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \
+             < $(srcdir)/wchar.in.h | \
+         sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
+             -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
+             -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
+             -e 's|@''HAVE_MBRTOWC''@|$(HAVE_MBRTOWC)|g' \
+             -e 's|@''HAVE_MBRLEN''@|$(HAVE_MBRLEN)|g' \
+             -e 's|@''HAVE_MBSRTOWCS''@|$(HAVE_MBSRTOWCS)|g' \
+             -e 's|@''HAVE_MBSNRTOWCS''@|$(HAVE_MBSNRTOWCS)|g' \
+             -e 's|@''HAVE_WCRTOMB''@|$(HAVE_WCRTOMB)|g' \
+             -e 's|@''HAVE_WCSRTOMBS''@|$(HAVE_WCSRTOMBS)|g' \
+             -e 's|@''HAVE_WCSNRTOMBS''@|$(HAVE_WCSNRTOMBS)|g' \
+             -e 's|@''HAVE_WMEMCHR''@|$(HAVE_WMEMCHR)|g' \
+             -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \
+             -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \
+             -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \
+             -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \
+             -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \
+             -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \
+             -e 's|@''HAVE_WCSCPY''@|$(HAVE_WCSCPY)|g' \
+             -e 's|@''HAVE_WCPCPY''@|$(HAVE_WCPCPY)|g' \
+             -e 's|@''HAVE_WCSNCPY''@|$(HAVE_WCSNCPY)|g' \
+             -e 's|@''HAVE_WCPNCPY''@|$(HAVE_WCPNCPY)|g' \
+             -e 's|@''HAVE_WCSCAT''@|$(HAVE_WCSCAT)|g' \
+             -e 's|@''HAVE_WCSNCAT''@|$(HAVE_WCSNCAT)|g' \
+             -e 's|@''HAVE_WCSCMP''@|$(HAVE_WCSCMP)|g' \
+             -e 's|@''HAVE_WCSNCMP''@|$(HAVE_WCSNCMP)|g' \
+             -e 's|@''HAVE_WCSCASECMP''@|$(HAVE_WCSCASECMP)|g' \
+             -e 's|@''HAVE_WCSNCASECMP''@|$(HAVE_WCSNCASECMP)|g' \
+             -e 's|@''HAVE_WCSCOLL''@|$(HAVE_WCSCOLL)|g' \
+             -e 's|@''HAVE_WCSXFRM''@|$(HAVE_WCSXFRM)|g' \
+             -e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|g' \
+             -e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|g' \
+             -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|g' \
+             -e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|g' \
+             -e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|g' \
+             -e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|g' \
+             -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \
+             -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \
+             -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \
+             -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
+             -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
+         | \
+         sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
+             -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \
+             -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
+             -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \
+             -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \
+             -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \
+             -e 's|@''REPLACE_MBSRTOWCS''@|$(REPLACE_MBSRTOWCS)|g' \
+             -e 's|@''REPLACE_MBSNRTOWCS''@|$(REPLACE_MBSNRTOWCS)|g' \
+             -e 's|@''REPLACE_WCRTOMB''@|$(REPLACE_WCRTOMB)|g' \
+             -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \
+             -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
+             -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
+             -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
+       } > address@hidden && \
        mv address@hidden $@
-MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
-
-WARN_ON_USE_H=warn-on-use.h
+MOSTLYCLEANFILES += wchar.h wchar.h-t
 
-EXTRA_DIST += $(top_srcdir)/build-aux/warn-on-use.h
+EXTRA_DIST += wchar.in.h
 
-## end   gnulib module warn-on-use
+## end   gnulib module wchar
 
 ## begin gnulib module xsize
 
diff --git a/gl/accept.c b/gl/accept.c
index 5591fa5..01faf54 100644
--- a/gl/accept.c
+++ b/gl/accept.c
@@ -31,12 +31,22 @@
 int
 rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
-  SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
-  if (fh == INVALID_SOCKET)
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
     {
-      set_winsock_errno ();
+      errno = EBADF;
       return -1;
     }
   else
-    return SOCKET_TO_FD (fh);
+    {
+      SOCKET fh = accept (sock, addr, addrlen);
+      if (fh == INVALID_SOCKET)
+        {
+          set_winsock_errno ();
+          return -1;
+        }
+      else
+        return SOCKET_TO_FD (fh);
+    }
 }
diff --git a/gl/alignof.h b/gl/alignof.h
index 03bed6f..1c1f75c 100644
--- a/gl/alignof.h
+++ b/gl/alignof.h
@@ -31,7 +31,7 @@
 # define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, 
__slot2)
 #endif
 
-/* Determine the good alignment of a object of the given type at compile time.
+/* Determine the good alignment of an object of the given type at compile time.
    Note that this is not necessarily the same as alignof_slot(type).
    For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
    - when -malign-double is not specified:  alignof_slot(double) = 4,
diff --git a/gl/alloca.c b/gl/alloca.c
index 771c2fa..06b12a7 100644
--- a/gl/alloca.c
+++ b/gl/alloca.c
@@ -93,25 +93,15 @@ long i00afunc ();
 static int stack_dir;           /* 1 or -1 once known.  */
 #   define STACK_DIR    stack_dir
 
-static void
-find_stack_direction (char **ptr)
+static int
+find_stack_direction (int *addr, int depth)
 {
-  auto char dummy;              /* To get stack address.  */
-
-  if (*ptr == NULL)
-    {                           /* Initial entry.  */
-      *ptr = ADDRESS_FUNCTION (dummy);
-
-      find_stack_direction (ptr);  /* Recurse once.  */
-    }
-  else
-    {
-      /* Second entry.  */
-      if (ADDRESS_FUNCTION (dummy) > *ptr)
-        stack_dir = 1;          /* Stack grew upward.  */
-      else
-        stack_dir = -1;         /* Stack grew downward.  */
-    }
+  int dir, dummy = 0;
+  if (! addr)
+    addr = &dummy;
+  *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
+  dir = depth ? find_stack_direction (addr, depth - 1) : 0;
+  return dir + dummy;
 }
 
 #  endif /* STACK_DIRECTION == 0 */
@@ -154,10 +144,7 @@ alloca (size_t size)
 
 #  if STACK_DIRECTION == 0
   if (STACK_DIR == 0)           /* Unknown growth direction.  */
-    {
-      char *addr = NULL;        /* Address of first `dummy', once known.  */
-      find_stack_direction (&addr);
-    }
+    STACK_DIR = find_stack_direction (NULL, (size & 1) + 20);
 #  endif
 
   /* Reclaim garbage, defined as all alloca'd storage that
diff --git a/gl/arpa_inet.in.h b/gl/arpa_inet.in.h
index 1470f86..5264853 100644
--- a/gl/arpa_inet.in.h
+++ b/gl/arpa_inet.in.h
@@ -16,7 +16,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_ARPA_INET_H
+#ifndef address@hidden@_ARPA_INET_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -27,8 +27,8 @@
 # include <features.h> /* for __GLIBC__ */
 #endif
 
-/* Gnulib's sys/socket.h is responsible for pulling in winsock2.h etc
-   under MinGW.
+/* Gnulib's sys/socket.h is responsible for defining socklen_t (used below) and
+   for pulling in winsock2.h etc. under MinGW.
    But avoid namespace pollution on glibc systems.  */
 #ifndef __GLIBC__
 # include <sys/socket.h>
@@ -47,8 +47,8 @@
 
 #endif
 
-#ifndef _GL_ARPA_INET_H
-#define _GL_ARPA_INET_H
+#ifndef address@hidden@_ARPA_INET_H
+#define address@hidden@_ARPA_INET_H
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
@@ -58,7 +58,6 @@
 
 
 #if @GNULIB_INET_NTOP@
-# if address@hidden@
 /* Converts an internet address from internal format to a printable,
    presentable format.
    AF is an internet address family, such as AF_INET or AF_INET6.
@@ -74,16 +73,31 @@
 
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/inet_ntop.html>.  */
+# if @REPLACE_INET_NTOP@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef inet_ntop
+#   define inet_ntop rpl_inet_ntop
+#  endif
+_GL_FUNCDECL_RPL (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt)
+                  _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt));
+# else
+#  if address@hidden@
 _GL_FUNCDECL_SYS (inet_ntop, const char *,
                   (int af, const void *restrict src,
                    char *restrict dst, socklen_t cnt)
                   _GL_ARG_NONNULL ((2, 3)));
-# endif
+#  endif
 /* Need to cast, because on NonStop Kernel, the fourth parameter is
                                             size_t cnt.  */
 _GL_CXXALIAS_SYS_CAST (inet_ntop, const char *,
                        (int af, const void *restrict src,
                         char *restrict dst, socklen_t cnt));
+# endif
 _GL_CXXALIASWARN (inet_ntop);
 #elif defined GNULIB_POSIXCHECK
 # undef inet_ntop
@@ -94,13 +108,25 @@ _GL_WARN_ON_USE (inet_ntop, "inet_ntop is unportable - "
 #endif
 
 #if @GNULIB_INET_PTON@
-# if address@hidden@
+# if @REPLACE_INET_PTON@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef inet_pton
+#   define inet_pton rpl_inet_pton
+#  endif
+_GL_FUNCDECL_RPL (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst)
+                  _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst));
+# else
+#  if address@hidden@
 _GL_FUNCDECL_SYS (inet_pton, int,
                   (int af, const char *restrict src, void *restrict dst)
                   _GL_ARG_NONNULL ((2, 3)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (inet_pton, int,
                   (int af, const char *restrict src, void *restrict dst));
+# endif
 _GL_CXXALIASWARN (inet_pton);
 #elif defined GNULIB_POSIXCHECK
 # undef inet_pton
@@ -111,5 +137,5 @@ _GL_WARN_ON_USE (inet_pton, "inet_pton is unportable - "
 #endif
 
 
-#endif /* _GL_ARPA_INET_H */
-#endif /* _GL_ARPA_INET_H */
+#endif /* address@hidden@_ARPA_INET_H */
+#endif /* address@hidden@_ARPA_INET_H */
diff --git a/gl/bind.c b/gl/bind.c
index e6d959d..baaea59 100644
--- a/gl/bind.c
+++ b/gl/bind.c
@@ -32,9 +32,18 @@ int
 rpl_bind (int fd, const struct sockaddr *sockaddr, socklen_t len)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = bind (sock, sockaddr, len);
-  if (r < 0)
-    set_winsock_errno ();
 
-  return r;
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = bind (sock, sockaddr, len);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
 }
diff --git a/gl/close-hook.c b/gl/close-hook.c
deleted file mode 100644
index ecc5f46..0000000
--- a/gl/close-hook.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Hook for making the close() function extensible.
-   Copyright (C) 2009-2011 Free Software Foundation, Inc.
-   Written by Bruno Haible <address@hidden>, 2009.
-
-   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/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "close-hook.h"
-
-#include <stdlib.h>
-#include <unistd.h>
-
-#undef close
-
-
-/* Currently, this entire code is only needed for the handling of sockets
-   on native Windows platforms.  */
-#if WINDOWS_SOCKETS
-
-/* The first and last link in the doubly linked list.
-   Initially the list is empty.  */
-static struct close_hook anchor = { &anchor, &anchor, NULL };
-
-int
-execute_close_hooks (int fd, const struct close_hook *remaining_list)
-{
-  if (remaining_list == &anchor)
-    /* End of list reached.  */
-    return close (fd);
-  else
-    return remaining_list->private_fn (fd, remaining_list->private_next);
-}
-
-int
-execute_all_close_hooks (int fd)
-{
-  return execute_close_hooks (fd, anchor.private_next);
-}
-
-void
-register_close_hook (close_hook_fn hook, struct close_hook *link)
-{
-  if (link->private_next == NULL && link->private_prev == NULL)
-    {
-      /* Add the link to the doubly linked list.  */
-      link->private_next = anchor.private_next;
-      link->private_prev = &anchor;
-      link->private_fn = hook;
-      anchor.private_next->private_prev = link;
-      anchor.private_next = link;
-    }
-  else
-    {
-      /* The link is already in use.  */
-      if (link->private_fn != hook)
-        abort ();
-    }
-}
-
-void
-unregister_close_hook (struct close_hook *link)
-{
-  struct close_hook *next = link->private_next;
-  struct close_hook *prev = link->private_prev;
-
-  if (next != NULL && prev != NULL)
-    {
-      /* The link is in use.  Remove it from the doubly linked list.  */
-      prev->private_next = next;
-      next->private_prev = prev;
-      /* Clear the link, to mark it unused.  */
-      link->private_next = NULL;
-      link->private_prev = NULL;
-      link->private_fn = NULL;
-    }
-}
-
-#endif
diff --git a/gl/close-hook.h b/gl/close-hook.h
deleted file mode 100644
index 283bebb..0000000
--- a/gl/close-hook.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Hook for making the close() function extensible.
-   Copyright (C) 2009-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/>.  */
-
-
-#ifndef CLOSE_HOOK_H
-#define CLOSE_HOOK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Currently, this entire code is only needed for the handling of sockets
-   on native Windows platforms.  */
-#if WINDOWS_SOCKETS
-
-
-/* An element of the list of close hooks.
-   The fields of this structure are considered private.  */
-struct close_hook
-{
-  /* Doubly linked list.  */
-  struct close_hook *private_next;
-  struct close_hook *private_prev;
-  /* Function that treats the types of FD that it knows about and calls
-     execute_close_hooks (FD, REMAINING_LIST) as a fallback.  */
-  int (*private_fn) (int fd, const struct close_hook *remaining_list);
-};
-
-/* This type of function closes FD, applying special knowledge for the FD
-   types it knows about, and calls execute_close_hooks (FD, REMAINING_LIST)
-   for the other FD types.  */
-typedef int (*close_hook_fn) (int fd, const struct close_hook *remaining_list);
-
-/* Execute the close hooks in REMAINING_LIST.
-   Return 0 or -1, like close() would do.  */
-extern int execute_close_hooks (int fd, const struct close_hook 
*remaining_list);
-
-/* Execute all close hooks.
-   Return 0 or -1, like close() would do.  */
-extern int execute_all_close_hooks (int fd);
-
-/* Add a function to the list of close hooks.
-   The LINK variable points to a piece of memory which is guaranteed to be
-   accessible until the corresponding call to unregister_close_hook.  */
-extern void register_close_hook (close_hook_fn hook, struct close_hook *link);
-
-/* Removes a function from the list of close hooks.  */
-extern void unregister_close_hook (struct close_hook *link);
-
-
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CLOSE_HOOK_H */
diff --git a/gl/close.c b/gl/close.c
index 1c06c16..c2197fe 100644
--- a/gl/close.c
+++ b/gl/close.c
@@ -19,18 +19,45 @@
 /* Specification.  */
 #include <unistd.h>
 
-#include "close-hook.h"
+#include <errno.h>
+
+#include "fd-hook.h"
+#include "msvc-inval.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
 rpl_close (int fd)
-#undef close
 {
 #if WINDOWS_SOCKETS
-  int retval = execute_all_close_hooks (fd);
+  int retval = execute_all_close_hooks (close_nothrow, fd);
 #else
-  int retval = close (fd);
+  int retval = close_nothrow (fd);
 #endif
 
 #if REPLACE_FCHDIR
diff --git a/gl/connect.c b/gl/connect.c
index ea03e77..afd13b9 100644
--- a/gl/connect.c
+++ b/gl/connect.c
@@ -32,16 +32,25 @@ int
 rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = connect (sock, sockaddr, len);
-  if (r < 0)
-    {
-      /* EINPROGRESS is not returned by WinSock 2.0; for backwards
-         compatibility, connect(2) uses EWOULDBLOCK.  */
-      if (WSAGetLastError () == WSAEWOULDBLOCK)
-        WSASetLastError (WSAEINPROGRESS);
 
-      set_winsock_errno ();
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = connect (sock, sockaddr, len);
+      if (r < 0)
+        {
+          /* EINPROGRESS is not returned by WinSock 2.0; for backwards
+             compatibility, connect(2) uses EWOULDBLOCK.  */
+          if (WSAGetLastError () == WSAEWOULDBLOCK)
+            WSASetLastError (WSAEINPROGRESS);
+
+          set_winsock_errno ();
+        }
+
+      return r;
     }
-
-  return r;
 }
diff --git a/gl/errno.in.h b/gl/errno.in.h
index a91f591..5a7533a 100644
--- a/gl/errno.in.h
+++ b/gl/errno.in.h
@@ -16,7 +16,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_ERRNO_H
+#ifndef address@hidden@_ERRNO_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -26,8 +26,8 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_ERRNO_H@
 
-#ifndef _GL_ERRNO_H
-#define _GL_ERRNO_H
+#ifndef address@hidden@_ERRNO_H
+#define address@hidden@_ERRNO_H
 
 
 /* On native Windows platforms, many macros are not defined.  */
@@ -147,6 +147,16 @@
 #  define GNULIB_defined_ENOTSUP 1
 # endif
 
+# ifndef ENETRESET
+#  define ENETRESET 2011
+#  define GNULIB_defined_ENETRESET 1
+# endif
+
+# ifndef ECONNABORTED
+#  define ECONNABORTED 2012
+#  define GNULIB_defined_ECONNABORTED 1
+# endif
+
 # ifndef ESTALE
 #  define ESTALE    2009
 #  define GNULIB_defined_ESTALE 1
@@ -163,5 +173,5 @@
 # endif
 
 
-#endif /* _GL_ERRNO_H */
-#endif /* _GL_ERRNO_H */
+#endif /* address@hidden@_ERRNO_H */
+#endif /* address@hidden@_ERRNO_H */
diff --git a/gl/error.c b/gl/error.c
index a2d1c1b..5ebe8bf 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -92,16 +92,22 @@ 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.  */
 # undef fcntl
 
-# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
+# if !HAVE_DECL_STRERROR_R
 #  ifndef HAVE_DECL_STRERROR_R
 "this configure-time declaration test was not run"
 #  endif
+#  if STRERROR_R_CHAR_P
 char *strerror_r ();
+#  else
+int strerror_r ();
+#  endif
 # endif
 
 /* The calling program should define program_name and set it to the
diff --git a/gl/fclose.c b/gl/fclose.c
deleted file mode 100644
index 1d7e85b..0000000
--- a/gl/fclose.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* fclose 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
-   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/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include <stdio.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-/* Override fclose() to call the overridden close().  */
-
-int
-rpl_fclose (FILE *fp)
-#undef fclose
-{
-  int saved_errno = 0;
-
-  if (fflush (fp))
-    saved_errno = errno;
-
-  if (close (fileno (fp)) < 0 && saved_errno == 0)
-    saved_errno = errno;
-
-  fclose (fp); /* will fail with errno = EBADF */
-
-  if (saved_errno != 0)
-    {
-      errno = saved_errno;
-      return EOF;
-    }
-  return 0;
-}
diff --git a/gl/fd-hook.c b/gl/fd-hook.c
new file mode 100644
index 0000000..b58300d
--- /dev/null
+++ b/gl/fd-hook.c
@@ -0,0 +1,116 @@
+/* Hook for making making file descriptor functions close(), ioctl() 
extensible.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+   Written by Bruno Haible <address@hidden>, 2009.
+
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "fd-hook.h"
+
+#include <stdlib.h>
+
+/* Currently, this entire code is only needed for the handling of sockets
+   on native Windows platforms.  */
+#if WINDOWS_SOCKETS
+
+/* The first and last link in the doubly linked list.
+   Initially the list is empty.  */
+static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
+
+int
+execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
+                     int fd)
+{
+  if (remaining_list == &anchor)
+    /* End of list reached.  */
+    return primary (fd);
+  else
+    return remaining_list->private_close_fn (remaining_list->private_next,
+                                             primary, fd);
+}
+
+int
+execute_all_close_hooks (gl_close_fn primary, int fd)
+{
+  return execute_close_hooks (anchor.private_next, primary, fd);
+}
+
+int
+execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
+                     int fd, int request, void *arg)
+{
+  if (remaining_list == &anchor)
+    /* End of list reached.  */
+    return primary (fd, request, arg);
+  else
+    return remaining_list->private_ioctl_fn (remaining_list->private_next,
+                                             primary, fd, request, arg);
+}
+
+int
+execute_all_ioctl_hooks (gl_ioctl_fn primary,
+                         int fd, int request, void *arg)
+{
+  return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
+}
+
+void
+register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct 
fd_hook *link)
+{
+  if (close_hook == NULL)
+    close_hook = execute_close_hooks;
+  if (ioctl_hook == NULL)
+    ioctl_hook = execute_ioctl_hooks;
+
+  if (link->private_next == NULL && link->private_prev == NULL)
+    {
+      /* Add the link to the doubly linked list.  */
+      link->private_next = anchor.private_next;
+      link->private_prev = &anchor;
+      link->private_close_fn = close_hook;
+      link->private_ioctl_fn = ioctl_hook;
+      anchor.private_next->private_prev = link;
+      anchor.private_next = link;
+    }
+  else
+    {
+      /* The link is already in use.  */
+      if (link->private_close_fn != close_hook
+          || link->private_ioctl_fn != ioctl_hook)
+        abort ();
+    }
+}
+
+void
+unregister_fd_hook (struct fd_hook *link)
+{
+  struct fd_hook *next = link->private_next;
+  struct fd_hook *prev = link->private_prev;
+
+  if (next != NULL && prev != NULL)
+    {
+      /* The link is in use.  Remove it from the doubly linked list.  */
+      prev->private_next = next;
+      next->private_prev = prev;
+      /* Clear the link, to mark it unused.  */
+      link->private_next = NULL;
+      link->private_prev = NULL;
+      link->private_close_fn = NULL;
+      link->private_ioctl_fn = NULL;
+    }
+}
+
+#endif
diff --git a/gl/fd-hook.h b/gl/fd-hook.h
new file mode 100644
index 0000000..ada4c87
--- /dev/null
+++ b/gl/fd-hook.h
@@ -0,0 +1,119 @@
+/* Hook for making making file descriptor functions close(), ioctl() 
extensible.
+   Copyright (C) 2009-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/>.  */
+
+
+#ifndef FD_HOOK_H
+#define FD_HOOK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Currently, this entire code is only needed for the handling of sockets
+   on native Windows platforms.  */
+#if WINDOWS_SOCKETS
+
+
+/* Type of function that closes FD.  */
+typedef int (*gl_close_fn) (int fd);
+
+/* Type of function that applies a control request to FD.  */
+typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
+
+/* An element of the list of file descriptor hooks.
+   In CLOS (Common Lisp Object System) speak, it consists of an "around"
+   method for the close() function and an "around" method for the ioctl()
+   function.
+   The fields of this structure are considered private.  */
+struct fd_hook
+{
+  /* Doubly linked list.  */
+  struct fd_hook *private_next;
+  struct fd_hook *private_prev;
+  /* Function that treats the types of FD that it knows about and calls
+     execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback.  */
+  int (*private_close_fn) (const struct fd_hook *remaining_list,
+                           gl_close_fn primary,
+                           int fd);
+  /* Function that treats the types of FD that it knows about and calls
+     execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
+     fallback.  */
+  int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
+                           gl_ioctl_fn primary,
+                           int fd, int request, void *arg);
+};
+
+/* This type of function closes FD, applying special knowledge for the FD
+   types it knows about, and calls
+   execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
+   for the other FD types.
+   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
+   and PRIMARY is the "primary" method for close().  */
+typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
+                              gl_close_fn primary,
+                              int fd);
+
+/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
+   Return 0 or -1, like close() would do.  */
+extern int execute_close_hooks (const struct fd_hook *remaining_list,
+                                gl_close_fn primary,
+                                int fd);
+
+/* Execute all close hooks, with PRIMARY as "primary" method.
+   Return 0 or -1, like close() would do.  */
+extern int execute_all_close_hooks (gl_close_fn primary, int fd);
+
+/* This type of function applies a control request to FD, applying special
+   knowledge for the FD types it knows about, and calls
+   execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
+   for the other FD types.
+   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
+   and PRIMARY is the "primary" method for ioctl().  */
+typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
+                              gl_ioctl_fn primary,
+                              int fd, int request, void *arg);
+
+/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
+   Return 0 or -1, like ioctl() would do.  */
+extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
+                                gl_ioctl_fn primary,
+                                int fd, int request, void *arg);
+
+/* Execute all ioctl hooks, with PRIMARY as "primary" method.
+   Return 0 or -1, like ioctl() would do.  */
+extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
+                                    int fd, int request, void *arg);
+
+/* Add a function pair to the list of file descriptor hooks.
+   CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
+   The LINK variable points to a piece of memory which is guaranteed to be
+   accessible until the corresponding call to unregister_fd_hook.  */
+extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn 
ioctl_hook,
+                              struct fd_hook *link);
+
+/* Removes a hook from the list of file descriptor hooks.  */
+extern void unregister_fd_hook (struct fd_hook *link);
+
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FD_HOOK_H */
diff --git a/gl/float.c b/gl/float.c
new file mode 100644
index 0000000..b05b40c
--- /dev/null
+++ b/gl/float.c
@@ -0,0 +1,33 @@
+/* Auxiliary definitions for <float.h>.
+   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
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <float.h>
+
+#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__
+const union gl_long_double_union gl_LDBL_MAX =
+  { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
+#else
+/* This declaration is solely to ensure that after preprocessing
+   this file is never empty.  */
+typedef int dummy;
+#endif
diff --git a/gl/float.in.h b/gl/float.in.h
index d32f20e..d5b2258 100644
--- a/gl/float.in.h
+++ b/gl/float.in.h
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#ifndef _GL_FLOAT_H
+#ifndef address@hidden@_FLOAT_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -25,10 +25,11 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_FLOAT_H@
 
-#ifndef _GL_FLOAT_H
-#define _GL_FLOAT_H
+#ifndef address@hidden@_FLOAT_H
+#define address@hidden@_FLOAT_H
 
 /* 'long double' properties.  */
+
 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
 /* Number of mantissa units, in base FLT_RADIX.  */
 # undef LDBL_MANT_DIG
@@ -59,5 +60,129 @@
 # define LDBL_MAX_10_EXP 4932
 #endif
 
-#endif /* _GL_FLOAT_H */
-#endif /* _GL_FLOAT_H */
+/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
+   precision in the compiler but 64 bits of precision at runtime.  See
+   <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>.  */
+#if defined __i386__ && defined __FreeBSD__
+/* Number of mantissa units, in base FLT_RADIX.  */
+# undef LDBL_MANT_DIG
+# define LDBL_MANT_DIG   64
+/* Number of decimal digits that is sufficient for representing a number.  */
+# undef LDBL_DIG
+# define LDBL_DIG        18
+/* x-1 where x is the smallest representable number > 1.  */
+# undef LDBL_EPSILON
+# define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 
*/
+/* Minimum e such that FLT_RADIX^(e-1) is a normalized number.  */
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number.  */
+# undef LDBL_MAX_EXP
+# define LDBL_MAX_EXP    16384
+/* Minimum positive normalized number.  */
+# undef LDBL_MIN
+# define LDBL_MIN        3.3621031431120935E-4932L /* = 0x1p-16382L */
+/* Maximum representable finite number.  */
+# undef LDBL_MAX
+/* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
+   But the largest literal that GCC allows us to write is
+   0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }.
+   So, define it like this through a reference to an external variable
+
+     const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 };
+     extern const long double LDBL_MAX;
+
+   Unfortunately, this is not a constant expression.  */
+union gl_long_double_union
+  {
+    struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
+    long double ld;
+  };
+extern const union gl_long_double_union gl_LDBL_MAX;
+# define LDBL_MAX (gl_LDBL_MAX.ld)
+/* Minimum e such that 10^e is in the range of normalized numbers.  */
+# undef LDBL_MIN_10_EXP
+# define LDBL_MIN_10_EXP (-4931)
+/* Maximum e such that 10^e is in the range of representable finite numbers.  
*/
+# undef LDBL_MAX_10_EXP
+# define LDBL_MAX_10_EXP 4932
+#endif
+
+/* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
+   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
+# undef LDBL_MIN_10_EXP
+# 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:
+     #define LDBL_MAX 1.79769313486231580793728971405302307166e308L
+   is too small, whereas
+     #define LDBL_MAX 1.79769313486231580793728971405302307167e308L
+   is too large.  Apparently a bug in GCC decimal-to-binary conversion.
+   Also, I can't get values larger than
+     #define LDBL63 ((long double) (1ULL << 63))
+     #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * 
LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
+     #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * 
LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
+     #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * 
LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 
* LDBL63)
+     #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 
9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
+   which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
+   So, define it like this through a reference to an external variable
+
+     const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / 
(double)134217728UL };
+     extern const long double LDBL_MAX;
+
+   or through a pointer cast
+
+     #define LDBL_MAX \
+       (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / 
(double)134217728UL / (double)134217728UL })
+
+   Unfortunately, this is not a constant expression, and the latter expression
+   does not work well when GCC is optimizing..  */
+union gl_long_double_union
+  {
+    struct { double hi; double lo; } dd;
+    long double ld;
+  };
+extern const union gl_long_double_union gl_LDBL_MAX;
+# define LDBL_MAX (gl_LDBL_MAX.ld)
+#endif
+
+/* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
+   On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, 
LDBL_EPSILON
+   are wrong.  */
+#if defined __sgi && (LDBL_MANT_DIG >= 106)
+# undef LDBL_MANT_DIG
+# define LDBL_MANT_DIG 106
+# if defined __GNUC__
+#  undef LDBL_MIN_EXP
+#  define LDBL_MIN_EXP DBL_MIN_EXP
+#  undef LDBL_MIN_10_EXP
+#  define LDBL_MIN_10_EXP DBL_MIN_10_EXP
+#  undef LDBL_MIN
+#  define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 
2^-1022 */
+#  undef LDBL_EPSILON
+#  define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 
*/
+# 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/fseek.c b/gl/fseek.c
new file mode 100644
index 0000000..bcb76d8
--- /dev/null
+++ b/gl/fseek.c
@@ -0,0 +1,30 @@
+/* An fseek() function that, together with fflush(), is POSIX compliant.
+   Copyright (C) 2007, 2009-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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+/* Get off_t.  */
+#include <unistd.h>
+
+int
+fseek (FILE *fp, long offset, int whence)
+{
+  /* Use the replacement fseeko function with all its workarounds.  */
+  return fseeko (fp, (off_t)offset, whence);
+}
diff --git a/gl/fseeko.c b/gl/fseeko.c
index 2dd4cdc..87d6638 100644
--- a/gl/fseeko.c
+++ b/gl/fseeko.c
@@ -69,6 +69,9 @@ fseeko (FILE *fp, off_t offset, int whence)
       && fp->_rcount == 0
       && fp->_wcount == 0
       && fp->_ungetc_count == 0)
+#elif defined __minix               /* Minix */
+  if (fp_->_ptr == fp_->_buf
+      && (fp_->_ptr == NULL || fp_->_count == 0))
 #elif defined _IOERR                /* AIX, HP-UX, IRIX, OSF/1, Solaris, 
OpenServer, mingw, NonStop Kernel */
   if (fp_->_ptr == fp_->_base
       && (fp_->_ptr == NULL || fp_->_cnt == 0))
@@ -90,14 +93,10 @@ fseeko (FILE *fp, off_t offset, int whence)
   #error "Please port gnulib fseeko.c to your platform! Look at the code in 
fpurge.c, then report this to bug-gnulib."
 #endif
     {
-      /* We get here when an fflush() call immediately preceded this one.  We
-         know there are no buffers.
-         POSIX requires us to modify the file descriptor's position.
-         But we cannot position beyond end of file here.  */
-      off_t pos =
-        lseek (fileno (fp),
-               whence == SEEK_END && offset > 0 ? 0 : offset,
-               whence);
+      /* We get here when an fflush() call immediately preceded this one (or
+         if ftell() has created buffers but no I/O has occurred on a
+         newly-opened stream).  We know there are no buffers.  */
+      off_t pos = lseek (fileno (fp), offset, whence);
       if (pos == -1)
         {
 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
@@ -108,6 +107,7 @@ fseeko (FILE *fp, off_t offset, int whence)
 
 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, 
Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
+      fp->_offset = pos;
 #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
 # if defined __CYGWIN__
       /* fp_->_offset is typed as an integer.  */
@@ -137,10 +137,7 @@ fseeko (FILE *fp, off_t offset, int whence)
       fp->__offset = pos;
       fp->__eof = 0;
 #endif
-      /* If we were not requested to position beyond end of file, we're
-         done.  */
-      if (!(whence == SEEK_END && offset > 0))
-        return 0;
+      return 0;
     }
   return fseeko (fp, offset, whence);
 }
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/ftell.c b/gl/ftell.c
new file mode 100644
index 0000000..74ec986
--- /dev/null
+++ b/gl/ftell.c
@@ -0,0 +1,37 @@
+/* An ftell() function that works around platform bugs.
+   Copyright (C) 2007-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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+
+long
+ftell (FILE *fp)
+{
+  /* Use the replacement ftello function with all its workarounds.  */
+  off_t offset = ftello (fp);
+  if (LONG_MIN <= offset && offset <= LONG_MAX)
+    return /* (long) */ offset;
+  else
+    {
+      errno = EOVERFLOW;
+      return -1;
+    }
+}
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c
index 402ba6f..052c9a0 100644
--- a/gl/gai_strerror.c
+++ b/gl/gai_strerror.c
@@ -32,6 +32,22 @@
 # define N_(String) String
 #endif
 
+#if HAVE_DECL_GAI_STRERROR
+
+# include <sys/socket.h>
+# undef gai_strerror
+# if HAVE_DECL_GAI_STRERRORA
+#  define gai_strerror gai_strerrorA
+# endif
+
+const char *
+rpl_gai_strerror (int code)
+{
+  return gai_strerror (code);
+}
+
+#else /* !HAVE_DECL_GAI_STRERROR */
+
 static struct
   {
     int code;
@@ -71,6 +87,7 @@ gai_strerror (int code)
 
   return _("Unknown error");
 }
-#ifdef _LIBC
+# ifdef _LIBC
 libc_hidden_def (gai_strerror)
-#endif
+# endif
+#endif /* !HAVE_DECL_GAI_STRERROR */
diff --git a/gl/getpass.c b/gl/getpass.c
index 37b35b3..90392f9 100644
--- a/gl/getpass.c
+++ b/gl/getpass.c
@@ -26,53 +26,53 @@
 
 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
 
-#include <stdbool.h>
-
-#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING
-# if HAVE_STDIO_EXT_H
-#  include <stdio_ext.h>
+# include <stdbool.h>
+
+# if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING
+#  if HAVE_STDIO_EXT_H
+#   include <stdio_ext.h>
+#  endif
+# else
+#  define __fsetlocking(stream, type)    /* empty */
 # endif
-#else
-# define __fsetlocking(stream, type)    /* empty */
-#endif
 
-#if HAVE_TERMIOS_H
-# include <termios.h>
-#endif
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#else
-# if !HAVE_DECL_FFLUSH_UNLOCKED
-#  undef fflush_unlocked
-#  define fflush_unlocked(x) fflush (x)
-# endif
-# if !HAVE_DECL_FLOCKFILE
-#  undef flockfile
-#  define flockfile(x) ((void) 0)
+# if HAVE_TERMIOS_H
+#  include <termios.h>
 # endif
-# if !HAVE_DECL_FUNLOCKFILE
-#  undef funlockfile
-#  define funlockfile(x) ((void) 0)
-# endif
-# if !HAVE_DECL_FPUTS_UNLOCKED
-#  undef fputs_unlocked
-#  define fputs_unlocked(str,stream) fputs (str, stream)
-# endif
-# if !HAVE_DECL_PUTC_UNLOCKED
-#  undef putc_unlocked
-#  define putc_unlocked(c,stream) putc (c, stream)
+
+# if USE_UNLOCKED_IO
+#  include "unlocked-io.h"
+# else
+#  if !HAVE_DECL_FFLUSH_UNLOCKED
+#   undef fflush_unlocked
+#   define fflush_unlocked(x) fflush (x)
+#  endif
+#  if !HAVE_DECL_FLOCKFILE
+#   undef flockfile
+#   define flockfile(x) ((void) 0)
+#  endif
+#  if !HAVE_DECL_FUNLOCKFILE
+#   undef funlockfile
+#   define funlockfile(x) ((void) 0)
+#  endif
+#  if !HAVE_DECL_FPUTS_UNLOCKED
+#   undef fputs_unlocked
+#   define fputs_unlocked(str,stream) fputs (str, stream)
+#  endif
+#  if !HAVE_DECL_PUTC_UNLOCKED
+#   undef putc_unlocked
+#   define putc_unlocked(c,stream) putc (c, stream)
+#  endif
 # endif
-#endif
 
 /* It is desirable to use this bit on systems that have it.
    The only bit of terminal state we want to twiddle is echoing, which is
    done in software; there is no need to change the state of the terminal
    hardware.  */
 
-#ifndef TCSASOFT
-# define TCSASOFT 0
-#endif
+# ifndef TCSASOFT
+#  define TCSASOFT 0
+# endif
 
 static void
 call_fclose (void *arg)
@@ -112,7 +112,7 @@ getpass (const char *prompt)
   flockfile (out);
 
   /* Turn echoing off if it is on now.  */
-#if HAVE_TCGETATTR
+# if HAVE_TCGETATTR
   if (tcgetattr (fileno (in), &t) == 0)
     {
       /* Save the old one. */
@@ -121,7 +121,7 @@ getpass (const char *prompt)
       t.c_lflag &= ~(ECHO | ISIG);
       tty_changed = (tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &t) == 0);
     }
-#endif
+# endif
 
   /* Write the prompt.  */
   fputs_unlocked (prompt, out);
@@ -158,10 +158,10 @@ getpass (const char *prompt)
     }
 
   /* Restore the original setting.  */
-#if HAVE_TCSETATTR
+# if HAVE_TCSETATTR
   if (tty_changed)
     tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s);
-#endif
+# endif
 
   funlockfile (out);
 
@@ -176,15 +176,15 @@ getpass (const char *prompt)
    improved by Simon Josefsson. */
 
 /* For PASS_MAX. */
-#include <limits.h>
+# include <limits.h>
 /* For _getch(). */
-#include <conio.h>
+# include <conio.h>
 /* For strdup(). */
-#include <string.h>
+# include <string.h>
 
-#ifndef PASS_MAX
-# define PASS_MAX 512
-#endif
+# ifndef PASS_MAX
+#  define PASS_MAX 512
+# endif
 
 char *
 getpass (const char *prompt)
diff --git a/gl/gettimeofday.c b/gl/gettimeofday.c
index e4ce951..adfb51f 100644
--- a/gl/gettimeofday.c
+++ b/gl/gettimeofday.c
@@ -40,10 +40,10 @@
 static struct tm tm_zero_buffer;
 static struct tm *localtime_buffer_addr = &tm_zero_buffer;
 
-#undef localtime
+# undef localtime
 extern struct tm *localtime (time_t const *);
 
-#undef gmtime
+# undef gmtime
 extern struct tm *gmtime (time_t const *);
 
 /* This is a wrapper for localtime.  It is used only on systems for which
@@ -79,7 +79,7 @@ rpl_gmtime (time_t const *timep)
 
 #if TZSET_CLOBBERS_LOCALTIME
 
-#undef tzset
+# undef tzset
 extern void tzset (void);
 
 /* This is a wrapper for tzset, for systems on which tzset may clobber
diff --git a/gl/glthread/lock.c b/gl/glthread/lock.c
new file mode 100644
index 0000000..64dbd3f
--- /dev/null
+++ b/gl/glthread/lock.c
@@ -0,0 +1,1058 @@
+/* Locking in multithreaded situations.
+   Copyright (C) 2005-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.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+#include <config.h>
+
+#include "glthread/lock.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+#  if !defined PTHREAD_RWLOCK_INITIALIZER
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_rwlock_init (&lock->rwlock, NULL);
+  if (err != 0)
+    return err;
+  lock->initialized = 1;
+  return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_rwlock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_rwlock_rdlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_rwlock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_rwlock_wrlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    return EINVAL;
+  return pthread_rwlock_unlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  if (!lock->initialized)
+    return EINVAL;
+  err = pthread_rwlock_destroy (&lock->rwlock);
+  if (err != 0)
+    return err;
+  lock->initialized = 0;
+  return 0;
+}
+
+#  endif
+
+# else
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_init (&lock->lock, NULL);
+  if (err != 0)
+    return err;
+  err = pthread_cond_init (&lock->waiting_readers, NULL);
+  if (err != 0)
+    return err;
+  err = pthread_cond_init (&lock->waiting_writers, NULL);
+  if (err != 0)
+    return err;
+  lock->waiting_writers_count = 0;
+  lock->runcount = 0;
+  return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  /* Test whether only readers are currently running, and whether the runcount
+     field will not overflow.  */
+  /* POSIX says: "It is implementation-defined whether the calling thread
+     acquires the lock when a writer does not hold the lock and there are
+     writers blocked on the lock."  Let's say, no: give the writers a higher
+     priority.  */
+  while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_readers.  */
+      err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
+      if (err != 0)
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return err;
+        }
+    }
+  lock->runcount++;
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  /* Test whether no readers or writers are currently running.  */
+  while (!(lock->runcount == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_writers.  */
+      lock->waiting_writers_count++;
+      err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
+      if (err != 0)
+        {
+          lock->waiting_writers_count--;
+          pthread_mutex_unlock (&lock->lock);
+          return err;
+        }
+      lock->waiting_writers_count--;
+    }
+  lock->runcount--; /* runcount becomes -1 */
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  if (lock->runcount < 0)
+    {
+      /* Drop a writer lock.  */
+      if (!(lock->runcount == -1))
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return EINVAL;
+        }
+      lock->runcount = 0;
+    }
+  else
+    {
+      /* Drop a reader lock.  */
+      if (!(lock->runcount > 0))
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return EINVAL;
+        }
+      lock->runcount--;
+    }
+  if (lock->runcount == 0)
+    {
+      /* POSIX recommends that "write locks shall take precedence over read
+         locks", to avoid "writer starvation".  */
+      if (lock->waiting_writers_count > 0)
+        {
+          /* Wake up one of the waiting writers.  */
+          err = pthread_cond_signal (&lock->waiting_writers);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->lock);
+              return err;
+            }
+        }
+      else
+        {
+          /* Wake up all waiting readers.  */
+          err = pthread_cond_broadcast (&lock->waiting_readers);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->lock);
+              return err;
+            }
+        }
+    }
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_destroy (&lock->lock);
+  if (err != 0)
+    return err;
+  err = pthread_cond_destroy (&lock->waiting_readers);
+  if (err != 0)
+    return err;
+  err = pthread_cond_destroy (&lock->waiting_writers);
+  if (err != 0)
+    return err;
+  return 0;
+}
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+#  if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined 
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_mutexattr_t attributes;
+  int err;
+
+  err = pthread_mutexattr_init (&attributes);
+  if (err != 0)
+    return err;
+  err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutex_init (lock, &attributes);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutexattr_destroy (&attributes);
+  if (err != 0)
+    return err;
+  return 0;
+}
+
+#  else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_mutexattr_t attributes;
+  int err;
+
+  err = pthread_mutexattr_init (&attributes);
+  if (err != 0)
+    return err;
+  err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutex_init (&lock->recmutex, &attributes);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutexattr_destroy (&attributes);
+  if (err != 0)
+    return err;
+  lock->initialized = 1;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_recursive_lock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_mutex_lock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (!lock->initialized)
+    return EINVAL;
+  return pthread_mutex_unlock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  if (!lock->initialized)
+    return EINVAL;
+  err = pthread_mutex_destroy (&lock->recmutex);
+  if (err != 0)
+    return err;
+  lock->initialized = 0;
+  return 0;
+}
+
+#  endif
+
+# else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_init (&lock->mutex, NULL);
+  if (err != 0)
+    return err;
+  lock->owner = (pthread_t) 0;
+  lock->depth = 0;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_t self = pthread_self ();
+  if (lock->owner != self)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->mutex);
+      if (err != 0)
+        return err;
+      lock->owner = self;
+    }
+  if (++(lock->depth) == 0) /* wraparound? */
+    {
+      lock->depth--;
+      return EAGAIN;
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != pthread_self ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = (pthread_t) 0;
+      return pthread_mutex_unlock (&lock->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != (pthread_t) 0)
+    return EBUSY;
+  return pthread_mutex_destroy (&lock->mutex);
+}
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT;
+
+int
+glthread_once_singlethreaded (pthread_once_t *once_control)
+{
+  /* We don't know whether pthread_once_t is an integer type, a floating-point
+     type, a pointer type, or a structure type.  */
+  char *firstbyte = (char *)once_control;
+  if (*firstbyte == *(const char *)&fresh_once)
+    {
+      /* First time use of once_control.  Invert the first byte.  */
+      *firstbyte = ~ *(const char *)&fresh_once;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static void
+glthread_once_call (void *arg)
+{
+  void (**gl_once_temp_addr) (void) = (void (**) (void)) arg;
+  void (*initfunction) (void) = *gl_once_temp_addr;
+  initfunction ();
+}
+
+int
+glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) 
(void))
+{
+  void (*temp) (void) = initfunction;
+  return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0);
+}
+
+int
+glthread_once_singlethreaded (pth_once_t *once_control)
+{
+  /* We know that pth_once_t is an integer type.  */
+  if (*once_control == PTH_ONCE_INIT)
+    {
+      /* First time use of once_control.  Invert the marker.  */
+      *once_control = ~ PTH_ONCE_INIT;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  err = mutex_init (&lock->mutex, USYNC_THREAD, NULL);
+  if (err != 0)
+    return err;
+  lock->owner = (thread_t) 0;
+  lock->depth = 0;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  thread_t self = thr_self ();
+  if (lock->owner != self)
+    {
+      int err;
+
+      err = mutex_lock (&lock->mutex);
+      if (err != 0)
+        return err;
+      lock->owner = self;
+    }
+  if (++(lock->depth) == 0) /* wraparound? */
+    {
+      lock->depth--;
+      return EAGAIN;
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != thr_self ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = (thread_t) 0;
+      return mutex_unlock (&lock->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != (thread_t) 0)
+    return EBUSY;
+  return mutex_destroy (&lock->mutex);
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+int
+glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) 
(void))
+{
+  if (!once_control->inited)
+    {
+      int err;
+
+      /* Use the mutex to guarantee that if another thread is already calling
+         the initfunction, this thread waits until it's finished.  */
+      err = mutex_lock (&once_control->mutex);
+      if (err != 0)
+        return err;
+      if (!once_control->inited)
+        {
+          once_control->inited = 1;
+          initfunction ();
+        }
+      return mutex_unlock (&once_control->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_once_singlethreaded (gl_once_t *once_control)
+{
+  /* We know that gl_once_t contains an integer type.  */
+  if (!once_control->inited)
+    {
+      /* First time use of once_control.  Invert the marker.  */
+      once_control->inited = ~ 0;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+void
+glthread_lock_init_func (gl_lock_t *lock)
+{
+  InitializeCriticalSection (&lock->lock);
+  lock->guard.done = 1;
+}
+
+int
+glthread_lock_lock_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_lock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_lock_unlock_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_lock_destroy_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  DeleteCriticalSection (&lock->lock);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* In this file, the waitqueues are implemented as circular arrays.  */
+#define gl_waitqueue_t gl_carray_waitqueue_t
+
+static inline void
+gl_waitqueue_init (gl_waitqueue_t *wq)
+{
+  wq->array = NULL;
+  wq->count = 0;
+  wq->alloc = 0;
+  wq->offset = 0;
+}
+
+/* Enqueues the current thread, represented by an event, in a wait queue.
+   Returns INVALID_HANDLE_VALUE if an allocation failure occurs.  */
+static HANDLE
+gl_waitqueue_add (gl_waitqueue_t *wq)
+{
+  HANDLE event;
+  unsigned int index;
+
+  if (wq->count == wq->alloc)
+    {
+      unsigned int new_alloc = 2 * wq->alloc + 1;
+      HANDLE *new_array =
+        (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
+      if (new_array == NULL)
+        /* No more memory.  */
+        return INVALID_HANDLE_VALUE;
+      /* Now is a good opportunity to rotate the array so that its contents
+         starts at offset 0.  */
+      if (wq->offset > 0)
+        {
+          unsigned int old_count = wq->count;
+          unsigned int old_alloc = wq->alloc;
+          unsigned int old_offset = wq->offset;
+          unsigned int i;
+          if (old_offset + old_count > old_alloc)
+            {
+              unsigned int limit = old_offset + old_count - old_alloc;
+              for (i = 0; i < limit; i++)
+                new_array[old_alloc + i] = new_array[i];
+            }
+          for (i = 0; i < old_count; i++)
+            new_array[i] = new_array[old_offset + i];
+          wq->offset = 0;
+        }
+      wq->array = new_array;
+      wq->alloc = new_alloc;
+    }
+  /* Whether the created event is a manual-reset one or an auto-reset one,
+     does not matter, since we will wait on it only once.  */
+  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  if (event == INVALID_HANDLE_VALUE)
+    /* No way to allocate an event.  */
+    return INVALID_HANDLE_VALUE;
+  index = wq->offset + wq->count;
+  if (index >= wq->alloc)
+    index -= wq->alloc;
+  wq->array[index] = event;
+  wq->count++;
+  return event;
+}
+
+/* Notifies the first thread from a wait queue and dequeues it.  */
+static inline void
+gl_waitqueue_notify_first (gl_waitqueue_t *wq)
+{
+  SetEvent (wq->array[wq->offset + 0]);
+  wq->offset++;
+  wq->count--;
+  if (wq->count == 0 || wq->offset == wq->alloc)
+    wq->offset = 0;
+}
+
+/* Notifies all threads from a wait queue and dequeues them all.  */
+static inline void
+gl_waitqueue_notify_all (gl_waitqueue_t *wq)
+{
+  unsigned int i;
+
+  for (i = 0; i < wq->count; i++)
+    {
+      unsigned int index = wq->offset + i;
+      if (index >= wq->alloc)
+        index -= wq->alloc;
+      SetEvent (wq->array[index]);
+    }
+  wq->count = 0;
+  wq->offset = 0;
+}
+
+void
+glthread_rwlock_init_func (gl_rwlock_t *lock)
+{
+  InitializeCriticalSection (&lock->lock);
+  gl_waitqueue_init (&lock->waiting_readers);
+  gl_waitqueue_init (&lock->waiting_writers);
+  lock->runcount = 0;
+  lock->guard.done = 1;
+}
+
+int
+glthread_rwlock_rdlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_rwlock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  /* Test whether only readers are currently running, and whether the runcount
+     field will not overflow.  */
+  if (!(lock->runcount + 1 > 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_readers.  */
+      HANDLE event = gl_waitqueue_add (&lock->waiting_readers);
+      if (event != INVALID_HANDLE_VALUE)
+        {
+          DWORD result;
+          LeaveCriticalSection (&lock->lock);
+          /* Wait until another thread signals this event.  */
+          result = WaitForSingleObject (event, INFINITE);
+          if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+            abort ();
+          CloseHandle (event);
+          /* The thread which signalled the event already did the bookkeeping:
+             removed us from the waiting_readers, incremented lock->runcount.  
*/
+          if (!(lock->runcount > 0))
+            abort ();
+          return 0;
+        }
+      else
+        {
+          /* Allocation failure.  Weird.  */
+          do
+            {
+              LeaveCriticalSection (&lock->lock);
+              Sleep (1);
+              EnterCriticalSection (&lock->lock);
+            }
+          while (!(lock->runcount + 1 > 0));
+        }
+    }
+  lock->runcount++;
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_wrlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_rwlock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  /* Test whether no readers or writers are currently running.  */
+  if (!(lock->runcount == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_writers.  */
+      HANDLE event = gl_waitqueue_add (&lock->waiting_writers);
+      if (event != INVALID_HANDLE_VALUE)
+        {
+          DWORD result;
+          LeaveCriticalSection (&lock->lock);
+          /* Wait until another thread signals this event.  */
+          result = WaitForSingleObject (event, INFINITE);
+          if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+            abort ();
+          CloseHandle (event);
+          /* The thread which signalled the event already did the bookkeeping:
+             removed us from the waiting_writers, set lock->runcount = -1.  */
+          if (!(lock->runcount == -1))
+            abort ();
+          return 0;
+        }
+      else
+        {
+          /* Allocation failure.  Weird.  */
+          do
+            {
+              LeaveCriticalSection (&lock->lock);
+              Sleep (1);
+              EnterCriticalSection (&lock->lock);
+            }
+          while (!(lock->runcount == 0));
+        }
+    }
+  lock->runcount--; /* runcount becomes -1 */
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_unlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  EnterCriticalSection (&lock->lock);
+  if (lock->runcount < 0)
+    {
+      /* Drop a writer lock.  */
+      if (!(lock->runcount == -1))
+        abort ();
+      lock->runcount = 0;
+    }
+  else
+    {
+      /* Drop a reader lock.  */
+      if (!(lock->runcount > 0))
+        {
+          LeaveCriticalSection (&lock->lock);
+          return EPERM;
+        }
+      lock->runcount--;
+    }
+  if (lock->runcount == 0)
+    {
+      /* POSIX recommends that "write locks shall take precedence over read
+         locks", to avoid "writer starvation".  */
+      if (lock->waiting_writers.count > 0)
+        {
+          /* Wake up one of the waiting writers.  */
+          lock->runcount--;
+          gl_waitqueue_notify_first (&lock->waiting_writers);
+        }
+      else
+        {
+          /* Wake up all waiting readers.  */
+          lock->runcount += lock->waiting_readers.count;
+          gl_waitqueue_notify_all (&lock->waiting_readers);
+        }
+    }
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_destroy_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  if (lock->runcount != 0)
+    return EBUSY;
+  DeleteCriticalSection (&lock->lock);
+  if (lock->waiting_readers.array != NULL)
+    free (lock->waiting_readers.array);
+  if (lock->waiting_writers.array != NULL)
+    free (lock->waiting_writers.array);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+void
+glthread_recursive_lock_init_func (gl_recursive_lock_t *lock)
+{
+  lock->owner = 0;
+  lock->depth = 0;
+  InitializeCriticalSection (&lock->lock);
+  lock->guard.done = 1;
+}
+
+int
+glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_recursive_lock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  {
+    DWORD self = GetCurrentThreadId ();
+    if (lock->owner != self)
+      {
+        EnterCriticalSection (&lock->lock);
+        lock->owner = self;
+      }
+    if (++(lock->depth) == 0) /* wraparound? */
+      {
+        lock->depth--;
+        return EAGAIN;
+      }
+  }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != GetCurrentThreadId ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = 0;
+      LeaveCriticalSection (&lock->lock);
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != 0)
+    return EBUSY;
+  DeleteCriticalSection (&lock->lock);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+void
+glthread_once_func (gl_once_t *once_control, void (*initfunction) (void))
+{
+  if (once_control->inited <= 0)
+    {
+      if (InterlockedIncrement (&once_control->started) == 0)
+        {
+          /* This thread is the first one to come to this once_control.  */
+          InitializeCriticalSection (&once_control->lock);
+          EnterCriticalSection (&once_control->lock);
+          once_control->inited = 0;
+          initfunction ();
+          once_control->inited = 1;
+          LeaveCriticalSection (&once_control->lock);
+        }
+      else
+        {
+          /* Undo last operation.  */
+          InterlockedDecrement (&once_control->started);
+          /* Some other thread has already started the initialization.
+             Yield the CPU while waiting for the other thread to finish
+             initializing and taking the lock.  */
+          while (once_control->inited < 0)
+            Sleep (0);
+          if (once_control->inited <= 0)
+            {
+              /* Take the lock.  This blocks until the other thread has
+                 finished calling the initfunction.  */
+              EnterCriticalSection (&once_control->lock);
+              LeaveCriticalSection (&once_control->lock);
+              if (!(once_control->inited > 0))
+                abort ();
+            }
+        }
+    }
+}
+
+#endif
+
+/* ========================================================================= */
diff --git a/gl/glthread/lock.h b/gl/glthread/lock.h
new file mode 100644
index 0000000..6267500
--- /dev/null
+++ b/gl/glthread/lock.h
@@ -0,0 +1,927 @@
+/* Locking in multithreaded situations.
+   Copyright (C) 2005-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.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+/* This file contains locking primitives for use with a given thread library.
+   It does not contain primitives for creating threads or for other
+   synchronization primitives.
+
+   Normal (non-recursive) locks:
+     Type:                gl_lock_t
+     Declaration:         gl_lock_define(extern, name)
+     Initializer:         gl_lock_define_initialized(, name)
+     Initialization:      gl_lock_init (name);
+     Taking the lock:     gl_lock_lock (name);
+     Releasing the lock:  gl_lock_unlock (name);
+     De-initialization:   gl_lock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_lock_init (&name);
+     Taking the lock:     err = glthread_lock_lock (&name);
+     Releasing the lock:  err = glthread_lock_unlock (&name);
+     De-initialization:   err = glthread_lock_destroy (&name);
+
+   Read-Write (non-recursive) locks:
+     Type:                gl_rwlock_t
+     Declaration:         gl_rwlock_define(extern, name)
+     Initializer:         gl_rwlock_define_initialized(, name)
+     Initialization:      gl_rwlock_init (name);
+     Taking the lock:     gl_rwlock_rdlock (name);
+                          gl_rwlock_wrlock (name);
+     Releasing the lock:  gl_rwlock_unlock (name);
+     De-initialization:   gl_rwlock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_rwlock_init (&name);
+     Taking the lock:     err = glthread_rwlock_rdlock (&name);
+                          err = glthread_rwlock_wrlock (&name);
+     Releasing the lock:  err = glthread_rwlock_unlock (&name);
+     De-initialization:   err = glthread_rwlock_destroy (&name);
+
+   Recursive locks:
+     Type:                gl_recursive_lock_t
+     Declaration:         gl_recursive_lock_define(extern, name)
+     Initializer:         gl_recursive_lock_define_initialized(, name)
+     Initialization:      gl_recursive_lock_init (name);
+     Taking the lock:     gl_recursive_lock_lock (name);
+     Releasing the lock:  gl_recursive_lock_unlock (name);
+     De-initialization:   gl_recursive_lock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_recursive_lock_init (&name);
+     Taking the lock:     err = glthread_recursive_lock_lock (&name);
+     Releasing the lock:  err = glthread_recursive_lock_unlock (&name);
+     De-initialization:   err = glthread_recursive_lock_destroy (&name);
+
+  Once-only execution:
+     Type:                gl_once_t
+     Initializer:         gl_once_define(extern, name)
+     Execution:           gl_once (name, initfunction);
+   Equivalent functions with control of error handling:
+     Execution:           err = glthread_once (&name, initfunction);
+*/
+
+
+#ifndef _LOCK_H
+#define _LOCK_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime.  */
+#  define pthread_in_use() \
+     glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library.  */
+
+/* Weak references avoid dragging in external libraries if the other parts
+   of the program don't use them.  Here we use them, because we don't want
+   every program that uses libintl to depend on libpthread.  This assumes
+   that libpthread would not be loaded after libintl; i.e. if libintl is
+   loaded first, by an executable that does not depend on libpthread, and
+   then a module is dynamically loaded that depends on libpthread, libintl
+   will not be multithread-safe.  */
+
+/* The way to test at runtime whether libpthread is present is to test
+   whether a function pointer's value, such as &pthread_mutex_init, is
+   non-NULL.  However, some versions of GCC have a bug through which, in
+   PIC mode, &foo != NULL always evaluates to true if there is a direct
+   call to foo(...) in the same function.  To avoid this, we test the
+   address of a function in libpthread that we don't use.  */
+
+#  pragma weak pthread_mutex_init
+#  pragma weak pthread_mutex_lock
+#  pragma weak pthread_mutex_unlock
+#  pragma weak pthread_mutex_destroy
+#  pragma weak pthread_rwlock_init
+#  pragma weak pthread_rwlock_rdlock
+#  pragma weak pthread_rwlock_wrlock
+#  pragma weak pthread_rwlock_unlock
+#  pragma weak pthread_rwlock_destroy
+#  pragma weak pthread_once
+#  pragma weak pthread_cond_init
+#  pragma weak pthread_cond_wait
+#  pragma weak pthread_cond_signal
+#  pragma weak pthread_cond_broadcast
+#  pragma weak pthread_cond_destroy
+#  pragma weak pthread_mutexattr_init
+#  pragma weak pthread_mutexattr_settype
+#  pragma weak pthread_mutexattr_destroy
+#  ifndef pthread_self
+#   pragma weak pthread_self
+#  endif
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   pragma weak pthread_cancel
+#   define pthread_in_use() (pthread_cancel != NULL)
+#  endif
+
+# else
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   define pthread_in_use() 1
+#  endif
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pthread_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    PTHREAD_MUTEX_INITIALIZER
+# define glthread_lock_init(LOCK) \
+    (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+    (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+    (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+    (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+#  ifdef PTHREAD_RWLOCK_INITIALIZER
+
+typedef pthread_rwlock_t gl_rwlock_t;
+#   define gl_rwlock_define(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_rwlock_t NAME;
+#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
+#   define gl_rwlock_initializer \
+      PTHREAD_RWLOCK_INITIALIZER
+#   define glthread_rwlock_init(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
+#   define glthread_rwlock_rdlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
+#   define glthread_rwlock_wrlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0)
+#   define glthread_rwlock_unlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0)
+#   define glthread_rwlock_destroy(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0)
+
+#  else
+
+typedef struct
+        {
+          int initialized;
+          pthread_mutex_t guard;   /* protects the initialization */
+          pthread_rwlock_t rwlock; /* read-write lock */
+        }
+        gl_rwlock_t;
+#   define gl_rwlock_define(STORAGECLASS, NAME) \
+      STORAGECLASS gl_rwlock_t NAME;
+#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+#   define gl_rwlock_initializer \
+      { 0, PTHREAD_MUTEX_INITIALIZER }
+#   define glthread_rwlock_init(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_rdlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_wrlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_unlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_destroy(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+#  endif
+
+# else
+
+typedef struct
+        {
+          pthread_mutex_t lock; /* protects the remaining fields */
+          pthread_cond_t waiting_readers; /* waiting readers */
+          pthread_cond_t waiting_writers; /* waiting writers */
+          unsigned int waiting_writers_count; /* number of waiting writers */
+          int runcount; /* number of readers running, or -1 when a writer runs 
*/
+        }
+        gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 
PTHREAD_COND_INITIALIZER, 0, 0 }
+# define glthread_rwlock_init(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+#  if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined 
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+typedef pthread_mutex_t gl_recursive_lock_t;
+#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_mutex_t NAME;
+#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer;
+#   ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#    define gl_recursive_lock_initializer \
+       PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#   else
+#    define gl_recursive_lock_initializer \
+       PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#   endif
+#   define glthread_recursive_lock_init(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_lock(LOCK) \
+      (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+#   define glthread_recursive_lock_unlock(LOCK) \
+      (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+#   define glthread_recursive_lock_destroy(LOCK) \
+      (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+
+#  else
+
+typedef struct
+        {
+          pthread_mutex_t recmutex; /* recursive mutex */
+          pthread_mutex_t guard;    /* protects the initialization */
+          int initialized;
+        }
+        gl_recursive_lock_t;
+#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
+      STORAGECLASS gl_recursive_lock_t NAME;
+#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+#   define gl_recursive_lock_initializer \
+      { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }
+#   define glthread_recursive_lock_init(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_lock(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_unlock(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) 
: 0)
+#   define glthread_recursive_lock_destroy(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded 
(LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+#  endif
+
+# else
+
+/* Old versions of POSIX threads on Solaris did not have recursive locks.
+   We have to implement them ourselves.  */
+
+typedef struct
+        {
+          pthread_mutex_t mutex;
+          pthread_t owner;
+          unsigned long depth;
+        }
+        gl_recursive_lock_t;
+#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
+     STORAGECLASS gl_recursive_lock_t NAME;
+#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+#  define gl_recursive_lock_initializer \
+     { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }
+#  define glthread_recursive_lock_init(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#  define glthread_recursive_lock_lock(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 
0)
+#  define glthread_recursive_lock_unlock(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) 
: 0)
+#  define glthread_recursive_lock_destroy(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) 
: 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pthread_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (pthread_in_use ()                                                         
\
+     ? pthread_once (ONCE_CONTROL, INITFUNCTION)                               
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_singlethreaded (pthread_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library.  */
+
+#  pragma weak pth_mutex_init
+#  pragma weak pth_mutex_acquire
+#  pragma weak pth_mutex_release
+#  pragma weak pth_rwlock_init
+#  pragma weak pth_rwlock_acquire
+#  pragma weak pth_rwlock_release
+#  pragma weak pth_once
+
+#  pragma weak pth_cancel
+#  define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+#  define pth_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pth_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS pth_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    PTH_MUTEX_INIT
+# define glthread_lock_init(LOCK) \
+    (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+# define glthread_lock_lock(LOCK) \
+    (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+# define glthread_lock_unlock(LOCK) \
+    (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+# define glthread_lock_destroy(LOCK) \
+    ((void)(LOCK), 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef pth_rwlock_t gl_rwlock_t;
+#  define gl_rwlock_define(STORAGECLASS, NAME) \
+     STORAGECLASS pth_rwlock_t NAME;
+#  define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
+#  define gl_rwlock_initializer \
+     PTH_RWLOCK_INIT
+#  define glthread_rwlock_init(LOCK) \
+     (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
+#  define glthread_rwlock_rdlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? 
errno : 0)
+#  define glthread_rwlock_wrlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? 
errno : 0)
+#  define glthread_rwlock_unlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
+#  define glthread_rwlock_destroy(LOCK) \
+     ((void)(LOCK), 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* In Pth, mutexes are recursive by default.  */
+typedef pth_mutex_t gl_recursive_lock_t;
+#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
+     STORAGECLASS pth_mutex_t NAME;
+#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
+#  define gl_recursive_lock_initializer \
+     PTH_MUTEX_INIT
+#  define glthread_recursive_lock_init(LOCK) \
+     (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+#  define glthread_recursive_lock_lock(LOCK) \
+     (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+#  define glthread_recursive_lock_unlock(LOCK) \
+     (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+#  define glthread_recursive_lock_destroy(LOCK) \
+     ((void)(LOCK), 0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pth_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (pth_in_use ()                                                             
\
+     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_multithreaded (pth_once_t *once_control, void 
(*initfunction) (void));
+extern int glthread_once_singlethreaded (pth_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+# include <synch.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library.  */
+
+#  pragma weak mutex_init
+#  pragma weak mutex_lock
+#  pragma weak mutex_unlock
+#  pragma weak mutex_destroy
+#  pragma weak rwlock_init
+#  pragma weak rw_rdlock
+#  pragma weak rw_wrlock
+#  pragma weak rw_unlock
+#  pragma weak rwlock_destroy
+#  pragma weak thr_self
+
+#  pragma weak thr_suspend
+#  define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+#  define thread_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    DEFAULTMUTEX
+# define glthread_lock_init(LOCK) \
+    (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+    (thread_in_use () ? mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+    (thread_in_use () ? mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+    (thread_in_use () ? mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef rwlock_t gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    DEFAULTRWLOCK
+# define glthread_rwlock_init(LOCK) \
+    (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    (thread_in_use () ? rw_rdlock (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+    (thread_in_use () ? rw_wrlock (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+    (thread_in_use () ? rw_unlock (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+    (thread_in_use () ? rwlock_destroy (LOCK) : 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* Old Solaris threads did not have recursive locks.
+   We have to implement them ourselves.  */
+
+typedef struct
+        {
+          mutex_t mutex;
+          thread_t owner;
+          unsigned long depth;
+        }
+        gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+    { DEFAULTMUTEX, (thread_t) 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 
0)
+# define glthread_recursive_lock_destroy(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 
0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+        {
+          volatile int inited;
+          mutex_t mutex;
+        }
+        gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (thread_in_use ()                                                          
\
+     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_multithreaded (gl_once_t *once_control, void 
(*initfunction) (void));
+extern int glthread_once_singlethreaded (gl_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* We can use CRITICAL_SECTION directly, rather than the Win32 Event, Mutex,
+   Semaphore types, because
+     - we need only to synchronize inside a single process (address space),
+       not inter-process locking,
+     - we don't need to support trylock operations.  (TryEnterCriticalSection
+       does not work on Windows 95/98/ME.  Packages that need trylock usually
+       define their own mutex type.)  */
+
+/* There is no way to statically initialize a CRITICAL_SECTION.  It needs
+   to be done lazily, once only.  For this we need spinlocks.  */
+
+typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          CRITICAL_SECTION lock;
+        }
+        gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_lock_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    { { 0, -1 } }
+# define glthread_lock_init(LOCK) \
+    (glthread_lock_init_func (LOCK), 0)
+# define glthread_lock_lock(LOCK) \
+    glthread_lock_lock_func (LOCK)
+# define glthread_lock_unlock(LOCK) \
+    glthread_lock_unlock_func (LOCK)
+# define glthread_lock_destroy(LOCK) \
+    glthread_lock_destroy_func (LOCK)
+extern void glthread_lock_init_func (gl_lock_t *lock);
+extern int glthread_lock_lock_func (gl_lock_t *lock);
+extern int glthread_lock_unlock_func (gl_lock_t *lock);
+extern int glthread_lock_destroy_func (gl_lock_t *lock);
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* It is impossible to implement read-write locks using plain locks, without
+   introducing an extra thread dedicated to managing read-write locks.
+   Therefore here we need to use the low-level Event type.  */
+
+typedef struct
+        {
+          HANDLE *array; /* array of waiting threads, each represented by an 
event */
+          unsigned int count; /* number of waiting threads */
+          unsigned int alloc; /* length of allocated array */
+          unsigned int offset; /* index of first waiting thread in array */
+        }
+        gl_carray_waitqueue_t;
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          CRITICAL_SECTION lock; /* protects the remaining fields */
+          gl_carray_waitqueue_t waiting_readers; /* waiting readers */
+          gl_carray_waitqueue_t waiting_writers; /* waiting writers */
+          int runcount; /* number of readers running, or -1 when a writer runs 
*/
+        }
+        gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    { { 0, -1 } }
+# define glthread_rwlock_init(LOCK) \
+    (glthread_rwlock_init_func (LOCK), 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    glthread_rwlock_rdlock_func (LOCK)
+# define glthread_rwlock_wrlock(LOCK) \
+    glthread_rwlock_wrlock_func (LOCK)
+# define glthread_rwlock_unlock(LOCK) \
+    glthread_rwlock_unlock_func (LOCK)
+# define glthread_rwlock_destroy(LOCK) \
+    glthread_rwlock_destroy_func (LOCK)
+extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* The Win32 documentation says that CRITICAL_SECTION already implements a
+   recursive lock.  But we need not rely on it: It's easy to implement a
+   recursive lock without this assumption.  */
+
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          DWORD owner;
+          unsigned long depth;
+          CRITICAL_SECTION lock;
+        }
+        gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+    { { 0, -1 }, 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+    (glthread_recursive_lock_init_func (LOCK), 0)
+# define glthread_recursive_lock_lock(LOCK) \
+    glthread_recursive_lock_lock_func (LOCK)
+# define glthread_recursive_lock_unlock(LOCK) \
+    glthread_recursive_lock_unlock_func (LOCK)
+# define glthread_recursive_lock_destroy(LOCK) \
+    glthread_recursive_lock_destroy_func (LOCK)
+extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+        {
+          volatile int inited;
+          volatile long started;
+          CRITICAL_SECTION lock;
+        }
+        gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = { -1, -1 };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0)
+extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) 
(void));
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef int gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME)
+# define gl_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_lock_init(NAME) 0
+# define glthread_lock_lock(NAME) 0
+# define glthread_lock_unlock(NAME) 0
+# define glthread_lock_destroy(NAME) 0
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef int gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME)
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME)
+# define glthread_rwlock_init(NAME) 0
+# define glthread_rwlock_rdlock(NAME) 0
+# define glthread_rwlock_wrlock(NAME) 0
+# define glthread_rwlock_unlock(NAME) 0
+# define glthread_rwlock_destroy(NAME) 0
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+typedef int gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME)
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_recursive_lock_init(NAME) 0
+# define glthread_recursive_lock_lock(NAME) 0
+# define glthread_recursive_lock_unlock(NAME) 0
+# define glthread_recursive_lock_destroy(NAME) 0
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef int gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = 0;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0)
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+#define gl_lock_init(NAME) \
+   do                                  \
+     {                                 \
+       if (glthread_lock_init (&NAME)) \
+         abort ();                     \
+     }                                 \
+   while (0)
+#define gl_lock_lock(NAME) \
+   do                                  \
+     {                                 \
+       if (glthread_lock_lock (&NAME)) \
+         abort ();                     \
+     }                                 \
+   while (0)
+#define gl_lock_unlock(NAME) \
+   do                                    \
+     {                                   \
+       if (glthread_lock_unlock (&NAME)) \
+         abort ();                       \
+     }                                   \
+   while (0)
+#define gl_lock_destroy(NAME) \
+   do                                     \
+     {                                    \
+       if (glthread_lock_destroy (&NAME)) \
+         abort ();                        \
+     }                                    \
+   while (0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+#define gl_rwlock_init(NAME) \
+   do                                    \
+     {                                   \
+       if (glthread_rwlock_init (&NAME)) \
+         abort ();                       \
+     }                                   \
+   while (0)
+#define gl_rwlock_rdlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_rdlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_wrlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_wrlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_unlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_unlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_destroy(NAME) \
+   do                                       \
+     {                                      \
+       if (glthread_rwlock_destroy (&NAME)) \
+         abort ();                          \
+     }                                      \
+   while (0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+#define gl_recursive_lock_init(NAME) \
+   do                                            \
+     {                                           \
+       if (glthread_recursive_lock_init (&NAME)) \
+         abort ();                               \
+     }                                           \
+   while (0)
+#define gl_recursive_lock_lock(NAME) \
+   do                                            \
+     {                                           \
+       if (glthread_recursive_lock_lock (&NAME)) \
+         abort ();                               \
+     }                                           \
+   while (0)
+#define gl_recursive_lock_unlock(NAME) \
+   do                                              \
+     {                                             \
+       if (glthread_recursive_lock_unlock (&NAME)) \
+         abort ();                                 \
+     }                                             \
+   while (0)
+#define gl_recursive_lock_destroy(NAME) \
+   do                                               \
+     {                                              \
+       if (glthread_recursive_lock_destroy (&NAME)) \
+         abort ();                                  \
+     }                                              \
+   while (0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+#define gl_once(NAME, INITFUNCTION) \
+   do                                           \
+     {                                          \
+       if (glthread_once (&NAME, INITFUNCTION)) \
+         abort ();                              \
+     }                                          \
+   while (0)
+
+/* ========================================================================= */
+
+#endif /* _LOCK_H */
diff --git a/gl/glthread/threadlib.c b/gl/glthread/threadlib.c
new file mode 100644
index 0000000..646defa
--- /dev/null
+++ b/gl/glthread/threadlib.c
@@ -0,0 +1,74 @@
+/* Multithreading primitives.
+   Copyright (C) 2005-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.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.  */
+
+#include <config.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+# include <stdlib.h>
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The function to be executed by a dummy thread.  */
+static void *
+dummy_thread_func (void *arg)
+{
+  return arg;
+}
+
+int
+glthread_in_use (void)
+{
+  static int tested;
+  static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+  if (!tested)
+    {
+      pthread_t thread;
+
+      if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
+        /* Thread creation failed.  */
+        result = 0;
+      else
+        {
+          /* Thread creation works.  */
+          void *retval;
+          if (pthread_join (thread, &retval) != 0)
+            abort ();
+          result = 1;
+        }
+      tested = 1;
+    }
+  return result;
+}
+
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+/* This declaration is solely to ensure that after preprocessing
+   this file is never empty.  */
+typedef int dummy;
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
index c1b3b70..c11b1e0 100644
--- a/gl/inet_ntop.c
+++ b/gl/inet_ntop.c
@@ -38,12 +38,25 @@
 /* Specification.  */
 #include <arpa/inet.h>
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#if HAVE_DECL_INET_NTOP
 
-#define NS_IN6ADDRSZ 16
-#define NS_INT16SZ 2
+# undef inet_ntop
+
+const char *
+rpl_inet_ntop (int af, const void *restrict src,
+               char *restrict dst, socklen_t cnt)
+{
+  return inet_ntop (af, src, dst, cnt);
+}
+
+#else
+
+# include <stdio.h>
+# include <string.h>
+# include <errno.h>
+
+# define NS_IN6ADDRSZ 16
+# define NS_INT16SZ 2
 
 /*
  * WARNING: Don't even consider trying to compile this on a system where
@@ -52,9 +65,9 @@
 typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1];
 
 static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t 
size);
-#if HAVE_IPV6
+# if HAVE_IPV6
 static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t 
size);
-#endif
+# endif
 
 
 /* char *
@@ -71,15 +84,15 @@ inet_ntop (int af, const void *restrict src,
 {
   switch (af)
     {
-#if HAVE_IPV4
+# if HAVE_IPV4
     case AF_INET:
       return (inet_ntop4 (src, dst, cnt));
-#endif
+# endif
 
-#if HAVE_IPV6
+# if HAVE_IPV6
     case AF_INET6:
       return (inet_ntop6 (src, dst, cnt));
-#endif
+# endif
 
     default:
       errno = EAFNOSUPPORT;
@@ -118,7 +131,7 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t 
size)
   return strcpy (dst, tmp);
 }
 
-#if HAVE_IPV6
+# if HAVE_IPV6
 
 /* const char *
  * inet_ntop6(src, dst, size)
@@ -231,4 +244,6 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t 
size)
   return strcpy (dst, tmp);
 }
 
+# endif
+
 #endif
diff --git a/gl/inet_pton.c b/gl/inet_pton.c
index 8b38e80..cb1a872 100644
--- a/gl/inet_pton.c
+++ b/gl/inet_pton.c
@@ -37,13 +37,25 @@
 /* Specification.  */
 #include <arpa/inet.h>
 
-#include <c-ctype.h>
-#include <string.h>
-#include <errno.h>
+#if HAVE_DECL_INET_PTON
 
-#define NS_INADDRSZ 4
-#define NS_IN6ADDRSZ 16
-#define NS_INT16SZ 2
+# undef inet_pton
+
+int
+rpl_inet_pton (int af, const char *restrict src, void *restrict dst)
+{
+  return inet_pton (af, src, dst);
+}
+
+#else
+
+# include <c-ctype.h>
+# include <string.h>
+# include <errno.h>
+
+# define NS_INADDRSZ 4
+# define NS_IN6ADDRSZ 16
+# define NS_INT16SZ 2
 
 /*
  * WARNING: Don't even consider trying to compile this on a system where
@@ -51,9 +63,9 @@
  */
 
 static int inet_pton4 (const char *src, unsigned char *dst);
-#if HAVE_IPV6
+# if HAVE_IPV6
 static int inet_pton6 (const char *src, unsigned char *dst);
-#endif
+# endif
 
 /* int
  * inet_pton(af, src, dst)
@@ -74,10 +86,10 @@ inet_pton (int af, const char *restrict src, void *restrict 
dst)
     case AF_INET:
       return (inet_pton4 (src, dst));
 
-#if HAVE_IPV6
+# if HAVE_IPV6
     case AF_INET6:
       return (inet_pton6 (src, dst));
-#endif
+# endif
 
     default:
       errno = EAFNOSUPPORT;
@@ -141,7 +153,7 @@ inet_pton4 (const char *restrict src, unsigned char 
*restrict dst)
   return (1);
 }
 
-#if HAVE_IPV6
+# if HAVE_IPV6
 
 /* int
  * inet_pton6(src, dst)
@@ -250,4 +262,7 @@ inet_pton6 (const char *restrict src, unsigned char 
*restrict dst)
   memcpy (dst, tmp, NS_IN6ADDRSZ);
   return (1);
 }
+
+# endif
+
 #endif
diff --git a/gl/intprops.h b/gl/intprops.h
index 58b1b3f..1f6a539 100644
--- a/gl/intprops.h
+++ b/gl/intprops.h
@@ -17,70 +17,303 @@
 
 /* Written by Paul Eggert.  */
 
-#ifndef GL_INTPROPS_H
-# define GL_INTPROPS_H
+#ifndef _GL_INTPROPS_H
+#define _GL_INTPROPS_H
 
-# include <limits.h>
+#include <limits.h>
+
+/* Return an integer value, converted to the same type as the integer
+   expression E after integer type promotion.  V is the unconverted value.  */
+#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
+
+/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
+   <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>.  */
+#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
 
 /* The extra casts in the following macros work around compiler bugs,
    e.g., in Cray C 5.0.3.0.  */
 
 /* True if the arithmetic type T is an integer type.  bool counts as
    an integer.  */
-# define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
+#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
 
 /* True if negative values of the signed integer type T use two's
    complement, ones' complement, or signed magnitude representation,
    respectively.  Much GNU code assumes two's complement, but some
    people like to be portable to all possible C hosts.  */
-# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
-# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
-# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the signed integer expression E uses two's complement.  */
+#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
 
 /* True if the arithmetic type T is signed.  */
-# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* Return 1 if the integer expression E, after integer promotion, has
+   a signed type.  */
+#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
+
 
-/* The maximum and minimum values for the integer type T.  These
+/* Minimum and maximum values for integer types and expressions.  These
    macros have undefined behavior if T is signed and has padding bits.
    If this is a problem for you, please let us know how to fix it for
    your host.  */
-# define TYPE_MINIMUM(t) \
-  ((t) (! TYPE_SIGNED (t) \
-        ? (t) 0 \
-        : TYPE_SIGNED_MAGNITUDE (t) \
-        ? ~ (t) 0 \
+
+/* The maximum and minimum values for the integer type T.  */
+#define TYPE_MINIMUM(t)                                                 \
+  ((t) (! TYPE_SIGNED (t)                                               \
+        ? (t) 0                                                         \
+        : TYPE_SIGNED_MAGNITUDE (t)                                     \
+        ? ~ (t) 0                                                       \
         : ~ TYPE_MAXIMUM (t)))
-# define TYPE_MAXIMUM(t) \
-  ((t) (! TYPE_SIGNED (t) \
-        ? (t) -1 \
+#define TYPE_MAXIMUM(t)                                                 \
+  ((t) (! TYPE_SIGNED (t)                                               \
+        ? (t) -1                                                        \
         : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
 
-/* Return zero if T can be determined to be an unsigned type.
-   Otherwise, return 1.
-   When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
-   tighter bound.  Otherwise, it overestimates the true bound by one byte
-   when applied to unsigned types of size 2, 4, 16, ... bytes.
-   The symbol signed_type_or_expr__ is private to this header file.  */
-# if __GNUC__ >= 2
-#  define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
-# else
-#  define signed_type_or_expr__(t) 1
-# endif
+/* The maximum and minimum values for the type of the expression E,
+   after integer promotion.  E should not have side effects.  */
+#define _GL_INT_MINIMUM(e)                                              \
+  (_GL_INT_SIGNED (e)                                                   \
+   ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e)         \
+   : _GL_INT_CONVERT (e, 0))
+#define _GL_INT_MAXIMUM(e)                                              \
+  (_GL_INT_SIGNED (e)                                                   \
+   ? _GL_SIGNED_INT_MAXIMUM (e)                                         \
+   : _GL_INT_NEGATE_CONVERT (e, 1))
+#define _GL_SIGNED_INT_MAXIMUM(e)                                       \
+  (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
+
+
+/* Return 1 if the __typeof__ keyword works.  This could be done by
+   'configure', but for now it's easier to do it by hand.  */
+#if 2 <= __GNUC__ || 0x5110 <= __SUNPRO_C
+# define _GL_HAVE___TYPEOF__ 1
+#else
+# define _GL_HAVE___TYPEOF__ 0
+#endif
+
+/* Return 1 if the integer type or expression T might be signed.  Return 0
+   if it is definitely unsigned.  This macro does not evaluate its argument,
+   and expands to an integer constant expression.  */
+#if _GL_HAVE___TYPEOF__
+# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
+#else
+# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
+#endif
 
 /* Bound on length of the string representing an unsigned integer
    value representable in B bits.  log10 (2.0) < 146/485.  The
    smallest value of B where this bound is not tight is 2621.  */
-# define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
 
 /* Bound on length of the string representing an integer type or expression T.
    Subtract 1 for the sign bit if T is signed, and then add 1 more for
-   a minus sign if needed.  */
-# define INT_STRLEN_BOUND(t) \
-  (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) \
-   + signed_type_or_expr__ (t))
+   a minus sign if needed.
+
+   Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is
+   signed, this macro may overestimate the true bound by one byte when
+   applied to unsigned types of size 2, 4, 16, ... bytes.  */
+#define INT_STRLEN_BOUND(t)                                     \
+  (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT                 \
+                          - _GL_SIGNED_TYPE_OR_EXPR (t))        \
+   + _GL_SIGNED_TYPE_OR_EXPR (t))
 
 /* Bound on buffer size needed to represent an integer type or expression T,
    including the terminating null.  */
-# define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
+#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
+
+
+/* Range overflow checks.
+
+   The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
+   operators might not yield numerically correct answers due to
+   arithmetic overflow.  They do not rely on undefined or
+   implementation-defined behavior.  Their implementations are simple
+   and straightforward, but they are a bit harder to use than the
+   INT_<op>_OVERFLOW macros described below.
+
+   Example usage:
+
+     long int i = ...;
+     long int j = ...;
+     if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX))
+       printf ("multiply would overflow");
+     else
+       printf ("product is %ld", i * j);
+
+   Restrictions on *_RANGE_OVERFLOW macros:
+
+   These macros do not check for all possible numerical problems or
+   undefined or unspecified behavior: they do not check for division
+   by zero, for bad shift counts, or for shifting negative numbers.
+
+   These macros may evaluate their arguments zero or multiple times,
+   so the arguments should not have side effects.  The arithmetic
+   arguments (including the MIN and MAX arguments) must be of the same
+   integer type after the usual arithmetic conversions, and the type
+   must have minimum value MIN and maximum MAX.  Unsigned types should
+   use a zero MIN of the proper type.
+
+   These macros are tuned for constant MIN and MAX.  For commutative
+   operations such as A + B, they are also tuned for constant B.  */
+
+/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_ADD_RANGE_OVERFLOW(a, b, min, max)          \
+  ((b) < 0                                              \
+   ? (a) < (min) - (b)                                  \
+   : (max) - (b) < (a))
+
+/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max)     \
+  ((b) < 0                                              \
+   ? (max) + (b) < (a)                                  \
+   : (a) < (min) + (b))
+
+/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_NEGATE_RANGE_OVERFLOW(a, min, max)          \
+  ((min) < 0                                            \
+   ? (a) < - (max)                                      \
+   : 0 < (a))
+
+/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Avoid && and || as they tickle
+   bugs in Sun C 5.11 2010/08/13 and other compilers; see
+   <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.  */
+#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max)     \
+  ((b) < 0                                              \
+   ? ((a) < 0                                           \
+      ? (a) < (max) / (b)                               \
+      : (b) == -1                                       \
+      ? 0                                               \
+      : (min) / (b) < (a))                              \
+   : (b) == 0                                           \
+   ? 0                                                  \
+   : ((a) < 0                                           \
+      ? (a) < (min) / (b)                               \
+      : (max) / (b) < (a)))
+
+/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Do not check for division by zero.  */
+#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max)       \
+  ((min) < 0 && (b) == -1 && (a) < - (max))
+
+/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Do not check for division by zero.
+   Mathematically, % should never overflow, but on x86-like hosts
+   INT_MIN % -1 traps, and the C standard permits this, so treat this
+   as an overflow too.  */
+#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max)    \
+  INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
+
+/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Here, MIN and MAX are for A only, and B need
+   not be of the same type as the other arguments.  The C standard says that
+   behavior is undefined for shifts unless 0 <= B < wordwidth, and that when
+   A is negative then A << B has undefined behavior and A >> B has
+   implementation-defined behavior, but do not check these other
+   restrictions.  */
+#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max)   \
+  ((a) < 0                                              \
+   ? (a) < (min) >> (b)                                 \
+   : (max) >> (b) < (a))
+
+
+/* The _GL*_OVERFLOW macros have the same restrictions as the
+   *_RANGE_OVERFLOW macros, except that they do not assume that operands
+   (e.g., A and B) have the same type as MIN and MAX.  Instead, they assume
+   that the result (e.g., A + B) has that type.  */
+#define _GL_ADD_OVERFLOW(a, b, min, max)                                \
+  ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max)                  \
+   : (a) < 0 ? (b) <= (a) + (b)                                         \
+   : (b) < 0 ? (a) <= (a) + (b)                                         \
+   : (a) + (b) < (b))
+#define _GL_SUBTRACT_OVERFLOW(a, b, min, max)                           \
+  ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max)             \
+   : (a) < 0 ? 1                                                        \
+   : (b) < 0 ? (a) - (b) <= (a)                                         \
+   : (a) < (b))
+#define _GL_MULTIPLY_OVERFLOW(a, b, min, max)                           \
+  (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a))))       \
+   || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
+#define _GL_DIVIDE_OVERFLOW(a, b, min, max)                             \
+  ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)  \
+   : (a) < 0 ? (b) <= (a) + (b) - 1                                     \
+   : (b) < 0 && (a) + (b) <= (a))
+#define _GL_REMAINDER_OVERFLOW(a, b, min, max)                          \
+  ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)  \
+   : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b)                     \
+   : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
+
+/* Return a nonzero value if A is a mathematical multiple of B, where
+   A is unsigned, B is negative, and MAX is the maximum value of A's
+   type.  A's type must be the same as (A % B)'s type.  Normally (A %
+   -B == 0) suffices, but things get tricky if -B would overflow.  */
+#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max)                            \
+  (((b) < -_GL_SIGNED_INT_MAXIMUM (b)                                   \
+    ? (_GL_SIGNED_INT_MAXIMUM (b) == (max)                              \
+       ? (a)                                                            \
+       : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1))   \
+    : (a) % - (b))                                                      \
+   == 0)
+
+
+/* Integer overflow checks.
+
+   The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
+   might not yield numerically correct answers due to arithmetic overflow.
+   They work correctly on all known practical hosts, and do not rely
+   on undefined behavior due to signed arithmetic overflow.
+
+   Example usage:
+
+     long int i = ...;
+     long int j = ...;
+     if (INT_MULTIPLY_OVERFLOW (i, j))
+       printf ("multiply would overflow");
+     else
+       printf ("product is %ld", i * j);
+
+   These macros do not check for all possible numerical problems or
+   undefined or unspecified behavior: they do not check for division
+   by zero, for bad shift counts, or for shifting negative numbers.
+
+   These macros may evaluate their arguments zero or multiple times, so the
+   arguments should not have side effects.
+
+   These macros are tuned for their last argument being a constant.
+
+   Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
+   A % B, and A << B would overflow, respectively.  */
+
+#define INT_ADD_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
+#define INT_SUBTRACT_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
+#define INT_NEGATE_OVERFLOW(a) \
+  INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+#define INT_MULTIPLY_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
+#define INT_DIVIDE_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW)
+#define INT_REMAINDER_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW)
+#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
+  INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
+                                 _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+
+/* Return 1 if the expression A <op> B would overflow,
+   where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
+   assuming MIN and MAX are the minimum and maximum for the result type.
+   Arguments should be free of side effects.  */
+#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow)        \
+  op_result_overflow (a, b,                                     \
+                      _GL_INT_MINIMUM (0 * (b) + (a)),          \
+                      _GL_INT_MAXIMUM (0 * (b) + (a)))
 
-#endif /* GL_INTPROPS_H */
+#endif /* _GL_INTPROPS_H */
diff --git a/gl/itold.c b/gl/itold.c
new file mode 100644
index 0000000..0236f33
--- /dev/null
+++ b/gl/itold.c
@@ -0,0 +1,28 @@
+/* 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
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <float.h>
+
+void
+_Qp_itoq (long double *result, int a)
+{
+  /* Convert from 'int' to 'double', then from 'double' to 'long double'.  */
+  *result = (double) a;
+}
diff --git a/gl/listen.c b/gl/listen.c
index 938aa75..b7d070e 100644
--- a/gl/listen.c
+++ b/gl/listen.c
@@ -32,9 +32,18 @@ int
 rpl_listen (int fd, int backlog)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = listen (sock, backlog);
-  if (r < 0)
-    set_winsock_errno ();
 
-  return r;
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = listen (sock, backlog);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
 }
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/alloca.m4 b/gl/m4/alloca.m4
index e2e8a05..a8744a8 100644
--- a/gl/m4/alloca.m4
+++ b/gl/m4/alloca.m4
@@ -1,4 +1,4 @@
-# alloca.m4 serial 10
+# alloca.m4 serial 13
 dnl Copyright (C) 2002-2004, 2006-2007, 2009-2011 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -36,8 +36,86 @@ AC_DEFUN([gl_FUNC_ALLOCA],
     ALLOCA_H=alloca.h
   fi
   AC_SUBST([ALLOCA_H])
+  AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"])
 ])
 
 # Prerequisites of lib/alloca.c.
 # STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
 AC_DEFUN([gl_PREREQ_ALLOCA], [:])
+
+# This works around a bug in autoconf <= 2.68.
+# See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>.
+
+m4_version_prereq([2.69], [] ,[
+
+# This is taken from the following Autoconf patch:
+# 
http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
+
+# _AC_LIBOBJ_ALLOCA
+# -----------------
+# Set up the LIBOBJ replacement of `alloca'.  Well, not exactly
+# AC_LIBOBJ since we actually set the output variable `ALLOCA'.
+# Nevertheless, for Automake, AC_LIBSOURCES it.
+m4_define([_AC_LIBOBJ_ALLOCA],
+[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+AC_LIBSOURCES(alloca.c)
+AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
+AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.])
+
+AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray,
+[AC_EGREP_CPP(webecray,
+[#if defined CRAY && ! defined CRAY2
+webecray
+#else
+wenotbecray
+#endif
+], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    AC_CHECK_FUNC($ac_func,
+                  [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
+                                      [Define to one of `_getb67', `GETB67',
+                                       `getb67' for Cray-2 and Cray-YMP
+                                       systems. This function is required for
+                                       `alloca.c' support on those systems.])
+    break])
+  done
+fi
+
+AC_CACHE_CHECK([stack direction for C alloca],
+               [ac_cv_c_stack_direction],
+[AC_RUN_IFELSE([AC_LANG_SOURCE(
+[AC_INCLUDES_DEFAULT
+int
+find_stack_direction (int *addr, int depth)
+{
+  int dir, dummy = 0;
+  if (! addr)
+    addr = &dummy;
+  *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
+  dir = depth ? find_stack_direction (addr, depth - 1) : 0;
+  return dir + dummy;
+}
+
+int
+main (int argc, char **argv)
+{
+  return find_stack_direction (0, argc + !argv + 20) < 0;
+}])],
+               [ac_cv_c_stack_direction=1],
+               [ac_cv_c_stack_direction=-1],
+               [ac_cv_c_stack_direction=0])])
+AH_VERBATIM([STACK_DIRECTION],
+[/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at runtime.
+        STACK_DIRECTION > 0 => grows toward higher addresses
+        STACK_DIRECTION < 0 => grows toward lower addresses
+        STACK_DIRECTION = 0 => direction of growth unknown */
address@hidden:@undef STACK_DIRECTION])dnl
+AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
+])# _AC_LIBOBJ_ALLOCA
+])
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4
index d21b162..1df7401 100644
--- a/gl/m4/arpa_inet_h.m4
+++ b/gl/m4/arpa_inet_h.m4
@@ -1,4 +1,4 @@
-# arpa_inet_h.m4 serial 11
+# arpa_inet_h.m4 serial 13
 dnl Copyright (C) 2006, 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,
@@ -38,13 +38,6 @@ AC_DEFUN([gl_HEADER_ARPA_INET],
     ]], [inet_ntop inet_pton])
 ])
 
-dnl Unconditionally enables the replacement of <arpa/inet.h>.
-AC_DEFUN([gl_REPLACE_ARPA_INET_H],
-[
-  dnl This is a no-op, because <arpa/inet.h> is always overridden.
-  :
-])
-
 AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR],
 [
   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
@@ -59,4 +52,6 @@ AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_INET_NTOP=1;  AC_SUBST([HAVE_DECL_INET_NTOP])
   HAVE_DECL_INET_PTON=1;  AC_SUBST([HAVE_DECL_INET_PTON])
+  REPLACE_INET_NTOP=0;    AC_SUBST([REPLACE_INET_NTOP])
+  REPLACE_INET_PTON=0;    AC_SUBST([REPLACE_INET_PTON])
 ])
diff --git a/gl/m4/asm-underscore.m4 b/gl/m4/asm-underscore.m4
deleted file mode 100644
index 15c89cc..0000000
--- a/gl/m4/asm-underscore.m4
+++ /dev/null
@@ -1,48 +0,0 @@
-# asm-underscore.m4 serial 1
-dnl Copyright (C) 2010-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.
-
-dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp.
-
-# gl_ASM_SYMBOL_PREFIX
-# Tests for the prefix of C symbols at the assembly language level and the
-# linker level. This prefix is either an underscore or empty. Defines the
-# C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to
-# a stringified variant of this prefix.
-
-AC_DEFUN([gl_ASM_SYMBOL_PREFIX],
-[
-  dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because
-  dnl 1. It works only for GCC.
-  dnl 2. It is incorrectly defined on some platforms, in some GCC versions.
-  AC_CACHE_CHECK(
-    [whether C symbols are prefixed with underscore at the linker level],
-    [gl_cv_prog_as_underscore],
-    [cat > conftest.c <<EOF
-#ifdef __cplusplus
-extern "C" int foo (void);
-#endif
-int foo(void) { return 0; }
-EOF
-     # Look for the assembly language name in the .s file.
-     AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -S conftest.c) >/dev/null 2>&1
-     if grep _foo conftest.s >/dev/null ; then
-       gl_cv_prog_as_underscore=yes
-     else
-       gl_cv_prog_as_underscore=no
-     fi
-     rm -f conftest*
-    ])
-  if test $gl_cv_prog_as_underscore = yes; then
-    USER_LABEL_PREFIX=_
-  else
-    USER_LABEL_PREFIX=
-  fi
-  AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX],
-    [Define to the prefix of C symbols at the assembler and linker level,
-     either an underscore or empty.])
-  ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
-  AC_SUBST([ASM_SYMBOL_PREFIX])
-])
diff --git a/gl/m4/close.m4 b/gl/m4/close.m4
index fc13138..f860a32 100644
--- a/gl/m4/close.m4
+++ b/gl/m4/close.m4
@@ -1,4 +1,4 @@
-# close.m4 serial 5
+# 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,
@@ -6,21 +6,28 @@ 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.
-      gl_REPLACE_CLOSE
+      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
   ])
-])
-
-AC_DEFUN([gl_REPLACE_CLOSE],
-[
-  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  REPLACE_CLOSE=1
-  AC_LIBOBJ([close])
-  gl_REPLACE_FCLOSE
 ])
diff --git a/gl/m4/dup2.m4 b/gl/m4/dup2.m4
new file mode 100644
index 0000000..cd9d254
--- /dev/null
+++ b/gl/m4/dup2.m4
@@ -0,0 +1,76 @@
+#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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_DUP2],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
+    AC_CHECK_FUNCS_ONCE([dup2])
+    if test $ac_cv_func_dup2 = no; then
+      HAVE_DUP2=0
+    fi
+  ], [
+    AC_DEFINE([HAVE_DUP2], [1], [Define to 1 if you have the 'dup2' function.])
+  ])
+  if test $HAVE_DUP2 = 1; then
+    AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
+      [AC_RUN_IFELSE([
+         AC_LANG_PROGRAM([[#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>]],
+           [int result = 0;
+#ifdef FD_CLOEXEC
+            if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
+              result |= 1;
+#endif
+            if (dup2 (1, 1) == 0)
+              result |= 2;
+#ifdef FD_CLOEXEC
+            if (fcntl (1, F_GETFD) != FD_CLOEXEC)
+              result |= 4;
+#endif
+            close (0);
+            if (dup2 (0, 0) != -1)
+              result |= 8;
+            /* Many gnulib modules require POSIX conformance of EBADF.  */
+            if (dup2 (2, 1000000) == -1 && errno != EBADF)
+              result |= 16;
+            return result;
+           ])
+        ],
+        [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
+        [case "$host_os" in
+           mingw*) # on this platform, dup2 always returns 0 for success
+             gl_cv_func_dup2_works=no;;
+           cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
+             gl_cv_func_dup2_works=no;;
+           linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
+                   # closed fd may yield -EBADF instead of -1 / errno=EBADF.
+             gl_cv_func_dup2_works=no;;
+           freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF.
+             gl_cv_func_dup2_works=no;;
+           haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
+             gl_cv_func_dup2_works=no;;
+           *) gl_cv_func_dup2_works=yes;;
+         esac])
+      ])
+    if test "$gl_cv_func_dup2_works" = no; then
+      REPLACE_DUP2=1
+    fi
+  fi
+  dnl Replace dup2() for supporting the gnulib-defined fchdir() function,
+  dnl to keep fchdir's bookkeeping up-to-date.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    gl_TEST_FCHDIR
+    if test $HAVE_FCHDIR = 0; then
+      REPLACE_DUP2=1
+    fi
+  ])
+])
+
+# Prerequisites of lib/dup2.c.
+AC_DEFUN([gl_PREREQ_DUP2], [])
diff --git a/gl/m4/errno_h.m4 b/gl/m4/errno_h.m4
index 687baff..560adba 100644
--- a/gl/m4/errno_h.m4
+++ b/gl/m4/errno_h.m4
@@ -1,4 +1,4 @@
-# errno_h.m4 serial 8
+# errno_h.m4 serial 10
 dnl Copyright (C) 2004, 2006, 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,
@@ -34,6 +34,12 @@ booboo
 #if !defined ENOTSUP
 booboo
 #endif
+#if !defined ENETRESET
+booboo
+#endif
+#if !defined ECONNABORTED
+booboo
+#endif
 #if !defined ESTALE
 booboo
 #endif
@@ -54,6 +60,7 @@ booboo
     ERRNO_H='errno.h'
   fi
   AC_SUBST([ERRNO_H])
+  AM_CONDITIONAL([GL_GENERATE_ERRNO_H], [test -n "$ERRNO_H"])
   gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
   gl_REPLACE_ERRNO_VALUE([ENOLINK])
   gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
diff --git a/gl/m4/error.m4 b/gl/m4/error.m4
index 6ea75ac..e7022fe 100644
--- a/gl/m4/error.m4
+++ b/gl/m4/error.m4
@@ -1,4 +1,4 @@
-#serial 13
+#serial 14
 
 # Copyright (C) 1996-1998, 2001-2004, 2009-2011 Free Software Foundation, Inc.
 #
@@ -8,16 +8,8 @@
 
 AC_DEFUN([gl_ERROR],
 [
-  AC_FUNC_ERROR_AT_LINE
-  dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]).
-  gl_PREREQ_ERROR
-])
-
-# Redefine AC_FUNC_ERROR_AT_LINE, because it is no longer maintained in
-# Autoconf.
-AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
-[
-  AC_LIBSOURCES([error.h, error.c])dnl
+  dnl We don't use AC_FUNC_ERROR_AT_LINE any more, because it is no longer
+  dnl maintained in Autoconf and because it invokes AC_LIBOBJ.
   AC_CACHE_CHECK([for error_at_line], [ac_cv_lib_error_at_line],
     [AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
@@ -25,9 +17,6 @@ AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
           [[error_at_line (0, 0, "", 0, "an error occurred");]])],
        [ac_cv_lib_error_at_line=yes],
        [ac_cv_lib_error_at_line=no])])
-  if test $ac_cv_lib_error_at_line = no; then
-    AC_LIBOBJ([error])
-  fi
 ])
 
 # Prerequisites of lib/error.c.
diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4
index 1330503..22156e0 100644
--- a/gl/m4/extensions.m4
+++ b/gl/m4/extensions.m4
@@ -1,4 +1,4 @@
-# serial 9  -*- Autoconf -*-
+# serial 10  -*- Autoconf -*-
 # Enable extensions on systems that normally disable them.
 
 # Copyright (C) 2003, 2006-2011 Free Software Foundation, Inc.
@@ -67,6 +67,10 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
+/* Enable general extensions on MacOS X.  */
+#ifndef _DARWIN_C_SOURCE
+# undef _DARWIN_C_SOURCE
+#endif
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
@@ -95,6 +99,7 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
   test $ac_cv_safe_to_define___extensions__ = yes &&
     AC_DEFINE([__EXTENSIONS__])
   AC_DEFINE([_ALL_SOURCE])
+  AC_DEFINE([_DARWIN_C_SOURCE])
   AC_DEFINE([_GNU_SOURCE])
   AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
   AC_DEFINE([_TANDEM_SOURCE])
diff --git a/gl/m4/fclose.m4 b/gl/m4/fclose.m4
deleted file mode 100644
index 278859c..0000000
--- a/gl/m4/fclose.m4
+++ /dev/null
@@ -1,16 +0,0 @@
-# fclose.m4 serial 2
-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_FCLOSE],
-[
-])
-
-AC_DEFUN([gl_REPLACE_FCLOSE],
-[
-  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
-  REPLACE_FCLOSE=1
-  AC_LIBOBJ([fclose])
-])
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
index 88db07e..bee6edc 100644
--- a/gl/m4/fcntl-o.m4
+++ b/gl/m4/fcntl-o.m4
@@ -1,4 +1,4 @@
-# fcntl-o.m4 serial 3
+# fcntl-o.m4 serial 4
 dnl Copyright (C) 2006, 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,
@@ -17,12 +17,21 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
   m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
     [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
     [AC_REQUIRE([AC_GNU_SOURCE])])
+
+  AC_CHECK_HEADERS_ONCE([unistd.h])
+  AC_CHECK_FUNCS_ONCE([symlink])
   AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <sys/types.h>
            #include <sys/stat.h>
-           #include <unistd.h>
+           #if HAVE_UNISTD_H
+           # include <unistd.h>
+           #else /* on Windows with MSVC */
+           # include <io.h>
+           # include <stdlib.h>
+           # defined sleep(n) _sleep ((n) * 1000)
+           #endif
            #include <fcntl.h>
            #ifndef O_NOATIME
             #define O_NOATIME 0
@@ -38,6 +47,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
           ]],
           [[
             int result = !constants;
+            #if HAVE_SYMLINK
             {
               static char const sym[] = "conftest.sym";
               if (symlink (".", sym) != 0)
@@ -53,6 +63,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
                 }
               unlink (sym);
             }
+            #endif
             {
               static char const file[] = "confdefs.h";
               int fd = open (file, O_RDONLY | O_NOATIME);
diff --git a/gl/m4/fcntl_h.m4 b/gl/m4/fcntl_h.m4
index 1ef4f45..03a41e6 100644
--- a/gl/m4/fcntl_h.m4
+++ b/gl/m4/fcntl_h.m4
@@ -1,4 +1,4 @@
-# serial 13
+# serial 15
 # Configure fcntl.h.
 dnl Copyright (C) 2006-2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -13,6 +13,12 @@ AC_DEFUN([gl_FCNTL_H],
   AC_REQUIRE([gl_FCNTL_O_FLAGS])
   gl_NEXT_HEADERS([fcntl.h])
 
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use, if it is not common
   dnl enough to be declared everywhere.
@@ -31,13 +37,14 @@ AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
 
 AC_DEFUN([gl_FCNTL_H_DEFAULTS],
 [
-  GNULIB_FCNTL=0;   AC_SUBST([GNULIB_FCNTL])
-  GNULIB_OPEN=0;    AC_SUBST([GNULIB_OPEN])
-  GNULIB_OPENAT=0;  AC_SUBST([GNULIB_OPENAT])
+  GNULIB_FCNTL=0;        AC_SUBST([GNULIB_FCNTL])
+  GNULIB_NONBLOCKING=0;  AC_SUBST([GNULIB_NONBLOCKING])
+  GNULIB_OPEN=0;         AC_SUBST([GNULIB_OPEN])
+  GNULIB_OPENAT=0;       AC_SUBST([GNULIB_OPENAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_FCNTL=1;     AC_SUBST([HAVE_FCNTL])
-  HAVE_OPENAT=1;    AC_SUBST([HAVE_OPENAT])
-  REPLACE_FCNTL=0;  AC_SUBST([REPLACE_FCNTL])
-  REPLACE_OPEN=0;   AC_SUBST([REPLACE_OPEN])
-  REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT])
+  HAVE_FCNTL=1;          AC_SUBST([HAVE_FCNTL])
+  HAVE_OPENAT=1;         AC_SUBST([HAVE_OPENAT])
+  REPLACE_FCNTL=0;       AC_SUBST([REPLACE_FCNTL])
+  REPLACE_OPEN=0;        AC_SUBST([REPLACE_OPEN])
+  REPLACE_OPENAT=0;      AC_SUBST([REPLACE_OPENAT])
 ])
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 265a4c1..0420e06 100644
--- a/gl/m4/float_h.m4
+++ b/gl/m4/float_h.m4
@@ -1,4 +1,4 @@
-# float_h.m4 serial 5
+# 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,
@@ -9,11 +9,90 @@ AC_DEFUN([gl_FLOAT_H],
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST])
   FLOAT_H=
+  REPLACE_FLOAT_LDBL=0
   case "$host_os" in
-    beos* | openbsd* | mirbsd*)
+    aix* | beos* | openbsd* | mirbsd* | irix*)
       FLOAT_H=float.h
-      gl_NEXT_HEADERS([float.h])
+      ;;
+    freebsd*)
+      case "$host_cpu" in
+changequote(,)dnl
+        i[34567]86 )
+changequote([,])dnl
+          FLOAT_H=float.h
+          ;;
+        x86_64 )
+          # On x86_64 systems, the C compiler may still be generating
+          # 32-bit code.
+          AC_EGREP_CPP([yes],
+            [#if defined __LP64__ || defined __x86_64__ || defined __amd64__
+             yes
+             #endif],
+            [],
+            [FLOAT_H=float.h])
+          ;;
+      esac
+      ;;
+    linux*)
+      case "$host_cpu" in
+        powerpc*)
+          FLOAT_H=float.h
+          ;;
+      esac
+      ;;
+  esac
+  case "$host_os" in
+    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/lib/gl/m4/fpieee.m4 b/gl/m4/fpieee.m4
similarity index 100%
copy from lib/gl/m4/fpieee.m4
copy to gl/m4/fpieee.m4
diff --git a/lib/gl/m4/fseek.m4 b/gl/m4/fseek.m4
similarity index 100%
copy from lib/gl/m4/fseek.m4
copy to gl/m4/fseek.m4
diff --git a/gl/m4/fseeko.m4 b/gl/m4/fseeko.m4
index 4a67260..391948d 100644
--- a/gl/m4/fseeko.m4
+++ b/gl/m4/fseeko.m4
@@ -1,4 +1,4 @@
-# fseeko.m4 serial 10
+# fseeko.m4 serial 15
 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,
@@ -7,8 +7,18 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_FUNC_FSEEKO],
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
-  AC_REQUIRE([gl_HAVE_FSEEKO])
   AC_REQUIRE([gl_STDIN_LARGE_OFFSET])
+  AC_REQUIRE([AC_PROG_CC])
+
+  dnl Persuade glibc <stdio.h> to declare fseeko().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko],
+    [
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
+]], [fseeko (stdin, 0, 0);])],
+        [gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no])
+    ])
 
   AC_CHECK_DECLS_ONCE([fseeko])
   if test $ac_cv_have_decl_fseeko = no; then
@@ -17,39 +27,35 @@ AC_DEFUN([gl_FUNC_FSEEKO],
 
   if test $gl_cv_func_fseeko = no; then
     HAVE_FSEEKO=0
-    gl_REPLACE_FSEEKO
   else
     if test $gl_cv_var_stdin_large_offset = no; then
-      gl_REPLACE_FSEEKO
+      REPLACE_FSEEKO=1
     fi
-  fi
-])
-
-dnl Tests whether fseeko is available.
-dnl Result is gl_cv_func_fseeko.
-AC_DEFUN([gl_HAVE_FSEEKO],
-[
-  AC_REQUIRE([AC_PROG_CC])
-
-  dnl Persuade glibc <stdio.h> to declare fseeko().
-  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
-
-  AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko],
-    [
-      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
-]], [fseeko (stdin, 0, 0);])],
-        [gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no])
+    m4_ifdef([gl_FUNC_FFLUSH_STDIN], [
+      gl_FUNC_FFLUSH_STDIN
+      if test $gl_cv_func_fflush_stdin = no; then
+        REPLACE_FSEEKO=1
+      fi
     ])
+  fi
 ])
 
-AC_DEFUN([gl_REPLACE_FSEEKO],
-[
-  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
-  AC_REQUIRE([gl_HAVE_FSEEKO])
-  if test $gl_cv_func_fseeko = yes; then
-    REPLACE_FSEEKO=1
-  fi
-  AC_LIBOBJ([fseeko])
-  dnl If we are also using the fseek module, then fseek needs replacing, too.
-  m4_ifdef([gl_REPLACE_FSEEK], [gl_REPLACE_FSEEK])
+dnl Code shared by fseeko and ftello.  Determine if large files are supported,
+dnl but stdin does not start as a large file by default.
+AC_DEFUN([gl_STDIN_LARGE_OFFSET],
+  [
+    AC_CACHE_CHECK([whether stdin defaults to large file offsets],
+      [gl_cv_var_stdin_large_offset],
+      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
+[[#if defined __SL64 && defined __SCLE /* cygwin */
+  /* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
+     fseeko/ftello needlessly fail.  This bug was fixed in 1.5.25, and
+     it is easier to do a version check than building a runtime test.  */
+# include <cygwin/version.h>
+# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
+  choke me
+# endif
+#endif]])],
+        [gl_cv_var_stdin_large_offset=yes],
+        [gl_cv_var_stdin_large_offset=no])])
 ])
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/lib/gl/m4/ftell.m4 b/gl/m4/ftell.m4
similarity index 100%
copy from lib/gl/m4/ftell.m4
copy to gl/m4/ftell.m4
diff --git a/gl/m4/ftello.m4 b/gl/m4/ftello.m4
index 599f8f2..10cf429 100644
--- a/gl/m4/ftello.m4
+++ b/gl/m4/ftello.m4
@@ -1,4 +1,4 @@
-# ftello.m4 serial 9
+# ftello.m4 serial 10
 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,
@@ -124,12 +124,4 @@ main (void)
       esac
     fi
   fi
-  if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
-    gl_REPLACE_FTELLO
-  fi
-])
-
-AC_DEFUN([gl_REPLACE_FTELLO],
-[
-  AC_LIBOBJ([ftello])
 ])
diff --git a/gl/m4/ftruncate.m4 b/gl/m4/ftruncate.m4
new file mode 100644
index 0000000..4a47ba4
--- /dev/null
+++ b/gl/m4/ftruncate.m4
@@ -0,0 +1,24 @@
+# serial 18
+
+# See if we need to emulate a missing ftruncate function using chsize.
+
+# Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FTRUNCATE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([ftruncate])
+  if test $ac_cv_func_ftruncate = no; then
+    HAVE_FTRUNCATE=0
+  fi
+])
+
+# Prerequisites of lib/ftruncate.c.
+AC_DEFUN([gl_PREREQ_FTRUNCATE],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_CHECK_FUNCS([chsize])
+])
diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4
index 94c276f..962e6e8 100644
--- a/gl/m4/getaddrinfo.m4
+++ b/gl/m4/getaddrinfo.m4
@@ -1,4 +1,4 @@
-# getaddrinfo.m4 serial 23
+# getaddrinfo.m4 serial 29
 dnl Copyright (C) 2004-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,
@@ -24,6 +24,7 @@ AC_DEFUN([gl_GETADDRINFO],
      fi])
   LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
 
+  HAVE_GETADDRINFO=1
   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/types.h>
@@ -55,16 +56,14 @@ AC_DEFUN([gl_GETADDRINFO],
       GETADDRINFO_LIB="-lws2_32"
       LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
     else
-      AC_LIBOBJ([getaddrinfo])
+      HAVE_GETADDRINFO=0
     fi
   fi
 
   # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
   # inline function declared in ws2tcpip.h, so we need to get that
   # header included somehow.
-  AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
-    gl_cv_func_gai_strerror, [
-      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+  AC_CHECK_DECLS([gai_strerror], [], [], [[
 #include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -76,11 +75,46 @@ AC_DEFUN([gl_GETADDRINFO],
 #include <ws2tcpip.h>
 #endif
 #include <stddef.h>
-]], [[gai_strerror (NULL);]])],
-        [gl_cv_func_gai_strerror=yes],
-        [gl_cv_func_gai_strerror=no])])
-  if test $gl_cv_func_gai_strerror = no; then
-    AC_LIBOBJ([gai_strerror])
+]])
+  if test $ac_cv_have_decl_gai_strerror = yes; then
+    AC_CHECK_DECLS([gai_strerrorA], [], [], [[
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+#include <stddef.h>
+]])
+    dnl check for correct signature
+    AC_CACHE_CHECK([for gai_strerror with POSIX signature],
+     [gl_cv_func_gai_strerror_posix_signature], [
+      AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+#include <stddef.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *gai_strerror(int);]])],
+        [gl_cv_func_gai_strerror_posix_signature=yes],
+        [gl_cv_func_gai_strerror_posix_signature=no])])
+    if test $gl_cv_func_gai_strerror_posix_signature = no; then
+      REPLACE_GAI_STRERROR=1
+    fi
   fi
 
   LIBS="$gai_saved_LIBS"
@@ -105,11 +139,14 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
 
   dnl Including sys/socket.h is wrong for Windows, but Windows does not
   dnl have sa_len so the result is correct anyway.
-  AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
+  AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
+#include <sys/types.h>
+#include <sys/socket.h>
+])
 
   AC_CHECK_HEADERS_ONCE([netinet/in.h])
 
-  AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
+  AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
      powerpc-apple-darwin5.5 required it. */
@@ -123,7 +160,7 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
 #ifdef HAVE_WS2TCPIP_H
 #include <ws2tcpip.h>
 #endif
-])
+]])
   if test $ac_cv_have_decl_getaddrinfo = no; then
     HAVE_DECL_GETADDRINFO=0
   fi
diff --git a/gl/m4/getcwd.m4 b/gl/m4/getcwd.m4
new file mode 100644
index 0000000..f828cf3
--- /dev/null
+++ b/gl/m4/getcwd.m4
@@ -0,0 +1,133 @@
+# getcwd.m4 - check for working getcwd that is compatible with glibc
+
+# Copyright (C) 2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Written by Paul Eggert.
+# serial 9
+
+AC_DEFUN([gl_FUNC_GETCWD_NULL],
+  [
+   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+   AC_CHECK_HEADERS_ONCE([unistd.h])
+   AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
+     [gl_cv_func_getcwd_null],
+     [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#        if HAVE_UNISTD_H
+#         include <unistd.h>
+#        else /* on Windows with MSVC */
+#         include <direct.h>
+#        endif
+#        ifndef getcwd
+         char *getcwd ();
+#        endif
+]], [[
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* mingw cwd does not start with '/', but getcwd does allocate.
+   However, mingw fails to honor non-zero size.  */
+#else
+           if (chdir ("/") != 0)
+             return 1;
+           else
+             {
+               char *f = getcwd (NULL, 0);
+               if (! f)
+                 return 2;
+               if (f[0] != '/')
+                 return 3;
+               if (f[1] != '\0')
+                 return 4;
+               return 0;
+             }
+#endif
+         ]])],
+        [gl_cv_func_getcwd_null=yes],
+        [gl_cv_func_getcwd_null=no],
+        [[
+       case "$host_os" in
+                               # Guess yes on glibc systems.
+         *-gnu*)               gl_cv_func_getcwd_null="guessing yes";;
+                               # Guess yes on Cygwin.
+         cygwin*)              gl_cv_func_getcwd_null="guessing yes";;
+                               # If we don't know, assume the worst.
+         *)                    gl_cv_func_getcwd_null="guessing no";;
+       esac
+        ]])])
+])
+
+AC_DEFUN([gl_FUNC_GETCWD_SIGNATURE],
+[
+  AC_CACHE_CHECK([for getcwd with POSIX signature],
+    [gl_cv_func_getcwd_posix_signature],
+    [AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM(
+         [[#include <unistd.h>]],
+         [[extern
+           #ifdef __cplusplus
+           "C"
+           #endif
+           char *getcwd (char *, size_t);
+         ]])
+      ],
+      [gl_cv_func_getcwd_posix_signature=yes],
+      [gl_cv_func_getcwd_posix_signature=no])
+   ])
+])
+
+dnl Guarantee that getcwd will malloc with a NULL first argument.  Assumes
+dnl that either the system getcwd is robust, or that calling code is okay
+dnl with spurious failures when run from a directory with an absolute name
+dnl larger than 4k bytes.
+dnl
+dnl Assumes that getcwd exists; if you are worried about obsolete
+dnl platforms that lacked getcwd(), then you need to use the GPL module.
+AC_DEFUN([gl_FUNC_GETCWD_LGPL],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_GETCWD_NULL])
+  AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
+
+  case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature in
+  *yes,yes) ;;
+  *)
+    dnl Minimal replacement lib/getcwd-lgpl.c.
+    REPLACE_GETCWD=1
+    ;;
+  esac
+])
+
+dnl Check for all known getcwd bugs; useful for a program likely to be
+dnl executed from an arbitrary location.
+AC_DEFUN([gl_FUNC_GETCWD],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_GETCWD_NULL])
+  AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+  gl_abort_bug=no
+  case $gl_cv_func_getcwd_null,$host_os in
+  *,mingw*)
+    gl_cv_func_getcwd_path_max=yes;;
+  yes,*)
+    gl_FUNC_GETCWD_PATH_MAX
+    gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
+  esac
+
+  case 
$gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature$gl_cv_func_getcwd_path_max,$gl_abort_bug
 in
+  *yes,yes,yes,no) ;;
+  *)
+    dnl Full replacement lib/getcwd.c, overrides LGPL replacement.
+    REPLACE_GETCWD=1;;
+  esac
+])
+
+# Prerequisites of lib/getcwd.c, when full replacement is in effect.
+AC_DEFUN([gl_PREREQ_GETCWD],
+[
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
+  :
+])
diff --git a/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4
index ef12736..6a0f632 100644
--- a/gl/m4/getdelim.m4
+++ b/gl/m4/getdelim.m4
@@ -1,4 +1,4 @@
-# getdelim.m4 serial 8
+# getdelim.m4 serial 9
 
 dnl Copyright (C) 2005-2007, 2009-2011 Free Software Foundation, Inc.
 dnl
@@ -19,6 +19,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
 
   AC_CHECK_FUNCS_ONCE([getdelim])
   if test $ac_cv_func_getdelim = yes; then
+    HAVE_GETDELIM=1
     dnl Found it in some library.  Verify that it works.
     AC_CACHE_CHECK([for working getdelim function], 
[gl_cv_func_working_getdelim],
     [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
@@ -65,21 +66,16 @@ AC_DEFUN([gl_FUNC_GETDELIM],
          [gl_cv_func_working_getdelim=yes],
          [gl_cv_func_working_getdelim=no])]
     )])
+    if test $gl_cv_func_working_getdelim = no; then
+      REPLACE_GETDELIM=1
+    fi
   else
-    gl_cv_func_working_getdelim=no
+    HAVE_GETDELIM=0
   fi
 
   if test $ac_cv_have_decl_getdelim = no; then
     HAVE_DECL_GETDELIM=0
   fi
-
-  if test $gl_cv_func_working_getdelim = no; then
-    if test $ac_cv_func_getdelim = yes; then
-      REPLACE_GETDELIM=1
-    fi
-    AC_LIBOBJ([getdelim])
-    gl_PREREQ_GETDELIM
-  fi
 ])
 
 # Prerequisites of lib/getdelim.c.
diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4
index ec001b9..4c57797 100644
--- a/gl/m4/getline.m4
+++ b/gl/m4/getline.m4
@@ -1,4 +1,4 @@
-# getline.m4 serial 23
+# getline.m4 serial 25
 
 dnl Copyright (C) 1998-2003, 2005-2007, 2009-2011 Free Software Foundation,
 dnl Inc.
@@ -84,14 +84,11 @@ AC_DEFUN([gl_FUNC_GETLINE],
     dnl getline function among $LIBS, it may exist in libinet and the
     dnl executable may be linked with -linet.
     REPLACE_GETLINE=1
-    AC_LIBOBJ([getline])
-
-    gl_PREREQ_GETLINE
   fi
 ])
 
 # Prerequisites of lib/getline.c.
 AC_DEFUN([gl_PREREQ_GETLINE],
 [
-  gl_FUNC_GETDELIM
+  :
 ])
diff --git a/gl/m4/getpagesize.m4 b/gl/m4/getpagesize.m4
index 79dfbbe..f7ac1ef 100644
--- a/gl/m4/getpagesize.m4
+++ b/gl/m4/getpagesize.m4
@@ -1,4 +1,4 @@
-# getpagesize.m4 serial 8
+# getpagesize.m4 serial 9
 dnl Copyright (C) 2002, 2004-2005, 2007, 2009-2011 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -24,7 +24,6 @@ AC_DEFUN([gl_FUNC_GETPAGESIZE],
   case "$host_os" in
     mingw*)
       REPLACE_GETPAGESIZE=1
-      AC_LIBOBJ([getpagesize])
       ;;
   esac
   dnl Also check whether it's declared.
diff --git a/gl/m4/getpass.m4 b/gl/m4/getpass.m4
index c6ec427..13e55f6 100644
--- a/gl/m4/getpass.m4
+++ b/gl/m4/getpass.m4
@@ -1,4 +1,4 @@
-# getpass.m4 serial 12
+# getpass.m4 serial 14
 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2011 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -11,10 +11,12 @@ AC_DEFUN([gl_FUNC_GETPASS],
   dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
-  AC_REPLACE_FUNCS([getpass])
+  AC_CHECK_FUNCS([getpass])
   AC_CHECK_DECLS_ONCE([getpass])
-  if test $ac_cv_func_getpass = no; then
-    gl_PREREQ_GETPASS
+  if test $ac_cv_func_getpass = yes; then
+    HAVE_GETPASS=1
+  else
+    HAVE_GETPASS=0
   fi
 ])
 
@@ -27,13 +29,15 @@ AC_DEFUN([gl_FUNC_GETPASS_GNU],
 
   AC_CHECK_DECLS_ONCE([getpass])
   dnl TODO: Detect when GNU getpass() is already found in glibc.
-  AC_LIBOBJ([getpass])
-  gl_PREREQ_GETPASS
-  dnl We must choose a different name for our function, since on ELF systems
-  dnl an unusable getpass() in libc.so would override our getpass() if it is
-  dnl compiled into a shared library.
-  AC_DEFINE([getpass], [gnu_getpass],
-    [Define to a replacement function name for getpass().])
+  REPLACE_GETPASS=1
+
+  if test $REPLACE_GETPASS = 1; then
+    dnl We must choose a different name for our function, since on ELF systems
+    dnl an unusable getpass() in libc.so would override our getpass() if it is
+    dnl compiled into a shared library.
+    AC_DEFINE([getpass], [gnu_getpass],
+      [Define to a replacement function name for getpass().])
+  fi
 ])
 
 # Prerequisites of lib/getpass.c.
@@ -41,10 +45,10 @@ AC_DEFUN([gl_PREREQ_GETPASS], [
   AC_CHECK_HEADERS_ONCE([stdio_ext.h termios.h])
   AC_CHECK_FUNCS_ONCE([__fsetlocking tcgetattr tcsetattr])
   AC_CHECK_DECLS([__fsetlocking],,,
-    [#include <stdio.h>
-     #if HAVE_STDIO_EXT_H
-      #include <stdio_ext.h>
-     #endif])
+    [[#include <stdio.h>
+      #if HAVE_STDIO_EXT_H
+       #include <stdio_ext.h>
+      #endif]])
   AC_CHECK_DECLS_ONCE([fflush_unlocked])
   AC_CHECK_DECLS_ONCE([flockfile])
   AC_CHECK_DECLS_ONCE([fputs_unlocked])
diff --git a/gl/m4/gettime.m4 b/gl/m4/gettime.m4
index 2b148ab..f2122dc 100644
--- a/gl/m4/gettime.m4
+++ b/gl/m4/gettime.m4
@@ -1,4 +1,4 @@
-# gettime.m4 serial 7
+# gettime.m4 serial 8
 dnl Copyright (C) 2002, 2004-2006, 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,
@@ -6,8 +6,6 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 AC_DEFUN([gl_GETTIME],
 [
-  AC_LIBOBJ([gettime])
-
   dnl Prerequisites of lib/gettime.c.
   AC_REQUIRE([gl_CLOCK_TIME])
   AC_REQUIRE([gl_TIMESPEC])
diff --git a/gl/m4/gettimeofday.m4 b/gl/m4/gettimeofday.m4
index 84acadf..47c1e1d 100644
--- a/gl/m4/gettimeofday.m4
+++ b/gl/m4/gettimeofday.m4
@@ -1,4 +1,4 @@
-# serial 15
+# serial 17
 
 # Copyright (C) 2001-2003, 2005, 2007, 2009-2011 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -17,8 +17,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
   gl_gettimeofday_timezone=void
   if test $ac_cv_func_gettimeofday != yes; then
     HAVE_GETTIMEOFDAY=0
-    AC_LIBOBJ([gettimeofday])
-    gl_PREREQ_GETTIMEOFDAY
   else
     gl_FUNC_GETTIMEOFDAY_CLOBBER
     AC_CACHE_CHECK([for gettimeofday with POSIX signature],
@@ -51,9 +49,18 @@ int gettimeofday (struct timeval *restrict, struct timezone 
*restrict);
       gl_gettimeofday_timezone='struct timezone'
     elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
       REPLACE_GETTIMEOFDAY=1
-      AC_LIBOBJ([gettimeofday])
-      gl_PREREQ_GETTIMEOFDAY
     fi
+    m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
+      gl_FUNC_TZSET_CLOBBER
+      if test $gl_cv_func_tzset_clobber = yes; then
+        REPLACE_GETTIMEOFDAY=1
+        gl_GETTIMEOFDAY_REPLACE_LOCALTIME
+        AC_DEFINE([tzset], [rpl_tzset],
+          [Define to rpl_tzset if the wrapper function should be used.])
+        AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
+          [Define if tzset clobbers localtime's static buffer.])
+      fi
+    ])
   fi
   AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
     [Define this to 'void' or 'struct timezone' to match the system's
@@ -105,8 +112,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
 ])
 
 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
-  AC_LIBOBJ([gettimeofday])
-  gl_PREREQ_GETTIMEOFDAY
   AC_DEFINE([gmtime], [rpl_gmtime],
     [Define to rpl_gmtime if the replacement function should be used.])
   AC_DEFINE([localtime], [rpl_localtime],
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 60d45ee..55658bd 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.
@@ -15,7 +27,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --with-tests --libtool --macro-prefix=gl --no-vc-files 
accept arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo 
getline getpass-gnu gettime gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 
listen maintainer-makefile manywarnings minmax perror pmccabe2html progname 
read-file readline recv select send setsockopt shutdown socket sockets sys_stat 
update-copyright valgrind-tests version-etc-fsf warnings
+#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --with-tests --no-conditional-dependencies --libtool 
--macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect 
error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gettime gnupload gpl-3.0 
inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax 
perror pmccabe2html progname read-file readline recv select send setsockopt 
shutdown socket sockets sys_stat update-copyright valgrind-tests 
version-etc-fsf warnings
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([gl/override])
@@ -72,4 +84,5 @@ gl_MAKEFILE_NAME([])
 gl_LIBTOOL
 gl_MACRO_PREFIX([gl])
 gl_PO_DOMAIN([])
+gl_WITNESS_C_DOMAIN([])
 gl_VC_FILES([false])
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index ecbf336..7d83299 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 23
+# 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,
@@ -12,6 +12,19 @@ AC_DEFUN([gl_COMMON], [
   AC_REQUIRE([gl_COMMON_BODY])
 ])
 AC_DEFUN([gl_COMMON_BODY], [
+  AH_VERBATIM([_Noreturn],
+[/* The _Noreturn keyword of draft C1X.  */
+#ifndef _Noreturn
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+      || 0x5110 <= __SUNPRO_C)
+#  define _Noreturn __attribute__ ((__noreturn__))
+# elif 1200 <= _MSC_VER
+#  define _Noreturn __declspec (noreturn)
+# else
+#  define _Noreturn
+# endif
+#endif
+])
   AH_VERBATIM([isoc99_inline],
 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
@@ -34,6 +47,20 @@ AC_DEFUN([gl_COMMON_BODY], [
 /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
    is a misnomer outside of parameter lists.  */
 #define _UNUSED_PARAMETER_ _GL_UNUSED
+
+/* The __pure__ attribute was added in gcc 2.96.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
+#endif
+
+/* The __const__ attribute was added in gcc 2.95.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
 ])
   dnl Preparation for running test programs:
   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
@@ -47,16 +74,49 @@ AC_DEFUN([gl_COMMON_BODY], [
 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
 # whether a gnulib module that has been requested shall be considered present
 # or not.
-AC_DEFUN([gl_MODULE_INDICATOR_CONDITION], [1])
+m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
 
 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
 # sets the shell variable that indicates the presence of the given module to
 # a C preprocessor expression that will evaluate to 1.
 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
 [
-  GNULIB_[]m4_translit([[$1]],
-    [abcdefghijklmnopqrstuvwxyz./-],
-    [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=gl_MODULE_INDICATOR_CONDITION
+  gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
+    [GNULIB_[]m4_translit([[$1]],
+                          [abcdefghijklmnopqrstuvwxyz./-],
+                          [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
+    [gl_MODULE_INDICATOR_CONDITION])
+])
+
+# gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
+# modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
+# The shell variable's value is a C preprocessor expression that evaluates
+# to 0 or 1.
+AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
+[
+  m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
+    [
+     dnl Simplify the expression VALUE || 1 to 1.
+     $1=1
+    ],
+    [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
+                                             [gl_MODULE_INDICATOR_CONDITION])])
+])
+
+# gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
+# modifies the shell variable to include the given condition.  The shell
+# variable's value is a C preprocessor expression that evaluates to 0 or 1.
+AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
+[
+  dnl Simplify the expression 1 || CONDITION to 1.
+  if test "$[]$1" != 1; then
+    dnl Simplify the expression 0 || CONDITION to CONDITION.
+    if test "$[]$1" = 0; then
+      $1=$2
+    else
+      $1="($[]$1 || $2)"
+    fi
+  fi
 ])
 
 # gl_MODULE_INDICATOR([modulename])
@@ -109,7 +169,8 @@ AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
 [
   dnl Override gl_WARN_ON_USE_PREPARE.
-  AC_DEFUN([gl_WARN_ON_USE_PREPARE], [])
+  dnl But hide this definition from 'aclocal'.
+  AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
 ])
 
 # gl_ASSERT_NO_GNULIB_TESTS
@@ -150,6 +211,83 @@ 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
+# the values.
+AC_DEFUN([gl_PROG_AR_RANLIB],
+[
+  dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
+  dnl as "cc", and GCC as "gcc". They have different object file formats and
+  dnl library formats. In particular, the GNU binutils programs ar, ranlib
+  dnl produce libraries that work only with gcc, not with cc.
+  AC_REQUIRE([AC_PROG_CC])
+  AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
+    [
+      AC_EGREP_CPP([Amsterdam],
+        [
+#ifdef __ACK__
+Amsterdam
+#endif
+        ],
+        [gl_cv_c_amsterdam_compiler=yes],
+        [gl_cv_c_amsterdam_compiler=no])
+    ])
+  if test -z "$AR"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      AR='cc -c.a'
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='-o'
+      fi
+    else
+      dnl Use the Automake-documented default values for AR and ARFLAGS,
+      dnl but prefer ${host}-ar over ar (useful for cross-compiling).
+      AC_CHECK_TOOL([AR], [ar], [ar])
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='cru'
+      fi
+    fi
+  else
+    if test -z "$ARFLAGS"; then
+      ARFLAGS='cru'
+    fi
+  fi
+  AC_SUBST([AR])
+  AC_SUBST([ARFLAGS])
+  if test -z "$RANLIB"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      RANLIB=':'
+    else
+      dnl Use the ranlib program if it is available.
+      AC_PROG_RANLIB
+    fi
+  fi
+  AC_SUBST([RANLIB])
+])
+
 # AC_PROG_MKDIR_P
 # is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
 # for interoperability with automake-1.9.6 from autoconf-2.62.
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 7fcdee9..c31470e 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.
@@ -25,14 +37,15 @@ AC_DEFUN([gl_EARLY],
   m4_pattern_allow([^gl_ES$])dnl a valid locale name
   m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
   m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
-  AC_REQUIRE([AC_PROG_RANLIB])
+  AC_REQUIRE([gl_PROG_AR_RANLIB])
+  AC_REQUIRE([AM_PROG_CC_C_O])
   # Code from module accept:
+  # Code from module accept-tests:
   # Code from module alignof:
   # Code from module alignof-tests:
   # Code from module alloca:
   # Code from module alloca-opt:
   # Code from module alloca-opt-tests:
-  # Code from module arg-nonnull:
   # Code from module arpa_inet:
   # Code from module arpa_inet-tests:
   # Code from module autobuild:
@@ -40,32 +53,56 @@ AC_DEFUN([gl_EARLY],
   # Code from module binary-io:
   # Code from module binary-io-tests:
   # Code from module bind:
-  # Code from module c++defs:
+  # Code from module bind-tests:
   # Code from module c-ctype:
   # Code from module c-ctype-tests:
   # Code from module clock-time:
   # Code from module close:
-  # Code from module close-hook:
+  # Code from module close-tests:
   # Code from module connect:
+  # Code from module connect-tests:
+  # Code from module dosname:
+  # Code from module dup2:
+  # Code from module dup2-tests:
   # Code from module errno:
   # Code from module errno-tests:
   # Code from module error:
   # Code from module extensions:
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-  # Code from module fclose:
   # Code from module fcntl-h:
   # Code from module fcntl-h-tests:
+  # Code from module fd-hook:
   # Code from module fdl-1.3:
+  # Code from module fdopen:
+  # Code from module fdopen-tests:
+  # Code from module fgetc-tests:
   # Code from module float:
+  # Code from module float-tests:
+  # 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 fseek:
+  # Code from module fseek-tests:
   # Code from module fseeko:
   AC_REQUIRE([AC_FUNC_FSEEKO])
   # Code from module fseeko-tests:
+  # Code from module fstat:
+  # Code from module fstat-tests:
+  # Code from module ftell:
+  # Code from module ftell-tests:
   # Code from module ftello:
   AC_REQUIRE([AC_FUNC_FSEEKO])
   # Code from module ftello-tests:
+  # Code from module ftruncate:
+  # Code from module ftruncate-tests:
+  # Code from module fwrite-tests:
   # Code from module gendocs:
   # Code from module getaddrinfo:
   # Code from module getaddrinfo-tests:
+  # Code from module getcwd-lgpl:
+  # Code from module getcwd-lgpl-tests:
   # Code from module getdelim:
   # Code from module getdelim-tests:
   # Code from module getline:
@@ -81,28 +118,48 @@ AC_DEFUN([gl_EARLY],
   # Code from module gpl-3.0:
   # Code from module havelib:
   # Code from module hostent:
+  # Code from module ignore-value:
+  # Code from module ignore-value-tests:
   # Code from module include_next:
   # Code from module inet_ntop:
   # Code from module inet_ntop-tests:
   # Code from module inet_pton:
   # Code from module inet_pton-tests:
   # Code from module intprops:
+  # Code from module intprops-tests:
+  # Code from module inttypes:
+  # Code from module inttypes-incomplete:
+  # Code from module inttypes-tests:
   # Code from module ioctl:
+  # Code from module ioctl-tests:
+  # Code from module largefile:
+  AC_REQUIRE([AC_SYS_LARGEFILE])
   # Code from module lgpl-2.1:
   # Code from module listen:
+  # Code from module listen-tests:
+  # Code from module lock:
+  # Code from module lock-tests:
   # Code from module lseek:
   # Code from module lseek-tests:
+  # Code from module lstat:
+  # Code from module lstat-tests:
   # Code from module maintainer-makefile:
   # Code from module malloc-posix:
   # Code from module manywarnings:
   # Code from module memchr:
   # Code from module memchr-tests:
   # 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:
   # Code from module netinet_in:
   # Code from module netinet_in-tests:
+  # Code from module open:
+  # Code from module open-tests:
+  # Code from module pathmax:
+  # Code from module pathmax-tests:
   # Code from module perror:
   # Code from module perror-tests:
   # Code from module pipe-posix:
@@ -114,13 +171,24 @@ AC_DEFUN([gl_EARLY],
   # Code from module readline:
   # Code from module realloc-posix:
   # Code from module recv:
+  # Code from module recv-tests:
+  # Code from module same-inode:
   # Code from module select:
   # Code from module select-tests:
   # Code from module send:
+  # Code from module send-tests:
   # Code from module servent:
   # Code from module setsockopt:
+  # Code from module setsockopt-tests:
   # Code from module shutdown:
+  # Code from module shutdown-tests:
+  # Code from module signal-h:
+  # Code from module signal-h-tests:
   # Code from module size_max:
+  # Code from module snippet/_Noreturn:
+  # Code from module snippet/arg-nonnull:
+  # Code from module snippet/c++defs:
+  # Code from module snippet/warn-on-use:
   # Code from module snprintf:
   # Code from module snprintf-tests:
   # Code from module socket:
@@ -128,12 +196,15 @@ AC_DEFUN([gl_EARLY],
   # Code from module sockets:
   # Code from module sockets-tests:
   # Code from module socklen:
+  # Code from module ssize_t:
+  # Code from module stat:
+  # Code from module stat-tests:
   # 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:
@@ -145,9 +216,14 @@ AC_DEFUN([gl_EARLY],
   # Code from module stdlib:
   # Code from module stdlib-tests:
   # Code from module strerror:
+  # Code from module strerror-override:
   # Code from module strerror-tests:
+  # Code from module strerror_r-posix:
+  # Code from module strerror_r-posix-tests:
   # Code from module string:
   # Code from module string-tests:
+  # Code from module symlink:
+  # Code from module symlink-tests:
   # Code from module sys_ioctl:
   # Code from module sys_ioctl-tests:
   # Code from module sys_select:
@@ -158,6 +234,14 @@ AC_DEFUN([gl_EARLY],
   # Code from module sys_stat-tests:
   # Code from module sys_time:
   # Code from module sys_time-tests:
+  # Code from module sys_types:
+  # Code from module sys_types-tests:
+  # Code from module sys_uio:
+  # Code from module sys_uio-tests:
+  # Code from module thread:
+  # Code from module thread-tests:
+  # Code from module threadlib:
+  gl_THREADLIB_EARLY
   # Code from module time:
   # Code from module time-tests:
   # Code from module timespec:
@@ -176,9 +260,11 @@ AC_DEFUN([gl_EARLY],
   # Code from module version-etc:
   # Code from module version-etc-fsf:
   # Code from module version-etc-tests:
-  # Code from module warn-on-use:
   # Code from module warnings:
+  # Code from module wchar:
+  # Code from module wchar-tests:
   # Code from module xsize:
+  # Code from module yield:
 ])
 
 # This macro should be invoked from ./configure.ac, in the section
@@ -195,260 +281,285 @@ AC_DEFUN([gl_INIT],
   m4_pushdef([gl_LIBSOURCES_DIR], [])
   gl_COMMON
   gl_source_base='gl'
-  # Code from module accept:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([accept])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([accept])
-  # Code from module alignof:
-  # Code from module alloca:
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([accept])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([accept])
 changequote(,)dnl
 LTALLOCA=`echo "$ALLOCA" | sed -e 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`
 changequote([, ])dnl
 AC_SUBST([LTALLOCA])
-  # Code from module alloca-opt:
-  gl_FUNC_ALLOCA
-  # Code from module arg-nonnull:
-  # Code from module arpa_inet:
-  gl_HEADER_ARPA_INET
-  AC_PROG_MKDIR_P
-  # Code from module autobuild:
-  # Code from module bind:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([bind])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([bind])
-  # Code from module c++defs:
-  # Code from module c-ctype:
-  # Code from module clock-time:
-  gl_CLOCK_TIME
-  # Code from module close:
-  gl_FUNC_CLOSE
-  gl_UNISTD_MODULE_INDICATOR([close])
-  # Code from module close-hook:
-  # Code from module connect:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([connect])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([connect])
-  # Code from module errno:
-  gl_HEADER_ERRNO_H
-  # Code from module error:
-  gl_ERROR
-  m4_ifdef([AM_XGETTEXT_OPTION],
-    [AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
-     AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
-  # Code from module extensions:
-  # Code from module fclose:
-  gl_FUNC_FCLOSE
-  gl_STDIO_MODULE_INDICATOR([fclose])
-  # Code from module fdl-1.3:
-  # Code from module float:
-  gl_FLOAT_H
-  # Code from module fseeko:
-  gl_FUNC_FSEEKO
-  gl_STDIO_MODULE_INDICATOR([fseeko])
-  # Code from module ftello:
-  gl_FUNC_FTELLO
-  gl_STDIO_MODULE_INDICATOR([ftello])
-  # Code from module gendocs:
-  # Code from module getaddrinfo:
-  gl_GETADDRINFO
-  gl_NETDB_MODULE_INDICATOR([getaddrinfo])
-  # Code from module getdelim:
-  gl_FUNC_GETDELIM
-  gl_STDIO_MODULE_INDICATOR([getdelim])
-  # Code from module getline:
-  gl_FUNC_GETLINE
-  gl_STDIO_MODULE_INDICATOR([getline])
-  # Code from module getpass-gnu:
-  gl_FUNC_GETPASS_GNU
-  # Code from module gettext-h:
-  AC_SUBST([LIBINTL])
-  AC_SUBST([LTLIBINTL])
-  # Code from module gettime:
-  gl_GETTIME
-  # Code from module gettimeofday:
-  gl_FUNC_GETTIMEOFDAY
-  gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
-  # Code from module gnumakefile:
-  # Autoconf 2.61a.99 and earlier don't support linking a file only
-  # in VPATH builds.  But since GNUmakefile is for maintainer use
-  # only, it does not matter if we skip the link with older autoconf.
-  # Automake 1.10.1 and earlier try to remove GNUmakefile in non-VPATH
-  # builds, so use a shell variable to bypass this.
-  GNUmakefile=GNUmakefile
-  m4_if(m4_version_compare([2.61a.100],
-       m4_defn([m4_PACKAGE_VERSION])), [1], [],
-        [AC_CONFIG_LINKS([$GNUmakefile:$GNUmakefile], [],
-       [GNUmakefile=$GNUmakefile])])
-  # Code from module gnupload:
-  # Code from module gpl-3.0:
-  # Code from module havelib:
-  # Code from module hostent:
-  gl_HOSTENT
-  # Code from module include_next:
-  # Code from module inet_ntop:
-  gl_FUNC_INET_NTOP
-  gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
-  # Code from module inet_pton:
-  gl_FUNC_INET_PTON
-  gl_ARPA_INET_MODULE_INDICATOR([inet_pton])
-  # Code from module intprops:
-  # Code from module lgpl-2.1:
-  # Code from module listen:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([listen])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([listen])
-  # Code from module lseek:
-  gl_FUNC_LSEEK
-  gl_UNISTD_MODULE_INDICATOR([lseek])
-  # Code from module maintainer-makefile:
-  AC_CONFIG_COMMANDS_PRE([m4_ifdef([AH_HEADER],
-    [AC_SUBST([CONFIG_INCLUDE], m4_defn([AH_HEADER]))])])
-  # Code from module malloc-posix:
-  gl_FUNC_MALLOC_POSIX
-  gl_STDLIB_MODULE_INDICATOR([malloc-posix])
-  # Code from module manywarnings:
-  # Code from module memchr:
-  gl_FUNC_MEMCHR
-  gl_STRING_MODULE_INDICATOR([memchr])
-  # Code from module minmax:
-  gl_MINMAX
-  # Code from module multiarch:
-  gl_MULTIARCH
-  # Code from module netdb:
-  gl_HEADER_NETDB
-  # Code from module netinet_in:
-  gl_HEADER_NETINET_IN
-  AC_PROG_MKDIR_P
-  # Code from module perror:
-  gl_FUNC_PERROR
-  gl_STRING_MODULE_INDICATOR([perror])
-  # Code from module pmccabe2html:
-  AC_PATH_PROG([PMCCABE], [pmccabe], [false])
-  # Code from module progname:
-  AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
-  AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
-  # Code from module read-file:
-  gl_FUNC_READ_FILE
-  # Code from module readline:
-  gl_FUNC_READLINE
-  # Code from module realloc-posix:
-  gl_FUNC_REALLOC_POSIX
-  gl_STDLIB_MODULE_INDICATOR([realloc-posix])
-  # Code from module recv:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([recv])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([recv])
-  # Code from module select:
-  gl_FUNC_SELECT
-  gl_SYS_SELECT_MODULE_INDICATOR([select])
-  # Code from module send:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([send])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([send])
-  # Code from module servent:
-  gl_SERVENT
-  # Code from module setsockopt:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([setsockopt])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([setsockopt])
-  # Code from module shutdown:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([shutdown])
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([shutdown])
-  # Code from module size_max:
-  gl_SIZE_MAX
-  # Code from module snprintf:
-  gl_FUNC_SNPRINTF
-  gl_STDIO_MODULE_INDICATOR([snprintf])
-  gl_MODULE_INDICATOR([snprintf])
-  # Code from module socket:
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([socket])
-  fi
-  # When this module is used, sockets may actually occur as file descriptors,
-  # hence it is worth warning if the modules 'close' and 'ioctl' are not used.
-  m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
-  m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
-  AC_REQUIRE([gl_PREREQ_SYS_H_WINSOCK2])
-  if test "$ac_cv_header_winsock2_h" = yes; then
-    UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
-    SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
-  fi
-  gl_SYS_SOCKET_MODULE_INDICATOR([socket])
-  # Code from module socketlib:
-  gl_SOCKETLIB
-  # Code from module sockets:
-  gl_SOCKETS
-  # Code from module socklen:
-  gl_TYPE_SOCKLEN_T
-  # Code from module stdarg:
-  gl_STDARG_H
-  # Code from module stdbool:
-  AM_STDBOOL_H
-  # Code from module stddef:
-  gl_STDDEF_H
-  # Code from module stdint:
-  gl_STDINT_H
-  # Code from module stdio:
-  gl_STDIO_H
-  # Code from module stdlib:
-  gl_STDLIB_H
-  # Code from module strerror:
-  gl_FUNC_STRERROR
-  gl_STRING_MODULE_INDICATOR([strerror])
-  # Code from module string:
-  gl_HEADER_STRING_H
-  # Code from module sys_select:
-  gl_HEADER_SYS_SELECT
-  AC_PROG_MKDIR_P
-  # Code from module sys_socket:
-  gl_HEADER_SYS_SOCKET
-  AC_PROG_MKDIR_P
-  # Code from module sys_stat:
-  gl_HEADER_SYS_STAT_H
-  AC_PROG_MKDIR_P
-  # Code from module sys_time:
-  gl_HEADER_SYS_TIME_H
-  AC_PROG_MKDIR_P
-  # Code from module time:
-  gl_HEADER_TIME_H
-  # Code from module timespec:
-  gl_TIMESPEC
-  # Code from module unistd:
-  gl_UNISTD_H
-  # Code from module update-copyright:
-  # Code from module useless-if-before-free:
-  # Code from module valgrind-tests:
-  gl_VALGRIND_TESTS
-  # Code from module vasnprintf:
-  gl_FUNC_VASNPRINTF
-  # Code from module vc-list-files:
-  # Code from module verify:
-  # Code from module version-etc:
-  gl_VERSION_ETC
-  # Code from module version-etc-fsf:
-  # Code from module warn-on-use:
-  # Code from module warnings:
-  AC_SUBST([WARN_CFLAGS])
-  # Code from module xsize:
-  gl_XSIZE
+gl_FUNC_ALLOCA
+gl_HEADER_ARPA_INET
+AC_PROG_MKDIR_P
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([bind])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([bind])
+gl_CLOCK_TIME
+gl_FUNC_CLOSE
+if test $REPLACE_CLOSE = 1; then
+  AC_LIBOBJ([close])
+fi
+gl_UNISTD_MODULE_INDICATOR([close])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([connect])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([connect])
+gl_HEADER_ERRNO_H
+gl_ERROR
+if test $ac_cv_lib_error_at_line = no; then
+  AC_LIBOBJ([error])
+  gl_PREREQ_ERROR
+fi
+m4_ifdef([AM_XGETTEXT_OPTION],
+  [AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
+   AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
+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_FSEEK
+if test $REPLACE_FSEEK = 1; then
+  AC_LIBOBJ([fseek])
+fi
+gl_STDIO_MODULE_INDICATOR([fseek])
+gl_FUNC_FSEEKO
+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])
+fi
+gl_STDIO_MODULE_INDICATOR([ftell])
+gl_FUNC_FTELLO
+if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
+  AC_LIBOBJ([ftello])
+fi
+gl_STDIO_MODULE_INDICATOR([ftello])
+gl_GETADDRINFO
+if test $HAVE_GETADDRINFO = 0; then
+  AC_LIBOBJ([getaddrinfo])
+fi
+if test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1; then
+  AC_LIBOBJ([gai_strerror])
+fi
+gl_NETDB_MODULE_INDICATOR([getaddrinfo])
+gl_FUNC_GETDELIM
+if test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1; then
+  AC_LIBOBJ([getdelim])
+  gl_PREREQ_GETDELIM
+fi
+gl_STDIO_MODULE_INDICATOR([getdelim])
+gl_FUNC_GETLINE
+if test $REPLACE_GETLINE = 1; then
+  AC_LIBOBJ([getline])
+  gl_PREREQ_GETLINE
+fi
+gl_STDIO_MODULE_INDICATOR([getline])
+gl_FUNC_GETPASS_GNU
+if test $REPLACE_GETPASS = 1; then
+  AC_LIBOBJ([getpass])
+  gl_PREREQ_GETPASS
+fi
+AC_SUBST([LIBINTL])
+AC_SUBST([LTLIBINTL])
+gl_GETTIME
+gl_FUNC_GETTIMEOFDAY
+if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
+  AC_LIBOBJ([gettimeofday])
+  gl_PREREQ_GETTIMEOFDAY
+fi
+gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
+# Autoconf 2.61a.99 and earlier don't support linking a file only
+# in VPATH builds.  But since GNUmakefile is for maintainer use
+# only, it does not matter if we skip the link with older autoconf.
+# Automake 1.10.1 and earlier try to remove GNUmakefile in non-VPATH
+# builds, so use a shell variable to bypass this.
+GNUmakefile=GNUmakefile
+m4_if(m4_version_compare([2.61a.100],
+        m4_defn([m4_PACKAGE_VERSION])), [1], [],
+      [AC_CONFIG_LINKS([$GNUmakefile:$GNUmakefile], [],
+        [GNUmakefile=$GNUmakefile])])
+gl_HOSTENT
+gl_FUNC_INET_NTOP
+if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then
+  AC_LIBOBJ([inet_ntop])
+  gl_PREREQ_INET_NTOP
+fi
+gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
+gl_FUNC_INET_PTON
+if test $HAVE_INET_PTON = 0 || test $REPLACE_INET_NTOP = 1; then
+  AC_LIBOBJ([inet_pton])
+  gl_PREREQ_INET_PTON
+fi
+gl_ARPA_INET_MODULE_INDICATOR([inet_pton])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([listen])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([listen])
+gl_LOCK
+gl_FUNC_LSEEK
+if test $REPLACE_LSEEK = 1; then
+  AC_LIBOBJ([lseek])
+fi
+gl_UNISTD_MODULE_INDICATOR([lseek])
+AC_CONFIG_COMMANDS_PRE([m4_ifdef([AH_HEADER],
+  [AC_SUBST([CONFIG_INCLUDE], m4_defn([AH_HEADER]))])])
+gl_FUNC_MALLOC_POSIX
+if test $REPLACE_MALLOC = 1; then
+  AC_LIBOBJ([malloc])
+fi
+gl_STDLIB_MODULE_INDICATOR([malloc-posix])
+gl_FUNC_MEMCHR
+if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
+  AC_LIBOBJ([memchr])
+  gl_PREREQ_MEMCHR
+fi
+gl_STRING_MODULE_INDICATOR([memchr])
+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
+AC_PROG_MKDIR_P
+gl_FUNC_PERROR
+if test $REPLACE_PERROR = 1; then
+  AC_LIBOBJ([perror])
+fi
+gl_STRING_MODULE_INDICATOR([perror])
+AC_PATH_PROG([PMCCABE], [pmccabe], [false])
+AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
+AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
+gl_PREREQ_READ_FILE
+gl_FUNC_READLINE
+if test "$gl_cv_lib_readline" = no; then
+  AC_LIBOBJ([readline])
+  gl_PREREQ_READLINE
+fi
+gl_FUNC_REALLOC_POSIX
+if test $REPLACE_REALLOC = 1; then
+  AC_LIBOBJ([realloc])
+fi
+gl_STDLIB_MODULE_INDICATOR([realloc-posix])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([recv])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([recv])
+gl_FUNC_SELECT
+if test $REPLACE_SELECT = 1; then
+  AC_LIBOBJ([select])
+fi
+gl_SYS_SELECT_MODULE_INDICATOR([select])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([send])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([send])
+gl_SERVENT
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([setsockopt])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([setsockopt])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([shutdown])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([shutdown])
+gl_SIGNAL_H
+gl_SIZE_MAX
+gl_FUNC_SNPRINTF
+gl_STDIO_MODULE_INDICATOR([snprintf])
+gl_MODULE_INDICATOR([snprintf])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([socket])
+fi
+# When this module is used, sockets may actually occur as file descriptors,
+# hence it is worth warning if the modules 'close' and 'ioctl' are not used.
+m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
+m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
+AC_REQUIRE([gl_PREREQ_SYS_H_WINSOCK2])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([socket])
+gl_SOCKETLIB
+gl_SOCKETS
+gl_TYPE_SOCKLEN_T
+gt_TYPE_SSIZE_T
+gl_STDARG_H
+AM_STDBOOL_H
+gl_STDDEF_H
+gl_STDINT_H
+gl_STDIO_H
+gl_STDLIB_H
+gl_FUNC_STRERROR
+if test $REPLACE_STRERROR = 1; then
+  AC_LIBOBJ([strerror])
+fi
+gl_MODULE_INDICATOR([strerror])
+gl_STRING_MODULE_INDICATOR([strerror])
+AC_REQUIRE([gl_HEADER_ERRNO_H])
+AC_REQUIRE([gl_FUNC_STRERROR_0])
+if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then
+  AC_LIBOBJ([strerror-override])
+  gl_PREREQ_SYS_H_WINSOCK2
+fi
+gl_FUNC_STRERROR_R
+if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
+  AC_LIBOBJ([strerror_r])
+  gl_PREREQ_STRERROR_R
+fi
+gl_STRING_MODULE_INDICATOR([strerror_r])
+gl_HEADER_STRING_H
+gl_HEADER_SYS_SELECT
+AC_PROG_MKDIR_P
+gl_HEADER_SYS_SOCKET
+AC_PROG_MKDIR_P
+gl_HEADER_SYS_STAT_H
+AC_PROG_MKDIR_P
+gl_HEADER_SYS_TIME_H
+AC_PROG_MKDIR_P
+gl_SYS_TYPES_H
+AC_PROG_MKDIR_P
+gl_HEADER_SYS_UIO
+AC_PROG_MKDIR_P
+gl_THREADLIB
+gl_HEADER_TIME_H
+gl_TIMESPEC
+gl_UNISTD_H
+gl_VALGRIND_TESTS
+gl_FUNC_VASNPRINTF
+gl_VERSION_ETC
+AC_SUBST([WARN_CFLAGS])
+gl_WCHAR_H
+gl_XSIZE
   # End of code from modules
   m4_ifval(gl_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
@@ -495,32 +606,95 @@ changequote([, ])dnl
   AC_SUBST([gltests_WITNESS])
   gl_module_indicator_condition=$gltests_WITNESS
   m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition])
-  gl_FCNTL_H
-  gl_FUNC_UNGETC_WORKS
-  gl_FUNC_UNGETC_WORKS
-  gl_FUNC_GETPAGESIZE
-  gl_UNISTD_MODULE_INDICATOR([getpagesize])
-  AC_C_BIGENDIAN
-  AC_C_BIGENDIAN
-  gl_FUNC_IOCTL
-  gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
-  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_FUNC_PIPE
-  gl_UNISTD_MODULE_INDICATOR([pipe])
-  AC_CHECK_HEADERS_ONCE([sys/wait.h])
-  gt_TYPE_WCHAR_T
-  gt_TYPE_WINT_T
-  gl_SYS_IOCTL_H
-  AC_PROG_MKDIR_P
-  AC_CHECK_FUNCS_ONCE([shutdown])
-  abs_aux_dir=`cd "$ac_aux_dir"; pwd`
-  AC_SUBST([abs_aux_dir])
-  gl_VALGRIND_TESTS
-  abs_aux_dir=`cd "$ac_aux_dir"; pwd`
-  AC_SUBST([abs_aux_dir])
+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_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
+gl_FUNC_UNGETC_WORKS
+gl_FUNC_FTRUNCATE
+if test $HAVE_FTRUNCATE = 0; then
+  AC_LIBOBJ([ftruncate])
+  gl_PREREQ_FTRUNCATE
+fi
+gl_UNISTD_MODULE_INDICATOR([ftruncate])
+gl_FUNC_GETCWD_LGPL
+if test $REPLACE_GETCWD = 1; then
+  AC_LIBOBJ([getcwd-lgpl])
+fi
+gl_UNISTD_MODULE_INDICATOR([getcwd])
+gl_FUNC_GETPAGESIZE
+if test $REPLACE_GETPAGESIZE = 1; then
+  AC_LIBOBJ([getpagesize])
+fi
+gl_UNISTD_MODULE_INDICATOR([getpagesize])
+AC_REQUIRE([AC_C_INLINE])
+AC_C_BIGENDIAN
+AC_C_BIGENDIAN
+gl_INTTYPES_H
+gl_INTTYPES_INCOMPLETE
+gl_FUNC_IOCTL
+if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+  AC_LIBOBJ([ioctl])
+fi
+gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
+gl_FUNC_LSTAT
+if test $REPLACE_LSTAT = 1; then
+  AC_LIBOBJ([lstat])
+  gl_PREREQ_LSTAT
+fi
+gl_SYS_STAT_MODULE_INDICATOR([lstat])
+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_FUNC_OPEN
+if test $REPLACE_OPEN = 1; then
+  AC_LIBOBJ([open])
+  gl_PREREQ_OPEN
+fi
+gl_FCNTL_MODULE_INDICATOR([open])
+gl_PATHMAX
+gl_FUNC_PIPE
+if test $HAVE_PIPE = 0; then
+  AC_LIBOBJ([pipe])
+fi
+gl_UNISTD_MODULE_INDICATOR([pipe])
+AC_CHECK_HEADERS_ONCE([sys/wait.h])
+gl_FUNC_STAT
+if test $REPLACE_STAT = 1; then
+  AC_LIBOBJ([stat])
+  gl_PREREQ_STAT
+fi
+gl_SYS_STAT_MODULE_INDICATOR([stat])
+gt_TYPE_WCHAR_T
+gt_TYPE_WINT_T
+gl_FUNC_SYMLINK
+if test $HAVE_SYMLINK = 0 || test $REPLACE_SYMLINK = 1; then
+  AC_LIBOBJ([symlink])
+fi
+gl_UNISTD_MODULE_INDICATOR([symlink])
+gl_SYS_IOCTL_H
+AC_PROG_MKDIR_P
+AC_CHECK_FUNCS_ONCE([shutdown])
+gl_THREAD
+abs_aux_dir=`cd "$ac_aux_dir"; pwd`
+AC_SUBST([abs_aux_dir])
+gl_VALGRIND_TESTS
+abs_aux_dir=`cd "$ac_aux_dir"; pwd`
+AC_SUBST([abs_aux_dir])
+gl_YIELD
   m4_popdef([gl_MODULE_INDICATOR_CONDITION])
   m4_ifval(gltests_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ ||
@@ -613,17 +787,18 @@ AC_DEFUN([gltests_LIBSOURCES], [
 # This macro records the list of files which have been installed by
 # gnulib-tool and may be removed by future gnulib-tool invocations.
 AC_DEFUN([gl_FILE_LIST], [
-  build-aux/arg-nonnull.h
-  build-aux/c++defs.h
   build-aux/config.rpath
   build-aux/gendocs.sh
   build-aux/gnupload
   build-aux/pmccabe.css
   build-aux/pmccabe2html
+  build-aux/snippet/_Noreturn.h
+  build-aux/snippet/arg-nonnull.h
+  build-aux/snippet/c++defs.h
+  build-aux/snippet/warn-on-use.h
   build-aux/update-copyright
   build-aux/useless-if-before-free
   build-aux/vc-list-files
-  build-aux/warn-on-use.h
   doc/fdl-1.3.texi
   doc/gendocs_template
   doc/gpl-3.0.texi
@@ -637,17 +812,20 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/bind.c
   lib/c-ctype.c
   lib/c-ctype.h
-  lib/close-hook.c
-  lib/close-hook.h
   lib/close.c
   lib/connect.c
   lib/errno.in.h
   lib/error.c
   lib/error.h
-  lib/fclose.c
+  lib/fd-hook.c
+  lib/fd-hook.h
   lib/float+.h
+  lib/float.c
   lib/float.in.h
+  lib/fseek.c
   lib/fseeko.c
+  lib/fstat.c
+  lib/ftell.c
   lib/ftello.c
   lib/gai_strerror.c
   lib/getaddrinfo.c
@@ -658,15 +836,23 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/gettext.h
   lib/gettime.c
   lib/gettimeofday.c
+  lib/glthread/lock.c
+  lib/glthread/lock.h
+  lib/glthread/threadlib.c
   lib/inet_ntop.c
   lib/inet_pton.c
   lib/intprops.h
+  lib/itold.c
   lib/listen.c
   lib/lseek.c
   lib/malloc.c
   lib/memchr.c
   lib/memchr.valgrind
   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/perror.c
@@ -686,6 +872,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/send.c
   lib/setsockopt.c
   lib/shutdown.c
+  lib/signal.in.h
   lib/size_max.h
   lib/snprintf.c
   lib/socket.c
@@ -696,15 +883,19 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/stddef.in.h
   lib/stdint.in.h
   lib/stdio-impl.h
-  lib/stdio-write.c
   lib/stdio.in.h
   lib/stdlib.in.h
+  lib/strerror-override.c
+  lib/strerror-override.h
   lib/strerror.c
+  lib/strerror_r.c
   lib/string.in.h
   lib/sys_select.in.h
   lib/sys_socket.in.h
   lib/sys_stat.in.h
   lib/sys_time.in.h
+  lib/sys_types.in.h
+  lib/sys_uio.in.h
   lib/time.in.h
   lib/timespec.h
   lib/unistd.in.h
@@ -715,24 +906,31 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/version-etc.c
   lib/version-etc.h
   lib/w32sock.h
+  lib/wchar.in.h
   lib/xsize.h
   m4/00gnulib.m4
   m4/alloca.m4
   m4/arpa_inet_h.m4
-  m4/asm-underscore.m4
   m4/autobuild.m4
   m4/clock_time.m4
   m4/close.m4
+  m4/dup2.m4
   m4/errno_h.m4
   m4/error.m4
   m4/extensions.m4
-  m4/fclose.m4
   m4/fcntl-o.m4
   m4/fcntl_h.m4
+  m4/fdopen.m4
   m4/float_h.m4
+  m4/fpieee.m4
+  m4/fseek.m4
   m4/fseeko.m4
+  m4/fstat.m4
+  m4/ftell.m4
   m4/ftello.m4
+  m4/ftruncate.m4
   m4/getaddrinfo.m4
+  m4/getcwd.m4
   m4/getdelim.m4
   m4/getline.m4
   m4/getpagesize.m4
@@ -745,21 +943,31 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/inet_ntop.m4
   m4/inet_pton.m4
   m4/intmax_t.m4
+  m4/inttypes-pri.m4
+  m4/inttypes.m4
   m4/inttypes_h.m4
   m4/ioctl.m4
+  m4/largefile.m4
   m4/lib-ld.m4
   m4/lib-link.m4
   m4/lib-prefix.m4
+  m4/lock.m4
   m4/longlong.m4
   m4/lseek.m4
+  m4/lstat.m4
   m4/malloc.m4
   m4/manywarnings.m4
   m4/memchr.m4
   m4/minmax.m4
   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
+  m4/open.m4
+  m4/pathmax.m4
   m4/perror.m4
   m4/pipe.m4
   m4/printf.m4
@@ -768,12 +976,15 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/realloc.m4
   m4/select.m4
   m4/servent.m4
+  m4/signal_h.m4
   m4/size_max.m4
   m4/snprintf.m4
   m4/socketlib.m4
   m4/sockets.m4
   m4/socklen.m4
   m4/sockpfaf.m4
+  m4/ssize_t.m4
+  m4/stat.m4
   m4/stdarg.m4
   m4/stdbool.m4
   m4/stddef_h.m4
@@ -782,12 +993,18 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/stdio_h.m4
   m4/stdlib_h.m4
   m4/strerror.m4
+  m4/strerror_r.m4
   m4/string_h.m4
+  m4/symlink.m4
   m4/sys_ioctl_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
   m4/sys_time_h.m4
+  m4/sys_types_h.m4
+  m4/sys_uio_h.m4
+  m4/thread.m4
+  m4/threadlib.m4
   m4/time_h.m4
   m4/timespec.m4
   m4/ungetc.m4
@@ -797,62 +1014,119 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/version-etc.m4
   m4/warn-on-use.m4
   m4/warnings.m4
+  m4/wchar_h.m4
   m4/wchar_t.m4
   m4/wint_t.m4
   m4/xsize.m4
+  m4/yield.m4
   tests/init.sh
   tests/macros.h
   tests/signature.h
+  tests/test-accept.c
   tests/test-alignof.c
   tests/test-alloca-opt.c
   tests/test-arpa_inet.c
   tests/test-binary-io.c
   tests/test-binary-io.sh
+  tests/test-bind.c
   tests/test-c-ctype.c
+  tests/test-close.c
+  tests/test-connect.c
+  tests/test-dup2.c
   tests/test-errno.c
   tests/test-fcntl-h.c
+  tests/test-fdopen.c
+  tests/test-fgetc.c
+  tests/test-float.c
+  tests/test-fputc.c
+  tests/test-fread.c
+  tests/test-fseek.c
+  tests/test-fseek.sh
+  tests/test-fseek2.sh
   tests/test-fseeko.c
   tests/test-fseeko.sh
   tests/test-fseeko2.sh
+  tests/test-fseeko3.c
+  tests/test-fseeko3.sh
+  tests/test-fseeko4.c
+  tests/test-fseeko4.sh
+  tests/test-fstat.c
+  tests/test-ftell.c
+  tests/test-ftell.sh
+  tests/test-ftell2.sh
+  tests/test-ftell3.c
   tests/test-ftello.c
   tests/test-ftello.sh
   tests/test-ftello2.sh
   tests/test-ftello3.c
+  tests/test-ftello4.c
+  tests/test-ftello4.sh
+  tests/test-ftruncate.c
+  tests/test-ftruncate.sh
+  tests/test-fwrite.c
   tests/test-getaddrinfo.c
+  tests/test-getcwd-lgpl.c
   tests/test-getdelim.c
   tests/test-getline.c
   tests/test-gettimeofday.c
+  tests/test-ignore-value.c
   tests/test-inet_ntop.c
   tests/test-inet_pton.c
+  tests/test-intprops.c
+  tests/test-inttypes.c
+  tests/test-ioctl.c
+  tests/test-listen.c
+  tests/test-lock.c
   tests/test-lseek.c
   tests/test-lseek.sh
+  tests/test-lstat.c
+  tests/test-lstat.h
   tests/test-memchr.c
   tests/test-netdb.c
   tests/test-netinet_in.c
+  tests/test-open.c
+  tests/test-open.h
+  tests/test-pathmax.c
   tests/test-perror.c
   tests/test-perror.sh
+  tests/test-perror2.c
   tests/test-pipe.c
   tests/test-read-file.c
+  tests/test-recv.c
   tests/test-select-fd.c
   tests/test-select-in.sh
   tests/test-select-out.sh
   tests/test-select-stdin.c
   tests/test-select.c
+  tests/test-select.h
+  tests/test-send.c
+  tests/test-setsockopt.c
+  tests/test-shutdown.c
+  tests/test-signal-h.c
   tests/test-snprintf.c
   tests/test-sockets.c
+  tests/test-stat.c
+  tests/test-stat.h
   tests/test-stdbool.c
   tests/test-stddef.c
   tests/test-stdint.c
   tests/test-stdio.c
   tests/test-stdlib.c
   tests/test-strerror.c
+  tests/test-strerror_r.c
   tests/test-string.c
+  tests/test-symlink.c
+  tests/test-symlink.h
   tests/test-sys_ioctl.c
   tests/test-sys_select.c
   tests/test-sys_socket.c
   tests/test-sys_stat.c
   tests/test-sys_time.c
+  tests/test-sys_types.c
+  tests/test-sys_uio.c
   tests/test-sys_wait.h
+  tests/test-thread_create.c
+  tests/test-thread_self.c
   tests/test-time.c
   tests/test-unistd.c
   tests/test-update-copyright.sh
@@ -863,13 +1137,30 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-verify.sh
   tests/test-version-etc.c
   tests/test-version-etc.sh
+  tests/test-wchar.c
   tests/zerosize-ptr.h
   tests=lib/binary-io.h
-  tests=lib/dummy.c
+  tests=lib/dosname.h
+  tests=lib/dup2.c
   tests=lib/fcntl.in.h
+  tests=lib/fdopen.c
+  tests=lib/fpucw.h
+  tests=lib/ftruncate.c
+  tests=lib/getcwd-lgpl.c
   tests=lib/getpagesize.c
+  tests=lib/glthread/thread.c
+  tests=lib/glthread/thread.h
+  tests=lib/glthread/yield.h
+  tests=lib/ignore-value.h
+  tests=lib/inttypes.in.h
   tests=lib/ioctl.c
+  tests=lib/lstat.c
+  tests=lib/open.c
+  tests=lib/pathmax.h
   tests=lib/pipe.c
+  tests=lib/same-inode.h
+  tests=lib/stat.c
+  tests=lib/symlink.c
   tests=lib/sys_ioctl.in.h
   tests=lib/w32sock.h
   top/GNUmakefile
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
index b3c7849..d5230ce 100644
--- a/gl/m4/include_next.m4
+++ b/gl/m4/include_next.m4
@@ -1,4 +1,4 @@
-# include_next.m4 serial 18
+# include_next.m4 serial 22
 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,
@@ -175,11 +175,13 @@ AC_DEFUN([gl_NEXT_HEADERS_INTERNAL],
     [AC_CHECK_HEADERS_ONCE([$1])
     ])
 
+dnl FIXME: gl_next_header and gl_header_exists must be used unquoted
+dnl until we can assume autoconf 2.64 or newer.
   m4_foreach_w([gl_HEADER_NAME], [$1],
     [AS_VAR_PUSHDEF([gl_next_header],
                     [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
      if test $gl_cv_have_include_next = yes; then
-       AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
+       AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>'])
      else
        AC_CACHE_CHECK(
          [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
@@ -205,33 +207,52 @@ AC_DEFUN([gl_NEXT_HEADERS_INTERNAL],
                  aix*) gl_absname_cpp="$ac_cpp -C" ;;
                  *)    gl_absname_cpp="$ac_cpp" ;;
                esac
+changequote(,)
+               case "$host_os" in
+                 mingw*)
+                   dnl For the sake of native Windows compilers (excluding 
gcc),
+                   dnl treat backslash as a directory separator, like /.
+                   dnl Actually, these compilers use a double-backslash as
+                   dnl directory separator, inside the
+                   dnl   # line "filename"
+                   dnl directives.
+                   gl_dirsep_regex='[/\\]'
+                   ;;
+                 *)
+                   gl_dirsep_regex='/'
+                   ;;
+               esac
+changequote([,])
+               
gl_absolute_header_sed='\|'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[|{
+                   
s|.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*|\1|
+changequote(,)dnl
+                   s|^/[^/]|//&|
+changequote([,])dnl
+                   p
+                   q
+                 }'
                dnl eval is necessary to expand gl_absname_cpp.
                dnl Ultrix and Pyramid sh refuse to redirect output of eval,
                dnl so use subshell.
-               AS_VAR_SET([gl_next_header],
+               AS_VAR_SET(gl_next_header,
                  ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 
2>&AS_MESSAGE_LOG_FD |
-                  sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
-                    s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
-                    s#^/[^/]#//&#
-                    p
-                    q
-                  }'`'"'])
+                      sed -n "$gl_absolute_header_sed"`'"'])
           m4_if([$2], [check],
             [else
-               AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
+               AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>'])
              fi
             ])
          ])
      fi
      AC_SUBST(
        AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
-       [AS_VAR_GET([gl_next_header])])
+       [AS_VAR_GET(gl_next_header)])
      if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = 
buggy; then
        # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
        gl_next_as_first_directive='<'gl_HEADER_NAME'>'
      else
        # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
-       gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
+       gl_next_as_first_directive=AS_VAR_GET(gl_next_header)
      fi
      AC_SUBST(
        AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4
index 57580b8..8291edd 100644
--- a/gl/m4/inet_ntop.m4
+++ b/gl/m4/inet_ntop.m4
@@ -1,4 +1,4 @@
-# inet_ntop.m4 serial 13
+# inet_ntop.m4 serial 18
 dnl Copyright (C) 2005-2006, 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,
@@ -9,36 +9,58 @@ AC_DEFUN([gl_FUNC_INET_NTOP],
   dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop.
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
-  gl_REPLACE_ARPA_INET_H
+  AC_REQUIRE([AC_C_RESTRICT])
 
   dnl Most platforms that provide inet_ntop define it in libc.
   dnl Solaris 8..10 provide inet_ntop in libnsl instead.
-  gl_save_LIBS=$LIBS
-  AC_SEARCH_LIBS([inet_ntop], [nsl], [],
-    [AC_REPLACE_FUNCS([inet_ntop])])
-  LIBS=$gl_save_LIBS
+  dnl Solaris 2.6..7 provide inet_ntop in libresolv instead.
+  dnl Native Windows provides it in -lws2_32 instead, with a declaration in
+  dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
+  dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
+  HAVE_INET_NTOP=1
   INET_NTOP_LIB=
-  if test "$ac_cv_search_inet_ntop" != "no" &&
-     test "$ac_cv_search_inet_ntop" != "none required"; then
-    INET_NTOP_LIB="$ac_cv_search_inet_ntop"
+  gl_PREREQ_SYS_H_WINSOCK2
+  if test $HAVE_WINSOCK2_H = 1; then
+    AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]])
+    if test $ac_cv_have_decl_inet_ntop = yes; then
+      dnl It needs to be overridden, because the stdcall calling convention
+      dnl is not compliant with POSIX.
+      REPLACE_INET_NTOP=1
+      INET_NTOP_LIB="-lws2_32"
+    else
+      HAVE_DECL_INET_NTOP=0
+      HAVE_INET_NTOP=0
+    fi
+  else
+    gl_save_LIBS=$LIBS
+    AC_SEARCH_LIBS([inet_ntop], [nsl resolv], [],
+      [AC_CHECK_FUNCS([inet_ntop])
+       if test $ac_cv_func_inet_ntop = no; then
+         HAVE_INET_NTOP=0
+       fi
+      ])
+    LIBS=$gl_save_LIBS
+
+    if test "$ac_cv_search_inet_ntop" != "no" \
+       && test "$ac_cv_search_inet_ntop" != "none required"; then
+      INET_NTOP_LIB="$ac_cv_search_inet_ntop"
+    fi
+
+    AC_CHECK_HEADERS_ONCE([netdb.h])
+    AC_CHECK_DECLS([inet_ntop],,,
+      [[#include <arpa/inet.h>
+        #if HAVE_NETDB_H
+        # include <netdb.h>
+        #endif
+      ]])
+    if test $ac_cv_have_decl_inet_ntop = no; then
+      HAVE_DECL_INET_NTOP=0
+    fi
   fi
   AC_SUBST([INET_NTOP_LIB])
-
-  gl_PREREQ_INET_NTOP
 ])
 
 # Prerequisites of lib/inet_ntop.c.
 AC_DEFUN([gl_PREREQ_INET_NTOP], [
-  AC_CHECK_HEADERS_ONCE([netdb.h])
-  AC_CHECK_DECLS([inet_ntop],,,
-    [#include <arpa/inet.h>
-     #if HAVE_NETDB_H
-     # include <netdb.h>
-     #endif
-    ])
-  if test $ac_cv_have_decl_inet_ntop = no; then
-    HAVE_DECL_INET_NTOP=0
-  fi
   AC_REQUIRE([gl_SOCKET_FAMILIES])
-  AC_REQUIRE([AC_C_RESTRICT])
 ])
diff --git a/gl/m4/inet_pton.m4 b/gl/m4/inet_pton.m4
index 9a7ad3b..807a4dd 100644
--- a/gl/m4/inet_pton.m4
+++ b/gl/m4/inet_pton.m4
@@ -1,4 +1,4 @@
-# inet_pton.m4 serial 11
+# inet_pton.m4 serial 16
 dnl Copyright (C) 2006, 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,
@@ -9,36 +9,58 @@ AC_DEFUN([gl_FUNC_INET_PTON],
   dnl Persuade Solaris <arpa/inet.h> to declare inet_pton.
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
-  gl_REPLACE_ARPA_INET_H
+  AC_REQUIRE([AC_C_RESTRICT])
 
   dnl Most platforms that provide inet_pton define it in libc.
   dnl Solaris 8..10 provide inet_pton in libnsl instead.
-  gl_save_LIBS=$LIBS
-  AC_SEARCH_LIBS([inet_pton], [nsl], [],
-    [AC_REPLACE_FUNCS([inet_pton])])
-  LIBS=$gl_save_LIBS
+  dnl Solaris 2.6..7 provide inet_pton in libresolv instead.
+  dnl Native Windows provides it in -lws2_32 instead, with a declaration in
+  dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
+  dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
+  HAVE_INET_PTON=1
   INET_PTON_LIB=
-  if test "$ac_cv_search_inet_pton" != "no" &&
-     test "$ac_cv_search_inet_pton" != "none required"; then
-    INET_PTON_LIB="$ac_cv_search_inet_pton"
+  gl_PREREQ_SYS_H_WINSOCK2
+  if test $HAVE_WINSOCK2_H = 1; then
+    AC_CHECK_DECLS([inet_pton],,, [[#include <ws2tcpip.h>]])
+    if test $ac_cv_have_decl_inet_pton = yes; then
+      dnl It needs to be overridden, because the stdcall calling convention
+      dnl is not compliant with POSIX.
+      REPLACE_INET_PTON=1
+      INET_PTON_LIB="-lws2_32"
+    else
+      HAVE_DECL_INET_PTON=0
+      HAVE_INET_PTON=0
+    fi
+  else
+    gl_save_LIBS=$LIBS
+    AC_SEARCH_LIBS([inet_pton], [nsl resolv], [],
+      [AC_CHECK_FUNCS([inet_pton])
+       if test $ac_cv_func_inet_pton = no; then
+         HAVE_INET_PTON=0
+       fi
+      ])
+    LIBS=$gl_save_LIBS
+
+    if test "$ac_cv_search_inet_pton" != "no" \
+       && test "$ac_cv_search_inet_pton" != "none required"; then
+      INET_PTON_LIB="$ac_cv_search_inet_pton"
+    fi
+
+    AC_CHECK_HEADERS_ONCE([netdb.h])
+    AC_CHECK_DECLS([inet_pton],,,
+      [[#include <arpa/inet.h>
+        #if HAVE_NETDB_H
+        # include <netdb.h>
+        #endif
+      ]])
+    if test $ac_cv_have_decl_inet_pton = no; then
+      HAVE_DECL_INET_PTON=0
+    fi
   fi
   AC_SUBST([INET_PTON_LIB])
-
-  gl_PREREQ_INET_PTON
 ])
 
 # Prerequisites of lib/inet_pton.c.
 AC_DEFUN([gl_PREREQ_INET_PTON], [
-  AC_CHECK_HEADERS_ONCE([netdb.h])
-  AC_CHECK_DECLS([inet_pton],,,
-    [#include <arpa/inet.h>
-     #if HAVE_NETDB_H
-     # include <netdb.h>
-     #endif
-    ])
-  if test $ac_cv_have_decl_inet_pton = no; then
-    HAVE_DECL_INET_PTON=0
-  fi
   AC_REQUIRE([gl_SOCKET_FAMILIES])
-  AC_REQUIRE([AC_C_RESTRICT])
 ])
diff --git a/lib/gl/m4/inttypes-pri.m4 b/gl/m4/inttypes-pri.m4
similarity index 100%
copy from lib/gl/m4/inttypes-pri.m4
copy to gl/m4/inttypes-pri.m4
diff --git a/lib/gl/m4/inttypes.m4 b/gl/m4/inttypes.m4
similarity index 100%
copy from lib/gl/m4/inttypes.m4
copy to gl/m4/inttypes.m4
diff --git a/gl/m4/ioctl.m4 b/gl/m4/ioctl.m4
index 8cb36d8..a1db8fc 100644
--- a/gl/m4/ioctl.m4
+++ b/gl/m4/ioctl.m4
@@ -1,4 +1,4 @@
-# ioctl.m4 serial 1
+# ioctl.m4 serial 4
 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,
@@ -8,12 +8,12 @@ AC_DEFUN([gl_FUNC_IOCTL],
 [
   AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  HAVE_IOCTL=1
   if test "$ac_cv_header_winsock2_h" = yes; 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 ioctl() function. So enable the support for sockets.
-    AC_LIBOBJ([ioctl])
-    gl_REPLACE_SYS_IOCTL_H
+    HAVE_IOCTL=0
   else
     AC_CHECK_FUNCS([ioctl])
     dnl On glibc systems, the second parameter is 'unsigned long int request',
@@ -24,15 +24,18 @@ AC_DEFUN([gl_FUNC_IOCTL],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
             [[#include <sys/ioctl.h>]],
-            [[extern int ioctl (int, int, ...);]])
+            [[extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+            ]])
          ],
          [gl_cv_func_ioctl_posix_signature=yes],
          [gl_cv_func_ioctl_posix_signature=no])
       ])
     if test $gl_cv_func_ioctl_posix_signature != yes; then
       REPLACE_IOCTL=1
-      AC_LIBOBJ([ioctl])
-      gl_REPLACE_SYS_IOCTL_H
     fi
   fi
 ])
diff --git a/gl/m4/largefile.m4 b/gl/m4/largefile.m4
new file mode 100644
index 0000000..d83fea1
--- /dev/null
+++ b/gl/m4/largefile.m4
@@ -0,0 +1,104 @@
+# Enable large files on systems where this is not the default.
+
+# Copyright 1992-1996, 1998-2011 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# The following implementation works around a problem in autoconf <= 2.68;
+# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5.
+m4_version_prereq([2.69], [] ,[
+
+# _AC_SYS_LARGEFILE_TEST_INCLUDES
+# -------------------------------
+m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
address@hidden:@include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
address@hidden:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
+                       && LARGE_OFF_T % 2147483647 == 1)
+                      ? 1 : -1]];[]dnl
+])
+
+
+# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
+#                              CACHE-VAR,
+#                              DESCRIPTION,
+#                              PROLOGUE, [FUNCTION-BODY])
+# --------------------------------------------------------
+m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
+[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
+[while :; do
+  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
+    [AC_LANG_PROGRAM([$5], [$6])],
+    [$3=no; break])
+  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
+    [AC_LANG_PROGRAM(address@hidden:@define $1 $2
+$5], [$6])],
+    [$3=$2; break])
+  $3=unknown
+  break
+done])
+case $$3 in #(
+  no | unknown) ;;
+  *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
+esac
+rm -rf conftest*[]dnl
+])# _AC_SYS_LARGEFILE_MACRO_VALUE
+
+
+# AC_SYS_LARGEFILE
+# ----------------
+# By default, many hosts won't let programs access large files;
+# one must use special compiler options to get large-file access to work.
+# For more details about this brain damage please see:
+# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html
+AC_DEFUN([AC_SYS_LARGEFILE],
+[AC_ARG_ENABLE(largefile,
+               [  --disable-largefile     omit support for large files])
+if test "$enable_largefile" != no; then
+
+  AC_CACHE_CHECK([for special C compiler options needed for large files],
+    ac_cv_sys_largefile_CC,
+    [ac_cv_sys_largefile_CC=no
+     if test "$GCC" != yes; then
+       ac_save_CC=$CC
+       while :; do
+         # IRIX 6.2 and later do not support large files by default,
+         # so use the C compiler's -n32 option if that helps.
+         AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
+         AC_COMPILE_IFELSE([], [break])
+         CC="$CC -n32"
+         AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
+         break
+       done
+       CC=$ac_save_CC
+       rm -f conftest.$ac_ext
+    fi])
+  if test "$ac_cv_sys_largefile_CC" != no; then
+    CC=$CC$ac_cv_sys_largefile_CC
+  fi
+
+  _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
+    ac_cv_sys_file_offset_bits,
+    [Number of bits in a file offset, on hosts where this is settable.],
+    [_AC_SYS_LARGEFILE_TEST_INCLUDES])
+  if test $ac_cv_sys_file_offset_bits = unknown; then
+    _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
+      ac_cv_sys_large_files,
+      [Define for large files, on AIX-style hosts.],
+      [_AC_SYS_LARGEFILE_TEST_INCLUDES])
+  fi
+
+  AH_VERBATIM([_DARWIN_USE_64_BIT_INODE],
+[/* Enable large inode numbers on Mac OS X.  */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif])
+fi
+])# AC_SYS_LARGEFILE
+
+])# m4_version_prereq 2.69
diff --git a/lib/gl/m4/lock.m4 b/gl/m4/lock.m4
similarity index 100%
copy from lib/gl/m4/lock.m4
copy to gl/m4/lock.m4
diff --git a/gl/m4/lseek.m4 b/gl/m4/lseek.m4
index f6452f6..73c4069 100644
--- a/gl/m4/lseek.m4
+++ b/gl/m4/lseek.m4
@@ -1,4 +1,4 @@
-# lseek.m4 serial 6
+# lseek.m4 serial 8
 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,
@@ -8,12 +8,18 @@ AC_DEFUN([gl_FUNC_LSEEK],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([AC_PROG_CC])
+  AC_CHECK_HEADERS_ONCE([unistd.h])
   AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
     [if test $cross_compiling = no; then
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/types.h> /* for off_t */
 #include <stdio.h> /* for SEEK_CUR */
-#include <unistd.h>]], [[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else /* on Windows with MSVC */
+# include <io.h>
+#endif
+]], [[
   /* Exit with success only if stdin is seekable.  */
   return lseek (0, (off_t)0, SEEK_CUR) < 0;
 ]])],
@@ -35,15 +41,8 @@ AC_DEFUN([gl_FUNC_LSEEK],
          [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
      fi])
   if test $gl_cv_func_lseek_pipe = no; then
-    gl_REPLACE_LSEEK
+    REPLACE_LSEEK=1
+    AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
+      [Define to 1 if lseek does not detect pipes.])
   fi
 ])
-
-AC_DEFUN([gl_REPLACE_LSEEK],
-[
-  AC_LIBOBJ([lseek])
-  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  REPLACE_LSEEK=1
-  AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
-            [Define to 1 if lseek does not detect pipes.])
-])
diff --git a/gl/m4/lstat.m4 b/gl/m4/lstat.m4
new file mode 100644
index 0000000..fe161d4
--- /dev/null
+++ b/gl/m4/lstat.m4
@@ -0,0 +1,70 @@
+# serial 23
+
+# Copyright (C) 1997-2001, 2003-2011 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+dnl From Jim Meyering.
+
+AC_DEFUN([gl_FUNC_LSTAT],
+[
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  dnl If lstat does not exist, the replacement <sys/stat.h> does
+  dnl "#define lstat stat", and lstat.c is a no-op.
+  AC_CHECK_FUNCS_ONCE([lstat])
+  if test $ac_cv_func_lstat = yes; then
+    AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
+    if test $gl_cv_func_lstat_dereferences_slashed_symlink = no; then
+      REPLACE_LSTAT=1
+    fi
+  else
+    HAVE_LSTAT=0
+  fi
+])
+
+# Prerequisites of lib/lstat.c.
+AC_DEFUN([gl_PREREQ_LSTAT],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  :
+])
+
+AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
+[
+  dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
+  dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
+  AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
+    [gl_cv_func_lstat_dereferences_slashed_symlink],
+    [rm -f conftest.sym conftest.file
+     echo >conftest.file
+     if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
+       AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT],
+            [[struct stat sbuf;
+              /* Linux will dereference the symlink and fail, as required by
+                 POSIX.  That is better in the sense that it means we will not
+                 have to compile and use the lstat wrapper.  */
+              return lstat ("conftest.sym/", &sbuf) == 0;
+            ]])],
+         [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
+         [gl_cv_func_lstat_dereferences_slashed_symlink=no],
+         [# When cross-compiling, be pessimistic so we will end up using the
+          # replacement version of lstat that checks for trailing slashes and
+          # calls lstat a second time when necessary.
+          gl_cv_func_lstat_dereferences_slashed_symlink=no
+         ])
+     else
+       # If the 'ln -s' command failed, then we probably don't even
+       # have an lstat function.
+       gl_cv_func_lstat_dereferences_slashed_symlink=no
+     fi
+     rm -f conftest.sym conftest.file
+    ])
+  test $gl_cv_func_lstat_dereferences_slashed_symlink = yes &&
+    AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
+      [Define to 1 if `lstat' dereferences a symlink specified
+       with a trailing slash.])
+])
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
index 8094444..87018ec 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,4 +1,4 @@
-# malloc.m4 serial 12
+# malloc.m4 serial 13
 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,
@@ -17,7 +17,7 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU],
                [Define to 1 if your system has a GNU libc compatible 'malloc'
                 function, and to 0 otherwise.])],
     [AC_DEFINE([HAVE_MALLOC_GNU], [0])
-     gl_REPLACE_MALLOC
+     REPLACE_MALLOC=1
     ])
 ])
 
@@ -33,7 +33,7 @@ AC_DEFUN([gl_FUNC_MALLOC_POSIX],
     AC_DEFINE([HAVE_MALLOC_POSIX], [1],
       [Define if the 'malloc' function is POSIX compliant.])
   else
-    gl_REPLACE_MALLOC
+    REPLACE_MALLOC=1
   fi
 ])
 
@@ -58,9 +58,3 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX],
         [gl_cv_func_malloc_posix=no])
     ])
 ])
-
-AC_DEFUN([gl_REPLACE_MALLOC],
-[
-  AC_LIBOBJ([malloc])
-  REPLACE_MALLOC=1
-])
diff --git a/gl/m4/manywarnings.m4 b/gl/m4/manywarnings.m4
index e928821..67db064 100644
--- a/gl/m4/manywarnings.m4
+++ b/gl/m4/manywarnings.m4
@@ -35,74 +35,124 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT],
 # using gl_WARN_ADD if you want to make sure your gcc understands it.
 AC_DEFUN([gl_MANYWARN_ALL_GCC],
 [
- gl_manywarn_set=
- for gl_manywarn_item in \
-   -Wall \
-   -W \
-   -Wformat-y2k \
-   -Wformat-nonliteral \
-   -Wformat-security \
-   -Winit-self \
-   -Wmissing-include-dirs \
-   -Wswitch-default \
-   -Wswitch-enum \
-   -Wunused \
-   -Wunknown-pragmas \
-   -Wstrict-aliasing \
-   -Wstrict-overflow \
-   -Wsystem-headers \
-   -Wfloat-equal \
-   -Wtraditional \
-   -Wtraditional-conversion \
-   -Wdeclaration-after-statement \
-   -Wundef \
-   -Wshadow \
-   -Wunsafe-loop-optimizations \
-   -Wpointer-arith \
-   -Wbad-function-cast \
-   -Wc++-compat \
-   -Wcast-qual \
-   -Wcast-align \
-   -Wwrite-strings \
-   -Wconversion \
-   -Wsign-conversion \
-   -Wlogical-op \
-   -Waggregate-return \
-   -Wstrict-prototypes \
-   -Wold-style-definition \
-   -Wmissing-prototypes \
-   -Wmissing-declarations \
-   -Wmissing-noreturn \
-   -Wmissing-format-attribute \
-   -Wpacked \
-   -Wpadded \
-   -Wredundant-decls \
-   -Wnested-externs \
-   -Wunreachable-code \
-   -Winline \
-   -Winvalid-pch \
-   -Wlong-long \
-   -Wvla \
-   -Wvolatile-register-var \
-   -Wdisabled-optimization \
-   -Wstack-protector \
-   -Woverlength-strings \
-   -Wbuiltin-macro-redefined \
-   -Wmudflap \
-   -Wpacked-bitfield-compat \
-   -Wsync-nand \
-  ; do
+  dnl First, check if -Wno-missing-field-initializers is needed.
+  dnl -Wmissing-field-initializers is implied by -W, but that issues
+  dnl warnings with GCC version before 4.7, for the common idiom
+  dnl of initializing types on the stack to zero, using { 0, }
+  AC_REQUIRE([AC_PROG_CC])
+  if test -n "$GCC"; then
+
+    dnl First, check -W -Werror -Wno-missing-field-initializers is supported
+    dnl with the current $CC $CFLAGS $CPPFLAGS.
+    AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
+    AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
+      gl_save_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[]], [[]])],
+        [gl_cv_cc_nomfi_supported=yes],
+        [gl_cv_cc_nomfi_supported=no])
+      CFLAGS="$gl_save_CFLAGS"])
+    AC_MSG_RESULT([$gl_cv_cc_nomfi_supported])
+
+    if test "$gl_cv_cc_nomfi_supported" = yes; then
+      dnl Now check whether -Wno-missing-field-initializers is needed
+      dnl for the { 0, } construct.
+      AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed])
+      AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [
+        gl_save_CFLAGS="$CFLAGS"
+        CFLAGS="$CFLAGS -W -Werror"
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM(
+             [[void f (void)
+               {
+                 typedef struct { int a; int b; } s_t;
+                 s_t s1 = { 0, };
+               }
+             ]],
+             [[]])],
+          [gl_cv_cc_nomfi_needed=no],
+          [gl_cv_cc_nomfi_needed=yes])
+        CFLAGS="$gl_save_CFLAGS"
+      ])
+      AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
+    fi
+  fi
+
+  gl_manywarn_set=
+  for gl_manywarn_item in \
+    -Wall \
+    -W \
+    -Wformat-y2k \
+    -Wformat-nonliteral \
+    -Wformat-security \
+    -Winit-self \
+    -Wmissing-include-dirs \
+    -Wswitch-default \
+    -Wswitch-enum \
+    -Wunused \
+    -Wunknown-pragmas \
+    -Wstrict-aliasing \
+    -Wstrict-overflow \
+    -Wsystem-headers \
+    -Wfloat-equal \
+    -Wtraditional \
+    -Wtraditional-conversion \
+    -Wdeclaration-after-statement \
+    -Wundef \
+    -Wshadow \
+    -Wunsafe-loop-optimizations \
+    -Wpointer-arith \
+    -Wbad-function-cast \
+    -Wc++-compat \
+    -Wcast-qual \
+    -Wcast-align \
+    -Wwrite-strings \
+    -Wconversion \
+    -Wsign-conversion \
+    -Wlogical-op \
+    -Waggregate-return \
+    -Wstrict-prototypes \
+    -Wold-style-definition \
+    -Wmissing-prototypes \
+    -Wmissing-declarations \
+    -Wmissing-noreturn \
+    -Wmissing-format-attribute \
+    -Wpacked \
+    -Wpadded \
+    -Wredundant-decls \
+    -Wnested-externs \
+    -Wunreachable-code \
+    -Winline \
+    -Winvalid-pch \
+    -Wlong-long \
+    -Wvla \
+    -Wvolatile-register-var \
+    -Wdisabled-optimization \
+    -Wstack-protector \
+    -Woverlength-strings \
+    -Wbuiltin-macro-redefined \
+    -Wmudflap \
+    -Wpacked-bitfield-compat \
+    -Wsync-nand \
+    ; do
     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
   done
- # The following are not documented in the manual but are included in
- # output from gcc --help=warnings.
- for gl_manywarn_item in \
-   -Wattributes \
-   -Wcoverage-mismatch \
-   -Wmultichar \
-   -Wunused-macros \
-  ; do
+  # The following are not documented in the manual but are included in
+  # output from gcc --help=warnings.
+  for gl_manywarn_item in \
+    -Wattributes \
+    -Wcoverage-mismatch \
+    -Wmultichar \
+    -Wunused-macros \
+    ; do
     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
   done
+
+  # Disable the missing-field-initializers warning if needed
+  if test "$gl_cv_cc_nomfi_needed" = yes; then
+    gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
+  fi
+
   $1=$gl_manywarn_set
 ])
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
index 3c2b313..f6dc3e7 100644
--- a/gl/m4/memchr.m4
+++ b/gl/m4/memchr.m4
@@ -1,4 +1,4 @@
-# memchr.m4 serial 10
+# memchr.m4 serial 12
 dnl Copyright (C) 2002-2004, 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,
@@ -11,10 +11,16 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
   AC_CHECK_HEADERS_ONCE([sys/mman.h])
   AC_CHECK_FUNCS_ONCE([mprotect])
 
-  dnl These days, we assume memchr is present.  But just in case...
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_CHECK_FUNCS_ONCE([memchr])
-  if test $ac_cv_func_memchr = yes; then
+  m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [
+    dnl These days, we assume memchr is present.  But if support for old
+    dnl platforms is desired:
+    AC_CHECK_FUNCS_ONCE([memchr])
+    if test $ac_cv_func_memchr = no; then
+      HAVE_MEMCHR=0
+    fi
+  ])
+  if test $HAVE_MEMCHR = 1; then
     # Detect platform-specific bugs in some versions of glibc:
     # memchr should not dereference anything with length 0
     #   http://bugzilla.redhat.com/499689
@@ -73,12 +79,6 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
     if test "$gl_cv_func_memchr_works" != yes; then
       REPLACE_MEMCHR=1
     fi
-  else
-    HAVE_MEMCHR=0
-  fi
-  if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
-    AC_LIBOBJ([memchr])
-    gl_PREREQ_MEMCHR
   fi
 ])
 
diff --git a/gl/m4/mmap-anon.m4 b/gl/m4/mmap-anon.m4
index 7ba7fd2..952536f 100644
--- a/gl/m4/mmap-anon.m4
+++ b/gl/m4/mmap-anon.m4
@@ -27,18 +27,18 @@ AC_DEFUN([gl_FUNC_MMAP_ANON],
   gl_have_mmap_anonymous=no
   if test $gl_have_mmap = yes; then
     AC_MSG_CHECKING([for MAP_ANONYMOUS])
-    AC_EGREP_CPP([I cant identify this map.], [
+    AC_EGREP_CPP([I cant identify this map], [
 #include <sys/mman.h>
 #ifdef MAP_ANONYMOUS
-    I cant identify this map.
+    I cant identify this map
 #endif
 ],
       [gl_have_mmap_anonymous=yes])
     if test $gl_have_mmap_anonymous != yes; then
-      AC_EGREP_CPP([I cant identify this map.], [
+      AC_EGREP_CPP([I cant identify this map], [
 #include <sys/mman.h>
 #ifdef MAP_ANON
-    I cant identify this map.
+    I cant identify this map
 #endif
 ],
         [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
diff --git a/gl/m4/mode_t.m4 b/gl/m4/mode_t.m4
new file mode 100644
index 0000000..f9cf704
--- /dev/null
+++ b/gl/m4/mode_t.m4
@@ -0,0 +1,26 @@
+# mode_t.m4 serial 2
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+# For using mode_t, it's sufficient to use AC_TYPE_MODE_T and
+# include <sys/types.h>.
+
+# Define PROMOTED_MODE_T to the type that is the result of "default argument
+# promotion" (ISO C 6.5.2.2.(6)) of the type mode_t.
+AC_DEFUN([gl_PROMOTED_TYPE_MODE_T],
+[
+  AC_REQUIRE([AC_TYPE_MODE_T])
+  AC_CACHE_CHECK([for promoted mode_t type], [gl_cv_promoted_mode_t], [
+    dnl Assume mode_t promotes to 'int' if and only if it is smaller than 
'int',
+    dnl and to itself otherwise. This assumption is not guaranteed by the ISO C
+    dnl standard, but we don't know of any real-world counterexamples.
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]],
+      [[typedef int array[2 * (sizeof (mode_t) < sizeof (int)) - 1];]])],
+      [gl_cv_promoted_mode_t='int'],
+      [gl_cv_promoted_mode_t='mode_t'])
+  ])
+  AC_DEFINE_UNQUOTED([PROMOTED_MODE_T], [$gl_cv_promoted_mode_t],
+    [Define to the type that is the result of default argument promotions of 
type mode_t.])
+])
diff --git a/gl/m4/msvc-inval.m4 b/gl/m4/msvc-inval.m4
new file mode 100644
index 0000000..fb797f0
--- /dev/null
+++ b/gl/m4/msvc-inval.m4
@@ -0,0 +1,19 @@
+# msvc-inval.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_MSVC_INVAL],
+[
+  AC_CHECK_FUNCS_ONCE([_set_invalid_parameter_handler])
+  if test $ac_cv_func__set_invalid_parameter_handler = yes; then
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
+    AC_DEFINE([HAVE_MSVC_INVALID_PARAMETER_HANDLER], [1],
+      [Define to 1 on MSVC platforms that have the "invalid parameter handler"
+       concept.])
+  else
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
+  fi
+  AC_SUBST([HAVE_MSVC_INVALID_PARAMETER_HANDLER])
+])
diff --git a/gl/m4/msvc-nothrow.m4 b/gl/m4/msvc-nothrow.m4
new file mode 100644
index 0000000..b2f6bb4
--- /dev/null
+++ b/gl/m4/msvc-nothrow.m4
@@ -0,0 +1,10 @@
+# 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_MSVC_NOTHROW],
+[
+  AC_REQUIRE([gl_MSVC_INVAL])
+])
diff --git a/gl/m4/netdb_h.m4 b/gl/m4/netdb_h.m4
index 9a01cd6..a54d670 100644
--- a/gl/m4/netdb_h.m4
+++ b/gl/m4/netdb_h.m4
@@ -1,4 +1,4 @@
-# netdb_h.m4 serial 10
+# netdb_h.m4 serial 11
 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,
@@ -26,6 +26,8 @@ AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
   AC_REQUIRE([gl_NETDB_H_DEFAULTS])
   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
 ])
 
 AC_DEFUN([gl_NETDB_H_DEFAULTS],
@@ -37,4 +39,5 @@ AC_DEFUN([gl_NETDB_H_DEFAULTS],
   HAVE_DECL_GAI_STRERROR=1; AC_SUBST([HAVE_DECL_GAI_STRERROR])
   HAVE_DECL_GETADDRINFO=1;  AC_SUBST([HAVE_DECL_GETADDRINFO])
   HAVE_DECL_GETNAMEINFO=1;  AC_SUBST([HAVE_DECL_GETNAMEINFO])
+  REPLACE_GAI_STRERROR=0;   AC_SUBST([REPLACE_GAI_STRERROR])
 ])
diff --git a/gl/m4/netinet_in_h.m4 b/gl/m4/netinet_in_h.m4
index e2d022d..87235b7 100644
--- a/gl/m4/netinet_in_h.m4
+++ b/gl/m4/netinet_in_h.m4
@@ -1,4 +1,4 @@
-# netinet_in_h.m4 serial 4
+# netinet_in_h.m4 serial 5
 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,
@@ -27,4 +27,5 @@ AC_DEFUN([gl_HEADER_NETINET_IN],
     AC_SUBST([HAVE_NETINET_IN_H])
   fi
   AC_SUBST([NETINET_IN_H])
+  AM_CONDITIONAL([GL_GENERATE_NETINET_IN_H], [test -n "$NETINET_IN_H"])
 ])
diff --git a/gl/m4/open.m4 b/gl/m4/open.m4
new file mode 100644
index 0000000..d819184
--- /dev/null
+++ b/gl/m4/open.m4
@@ -0,0 +1,92 @@
+# open.m4 serial 13
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_OPEN],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw* | pw*)
+      REPLACE_OPEN=1
+      ;;
+    *)
+      dnl open("foo/") should not create a file when the file name has a
+      dnl trailing slash.  FreeBSD only has the problem on symlinks.
+      AC_CHECK_FUNCS_ONCE([lstat])
+      AC_CACHE_CHECK([whether open recognizes a trailing slash],
+        [gl_cv_func_open_slash],
+        [# Assume that if we have lstat, we can also check symlinks.
+          if test $ac_cv_func_lstat = yes; then
+            touch conftest.tmp
+            ln -s conftest.tmp conftest.lnk
+          fi
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE([[
+#include <fcntl.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+int main ()
+{
+  int result = 0;
+#if HAVE_LSTAT
+  if (open ("conftest.lnk/", O_RDONLY) != -1)
+    result |= 1;
+#endif
+  if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
+    result |= 2;
+  return result;
+}]])],
+            [gl_cv_func_open_slash=yes],
+            [gl_cv_func_open_slash=no],
+            [
+changequote(,)dnl
+             case "$host_os" in
+               freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
+                 gl_cv_func_open_slash="guessing no" ;;
+               *)
+                 gl_cv_func_open_slash="guessing yes" ;;
+             esac
+changequote([,])dnl
+            ])
+          rm -f conftest.sl conftest.tmp conftest.lnk
+        ])
+      case "$gl_cv_func_open_slash" in
+        *no)
+          AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
+            [Define to 1 if open() fails to recognize a trailing slash.])
+          REPLACE_OPEN=1
+          ;;
+      esac
+      ;;
+  esac
+  dnl Replace open() for supporting the gnulib-defined fchdir() function,
+  dnl to keep fchdir's bookkeeping up-to-date.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    if test $REPLACE_OPEN = 0; then
+      gl_TEST_FCHDIR
+      if test $HAVE_FCHDIR = 0; then
+        REPLACE_OPEN=1
+      fi
+    fi
+  ])
+  dnl Replace open() for supporting the gnulib-defined O_NONBLOCK flag.
+  m4_ifdef([gl_NONBLOCKING_IO], [
+    if test $REPLACE_OPEN = 0; then
+      gl_NONBLOCKING_IO
+      if test $gl_cv_have_open_O_NONBLOCK != yes; then
+        REPLACE_OPEN=1
+      fi
+    fi
+  ])
+])
+
+# Prerequisites of lib/open.c.
+AC_DEFUN([gl_PREREQ_OPEN],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
+  :
+])
diff --git a/gl/m4/pathmax.m4 b/gl/m4/pathmax.m4
new file mode 100644
index 0000000..4913fa0
--- /dev/null
+++ b/gl/m4/pathmax.m4
@@ -0,0 +1,42 @@
+# 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
+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_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/perror.m4 b/gl/m4/perror.m4
index 2a03e08..86e2020 100644
--- a/gl/m4/perror.m4
+++ b/gl/m4/perror.m4
@@ -1,4 +1,4 @@
-# perror.m4 serial 1
+# perror.m4 serial 3
 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,
@@ -8,10 +8,48 @@ AC_DEFUN([gl_FUNC_PERROR],
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_ERRNO_H])
-  if test -n "$ERRNO_H"; then
+  AC_REQUIRE([gl_FUNC_STRERROR_R])
+  AC_REQUIRE([gl_FUNC_STRERROR_0])
+  dnl We intentionally do not check for the broader REPLACE_STRERROR_R,
+  dnl since on glibc systems, strerror_r is replaced only for signature
+  dnl issues, and perror is just fine.  Rather, we only want to
+  dnl replace perror if strerror_r was replaced for a content fix.
+  if test "$ERRNO_H:$REPLACE_STRERROR_0" != :0; then
     dnl The system's perror() cannot know about the new errno values we add
-    dnl to <errno.h>. Replace it.
+    dnl to <errno.h>, or any fix for strerror(0). Replace it.
     REPLACE_PERROR=1
-    AC_LIBOBJ([perror])
   fi
+  case ${gl_cv_func_strerror_r_works-unset} in
+    unset|*yes)
+      AC_CACHE_CHECK([whether perror matches strerror],
+        [gl_cv_func_perror_works],
+        [AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <errno.h>
+                #include <stdio.h>
+              ]],
+              [[char *str = strerror (-1);
+                if (!getenv("CONFTEST_OUTPUT")) return 0;
+                if (!str) str = "";
+                puts (str);
+                errno = -1;
+                perror ("");
+              ]])],
+           [CONFTEST_OUTPUT=1 ./conftest$EXEEXT >conftest.txt1 2>conftest.txt2
+            if cmp conftest.txt1 conftest.txt2 >/dev/null; then
+              gl_cv_func_perror_works=yes
+            else
+              gl_cv_func_perror_works=no
+            fi
+            rm -rf conftest.txt1 conftest.txt2],
+           [gl_cv_func_perror_works=no],
+           [dnl Guess no when cross-compiling.
+            gl_cv_func_perror_works="guessing no"])])
+       if test "$gl_cv_func_perror_works" != yes; then
+         REPLACE_PERROR=1
+       fi ;;
+    *) dnl The system's perror() probably inherits the bugs in the
+       dnl system's strerror_r(). Replace it.
+      REPLACE_PERROR=1 ;;
+  esac
 ])
diff --git a/gl/m4/pipe.m4 b/gl/m4/pipe.m4
index ae00049..9013174 100644
--- a/gl/m4/pipe.m4
+++ b/gl/m4/pipe.m4
@@ -1,4 +1,4 @@
-# pipe.m4 serial 1
+# pipe.m4 serial 2
 dnl Copyright (C) 2010-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,
@@ -11,6 +11,5 @@ AC_DEFUN([gl_FUNC_PIPE],
   AC_CHECK_FUNCS_ONCE([pipe])
   if test $ac_cv_func_pipe != yes; then
     HAVE_PIPE=0
-    AC_LIBOBJ([pipe])
   fi
 ])
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4
index 9c2ed1e..d046c11 100644
--- a/gl/m4/printf.m4
+++ b/gl/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 42
+# printf.m4 serial 45
 dnl Copyright (C) 2003, 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,
@@ -178,28 +178,28 @@ static double zero = 0.0;
 int main ()
 {
   int result = 0;
-  if (sprintf (buf, "%f", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%f", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%f", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%f", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%f", zero / zero) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 2;
-  if (sprintf (buf, "%e", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%e", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 4;
-  if (sprintf (buf, "%e", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%e", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 4;
   if (sprintf (buf, "%e", zero / zero) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 8;
-  if (sprintf (buf, "%g", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%g", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 16;
-  if (sprintf (buf, "%g", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%g", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 16;
   if (sprintf (buf, "%g", zero / zero) < 0
@@ -294,28 +294,28 @@ int main ()
 {
   int result = 0;
   nocrash_init();
-  if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 1;
-  if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Le", zeroL / zeroL) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 1;
-  if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
@@ -478,6 +478,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
   int result = 0;
@@ -502,7 +503,7 @@ int main ()
     result |= 4;
   /* This catches a FreeBSD 6.1 bug.  See
      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
-  if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
+  if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
       || buf[0] == '0')
     result |= 8;
   /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug.  */
@@ -562,13 +563,14 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
   int result = 0;
   if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
       || strcmp (buf, "1234567.000000 33") != 0)
     result |= 1;
-  if (sprintf (buf, "%F", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%F", 1.0 / zero) < 0
       || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
     result |= 2;
   /* This catches a Cygwin 1.5.x bug.  */
@@ -615,12 +617,27 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#ifdef _MSC_VER
+/* See page about "Parameter Validation" on msdn.microsoft.com.  */
+static void cdecl
+invalid_parameter_handler (const wchar_t *expression,
+                           const wchar_t *function,
+                           const wchar_t *file, unsigned int line,
+                           uintptr_t dummy)
+{
+  exit (1);
+}
+#endif
 static char fmtstring[10];
 static char buf[100];
 int main ()
 {
   int count = -1;
+#ifdef _MSC_VER
+  _set_invalid_parameter_handler (invalid_parameter_handler);
+#endif
   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
      support %n in format strings in read-only memory but not in writable
      memory.  */
@@ -636,7 +653,8 @@ int main ()
         [
 changequote(,)dnl
          case "$host_os" in
-           *)     gl_cv_func_printf_directive_n="guessing yes";;
+           mingw*) gl_cv_func_printf_directive_n="guessing no";;
+           *)      gl_cv_func_printf_directive_n="guessing yes";;
          esac
 changequote([,])dnl
         ])
@@ -862,9 +880,10 @@ AC_DEFUN([gl_PRINTF_FLAG_ZERO],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
-  if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
+  if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
       || (strcmp (buf, "       inf") != 0
           && strcmp (buf, "  infinity") != 0))
     return 1;
@@ -892,7 +911,8 @@ dnl On mingw, precisions larger than 512 are treated like 
512, in integer,
 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
 dnl precisions larger than 510 in floating-point output yield wrong results.
-dnl On BeOS, precisions larger than 1044 crash the program.
+dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
+dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
 dnl Result is gl_cv_func_printf_precision.
 
 AC_DEFUN([gl_PRINTF_PRECISION],
@@ -921,6 +941,9 @@ int main ()
   if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
       || buf[0] != '1')
     result |= 4;
+  if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
+      || buf[0] != '1')
+    result |= 4;
   return result;
 }]])],
         [gl_cv_func_printf_precision=yes],
@@ -1072,6 +1095,7 @@ AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
     [gl_cv_func_snprintf_truncation_c99],
     [
@@ -1079,11 +1103,25 @@ AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char buf[100];
 int main ()
 {
   strcpy (buf, "ABCDEF");
-  snprintf (buf, 3, "%d %d", 4567, 89);
+  my_snprintf (buf, 3, "%d %d", 4567, 89);
   if (memcmp (buf, "45\0DEF", 6) != 0)
     return 1;
   return 0;
@@ -1153,6 +1191,7 @@ AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
     [gl_cv_func_snprintf_retval_c99],
     [
@@ -1160,15 +1199,29 @@ AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char buf[100];
 int main ()
 {
   strcpy (buf, "ABCDEF");
-  if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
     return 1;
-  if (snprintf (buf, 0, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
     return 2;
-  if (snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
     return 3;
   return 0;
 }]])],
@@ -1217,6 +1270,7 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
     [gl_cv_func_snprintf_directive_n],
     [
@@ -1224,6 +1278,20 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char fmtstring[10];
 static char buf[100];
 int main ()
@@ -1233,7 +1301,7 @@ int main ()
      support %n in format strings in read-only memory but not in writable
      memory.  */
   strcpy (fmtstring, "%d %n");
-  snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
+  my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
   if (count != 6)
     return 1;
   return 0;
@@ -1285,16 +1353,31 @@ dnl Result is gl_cv_func_snprintf_size1.
 AC_DEFUN([gl_SNPRINTF_SIZE1],
 [
   AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf respects a size of 1],
     [gl_cv_func_snprintf_size1],
     [
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
 #include <stdio.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 int main()
 {
   static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
-  snprintf (buf, 1, "%d", 12345);
+  my_snprintf (buf, 1, "%d", 12345);
   return buf[1] != 'E';
 }]])],
         [gl_cv_func_snprintf_size1=yes],
@@ -1465,7 +1548,8 @@ dnl   Solaris 11 2010-11             .  .  #  #  #  .  .  
#  .  .  .  #  .  .  .
 dnl   Solaris 10                     .  .  #  #  #  .  .  #  .  .  .  #  #  .  
.  .  .  .  .  .
 dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  #  .  .  .  #  #  .  
.  .  #  .  .  .
 dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  
#  #  #  #  #  #
-dnl   AIX 5.2, 7.1                   .  .  #  #  #  .  .  .  .  .  .  #  .  .  
.  .  .  .  .  .
+dnl   AIX 7.1                        .  .  #  #  #  .  .  .  .  .  .  #  #  .  
.  .  .  .  .  .
+dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  
.  .  .  .  .  .
 dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  
.  .  #  .  .  .
 dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  
.  .  #  #  .  .
 dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  
.  .  #  #  .  #
@@ -1478,4 +1562,7 @@ dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  
?  .  ?  ?  ?  ?  ?  .
 dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  
.  .  .  .  .  .
 dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  
.  .  ?  .  .  .
 dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  
.  .  ?  .  .  .
-dnl   mingw                          #  #  #  #  #  #  .  .  #  #  .  #  #  ?  
.  #  #  #  .  .
+dnl   old mingw / msvcrt             #  #  #  #  #  #  .  .  #  #  .  #  #  ?  
.  #  #  #  .  .
+dnl   MSVC 9                         #  #  #  #  #  #  #  .  #  #  .  #  #  ?  
#  #  #  #  .  .
+dnl   mingw 2009-2011                .  #  .  #  .  .  .  .  #  #  .  .  .  ?  
.  .  .  .  .  .
+dnl   mingw-w64 2011                 #  #  #  #  #  #  .  .  #  #  .  #  #  ?  
.  #  #  #  .  .
diff --git a/gl/m4/read-file.m4 b/gl/m4/read-file.m4
index 60d0360..93e0ac3 100644
--- a/gl/m4/read-file.m4
+++ b/gl/m4/read-file.m4
@@ -1,14 +1,8 @@
-# read-file.m4 serial 2
+# read-file.m4 serial 3
 dnl Copyright (C) 2002-2006, 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,
 dnl with or without modifications, as long as this notice is preserved.
 
-AC_DEFUN([gl_FUNC_READ_FILE],
-[
-  AC_LIBOBJ([read-file])
-  gl_PREREQ_READ_FILE
-])
-
 # Prerequisites of lib/read-file.c.
 AC_DEFUN([gl_PREREQ_READ_FILE], [:])
diff --git a/gl/m4/readline.m4 b/gl/m4/readline.m4
index 90ce357..a5ab067 100644
--- a/gl/m4/readline.m4
+++ b/gl/m4/readline.m4
@@ -1,4 +1,4 @@
-# readline.m4 serial 8
+# readline.m4 serial 9
 dnl Copyright (C) 2005-2006, 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,
@@ -73,11 +73,6 @@ AC_DEFUN([gl_FUNC_READLINE],
   AC_SUBST([LTLIBREADLINE])
 
   AC_CHECK_HEADERS([readline/readline.h])
-
-  if test "$gl_cv_lib_readline" = no; then
-    AC_LIBOBJ([readline])
-    gl_PREREQ_READLINE
-  fi
 ])
 
 # Prerequisites of lib/readline.c.
diff --git a/gl/m4/realloc.m4 b/gl/m4/realloc.m4
index a403d9f..5cc1340 100644
--- a/gl/m4/realloc.m4
+++ b/gl/m4/realloc.m4
@@ -1,4 +1,4 @@
-# realloc.m4 serial 11
+# realloc.m4 serial 12
 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,
@@ -17,7 +17,7 @@ AC_DEFUN([gl_FUNC_REALLOC_GNU],
                [Define to 1 if your system has a GNU libc compatible 'realloc'
                 function, and to 0 otherwise.])],
     [AC_DEFINE([HAVE_REALLOC_GNU], [0])
-     gl_REPLACE_REALLOC
+     REPLACE_REALLOC=1
     ])
 ])# gl_FUNC_REALLOC_GNU
 
@@ -33,12 +33,6 @@ AC_DEFUN([gl_FUNC_REALLOC_POSIX],
     AC_DEFINE([HAVE_REALLOC_POSIX], [1],
       [Define if the 'realloc' function is POSIX compliant.])
   else
-    gl_REPLACE_REALLOC
+    REPLACE_REALLOC=1
   fi
 ])
-
-AC_DEFUN([gl_REPLACE_REALLOC],
-[
-  AC_LIBOBJ([realloc])
-  REPLACE_REALLOC=1
-])
diff --git a/gl/m4/select.m4 b/gl/m4/select.m4
index dc771d0..a58f0ac 100644
--- a/gl/m4/select.m4
+++ b/gl/m4/select.m4
@@ -1,4 +1,4 @@
-# select.m4 serial 3
+# select.m4 serial 6
 dnl Copyright (C) 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,
@@ -10,7 +10,7 @@ AC_DEFUN([gl_FUNC_SELECT],
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_REQUIRE([gl_SOCKETS])
   if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([select])
+    REPLACE_SELECT=1
   else
     dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
     dnl EFAULT.
@@ -44,10 +44,32 @@ changequote([,])dnl
       ])
     case "$gl_cv_func_select_supports0" in
       *yes) ;;
-      *)
-        REPLACE_SELECT=1
-        AC_LIBOBJ([select])
+      *) REPLACE_SELECT=1 ;;
+    esac
+  fi
+
+  dnl Determine the needed libraries.
+  LIB_SELECT="$LIBSOCKET"
+  if test $REPLACE_SELECT = 1; then
+    case "$host_os" in
+      mingw*)
+        dnl On the MSVC platform, the function MsgWaitForMultipleObjects
+        dnl (used in lib/select.c) requires linking with -luser32. On mingw,
+        dnl it is implicit.
+        AC_LINK_IFELSE(
+          [AC_LANG_SOURCE([[
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+int
+main ()
+{
+  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
+  return 0;
+}]])],
+          [],
+          [LIB_SELECT="$LIB_SELECT -luser32"])
         ;;
     esac
   fi
+  AC_SUBST([LIB_SELECT])
 ])
diff --git a/gl/m4/signal_h.m4 b/gl/m4/signal_h.m4
new file mode 100644
index 0000000..5cf54a0
--- /dev/null
+++ b/gl/m4/signal_h.m4
@@ -0,0 +1,83 @@
+# signal_h.m4 serial 18
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_SIGNAL_H],
+[
+  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
+  AC_REQUIRE([gl_CHECK_TYPE_SIGSET_T])
+  gl_NEXT_HEADERS([signal.h])
+
+# AIX declares sig_atomic_t to already include volatile, and C89 compilers
+# then choke on 'volatile sig_atomic_t'.  C99 requires that it compile.
+  AC_CHECK_TYPE([volatile sig_atomic_t], [],
+    [HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=0], [[
+#include <signal.h>
+    ]])
+
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  AC_REQUIRE([AC_TYPE_UID_T])
+
+  dnl Persuade glibc <signal.h> to define sighandler_t.
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+  AC_CHECK_TYPE([sighandler_t], [], [HAVE_SIGHANDLER_T=0], [[
+#include <signal.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 <signal.h>
+    ]], [pthread_sigmask sigaction
+    sigaddset sigdelset sigemptyset sigfillset sigismember
+    sigpending sigprocmask])
+])
+
+AC_DEFUN([gl_CHECK_TYPE_SIGSET_T],
+[
+  AC_CHECK_TYPES([sigset_t],
+    [gl_cv_type_sigset_t=yes], [gl_cv_type_sigset_t=no],
+    [[
+      #include <signal.h>
+      /* Mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.  */
+      #include <sys/types.h>
+    ]])
+  if test $gl_cv_type_sigset_t != yes; then
+    HAVE_SIGSET_T=0
+  fi
+])
+
+AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
+[
+  GNULIB_PTHREAD_SIGMASK=0;    AC_SUBST([GNULIB_PTHREAD_SIGMASK])
+  GNULIB_RAISE=0;              AC_SUBST([GNULIB_RAISE])
+  GNULIB_SIGNAL_H_SIGPIPE=0;   AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE])
+  GNULIB_SIGPROCMASK=0;        AC_SUBST([GNULIB_SIGPROCMASK])
+  GNULIB_SIGACTION=0;          AC_SUBST([GNULIB_SIGACTION])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING])
+  HAVE_PTHREAD_SIGMASK=1;      AC_SUBST([HAVE_PTHREAD_SIGMASK])
+  HAVE_RAISE=1;                AC_SUBST([HAVE_RAISE])
+  HAVE_SIGSET_T=1;             AC_SUBST([HAVE_SIGSET_T])
+  HAVE_SIGINFO_T=1;            AC_SUBST([HAVE_SIGINFO_T])
+  HAVE_SIGACTION=1;            AC_SUBST([HAVE_SIGACTION])
+  HAVE_STRUCT_SIGACTION_SA_SIGACTION=1;
+                               AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION])
+  HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1;
+                               AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T])
+  HAVE_SIGHANDLER_T=1;         AC_SUBST([HAVE_SIGHANDLER_T])
+  REPLACE_PTHREAD_SIGMASK=0;   AC_SUBST([REPLACE_PTHREAD_SIGMASK])
+  REPLACE_RAISE=0;             AC_SUBST([REPLACE_RAISE])
+])
diff --git a/gl/m4/snprintf.m4 b/gl/m4/snprintf.m4
index 8aa5dbe..6f71623 100644
--- a/gl/m4/snprintf.m4
+++ b/gl/m4/snprintf.m4
@@ -1,9 +1,13 @@
-# snprintf.m4 serial 5
+# snprintf.m4 serial 6
 dnl Copyright (C) 2002-2004, 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,
 dnl with or without modifications, as long as this notice is preserved.
 
+dnl Libintl 0.17 will replace snprintf only if it does not support %1$s,
+dnl but defers to any gnulib snprintf replacements.  Therefore, gnulib
+dnl must guarantee that the decision for replacing snprintf is a superset
+dnl of the reasons checked by libintl.
 AC_DEFUN([gl_FUNC_SNPRINTF],
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
@@ -16,7 +20,12 @@ AC_DEFUN([gl_FUNC_SNPRINTF],
         gl_SNPRINTF_RETVAL_C99
         case "$gl_cv_func_snprintf_retval_c99" in
           *yes)
-            gl_cv_func_snprintf_usable=yes
+            gl_PRINTF_POSITIONS
+            case "$gl_cv_func_printf_positions" in
+              *yes)
+                gl_cv_func_snprintf_usable=yes
+                ;;
+            esac
             ;;
         esac
         ;;
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4
index 5e4c69e..4475154 100644
--- a/gl/m4/socklen.m4
+++ b/gl/m4/socklen.m4
@@ -1,4 +1,4 @@
-# socklen.m4 serial 8
+# socklen.m4 serial 10
 dnl Copyright (C) 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,
@@ -9,15 +9,11 @@ dnl From Albert Chin, Windows fixes from Simon Josefsson.
 dnl Check for socklen_t: historically on BSD it is an int, and in
 dnl POSIX 1g it is a type of its own, but some platforms use different
 dnl types for the argument to getsockopt, getpeername, etc.:
-dnl HP-UX 10.20, IRIX 6.5, Interix 3.5, BeOS.
+dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
 dnl So we have to test to find something that will work.
 
-dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
-dnl it there first.  That file is included by gnulib's sys_socket.in.h, which
-dnl all users of this module should include.  Cygwin must not include
-dnl ws2tcpip.h.
 AC_DEFUN([gl_TYPE_SOCKLEN_T],
-  [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl
+  [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
    AC_CHECK_TYPE([socklen_t], ,
      [AC_MSG_CHECKING([for socklen_t equivalent])
       AC_CACHE_VAL([gl_cv_socklen_t_equiv],
@@ -45,9 +41,37 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T],
       AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
       AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
         [type to use in place of socklen_t if not defined])],
-     [#include <sys/types.h>
-      #if HAVE_SYS_SOCKET_H
-      # include <sys/socket.h>
-      #elif HAVE_WS2TCPIP_H
-      # include <ws2tcpip.h>
-      #endif])])
+     [gl_SOCKET_HEADERS])])
+
+dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
+dnl it there too.  But on Cygwin, wc2tcpip.h must not be included.  Users
+dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
+dnl When you change this macro, keep also in sync:
+dnl   - gl_CHECK_SOCKET_HEADERS,
+dnl   - the Include section of modules/socklen.
+AC_DEFUN([gl_SOCKET_HEADERS],
+[
+/* <sys/types.h> is not needed according to POSIX, but the
+   <sys/socket.h> in i386-unknown-freebsd4.10 and
+   powerpc-apple-darwin5.5 required it. */
+#include <sys/types.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
+])
+
+dnl Tests for the existence of the header for socket facilities.
+dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
+dnl This macro must match gl_SOCKET_HEADERS.
+AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
+  [AC_CHECK_HEADERS_ONCE([sys/socket.h])
+   if test $ac_cv_header_sys_socket_h = no; then
+     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
+     dnl the check for those headers unconditional; yet cygwin reports
+     dnl that the headers are present but cannot be compiled (since on
+     dnl cygwin, all socket information should come from sys/socket.h).
+     AC_CHECK_HEADERS([ws2tcpip.h])
+   fi
+  ])
diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4
index 27899aa..c38daea 100644
--- a/gl/m4/sockpfaf.m4
+++ b/gl/m4/sockpfaf.m4
@@ -1,4 +1,4 @@
-# sockpfaf.m4 serial 7
+# sockpfaf.m4 serial 8
 dnl Copyright (C) 2004, 2006, 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,
@@ -59,3 +59,29 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
     AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines 
AF_INET6.])
   fi
 ])
+
+AC_DEFUN([gl_SOCKET_FAMILY_UNIX],
+[
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  AC_CHECK_HEADERS_ONCE([sys/un.h])
+
+  AC_MSG_CHECKING([for UNIX domain sockets])
+  AC_CACHE_VAL([gl_cv_socket_unix],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif]],
+[[int x = AF_UNIX; struct sockaddr_un y;
+ if (&x && &y) return 0;]])],
+       gl_cv_socket_unix=yes, gl_cv_socket_unix=no)])
+  AC_MSG_RESULT([$gl_cv_socket_unix])
+  if test $gl_cv_socket_unix = yes; then
+    AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines 
AF_UNIX.])
+  fi
+])
diff --git a/gl/m4/ssize_t.m4 b/gl/m4/ssize_t.m4
new file mode 100644
index 0000000..d712752
--- /dev/null
+++ b/gl/m4/ssize_t.m4
@@ -0,0 +1,23 @@
+# ssize_t.m4 serial 5 (gettext-0.18.2)
+dnl Copyright (C) 2001-2003, 2006, 2010-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.
+
+dnl From Bruno Haible.
+dnl Test whether ssize_t is defined.
+
+AC_DEFUN([gt_TYPE_SSIZE_T],
+[
+  AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <sys/types.h>]],
+          [[int x = sizeof (ssize_t *) + sizeof (ssize_t);
+            return !x;]])],
+       [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
+  if test $gt_cv_ssize_t = no; then
+    AC_DEFINE([ssize_t], [int],
+              [Define as a signed type of the same size as size_t.])
+  fi
+])
diff --git a/gl/m4/stat.m4 b/gl/m4/stat.m4
new file mode 100644
index 0000000..c63f59f
--- /dev/null
+++ b/gl/m4/stat.m4
@@ -0,0 +1,68 @@
+# serial 8
+
+# Copyright (C) 2009-2011 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STAT],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([lstat])
+  dnl mingw is the only known platform where stat(".") and stat("./") differ
+  AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
+      [gl_cv_func_stat_dir_slash],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+           [[#include <sys/stat.h>
+]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
+         [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
+         [case $host_os in
+            mingw*) gl_cv_func_stat_dir_slash="guessing no";;
+            *) gl_cv_func_stat_dir_slash="guessing yes";;
+          esac])])
+  dnl AIX 7.1, Solaris 9 mistakenly succeed on stat("file/")
+  dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/")
+  AC_CACHE_CHECK([whether stat handles trailing slashes on files],
+      [gl_cv_func_stat_file_slash],
+      [touch conftest.tmp
+       # Assume that if we have lstat, we can also check symlinks.
+       if test $ac_cv_func_lstat = yes; then
+         ln -s conftest.tmp conftest.lnk
+       fi
+       AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+           [[#include <sys/stat.h>
+]], [[int result = 0;
+      struct stat st;
+      if (!stat ("conftest.tmp/", &st))
+        result |= 1;
+#if HAVE_LSTAT
+      if (!stat ("conftest.lnk/", &st))
+        result |= 2;
+#endif
+      return result;
+           ]])],
+         [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
+         [gl_cv_func_stat_file_slash="guessing no"])
+       rm -f conftest.tmp conftest.lnk])
+  case $gl_cv_func_stat_dir_slash in
+    *no) REPLACE_STAT=1
+      AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
+        help when passed a directory name with a trailing slash]);;
+  esac
+  case $gl_cv_func_stat_file_slash in
+    *no) REPLACE_STAT=1
+      AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
+        help when passed a file name with a trailing slash]);;
+  esac
+])
+
+# Prerequisites of lib/stat.c.
+AC_DEFUN([gl_PREREQ_STAT],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  :
+])
diff --git a/gl/m4/stdarg.m4 b/gl/m4/stdarg.m4
index a1ef178..5705de9 100644
--- a/gl/m4/stdarg.m4
+++ b/gl/m4/stdarg.m4
@@ -1,4 +1,4 @@
-# stdarg.m4 serial 5
+# stdarg.m4 serial 6
 dnl Copyright (C) 2006, 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,
@@ -9,8 +9,8 @@ dnl Provide a working va_copy in combination with <stdarg.h>.
 
 AC_DEFUN([gl_STDARG_H],
 [
-  STDARG_H='';                AC_SUBST([STDARG_H])
-  NEXT_STDARG_H='<stdarg.h>'; AC_SUBST([NEXT_STDARG_H])
+  STDARG_H=''
+  NEXT_STDARG_H='<stdarg.h>'
   AC_MSG_CHECKING([for va_copy])
   AC_CACHE_VAL([gl_cv_func_va_copy], [
     AC_COMPILE_IFELSE(
@@ -72,4 +72,7 @@ error, bail out
       fi
     fi
   fi
+  AC_SUBST([STDARG_H])
+  AM_CONDITIONAL([GL_GENERATE_STDARG_H], [test -n "$STDARG_H"])
+  AC_SUBST([NEXT_STDARG_H])
 ])
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4
index 838cf0f..1ebf3e6 100644
--- a/gl/m4/stdbool.m4
+++ b/gl/m4/stdbool.m4
@@ -5,7 +5,7 @@ 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.
 
-#serial 4
+#serial 5
 
 # Prepare for substituting <stdbool.h> if it is not supported.
 
@@ -21,6 +21,7 @@ AC_DEFUN([AM_STDBOOL_H],
     STDBOOL_H='stdbool.h'
   fi
   AC_SUBST([STDBOOL_H])
+  AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
 
   if test "$ac_cv_type__Bool" = yes; then
     HAVE__BOOL=1
diff --git a/gl/m4/stddef_h.m4 b/gl/m4/stddef_h.m4
index 1942b6a..1ae2344 100644
--- a/gl/m4/stddef_h.m4
+++ b/gl/m4/stddef_h.m4
@@ -1,5 +1,5 @@
 dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues.
-# stddef_h.m4 serial 3
+# stddef_h.m4 serial 4
 dnl Copyright (C) 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,
@@ -9,6 +9,7 @@ AC_DEFUN([gl_STDDEF_H],
 [
   AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
   AC_REQUIRE([gt_TYPE_WCHAR_T])
+  STDDEF_H=
   if test $gt_cv_c_wchar_t = no; then
     HAVE_WCHAR_T=0
     STDDEF_H=stddef.h
@@ -24,6 +25,8 @@ AC_DEFUN([gl_STDDEF_H],
     REPLACE_NULL=1
     STDDEF_H=stddef.h
   fi
+  AC_SUBST([STDDEF_H])
+  AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"])
   if test -n "$STDDEF_H"; then
     gl_NEXT_HEADERS([stddef.h])
   fi
@@ -41,5 +44,4 @@ AC_DEFUN([gl_STDDEF_H_DEFAULTS],
   dnl Assume proper GNU behavior unless another module says otherwise.
   REPLACE_NULL=0;                AC_SUBST([REPLACE_NULL])
   HAVE_WCHAR_T=1;                AC_SUBST([HAVE_WCHAR_T])
-  STDDEF_H='';                   AC_SUBST([STDDEF_H])
 ])
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4
index e7d0d07..092161c 100644
--- a/gl/m4/stdint.m4
+++ b/gl/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 39
+# stdint.m4 serial 41
 dnl Copyright (C) 2001-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,
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 dnl From Paul Eggert and Bruno Haible.
 dnl Test whether <stdint.h> is supported or must be substituted.
 
-AC_DEFUN([gl_STDINT_H],
+AC_DEFUN_ONCE([gl_STDINT_H],
 [
   AC_PREREQ([2.59])dnl
 
@@ -305,6 +305,7 @@ static const char *macro_values[] =
     STDINT_H=stdint.h
   fi
   AC_SUBST([STDINT_H])
+  AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
 ])
 
 dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
@@ -465,6 +466,14 @@ AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
   fi
   gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t],
     [gl_STDINT_INCLUDES])
+
+  dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99
+  dnl requirement that wint_t is "unchanged by default argument promotions".
+  dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
+  dnl Set the variable BITSIZEOF_WINT_T accordingly.
+  if test $BITSIZEOF_WINT_T -lt 32; then
+    BITSIZEOF_WINT_T=32
+  fi
 ])
 
 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index b6163d6..39bf80e 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 32
+# 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,
@@ -8,8 +8,31 @@ AC_DEFUN([gl_STDIO_H],
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_REQUIRE([AC_C_INLINE])
-  AC_REQUIRE([gl_ASM_SYMBOL_PREFIX])
   gl_NEXT_HEADERS([stdio.h])
+
+  dnl No need to create extra modules for these functions. Everyone who uses
+  dnl <stdio.h> likely needs them.
+  GNULIB_FSCANF=1
+  GNULIB_SCANF=1
+  GNULIB_FGETC=1
+  GNULIB_GETC=1
+  GNULIB_GETCHAR=1
+  GNULIB_FGETS=1
+  GNULIB_GETS=1
+  GNULIB_FREAD=1
+  dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c"
+  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
+  dnl also an optimization, to avoid performing a configure check whose result
+  dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
+  dnl or GNULIB_NONBLOCKING redundant.
+  m4_ifdef([gl_NONBLOCKING_IO], [
+    gl_NONBLOCKING_IO
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_READ_FUNCS=1
+      AC_LIBOBJ([stdio-read])
+    fi
+  ])
+
   dnl No need to create extra modules for these functions. Everyone who uses
   dnl <stdio.h> likely needs them.
   GNULIB_FPRINTF=1
@@ -22,9 +45,11 @@ AC_DEFUN([gl_STDIO_H],
   GNULIB_FPUTS=1
   GNULIB_PUTS=1
   GNULIB_FWRITE=1
-  dnl This ifdef is just an optimization, to avoid performing a configure
-  dnl check whose result is not used. It does not make the test of
-  dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
+  dnl This ifdef is necessary to avoid an error "missing file 
lib/stdio-write.c"
+  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
+  dnl also an optimization, to avoid performing a configure check whose result
+  dnl is not used. But it does not make the test of GNULIB_STDIO_H_SIGPIPE or
+  dnl GNULIB_SIGPIPE redundant.
   m4_ifdef([gl_SIGNAL_SIGPIPE], [
     gl_SIGNAL_SIGPIPE
     if test $gl_cv_header_signal_h_SIGPIPE != yes; then
@@ -32,12 +57,24 @@ AC_DEFUN([gl_STDIO_H],
       AC_LIBOBJ([stdio-write])
     fi
   ])
+  dnl This ifdef is necessary to avoid an error "missing file 
lib/stdio-write.c"
+  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
+  dnl also an optimization, to avoid performing a configure check whose result
+  dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
+  dnl or GNULIB_NONBLOCKING redundant.
+  m4_ifdef([gl_NONBLOCKING_IO], [
+    gl_NONBLOCKING_IO
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_WRITE_FUNCS=1
+      AC_LIBOBJ([stdio-write])
+    fi
+  ])
 
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use, and which is not
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
-    ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
+    ]], [dprintf fpurge fseeko ftello getdelim getline pclose popen renameat
     snprintf tmpfile vdprintf vsnprintf])
 ])
 
@@ -54,23 +91,32 @@ 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])
   GNULIB_FOPEN=0;                AC_SUBST([GNULIB_FOPEN])
   GNULIB_FPRINTF=0;              AC_SUBST([GNULIB_FPRINTF])
   GNULIB_FPRINTF_POSIX=0;        AC_SUBST([GNULIB_FPRINTF_POSIX])
   GNULIB_FPURGE=0;               AC_SUBST([GNULIB_FPURGE])
   GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
   GNULIB_FPUTS=0;                AC_SUBST([GNULIB_FPUTS])
+  GNULIB_FREAD=0;                AC_SUBST([GNULIB_FREAD])
   GNULIB_FREOPEN=0;              AC_SUBST([GNULIB_FREOPEN])
+  GNULIB_FSCANF=0;               AC_SUBST([GNULIB_FSCANF])
   GNULIB_FSEEK=0;                AC_SUBST([GNULIB_FSEEK])
   GNULIB_FSEEKO=0;               AC_SUBST([GNULIB_FSEEKO])
   GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
   GNULIB_FWRITE=0;               AC_SUBST([GNULIB_FWRITE])
+  GNULIB_GETC=0;                 AC_SUBST([GNULIB_GETC])
+  GNULIB_GETCHAR=0;              AC_SUBST([GNULIB_GETCHAR])
   GNULIB_GETDELIM=0;             AC_SUBST([GNULIB_GETDELIM])
   GNULIB_GETLINE=0;              AC_SUBST([GNULIB_GETLINE])
+  GNULIB_GETS=0;                 AC_SUBST([GNULIB_GETS])
   GNULIB_OBSTACK_PRINTF=0;       AC_SUBST([GNULIB_OBSTACK_PRINTF])
   GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
+  GNULIB_PCLOSE=0;               AC_SUBST([GNULIB_PCLOSE])
   GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
   GNULIB_POPEN=0;                AC_SUBST([GNULIB_POPEN])
   GNULIB_PRINTF=0;               AC_SUBST([GNULIB_PRINTF])
@@ -81,11 +127,15 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_REMOVE=0;               AC_SUBST([GNULIB_REMOVE])
   GNULIB_RENAME=0;               AC_SUBST([GNULIB_RENAME])
   GNULIB_RENAMEAT=0;             AC_SUBST([GNULIB_RENAMEAT])
+  GNULIB_SCANF=0;                AC_SUBST([GNULIB_SCANF])
   GNULIB_SNPRINTF=0;             AC_SUBST([GNULIB_SNPRINTF])
   GNULIB_SPRINTF_POSIX=0;        AC_SUBST([GNULIB_SPRINTF_POSIX])
+  GNULIB_STDIO_H_NONBLOCKING=0;  AC_SUBST([GNULIB_STDIO_H_NONBLOCKING])
   GNULIB_STDIO_H_SIGPIPE=0;      AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
   GNULIB_TMPFILE=0;              AC_SUBST([GNULIB_TMPFILE])
   GNULIB_VASPRINTF=0;            AC_SUBST([GNULIB_VASPRINTF])
+  GNULIB_VFSCANF=0;              AC_SUBST([GNULIB_VFSCANF])
+  GNULIB_VSCANF=0;               AC_SUBST([GNULIB_VSCANF])
   GNULIB_VDPRINTF=0;             AC_SUBST([GNULIB_VDPRINTF])
   GNULIB_VFPRINTF=0;             AC_SUBST([GNULIB_VFPRINTF])
   GNULIB_VFPRINTF_POSIX=0;       AC_SUBST([GNULIB_VFPRINTF_POSIX])
@@ -105,11 +155,14 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
   HAVE_FSEEKO=1;                 AC_SUBST([HAVE_FSEEKO])
   HAVE_FTELLO=1;                 AC_SUBST([HAVE_FTELLO])
+  HAVE_PCLOSE=1;                 AC_SUBST([HAVE_PCLOSE])
+  HAVE_POPEN=1;                  AC_SUBST([HAVE_POPEN])
   HAVE_RENAMEAT=1;               AC_SUBST([HAVE_RENAMEAT])
   HAVE_VASPRINTF=1;              AC_SUBST([HAVE_VASPRINTF])
   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])
@@ -130,6 +183,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   REPLACE_RENAMEAT=0;            AC_SUBST([REPLACE_RENAMEAT])
   REPLACE_SNPRINTF=0;            AC_SUBST([REPLACE_SNPRINTF])
   REPLACE_SPRINTF=0;             AC_SUBST([REPLACE_SPRINTF])
+  REPLACE_STDIO_READ_FUNCS=0;    AC_SUBST([REPLACE_STDIO_READ_FUNCS])
   REPLACE_STDIO_WRITE_FUNCS=0;   AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
   REPLACE_TMPFILE=0;             AC_SUBST([REPLACE_TMPFILE])
   REPLACE_VASPRINTF=0;           AC_SUBST([REPLACE_VASPRINTF])
@@ -139,23 +193,3 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   REPLACE_VSNPRINTF=0;           AC_SUBST([REPLACE_VSNPRINTF])
   REPLACE_VSPRINTF=0;            AC_SUBST([REPLACE_VSPRINTF])
 ])
-
-dnl Code shared by fseeko and ftello.  Determine if large files are supported,
-dnl but stdin does not start as a large file by default.
-AC_DEFUN([gl_STDIN_LARGE_OFFSET],
-  [
-    AC_CACHE_CHECK([whether stdin defaults to large file offsets],
-      [gl_cv_var_stdin_large_offset],
-      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
-[[#if defined __SL64 && defined __SCLE /* cygwin */
-  /* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
-     fseeko/ftello needlessly fail.  This bug was fixed in 1.5.25, and
-     it is easier to do a version check than building a runtime test.  */
-# include <cygwin/version.h>
-# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
-  choke me
-# endif
-#endif]])],
-        [gl_cv_var_stdin_large_offset=yes],
-        [gl_cv_var_stdin_large_offset=no])])
-])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index d28b552..25fdada 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 36
+# stdlib_h.m4 serial 37
 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,
@@ -44,6 +44,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_GRANTPT=0;       AC_SUBST([GNULIB_GRANTPT])
   GNULIB_MALLOC_POSIX=0;  AC_SUBST([GNULIB_MALLOC_POSIX])
+  GNULIB_MBTOWC=0;        AC_SUBST([GNULIB_MBTOWC])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKOSTEMP=0;      AC_SUBST([GNULIB_MKOSTEMP])
   GNULIB_MKOSTEMPS=0;     AC_SUBST([GNULIB_MKOSTEMPS])
@@ -62,6 +63,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_SYSTEM_POSIX=0;  AC_SUBST([GNULIB_SYSTEM_POSIX])
   GNULIB_UNLOCKPT=0;      AC_SUBST([GNULIB_UNLOCKPT])
   GNULIB_UNSETENV=0;      AC_SUBST([GNULIB_UNSETENV])
+  GNULIB_WCTOMB=0;        AC_SUBST([GNULIB_WCTOMB])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE__EXIT=1;              AC_SUBST([HAVE__EXIT])
   HAVE_ATOLL=1;              AC_SUBST([HAVE_ATOLL])
@@ -91,6 +93,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_CALLOC=0;          AC_SUBST([REPLACE_CALLOC])
   REPLACE_CANONICALIZE_FILE_NAME=0;  AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
   REPLACE_MALLOC=0;          AC_SUBST([REPLACE_MALLOC])
+  REPLACE_MBTOWC=0;          AC_SUBST([REPLACE_MBTOWC])
   REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
   REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
   REPLACE_REALLOC=0;         AC_SUBST([REPLACE_REALLOC])
@@ -98,4 +101,5 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_SETENV=0;          AC_SUBST([REPLACE_SETENV])
   REPLACE_STRTOD=0;          AC_SUBST([REPLACE_STRTOD])
   REPLACE_UNSETENV=0;        AC_SUBST([REPLACE_UNSETENV])
+  REPLACE_WCTOMB=0;          AC_SUBST([REPLACE_WCTOMB])
 ])
diff --git a/gl/m4/strerror.m4 b/gl/m4/strerror.m4
index 73d1d54..ca05be6 100644
--- a/gl/m4/strerror.m4
+++ b/gl/m4/strerror.m4
@@ -1,4 +1,4 @@
-# strerror.m4 serial 9
+# strerror.m4 serial 16
 dnl Copyright (C) 2002, 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,
@@ -6,63 +6,73 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 AC_DEFUN([gl_FUNC_STRERROR],
 [
-  AC_REQUIRE([gl_FUNC_STRERROR_SEPARATE])
-  if test $REPLACE_STRERROR = 1; then
-    AC_LIBOBJ([strerror])
-    AC_DEFINE_UNQUOTED([REPLACE_STRERROR], [$REPLACE_STRERROR],
-      [Define this to 1 if strerror is broken.])
-  fi
-])
-
-# Like gl_FUNC_STRERROR, except prepare for separate compilation (no 
AC_LIBOBJ).
-AC_DEFUN([gl_FUNC_STRERROR_SEPARATE],
-[
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_ERRNO_H])
-  if test -z "$ERRNO_H"; then
+  AC_REQUIRE([gl_FUNC_STRERROR_0])
+  m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
+    AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
+  ])
+  if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
     AC_CACHE_CHECK([for working strerror function],
      [gl_cv_func_working_strerror],
      [AC_RUN_IFELSE(
         [AC_LANG_PROGRAM(
            [[#include <string.h>
            ]],
-           [[return !*strerror (-2);]])],
+           [[if (!*strerror (-2)) return 1;]])],
         [gl_cv_func_working_strerror=yes],
         [gl_cv_func_working_strerror=no],
-        [dnl Assume crossbuild works if it compiles.
-         AC_COMPILE_IFELSE(
-           [AC_LANG_PROGRAM(
-              [[#include <string.h>
-              ]],
-              [[return !*strerror (-2);]])],
-           [gl_cv_func_working_strerror=yes],
-           [gl_cv_func_working_strerror=no])
-      ])
+        [dnl Be pessimistic on cross-compiles for now.
+         gl_cv_func_working_strerror="guessing no"])
     ])
-    if test $gl_cv_func_working_strerror = no; then
+    if test "$gl_cv_func_working_strerror" != yes; then
       dnl The system's strerror() fails to return a string for out-of-range
       dnl integers. Replace it.
       REPLACE_STRERROR=1
     fi
+    m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
+      dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
+      dnl buffer, we must replace strerror.
+      case "$gl_cv_func_strerror_r_works" in
+        *no) REPLACE_STRERROR=1 ;;
+      esac
+    ])
   else
     dnl The system's strerror() cannot know about the new errno values we add
-    dnl to <errno.h>. Replace it.
+    dnl to <errno.h>, or any fix for strerror(0). Replace it.
     REPLACE_STRERROR=1
   fi
-  if test $REPLACE_STRERROR = 1; then
-    gl_PREREQ_STRERROR
-  fi
 ])
 
-# Prerequisites of lib/strerror.c.
-AC_DEFUN([gl_PREREQ_STRERROR], [
-  AC_CHECK_DECLS([strerror])
-  AC_CHECK_HEADERS_ONCE([sys/socket.h])
-  if test $ac_cv_header_sys_socket_h != yes; then
-    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
-    dnl the check for those headers unconditional; yet cygwin reports
-    dnl that the headers are present but cannot be compiled (since on
-    dnl cygwin, all socket information should come from sys/socket.h).
-    AC_CHECK_HEADERS([winsock2.h])
+dnl Detect if strerror(0) passes (that is, does not set errno, and does not
+dnl return a string that matches strerror(-1)).
+AC_DEFUN([gl_FUNC_STRERROR_0],
+[
+  REPLACE_STRERROR_0=0
+  AC_CACHE_CHECK([whether strerror(0) succeeds],
+   [gl_cv_func_strerror_0_works],
+   [AC_RUN_IFELSE(
+      [AC_LANG_PROGRAM(
+         [[#include <string.h>
+           #include <errno.h>
+         ]],
+         [[int result = 0;
+           char *str;
+           errno = 0;
+           str = strerror (0);
+           if (!*str) result |= 1;
+           if (errno) result |= 2;
+           if (strstr (str, "nknown") || strstr (str, "ndefined"))
+             result |= 4;
+           return result;]])],
+      [gl_cv_func_strerror_0_works=yes],
+      [gl_cv_func_strerror_0_works=no],
+      [dnl Be pessimistic on cross-compiles for now.
+       gl_cv_func_strerror_0_works="guessing no"])
+  ])
+  if test "$gl_cv_func_strerror_0_works" != yes; then
+    REPLACE_STRERROR_0=1
+    AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
+      does not return a message implying success.])
   fi
 ])
diff --git a/gl/m4/strerror_r.m4 b/gl/m4/strerror_r.m4
new file mode 100644
index 0000000..1d4a653
--- /dev/null
+++ b/gl/m4/strerror_r.m4
@@ -0,0 +1,173 @@
+# strerror_r.m4 serial 14
+dnl Copyright (C) 2002, 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STRERROR_R],
+[
+  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
+
+  dnl Persuade Solaris <string.h> to declare strerror_r().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  dnl Some systems don't declare strerror_r() if _THREAD_SAFE and _REENTRANT
+  dnl are not defined.
+  AC_CHECK_DECLS_ONCE([strerror_r])
+  if test $ac_cv_have_decl_strerror_r = no; then
+    HAVE_DECL_STRERROR_R=0
+  fi
+
+  if test $ac_cv_func_strerror_r = yes; then
+    if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
+      if test $gl_cv_func_strerror_r_posix_signature = yes; then
+        case "$gl_cv_func_strerror_r_works" in
+          dnl The system's strerror_r has bugs.  Replace it.
+          *no) REPLACE_STRERROR_R=1 ;;
+        esac
+      else
+        dnl The system's strerror_r() has a wrong signature. Replace it.
+        REPLACE_STRERROR_R=1
+      fi
+    else
+      dnl The system's strerror_r() cannot know about the new errno values we
+      dnl add to <errno.h>, or any fix for strerror(0). Replace it.
+      REPLACE_STRERROR_R=1
+    fi
+  fi
+])
+
+# Prerequisites of lib/strerror_r.c.
+AC_DEFUN([gl_PREREQ_STRERROR_R], [
+  dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
+  AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
+  AC_CHECK_FUNCS_ONCE([catgets])
+  AC_CHECK_FUNCS_ONCE([snprintf])
+])
+
+# Detect if strerror_r works, but without affecting whether a replacement
+# strerror_r will be used.
+AC_DEFUN([gl_FUNC_STRERROR_R_WORKS],
+[
+  AC_REQUIRE([gl_HEADER_ERRNO_H])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_FUNC_STRERROR_0])
+
+  AC_CHECK_FUNCS_ONCE([strerror_r])
+  if test $ac_cv_func_strerror_r = yes; then
+    if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
+      dnl The POSIX prototype is:  int strerror_r (int, char *, size_t);
+      dnl glibc, Cygwin:           char *strerror_r (int, char *, size_t);
+      dnl AIX 5.1, OSF/1 5.1:      int strerror_r (int, char *, int);
+      AC_CACHE_CHECK([for strerror_r with POSIX signature],
+        [gl_cv_func_strerror_r_posix_signature],
+        [AC_COMPILE_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <string.h>
+                int strerror_r (int, char *, size_t);
+              ]],
+              [])],
+           [gl_cv_func_strerror_r_posix_signature=yes],
+           [gl_cv_func_strerror_r_posix_signature=no])
+        ])
+      if test $gl_cv_func_strerror_r_posix_signature = yes; then
+        dnl AIX 6.1 strerror_r fails by returning -1, not an error number.
+        dnl HP-UX 11.31 strerror_r always fails when the buffer length argument
+        dnl is less than 80.
+        dnl FreeBSD 8.s strerror_r claims failure on 0
+        dnl MacOS X 10.5 strerror_r treats 0 like -1
+        dnl Solaris 10 strerror_r corrupts errno on failure
+        AC_CACHE_CHECK([whether strerror_r works],
+          [gl_cv_func_strerror_r_works],
+          [AC_RUN_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <errno.h>
+                  #include <string.h>
+                ]],
+                [[int result = 0;
+                  char buf[79];
+                  if (strerror_r (EACCES, buf, 0) < 0)
+                    result |= 1;
+                  errno = 0;
+                  if (strerror_r (EACCES, buf, sizeof buf) != 0)
+                    result |= 2;
+                  strcpy (buf, "Unknown");
+                  if (strerror_r (0, buf, sizeof buf) != 0)
+                    result |= 4;
+                  if (errno)
+                    result |= 8;
+                  if (strstr (buf, "nknown") || strstr (buf, "ndefined"))
+                    result |= 0x10;
+                  errno = 0;
+                  *buf = 0;
+                  if (strerror_r (-3, buf, sizeof buf) < 0)
+                    result |= 0x20;
+                  if (errno)
+                    result |= 0x40;
+                  if (!*buf)
+                    result |= 0x80;
+                  return result;
+                ]])],
+             [gl_cv_func_strerror_r_works=yes],
+             [gl_cv_func_strerror_r_works=no],
+             [
+changequote(,)dnl
+              case "$host_os" in
+                       # Guess no on AIX.
+                aix*)  gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess no on HP-UX.
+                hpux*) gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess no on BSD variants.
+                *bsd*)  gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess yes otherwise.
+                *)     gl_cv_func_strerror_r_works="guessing yes";;
+              esac
+changequote([,])dnl
+             ])
+          ])
+      else
+        dnl The system's strerror() has a wrong signature.
+        dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
+        AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
+        dnl In glibc < 2.14, __xpg_strerror_r does not populate buf on failure.
+        dnl In cygwin < 1.7.10, __xpg_strerror_r clobbers strerror's buffer.
+        if test $ac_cv_func___xpg_strerror_r = yes; then
+          AC_CACHE_CHECK([whether __xpg_strerror_r works],
+            [gl_cv_func_strerror_r_works],
+            [AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM(
+                  [[#include <errno.h>
+                    #include <string.h>
+                    extern
+                    #ifdef __cplusplus
+                    "C"
+                    #endif
+                    int __xpg_strerror_r(int, char *, size_t);
+                  ]],
+                  [[int result = 0;
+                    char buf[256] = "^";
+                    char copy[256];
+                    char *str = strerror (-1);
+                    strcpy (copy, str);
+                    if (__xpg_strerror_r (-2, buf, 1) == 0)
+                      result |= 1;
+                    if (*buf)
+                      result |= 2;
+                    __xpg_strerror_r (-2, buf, 256);
+                    if (strcmp (str, copy))
+                      result |= 4;
+                    return result;
+                  ]])],
+               [gl_cv_func_strerror_r_works=yes],
+               [gl_cv_func_strerror_r_works=no],
+               [dnl Guess no on all platforms that have __xpg_strerror_r,
+                dnl at least until fixed glibc and cygwin are more common.
+                gl_cv_func_strerror_r_works="guessing no"
+               ])
+            ])
+        fi
+      fi
+    fi
+  fi
+])
diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4
index 30ddfbc..4f9f511 100644
--- a/gl/m4/string_h.m4
+++ b/gl/m4/string_h.m4
@@ -5,7 +5,7 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 19
+# serial 21
 
 # Written by Paul Eggert.
 
@@ -27,9 +27,9 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY],
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <string.h>
     ]],
-    [memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul strdup
-     strncat strndup strnlen strpbrk strsep strcasestr strtok_r strerror_r
-     strsignal strverscmp])
+    [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul
+     strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r
+     strerror_r strsignal strverscmp])
 ])
 
 AC_DEFUN([gl_STRING_MODULE_INDICATOR],
@@ -43,6 +43,8 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR],
 
 AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
 [
+  GNULIB_FFSL=0;        AC_SUBST([GNULIB_FFSL])
+  GNULIB_FFSLL=0;       AC_SUBST([GNULIB_FFSLL])
   GNULIB_MEMCHR=0;      AC_SUBST([GNULIB_MEMCHR])
   GNULIB_MEMMEM=0;      AC_SUBST([GNULIB_MEMMEM])
   GNULIB_MEMPCPY=0;     AC_SUBST([GNULIB_MEMPCPY])
@@ -80,6 +82,8 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
   GNULIB_STRVERSCMP=0;  AC_SUBST([GNULIB_STRVERSCMP])
   HAVE_MBSLEN=0;        AC_SUBST([HAVE_MBSLEN])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_FFSL=1;                  AC_SUBST([HAVE_FFSL])
+  HAVE_FFSLL=1;                 AC_SUBST([HAVE_FFSLL])
   HAVE_MEMCHR=1;                AC_SUBST([HAVE_MEMCHR])
   HAVE_DECL_MEMMEM=1;           AC_SUBST([HAVE_DECL_MEMMEM])
   HAVE_MEMPCPY=1;               AC_SUBST([HAVE_MEMPCPY])
@@ -104,6 +108,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
   REPLACE_STRDUP=0;             AC_SUBST([REPLACE_STRDUP])
   REPLACE_STRSTR=0;             AC_SUBST([REPLACE_STRSTR])
   REPLACE_STRCASESTR=0;         AC_SUBST([REPLACE_STRCASESTR])
+  REPLACE_STRCHRNUL=0;          AC_SUBST([REPLACE_STRCHRNUL])
   REPLACE_STRERROR=0;           AC_SUBST([REPLACE_STRERROR])
   REPLACE_STRERROR_R=0;         AC_SUBST([REPLACE_STRERROR_R])
   REPLACE_STRNCAT=0;            AC_SUBST([REPLACE_STRNCAT])
diff --git a/gl/m4/symlink.m4 b/gl/m4/symlink.m4
new file mode 100644
index 0000000..680c14f
--- /dev/null
+++ b/gl/m4/symlink.m4
@@ -0,0 +1,43 @@
+# serial 5
+# See if we need to provide symlink replacement.
+
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Written by Eric Blake.
+
+AC_DEFUN([gl_FUNC_SYMLINK],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([symlink])
+  dnl The best we can do on mingw is provide a dummy that always fails, so
+  dnl that compilation can proceed with fewer ifdefs.  On FreeBSD 7.2, AIX 7.1,
+  dnl and Solaris 9, we want to fix a bug with trailing slash handling.
+  if test $ac_cv_func_symlink = no; then
+    HAVE_SYMLINK=0
+  else
+    AC_CACHE_CHECK([whether symlink handles trailing slash correctly],
+      [gl_cv_func_symlink_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+           [[#include <unistd.h>
+           ]],
+           [[int result = 0;
+             if (!symlink ("a", "conftest.link/"))
+               result |= 1;
+             if (symlink ("conftest.f", "conftest.lnk2"))
+               result |= 2;
+             else if (!symlink ("a", "conftest.lnk2/"))
+               result |= 4;
+             return result;
+           ]])],
+         [gl_cv_func_symlink_works=yes], [gl_cv_func_symlink_works=no],
+         [gl_cv_func_symlink_works="guessing no"])
+      rm -f conftest.f conftest.link conftest.lnk2])
+    if test "$gl_cv_func_symlink_works" != yes; then
+      REPLACE_SYMLINK=1
+    fi
+  fi
+])
diff --git a/gl/m4/sys_ioctl_h.m4 b/gl/m4/sys_ioctl_h.m4
index 97cab84..8c7d112 100644
--- a/gl/m4/sys_ioctl_h.m4
+++ b/gl/m4/sys_ioctl_h.m4
@@ -1,4 +1,4 @@
-# sys_ioctl_h.m4 serial 9
+# sys_ioctl_h.m4 serial 10
 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,
@@ -44,13 +44,6 @@ AC_DEFUN([gl_SYS_IOCTL_H],
     ]], [ioctl])
 ])
 
-dnl Unconditionally enables the replacement of <sys/ioctl.h>.
-AC_DEFUN([gl_REPLACE_SYS_IOCTL_H],
-[
-  dnl This is a no-op, because <sys/ioctl.h> is always overridden.
-  :
-])
-
 AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
 [
   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
diff --git a/gl/m4/sys_select_h.m4 b/gl/m4/sys_select_h.m4
index f167118..b1914fb 100644
--- a/gl/m4/sys_select_h.m4
+++ b/gl/m4/sys_select_h.m4
@@ -1,4 +1,4 @@
-# sys_select_h.m4 serial 16
+# sys_select_h.m4 serial 20
 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,
@@ -6,7 +6,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 AC_DEFUN([gl_HEADER_SYS_SELECT],
 [
-  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  AC_REQUIRE([AC_C_RESTRICT])
   AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
   AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
     [gl_cv_header_sys_select_h_selfcontained],
@@ -32,10 +32,18 @@ AC_DEFUN([gl_HEADER_SYS_SELECT],
              [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
                   #undef memset
                   #define memset nonexistent_memset
-                  extern void *memset (void *, int, unsigned long);
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void *memset (void *, int, unsigned long);
                   #undef bzero
                   #define bzero nonexistent_bzero
-                  extern void bzero (void *, unsigned long);
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void bzero (void *, unsigned long);
                   fd_set fds;
                   FD_ZERO (&fds);
                 ]])
@@ -64,7 +72,7 @@ AC_DEFUN([gl_HEADER_SYS_SELECT],
 # include <sys/time.h>
 #endif
 #include <sys/select.h>
-    ]], [select])
+    ]], [pselect select])
 ])
 
 AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
@@ -78,7 +86,10 @@ AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
 
 AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
 [
+  GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT])
   GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
+  REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
   REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
 ])
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4
index 12dc05d..7da91a4 100644
--- a/gl/m4/sys_socket_h.m4
+++ b/gl/m4/sys_socket_h.m4
@@ -1,4 +1,4 @@
-# sys_socket_h.m4 serial 21
+# sys_socket_h.m4 serial 22
 dnl Copyright (C) 2005-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,
@@ -101,17 +101,13 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
 [
   dnl Check prerequisites of the <sys/socket.h> replacement.
+  AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
   gl_CHECK_NEXT_HEADERS([sys/socket.h])
   if test $ac_cv_header_sys_socket_h = yes; then
     HAVE_SYS_SOCKET_H=1
     HAVE_WS2TCPIP_H=0
   else
     HAVE_SYS_SOCKET_H=0
-    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
-    dnl the check for those headers unconditional; yet cygwin reports
-    dnl that the headers are present but cannot be compiled (since on
-    dnl cygwin, all socket information should come from sys/socket.h).
-    AC_CHECK_HEADERS([ws2tcpip.h])
     if test $ac_cv_header_ws2tcpip_h = yes; then
       HAVE_WS2TCPIP_H=1
     else
diff --git a/gl/m4/sys_stat_h.m4 b/gl/m4/sys_stat_h.m4
index fc41912..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 24   -*- 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,
@@ -19,6 +19,9 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
 
   gl_CHECK_NEXT_HEADERS([sys/stat.h])
 
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+
   dnl Define types that are supposed to be defined in <sys/types.h> or
   dnl <sys/stat.h>.
   AC_CHECK_TYPE([nlink_t], [],
@@ -30,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
 
@@ -47,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/sys_time_h.m4 b/gl/m4/sys_time_h.m4
index 3a3adc8..064e0de 100644
--- a/gl/m4/sys_time_h.m4
+++ b/gl/m4/sys_time_h.m4
@@ -1,5 +1,5 @@
 # Configure a replacement for <sys/time.h>.
-# serial 6
+# serial 7
 
 # Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -27,6 +27,9 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
     HAVE_SYS_TIME_H=0
   fi
 
+  dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
+  dnl only. So include that header in the list.
+  gl_PREREQ_SYS_H_WINSOCK2
   AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
     [AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM(
@@ -34,6 +37,9 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
              #include <sys/time.h>
             #endif
             #include <time.h>
+            #if HAVE_WINSOCK2_H
+            # include <winsock2.h>
+            #endif
           ]],
           [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
        [gl_cv_sys_struct_timeval=yes],
diff --git a/gl/m4/sys_types_h.m4 b/gl/m4/sys_types_h.m4
new file mode 100644
index 0000000..62113df
--- /dev/null
+++ b/gl/m4/sys_types_h.m4
@@ -0,0 +1,21 @@
+# sys_types_h.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_SYS_TYPES_H],
+[
+  AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
+  gl_NEXT_HEADERS([sys/types.h])
+
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+])
+
+AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS],
+[
+])
diff --git a/lib/gl/m4/sys_uio_h.m4 b/gl/m4/sys_uio_h.m4
similarity index 100%
copy from lib/gl/m4/sys_uio_h.m4
copy to gl/m4/sys_uio_h.m4
diff --git a/gl/m4/thread.m4 b/gl/m4/thread.m4
new file mode 100644
index 0000000..49a4bc7
--- /dev/null
+++ b/gl/m4/thread.m4
@@ -0,0 +1,18 @@
+# thread.m4 serial 2
+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_THREAD],
+[
+  AC_REQUIRE([gl_THREADLIB])
+  AC_REQUIRE([AC_C_INLINE])
+
+  if test $gl_threads_api = posix; then
+    gl_save_LIBS="$LIBS"
+    LIBS="$LIBS $LIBMULTITHREAD"
+    AC_CHECK_FUNCS([pthread_atfork])
+    LIBS="$gl_save_LIBS"
+  fi
+])
diff --git a/lib/gl/m4/threadlib.m4 b/gl/m4/threadlib.m4
similarity index 100%
copy from lib/gl/m4/threadlib.m4
copy to gl/m4/threadlib.m4
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4
index 615da1c..3454b23 100644
--- a/gl/m4/time_h.m4
+++ b/gl/m4/time_h.m4
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
 
-# serial 4
+# serial 6
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index c81a113..57c8094 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 53
+# 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,
@@ -21,9 +21,15 @@ AC_DEFUN([gl_UNISTD_H],
   fi
   AC_SUBST([HAVE_UNISTD_H])
 
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
   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 <unistd.h>
+  gl_WARN_ON_USE_PREPARE([[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 /* Some systems declare various items in the wrong headers.  */
 #if !(defined __GLIBC__ && !defined __UCLIBC__)
 # include <fcntl.h>
@@ -33,11 +39,11 @@ AC_DEFUN([gl_UNISTD_H],
 #  include <io.h>
 # endif
 #endif
-    ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
-    fsync ftruncate getcwd getdomainname getdtablesize getgroups
+    ]], [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 lchown link linkat lseek pipe pipe2 pread pwrite readlink
-    readlinkat rmdir sleep symlink symlinkat ttyname_r unlink unlinkat
+    endusershell group_member lchown link linkat lseek pipe pipe2 pread pwrite
+    readlink readlinkat rmdir sleep symlink symlinkat ttyname_r unlink unlinkat
     usleep])
 ])
 
@@ -52,47 +58,53 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
 
 AC_DEFUN([gl_UNISTD_H_DEFAULTS],
 [
-  GNULIB_CHOWN=0;            AC_SUBST([GNULIB_CHOWN])
-  GNULIB_CLOSE=0;            AC_SUBST([GNULIB_CLOSE])
-  GNULIB_DUP2=0;             AC_SUBST([GNULIB_DUP2])
-  GNULIB_DUP3=0;             AC_SUBST([GNULIB_DUP3])
-  GNULIB_ENVIRON=0;          AC_SUBST([GNULIB_ENVIRON])
-  GNULIB_EUIDACCESS=0;       AC_SUBST([GNULIB_EUIDACCESS])
-  GNULIB_FACCESSAT=0;        AC_SUBST([GNULIB_FACCESSAT])
-  GNULIB_FCHDIR=0;           AC_SUBST([GNULIB_FCHDIR])
-  GNULIB_FCHOWNAT=0;         AC_SUBST([GNULIB_FCHOWNAT])
-  GNULIB_FSYNC=0;            AC_SUBST([GNULIB_FSYNC])
-  GNULIB_FTRUNCATE=0;        AC_SUBST([GNULIB_FTRUNCATE])
-  GNULIB_GETCWD=0;           AC_SUBST([GNULIB_GETCWD])
-  GNULIB_GETDOMAINNAME=0;    AC_SUBST([GNULIB_GETDOMAINNAME])
-  GNULIB_GETDTABLESIZE=0;    AC_SUBST([GNULIB_GETDTABLESIZE])
-  GNULIB_GETGROUPS=0;        AC_SUBST([GNULIB_GETGROUPS])
-  GNULIB_GETHOSTNAME=0;      AC_SUBST([GNULIB_GETHOSTNAME])
-  GNULIB_GETLOGIN=0;         AC_SUBST([GNULIB_GETLOGIN])
-  GNULIB_GETLOGIN_R=0;       AC_SUBST([GNULIB_GETLOGIN_R])
-  GNULIB_GETPAGESIZE=0;      AC_SUBST([GNULIB_GETPAGESIZE])
-  GNULIB_GETUSERSHELL=0;     AC_SUBST([GNULIB_GETUSERSHELL])
-  GNULIB_LCHOWN=0;           AC_SUBST([GNULIB_LCHOWN])
-  GNULIB_LINK=0;             AC_SUBST([GNULIB_LINK])
-  GNULIB_LINKAT=0;           AC_SUBST([GNULIB_LINKAT])
-  GNULIB_LSEEK=0;            AC_SUBST([GNULIB_LSEEK])
-  GNULIB_PIPE=0;             AC_SUBST([GNULIB_PIPE])
-  GNULIB_PIPE2=0;            AC_SUBST([GNULIB_PIPE2])
-  GNULIB_PREAD=0;            AC_SUBST([GNULIB_PREAD])
-  GNULIB_PWRITE=0;           AC_SUBST([GNULIB_PWRITE])
-  GNULIB_READLINK=0;         AC_SUBST([GNULIB_READLINK])
-  GNULIB_READLINKAT=0;       AC_SUBST([GNULIB_READLINKAT])
-  GNULIB_RMDIR=0;            AC_SUBST([GNULIB_RMDIR])
-  GNULIB_SLEEP=0;            AC_SUBST([GNULIB_SLEEP])
-  GNULIB_SYMLINK=0;          AC_SUBST([GNULIB_SYMLINK])
-  GNULIB_SYMLINKAT=0;        AC_SUBST([GNULIB_SYMLINKAT])
-  GNULIB_TTYNAME_R=0;        AC_SUBST([GNULIB_TTYNAME_R])
-  GNULIB_UNISTD_H_GETOPT=0;  AC_SUBST([GNULIB_UNISTD_H_GETOPT])
-  GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE])
-  GNULIB_UNLINK=0;           AC_SUBST([GNULIB_UNLINK])
-  GNULIB_UNLINKAT=0;         AC_SUBST([GNULIB_UNLINKAT])
-  GNULIB_USLEEP=0;           AC_SUBST([GNULIB_USLEEP])
-  GNULIB_WRITE=0;            AC_SUBST([GNULIB_WRITE])
+  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])
+  GNULIB_EUIDACCESS=0;           AC_SUBST([GNULIB_EUIDACCESS])
+  GNULIB_FACCESSAT=0;            AC_SUBST([GNULIB_FACCESSAT])
+  GNULIB_FCHDIR=0;               AC_SUBST([GNULIB_FCHDIR])
+  GNULIB_FCHOWNAT=0;             AC_SUBST([GNULIB_FCHOWNAT])
+  GNULIB_FDATASYNC=0;            AC_SUBST([GNULIB_FDATASYNC])
+  GNULIB_FSYNC=0;                AC_SUBST([GNULIB_FSYNC])
+  GNULIB_FTRUNCATE=0;            AC_SUBST([GNULIB_FTRUNCATE])
+  GNULIB_GETCWD=0;               AC_SUBST([GNULIB_GETCWD])
+  GNULIB_GETDOMAINNAME=0;        AC_SUBST([GNULIB_GETDOMAINNAME])
+  GNULIB_GETDTABLESIZE=0;        AC_SUBST([GNULIB_GETDTABLESIZE])
+  GNULIB_GETGROUPS=0;            AC_SUBST([GNULIB_GETGROUPS])
+  GNULIB_GETHOSTNAME=0;          AC_SUBST([GNULIB_GETHOSTNAME])
+  GNULIB_GETLOGIN=0;             AC_SUBST([GNULIB_GETLOGIN])
+  GNULIB_GETLOGIN_R=0;           AC_SUBST([GNULIB_GETLOGIN_R])
+  GNULIB_GETPAGESIZE=0;          AC_SUBST([GNULIB_GETPAGESIZE])
+  GNULIB_GETUSERSHELL=0;         AC_SUBST([GNULIB_GETUSERSHELL])
+  GNULIB_GROUP_MEMBER=0;         AC_SUBST([GNULIB_GROUP_MEMBER])
+  GNULIB_LCHOWN=0;               AC_SUBST([GNULIB_LCHOWN])
+  GNULIB_LINK=0;                 AC_SUBST([GNULIB_LINK])
+  GNULIB_LINKAT=0;               AC_SUBST([GNULIB_LINKAT])
+  GNULIB_LSEEK=0;                AC_SUBST([GNULIB_LSEEK])
+  GNULIB_PIPE=0;                 AC_SUBST([GNULIB_PIPE])
+  GNULIB_PIPE2=0;                AC_SUBST([GNULIB_PIPE2])
+  GNULIB_PREAD=0;                AC_SUBST([GNULIB_PREAD])
+  GNULIB_PWRITE=0;               AC_SUBST([GNULIB_PWRITE])
+  GNULIB_READ=0;                 AC_SUBST([GNULIB_READ])
+  GNULIB_READLINK=0;             AC_SUBST([GNULIB_READLINK])
+  GNULIB_READLINKAT=0;           AC_SUBST([GNULIB_READLINKAT])
+  GNULIB_RMDIR=0;                AC_SUBST([GNULIB_RMDIR])
+  GNULIB_SLEEP=0;                AC_SUBST([GNULIB_SLEEP])
+  GNULIB_SYMLINK=0;              AC_SUBST([GNULIB_SYMLINK])
+  GNULIB_SYMLINKAT=0;            AC_SUBST([GNULIB_SYMLINKAT])
+  GNULIB_TTYNAME_R=0;            AC_SUBST([GNULIB_TTYNAME_R])
+  GNULIB_UNISTD_H_GETOPT=0;      AC_SUBST([GNULIB_UNISTD_H_GETOPT])
+  GNULIB_UNISTD_H_NONBLOCKING=0; AC_SUBST([GNULIB_UNISTD_H_NONBLOCKING])
+  GNULIB_UNISTD_H_SIGPIPE=0;     AC_SUBST([GNULIB_UNISTD_H_SIGPIPE])
+  GNULIB_UNLINK=0;               AC_SUBST([GNULIB_UNLINK])
+  GNULIB_UNLINKAT=0;             AC_SUBST([GNULIB_UNLINKAT])
+  GNULIB_USLEEP=0;               AC_SUBST([GNULIB_USLEEP])
+  GNULIB_WRITE=0;                AC_SUBST([GNULIB_WRITE])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_CHOWN=1;           AC_SUBST([HAVE_CHOWN])
   HAVE_DUP2=1;            AC_SUBST([HAVE_DUP2])
@@ -101,6 +113,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_FACCESSAT=1;       AC_SUBST([HAVE_FACCESSAT])
   HAVE_FCHDIR=1;          AC_SUBST([HAVE_FCHDIR])
   HAVE_FCHOWNAT=1;        AC_SUBST([HAVE_FCHOWNAT])
+  HAVE_FDATASYNC=1;       AC_SUBST([HAVE_FDATASYNC])
   HAVE_FSYNC=1;           AC_SUBST([HAVE_FSYNC])
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
   HAVE_GETDTABLESIZE=1;   AC_SUBST([HAVE_GETDTABLESIZE])
@@ -108,6 +121,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_GETHOSTNAME=1;     AC_SUBST([HAVE_GETHOSTNAME])
   HAVE_GETLOGIN=1;        AC_SUBST([HAVE_GETLOGIN])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
+  HAVE_GROUP_MEMBER=1;    AC_SUBST([HAVE_GROUP_MEMBER])
   HAVE_LCHOWN=1;          AC_SUBST([HAVE_LCHOWN])
   HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
   HAVE_LINKAT=1;          AC_SUBST([HAVE_LINKAT])
@@ -124,6 +138,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_USLEEP=1;          AC_SUBST([HAVE_USLEEP])
   HAVE_DECL_ENVIRON=1;    AC_SUBST([HAVE_DECL_ENVIRON])
   HAVE_DECL_FCHDIR=1;     AC_SUBST([HAVE_DECL_FCHDIR])
+  HAVE_DECL_FDATASYNC=1;  AC_SUBST([HAVE_DECL_FDATASYNC])
   HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME])
   HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
   HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
@@ -147,6 +162,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_LSEEK=0;        AC_SUBST([REPLACE_LSEEK])
   REPLACE_PREAD=0;        AC_SUBST([REPLACE_PREAD])
   REPLACE_PWRITE=0;       AC_SUBST([REPLACE_PWRITE])
+  REPLACE_READ=0;         AC_SUBST([REPLACE_READ])
   REPLACE_READLINK=0;     AC_SUBST([REPLACE_READLINK])
   REPLACE_RMDIR=0;        AC_SUBST([REPLACE_RMDIR])
   REPLACE_SLEEP=0;        AC_SUBST([REPLACE_SLEEP])
diff --git a/gl/m4/valgrind-tests.m4 b/gl/m4/valgrind-tests.m4
index 8f90dac..9c4d029 100644
--- a/gl/m4/valgrind-tests.m4
+++ b/gl/m4/valgrind-tests.m4
@@ -1,4 +1,4 @@
-# valgrind-tests.m4 serial 1
+# valgrind-tests.m4 serial 2
 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,
@@ -23,7 +23,7 @@ AC_DEFUN([gl_VALGRIND_TESTS],
 
   if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
     opt_valgrind_tests=yes
-    VALGRIND="$VALGRIND -q"
+    VALGRIND="$VALGRIND -q --error-exitcode=1 
--suppressions=suppressions.valgrind"
   else
     opt_valgrind_tests=no
     VALGRIND=
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 32ea985..749d708 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 32
+# vasnprintf.m4 serial 33
 dnl Copyright (C) 2002-2004, 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,
@@ -63,7 +63,7 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
   AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
   dnl Use the _snprintf function only if it is declared (because on NetBSD it
   dnl is defined as a weak alias of snprintf; we prefer to use the latter).
-  AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>])
+  AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
   dnl We can avoid a lot of code by assuming that snprintf's return value
   dnl conforms to ISO C99. So check that.
   AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
diff --git a/gl/m4/warn-on-use.m4 b/gl/m4/warn-on-use.m4
index e0d0f27..f09deef 100644
--- a/gl/m4/warn-on-use.m4
+++ b/gl/m4/warn-on-use.m4
@@ -1,4 +1,4 @@
-# warn-on-use.m4 serial 2
+# warn-on-use.m4 serial 4
 dnl Copyright (C) 2010-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,
@@ -27,6 +27,8 @@ AC_DEFUN([gl_WARN_ON_USE_PREPARE],
     [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
       [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
        undefining macros.])])dnl
+dnl FIXME: gl_Symbol must be used unquoted until we can assume
+dnl autoconf 2.64 or newer.
   for gl_func in m4_flatten([$2]); do
     AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
     AC_CACHE_CHECK([whether $gl_func is declared without a macro],
@@ -35,8 +37,8 @@ AC_DEFUN([gl_WARN_ON_USE_PREPARE],
 address@hidden:@undef $gl_func
   (void) $gl_func;])],
         [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])])
-     AS_VAR_IF(gl_Symbol, [yes],
-       [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
+    AS_VAR_IF(gl_Symbol, [yes],
+      [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
        dnl shortcut - if the raw declaration exists, then set a cache
        dnl variable to allow skipping any later AC_CHECK_DECL efforts
        eval ac_cv_have_decl_$gl_func=yes])
diff --git a/gl/m4/warnings.m4 b/gl/m4/warnings.m4
index a8f3466..a4a750a 100644
--- a/gl/m4/warnings.m4
+++ b/gl/m4/warnings.m4
@@ -1,4 +1,4 @@
-# warnings.m4 serial 2
+# warnings.m4 serial 5
 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,
@@ -19,18 +19,19 @@ m4_ifdef([AS_VAR_APPEND],
 # Adds parameter to WARN_CFLAGS if the compiler supports it.  For example,
 # gl_WARN_ADD([-Wparentheses]).
 AC_DEFUN([gl_WARN_ADD],
+dnl FIXME: gl_Warn must be used unquoted until we can assume
+dnl autoconf 2.64 or newer.
 [AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_$1])dnl
-AC_CACHE_CHECK([whether compiler handles $1], [gl_Warn], [
-  save_CPPFLAGS="$CPPFLAGS"
+AC_CACHE_CHECK([whether compiler handles $1], m4_defn([gl_Warn]), [
+  gl_save_CPPFLAGS="$CPPFLAGS"
   CPPFLAGS="${CPPFLAGS} $1"
   AC_PREPROC_IFELSE([AC_LANG_PROGRAM([])],
-                    [AS_VAR_SET([gl_Warn], [yes])],
-                    [AS_VAR_SET([gl_Warn], [no])])
-  CPPFLAGS="$save_CPPFLAGS"
+                    [AS_VAR_SET(gl_Warn, [yes])],
+                    [AS_VAR_SET(gl_Warn, [no])])
+  CPPFLAGS="$gl_save_CPPFLAGS"
 ])
-AS_VAR_PUSHDEF([gl_Flags], m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]))dnl
-AS_VAR_IF([gl_Warn], [yes], [gl_AS_VAR_APPEND([gl_Flags], [" $1"])])
-AS_VAR_POPDEF([gl_Flags])dnl
+AS_VAR_IF(gl_Warn, [yes],
+  [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])])
 AS_VAR_POPDEF([gl_Warn])dnl
 m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl
 ])
diff --git a/lib/gl/m4/wchar_h.m4 b/gl/m4/wchar_h.m4
similarity index 100%
copy from lib/gl/m4/wchar_h.m4
copy to gl/m4/wchar_h.m4
diff --git a/gl/m4/yield.m4 b/gl/m4/yield.m4
new file mode 100644
index 0000000..15d5ac2
--- /dev/null
+++ b/gl/m4/yield.m4
@@ -0,0 +1,19 @@
+# yield.m4 serial 2
+dnl Copyright (C) 2005-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_YIELD],
+[
+  AC_REQUIRE([gl_THREADLIB])
+  dnl On some systems, sched_yield is in librt, rather than in libpthread.
+  YIELD_LIB=
+  if test $gl_threads_api = posix; then
+    dnl Solaris has sched_yield in librt, not in libpthread or libc.
+    AC_CHECK_LIB([rt], [sched_yield], [YIELD_LIB=-lrt],
+      [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt.
+       AC_CHECK_LIB([posix4], [sched_yield], [YIELD_LIB=-lposix4])])
+  fi
+  AC_SUBST([YIELD_LIB])
+])
diff --git a/gl/malloc.c b/gl/malloc.c
index a325d61..da45618 100644
--- a/gl/malloc.c
+++ b/gl/malloc.c
@@ -18,6 +18,7 @@
 
 /* written by Jim Meyering and Bruno Haible */
 
+#define _GL_USE_STDLIB_ALLOC 1
 #include <config.h>
 /* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h.  */
 #ifdef malloc
@@ -28,14 +29,10 @@
 # define NEED_MALLOC_GNU 1
 #endif
 
-/* Specification.  */
 #include <stdlib.h>
 
 #include <errno.h>
 
-/* Call the system's malloc below.  */
-#undef malloc
-
 /* Allocate an N-byte block of memory from the heap.
    If N is zero, allocate a 1-byte block.  */
 
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/msvc-nothrow.c b/gl/msvc-nothrow.c
new file mode 100644
index 0000000..8965140
--- /dev/null
+++ b/gl/msvc-nothrow.c
@@ -0,0 +1,50 @@
+/* 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.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "msvc-nothrow.h"
+
+/* Get declarations of the Win32 API functions.  */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "msvc-inval.h"
+
+#undef _get_osfhandle
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+intptr_t
+_gl_nothrow_get_osfhandle (int fd)
+{
+  intptr_t result;
+
+  TRY_MSVC_INVAL
+    {
+      result = _get_osfhandle (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = (intptr_t) INVALID_HANDLE_VALUE;
+    }
+  DONE_MSVC_INVAL;
+
+  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/netdb.in.h b/gl/netdb.in.h
index 850d97b..69b6d5d 100644
--- a/gl/netdb.in.h
+++ b/gl/netdb.in.h
@@ -20,7 +20,7 @@
    It is intended to provide definitions and prototypes needed by an
    application.  */
 
-#ifndef _GL_NETDB_H
+#ifndef address@hidden@_NETDB_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -34,12 +34,15 @@
 
 #endif
 
-#ifndef _GL_NETDB_H
-#define _GL_NETDB_H
+#ifndef address@hidden@_NETDB_H
+#define address@hidden@_NETDB_H
 
-/* Get netdb.h definitions such as struct hostent for MinGW.  */
+/* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
+   'struct hostent' on MinGW.  */
 #include <sys/socket.h>
 
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
 /* The definition of _GL_ARG_NONNULL is copied here.  */
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
@@ -51,6 +54,10 @@
 
 # if address@hidden@
 
+#  ifdef __cplusplus
+extern "C" {
+#  endif
+
 #  if !GNULIB_defined_struct_addrinfo
 /* Structure to contain information about address of a service provider.  */
 struct addrinfo
@@ -66,6 +73,11 @@ struct addrinfo
 };
 #   define GNULIB_defined_struct_addrinfo 1
 #  endif
+
+#  ifdef __cplusplus
+}
+#  endif
+
 # endif
 
 /* Possible values for `ai_flags' field in `addrinfo' structure.  */
@@ -152,37 +164,67 @@ struct addrinfo
    socket addresses.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern int getaddrinfo (const char *restrict nodename,
-                        const char *restrict servname,
-                        const struct addrinfo *restrict hints,
-                        struct addrinfo **restrict res)
-     _GL_ARG_NONNULL ((4));
+_GL_FUNCDECL_SYS (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res)
+                  _GL_ARG_NONNULL ((4)));
 # endif
+_GL_CXXALIAS_SYS (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res));
+_GL_CXXALIASWARN (getaddrinfo);
 
 # if address@hidden@
 /* Free `addrinfo' structure AI including associated storage.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
+_GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
+                                      _GL_ARG_NONNULL ((1)));
 # endif
+_GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
+_GL_CXXALIASWARN (freeaddrinfo);
 
-# if address@hidden@
+# if @REPLACE_GAI_STRERROR@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gai_strerror
+#   define gai_strerror rpl_gai_strerror
+#  endif
+_GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode));
+_GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
+# else
+#  if address@hidden@
 /* Convert error return from getaddrinfo() to a string.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
-extern const char *gai_strerror (int ecode);
+_GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
+#  endif
+_GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
 # endif
+_GL_CXXALIASWARN (gai_strerror);
 
 # if address@hidden@
 /* Convert socket address to printable node and service names.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
-extern int getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
+_GL_FUNCDECL_SYS (getnameinfo, int,
+                  (const struct sockaddr *restrict sa, socklen_t salen,
+                   char *restrict node, socklen_t nodelen,
+                   char *restrict service, socklen_t servicelen,
+                   int flags)
+                  _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on glibc systems, the seventh parameter is
+                        unsigned int flags.  */
+_GL_CXXALIAS_SYS_CAST (getnameinfo, int,
+                       (const struct sockaddr *restrict sa, socklen_t salen,
                         char *restrict node, socklen_t nodelen,
                         char *restrict service, socklen_t servicelen,
-                        int flags)
-     _GL_ARG_NONNULL ((1));
-# endif
+                        int flags));
+_GL_CXXALIASWARN (getnameinfo);
 
 /* Possible flags for getnameinfo.  */
 # ifndef NI_NUMERICHOST
@@ -220,5 +262,5 @@ _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
 
 #endif
 
-#endif /* _GL_NETDB_H */
-#endif /* _GL_NETDB_H */
+#endif /* address@hidden@_NETDB_H */
+#endif /* address@hidden@_NETDB_H */
diff --git a/gl/netinet_in.in.h b/gl/netinet_in.in.h
index f5eea43..966d6a5 100644
--- a/gl/netinet_in.in.h
+++ b/gl/netinet_in.in.h
@@ -15,7 +15,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_NETINET_IN_H
+#ifndef address@hidden@_NETINET_IN_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -33,8 +33,8 @@
 
 #endif
 
-#ifndef _GL_NETINET_IN_H
-#define _GL_NETINET_IN_H
+#ifndef address@hidden@_NETINET_IN_H
+#define address@hidden@_NETINET_IN_H
 
 #if address@hidden@
 
@@ -44,5 +44,5 @@
 
 #endif
 
-#endif /* _GL_NETINET_IN_H */
-#endif /* _GL_NETINET_IN_H */
+#endif /* address@hidden@_NETINET_IN_H */
+#endif /* address@hidden@_NETINET_IN_H */
diff --git a/gl/override/m4/valgrind-tests.m4.diff 
b/gl/override/m4/valgrind-tests.m4.diff
new file mode 100644
index 0000000..dac9a24
--- /dev/null
+++ b/gl/override/m4/valgrind-tests.m4.diff
@@ -0,0 +1,11 @@
+--- valgrind-tests.m4.orig     2011-05-21 09:37:17.415555504 +0200
++++ valgrind-tests.m4  2011-05-21 09:37:34.600259721 +0200
+@@ -23,7 +23,7 @@
+ 
+   if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
+     opt_valgrind_tests=yes
+-    VALGRIND="$VALGRIND -q --error-exitcode=1 --leak-check=full"
++    VALGRIND="$VALGRIND -q --error-exitcode=1 
--suppressions=suppressions.valgrind"
+   else
+     opt_valgrind_tests=no
+     VALGRIND=
diff --git a/gl/override/tests/test-lseek.c.diff 
b/gl/override/tests/test-lseek.c.diff
deleted file mode 100644
index 1531b1d..0000000
--- a/gl/override/tests/test-lseek.c.diff
+++ /dev/null
@@ -1,15 +0,0 @@
---- gl/tests/test-lseek.c.orig 2008-12-10 16:49:14.000000000 +0100
-+++ gl/tests/test-lseek.c      2008-12-10 16:50:14.000000000 +0100
-@@ -85,9 +85,9 @@
- 
-     case '2': /* closed */
-       /* Explicitly close file descriptors 0 and 1.  The <&- and >&- in the
--         invoking shell are not enough on HP-UX.  */
--      close (0);
--      close (1);
-+         invoking shell are not enough on HP-UX.
-+      close (0);     calling close fails on mingw -- address@hidden
-+      close (1);  */
-       errno = 0;
-       ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
-       ASSERT (errno == EBADF);
diff --git a/gl/perror.c b/gl/perror.c
index 2c13a89..af4b56c 100644
--- a/gl/perror.c
+++ b/gl/perror.c
@@ -21,15 +21,29 @@
 #include <stdio.h>
 
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 
+#include "strerror-override.h"
+
+/* Use the system functions, not the gnulib overrides in this file.  */
+#undef fprintf
+
 void
 perror (const char *string)
 {
-  const char *errno_description = strerror (errno);
+  char stackbuf[STACKBUF_LEN];
+  int ret;
+
+  /* Our implementation guarantees that this will be a non-empty
+     string, even if it returns EINVAL; and stackbuf should be sized
+     large enough to avoid ERANGE.  */
+  ret = strerror_r (errno, stackbuf, sizeof stackbuf);
+  if (ret == ERANGE)
+    abort ();
 
   if (string != NULL && *string != '\0')
-    fprintf (stderr, "%s: %s\n", string, errno_description);
+    fprintf (stderr, "%s: %s\n", string, stackbuf);
   else
-    fprintf (stderr, "%s\n", errno_description);
+    fprintf (stderr, "%s\n", stackbuf);
 }
diff --git a/gl/realloc.c b/gl/realloc.c
index 6ef37e7..0c96ffa 100644
--- a/gl/realloc.c
+++ b/gl/realloc.c
@@ -18,6 +18,7 @@
 
 /* written by Jim Meyering and Bruno Haible */
 
+#define _GL_USE_STDLIB_ALLOC 1
 #include <config.h>
 
 /* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h.  */
@@ -34,23 +35,10 @@
 # define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
 #endif
 
-/* Below we want to call the system's malloc and realloc.
-   Undefine the symbols here so that including <stdlib.h> provides a
-   declaration of malloc(), not of rpl_malloc(), and likewise for realloc.  */
-#undef malloc
-#undef realloc
-
-/* Specification.  */
 #include <stdlib.h>
 
 #include <errno.h>
 
-/* Below we want to call the system's malloc and realloc.
-   Undefine the symbols, if they were defined by gnulib's <stdlib.h>
-   replacement.  */
-#undef malloc
-#undef realloc
-
 /* Change the size of an allocated block of memory P to N bytes,
    with error checking.  If N is zero, change it to 1.  If P is NULL,
    use malloc.  */
diff --git a/gl/recv.c b/gl/recv.c
index d99b7a4..4755f63 100644
--- a/gl/recv.c
+++ b/gl/recv.c
@@ -32,9 +32,18 @@ ssize_t
 rpl_recv (int fd, void *buf, size_t len, int flags)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = recv (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
 
-  return r;
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = recv (sock, buf, len, flags);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
 }
diff --git a/gl/select.c b/gl/select.c
index e4fb445..236b951 100644
--- a/gl/select.c
+++ b/gl/select.c
@@ -27,7 +27,6 @@
 /* Native Win32.  */
 
 #include <sys/types.h>
-#include <stdbool.h>
 #include <errno.h>
 #include <limits.h>
 
@@ -38,6 +37,8 @@
 #include <conio.h>
 #include <time.h>
 
+#include "msvc-nothrow.h"
+
 struct bitset {
   unsigned char in[FD_SETSIZE / CHAR_BIT];
   unsigned char out[FD_SETSIZE / CHAR_BIT];
diff --git a/gl/send.c b/gl/send.c
index d8a876e..cd21482 100644
--- a/gl/send.c
+++ b/gl/send.c
@@ -32,9 +32,18 @@ ssize_t
 rpl_send (int fd, const void *buf, size_t len, int flags)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = send (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
 
-  return r;
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = send (sock, buf, len, flags);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
 }
diff --git a/gl/setsockopt.c b/gl/setsockopt.c
index a31a10e..6a7ca5e 100644
--- a/gl/setsockopt.c
+++ b/gl/setsockopt.c
@@ -34,23 +34,32 @@
 int
 rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t 
optlen)
 {
-  int r;
   SOCKET sock = FD_TO_SOCKET (fd);
+  int r;
 
-  if (level == SOL_SOCKET && (optname == SO_RCVTIMEO || optname == 
SO_SNDTIMEO))
+  if (sock == INVALID_SOCKET)
     {
-      const struct timeval *tv = optval;
-      int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
-      optval = &milliseconds;
-      r = setsockopt (sock, level, optname, optval, sizeof (int));
+      errno = EBADF;
+      return -1;
     }
   else
     {
-      r = setsockopt (sock, level, optname, optval, optlen);
-    }
+      if (level == SOL_SOCKET
+          && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
+        {
+          const struct timeval *tv = optval;
+          int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
+          optval = &milliseconds;
+          r = setsockopt (sock, level, optname, optval, sizeof (int));
+        }
+      else
+        {
+          r = setsockopt (sock, level, optname, optval, optlen);
+        }
 
-  if (r < 0)
-    set_winsock_errno ();
+      if (r < 0)
+        set_winsock_errno ();
 
-  return r;
+      return r;
+    }
 }
diff --git a/gl/shutdown.c b/gl/shutdown.c
index 26c4932..1c302a2 100644
--- a/gl/shutdown.c
+++ b/gl/shutdown.c
@@ -32,9 +32,18 @@ int
 rpl_shutdown (int fd, int how)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r = shutdown (sock, how);
-  if (r < 0)
-    set_winsock_errno ();
 
-  return r;
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = shutdown (sock, how);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
 }
diff --git a/gl/signal.in.h b/gl/signal.in.h
new file mode 100644
index 0000000..e18e0b2
--- /dev/null
+++ b/gl/signal.in.h
@@ -0,0 +1,447 @@
+/* A GNU-like <signal.h>.
+
+   Copyright (C) 2006-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 __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#if defined __need_sig_atomic_t || defined __need_sigset_t || defined 
_GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined 
__SIZEOF_PTHREAD_MUTEX_T)
+/* Special invocation convention:
+   - Inside glibc header files.
+   - On glibc systems we have a sequence of nested includes
+     <signal.h> -> <ucontext.h> -> <signal.h>.
+     In this situation, the functions are not yet declared, therefore we cannot
+     provide the C++ aliases.
+   - On glibc systems with GCC 4.3 we have a sequence of nested includes
+     <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
+     In this situation, some of the functions are not yet declared, therefore
+     we cannot provide the C++ aliases.  */
+
+# @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef address@hidden@_SIGNAL_H
+
+#define _GL_ALREADY_INCLUDING_SIGNAL_H
+
+/* Define pid_t, uid_t.
+   Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
+   On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
+   us; so include <sys/types.h> now, before the second inclusion guard.  */
+#include <sys/types.h>
+
+/* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_SIGNAL_H@
+
+#undef _GL_ALREADY_INCLUDING_SIGNAL_H
+
+#ifndef address@hidden@_SIGNAL_H
+#define address@hidden@_SIGNAL_H
+
+/* MacOS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare
+   pthread_sigmask in <pthread.h>, not in <signal.h>.
+   But avoid namespace pollution on glibc systems.*/
+#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
+    && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || 
defined __OpenBSD__ || defined __osf__ || defined __sun) \
+    && ! defined __GLIBC__
+# include <pthread.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+/* On AIX, sig_atomic_t already includes volatile.  C99 requires that
+   'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
+   Hence, redefine this to a non-volatile type as needed.  */
+#if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
+# if !GNULIB_defined_sig_atomic_t
+typedef int rpl_sig_atomic_t;
+#  undef sig_atomic_t
+#  define sig_atomic_t rpl_sig_atomic_t
+#  define GNULIB_defined_sig_atomic_t 1
+# endif
+#endif
+
+/* A set or mask of signals.  */
+#if address@hidden@
+# if !GNULIB_defined_sigset_t
+typedef unsigned int sigset_t;
+#  define GNULIB_defined_sigset_t 1
+# endif
+#endif
+
+/* Define sighandler_t, the type of signal handlers.  A GNU extension.  */
+#if address@hidden@
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_sighandler_t
+typedef void (*sighandler_t) (int);
+#  define GNULIB_defined_sighandler_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+#endif
+
+
+#if @GNULIB_SIGNAL_H_SIGPIPE@
+# ifndef SIGPIPE
+/* Define SIGPIPE to a value that does not overlap with other signals.  */
+#  define SIGPIPE 13
+#  define GNULIB_defined_SIGPIPE 1
+/* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
+   'write', 'stdio'.  */
+# endif
+#endif
+
+
+/* Maximum signal number + 1.  */
+#ifndef NSIG
+# if defined __TANDEM
+#  define NSIG 32
+# endif
+#endif
+
+
+#if @GNULIB_PTHREAD_SIGMASK@
+# if @REPLACE_PTHREAD_SIGMASK@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pthread_sigmask
+#   define pthread_sigmask rpl_pthread_sigmask
+#  endif
+_GL_FUNCDECL_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+_GL_CXXALIAS_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+#  endif
+_GL_CXXALIAS_SYS (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# endif
+_GL_CXXALIASWARN (pthread_sigmask);
+#elif defined GNULIB_POSIXCHECK
+# undef pthread_sigmask
+# if HAVE_RAW_DECL_PTHREAD_SIGMASK
+_GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
+                 "use gnulib module pthread_sigmask for portability");
+# endif
+#endif
+
+
+#if @GNULIB_RAISE@
+# if @REPLACE_RAISE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef raise
+#   define raise rpl_raise
+#  endif
+_GL_FUNCDECL_RPL (raise, int, (int sig));
+_GL_CXXALIAS_RPL (raise, int, (int sig));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (raise, int, (int sig));
+#  endif
+_GL_CXXALIAS_SYS (raise, int, (int sig));
+# endif
+_GL_CXXALIASWARN (raise);
+#elif defined GNULIB_POSIXCHECK
+# undef raise
+/* Assume raise is always declared.  */
+_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
+                 "use gnulib module raise for portability");
+#endif
+
+
+#if @GNULIB_SIGPROCMASK@
+# if address@hidden@
+
+#  ifndef GNULIB_defined_signal_blocking
+#   define GNULIB_defined_signal_blocking 1
+#  endif
+
+/* Maximum signal number + 1.  */
+#  ifndef NSIG
+#   define NSIG 32
+#  endif
+
+/* This code supports only 32 signals.  */
+#  if !GNULIB_defined_verify_NSIG_constraint
+typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
+#   define GNULIB_defined_verify_NSIG_constraint 1
+#  endif
+
+# endif
+
+/* Test whether a given signal is contained in a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigismember
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
+                                    _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigismember);
+
+/* Initialize a signal set to the empty set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigemptyset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigemptyset);
+
+/* Add a signal to a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigaddset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
+                                  _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigaddset);
+
+/* Remove a signal from a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigdelset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
+                                  _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigdelset);
+
+/* Fill a signal set with all possible signals.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigfillset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigfillset);
+
+/* Return the set of those blocked signals that are pending.  */
+# if address@hidden@
+_GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigpending);
+
+/* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
+   Then, if SET is not NULL, affect the current set of blocked signals by
+   combining it with *SET as indicated in OPERATION.
+   In this implementation, you are not allowed to change a signal handler
+   while the signal is blocked.  */
+# if address@hidden@
+#  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
+#  define SIG_SETMASK 1  /* blocked_set = *set; */
+#  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
+_GL_FUNCDECL_SYS (sigprocmask, int,
+                  (int operation, const sigset_t *set, sigset_t *old_set));
+# endif
+_GL_CXXALIAS_SYS (sigprocmask, int,
+                  (int operation, const sigset_t *set, sigset_t *old_set));
+_GL_CXXALIASWARN (sigprocmask);
+
+/* Install the handler FUNC for signal SIG, and return the previous
+   handler.  */
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_function_taking_int_returning_void_t
+typedef void (*_gl_function_taking_int_returning_void_t) (int);
+#  define GNULIB_defined_function_taking_int_returning_void_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+# if address@hidden@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define signal rpl_signal
+#  endif
+_GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+_GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+# else
+_GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+# endif
+_GL_CXXALIASWARN (signal);
+
+# if address@hidden@ && GNULIB_defined_SIGPIPE
+/* Raise signal SIGPIPE.  */
+_GL_EXTERN_C int _gl_raise_SIGPIPE (void);
+# endif
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaddset
+# if HAVE_RAW_DECL_SIGADDSET
+_GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigdelset
+# if HAVE_RAW_DECL_SIGDELSET
+_GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigemptyset
+# if HAVE_RAW_DECL_SIGEMPTYSET
+_GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigfillset
+# if HAVE_RAW_DECL_SIGFILLSET
+_GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigismember
+# if HAVE_RAW_DECL_SIGISMEMBER
+_GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigpending
+# if HAVE_RAW_DECL_SIGPENDING
+_GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigprocmask
+# if HAVE_RAW_DECL_SIGPROCMASK
+_GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+#endif /* @GNULIB_SIGPROCMASK@ */
+
+
+#if @GNULIB_SIGACTION@
+# if address@hidden@
+
+#  if address@hidden@
+
+#   if !GNULIB_defined_siginfo_types
+
+/* Present to allow compilation, but unsupported by gnulib.  */
+union sigval
+{
+  int sival_int;
+  void *sival_ptr;
+};
+
+/* Present to allow compilation, but unsupported by gnulib.  */
+struct siginfo_t
+{
+  int si_signo;
+  int si_code;
+  int si_errno;
+  pid_t si_pid;
+  uid_t si_uid;
+  void *si_addr;
+  int si_status;
+  long si_band;
+  union sigval si_value;
+};
+typedef struct siginfo_t siginfo_t;
+
+#    define GNULIB_defined_siginfo_types 1
+#   endif
+
+#  endif /* address@hidden@ */
+
+/* We assume that platforms which lack the sigaction() function also lack
+   the 'struct sigaction' type, and vice versa.  */
+
+#  if !GNULIB_defined_struct_sigaction
+
+struct sigaction
+{
+  union
+  {
+    void (*_sa_handler) (int);
+    /* Present to allow compilation, but unsupported by gnulib.  POSIX
+       says that implementations may, but not must, make sa_sigaction
+       overlap with sa_handler, but we know of no implementation where
+       they do not overlap.  */
+    void (*_sa_sigaction) (int, siginfo_t *, void *);
+  } _sa_func;
+  sigset_t sa_mask;
+  /* Not all POSIX flags are supported.  */
+  int sa_flags;
+};
+#   define sa_handler _sa_func._sa_handler
+#   define sa_sigaction _sa_func._sa_sigaction
+/* Unsupported flags are not present.  */
+#   define SA_RESETHAND 1
+#   define SA_NODEFER 2
+#   define SA_RESTART 4
+
+#   define GNULIB_defined_struct_sigaction 1
+#  endif
+
+_GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
+                                   struct sigaction *restrict));
+
+# elif address@hidden@
+
+#  define sa_sigaction sa_handler
+
+# endif /* address@hidden@, address@hidden@ */
+
+_GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
+                                   struct sigaction *restrict));
+_GL_CXXALIASWARN (sigaction);
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaction
+# if HAVE_RAW_DECL_SIGACTION
+_GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
+                 "use the gnulib module sigaction for portability");
+# endif
+#endif
+
+/* Some systems don't have SA_NODEFER.  */
+#ifndef SA_NODEFER
+# define SA_NODEFER 0
+#endif
+
+
+#endif /* address@hidden@_SIGNAL_H */
+#endif /* address@hidden@_SIGNAL_H */
+#endif
diff --git a/gl/sockets.c b/gl/sockets.c
index 4e905e1..39939b0 100644
--- a/gl/sockets.c
+++ b/gl/sockets.c
@@ -27,14 +27,21 @@
 /* This includes winsock2.h on MinGW. */
 # include <sys/socket.h>
 
-# include "close-hook.h"
+# include "fd-hook.h"
+# include "msvc-nothrow.h"
 
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
 # include "w32sock.h"
 
 static int
-close_fd_maybe_socket (int fd, const struct close_hook *remaining_list)
+close_fd_maybe_socket (const struct fd_hook *remaining_list,
+                       gl_close_fn primary,
+                       int fd)
 {
+  /* Note about multithread-safety: There is a race condition where, between
+     our calls to closesocket() and the primary close(), some other thread
+     could make system calls that allocate precisely the same HANDLE value
+     as sock; then the primary close() would call CloseHandle() on it.  */
   SOCKET sock;
   WSANETWORKEVENTS ev;
 
@@ -64,10 +71,38 @@ close_fd_maybe_socket (int fd, const struct close_hook 
*remaining_list)
     }
   else
     /* Some other type of file descriptor.  */
-    return execute_close_hooks (fd, remaining_list);
+    return execute_close_hooks (remaining_list, primary, fd);
 }
 
-static struct close_hook close_sockets_hook;
+static int
+ioctl_fd_maybe_socket (const struct fd_hook *remaining_list,
+                       gl_ioctl_fn primary,
+                       int fd, int request, void *arg)
+{
+  SOCKET sock;
+  WSANETWORKEVENTS ev;
+
+  /* Test whether fd refers to a socket.  */
+  sock = FD_TO_SOCKET (fd);
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* fd refers to a socket.  */
+      if (ioctlsocket (sock, request, arg) < 0)
+        {
+          set_winsock_errno ();
+          return -1;
+        }
+      else
+        return 0;
+    }
+  else
+    /* Some other type of file descriptor.  */
+    return execute_ioctl_hooks (remaining_list, primary, fd, request, arg);
+}
+
+static struct fd_hook fd_sockets_hook;
 
 static int initialized_sockets_version /* = 0 */;
 
@@ -90,7 +125,8 @@ gl_sockets_startup (int version _GL_UNUSED)
         return 2;
 
       if (initialized_sockets_version == 0)
-        register_close_hook (close_fd_maybe_socket, &close_sockets_hook);
+        register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket,
+                          &fd_sockets_hook);
 
       initialized_sockets_version = version;
     }
@@ -107,7 +143,7 @@ gl_sockets_cleanup (void)
 
   initialized_sockets_version = 0;
 
-  unregister_close_hook (&close_sockets_hook);
+  unregister_fd_hook (&fd_sockets_hook);
 
   err = WSACleanup ();
   if (err != 0)
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/stdarg.in.h b/gl/stdarg.in.h
index 4469d54..43f9607 100644
--- a/gl/stdarg.in.h
+++ b/gl/stdarg.in.h
@@ -15,7 +15,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_STDARG_H
+#ifndef address@hidden@_STDARG_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -25,12 +25,12 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_STDARG_H@
 
-#ifndef _GL_STDARG_H
-#define _GL_STDARG_H
+#ifndef address@hidden@_STDARG_H
+#define address@hidden@_STDARG_H
 
 #ifndef va_copy
 # define va_copy(a,b) ((a) = (b))
 #endif
 
-#endif /* _GL_STDARG_H */
-#endif /* _GL_STDARG_H */
+#endif /* address@hidden@_STDARG_H */
+#endif /* address@hidden@_STDARG_H */
diff --git a/gl/stddef.in.h b/gl/stddef.in.h
index 62a91a7..c7b98e7 100644
--- a/gl/stddef.in.h
+++ b/gl/stddef.in.h
@@ -38,9 +38,9 @@
    remember if special invocation has ever been used to obtain wint_t,
    in which case we need to clean up NULL yet again.  */
 
-# if !(defined _GL_STDDEF_H && defined _GL_STDDEF_WINT_T)
+# if !(defined address@hidden@_STDDEF_H && defined _GL_STDDEF_WINT_T)
 #  ifdef __need_wint_t
-#   undef _GL_STDDEF_H
+#   undef address@hidden@_STDDEF_H
 #   define _GL_STDDEF_WINT_T
 #  endif
 #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
@@ -49,14 +49,14 @@
 #else
 /* Normal invocation convention.  */
 
-# ifndef _GL_STDDEF_H
+# ifndef address@hidden@_STDDEF_H
 
 /* The include_next requires a split double-inclusion guard.  */
 
 #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
 
-#  ifndef _GL_STDDEF_H
-#   define _GL_STDDEF_H
+#  ifndef address@hidden@_STDDEF_H
+#   define address@hidden@_STDDEF_H
 
 /* On NetBSD 5.0, the definition of NULL lacks proper parentheses.  */
 #if @REPLACE_NULL@
@@ -82,6 +82,6 @@
 # define wchar_t int
 #endif
 
-#  endif /* _GL_STDDEF_H */
-# endif /* _GL_STDDEF_H */
+#  endif /* address@hidden@_STDDEF_H */
+# endif /* address@hidden@_STDDEF_H */
 #endif /* __need_XXX */
diff --git a/gl/stdint.in.h b/gl/stdint.in.h
index b32227b..b6d08c7 100644
--- a/gl/stdint.in.h
+++ b/gl/stdint.in.h
@@ -21,7 +21,7 @@
  * <http://www.opengroup.org/susv3xbd/stdint.h.html>
  */
 
-#ifndef _GL_STDINT_H
+#ifndef address@hidden@_STDINT_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -52,13 +52,13 @@
   /* Other systems may have an incomplete or buggy <stdint.h>.
      Include it before <inttypes.h>, since any "#include <stdint.h>"
      in <inttypes.h> would reinclude us, skipping our contents because
-     _GL_STDINT_H is defined.
+     address@hidden@_STDINT_H is defined.
      The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_STDINT_H@
 #endif
 
-#if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
-#define _GL_STDINT_H
+#if ! defined address@hidden@_STDINT_H && ! defined 
_GL_JUST_INCLUDE_SYSTEM_STDINT_H
+#define address@hidden@_STDINT_H
 
 /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
    IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
@@ -93,7 +93,7 @@
 
 #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
 
-/* Minimum and maximum values for a integer type under the usual assumption.
+/* Minimum and maximum values for an integer type under the usual assumption.
    Return an unspecified value if BITS == 0, adding a check to pacify
    picky compilers.  */
 
@@ -270,26 +270,36 @@ typedef unsigned long int gl_uintptr_t;
 /* Note: These types are compiler dependent. It may be unwise to use them in
    public header files. */
 
-#undef intmax_t
-#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
+/* If the system defines INTMAX_MAX, assume that intmax_t works, and
+   similarly for UINTMAX_MAX and uintmax_t.  This avoids problems with
+   assuming one type where another is used by the system.  */
+
+#ifndef INTMAX_MAX
+# undef INTMAX_C
+# undef intmax_t
+# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
 typedef long long int gl_intmax_t;
-# define intmax_t gl_intmax_t
-#elif defined GL_INT64_T
-# define intmax_t int64_t
-#else
+#  define intmax_t gl_intmax_t
+# elif defined GL_INT64_T
+#  define intmax_t int64_t
+# else
 typedef long int gl_intmax_t;
-# define intmax_t gl_intmax_t
+#  define intmax_t gl_intmax_t
+# endif
 #endif
 
-#undef uintmax_t
-#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
+#ifndef UINTMAX_MAX
+# undef UINTMAX_C
+# undef uintmax_t
+# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
 typedef unsigned long long int gl_uintmax_t;
-# define uintmax_t gl_uintmax_t
-#elif defined GL_UINT64_T
-# define uintmax_t uint64_t
-#else
+#  define uintmax_t gl_uintmax_t
+# elif defined GL_UINT64_T
+#  define uintmax_t uint64_t
+# else
 typedef unsigned long int gl_uintmax_t;
-# define uintmax_t gl_uintmax_t
+#  define uintmax_t gl_uintmax_t
+# endif
 #endif
 
 /* Verify that intmax_t and uintmax_t have the same size.  Too much code
@@ -431,21 +441,23 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == 
sizeof (uintmax_t)
 
 /* 7.18.2.5. Limits of greatest-width integer types */
 
-#undef INTMAX_MIN
-#undef INTMAX_MAX
-#ifdef INT64_MAX
-# define INTMAX_MIN  INT64_MIN
-# define INTMAX_MAX  INT64_MAX
-#else
-# define INTMAX_MIN  INT32_MIN
-# define INTMAX_MAX  INT32_MAX
+#ifndef INTMAX_MAX
+# undef INTMAX_MIN
+# ifdef INT64_MAX
+#  define INTMAX_MIN  INT64_MIN
+#  define INTMAX_MAX  INT64_MAX
+# else
+#  define INTMAX_MIN  INT32_MIN
+#  define INTMAX_MAX  INT32_MAX
+# endif
 #endif
 
-#undef UINTMAX_MAX
-#ifdef UINT64_MAX
-# define UINTMAX_MAX  UINT64_MAX
-#else
-# define UINTMAX_MAX  UINT32_MAX
+#ifndef UINTMAX_MAX
+# ifdef UINT64_MAX
+#  define UINTMAX_MAX  UINT64_MAX
+# else
+#  define UINTMAX_MAX  UINT32_MAX
+# endif
 #endif
 
 /* 7.18.3. Limits of other integer types */
@@ -568,25 +580,27 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == 
sizeof (uintmax_t)
 
 /* 7.18.4.2. Macros for greatest-width integer constants */
 
-#undef INTMAX_C
-#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
-# define INTMAX_C(x)   x##LL
-#elif defined GL_INT64_T
-# define INTMAX_C(x)   INT64_C(x)
-#else
-# define INTMAX_C(x)   x##L
+#ifndef INTMAX_C
+# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
+#  define INTMAX_C(x)   x##LL
+# elif defined GL_INT64_T
+#  define INTMAX_C(x)   INT64_C(x)
+# else
+#  define INTMAX_C(x)   x##L
+# endif
 #endif
 
-#undef UINTMAX_C
-#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
-# define UINTMAX_C(x)  x##ULL
-#elif defined GL_UINT64_T
-# define UINTMAX_C(x)  UINT64_C(x)
-#else
-# define UINTMAX_C(x)  x##UL
+#ifndef UINTMAX_C
+# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
+#  define UINTMAX_C(x)  x##ULL
+# elif defined GL_UINT64_T
+#  define UINTMAX_C(x)  UINT64_C(x)
+# else
+#  define UINTMAX_C(x)  x##UL
+# endif
 #endif
 
 #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
 
-#endif /* _GL_STDINT_H */
-#endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
+#endif /* address@hidden@_STDINT_H */
+#endif /* !defined address@hidden@_STDINT_H && !defined 
_GL_JUST_INCLUDE_SYSTEM_STDINT_H */
diff --git a/gl/stdio-write.c b/gl/stdio-write.c
deleted file mode 100644
index 10fcfba..0000000
--- a/gl/stdio-write.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* POSIX compatible FILE stream write function.
-   Copyright (C) 2008-2011 Free Software Foundation, Inc.
-   Written by Bruno Haible <address@hidden>, 2008.
-
-   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/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include <stdio.h>
-
-/* Replace these functions only if module 'sigpipe' is requested.  */
-#if GNULIB_SIGPIPE
-
-/* On native Windows platforms, SIGPIPE does not exist.  When write() is
-   called on a pipe with no readers, WriteFile() fails with error
-   GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
-   error EINVAL.  This write() function is at the basis of the function
-   which flushes the buffer of a FILE stream.  */
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-#  include <errno.h>
-#  include <signal.h>
-#  include <io.h>
-
-#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
-#  include <windows.h>
-
-#  define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
-  if (ferror (stream))                                                        \
-    return (EXPRESSION);                                                      \
-  else                                                                        \
-    {                                                                         \
-      RETTYPE ret;                                                            \
-      SetLastError (0);                                                       \
-      ret = (EXPRESSION);                                                     \
-      if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream))      \
-        {                                                                     \
-          int fd = fileno (stream);                                           \
-          if (fd >= 0                                                         \
-              && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
-            {                                                                 \
-              /* Try to raise signal SIGPIPE.  */                             \
-              raise (SIGPIPE);                                                \
-              /* If it is currently blocked or ignored, change errno from     \
-                 EINVAL to EPIPE.  */                                         \
-              errno = EPIPE;                                                  \
-            }                                                                 \
-        }                                                                     \
-      return ret;                                                             \
-    }
-
-#  if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
-int
-printf (const char *format, ...)
-{
-  int retval;
-  va_list args;
-
-  va_start (args, format);
-  retval = vfprintf (stdout, format, args);
-  va_end (args);
-
-  return retval;
-}
-#  endif
-
-#  if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
-int
-fprintf (FILE *stream, const char *format, ...)
-{
-  int retval;
-  va_list args;
-
-  va_start (args, format);
-  retval = vfprintf (stream, format, args);
-  va_end (args);
-
-  return retval;
-}
-#  endif
-
-#  if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
-int
-vprintf (const char *format, va_list args)
-{
-  return vfprintf (stdout, format, args);
-}
-#  endif
-
-#  if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
-int
-vfprintf (FILE *stream, const char *format, va_list args)
-#undef vfprintf
-{
-  CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == 
EOF)
-}
-#  endif
-
-int
-putchar (int c)
-{
-  return fputc (c, stdout);
-}
-
-int
-fputc (int c, FILE *stream)
-#undef fputc
-{
-  CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
-}
-
-int
-fputs (const char *string, FILE *stream)
-#undef fputs
-{
-  CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
-}
-
-int
-puts (const char *string)
-#undef puts
-{
-  FILE *stream = stdout;
-  CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
-}
-
-size_t
-fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
-#undef fwrite
-{
-  CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
-}
-
-# endif
-#endif
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index b7f3b6f..ce00af5 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -35,7 +35,7 @@
 #else
 /* Normal invocation convention.  */
 
-#ifndef _GL_STDIO_H
+#ifndef address@hidden@_STDIO_H
 
 #define _GL_ALREADY_INCLUDING_STDIO_H
 
@@ -44,8 +44,8 @@
 
 #undef _GL_ALREADY_INCLUDING_STDIO_H
 
-#ifndef _GL_STDIO_H
-#define _GL_STDIO_H
+#ifndef address@hidden@_STDIO_H
+#define address@hidden@_STDIO_H
 
 /* Get va_list.  Needed on many systems, including glibc 2.8.  */
 #include <stdarg.h>
@@ -67,9 +67,45 @@
 #else
 # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
-#define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+
+/* _GL_ATTRIBUTE_FORMAT_PRINTF
+   indicates to GCC that the function takes a format string and arguments,
+   where the format string directives are the ones standardized by ISO C99
+   and POSIX.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, 
first_argument))
+#else
+# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
+#endif
+
+/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF,
+   except that it indicates to GCC that the supported format string directives
+   are the ones of the system printf(), rather than the ones standardized by
+   ISO C99 and POSIX.  */
+#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, 
first_argument) \
   _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
 
+/* _GL_ATTRIBUTE_FORMAT_SCANF
+   indicates to GCC that the function takes a format string and arguments,
+   where the format string directives are the ones standardized by ISO C99
+   and POSIX.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, 
first_argument))
+#else
+# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
+#endif
+
+/* _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_SCANF,
+   except that it indicates to GCC that the supported format string directives
+   are the ones of the system scanf(), rather than the ones standardized by
+   ISO C99 and POSIX.  */
+#define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, 
first_argument) \
+  _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
+
 /* Solaris 10 declares renameat in <unistd.h>, not in <stdio.h>.  */
 /* But in any case avoid namespace pollution on glibc systems.  */
 #if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __sun \
@@ -134,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.
@@ -158,11 +214,34 @@ _GL_WARN_ON_USE (fflush, "fflush is not always POSIX 
compliant - "
                  "use gnulib module fflush for portable POSIX compliance");
 #endif
 
-/* It is very rare that the developer ever has full control of stdin,
-   so any use of gets warrants an unconditional warning.  Assume it is
-   always declared, since it is required by C89.  */
-#undef gets
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#if @GNULIB_FGETC@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fgetc
+#   define fgetc rpl_fgetc
+#  endif
+_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (fgetc, int, (FILE *stream));
+# else
+_GL_CXXALIAS_SYS (fgetc, int, (FILE *stream));
+# endif
+_GL_CXXALIASWARN (fgetc);
+#endif
+
+#if @GNULIB_FGETS@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fgets
+#   define fgets rpl_fgets
+#  endif
+_GL_FUNCDECL_RPL (fgets, char *, (char *s, int n, FILE *stream)
+                                 _GL_ARG_NONNULL ((1, 3)));
+_GL_CXXALIAS_RPL (fgets, char *, (char *s, int n, FILE *stream));
+# else
+_GL_CXXALIAS_SYS (fgets, char *, (char *s, int n, FILE *stream));
+# endif
+_GL_CXXALIASWARN (fgets);
+#endif
 
 #if @GNULIB_FOPEN@
 # if @REPLACE_FOPEN@
@@ -186,14 +265,20 @@ _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not 
POSIX compatible - "
 
 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
-     || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
@GNULIB_STDIO_H_SIGPIPE@)
+     || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
(@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define fprintf rpl_fprintf
 #  endif
 #  define GNULIB_overrides_fprintf 1
+#  if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
                                 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3)
                                 _GL_ARG_NONNULL ((1, 2)));
+#  else
+_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
+                                _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3)
+                                _GL_ARG_NONNULL ((1, 2)));
+#  endif
 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
 # else
 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
@@ -239,7 +324,7 @@ _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
 #endif
 
 #if @GNULIB_FPUTC@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef fputc
 #   define fputc rpl_fputc
@@ -253,7 +338,7 @@ _GL_CXXALIASWARN (fputc);
 #endif
 
 #if @GNULIB_FPUTS@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef fputs
 #   define fputs rpl_fputs
@@ -267,6 +352,21 @@ _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE 
*stream));
 _GL_CXXALIASWARN (fputs);
 #endif
 
+#if @GNULIB_FREAD@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fread
+#   define fread rpl_fread
+#  endif
+_GL_FUNCDECL_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)
+                                 _GL_ARG_NONNULL ((4)));
+_GL_CXXALIAS_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE 
*stream));
+# else
+_GL_CXXALIAS_SYS (fread, size_t, (void *ptr, size_t s, size_t n, FILE 
*stream));
+# endif
+_GL_CXXALIASWARN (fread);
+#endif
+
 #if @GNULIB_FREOPEN@
 # if @REPLACE_FREOPEN@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -291,6 +391,22 @@ _GL_WARN_ON_USE (freopen,
                  "use gnulib module freopen for portability");
 #endif
 
+#if @GNULIB_FSCANF@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fscanf
+#   define fscanf rpl_fscanf
+#  endif
+_GL_FUNCDECL_RPL (fscanf, int, (FILE *stream, const char *format, ...)
+                               _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3)
+                               _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (fscanf, int, (FILE *stream, const char *format, ...));
+# else
+_GL_CXXALIAS_SYS (fscanf, int, (FILE *stream, const char *format, ...));
+# endif
+_GL_CXXALIASWARN (fscanf);
+#endif
+
 
 /* Set up the following warnings, based on which modules are in use.
    GNU Coding Standards discourage the use of fseek, since it imposes
@@ -365,25 +481,6 @@ _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, 
int whence)
 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
 # endif
 _GL_CXXALIASWARN (fseeko);
-# if (@REPLACE_FSEEKO@ || address@hidden@) && address@hidden@
-   /* Provide an fseek function that is consistent with fseeko.  */
-   /* In order to avoid that fseek gets defined as a macro here, the
-      developer can request the 'fseek' module.  */
-#  if !GNULIB_defined_fseek_function
-#   undef fseek
-#   define fseek rpl_fseek
-static inline int _GL_ARG_NONNULL ((1))
-rpl_fseek (FILE *fp, long offset, int whence)
-{
-#   if @REPLACE_FSEEKO@
-  return rpl_fseeko (fp, offset, whence);
-#   else
-  return fseeko (fp, offset, whence);
-#   endif
-}
-#   define GNULIB_defined_fseek_function 1
-#  endif
-# endif
 #elif defined GNULIB_POSIXCHECK
 # define _GL_FSEEK_WARN /* Category 1, above.  */
 # undef fseek
@@ -443,25 +540,6 @@ _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) 
_GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
 # endif
 _GL_CXXALIASWARN (ftello);
-# if (@REPLACE_FTELLO@ || address@hidden@) && address@hidden@
-   /* Provide an ftell function that is consistent with ftello.  */
-   /* In order to avoid that ftell gets defined as a macro here, the
-      developer can request the 'ftell' module.  */
-#  if !GNULIB_defined_ftell_function
-#   undef ftell
-#   define ftell rpl_ftell
-static inline long _GL_ARG_NONNULL ((1))
-rpl_ftell (FILE *f)
-{
-#   if @REPLACE_FTELLO@
-  return rpl_ftello (f);
-#   else
-  return ftello (f);
-#   endif
-}
-#   define GNULIB_defined_ftell_function 1
-#  endif
-# endif
 #elif defined GNULIB_POSIXCHECK
 # define _GL_FTELL_WARN /* Category 1, above.  */
 # undef ftell
@@ -483,7 +561,7 @@ _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger 
than 4 GB "
 
 
 #if @GNULIB_FWRITE@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef fwrite
 #   define fwrite rpl_fwrite
@@ -496,10 +574,55 @@ _GL_CXXALIAS_RPL (fwrite, size_t,
 # else
 _GL_CXXALIAS_SYS (fwrite, size_t,
                   (const void *ptr, size_t s, size_t n, FILE *stream));
+
+/* Work around glibc bug 11959
+   <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>,
+   which sometimes causes an unwanted diagnostic for fwrite calls.
+   This affects only function declaration attributes, so it's not
+   needed for C++.  */
+#  if !defined __cplusplus && 0 < __USE_FORTIFY_LEVEL
+static inline size_t _GL_ARG_NONNULL ((1, 4))
+rpl_fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
+{
+  size_t r = fwrite (ptr, s, n, stream);
+  (void) r;
+  return r;
+}
+#   undef fwrite
+#   define fwrite rpl_fwrite
+#  endif
 # endif
 _GL_CXXALIASWARN (fwrite);
 #endif
 
+#if @GNULIB_GETC@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef getc
+#   define getc rpl_fgetc
+#  endif
+_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL_1 (getc, rpl_fgetc, int, (FILE *stream));
+# else
+_GL_CXXALIAS_SYS (getc, int, (FILE *stream));
+# endif
+_GL_CXXALIASWARN (getc);
+#endif
+
+#if @GNULIB_GETCHAR@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef getchar
+#   define getchar rpl_getchar
+#  endif
+_GL_FUNCDECL_RPL (getchar, int, (void));
+_GL_CXXALIAS_RPL (getchar, int, (void));
+# else
+_GL_CXXALIAS_SYS (getchar, int, (void));
+# endif
+_GL_CXXALIASWARN (getchar);
+#endif
+
 #if @GNULIB_GETDELIM@
 /* Read input, up to (and including) the next occurrence of DELIMITER, from
    STREAM, store it in *LINEPTR (and NUL-terminate it).
@@ -576,6 +699,26 @@ _GL_WARN_ON_USE (getline, "getline is unportable - "
 # endif
 #endif
 
+#if @GNULIB_GETS@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gets
+#   define gets rpl_gets
+#  endif
+_GL_FUNCDECL_RPL (gets, char *, (char *s) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (gets, char *, (char *s));
+# else
+_GL_CXXALIAS_SYS (gets, char *, (char *s));
+#  undef gets
+# endif
+_GL_CXXALIASWARN (gets);
+/* It is very rare that the developer ever has full control of stdin,
+   so any use of gets warrants an unconditional warning.  Assume it is
+   always declared, since it is required by C89.  */
+_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#endif
+
+
 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
 struct obstack;
 /* Grow an obstack with formatted output.  Return the number of
@@ -627,6 +770,20 @@ _GL_CXXALIAS_SYS (obstack_vprintf, int,
 _GL_CXXALIASWARN (obstack_vprintf);
 #endif
 
+#if @GNULIB_PCLOSE@
+# if address@hidden@
+_GL_FUNCDECL_SYS (pclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (pclose, int, (FILE *stream));
+_GL_CXXALIASWARN (pclose);
+#elif defined GNULIB_POSIXCHECK
+# undef pclose
+# if HAVE_RAW_DECL_PCLOSE
+_GL_WARN_ON_USE (pclose, "popen is unportable - "
+                 "use gnulib module pclose for more portability");
+# endif
+#endif
+
 #if @GNULIB_PERROR@
 /* Print a message to standard error, describing the value of ERRNO,
    (if STRING is not NULL and not empty) prefixed with STRING and ": ",
@@ -658,6 +815,10 @@ _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const 
char *mode)
                                  _GL_ARG_NONNULL ((1, 2)));
 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
 # else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode)
+                                 _GL_ARG_NONNULL ((1, 2)));
+#  endif
 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
 # endif
 _GL_CXXALIASWARN (popen);
@@ -671,18 +832,27 @@ _GL_WARN_ON_USE (popen, "popen is buggy on some platforms 
- "
 
 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
-     || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
@GNULIB_STDIO_H_SIGPIPE@)
+     || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
(@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
 #  if defined __GNUC__
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 /* Don't break __attribute__((format(printf,M,N))).  */
 #    define printf __printf__
 #   endif
+#   if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL_1 (__printf__, int,
                     (const char *format, ...)
                     __asm__ (@ASM_SYMBOL_PREFIX@
                              _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
                     _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2)
                     _GL_ARG_NONNULL ((1)));
+#   else
+_GL_FUNCDECL_RPL_1 (__printf__, int,
+                    (const char *format, ...)
+                    __asm__ (@ASM_SYMBOL_PREFIX@
+                             _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
+                    _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2)
+                    _GL_ARG_NONNULL ((1)));
+#   endif
 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
 #  else
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -711,7 +881,7 @@ _GL_WARN_ON_USE (printf, "printf is not always POSIX 
compliant - "
 #endif
 
 #if @GNULIB_PUTC@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef putc
 #   define putc rpl_fputc
@@ -725,7 +895,7 @@ _GL_CXXALIASWARN (putc);
 #endif
 
 #if @GNULIB_PUTCHAR@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef putchar
 #   define putchar rpl_putchar
@@ -739,7 +909,7 @@ _GL_CXXALIASWARN (putchar);
 #endif
 
 #if @GNULIB_PUTS@
-# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || 
@GNULIB_STDIO_H_SIGPIPE@)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef puts
 #   define puts rpl_puts
@@ -823,6 +993,37 @@ _GL_WARN_ON_USE (renameat, "renameat is not portable - "
 # endif
 #endif
 
+#if @GNULIB_SCANF@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if defined __GNUC__
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef scanf
+/* Don't break __attribute__((format(scanf,M,N))).  */
+#    define scanf __scanf__
+#   endif
+_GL_FUNCDECL_RPL_1 (__scanf__, int,
+                    (const char *format, ...)
+                    __asm__ (@ASM_SYMBOL_PREFIX@
+                             _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf))
+                    _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
+                    _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *format, ...));
+#  else
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef scanf
+#    define scanf rpl_scanf
+#   endif
+_GL_FUNCDECL_RPL (scanf, int, (const char *format, ...)
+                              _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
+                              _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (scanf, int, (const char *format, ...));
+#  endif
+# else
+_GL_CXXALIAS_SYS (scanf, int, (const char *format, ...));
+# endif
+_GL_CXXALIASWARN (scanf);
+#endif
+
 #if @GNULIB_SNPRINTF@
 # if @REPLACE_SNPRINTF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -982,14 +1183,20 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
 
 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
-     || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
@GNULIB_STDIO_H_SIGPIPE@)
+     || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
(@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define vfprintf rpl_vfprintf
 #  endif
 #  define GNULIB_overrides_vfprintf 1
+#  if @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
                                  _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0)
                                  _GL_ARG_NONNULL ((1, 2)));
+#  else
+_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
+                                 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0)
+                                 _GL_ARG_NONNULL ((1, 2)));
+#  endif
 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
 # else
 /* Need to cast, because on Solaris, the third parameter is
@@ -1010,16 +1217,41 @@ _GL_WARN_ON_USE (vfprintf, "vfprintf is not always 
POSIX compliant - "
                       "POSIX compliance");
 #endif
 
+#if @GNULIB_VFSCANF@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef vfscanf
+#   define vfscanf rpl_vfscanf
+#  endif
+_GL_FUNCDECL_RPL (vfscanf, int,
+                  (FILE *stream, const char *format, va_list args)
+                  _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0)
+                  _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (vfscanf, int,
+                  (FILE *stream, const char *format, va_list args));
+# else
+_GL_CXXALIAS_SYS (vfscanf, int,
+                  (FILE *stream, const char *format, va_list args));
+# endif
+_GL_CXXALIASWARN (vfscanf);
+#endif
+
 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
-     || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
@GNULIB_STDIO_H_SIGPIPE@)
+     || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && 
(@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define vprintf rpl_vprintf
 #  endif
 #  define GNULIB_overrides_vprintf 1
+#  if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
                                 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0)
                                 _GL_ARG_NONNULL ((1)));
+#  else
+_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
+                                _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0)
+                                _GL_ARG_NONNULL ((1)));
+#  endif
 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
 # else
 /* Need to cast, because on Solaris, the second parameter is
@@ -1039,6 +1271,22 @@ _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX 
compliant - "
                  "POSIX compliance");
 #endif
 
+#if @GNULIB_VSCANF@
+# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef vscanf
+#   define vscanf rpl_vscanf
+#  endif
+_GL_FUNCDECL_RPL (vscanf, int, (const char *format, va_list args)
+                               _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0)
+                               _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (vscanf, int, (const char *format, va_list args));
+# else
+_GL_CXXALIAS_SYS (vscanf, int, (const char *format, va_list args));
+# endif
+_GL_CXXALIASWARN (vscanf);
+#endif
+
 #if @GNULIB_VSNPRINTF@
 # if @REPLACE_VSNPRINTF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -1097,6 +1345,6 @@ _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX 
compliant - "
 #endif
 
 
-#endif /* _GL_STDIO_H */
-#endif /* _GL_STDIO_H */
+#endif /* address@hidden@_STDIO_H */
+#endif /* address@hidden@_STDIO_H */
 #endif
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index 62d18c6..047fac1 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -28,13 +28,13 @@
 #else
 /* Normal invocation convention.  */
 
-#ifndef _GL_STDLIB_H
+#ifndef address@hidden@_STDLIB_H
 
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_STDLIB_H@
 
-#ifndef _GL_STDLIB_H
-#define _GL_STDLIB_H
+#ifndef address@hidden@_STDLIB_H
+#define address@hidden@_STDLIB_H
 
 /* NetBSD 5.0 mis-defines NULL.  */
 #include <stddef.h>
@@ -81,18 +81,15 @@ struct random_data
 # endif
 #endif
 
-#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! 
defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined 
__CYGWIN__)
+#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined 
GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined 
__WIN32__) && ! defined __CYGWIN__)
 /* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
+/* On MacOS X 10.5, only <unistd.h> declares mkstemps.  */
 /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt.  */
 /* But avoid namespace pollution on glibc systems and native Windows.  */
 # include <unistd.h>
 #endif
 
-#if 3 <= __GNUC__ || __GNUC__ == 2 && 8 <= __GNUC_MINOR__
-# define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-#else
-# define _GL_ATTRIBUTE_NORETURN
-#endif
+/* The definition of _Noreturn is copied here.  */
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
@@ -119,7 +116,7 @@ struct random_data
 /* Terminate the current process with the given return code, without running
    the 'atexit' handlers.  */
 # if address@hidden@
-_GL_FUNCDECL_SYS (_Exit, void, (int status) _GL_ATTRIBUTE_NORETURN);
+_GL_FUNCDECL_SYS (_Exit, _Noreturn void, (int status));
 # endif
 _GL_CXXALIAS_SYS (_Exit, void, (int status));
 _GL_CXXALIASWARN (_Exit);
@@ -255,9 +252,14 @@ _GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
 # endif
 #endif
 
+/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
+   rely on GNU or POSIX semantics for malloc and realloc (for example,
+   by never specifying a zero size), so it does not need malloc or
+   realloc to be redefined.  */
 #if @GNULIB_MALLOC_POSIX@
 # if @REPLACE_MALLOC@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#  if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+        || _GL_USE_STDLIB_ALLOC)
 #   undef malloc
 #   define malloc rpl_malloc
 #  endif
@@ -267,13 +269,28 @@ _GL_CXXALIAS_RPL (malloc, void *, (size_t size));
 _GL_CXXALIAS_SYS (malloc, void *, (size_t size));
 # endif
 _GL_CXXALIASWARN (malloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
 # undef malloc
 /* Assume malloc is always declared.  */
 _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
                  "use gnulib module malloc-posix for portability");
 #endif
 
+/* Convert a multibyte character to a wide character.  */
+#if @GNULIB_MBTOWC@
+# if @REPLACE_MBTOWC@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbtowc
+#   define mbtowc rpl_mbtowc
+#  endif
+_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
+_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
+# else
+_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
+# endif
+_GL_CXXALIASWARN (mbtowc);
+#endif
+
 #if @GNULIB_MKDTEMP@
 /* Create a unique temporary directory from TEMPLATE.
    The last six characters of TEMPLATE must be "XXXXXX";
@@ -516,7 +533,8 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
 
 #if @GNULIB_REALLOC_POSIX@
 # if @REPLACE_REALLOC@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#  if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+        || _GL_USE_STDLIB_ALLOC)
 #   undef realloc
 #   define realloc rpl_realloc
 #  endif
@@ -526,7 +544,7 @@ _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t 
size));
 _GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
 # endif
 _GL_CXXALIASWARN (realloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
 # undef realloc
 /* Assume realloc is always declared.  */
 _GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
@@ -723,7 +741,22 @@ _GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
 # endif
 #endif
 
+/* Convert a wide character to a multibyte character.  */
+#if @GNULIB_WCTOMB@
+# if @REPLACE_WCTOMB@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wctomb
+#   define wctomb rpl_wctomb
+#  endif
+_GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc));
+_GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
+# else
+_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
+# endif
+_GL_CXXALIASWARN (wctomb);
+#endif
+
 
-#endif /* _GL_STDLIB_H */
-#endif /* _GL_STDLIB_H */
+#endif /* address@hidden@_STDLIB_H */
+#endif /* address@hidden@_STDLIB_H */
 #endif
diff --git a/gl/strerror-override.c b/gl/strerror-override.c
new file mode 100644
index 0000000..d6ecf2e
--- /dev/null
+++ b/gl/strerror-override.c
@@ -0,0 +1,279 @@
+/* strerror-override.c --- POSIX compatible system error routine
+
+   Copyright (C) 2010-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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2010.  */
+
+#include <config.h>
+
+#include "strerror-override.h"
+
+#include <errno.h>
+
+#if GNULIB_defined_ESOCK /* native Windows platforms */
+# if HAVE_WINSOCK2_H
+#  include <winsock2.h>
+# endif
+#endif
+
+/* If ERRNUM maps to an errno value defined by gnulib, return a string
+   describing the error.  Otherwise return NULL.  */
+const char *
+strerror_override (int errnum)
+{
+  /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
+  switch (errnum)
+    {
+#if REPLACE_STRERROR_0
+    case 0:
+      return "Success";
+#endif
+
+#if GNULIB_defined_ETXTBSY
+    case ETXTBSY:
+      return "Text file busy";
+#endif
+
+#if GNULIB_defined_ESOCK /* native Windows platforms */
+      /* EWOULDBLOCK is the same as EAGAIN.  */
+    case EINPROGRESS:
+      return "Operation now in progress";
+    case EALREADY:
+      return "Operation already in progress";
+    case ENOTSOCK:
+      return "Socket operation on non-socket";
+    case EDESTADDRREQ:
+      return "Destination address required";
+    case EMSGSIZE:
+      return "Message too long";
+    case EPROTOTYPE:
+      return "Protocol wrong type for socket";
+    case ENOPROTOOPT:
+      return "Protocol not available";
+    case EPROTONOSUPPORT:
+      return "Protocol not supported";
+    case ESOCKTNOSUPPORT:
+      return "Socket type not supported";
+    case EOPNOTSUPP:
+      return "Operation not supported";
+    case EPFNOSUPPORT:
+      return "Protocol family not supported";
+    case EAFNOSUPPORT:
+      return "Address family not supported by protocol";
+    case EADDRINUSE:
+      return "Address already in use";
+    case EADDRNOTAVAIL:
+      return "Cannot assign requested address";
+    case ENETDOWN:
+      return "Network is down";
+    case ENETUNREACH:
+      return "Network is unreachable";
+    case ENETRESET:
+      return "Network dropped connection on reset";
+    case ECONNABORTED:
+      return "Software caused connection abort";
+    case ECONNRESET:
+      return "Connection reset by peer";
+    case ENOBUFS:
+      return "No buffer space available";
+    case EISCONN:
+      return "Transport endpoint is already connected";
+    case ENOTCONN:
+      return "Transport endpoint is not connected";
+    case ESHUTDOWN:
+      return "Cannot send after transport endpoint shutdown";
+    case ETOOMANYREFS:
+      return "Too many references: cannot splice";
+    case ETIMEDOUT:
+      return "Connection timed out";
+    case ECONNREFUSED:
+      return "Connection refused";
+    case ELOOP:
+      return "Too many levels of symbolic links";
+    case EHOSTDOWN:
+      return "Host is down";
+    case EHOSTUNREACH:
+      return "No route to host";
+    case EPROCLIM:
+      return "Too many processes";
+    case EUSERS:
+      return "Too many users";
+    case EDQUOT:
+      return "Disk quota exceeded";
+    case ESTALE:
+      return "Stale NFS file handle";
+    case EREMOTE:
+      return "Object is remote";
+# if HAVE_WINSOCK2_H
+      /* WSA_INVALID_HANDLE maps to EBADF */
+      /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
+      /* WSA_INVALID_PARAMETER maps to EINVAL */
+    case WSA_OPERATION_ABORTED:
+      return "Overlapped operation aborted";
+    case WSA_IO_INCOMPLETE:
+      return "Overlapped I/O event object not in signaled state";
+    case WSA_IO_PENDING:
+      return "Overlapped operations will complete later";
+      /* WSAEINTR maps to EINTR */
+      /* WSAEBADF maps to EBADF */
+      /* WSAEACCES maps to EACCES */
+      /* WSAEFAULT maps to EFAULT */
+      /* WSAEINVAL maps to EINVAL */
+      /* WSAEMFILE maps to EMFILE */
+      /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
+      /* WSAEINPROGRESS is EINPROGRESS */
+      /* WSAEALREADY is EALREADY */
+      /* WSAENOTSOCK is ENOTSOCK */
+      /* WSAEDESTADDRREQ is EDESTADDRREQ */
+      /* WSAEMSGSIZE is EMSGSIZE */
+      /* WSAEPROTOTYPE is EPROTOTYPE */
+      /* WSAENOPROTOOPT is ENOPROTOOPT */
+      /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
+      /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
+      /* WSAEOPNOTSUPP is EOPNOTSUPP */
+      /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
+      /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
+      /* WSAEADDRINUSE is EADDRINUSE */
+      /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
+      /* WSAENETDOWN is ENETDOWN */
+      /* WSAENETUNREACH is ENETUNREACH */
+      /* WSAENETRESET is ENETRESET */
+      /* WSAECONNABORTED is ECONNABORTED */
+      /* WSAECONNRESET is ECONNRESET */
+      /* WSAENOBUFS is ENOBUFS */
+      /* WSAEISCONN is EISCONN */
+      /* WSAENOTCONN is ENOTCONN */
+      /* WSAESHUTDOWN is ESHUTDOWN */
+      /* WSAETOOMANYREFS is ETOOMANYREFS */
+      /* WSAETIMEDOUT is ETIMEDOUT */
+      /* WSAECONNREFUSED is ECONNREFUSED */
+      /* WSAELOOP is ELOOP */
+      /* WSAENAMETOOLONG maps to ENAMETOOLONG */
+      /* WSAEHOSTDOWN is EHOSTDOWN */
+      /* WSAEHOSTUNREACH is EHOSTUNREACH */
+      /* WSAENOTEMPTY maps to ENOTEMPTY */
+      /* WSAEPROCLIM is EPROCLIM */
+      /* WSAEUSERS is EUSERS */
+      /* WSAEDQUOT is EDQUOT */
+      /* WSAESTALE is ESTALE */
+      /* WSAEREMOTE is EREMOTE */
+    case WSASYSNOTREADY:
+      return "Network subsystem is unavailable";
+    case WSAVERNOTSUPPORTED:
+      return "Winsock.dll version out of range";
+    case WSANOTINITIALISED:
+      return "Successful WSAStartup not yet performed";
+    case WSAEDISCON:
+      return "Graceful shutdown in progress";
+    case WSAENOMORE: case WSA_E_NO_MORE:
+      return "No more results";
+    case WSAECANCELLED: case WSA_E_CANCELLED:
+      return "Call was canceled";
+    case WSAEINVALIDPROCTABLE:
+      return "Procedure call table is invalid";
+    case WSAEINVALIDPROVIDER:
+      return "Service provider is invalid";
+    case WSAEPROVIDERFAILEDINIT:
+      return "Service provider failed to initialize";
+    case WSASYSCALLFAILURE:
+      return "System call failure";
+    case WSASERVICE_NOT_FOUND:
+      return "Service not found";
+    case WSATYPE_NOT_FOUND:
+      return "Class type not found";
+    case WSAEREFUSED:
+      return "Database query was refused";
+    case WSAHOST_NOT_FOUND:
+      return "Host not found";
+    case WSATRY_AGAIN:
+      return "Nonauthoritative host not found";
+    case WSANO_RECOVERY:
+      return "Nonrecoverable error";
+    case WSANO_DATA:
+      return "Valid name, no data record of requested type";
+      /* WSA_QOS_* omitted */
+# endif
+#endif
+
+#if GNULIB_defined_ENOMSG
+    case ENOMSG:
+      return "No message of desired type";
+#endif
+
+#if GNULIB_defined_EIDRM
+    case EIDRM:
+      return "Identifier removed";
+#endif
+
+#if GNULIB_defined_ENOLINK
+    case ENOLINK:
+      return "Link has been severed";
+#endif
+
+#if GNULIB_defined_EPROTO
+    case EPROTO:
+      return "Protocol error";
+#endif
+
+#if GNULIB_defined_EMULTIHOP
+    case EMULTIHOP:
+      return "Multihop attempted";
+#endif
+
+#if GNULIB_defined_EBADMSG
+    case EBADMSG:
+      return "Bad message";
+#endif
+
+#if GNULIB_defined_EOVERFLOW
+    case EOVERFLOW:
+      return "Value too large for defined data type";
+#endif
+
+#if GNULIB_defined_ENOTSUP
+    case ENOTSUP:
+      return "Not supported";
+#endif
+
+#if GNULIB_defined_ENETRESET
+    case ENETRESET:
+      return "Network dropped connection on reset";
+#endif
+
+#if GNULIB_defined_ECONNABORTED
+    case ECONNABORTED:
+      return "Software caused connection abort";
+#endif
+
+#if GNULIB_defined_ESTALE
+    case ESTALE:
+      return "Stale NFS file handle";
+#endif
+
+#if GNULIB_defined_EDQUOT
+    case EDQUOT:
+      return "Disk quota exceeded";
+#endif
+
+#if GNULIB_defined_ECANCELED
+    case ECANCELED:
+      return "Operation canceled";
+#endif
+
+    default:
+      return NULL;
+    }
+}
diff --git a/gl/strerror-override.h b/gl/strerror-override.h
new file mode 100644
index 0000000..81e4a50
--- /dev/null
+++ b/gl/strerror-override.h
@@ -0,0 +1,52 @@
+/* strerror-override.h --- POSIX compatible system error routine
+
+   Copyright (C) 2010-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/>.  */
+
+#ifndef _GL_STRERROR_OVERRIDE_H
+# define _GL_STRERROR_OVERRIDE_H
+
+# include <errno.h>
+# include <stddef.h>
+
+/* Reasonable buffer size that should never trigger ERANGE; if this
+   proves too small, we intentionally abort(), to remind us to fix
+   this value.  */
+# define STACKBUF_LEN 256
+
+/* If ERRNUM maps to an errno value defined by gnulib, return a string
+   describing the error.  Otherwise return NULL.  */
+# if REPLACE_STRERROR_0 \
+     || GNULIB_defined_ETXTBSY \
+     || GNULIB_defined_ESOCK \
+     || GNULIB_defined_ENOMSG \
+     || GNULIB_defined_EIDRM \
+     || GNULIB_defined_ENOLINK \
+     || GNULIB_defined_EPROTO \
+     || GNULIB_defined_EMULTIHOP \
+     || GNULIB_defined_EBADMSG \
+     || GNULIB_defined_EOVERFLOW \
+     || GNULIB_defined_ENOTSUP \
+     || GNULIB_defined_ENETRESET \
+     || GNULIB_defined_ECONNABORTED \
+     || GNULIB_defined_ESTALE \
+     || GNULIB_defined_EDQUOT \
+     || GNULIB_defined_ECANCELED
+extern const char *strerror_override (int errnum);
+# else
+#  define strerror_override(ignored) NULL
+# endif
+
+#endif /* _GL_STRERROR_OVERRIDE_H */
diff --git a/gl/strerror.c b/gl/strerror.c
index 5dae111..63899ca 100644
--- a/gl/strerror.c
+++ b/gl/strerror.c
@@ -17,340 +17,54 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <string.h>
 
-#if REPLACE_STRERROR
-
-# include <errno.h>
-# include <stdio.h>
-
-# if GNULIB_defined_ESOCK /* native Windows platforms */
-#  if HAVE_WINSOCK2_H
-#   include <winsock2.h>
-#  endif
-# endif
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-# include "intprops.h"
+#include "intprops.h"
+#include "strerror-override.h"
+#include "verify.h"
 
 /* Use the system functions, not the gnulib overrides in this file.  */
-# undef sprintf
-
-# undef strerror
-# if ! HAVE_DECL_STRERROR
-#  define strerror(n) NULL
-# endif
+#undef sprintf
 
 char *
-rpl_strerror (int n)
+strerror (int n)
+#undef strerror
 {
-  char const *msg = NULL;
-  /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
-  switch (n)
-    {
-# if GNULIB_defined_ETXTBSY
-    case ETXTBSY:
-      msg = "Text file busy";
-      break;
-# endif
-
-# if GNULIB_defined_ESOCK /* native Windows platforms */
-    /* EWOULDBLOCK is the same as EAGAIN.  */
-    case EINPROGRESS:
-      msg = "Operation now in progress";
-      break;
-    case EALREADY:
-      msg = "Operation already in progress";
-      break;
-    case ENOTSOCK:
-      msg = "Socket operation on non-socket";
-      break;
-    case EDESTADDRREQ:
-      msg = "Destination address required";
-      break;
-    case EMSGSIZE:
-      msg = "Message too long";
-      break;
-    case EPROTOTYPE:
-      msg = "Protocol wrong type for socket";
-      break;
-    case ENOPROTOOPT:
-      msg = "Protocol not available";
-      break;
-    case EPROTONOSUPPORT:
-      msg = "Protocol not supported";
-      break;
-    case ESOCKTNOSUPPORT:
-      msg = "Socket type not supported";
-      break;
-    case EOPNOTSUPP:
-      msg = "Operation not supported";
-      break;
-    case EPFNOSUPPORT:
-      msg = "Protocol family not supported";
-      break;
-    case EAFNOSUPPORT:
-      msg = "Address family not supported by protocol";
-      break;
-    case EADDRINUSE:
-      msg = "Address already in use";
-      break;
-    case EADDRNOTAVAIL:
-      msg = "Cannot assign requested address";
-      break;
-    case ENETDOWN:
-      msg = "Network is down";
-      break;
-    case ENETUNREACH:
-      msg = "Network is unreachable";
-      break;
-    case ENETRESET:
-      msg = "Network dropped connection on reset";
-      break;
-    case ECONNABORTED:
-      msg = "Software caused connection abort";
-      break;
-    case ECONNRESET:
-      msg = "Connection reset by peer";
-      break;
-    case ENOBUFS:
-      msg = "No buffer space available";
-      break;
-    case EISCONN:
-      msg = "Transport endpoint is already connected";
-      break;
-    case ENOTCONN:
-      msg = "Transport endpoint is not connected";
-      break;
-    case ESHUTDOWN:
-      msg = "Cannot send after transport endpoint shutdown";
-      break;
-    case ETOOMANYREFS:
-      msg = "Too many references: cannot splice";
-      break;
-    case ETIMEDOUT:
-      msg = "Connection timed out";
-      break;
-    case ECONNREFUSED:
-      msg = "Connection refused";
-      break;
-    case ELOOP:
-      msg = "Too many levels of symbolic links";
-      break;
-    case EHOSTDOWN:
-      msg = "Host is down";
-      break;
-    case EHOSTUNREACH:
-      msg = "No route to host";
-      break;
-    case EPROCLIM:
-      msg = "Too many processes";
-      break;
-    case EUSERS:
-      msg = "Too many users";
-      break;
-    case EDQUOT:
-      msg = "Disk quota exceeded";
-      break;
-    case ESTALE:
-      msg = "Stale NFS file handle";
-      break;
-    case EREMOTE:
-      msg = "Object is remote";
-      break;
-#  if HAVE_WINSOCK2_H
-    /* WSA_INVALID_HANDLE maps to EBADF */
-    /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
-    /* WSA_INVALID_PARAMETER maps to EINVAL */
-    case WSA_OPERATION_ABORTED:
-      msg = "Overlapped operation aborted";
-      break;
-    case WSA_IO_INCOMPLETE:
-      msg = "Overlapped I/O event object not in signaled state";
-      break;
-    case WSA_IO_PENDING:
-      msg = "Overlapped operations will complete later";
-      break;
-    /* WSAEINTR maps to EINTR */
-    /* WSAEBADF maps to EBADF */
-    /* WSAEACCES maps to EACCES */
-    /* WSAEFAULT maps to EFAULT */
-    /* WSAEINVAL maps to EINVAL */
-    /* WSAEMFILE maps to EMFILE */
-    /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
-    /* WSAEINPROGRESS is EINPROGRESS */
-    /* WSAEALREADY is EALREADY */
-    /* WSAENOTSOCK is ENOTSOCK */
-    /* WSAEDESTADDRREQ is EDESTADDRREQ */
-    /* WSAEMSGSIZE is EMSGSIZE */
-    /* WSAEPROTOTYPE is EPROTOTYPE */
-    /* WSAENOPROTOOPT is ENOPROTOOPT */
-    /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
-    /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
-    /* WSAEOPNOTSUPP is EOPNOTSUPP */
-    /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
-    /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
-    /* WSAEADDRINUSE is EADDRINUSE */
-    /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
-    /* WSAENETDOWN is ENETDOWN */
-    /* WSAENETUNREACH is ENETUNREACH */
-    /* WSAENETRESET is ENETRESET */
-    /* WSAECONNABORTED is ECONNABORTED */
-    /* WSAECONNRESET is ECONNRESET */
-    /* WSAENOBUFS is ENOBUFS */
-    /* WSAEISCONN is EISCONN */
-    /* WSAENOTCONN is ENOTCONN */
-    /* WSAESHUTDOWN is ESHUTDOWN */
-    /* WSAETOOMANYREFS is ETOOMANYREFS */
-    /* WSAETIMEDOUT is ETIMEDOUT */
-    /* WSAECONNREFUSED is ECONNREFUSED */
-    /* WSAELOOP is ELOOP */
-    /* WSAENAMETOOLONG maps to ENAMETOOLONG */
-    /* WSAEHOSTDOWN is EHOSTDOWN */
-    /* WSAEHOSTUNREACH is EHOSTUNREACH */
-    /* WSAENOTEMPTY maps to ENOTEMPTY */
-    /* WSAEPROCLIM is EPROCLIM */
-    /* WSAEUSERS is EUSERS */
-    /* WSAEDQUOT is EDQUOT */
-    /* WSAESTALE is ESTALE */
-    /* WSAEREMOTE is EREMOTE */
-    case WSASYSNOTREADY:
-      msg = "Network subsystem is unavailable";
-      break;
-    case WSAVERNOTSUPPORTED:
-      msg = "Winsock.dll version out of range";
-      break;
-    case WSANOTINITIALISED:
-      msg = "Successful WSAStartup not yet performed";
-      break;
-    case WSAEDISCON:
-      msg = "Graceful shutdown in progress";
-      break;
-    case WSAENOMORE: case WSA_E_NO_MORE:
-      msg = "No more results";
-      break;
-    case WSAECANCELLED: case WSA_E_CANCELLED:
-      msg = "Call was canceled";
-      break;
-    case WSAEINVALIDPROCTABLE:
-      msg = "Procedure call table is invalid";
-      break;
-    case WSAEINVALIDPROVIDER:
-      msg = "Service provider is invalid";
-      break;
-    case WSAEPROVIDERFAILEDINIT:
-      msg = "Service provider failed to initialize";
-      break;
-    case WSASYSCALLFAILURE:
-      msg = "System call failure";
-      break;
-    case WSASERVICE_NOT_FOUND:
-      msg = "Service not found";
-      break;
-    case WSATYPE_NOT_FOUND:
-      msg = "Class type not found";
-      break;
-    case WSAEREFUSED:
-      msg = "Database query was refused";
-      break;
-    case WSAHOST_NOT_FOUND:
-      msg = "Host not found";
-      break;
-    case WSATRY_AGAIN:
-      msg = "Nonauthoritative host not found";
-      break;
-    case WSANO_RECOVERY:
-      msg = "Nonrecoverable error";
-      break;
-    case WSANO_DATA:
-      msg = "Valid name, no data record of requested type";
-      break;
-    /* WSA_QOS_* omitted */
-#  endif
-# endif
-
-# if GNULIB_defined_ENOMSG
-    case ENOMSG:
-      msg = "No message of desired type";
-      break;
-# endif
-
-# if GNULIB_defined_EIDRM
-    case EIDRM:
-      msg = "Identifier removed";
-      break;
-# endif
-
-# if GNULIB_defined_ENOLINK
-    case ENOLINK:
-      msg = "Link has been severed";
-      break;
-# endif
-
-# if GNULIB_defined_EPROTO
-    case EPROTO:
-      msg = "Protocol error";
-      break;
-# endif
-
-# if GNULIB_defined_EMULTIHOP
-    case EMULTIHOP:
-      msg = "Multihop attempted";
-      break;
-# endif
-
-# if GNULIB_defined_EBADMSG
-    case EBADMSG:
-      msg = "Bad message";
-      break;
-# endif
-
-# if GNULIB_defined_EOVERFLOW
-    case EOVERFLOW:
-      msg = "Value too large for defined data type";
-      break;
-# endif
-
-# if GNULIB_defined_ENOTSUP
-    case ENOTSUP:
-      msg = "Not supported";
-      break;
-# endif
-
-# if GNULIB_defined_ESTALE
-    case ESTALE:
-      msg = "Stale NFS file handle";
-      break;
-# endif
-
-# if GNULIB_defined_EDQUOT
-    case EDQUOT:
-      msg = "Disk quota exceeded";
-      break;
-# endif
-
-# if GNULIB_defined_ECANCELED
-    case ECANCELED:
-      msg = "Operation canceled";
-      break;
-# endif
-    }
+  static char buf[STACKBUF_LEN];
+  size_t len;
 
+  /* Cast away const, due to the historical signature of strerror;
+     callers should not be modifying the string.  */
+  const char *msg = strerror_override (n);
   if (msg)
     return (char *) msg;
 
-  {
-    char *result = strerror (n);
+  msg = strerror (n);
 
-    if (result == NULL || result[0] == '\0')
-      {
-        static char const fmt[] = "Unknown error (%d)";
-        static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)];
-        sprintf (msg_buf, fmt, n);
-        return msg_buf;
-      }
+  /* Our strerror_r implementation might use the system's strerror
+     buffer, so all other clients of strerror have to see the error
+     copied into a buffer that we manage.  This is not thread-safe,
+     even if the system strerror is, but portable programs shouldn't
+     be using strerror if they care about thread-safety.  */
+  if (!msg || !*msg)
+    {
+      static char const fmt[] = "Unknown error %d";
+      verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n));
+      sprintf (buf, fmt, n);
+      errno = EINVAL;
+      return buf;
+    }
 
-    return result;
-  }
-}
+  /* Fix STACKBUF_LEN if this ever aborts.  */
+  len = strlen (msg);
+  if (sizeof buf <= len)
+    abort ();
 
-#endif
+  return memcpy (buf, msg, len + 1);
+}
diff --git a/gl/strerror_r.c b/gl/strerror_r.c
new file mode 100644
index 0000000..e6cf99b
--- /dev/null
+++ b/gl/strerror_r.c
@@ -0,0 +1,327 @@
+/* strerror_r.c --- POSIX compatible system error routine
+
+   Copyright (C) 2010-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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2010.  */
+
+#include <config.h>
+
+/* Enable declaration of sys_nerr and sys_errlist in <errno.h> on NetBSD.  */
+#define _NETBSD_SOURCE 1
+
+/* Specification.  */
+#include <string.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "strerror-override.h"
+
+#if (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) && 
HAVE___XPG_STRERROR_R /* glibc >= 2.3.4, cygwin >= 1.7.9 */
+
+# define USE_XPG_STRERROR_R 1
+
+#elif HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__ || 
defined __CYGWIN__)
+
+/* The system's strerror_r function is OK, except that its third argument
+   is 'int', not 'size_t', or its return type is wrong.  */
+
+# include <limits.h>
+
+# define USE_SYSTEM_STRERROR_R 1
+
+#else /* (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__ ? 
!HAVE___XPG_STRERROR_R : !HAVE_DECL_STRERROR_R) */
+
+/* Use the system's strerror().  Exclude glibc and cygwin because the
+   system strerror_r has the wrong return type, and cygwin 1.7.9
+   strerror_r clobbers strerror.  */
+# undef strerror
+
+# define USE_SYSTEM_STRERROR 1
+
+# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined 
__WIN32__) && !defined __CYGWIN__) || defined __sgi || (defined __sun && 
!defined _LP64) || defined __CYGWIN__
+
+/* No locking needed.  */
+
+/* Get catgets internationalization functions.  */
+#  if HAVE_CATGETS
+#   include <nl_types.h>
+#  endif
+
+/* Get sys_nerr, sys_errlist on HP-UX (otherwise only declared in C++ mode).
+   Get sys_nerr, sys_errlist on IRIX (otherwise only declared with _SGIAPI).  
*/
+#  if defined __hpux || defined __sgi
+extern int sys_nerr;
+extern char *sys_errlist[];
+#  endif
+
+/* Get sys_nerr on Solaris.  */
+#  if defined __sun && !defined _LP64
+extern int sys_nerr;
+#  endif
+
+# else
+
+#  include "glthread/lock.h"
+
+/* This lock protects the buffer returned by strerror().  We assume that
+   no other uses of strerror() exist in the program.  */
+gl_lock_define_initialized(static, strerror_lock)
+
+# endif
+
+#endif
+
+/* On MSVC, there is no snprintf() function, just a _snprintf().
+   It is of lower quality, but sufficient for the simple use here.
+   We only have to make sure to NUL terminate the result (_snprintf
+   does not NUL terminate, like strncpy).  */
+#if !HAVE_SNPRINTF
+static int
+local_snprintf (char *buf, size_t buflen, const char *format, ...)
+{
+  va_list args;
+  int result;
+
+  va_start (args, format);
+  result = _vsnprintf (buf, buflen, format, args);
+  va_end (args);
+  if (buflen > 0 && (result < 0 || result >= buflen))
+    buf[buflen - 1] = '\0';
+  return result;
+}
+# define snprintf local_snprintf
+#endif
+
+/* Copy as much of MSG into BUF as possible, without corrupting errno.
+   Return 0 if MSG fit in BUFLEN, otherwise return ERANGE.  */
+static int
+safe_copy (char *buf, size_t buflen, const char *msg)
+{
+  size_t len = strlen (msg);
+  int ret;
+
+  if (len < buflen)
+    {
+      /* Although POSIX allows memcpy() to corrupt errno, we don't
+         know of any implementation where this is a real problem.  */
+      memcpy (buf, msg, len + 1);
+      ret = 0;
+    }
+  else
+    {
+      memcpy (buf, msg, buflen - 1);
+      buf[buflen - 1] = '\0';
+      ret = ERANGE;
+    }
+  return ret;
+}
+
+
+int
+strerror_r (int errnum, char *buf, size_t buflen)
+#undef strerror_r
+{
+  /* Filter this out now, so that rest of this replacement knows that
+     there is room for a non-empty message and trailing NUL.  */
+  if (buflen <= 1)
+    {
+      if (buflen)
+        *buf = '\0';
+      return ERANGE;
+    }
+  *buf = '\0';
+
+  /* Check for gnulib overrides.  */
+  {
+    char const *msg = strerror_override (errnum);
+
+    if (msg)
+      return safe_copy (buf, buflen, msg);
+  }
+
+  {
+    int ret;
+    int saved_errno = errno;
+
+#if USE_XPG_STRERROR_R
+
+    {
+      extern int __xpg_strerror_r (int errnum, char *buf, size_t buflen);
+
+      ret = __xpg_strerror_r (errnum, buf, buflen);
+      if (ret < 0)
+        ret = errno;
+      if (!*buf)
+        {
+          /* glibc 2.13 would not touch buf on err, so we have to fall
+             back to GNU strerror_r which always returns a thread-safe
+             untruncated string to (partially) copy into our buf.  */
+          safe_copy (buf, buflen, strerror_r (errnum, buf, buflen));
+        }
+    }
+
+#elif USE_SYSTEM_STRERROR_R
+
+    if (buflen > INT_MAX)
+      buflen = INT_MAX;
+
+# ifdef __hpux
+    /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it
+       also fails to change buf on EINVAL.  */
+    {
+      char stackbuf[80];
+
+      if (buflen < sizeof stackbuf)
+        {
+          ret = strerror_r (errnum, stackbuf, sizeof stackbuf);
+          if (ret == 0)
+            ret = safe_copy (buf, buflen, stackbuf);
+        }
+      else
+        ret = strerror_r (errnum, buf, buflen);
+    }
+# else
+    ret = strerror_r (errnum, buf, buflen);
+
+    /* Some old implementations may return (-1, EINVAL) instead of EINVAL.  */
+    if (ret < 0)
+      ret = errno;
+# endif
+
+# ifdef _AIX
+    /* AIX returns 0 rather than ERANGE when truncating strings; try
+       again until we are sure we got the entire string.  */
+    if (!ret && strlen (buf) == buflen - 1)
+      {
+        char stackbuf[STACKBUF_LEN];
+        size_t len;
+        strerror_r (errnum, stackbuf, sizeof stackbuf);
+        len = strlen (stackbuf);
+        /* STACKBUF_LEN should have been large enough.  */
+        if (len + 1 == sizeof stackbuf)
+          abort ();
+        if (buflen <= len)
+          ret = ERANGE;
+      }
+# else
+    /* Solaris 10 does not populate buf on ERANGE.  OpenBSD 4.7
+       truncates early on ERANGE rather than return a partial integer.
+       We prefer the maximal string.  We set buf[0] earlier, and we
+       know of no implementation that modifies buf to be an
+       unterminated string, so this strlen should be portable in
+       practice (rather than pulling in a safer strnlen).  */
+    if (ret == ERANGE && strlen (buf) < buflen - 1)
+      {
+        char stackbuf[STACKBUF_LEN];
+
+        /* STACKBUF_LEN should have been large enough.  */
+        if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE)
+          abort ();
+        safe_copy (buf, buflen, stackbuf);
+      }
+# endif
+
+#else /* USE_SYSTEM_STRERROR */
+
+    /* Try to do what strerror (errnum) does, but without clobbering the
+       buffer used by strerror().  */
+
+# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined 
__WIN32__) && !defined __CYGWIN__) || defined __CYGWIN__ /* NetBSD, HP-UX, 
native Win32, Cygwin */
+
+    /* NetBSD:        sys_nerr, sys_errlist are declared through _NETBSD_SOURCE
+                      and <errno.h> above.
+       HP-UX:         sys_nerr, sys_errlist are declared explicitly above.
+       native Win32:  sys_nerr, sys_errlist are declared in <stdlib.h>.
+       Cygwin:        sys_nerr, sys_errlist are declared in <errno.h>.  */
+    if (errnum >= 0 && errnum < sys_nerr)
+      {
+#  if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux)
+#   if defined __NetBSD__
+        nl_catd catd = catopen ("libc", NL_CAT_LOCALE);
+        const char *errmsg =
+          (catd != (nl_catd)-1
+           ? catgets (catd, 1, errnum, sys_errlist[errnum])
+           : sys_errlist[errnum]);
+#   endif
+#   if defined __hpux
+        nl_catd catd = catopen ("perror", NL_CAT_LOCALE);
+        const char *errmsg =
+          (catd != (nl_catd)-1
+           ? catgets (catd, 1, 1 + errnum, sys_errlist[errnum])
+           : sys_errlist[errnum]);
+#   endif
+#  else
+        const char *errmsg = sys_errlist[errnum];
+#  endif
+        if (errmsg == NULL || *errmsg == '\0')
+          ret = EINVAL;
+        else
+          ret = safe_copy (buf, buflen, errmsg);
+#  if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux)
+        if (catd != (nl_catd)-1)
+          catclose (catd);
+#  endif
+      }
+    else
+      ret = EINVAL;
+
+# elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 
9 32-bit */
+
+    /* For a valid error number, the system's strerror() function returns
+       a pointer to a not copied string, not to a buffer.  */
+    if (errnum >= 0 && errnum < sys_nerr)
+      {
+        char *errmsg = strerror (errnum);
+
+        if (errmsg == NULL || *errmsg == '\0')
+          ret = EINVAL;
+        else
+          ret = safe_copy (buf, buflen, errmsg);
+      }
+    else
+      ret = EINVAL;
+
+# else
+
+    gl_lock_lock (strerror_lock);
+
+    {
+      char *errmsg = strerror (errnum);
+
+      /* For invalid error numbers, strerror() on
+           - IRIX 6.5 returns NULL,
+           - HP-UX 11 returns an empty string.  */
+      if (errmsg == NULL || *errmsg == '\0')
+        ret = EINVAL;
+      else
+        ret = safe_copy (buf, buflen, errmsg);
+    }
+
+    gl_lock_unlock (strerror_lock);
+
+# endif
+
+#endif
+
+    if (ret == EINVAL && !*buf)
+      snprintf (buf, buflen, "Unknown error %d", errnum);
+
+    errno = saved_errno;
+    return ret;
+  }
+}
diff --git a/gl/string.in.h b/gl/string.in.h
index 336e246..62d7994 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -16,7 +16,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_STRING_H
+#ifndef address@hidden@_STRING_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -26,8 +26,8 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_STRING_H@
 
-#ifndef _GL_STRING_H
-#define _GL_STRING_H
+#ifndef address@hidden@_STRING_H
+#define address@hidden@_STRING_H
 
 /* NetBSD 5.0 mis-defines NULL.  */
 #include <stddef.h>
@@ -59,6 +59,36 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
+/* Find the index of the least-significant set bit.  */
+#if @GNULIB_FFSL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (ffsl, int, (long int i));
+# endif
+_GL_CXXALIAS_SYS (ffsl, int, (long int i));
+_GL_CXXALIASWARN (ffsl);
+#elif defined GNULIB_POSIXCHECK
+# undef ffsl
+# if HAVE_RAW_DECL_FFSL
+_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
+# endif
+#endif
+
+
+/* Find the index of the least-significant set bit.  */
+#if @GNULIB_FFSLL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (ffsll, int, (long long int i));
+# endif
+_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
+_GL_CXXALIASWARN (ffsll);
+#elif defined GNULIB_POSIXCHECK
+# undef ffsll
+# if HAVE_RAW_DECL_FFSLL
+_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
+# endif
+#endif
+
+
 /* Return the first instance of C within N bytes of S, or NULL.  */
 #if @GNULIB_MEMCHR@
 # if @REPLACE_MEMCHR@
@@ -277,17 +307,28 @@ _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on 
character strings "
 
 /* Find the first occurrence of C in S or the final NUL byte.  */
 #if @GNULIB_STRCHRNUL@
-# if ! @HAVE_STRCHRNUL@
+# if @REPLACE_STRCHRNUL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define strchrnul rpl_strchrnul
+#  endif
+_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
+                                     _GL_ATTRIBUTE_PURE
+                                     _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (strchrnul, char *,
+                  (const char *str, int ch));
+# else
+#  if ! @HAVE_STRCHRNUL@
 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
                                      _GL_ATTRIBUTE_PURE
                                      _GL_ARG_NONNULL ((1)));
-# endif
+#  endif
   /* On some systems, this function is defined as an overloaded function:
        extern "C++" { const char * std::strchrnul (const char *, int); }
        extern "C++" { char * std::strchrnul (char *, int); }  */
 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
                         char *, (char const *__s, int __c_in),
                         char const *, (char const *__s, int __c_in));
+# endif
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
@@ -725,9 +766,9 @@ _GL_CXXALIASWARN (mbschr);
    and return a pointer to it.  Return NULL if C is not found in STRING.
    Unlike strrchr(), this function works correctly in multibyte locales with
    encodings such as GB18030.  */
-# if defined __hpux
+# if defined __hpux || defined __INTERIX
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
+#   define mbsrchr rpl_mbsrchr /* avoid collision with system function */
 #  endif
 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
                                    _GL_ARG_NONNULL ((1)));
@@ -966,5 +1007,5 @@ _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
 #endif
 
 
-#endif /* _GL_STRING_H */
-#endif /* _GL_STRING_H */
+#endif /* address@hidden@_STRING_H */
+#endif /* address@hidden@_STRING_H */
diff --git a/gl/sys_select.in.h b/gl/sys_select.in.h
index edff386..56a2d15 100644
--- a/gl/sys_select.in.h
+++ b/gl/sys_select.in.h
@@ -32,15 +32,32 @@
 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
 
-#else
+/* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
+   <sys/bsd_types.h>, which includes <sys/select.h>.  At this point we cannot
+   include <signal.h>, because that includes <internal/signal_core.h>, which
+   gives a syntax error because <sys/timespec.h> has not been completely
+   processed.  Simply delegate to the system's header in this case.  */
+#elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && 
!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
 
-#ifndef _GL_SYS_SELECT_H
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
 
-#if @HAVE_SYS_SELECT_H@
+#else
+
+#ifndef address@hidden@_SYS_SELECT_H
 
 /* On many platforms, <sys/select.h> assumes prior inclusion of
-   <sys/types.h>.  */
-# include <sys/types.h>
+   <sys/types.h>.  Also, mingw defines sigset_t there, instead of
+   in <signal.h> where it belongs.  */
+#include <sys/types.h>
+
+/* Get definition of 'sigset_t'.
+   But avoid namespace pollution on glibc systems.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <signal.h>
+#endif
+
+#if @HAVE_SYS_SELECT_H@
 
 /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
    of 'struct timeval', and no definition of this type.
@@ -51,10 +68,10 @@
 #  include <sys/time.h>
 # endif
 
-/* On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
+/* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
    that relies on memset(), but without including <string.h>.
    But in any case avoid namespace pollution on glibc systems.  */
-# if (defined __OpenBSD__ || defined __sun || defined __osf__ || defined 
__BEOS__) \
+# if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ 
|| defined __BEOS__) \
      && ! defined __GLIBC__
 #  include <string.h>
 # endif
@@ -64,8 +81,8 @@
 
 #endif
 
-#ifndef _GL_SYS_SELECT_H
-#define _GL_SYS_SELECT_H
+#ifndef address@hidden@_SYS_SELECT_H
+#define address@hidden@_SYS_SELECT_H
 
 #if address@hidden@
 /* A platform that lacks <sys/select.h>.  */
@@ -78,9 +95,12 @@
 #  include <string.h>
 # endif
 /* On native Windows platforms:
-   Get the 'fd_set' type.  Also, gnulib's <sys/socket.h> redefines select
-   so as to hide the declaration from <winsock2.h>.  */
-# include <sys/socket.h>
+   Get the 'fd_set' type.  */
+# if @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
+#  define _GL_INCLUDING_WINSOCK2_H
+#  include <winsock2.h>
+#  undef _GL_INCLUDING_WINSOCK2_H
+# endif
 #endif
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
@@ -88,8 +108,152 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
+/* Fix some definitions from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+
+# if !GNULIB_defined_rpl_fd_isset
+
+/* Re-define FD_ISSET to avoid a WSA call while we are not using
+   network sockets.  */
+static inline int
+rpl_fd_isset (SOCKET fd, fd_set * set)
+{
+  u_int i;
+  if (set == NULL)
+    return 0;
+
+  for (i = 0; i < set->fd_count; i++)
+    if (set->fd_array[i] == fd)
+      return 1;
+
+  return 0;
+}
+
+#  define GNULIB_defined_rpl_fd_isset 1
+# endif
+
+# undef FD_ISSET
+# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
+
+#endif
+
+/* Hide some function declarations from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+# if !defined address@hidden@_UNISTD_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef close
+#   define close close_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (close,
+                     "close() used without including <unistd.h>");
+#  endif
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gethostname
+#   define gethostname gethostname_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (gethostname,
+                     "gethostname() used without including <unistd.h>");
+#  endif
+# endif
+# if !defined address@hidden@_SYS_SOCKET_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef socket
+#   define socket              socket_used_without_including_sys_socket_h
+#   undef connect
+#   define connect             connect_used_without_including_sys_socket_h
+#   undef accept
+#   define accept              accept_used_without_including_sys_socket_h
+#   undef bind
+#   define bind                bind_used_without_including_sys_socket_h
+#   undef getpeername
+#   define getpeername         getpeername_used_without_including_sys_socket_h
+#   undef getsockname
+#   define getsockname         getsockname_used_without_including_sys_socket_h
+#   undef getsockopt
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
+#   undef listen
+#   define listen              listen_used_without_including_sys_socket_h
+#   undef recv
+#   define recv                recv_used_without_including_sys_socket_h
+#   undef send
+#   define send                send_used_without_including_sys_socket_h
+#   undef recvfrom
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
+#   undef sendto
+#   define sendto              sendto_used_without_including_sys_socket_h
+#   undef setsockopt
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
+#   undef shutdown
+#   define shutdown            shutdown_used_without_including_sys_socket_h
+#  else
+    _GL_WARN_ON_USE (socket,
+                     "socket() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (connect,
+                     "connect() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (accept,
+                     "accept() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (bind,
+                     "bind() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getpeername,
+                     "getpeername() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockname,
+                     "getsockname() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockopt,
+                     "getsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (listen,
+                     "listen() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recv,
+                     "recv() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (send,
+                     "send() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recvfrom,
+                     "recvfrom() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (sendto,
+                     "sendto() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (setsockopt,
+                     "setsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (shutdown,
+                     "shutdown() used without including <sys/socket.h>");
+#  endif
+# endif
+#endif
+
+
+#if @GNULIB_PSELECT@
+# if @REPLACE_PSELECT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pselect
+#   define pselect rpl_pselect
+#  endif
+_GL_FUNCDECL_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+_GL_CXXALIAS_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+#  endif
+_GL_CXXALIAS_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# endif
+_GL_CXXALIASWARN (pselect);
+#elif defined GNULIB_POSIXCHECK
+# undef pselect
+# if HAVE_RAW_DECL_PSELECT
+_GL_WARN_ON_USE (pselect, "pselect is not portable - "
+                 "use gnulib module pselect for portability");
+# endif
+#endif
+
 #if @GNULIB_SELECT@
-# if @HAVE_WINSOCK2_H@ || @REPLACE_SELECT@
+# if @REPLACE_SELECT@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef select
 #   define select rpl_select
@@ -115,6 +279,6 @@ _GL_WARN_ON_USE (select, "select is not always POSIX 
compliant - "
 #endif
 
 
-#endif /* _GL_SYS_SELECT_H */
-#endif /* _GL_SYS_SELECT_H */
+#endif /* address@hidden@_SYS_SELECT_H */
+#endif /* address@hidden@_SYS_SELECT_H */
 #endif /* OSF/1 */
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index 8e12044..aba28f8 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -40,7 +40,7 @@
 #else
 /* Normal invocation convention.  */
 
-#ifndef _GL_SYS_SOCKET_H
+#ifndef address@hidden@_SYS_SOCKET_H
 
 #if @HAVE_SYS_SOCKET_H@
 
@@ -50,6 +50,10 @@
    <sys/types.h>.  */
 # include <sys/types.h>
 
+/* On FreeBSD 6.4, <sys/socket.h> defines some macros that assume that NULL
+   is defined.  */
+# include <stddef.h>
+
 /* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
 
@@ -57,8 +61,8 @@
 
 #endif
 
-#ifndef _GL_SYS_SOCKET_H
-#define _GL_SYS_SOCKET_H
+#ifndef address@hidden@_SYS_SOCKET_H
+#define address@hidden@_SYS_SOCKET_H
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
@@ -104,6 +108,12 @@ struct sockaddr_storage
 
 #endif
 
+/* Get struct iovec.  */
+/* But avoid namespace pollution on glibc systems.  */
+#if ! defined __GLIBC__
+# include <sys/uio.h>
+#endif
+
 #if @HAVE_SYS_SOCKET_H@
 
 /* A platform that has <sys/socket.h>.  */
@@ -142,7 +152,6 @@ struct sockaddr_storage
    suggests that getaddrinfo should be available on all Windows
    releases. */
 
-
 # if @HAVE_WINSOCK2_H@
 #  include <winsock2.h>
 # endif
@@ -173,8 +182,20 @@ typedef int socklen_t;
 
 # endif
 
+/* Rudimentary 'struct msghdr'; this works as long as you don't try to
+   access msg_control or msg_controllen.  */
+struct msghdr {
+  void *msg_name;
+  socklen_t msg_namelen;
+  struct iovec *msg_iov;
+  int msg_iovlen;
+  int msg_flags;
+};
+
 #endif
 
+/* Fix some definitions from <winsock2.h>.  */
+
 #if @HAVE_WINSOCK2_H@
 
 # if !GNULIB_defined_rpl_fd_isset
@@ -203,28 +224,38 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
 
 #endif
 
-/* Wrap everything else to use libc file descriptors for sockets.  */
+/* Hide some function declarations from <winsock2.h>.  */
 
-#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  undef close
-#  define close close_used_without_including_unistd_h
-# else
-   _GL_WARN_ON_USE (close,
-                    "close() used without including <unistd.h>");
+#if @HAVE_WINSOCK2_H@
+# if !defined address@hidden@_UNISTD_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef close
+#   define close close_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (close,
+                     "close() used without including <unistd.h>");
+#  endif
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gethostname
+#   define gethostname gethostname_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (gethostname,
+                     "gethostname() used without including <unistd.h>");
+#  endif
 # endif
-#endif
-
-#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  undef gethostname
-#  define gethostname gethostname_used_without_including_unistd_h
-# else
-   _GL_WARN_ON_USE (gethostname,
-                    "gethostname() used without including <unistd.h>");
+# if !defined address@hidden@_SYS_SELECT_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef select
+#   define select select_used_without_including_sys_select_h
+#  else
+    _GL_WARN_ON_USE (select,
+                     "select() used without including <sys/select.h>");
+#  endif
 # endif
 #endif
 
+/* Wrap everything else to use libc file descriptors for sockets.  */
+
 #if @GNULIB_SOCKET@
 # if @HAVE_WINSOCK2_H@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -614,16 +645,6 @@ _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX 
compliant - "
 # endif
 #endif
 
-#if @HAVE_WINSOCK2_H@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  undef select
-#  define select select_used_without_including_sys_select_h
-# else
-   _GL_WARN_ON_USE (select,
-                    "select() used without including <sys/select.h>");
-# endif
-#endif
-
 #if @GNULIB_ACCEPT4@
 /* Accept a connection on a socket, with specific opening flags.
    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
@@ -657,6 +678,6 @@ _GL_WARN_ON_USE (accept4, "accept4 is unportable - "
 # endif
 #endif
 
-#endif /* _GL_SYS_SOCKET_H */
-#endif /* _GL_SYS_SOCKET_H */
+#endif /* address@hidden@_SYS_SOCKET_H */
+#endif /* address@hidden@_SYS_SOCKET_H */
 #endif
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
index 61cdcc5..77a7177 100644
--- a/gl/sys_stat.in.h
+++ b/gl/sys_stat.in.h
@@ -34,7 +34,7 @@
 #else
 /* Normal invocation convention.  */
 
-#ifndef _GL_SYS_STAT_H
+#ifndef address@hidden@_SYS_STAT_H
 
 /* Get nlink_t.  */
 #include <sys/types.h>
@@ -45,8 +45,8 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_SYS_STAT_H@
 
-#ifndef _GL_SYS_STAT_H
-#define _GL_SYS_STAT_H
+#ifndef address@hidden@_SYS_STAT_H
+#define address@hidden@_SYS_STAT_H
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
@@ -55,10 +55,17 @@
 /* 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
+# ifdef _S_IFIFO
+#  define S_IFIFO _S_IFIFO
+# endif
 #endif
 
 #ifndef S_IFMT
@@ -312,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@
@@ -355,7 +371,11 @@ _GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
 
 
 #if @GNULIB_FUTIMENS@
-# if @REPLACE_FUTIMENS@
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
+   implementation relies on futimesat, which on Solaris 10 makes an invocation
+   to futimens that is meant to invoke the libc's futimens(), not gnulib's
+   futimens().  */
+# if @REPLACE_FUTIMENS@ || (address@hidden@ && defined __sun)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef futimens
 #   define futimens rpl_futimens
@@ -368,7 +388,9 @@ _GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec 
const times[2]));
 #  endif
 _GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
 # endif
+# if @HAVE_FUTIMENS@
 _GL_CXXALIASWARN (futimens);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef futimens
 # if HAVE_RAW_DECL_FUTIMENS
@@ -612,7 +634,11 @@ _GL_WARN_ON_USE (stat, "stat is unportable - "
 
 
 #if @GNULIB_UTIMENSAT@
-# if @REPLACE_UTIMENSAT@
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
+   implementation relies on futimesat, which on Solaris 10 makes an invocation
+   to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
+   utimensat().  */
+# if @REPLACE_UTIMENSAT@ || (address@hidden@ && defined __sun)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef utimensat
 #   define utimensat rpl_utimensat
@@ -631,7 +657,9 @@ _GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
 _GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
                                    struct timespec const times[2], int flag));
 # endif
+# if @HAVE_UTIMENSAT@
 _GL_CXXALIASWARN (utimensat);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef utimensat
 # if HAVE_RAW_DECL_UTIMENSAT
@@ -641,6 +669,6 @@ _GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
 #endif
 
 
-#endif /* _GL_SYS_STAT_H */
-#endif /* _GL_SYS_STAT_H */
+#endif /* address@hidden@_SYS_STAT_H */
+#endif /* address@hidden@_SYS_STAT_H */
 #endif
diff --git a/gl/sys_time.in.h b/gl/sys_time.in.h
index d4319d2..db4eeae 100644
--- a/gl/sys_time.in.h
+++ b/gl/sys_time.in.h
@@ -23,7 +23,7 @@
 #endif
 @PRAGMA_COLUMNS@
 
-#if defined _GL_SYS_TIME_H
+#if defined address@hidden@_SYS_TIME_H
 
 /* Simply delegate to the system's header, without adding anything.  */
 # if @HAVE_SYS_TIME_H@
@@ -32,7 +32,7 @@
 
 #else
 
-# define _GL_SYS_TIME_H
+# define address@hidden@_SYS_TIME_H
 
 # if @HAVE_SYS_TIME_H@
 #  @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
@@ -40,6 +40,14 @@
 #  include <time.h>
 # endif
 
+/* On native Windows with MSVC:
+   Get the 'struct timeval' type.  */
+# if defined _MSC_VER && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
+#  define _GL_INCLUDING_WINSOCK2_H
+#  include <winsock2.h>
+#  undef _GL_INCLUDING_WINSOCK2_H
+# endif
+
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
 /* The definition of _GL_ARG_NONNULL is copied here.  */
@@ -98,4 +106,95 @@ _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable 
- "
 #  endif
 # endif
 
-#endif /* _GL_SYS_TIME_H */
+/* Hide some function declarations from <winsock2.h>.  */
+
+# if defined _MSC_VER && @HAVE_WINSOCK2_H@
+#  if !defined address@hidden@_UNISTD_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef close
+#    define close close_used_without_including_unistd_h
+#   else
+     _GL_WARN_ON_USE (close,
+                      "close() used without including <unistd.h>");
+#   endif
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef gethostname
+#    define gethostname gethostname_used_without_including_unistd_h
+#   else
+     _GL_WARN_ON_USE (gethostname,
+                      "gethostname() used without including <unistd.h>");
+#   endif
+#  endif
+#  if !defined address@hidden@_SYS_SOCKET_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef socket
+#    define socket              socket_used_without_including_sys_socket_h
+#    undef connect
+#    define connect             connect_used_without_including_sys_socket_h
+#    undef accept
+#    define accept              accept_used_without_including_sys_socket_h
+#    undef bind
+#    define bind                bind_used_without_including_sys_socket_h
+#    undef getpeername
+#    define getpeername         getpeername_used_without_including_sys_socket_h
+#    undef getsockname
+#    define getsockname         getsockname_used_without_including_sys_socket_h
+#    undef getsockopt
+#    define getsockopt          getsockopt_used_without_including_sys_socket_h
+#    undef listen
+#    define listen              listen_used_without_including_sys_socket_h
+#    undef recv
+#    define recv                recv_used_without_including_sys_socket_h
+#    undef send
+#    define send                send_used_without_including_sys_socket_h
+#    undef recvfrom
+#    define recvfrom            recvfrom_used_without_including_sys_socket_h
+#    undef sendto
+#    define sendto              sendto_used_without_including_sys_socket_h
+#    undef setsockopt
+#    define setsockopt          setsockopt_used_without_including_sys_socket_h
+#    undef shutdown
+#    define shutdown            shutdown_used_without_including_sys_socket_h
+#   else
+     _GL_WARN_ON_USE (socket,
+                      "socket() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (connect,
+                      "connect() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (accept,
+                      "accept() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (bind,
+                      "bind() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getpeername,
+                      "getpeername() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getsockname,
+                      "getsockname() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (getsockopt,
+                      "getsockopt() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (listen,
+                      "listen() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (recv,
+                      "recv() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (send,
+                      "send() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (recvfrom,
+                      "recvfrom() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (sendto,
+                      "sendto() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (setsockopt,
+                      "setsockopt() used without including <sys/socket.h>");
+     _GL_WARN_ON_USE (shutdown,
+                      "shutdown() used without including <sys/socket.h>");
+#   endif
+#  endif
+#  if !defined address@hidden@_SYS_SELECT_H
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef select
+#    define select select_used_without_including_sys_select_h
+#   else
+     _GL_WARN_ON_USE (select,
+                      "select() used without including <sys/select.h>");
+#   endif
+#  endif
+# endif
+
+#endif /* address@hidden@_SYS_TIME_H */
diff --git a/gl/sys_types.in.h b/gl/sys_types.in.h
new file mode 100644
index 0000000..63389de
--- /dev/null
+++ b/gl/sys_types.in.h
@@ -0,0 +1,40 @@
+/* Provide a more complete sys/types.h.
+
+   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.  */
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#ifndef address@hidden@_SYS_TYPES_H
+
+/* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_SYS_TYPES_H@
+
+#ifndef address@hidden@_SYS_TYPES_H
+#define address@hidden@_SYS_TYPES_H
+
+/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>.  */
+/* But avoid namespace pollution on glibc systems.  */
+#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
+    && ! defined __GLIBC__
+# include <stddef.h>
+#endif
+
+#endif /* address@hidden@_SYS_TYPES_H */
+#endif /* address@hidden@_SYS_TYPES_H */
diff --git a/gl/sys_uio.in.h b/gl/sys_uio.in.h
new file mode 100644
index 0000000..6995e6c
--- /dev/null
+++ b/gl/sys_uio.in.h
@@ -0,0 +1,64 @@
+/* Substitute for <sys/uio.h>.
+   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.  */
+
+# if __GNUC__ >= 3
address@hidden@
+# endif
address@hidden@
+
+#ifndef address@hidden@_SYS_UIO_H
+
+#if @HAVE_SYS_UIO_H@
+
+/* On OpenBSD 4.4, <sys/uio.h> assumes prior inclusion of <sys/types.h>.  */
+# include <sys/types.h>
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_SYS_UIO_H@
+
+#endif
+
+#ifndef address@hidden@_SYS_UIO_H
+#define address@hidden@_SYS_UIO_H
+
+#if address@hidden@
+/* A platform that lacks <sys/uio.h>.  */
+/* Get 'size_t' and 'ssize_t'.  */
+# include <sys/types.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if !GNULIB_defined_struct_iovec
+/* All known platforms that lack <sys/uio.h> also lack any declaration
+   of struct iovec in any other header.  */
+struct iovec {
+  void *iov_base;
+  size_t iov_len;
+};
+#  define GNULIB_defined_struct_iovec 1
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+#endif /* address@hidden@_SYS_UIO_H */
+#endif /* address@hidden@_SYS_UIO_H */
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index 33da277..2facbe6 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -2,15 +2,27 @@
 ## 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.
 
-AUTOMAKE_OPTIONS = 1.5 foreign
+AUTOMAKE_OPTIONS = 1.5 foreign subdir-objects
 
 SUBDIRS = .
 TESTS =
@@ -46,6 +58,15 @@ AM_LIBTOOLFLAGS = --preserve-dup-deps
 
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 
+## begin gnulib module accept-tests
+
+TESTS += test-accept
+check_PROGRAMS += test-accept
+test_accept_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-accept.c signature.h macros.h
+
+## end   gnulib module accept-tests
+
 ## begin gnulib module alignof-tests
 
 TESTS += test-alignof
@@ -64,30 +85,6 @@ EXTRA_DIST += test-alloca-opt.c
 
 ## end   gnulib module alloca-opt-tests
 
-## begin gnulib module arg-nonnull
-
-# The BUILT_SOURCES created by this Makefile snippet are not used via #include
-# statements but through direct file reference. Therefore this snippet must be
-# present in all Makefile.am that need it. This is ensured by the applicability
-# 'all' defined above.
-
-BUILT_SOURCES += arg-nonnull.h
-# The arg-nonnull.h that gets inserted into generated .h files is the same as
-# build-aux/arg-nonnull.h, except that it has the copyright header cut off.
-arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h
-       $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/GL_ARG_NONNULL/,$$p' \
-         < $(top_srcdir)/build-aux/arg-nonnull.h \
-         > address@hidden && \
-       mv address@hidden $@
-MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
-
-ARG_NONNULL_H=arg-nonnull.h
-
-EXTRA_DIST += $(top_srcdir)/build-aux/arg-nonnull.h
-
-## end   gnulib module arg-nonnull
-
 ## begin gnulib module arpa_inet-tests
 
 TESTS += test-arpa_inet
@@ -111,29 +108,14 @@ EXTRA_DIST += test-binary-io.sh test-binary-io.c macros.h
 
 ## end   gnulib module binary-io-tests
 
-## begin gnulib module c++defs
+## begin gnulib module bind-tests
 
-# The BUILT_SOURCES created by this Makefile snippet are not used via #include
-# statements but through direct file reference. Therefore this snippet must be
-# present in all Makefile.am that need it. This is ensured by the applicability
-# 'all' defined above.
+TESTS += test-bind
+check_PROGRAMS += test-bind
+test_bind_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+EXTRA_DIST += test-bind.c signature.h macros.h
 
-BUILT_SOURCES += c++defs.h
-# The c++defs.h that gets inserted into generated .h files is the same as
-# build-aux/c++defs.h, except that it has the copyright header cut off.
-c++defs.h: $(top_srcdir)/build-aux/c++defs.h
-       $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/_GL_CXXDEFS/,$$p' \
-         < $(top_srcdir)/build-aux/c++defs.h \
-         > address@hidden && \
-       mv address@hidden $@
-MOSTLYCLEANFILES += c++defs.h c++defs.h-t
-
-CXXDEFS_H=c++defs.h
-
-EXTRA_DIST += $(top_srcdir)/build-aux/c++defs.h
-
-## end   gnulib module c++defs
+## end   gnulib module bind-tests
 
 ## begin gnulib module c-ctype-tests
 
@@ -144,6 +126,47 @@ EXTRA_DIST += test-c-ctype.c macros.h
 
 ## end   gnulib module c-ctype-tests
 
+## 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 connect-tests
+
+TESTS += test-connect
+check_PROGRAMS += test-connect
+test_connect_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+EXTRA_DIST += test-connect.c signature.h macros.h
+
+## end   gnulib module connect-tests
+
+## begin gnulib module dosname
+
+
+EXTRA_DIST += dosname.h
+
+## end   gnulib module dosname
+
+## begin gnulib module dup2
+
+
+EXTRA_DIST += dup2.c
+
+EXTRA_libtests_a_SOURCES += dup2.c
+
+## end   gnulib module dup2
+
+## begin gnulib module dup2-tests
+
+TESTS += test-dup2
+check_PROGRAMS += test-dup2
+EXTRA_DIST += test-dup2.c signature.h macros.h
+
+## end   gnulib module dup2-tests
+
 ## begin gnulib module errno-tests
 
 TESTS += test-errno
@@ -159,16 +182,18 @@ BUILT_SOURCES += fcntl.h
 
 # We need the following in order to create <fcntl.h> when the system
 # doesn't have one that works with the given compiler.
-fcntl.h: fcntl.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
-             -e 's|@''GNULIB_FCNTL''@|$(GNULIB_FCNTL)|g' \
-             -e 's|@''GNULIB_OPEN''@|$(GNULIB_OPEN)|g' \
-             -e 's|@''GNULIB_OPENAT''@|$(GNULIB_OPENAT)|g' \
+             -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
+             -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
+             -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
+             -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
              -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
              -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
              -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
@@ -194,23 +219,129 @@ 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
+check_PROGRAMS += test-fdopen
+EXTRA_DIST += test-fdopen.c signature.h macros.h
+
+## end   gnulib module fdopen-tests
+
+## begin gnulib module fgetc-tests
+
+TESTS += test-fgetc
+check_PROGRAMS += test-fgetc
+EXTRA_DIST += test-fgetc.c signature.h macros.h
+
+## end   gnulib module fgetc-tests
+
+## begin gnulib module float-tests
+
+TESTS += test-float
+check_PROGRAMS += test-float
+EXTRA_DIST += test-float.c macros.h
+
+## end   gnulib module float-tests
+
+## begin gnulib module fpucw
+
+
+EXTRA_DIST += fpucw.h
+
+## end   gnulib module fpucw
+
+## 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 fseek-tests
+
+TESTS += test-fseek.sh test-fseek2.sh
+check_PROGRAMS += test-fseek
+EXTRA_DIST += test-fseek.c test-fseek.sh test-fseek2.sh signature.h macros.h
+
+## end   gnulib module fseek-tests
+
 ## begin gnulib module fseeko-tests
 
-TESTS += test-fseeko.sh test-fseeko2.sh
-check_PROGRAMS += test-fseeko
-EXTRA_DIST += test-fseeko.c test-fseeko.sh test-fseeko2.sh signature.h macros.h
+TESTS += test-fseeko.sh test-fseeko2.sh test-fseeko3.sh test-fseeko4.sh
+check_PROGRAMS += test-fseeko test-fseeko3 test-fseeko4
+EXTRA_DIST += test-fseeko.c test-fseeko.sh test-fseeko2.sh test-fseeko3.c 
test-fseeko3.sh test-fseeko4.c test-fseeko4.sh signature.h macros.h
 
 ## end   gnulib module fseeko-tests
 
+## begin gnulib module fstat-tests
+
+TESTS += test-fstat
+check_PROGRAMS += test-fstat
+EXTRA_DIST += test-fstat.c signature.h macros.h
+
+## end   gnulib module fstat-tests
+
+## begin gnulib module ftell-tests
+
+TESTS += test-ftell.sh test-ftell2.sh test-ftell3
+check_PROGRAMS += test-ftell test-ftell3
+MOSTLYCLEANFILES += t-ftell3.tmp
+EXTRA_DIST += test-ftell.c test-ftell.sh test-ftell2.sh test-ftell3.c 
signature.h macros.h
+
+## end   gnulib module ftell-tests
+
 ## begin gnulib module ftello-tests
 
-TESTS += test-ftello.sh test-ftello2.sh test-ftello3
-check_PROGRAMS += test-ftello test-ftello3
+TESTS += test-ftello.sh test-ftello2.sh test-ftello3 test-ftello4.sh
+check_PROGRAMS += test-ftello test-ftello3 test-ftello4
 MOSTLYCLEANFILES += t-ftello3.tmp
-EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh test-ftello3.c 
signature.h macros.h
+EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh test-ftello3.c 
test-ftello4.c test-ftello4.sh signature.h macros.h
 
 ## end   gnulib module ftello-tests
 
+## begin gnulib module ftruncate
+
+
+EXTRA_DIST += ftruncate.c
+
+EXTRA_libtests_a_SOURCES += ftruncate.c
+
+## end   gnulib module ftruncate
+
+## begin gnulib module ftruncate-tests
+
+TESTS += test-ftruncate.sh
+check_PROGRAMS += test-ftruncate
+EXTRA_DIST += test-ftruncate.c test-ftruncate.sh signature.h macros.h
+
+## end   gnulib module ftruncate-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 getaddrinfo-tests
 
 TESTS += test-getaddrinfo
@@ -220,6 +351,23 @@ EXTRA_DIST += signature.h test-getaddrinfo.c
 
 ## end   gnulib module getaddrinfo-tests
 
+## begin gnulib module getcwd-lgpl
+
+
+EXTRA_DIST += getcwd-lgpl.c
+
+EXTRA_libtests_a_SOURCES += getcwd-lgpl.c
+
+## end   gnulib module getcwd-lgpl
+
+## begin gnulib module getcwd-lgpl-tests
+
+TESTS += test-getcwd-lgpl
+check_PROGRAMS += test-getcwd-lgpl
+EXTRA_DIST += test-getcwd-lgpl.c signature.h macros.h
+
+## end   gnulib module getcwd-lgpl-tests
+
 ## begin gnulib module getdelim-tests
 
 TESTS += test-getdelim
@@ -256,6 +404,21 @@ EXTRA_DIST += signature.h test-gettimeofday.c
 
 ## end   gnulib module gettimeofday-tests
 
+## begin gnulib module ignore-value
+
+
+EXTRA_DIST += ignore-value.h
+
+## end   gnulib module ignore-value
+
+## begin gnulib module ignore-value-tests
+
+TESTS += test-ignore-value
+check_PROGRAMS += test-ignore-value
+EXTRA_DIST += test-ignore-value.c
+
+## end   gnulib module ignore-value-tests
+
 ## begin gnulib module inet_ntop-tests
 
 TESTS += test-inet_ntop
@@ -274,6 +437,64 @@ EXTRA_DIST += test-inet_pton.c signature.h macros.h
 
 ## end   gnulib module inet_pton-tests
 
+## begin gnulib module intprops-tests
+
+TESTS += test-intprops
+check_PROGRAMS += test-intprops
+EXTRA_DIST += test-intprops.c macros.h
+
+## end   gnulib module intprops-tests
+
+## begin gnulib module inttypes-incomplete
+
+BUILT_SOURCES += inttypes.h
+
+# We need the following in order to create <inttypes.h> when the system
+# doesn't have one that works with the given compiler.
+inttypes.h: inttypes.in.h $(top_builddir)/config.status $(WARN_ON_USE_H) 
$(ARG_NONNULL_H)
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_INTTYPES_H''@|$(NEXT_INTTYPES_H)|g' \
+             -e 's/@''PRI_MACROS_BROKEN''@/$(PRI_MACROS_BROKEN)/g' \
+             -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
+             -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \
+             -e 
's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \
+             -e 's/@''PRIPTR_PREFIX''@/$(PRIPTR_PREFIX)/g' \
+             -e 's/@''GNULIB_IMAXABS''@/$(GNULIB_IMAXABS)/g' \
+             -e 's/@''GNULIB_IMAXDIV''@/$(GNULIB_IMAXDIV)/g' \
+             -e 's/@''GNULIB_STRTOIMAX''@/$(GNULIB_STRTOIMAX)/g' \
+             -e 's/@''GNULIB_STRTOUMAX''@/$(GNULIB_STRTOUMAX)/g' \
+             -e 's/@''HAVE_DECL_IMAXABS''@/$(HAVE_DECL_IMAXABS)/g' \
+             -e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
+             -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
+             -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
+             -e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' 
\
+             -e 's/@''INT64_MAX_EQ_LONG_MAX''@/$(INT64_MAX_EQ_LONG_MAX)/g' \
+             -e 
's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \
+             -e 's/@''UINT64_MAX_EQ_ULONG_MAX''@/$(UINT64_MAX_EQ_ULONG_MAX)/g' 
\
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/inttypes.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += inttypes.h inttypes.h-t
+
+EXTRA_DIST += inttypes.in.h
+
+## end   gnulib module inttypes-incomplete
+
+## begin gnulib module inttypes-tests
+
+TESTS += test-inttypes
+check_PROGRAMS += test-inttypes
+EXTRA_DIST += test-inttypes.c
+
+## end   gnulib module inttypes-tests
+
 ## begin gnulib module ioctl
 
 
@@ -283,6 +504,32 @@ EXTRA_libtests_a_SOURCES += ioctl.c
 
 ## end   gnulib module ioctl
 
+## begin gnulib module ioctl-tests
+
+TESTS += test-ioctl
+check_PROGRAMS += test-ioctl
+EXTRA_DIST += test-ioctl.c signature.h macros.h
+
+## end   gnulib module ioctl-tests
+
+## begin gnulib module listen-tests
+
+TESTS += test-listen
+check_PROGRAMS += test-listen
+test_listen_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-listen.c signature.h macros.h
+
+## end   gnulib module listen-tests
+
+## begin gnulib module lock-tests
+
+TESTS += test-lock
+check_PROGRAMS += test-lock
+test_lock_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+EXTRA_DIST += test-lock.c
+
+## end   gnulib module lock-tests
+
 ## begin gnulib module lseek-tests
 
 TESTS += test-lseek.sh
@@ -291,6 +538,23 @@ EXTRA_DIST += test-lseek.c test-lseek.sh signature.h 
macros.h
 
 ## end   gnulib module lseek-tests
 
+## begin gnulib module lstat
+
+
+EXTRA_DIST += lstat.c
+
+EXTRA_libtests_a_SOURCES += lstat.c
+
+## end   gnulib module lstat
+
+## begin gnulib module lstat-tests
+
+TESTS += test-lstat
+check_PROGRAMS += test-lstat
+EXTRA_DIST += test-lstat.h test-lstat.c signature.h macros.h
+
+## end   gnulib module lstat-tests
+
 ## begin gnulib module memchr-tests
 
 TESTS += test-memchr
@@ -315,11 +579,43 @@ EXTRA_DIST += test-netinet_in.c
 
 ## end   gnulib module netinet_in-tests
 
+## begin gnulib module open
+
+
+EXTRA_DIST += open.c
+
+EXTRA_libtests_a_SOURCES += open.c
+
+## end   gnulib module open
+
+## begin gnulib module open-tests
+
+TESTS += test-open
+check_PROGRAMS += test-open
+EXTRA_DIST += test-open.h test-open.c signature.h macros.h
+
+## end   gnulib module open-tests
+
+## begin gnulib module pathmax
+
+
+EXTRA_DIST += pathmax.h
+
+## end   gnulib module pathmax
+
+## begin gnulib module pathmax-tests
+
+TESTS += test-pathmax
+check_PROGRAMS += test-pathmax
+EXTRA_DIST += test-pathmax.c
+
+## end   gnulib module pathmax-tests
+
 ## begin gnulib module perror-tests
 
-TESTS += test-perror.sh
-check_PROGRAMS += test-perror
-EXTRA_DIST += signature.h test-perror.c test-perror.sh
+TESTS += test-perror.sh test-perror2
+check_PROGRAMS += test-perror test-perror2
+EXTRA_DIST += init.sh macros.h signature.h test-perror.c test-perror2.c 
test-perror.sh
 
 ## end   gnulib module perror-tests
 
@@ -348,18 +644,150 @@ EXTRA_DIST += test-read-file.c
 
 ## end   gnulib module read-file-tests
 
+## begin gnulib module recv-tests
+
+TESTS += test-recv
+check_PROGRAMS += test-recv
+test_recv_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-recv.c signature.h macros.h
+
+## end   gnulib module recv-tests
+
+## begin gnulib module same-inode
+
+
+EXTRA_DIST += same-inode.h
+
+## end   gnulib module same-inode
+
 ## begin gnulib module select-tests
 
 TESTS += test-select test-select-in.sh test-select-out.sh
 # test-select-stdin has to be run by hand.
 check_PROGRAMS += test-select test-select-fd test-select-stdin
-test_select_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
-test_select_fd_LDADD = $(LDADD) @LIBSOCKET@
-test_select_stdin_LDADD = $(LDADD) @LIBSOCKET@
-EXTRA_DIST += macros.h signature.h test-select.c test-select-fd.c 
test-select-in.sh test-select-out.sh test-select-stdin.c
+test_select_LDADD = $(LDADD) @LIB_SELECT@ @LIBSOCKET@ $(INET_PTON_LIB)
+test_select_fd_LDADD = $(LDADD) @LIB_SELECT@
+test_select_stdin_LDADD = $(LDADD) @LIB_SELECT@
+EXTRA_DIST += macros.h signature.h test-select.c test-select.h 
test-select-fd.c test-select-in.sh test-select-out.sh test-select-stdin.c
 
 ## end   gnulib module select-tests
 
+## begin gnulib module send-tests
+
+TESTS += test-send
+check_PROGRAMS += test-send
+test_send_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-send.c signature.h macros.h
+
+## end   gnulib module send-tests
+
+## begin gnulib module setsockopt-tests
+
+TESTS += test-setsockopt
+check_PROGRAMS += test-setsockopt
+test_setsockopt_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-setsockopt.c signature.h macros.h
+
+## end   gnulib module setsockopt-tests
+
+## begin gnulib module shutdown-tests
+
+TESTS += test-shutdown
+check_PROGRAMS += test-shutdown
+test_shutdown_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-shutdown.c signature.h macros.h
+
+## end   gnulib module shutdown-tests
+
+## begin gnulib module signal-h-tests
+
+TESTS += test-signal-h
+check_PROGRAMS += test-signal-h
+EXTRA_DIST += test-signal-h.c
+
+## end   gnulib module signal-h-tests
+
+## begin gnulib module snippet/_Noreturn
+
+# Because this Makefile snippet defines a variable used by other
+# gnulib Makefile snippets, it must be present in all Makefile.am that
+# need it. This is ensured by the applicability 'all' defined above.
+
+_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h
+
+## end   gnulib module snippet/_Noreturn
+
+## begin gnulib module snippet/arg-nonnull
+
+# The BUILT_SOURCES created by this Makefile snippet are not used via #include
+# statements but through direct file reference. Therefore this snippet must be
+# present in all Makefile.am that need it. This is ensured by the applicability
+# 'all' defined above.
+
+BUILT_SOURCES += arg-nonnull.h
+# The arg-nonnull.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut
+# off.
+arg-nonnull.h: $(top_srcdir)/build-aux/snippet/arg-nonnull.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/GL_ARG_NONNULL/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/arg-nonnull.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
+
+ARG_NONNULL_H=arg-nonnull.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h
+
+## end   gnulib module snippet/arg-nonnull
+
+## begin gnulib module snippet/c++defs
+
+# The BUILT_SOURCES created by this Makefile snippet are not used via #include
+# statements but through direct file reference. Therefore this snippet must be
+# present in all Makefile.am that need it. This is ensured by the applicability
+# 'all' defined above.
+
+BUILT_SOURCES += c++defs.h
+# The c++defs.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/c++defs.h, except that it has the copyright header cut off.
+c++defs.h: $(top_srcdir)/build-aux/snippet/c++defs.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/_GL_CXXDEFS/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/c++defs.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += c++defs.h c++defs.h-t
+
+CXXDEFS_H=c++defs.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h
+
+## end   gnulib module snippet/c++defs
+
+## begin gnulib module snippet/warn-on-use
+
+BUILT_SOURCES += warn-on-use.h
+# The warn-on-use.h that gets inserted into generated .h files is the same as
+# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut
+# off.
+warn-on-use.h: $(top_srcdir)/build-aux/snippet/warn-on-use.h
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       sed -n -e '/^.ifndef/,$$p' \
+         < $(top_srcdir)/build-aux/snippet/warn-on-use.h \
+         > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
+
+WARN_ON_USE_H=warn-on-use.h
+
+EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h
+
+## end   gnulib module snippet/warn-on-use
+
 ## begin gnulib module snprintf-tests
 
 TESTS += test-snprintf
@@ -378,6 +806,23 @@ EXTRA_DIST += test-sockets.c
 
 ## end   gnulib module sockets-tests
 
+## begin gnulib module stat
+
+
+EXTRA_DIST += stat.c
+
+EXTRA_libtests_a_SOURCES += stat.c
+
+## end   gnulib module stat
+
+## begin gnulib module stat-tests
+
+TESTS += test-stat
+check_PROGRAMS += test-stat
+EXTRA_DIST += test-stat.h test-stat.c signature.h macros.h
+
+## end   gnulib module stat-tests
+
 ## begin gnulib module stdbool-tests
 
 TESTS += test-stdbool
@@ -426,6 +871,14 @@ EXTRA_DIST += test-strerror.c signature.h macros.h
 
 ## end   gnulib module strerror-tests
 
+## begin gnulib module strerror_r-posix-tests
+
+TESTS += test-strerror_r
+check_PROGRAMS += test-strerror_r
+EXTRA_DIST += test-strerror_r.c signature.h macros.h
+
+## end   gnulib module strerror_r-posix-tests
+
 ## begin gnulib module string-tests
 
 TESTS += test-string
@@ -434,22 +887,40 @@ EXTRA_DIST += test-string.c
 
 ## end   gnulib module string-tests
 
+## begin gnulib module symlink
+
+
+EXTRA_DIST += symlink.c
+
+EXTRA_libtests_a_SOURCES += symlink.c
+
+## end   gnulib module symlink
+
+## begin gnulib module symlink-tests
+
+TESTS += test-symlink
+check_PROGRAMS += test-symlink
+EXTRA_DIST += test-symlink.h test-symlink.c signature.h macros.h
+
+## end   gnulib module symlink-tests
+
 ## begin gnulib module sys_ioctl
 
 BUILT_SOURCES += sys/ioctl.h
 
 # We need the following in order to create <sys/ioctl.h> when the system
 # does not have a complete one.
-sys/ioctl.h: sys_ioctl.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         sed -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
-             -e 's|@''GNULIB_IOCTL''@|$(GNULIB_IOCTL)|g' \
+             -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
              -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
              -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g'
 \
              -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
@@ -477,7 +948,7 @@ EXTRA_DIST += test-sys_ioctl.c
 
 TESTS += test-sys_select
 check_PROGRAMS += test-sys_select
-EXTRA_DIST += test-sys_select.c
+EXTRA_DIST += test-sys_select.c signature.h
 
 ## end   gnulib module sys_select-tests
 
@@ -505,6 +976,38 @@ EXTRA_DIST += test-sys_time.c
 
 ## end   gnulib module sys_time-tests
 
+## begin gnulib module sys_types-tests
+
+TESTS += test-sys_types
+check_PROGRAMS += test-sys_types
+EXTRA_DIST += test-sys_types.c
+
+## end   gnulib module sys_types-tests
+
+## begin gnulib module sys_uio-tests
+
+TESTS += test-sys_uio
+check_PROGRAMS += test-sys_uio
+EXTRA_DIST += test-sys_uio.c
+
+## end   gnulib module sys_uio-tests
+
+## begin gnulib module thread
+
+libtests_a_SOURCES += glthread/thread.h glthread/thread.c
+
+## end   gnulib module thread
+
+## begin gnulib module thread-tests
+
+TESTS += test-thread_self test-thread_create
+check_PROGRAMS += test-thread_self test-thread_create
+test_thread_self_LDADD = $(LDADD) @LIBTHREAD@
+test_thread_create_LDADD = $(LDADD) @LIBMULTITHREAD@
+EXTRA_DIST += test-thread_self.c test-thread_create.c macros.h
+
+## end   gnulib module thread-tests
+
 ## begin gnulib module time-tests
 
 TESTS += test-time
@@ -565,30 +1068,19 @@ EXTRA_DIST += test-version-etc.c test-version-etc.sh
 
 ## end   gnulib module version-etc-tests
 
-## begin gnulib module warn-on-use
-
-BUILT_SOURCES += warn-on-use.h
-# The warn-on-use.h that gets inserted into generated .h files is the same as
-# build-aux/warn-on-use.h, except that it has the copyright header cut off.
-warn-on-use.h: $(top_srcdir)/build-aux/warn-on-use.h
-       $(AM_V_GEN)rm -f address@hidden $@ && \
-       sed -n -e '/^.ifndef/,$$p' \
-         < $(top_srcdir)/build-aux/warn-on-use.h \
-         > address@hidden && \
-       mv address@hidden $@
-MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
-
-WARN_ON_USE_H=warn-on-use.h
+## begin gnulib module wchar-tests
 
-EXTRA_DIST += $(top_srcdir)/build-aux/warn-on-use.h
+TESTS += test-wchar
+check_PROGRAMS += test-wchar
+EXTRA_DIST += test-wchar.c
 
-## end   gnulib module warn-on-use
+## end   gnulib module wchar-tests
 
-## begin gnulib module dummy
+## begin gnulib module yield
 
-libtests_a_SOURCES += dummy.c
+libtests_a_SOURCES += glthread/yield.h
 
-## end   gnulib module dummy
+## end   gnulib module yield
 
 # Clean up after Solaris cc.
 clean-local:
diff --git a/gl/tests/dosname.h b/gl/tests/dosname.h
new file mode 100644
index 0000000..acdd03b
--- /dev/null
+++ b/gl/tests/dosname.h
@@ -0,0 +1,53 @@
+/* File names on MS-DOS/Windows systems.
+
+   Copyright (C) 2000-2001, 2004-2006, 2009-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/>.
+
+   From Paul Eggert and Jim Meyering.  */
+
+#ifndef _DOSNAME_H
+#define _DOSNAME_H
+
+#if (defined _WIN32 || defined __WIN32__ ||     \
+     defined __MSDOS__ || defined __CYGWIN__ || \
+     defined __EMX__ || defined __DJGPP__)
+   /* This internal macro assumes ASCII, but all hosts that support drive
+      letters use ASCII.  */
+# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a'  \
+                              <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(Filename) \
+          (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
+# ifndef __CYGWIN__
+#  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
+# endif
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#else
+# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
+# define ISSLASH(C) ((C) == '/')
+#endif
+
+#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
+#endif
+
+#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+#  define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
+# else
+#  define IS_ABSOLUTE_FILE_NAME(F)                              \
+     (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
+#endif
+#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
+
+#endif /* DOSNAME_H_ */
diff --git a/gl/tests/dummy.c b/gl/tests/dummy.c
deleted file mode 100644
index c958ea0..0000000
--- a/gl/tests/dummy.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* A dummy file, to prevent empty libraries from breaking builds.
-   Copyright (C) 2004, 2007, 2009-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/>.  */
-
-/* Some systems, reportedly OpenBSD and Mac OS X, refuse to create
-   libraries without any object files.  You might get an error like:
-
-   > ar cru .libs/libgl.a
-   > ar: no archive members specified
-
-   Compiling this file, and adding its object file to the library, will
-   prevent the library from being empty.  */
-
-/* Some systems, such as Solaris with cc 5.0, refuse to work with libraries
-   that don't export any symbol.  You might get an error like:
-
-   > cc ... libgnu.a
-   > ild: (bad file) garbled symbol table in archive ../gllib/libgnu.a
-
-   Compiling this file, and adding its object file to the library, will
-   prevent the library from exporting no symbols.  */
-
-#ifdef __sun
-/* This declaration ensures that the library will export at least 1 symbol.  */
-int gl_dummy_symbol;
-#else
-/* This declaration is solely to ensure that after preprocessing
-   this file is never empty.  */
-typedef int dummy;
-#endif
diff --git a/gl/tests/dup2.c b/gl/tests/dup2.c
new file mode 100644
index 0000000..790c98a
--- /dev/null
+++ b/gl/tests/dup2.c
@@ -0,0 +1,157 @@
+/* Duplicate an open file descriptor to a specified file descriptor.
+
+   Copyright (C) 1999, 2004-2007, 2009-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/>.  */
+
+/* written by Paul Eggert */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+
+#if HAVE_DUP2
+
+# undef dup2
+
+# 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 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)
+    {
+      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)
+    {
+      errno = EBADF;
+      return -1;
+    }
+
+  TRY_MSVC_INVAL
+    {
+      result = dup2 (fd, desired_fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      errno = EBADF;
+      result = -1;
+    }
+  DONE_MSVC_INVAL;
+
+  if (result == 0)
+    result = desired_fd;
+
+  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)
+    result = _gl_register_dup (fd, result);
+# endif
+  return result;
+}
+
+#else /* !HAVE_DUP2 */
+
+/* On older platforms, dup2 did not exist.  */
+
+# ifndef F_DUPFD
+static int
+dupfd (int fd, int desired_fd)
+{
+  int duplicated_fd = dup (fd);
+  if (duplicated_fd < 0 || duplicated_fd == desired_fd)
+    return duplicated_fd;
+  else
+    {
+      int r = dupfd (fd, desired_fd);
+      int e = errno;
+      close (duplicated_fd);
+      errno = e;
+      return r;
+    }
+}
+# endif
+
+int
+dup2 (int fd, int desired_fd)
+{
+  int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
+  if (result == -1 || fd == desired_fd)
+    return result;
+  close (desired_fd);
+# ifdef F_DUPFD
+  result = fcntl (fd, F_DUPFD, desired_fd);
+#  if REPLACE_FCHDIR
+  if (0 <= result)
+    result = _gl_register_dup (fd, result);
+#  endif
+# else
+  result = dupfd (fd, desired_fd);
+# endif
+  if (result == -1 && (errno == EMFILE || errno == EINVAL))
+    errno = EBADF;
+  return result;
+}
+#endif /* !HAVE_DUP2 */
diff --git a/gl/tests/fcntl.in.h b/gl/tests/fcntl.in.h
index 18cac45..0a07221 100644
--- a/gl/tests/fcntl.in.h
+++ b/gl/tests/fcntl.in.h
@@ -40,7 +40,7 @@
 #else
 /* Normal invocation convention.  */
 
-#ifndef _GL_FCNTL_H
+#ifndef address@hidden@_FCNTL_H
 
 #include <sys/types.h>
 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
@@ -55,8 +55,8 @@
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_FCNTL_H@
 
-#ifndef _GL_FCNTL_H
-#define _GL_FCNTL_H
+#ifndef address@hidden@_FCNTL_H
+#define address@hidden@_FCNTL_H
 
 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems.  */
 # include <unistd.h>
@@ -182,8 +182,7 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 #endif
 
 #if !defined O_CLOEXEC && defined O_NOINHERIT
-/* Mingw spells it `O_NOINHERIT'.  Intentionally leave it
-   undefined if not available.  */
+/* Mingw spells it `O_NOINHERIT'.  */
 # define O_CLOEXEC O_NOINHERIT
 #endif
 
@@ -219,6 +218,19 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 # define O_NONBLOCK O_NDELAY
 #endif
 
+/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
+   value of O_NONBLOCK.  Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
+   or to 0 as fallback.  */
+#if @GNULIB_NONBLOCKING@
+# if O_NONBLOCK
+#  define GNULIB_defined_O_NONBLOCK 0
+# else
+#  define GNULIB_defined_O_NONBLOCK 1
+#  undef O_NONBLOCK
+#  define O_NONBLOCK 0x40000000
+# endif
+#endif
+
 #ifndef O_NOCTTY
 # define O_NOCTTY 0
 #endif
@@ -247,6 +259,11 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 # define O_TTY_INIT 0
 #endif
 
+#if O_ACCMODE != (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+# undef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+#endif
+
 /* For systems that distinguish between text and binary I/O.
    O_BINARY is usually declared in fcntl.h  */
 #if !defined O_BINARY && defined _O_BINARY
@@ -303,6 +320,6 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 #endif
 
 
-#endif /* _GL_FCNTL_H */
-#endif /* _GL_FCNTL_H */
+#endif /* address@hidden@_FCNTL_H */
+#endif /* address@hidden@_FCNTL_H */
 #endif
diff --git a/gl/tests/fdopen.c b/gl/tests/fdopen.c
new file mode 100644
index 0000000..50c889b
--- /dev/null
+++ b/gl/tests/fdopen.c
@@ -0,0 +1,69 @@
+/* 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
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#undef fdopen
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static FILE *
+fdopen_nothrow (int fd, const char *mode)
+{
+  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/lib/gl/tests/fpucw.h b/gl/tests/fpucw.h
similarity index 100%
copy from lib/gl/tests/fpucw.h
copy to gl/tests/fpucw.h
diff --git a/gl/tests/ftruncate.c b/gl/tests/ftruncate.c
new file mode 100644
index 0000000..ae1e858
--- /dev/null
+++ b/gl/tests/ftruncate.c
@@ -0,0 +1,43 @@
+/* ftruncate emulations for native Windows.
+   This file is in the public domain.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#if HAVE_CHSIZE
+
+# include <errno.h>
+# include <io.h>
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+#  include "msvc-inval.h"
+static inline int
+chsize_nothrow (int fd, long length)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = chsize (fd, length);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#  define chsize chsize_nothrow
+# endif
+
+int
+ftruncate (int fd, off_t length)
+{
+  return chsize (fd, length);
+}
+
+#endif
diff --git a/gl/tests/getcwd-lgpl.c b/gl/tests/getcwd-lgpl.c
new file mode 100644
index 0000000..2761422
--- /dev/null
+++ b/gl/tests/getcwd-lgpl.c
@@ -0,0 +1,125 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+   This file is part of gnulib.
+
+   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/>.  */
+
+#include <config.h>
+
+/* Specification */
+#include <unistd.h>
+
+#include <errno.h>
+#include <string.h>
+
+#if GNULIB_GETCWD
+/* Favor GPL getcwd.c if both getcwd and getcwd-lgpl modules are in use.  */
+typedef int dummy;
+#else
+
+/* Get the name of the current working directory, and put it in SIZE
+   bytes of BUF.  Returns NULL if the directory couldn't be determined
+   (perhaps because the absolute name was longer than PATH_MAX, or
+   because of missing read/search permissions on parent directories)
+   or SIZE was too small.  If successful, returns BUF.  If BUF is
+   NULL, an array is allocated with `malloc'; the array is SIZE bytes
+   long, unless SIZE == 0, in which case it is as big as
+   necessary.  */
+
+# undef getcwd
+char *
+rpl_getcwd (char *buf, size_t size)
+{
+  char *ptr;
+  char *result;
+
+  /* Handle single size operations.  */
+  if (buf)
+    {
+      if (!size)
+        {
+          errno = EINVAL;
+          return NULL;
+        }
+      return getcwd (buf, size);
+    }
+
+  if (size)
+    {
+      buf = malloc (size);
+      if (!buf)
+        {
+          errno = ENOMEM;
+          return NULL;
+        }
+      result = getcwd (buf, size);
+      if (!result)
+        {
+          int saved_errno = errno;
+          free (buf);
+          errno = saved_errno;
+        }
+      return result;
+    }
+
+  /* Flexible sizing requested.  Avoid over-allocation for the common
+     case of a name that fits within a 4k page, minus some space for
+     local variables, to be sure we don't skip over a guard page.  */
+  {
+    char tmp[4032];
+    size = sizeof tmp;
+    ptr = getcwd (tmp, size);
+    if (ptr)
+      {
+        result = strdup (ptr);
+        if (!result)
+          errno = ENOMEM;
+        return result;
+      }
+    if (errno != ERANGE)
+      return NULL;
+  }
+
+  /* My what a large directory name we have.  */
+  do
+    {
+      size <<= 1;
+      ptr = realloc (buf, size);
+      if (ptr == NULL)
+        {
+          free (buf);
+          errno = ENOMEM;
+          return NULL;
+        }
+      buf = ptr;
+      result = getcwd (buf, size);
+    }
+  while (!result && errno == ERANGE);
+
+  if (!result)
+    {
+      int saved_errno = errno;
+      free (buf);
+      errno = saved_errno;
+    }
+  else
+    {
+      /* Trim to fit, if possible.  */
+      result = realloc (buf, strlen (buf) + 1);
+      if (!result)
+        result = buf;
+    }
+  return result;
+}
+
+#endif
diff --git a/gl/tests/glthread/thread.c b/gl/tests/glthread/thread.c
new file mode 100644
index 0000000..83b8c57
--- /dev/null
+++ b/gl/tests/glthread/thread.c
@@ -0,0 +1,232 @@
+/* Creating and controlling threads.
+   Copyright (C) 2005-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.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "glthread/thread.h"
+
+#include <stdlib.h>
+#include "glthread/lock.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+#include <pthread.h>
+
+#ifdef PTW32_VERSION
+
+const gl_thread_t gl_null_thread /* = { .p = NULL } */;
+
+#endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+#include <process.h>
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* The Thread-Local Storage (TLS) key that allows to access each thread's
+   'struct gl_thread_struct *' pointer.  */
+static DWORD self_key = (DWORD)-1;
+
+/* Initializes self_key.  This function must only be called once.  */
+static void
+do_init_self_key (void)
+{
+  self_key = TlsAlloc ();
+  /* If this fails, we're hosed.  */
+  if (self_key == (DWORD)-1)
+    abort ();
+}
+
+/* Initializes self_key.  */
+static void
+init_self_key (void)
+{
+  gl_once_define(static, once)
+  gl_once (once, do_init_self_key);
+}
+
+/* This structure contains information about a thread.
+   It is stored in TLS under key self_key.  */
+struct gl_thread_struct
+{
+  /* Fields for managing the handle.  */
+  HANDLE volatile handle;
+  CRITICAL_SECTION handle_lock;
+  /* Fields for managing the exit value.  */
+  void * volatile result;
+  /* Fields for managing the thread start.  */
+  void * (*func) (void *);
+  void *arg;
+};
+
+/* Return a real HANDLE object for the current thread.  */
+static inline HANDLE
+get_current_thread_handle (void)
+{
+  HANDLE this_handle;
+
+  /* GetCurrentThread() returns a pseudo-handle, i.e. only a symbolic
+     identifier, not a real handle.  */
+  if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
+                        GetCurrentProcess (), &this_handle,
+                        0, FALSE, DUPLICATE_SAME_ACCESS))
+    abort ();
+  return this_handle;
+}
+
+gl_thread_t
+gl_thread_self_func (void)
+{
+  gl_thread_t thread;
+
+  if (self_key == (DWORD)-1)
+    init_self_key ();
+  thread = TlsGetValue (self_key);
+  if (thread == NULL)
+    {
+      /* This happens only in threads that have not been created through
+         glthread_create(), such as the main thread.  */
+      for (;;)
+        {
+          thread =
+            (struct gl_thread_struct *)
+            malloc (sizeof (struct gl_thread_struct));
+          if (thread != NULL)
+            break;
+          /* Memory allocation failed.  There is not much we can do.  Have to
+             busy-loop, waiting for the availability of memory.  */
+          Sleep (1);
+        }
+
+      thread->handle = get_current_thread_handle ();
+      InitializeCriticalSection (&thread->handle_lock);
+      thread->result = NULL; /* just to be deterministic */
+      TlsSetValue (self_key, thread);
+    }
+  return thread;
+}
+
+/* The main function of a freshly creating thread.  It's a wrapper around
+   the FUNC and ARG arguments passed to glthread_create_func.  */
+static unsigned int WINAPI
+wrapper_func (void *varg)
+{
+  struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
+
+  EnterCriticalSection (&thread->handle_lock);
+  /* Create a new handle for the thread only if the parent thread did not yet
+     fill in the handle.  */
+  if (thread->handle == NULL)
+    thread->handle = get_current_thread_handle ();
+  LeaveCriticalSection (&thread->handle_lock);
+
+  if (self_key == (DWORD)-1)
+    init_self_key ();
+  TlsSetValue (self_key, thread);
+
+  /* Run the thread.  Store the exit value if the thread was not terminated
+     otherwise.  */
+  thread->result = thread->func (thread->arg);
+  return 0;
+}
+
+int
+glthread_create_func (gl_thread_t *threadp, void * (*func) (void *), void *arg)
+{
+  struct gl_thread_struct *thread =
+    (struct gl_thread_struct *) malloc (sizeof (struct gl_thread_struct));
+  if (thread == NULL)
+    return ENOMEM;
+  thread->handle = NULL;
+  InitializeCriticalSection (&thread->handle_lock);
+  thread->result = NULL; /* just to be deterministic */
+  thread->func = func;
+  thread->arg = arg;
+
+  {
+    unsigned int thread_id;
+    HANDLE thread_handle;
+
+    thread_handle = (HANDLE)
+      _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+      /* calls CreateThread with the same arguments */
+    if (thread_handle == NULL)
+      {
+        DeleteCriticalSection (&thread->handle_lock);
+        free (thread);
+        return EAGAIN;
+      }
+
+    EnterCriticalSection (&thread->handle_lock);
+    if (thread->handle == NULL)
+      thread->handle = thread_handle;
+    else
+      /* thread->handle was already set by the thread itself.  */
+      CloseHandle (thread_handle);
+    LeaveCriticalSection (&thread->handle_lock);
+
+    *threadp = thread;
+    return 0;
+  }
+}
+
+int
+glthread_join_func (gl_thread_t thread, void **retvalp)
+{
+  if (thread == NULL)
+    return EINVAL;
+
+  if (thread == gl_thread_self ())
+    return EDEADLK;
+
+  if (WaitForSingleObject (thread->handle, INFINITE) == WAIT_FAILED)
+    return EINVAL;
+
+  if (retvalp != NULL)
+    *retvalp = thread->result;
+
+  DeleteCriticalSection (&thread->handle_lock);
+  CloseHandle (thread->handle);
+  free (thread);
+
+  return 0;
+}
+
+int
+gl_thread_exit_func (void *retval)
+{
+  gl_thread_t thread = gl_thread_self ();
+  thread->result = retval;
+  _endthreadex (0); /* calls ExitThread (0) */
+  abort ();
+}
+
+#endif
+
+/* ========================================================================= */
diff --git a/gl/tests/glthread/thread.h b/gl/tests/glthread/thread.h
new file mode 100644
index 0000000..6008c92
--- /dev/null
+++ b/gl/tests/glthread/thread.h
@@ -0,0 +1,400 @@
+/* Creating and controlling threads.
+   Copyright (C) 2005-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.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+/* This file contains primitives for creating and controlling threads.
+
+   Thread data type: gl_thread_t.
+
+   Creating a thread:
+       thread = gl_thread_create (func, arg);
+   Or with control of error handling:
+       err = glthread_create (&thread, func, arg);
+       extern int glthread_create (gl_thread_t *result,
+                                   void *(*func) (void *), void *arg);
+
+   Querying and changing the signal mask of a thread (not supported on all
+   platforms):
+       gl_thread_sigmask (how, newmask, oldmask);
+   Or with control of error handling:
+       err = glthread_sigmask (how, newmask, oldmask);
+       extern int glthread_sigmask (int how, const sigset_t *newmask, sigset_t 
*oldmask);
+
+   Waiting for termination of another thread:
+       gl_thread_join (thread, &return_value);
+   Or with control of error handling:
+       err = glthread_join (thread, &return_value);
+       extern int glthread_join (gl_thread_t thread, void **return_value_ptr);
+
+   Getting a reference to the current thread:
+       current = gl_thread_self ();
+       extern gl_thread_t gl_thread_self (void);
+
+   Getting a reference to the current thread as a pointer, for debugging:
+       ptr = gl_thread_self_pointer ();
+       extern void * gl_thread_self_pointer (void);
+
+   Terminating the current thread:
+       gl_thread_exit (return_value);
+       extern _Noreturn void gl_thread_exit (void *return_value);
+
+   Requesting custom code to be executed at fork() time(not supported on all
+   platforms):
+       gl_thread_atfork (prepare_func, parent_func, child_func);
+   Or with control of error handling:
+       err = glthread_atfork (prepare_func, parent_func, child_func);
+       extern int glthread_atfork (void (*prepare_func) (void),
+                                   void (*parent_func) (void),
+                                   void (*child_func) (void));
+   Note that even on platforms where this is supported, use of fork() and
+   threads together is problematic, see
+     <http://lists.gnu.org/archive/html/bug-gnulib/2008-08/msg00062.html>
+ */
+
+
+#ifndef _GLTHREAD_THREAD_H
+#define _GLTHREAD_THREAD_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime.  */
+#  define pthread_in_use() \
+     glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library.  */
+
+/* Weak references avoid dragging in external libraries if the other parts
+   of the program don't use them.  Here we use them, because we don't want
+   every program that uses libintl to depend on libpthread.  This assumes
+   that libpthread would not be loaded after libintl; i.e. if libintl is
+   loaded first, by an executable that does not depend on libpthread, and
+   then a module is dynamically loaded that depends on libpthread, libintl
+   will not be multithread-safe.  */
+
+/* The way to test at runtime whether libpthread is present is to test
+   whether a function pointer's value, such as &pthread_mutex_init, is
+   non-NULL.  However, some versions of GCC have a bug through which, in
+   PIC mode, &foo != NULL always evaluates to true if there is a direct
+   call to foo(...) in the same function.  To avoid this, we test the
+   address of a function in libpthread that we don't use.  */
+
+#  pragma weak pthread_create
+#  pragma weak pthread_sigmask
+#  pragma weak pthread_join
+#  ifndef pthread_self
+#   pragma weak pthread_self
+#  endif
+#  pragma weak pthread_exit
+#  if HAVE_PTHREAD_ATFORK
+#   pragma weak pthread_atfork
+#  endif
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   pragma weak pthread_cancel
+#   define pthread_in_use() (pthread_cancel != NULL)
+#  endif
+
+# else
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   define pthread_in_use() 1
+#  endif
+
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* This choice of gl_thread_t assumes that
+     pthread_equal (a, b)  is equivalent to  ((a) == (b)).
+   This is the case on all platforms in use in 2008.  */
+typedef pthread_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (pthread_in_use () ? pthread_create (THREADP, NULL, FUNC, ARG) : ENOSYS)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (pthread_in_use () ? pthread_sigmask (HOW, SET, OSET) : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (pthread_in_use () ? pthread_join (THREAD, RETVALP) : 0)
+# ifdef PTW32_VERSION
+   /* In pthreads-win32, pthread_t is a struct with a pointer field 'p' and
+      other fields.  */
+#  define gl_thread_self() \
+     (pthread_in_use () ? pthread_self () : gl_null_thread)
+#  define gl_thread_self_pointer() \
+     (pthread_in_use () ? pthread_self ().p : NULL)
+extern const gl_thread_t gl_null_thread;
+# else
+#  define gl_thread_self() \
+     (pthread_in_use () ? pthread_self () : (pthread_t) NULL)
+#  define gl_thread_self_pointer() \
+     (pthread_in_use () ? (void *) pthread_self () : NULL)
+# endif
+# define gl_thread_exit(RETVAL) \
+    (pthread_in_use () ? pthread_exit (RETVAL) : 0)
+
+# if HAVE_PTHREAD_ATFORK
+#  define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) \
+     (pthread_in_use () ? pthread_atfork (PREPARE_FUNC, PARENT_FUNC, 
CHILD_FUNC) : 0)
+# else
+#  define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library.  */
+
+#  pragma weak pth_spawn
+#  pragma weak pth_sigmask
+#  pragma weak pth_join
+#  pragma weak pth_self
+#  pragma weak pth_exit
+
+#  pragma weak pth_cancel
+#  define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+#  define pth_in_use() 1
+
+# endif
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+typedef pth_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (pth_in_use () ? ((*(THREADP) = pth_spawn (NULL, FUNC, ARG)) ? 0 : errno) 
: 0)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (pth_in_use () && !pth_sigmask (HOW, SET, OSET) ? errno : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (pth_in_use () && !pth_join (THREAD, RETVALP) ? errno : 0)
+# define gl_thread_self() \
+    (pth_in_use () ? (void *) pth_self () : NULL)
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    (pth_in_use () ? pth_exit (RETVAL) : 0)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+# include <synch.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library.  */
+
+#  pragma weak thr_create
+#  pragma weak thr_join
+#  pragma weak thr_self
+#  pragma weak thr_exit
+
+#  pragma weak thr_suspend
+#  define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+#  define thread_in_use() 1
+
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+typedef thread_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (thread_in_use () ? thr_create (NULL, 0, FUNC, ARG, 0, THREADP) : 0)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (thread_in_use () ? sigprocmask (HOW, SET, OSET) : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (thread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0)
+# define gl_thread_self() \
+    (thread_in_use () ? (void *) thr_self () : NULL)
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    (thread_in_use () ? thr_exit (RETVAL) : 0)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* The gl_thread_t is a pointer to a structure in memory.
+   Why not the thread handle?  If it were the thread handle, it would be hard
+   to implement gl_thread_self() (since GetCurrentThread () returns a pseudo-
+   handle, DuplicateHandle (GetCurrentThread ()) returns a handle that must be
+   closed afterwards, and there is no function for quickly retrieving a thread
+   handle from its id).
+   Why not the thread id?  I tried it.  It did not work: Sometimes ids appeared
+   that did not belong to running threads, and glthread_join failed with ESRCH.
+ */
+typedef struct gl_thread_struct *gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    glthread_create_func (THREADP, FUNC, ARG)
+# define glthread_sigmask(HOW, SET, OSET) \
+    /* unsupported */ 0
+# define glthread_join(THREAD, RETVALP) \
+    glthread_join_func (THREAD, RETVALP)
+# define gl_thread_self() \
+    gl_thread_self_func ()
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    gl_thread_exit_func (RETVAL)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+extern int glthread_create_func (gl_thread_t *threadp, void * (*func) (void 
*), void *arg);
+extern int glthread_join_func (gl_thread_t thread, void **retvalp);
+extern gl_thread_t gl_thread_self_func (void);
+extern int gl_thread_exit_func (void *retval);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+typedef int gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) ENOSYS
+# define glthread_sigmask(HOW, SET, OSET) 0
+# define glthread_join(THREAD, RETVALP) 0
+# define gl_thread_self() 0
+# define gl_thread_self_pointer() \
+    ((void *) gl_thread_self ())
+# define gl_thread_exit(RETVAL) 0
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline gl_thread_t
+gl_thread_create (void *(*func) (void *arg), void *arg)
+{
+  gl_thread_t thread;
+  int ret;
+
+  ret = glthread_create (&thread, func, arg);
+  if (ret != 0)
+    abort ();
+  return thread;
+}
+#define gl_thread_sigmask(HOW, SET, OSET)     \
+   do                                         \
+     {                                        \
+       if (glthread_sigmask (HOW, SET, OSET)) \
+         abort ();                            \
+     }                                        \
+   while (0)
+#define gl_thread_join(THREAD, RETVAL)     \
+   do                                      \
+     {                                     \
+       if (glthread_join (THREAD, RETVAL)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_thread_atfork(PREPARE, PARENT, CHILD)     \
+   do                                                \
+     {                                               \
+       if (glthread_atfork (PREPARE, PARENT, CHILD)) \
+         abort ();                                   \
+     }                                               \
+   while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GLTHREAD_THREAD_H */
diff --git a/gl/tests/glthread/yield.h b/gl/tests/glthread/yield.h
new file mode 100644
index 0000000..4eb1cb8
--- /dev/null
+++ b/gl/tests/glthread/yield.h
@@ -0,0 +1,121 @@
+/* Yielding the processor to other threads and processes.
+   Copyright (C) 2005-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.  */
+
+/* This file contains a primitive for yielding the processor to other threads.
+     extern void gl_thread_yield (void);
+ */
+
+#ifndef _GLTHREAD_YIELD_H
+#define _GLTHREAD_YIELD_H
+
+#include <errno.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <sched.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    sched_yield ()
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    pth_yield (NULL)
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    thr_yield ()
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    Sleep (0)
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+# define gl_thread_yield() 0
+
+#endif
+
+/* ========================================================================= */
+
+#endif /* _GLTHREAD_YIELD_H */
diff --git a/gl/tests/ignore-value.h b/gl/tests/ignore-value.h
new file mode 100644
index 0000000..f021a1a
--- /dev/null
+++ b/gl/tests/ignore-value.h
@@ -0,0 +1,62 @@
+/* ignore a function return without a compiler warning
+
+   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
+   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/>.  */
+
+/* Written by Jim Meyering, Eric Blake and Pádraig Brady.  */
+
+/* Use "ignore_value" to avoid a warning when using a function declared with
+   gcc's warn_unused_result attribute, but for which you really do want to
+   ignore the result.  Traditionally, people have used a "(void)" cast to
+   indicate that a function's return value is deliberately unused.  However,
+   if the function is declared with __attribute__((warn_unused_result)),
+   gcc issues a warning even with the cast.
+
+   Caution: most of the time, you really should heed gcc's warning, and
+   check the return value.  However, in those exceptional cases in which
+   you're sure you know what you're doing, use this function.
+
+   For the record, here's one of the ignorable warnings:
+   "copy.c:233: warning: ignoring return value of 'fchown',
+   declared with attribute warn_unused_result".  */
+
+#ifndef _GL_IGNORE_VALUE_H
+# define _GL_IGNORE_VALUE_H
+
+# ifndef _GL_ATTRIBUTE_DEPRECATED
+/* The __attribute__((__deprecated__)) feature
+   is available in gcc versions 3.1 and newer.  */
+#  if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
+#   define _GL_ATTRIBUTE_DEPRECATED /* empty */
+#  else
+#   define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
+#  endif
+# endif
+
+/* The __attribute__((__warn_unused_result__)) feature
+   is available in gcc versions 3.4 and newer,
+   while the typeof feature has been available since 2.7 at least.  */
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+#  define ignore_value(x) ((void) (x))
+# else
+#  define ignore_value(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
+# endif
+
+/* ignore_value works for scalars, pointers and aggregates;
+   deprecate ignore_ptr.  */
+static inline void _GL_ATTRIBUTE_DEPRECATED
+ignore_ptr (void *p) { (void) p; } /* deprecated: use ignore_value */
+
+#endif
diff --git a/gl/tests/init.sh b/gl/tests/init.sh
index 71c6516..373d9d4 100644
--- a/gl/tests/init.sh
+++ b/gl/tests/init.sh
@@ -68,15 +68,29 @@ Exit () { set +e; (exit $1); exit $1; }
 
 # Print warnings (e.g., about skipped and failed tests) to this file number.
 # Override by defining to say, 9, in init.cfg, and putting say,
-# "export ...ENVVAR_SETTINGS...; exec 9>&2; $(SHELL)" in the definition
-# of TESTS_ENVIRONMENT in your tests/Makefile.am file.
+#   export ...ENVVAR_SETTINGS...; $(SHELL) 9>&2
+# in the definition of TESTS_ENVIRONMENT in your tests/Makefile.am file.
 # This is useful when using automake's parallel tests mode, to print
 # the reason for skip/failure to console, rather than to the .log files.
 : ${stderr_fileno_=2}
 
-warn_ () { echo "$@" 1>&$stderr_fileno_; }
+# Note that correct expansion of "$*" depends on IFS starting with ' '.
+# Always write the full diagnostic to stderr.
+# When stderr_fileno_ is not 2, also emit the first line of the
+# diagnostic to that file descriptor.
+warn_ ()
+{
+  # If IFS does not start with ' ', set it and emit the warning in a subshell.
+  case $IFS in
+    ' '*) printf '%s\n' "$*" >&2
+          test $stderr_fileno_ = 2 \
+            || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
+    *) (IFS=' '; warn_ "$@");;
+  esac
+}
 fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
 skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
+fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }
 framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; }
 
 # Sanitize this shell to POSIX mode, if possible.
@@ -167,7 +181,10 @@ else
     st_=$?
 
     # $re_shell_ works just fine.  Use it.
-    test $st_ = 10 && break
+    if test $st_ = 10; then
+      gl_set_x_corrupts_stderr_=false
+      break
+    fi
 
     # If this is our first marginally acceptable shell, remember it.
     if test "$st_:$marginal_" = 9: ; then
@@ -204,8 +221,10 @@ export MALLOC_PERTURB_
 # a partition, or to undo any other global state changes.
 cleanup_ () { :; }
 
-if ( diff --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
+if ( diff -u "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
   compare () { diff -u "$@"; }
+elif ( diff -c "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
+  compare () { diff -c "$@"; }
 elif ( cmp --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
   compare () { cmp -s "$@"; }
 else
@@ -400,7 +419,7 @@ mktempd_ ()
 {
   case $# in
   2);;
-  *) fail_ "Usage: $ME DIR TEMPLATE";;
+  *) fail_ "Usage: mktempd_ DIR TEMPLATE";;
   esac
 
   destdir_=$1
diff --git a/lib/gl/tests/inttypes.in.h b/gl/tests/inttypes.in.h
similarity index 100%
copy from lib/gl/tests/inttypes.in.h
copy to gl/tests/inttypes.in.h
diff --git a/gl/tests/ioctl.c b/gl/tests/ioctl.c
index 72f9f37..c6ba989 100644
--- a/gl/tests/ioctl.c
+++ b/gl/tests/ioctl.c
@@ -37,36 +37,43 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg 
*/)
   buf = va_arg (args, void *);
   va_end (args);
 
-  return ioctl (fd, request, buf);
+  /* Cast 'request' so that when the system's ioctl function takes a 64-bit
+     request argument, the value gets zero-extended, not sign-extended.  */
+  return ioctl (fd, (unsigned int) request, buf);
 }
 
 #else /* mingw */
 
-# define WIN32_LEAN_AND_MEAN
-/* Get winsock2.h. */
-# include <sys/socket.h>
+# include <errno.h>
 
-/* Get set_winsock_errno, FD_TO_SOCKET etc. */
-# include "w32sock.h"
+# include "fd-hook.h"
+
+static int
+primary_ioctl (int fd, int request, void *arg)
+{
+  /* We don't support FIONBIO on pipes here.  If you want to make pipe
+     fds non-blocking, use the gnulib 'nonblocking' module, until
+     gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
+
+  errno = ENOSYS;
+  return -1;
+}
 
 int
-ioctl (int fd, int req, ...)
+ioctl (int fd, int request, ... /* {void *,char *} arg */)
 {
-  void *buf;
+  void *arg;
   va_list args;
-  SOCKET sock;
-  int r;
 
-  va_start (args, req);
-  buf = va_arg (args, void *);
+  va_start (args, request);
+  arg = va_arg (args, void *);
   va_end (args);
 
-  sock = FD_TO_SOCKET (fd);
-  r = ioctlsocket (sock, req, buf);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
+# if WINDOWS_SOCKETS
+  return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg);
+# else
+  return primary_ioctl (fd, request, arg);
+# endif
 }
 
 #endif
diff --git a/gl/tests/lstat.c b/gl/tests/lstat.c
new file mode 100644
index 0000000..d786288
--- /dev/null
+++ b/gl/tests/lstat.c
@@ -0,0 +1,97 @@
+/* Work around a bug of lstat on some systems
+
+   Copyright (C) 1997-2006, 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
+   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/>.  */
+
+/* written by Jim Meyering */
+
+/* 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_lstat doesn't recurse to
+   rpl_lstat.  */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+#if !HAVE_LSTAT
+/* On systems that lack symlinks, our replacement <sys/stat.h> already
+   defined lstat as stat, so there is nothing further to do other than
+   avoid an empty file.  */
+typedef int dummy;
+#else /* HAVE_LSTAT */
+
+/* Get the original definition of lstat.  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_lstat (const char *filename, struct stat *buf)
+{
+  return lstat (filename, 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 <string.h>
+# include <errno.h>
+
+/* lstat works differently on Linux and Solaris systems.  POSIX (see
+   `pathname resolution' in the glossary) requires that programs like
+   `ls' take into consideration the fact that FILE has a trailing slash
+   when FILE is a symbolic link.  On Linux and Solaris 10 systems, the
+   lstat function already has the desired semantics (in treating
+   `lstat ("symlink/", sbuf)' just like `lstat ("symlink/.", sbuf)',
+   but on Solaris 9 and earlier it does not.
+
+   If FILE has a trailing slash and specifies a symbolic link,
+   then use stat() to get more info on the referent of FILE.
+   If the referent is a non-directory, then set errno to ENOTDIR
+   and return -1.  Otherwise, return stat's result.  */
+
+int
+rpl_lstat (const char *file, struct stat *sbuf)
+{
+  size_t len;
+  int lstat_result = orig_lstat (file, sbuf);
+
+  if (lstat_result != 0)
+    return lstat_result;
+
+  /* This replacement file can blindly check against '/' rather than
+     using the ISSLASH macro, because all platforms with '\\' either
+     lack symlinks (mingw) or have working lstat (cygwin) and thus do
+     not compile this file.  0 len should have already been filtered
+     out above, with a failure return of ENOENT.  */
+  len = strlen (file);
+  if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
+    return 0;
+
+  /* At this point, a trailing slash is only permitted on
+     symlink-to-dir; but it should have found information on the
+     directory, not the symlink.  Call stat() to get info about the
+     link's referent.  Our replacement stat guarantees valid results,
+     even if the symlink is not pointing to a directory.  */
+  if (!S_ISLNK (sbuf->st_mode))
+    {
+      errno = ENOTDIR;
+      return -1;
+    }
+  return stat (file, sbuf);
+}
+
+#endif /* HAVE_LSTAT */
diff --git a/gl/tests/macros.h b/gl/tests/macros.h
index 8922675..adb3744 100644
--- a/gl/tests/macros.h
+++ b/gl/tests/macros.h
@@ -62,3 +62,7 @@
    *not* work for function parameters of array type, because they are actually
    parameters of pointer type.  */
 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
+
+/* STREQ (str1, str2)
+   Return true if two strings compare equal.  */
+#define STREQ(a, b) (strcmp (a, b) == 0)
diff --git a/gl/tests/open.c b/gl/tests/open.c
new file mode 100644
index 0000000..8dc36ef
--- /dev/null
+++ b/gl/tests/open.c
@@ -0,0 +1,181 @@
+/* Open a descriptor to a file.
+   Copyright (C) 2007-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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2007.  */
+
+/* If the user's config.h happens to include <fcntl.h>, let it include only
+   the system's <fcntl.h> here, so that orig_open doesn't recurse to
+   rpl_open.  */
+#define __need_system_fcntl_h
+#include <config.h>
+
+/* Get the original definition of open.  It might be defined as a macro.  */
+#include <fcntl.h>
+#include <sys/types.h>
+#undef __need_system_fcntl_h
+
+static inline int
+orig_open (const char *filename, int flags, mode_t mode)
+{
+  return open (filename, flags, mode);
+}
+
+/* Specification.  */
+/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates
+   this include because of the preliminary #include <fcntl.h> above.  */
+#include "fcntl.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifndef REPLACE_OPEN_DIRECTORY
+# define REPLACE_OPEN_DIRECTORY 0
+#endif
+
+int
+open (const char *filename, int flags, ...)
+{
+  mode_t mode;
+  int fd;
+
+  mode = 0;
+  if (flags & O_CREAT)
+    {
+      va_list arg;
+      va_start (arg, flags);
+
+      /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
+         creates crashing code when 'mode_t' is smaller than 'int'.  */
+      mode = va_arg (arg, PROMOTED_MODE_T);
+
+      va_end (arg);
+    }
+
+#if GNULIB_defined_O_NONBLOCK
+  /* The only known platform that lacks O_NONBLOCK is mingw, but it
+     also lacks named pipes and Unix sockets, which are the only two
+     file types that require non-blocking handling in open().
+     Therefore, it is safe to ignore O_NONBLOCK here.  It is handy
+     that mingw also lacks openat(), so that is also covered here.  */
+  flags &= ~O_NONBLOCK;
+#endif
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  if (strcmp (filename, "/dev/null") == 0)
+    filename = "NUL";
+#endif
+
+#if OPEN_TRAILING_SLASH_BUG
+  /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
+     is specified, then fail.
+     Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+     says that
+       "A pathname that contains at least one non-slash character and that
+        ends with one or more trailing slashes shall be resolved as if a
+        single dot character ( '.' ) were appended to the pathname."
+     and
+       "The special filename dot shall refer to the directory specified by
+        its predecessor."
+     If the named file already exists as a directory, then
+       - if O_CREAT is specified, open() must fail because of the semantics
+         of O_CREAT,
+       - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
+         <http://www.opengroup.org/susv3/functions/open.html> says that it
+         fails with errno = EISDIR in this case.
+     If the named file does not exist or does not name a directory, then
+       - if O_CREAT is specified, open() must fail since open() cannot create
+         directories,
+       - if O_WRONLY or O_RDWR is specified, open() must fail because the
+         file does not contain a '.' directory.  */
+  if (flags & (O_CREAT | O_WRONLY | O_RDWR))
+    {
+      size_t len = strlen (filename);
+      if (len > 0 && filename[len - 1] == '/')
+        {
+          errno = EISDIR;
+          return -1;
+        }
+    }
+#endif
+
+  fd = orig_open (filename, flags, mode);
+
+#if REPLACE_FCHDIR
+  /* Implementing fchdir and fdopendir requires the ability to open a
+     directory file descriptor.  If open doesn't support that (as on
+     mingw), we use a dummy file that behaves the same as directories
+     on Linux (ie. always reports EOF on attempts to read()), and
+     override fstat() in fchdir.c to hide the fact that we have a
+     dummy.  */
+  if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
+      && ((flags & O_ACCMODE) == O_RDONLY
+          || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
+    {
+      struct stat statbuf;
+      if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
+        {
+          /* Maximum recursion depth of 1.  */
+          fd = open ("/dev/null", flags, mode);
+          if (0 <= fd)
+            fd = _gl_register_fd (fd, filename);
+        }
+      else
+        errno = EACCES;
+    }
+#endif
+
+#if OPEN_TRAILING_SLASH_BUG
+  /* If the filename ends in a slash and fd does not refer to a directory,
+     then fail.
+     Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+     says that
+       "A pathname that contains at least one non-slash character and that
+        ends with one or more trailing slashes shall be resolved as if a
+        single dot character ( '.' ) were appended to the pathname."
+     and
+       "The special filename dot shall refer to the directory specified by
+        its predecessor."
+     If the named file without the slash is not a directory, open() must fail
+     with ENOTDIR.  */
+  if (fd >= 0)
+    {
+      /* We know len is positive, since open did not fail with ENOENT.  */
+      size_t len = strlen (filename);
+      if (filename[len - 1] == '/')
+        {
+          struct stat statbuf;
+
+          if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
+            {
+              close (fd);
+              errno = ENOTDIR;
+              return -1;
+            }
+        }
+    }
+#endif
+
+#if REPLACE_FCHDIR
+  if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
+    fd = _gl_register_fd (fd, filename);
+#endif
+
+  return fd;
+}
diff --git a/gl/tests/pathmax.h b/gl/tests/pathmax.h
new file mode 100644
index 0000000..c47618a
--- /dev/null
+++ b/gl/tests/pathmax.h
@@ -0,0 +1,84 @@
+/* Define PATH_MAX somehow.  Requires sys/types.h.
+   Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-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 _PATHMAX_H
+# define _PATHMAX_H
+
+/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
+   including the terminating NUL byte.
+   <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
+   PATH_MAX is not defined on systems which have no limit on filename length,
+   such as GNU/Hurd.
+
+   This file does *not* define PATH_MAX always.  Programs that use this file
+   can handle the GNU/Hurd case in several ways:
+     - Either with a package-wide handling, or with a per-file handling,
+     - Either through a
+         #ifdef PATH_MAX
+       or through a fallback like
+         #ifndef PATH_MAX
+         # define PATH_MAX 8192
+         #endif
+       or through a fallback like
+         #ifndef PATH_MAX
+         # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
+         #endif
+ */
+
+# include <unistd.h>
+
+# include <limits.h>
+
+# ifndef _POSIX_PATH_MAX
+#  define _POSIX_PATH_MAX 256
+# endif
+
+/* Don't include sys/param.h if it already has been.  */
+# 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
+/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
+   *not* including the terminating NUL byte, and is set to 1023.
+   Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
+   not defined at all any more.  */
+#  undef PATH_MAX
+#  define PATH_MAX 1024
+# endif
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
+   section "Maximum Path Length Limitation",
+   <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath>
+   explains that the maximum size of a filename, including the terminating
+   NUL byte, is 260 = 3 + 256 + 1.
+   This is the same value as
+     - FILENAME_MAX in <stdio.h>,
+     - _MAX_PATH in <stdlib.h>,
+     - MAX_PATH in <windef.h>.
+   Undefine the original value, because mingw's <limits.h> gets it wrong.  */
+#  undef PATH_MAX
+#  define PATH_MAX 260
+# endif
+
+#endif /* _PATHMAX_H */
diff --git a/gl/tests/pipe.c b/gl/tests/pipe.c
index cfd8acb..425dd70 100644
--- a/gl/tests/pipe.c
+++ b/gl/tests/pipe.c
@@ -32,7 +32,16 @@
 int
 pipe (int fd[2])
 {
-  return _pipe (fd, 4096, _O_BINARY);
+  /* Mingw changes fd to {-1,-1} on failure, but this violates
+     http://austingroupbugs.net/view.php?id=467 */
+  int tmp[2];
+  int result = _pipe (tmp, 4096, _O_BINARY);
+  if (!result)
+    {
+      fd[0] = tmp[0];
+      fd[1] = tmp[1];
+    }
+  return result;
 }
 
 #else
diff --git a/gl/tests/same-inode.h b/gl/tests/same-inode.h
new file mode 100644
index 0000000..d434b94
--- /dev/null
+++ b/gl/tests/same-inode.h
@@ -0,0 +1,25 @@
+/* Determine whether two stat buffers refer to the same file.
+
+   Copyright (C) 2006, 2009-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/>.  */
+
+#ifndef SAME_INODE_H
+# define SAME_INODE_H 1
+
+# define SAME_INODE(Stat_buf_1, Stat_buf_2) \
+   ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
+    && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
+
+#endif
diff --git a/gl/tests/stat.c b/gl/tests/stat.c
new file mode 100644
index 0000000..1397aa9
--- /dev/null
+++ b/gl/tests/stat.c
@@ -0,0 +1,123 @@
+/* Work around platform bugs in stat.
+   Copyright (C) 2009-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/>.  */
+
+/* written by Eric Blake */
+
+/* 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_stat doesn't recurse to
+   rpl_stat.  */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+/* Get the original definition of stat.  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_stat (const char *filename, struct stat *buf)
+{
+  return stat (filename, 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 <limits.h>
+#include <stdbool.h>
+#include <string.h>
+#include "dosname.h"
+#include "verify.h"
+
+#if REPLACE_FUNC_STAT_DIR
+# include "pathmax.h"
+  /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
+     have a constant PATH_MAX.  */
+# ifndef PATH_MAX
+#  error "Please port this replacement to your platform"
+# endif
+#endif
+
+/* Store information about NAME into ST.  Work around bugs with
+   trailing slashes.  Mingw has other bugs (such as st_ino always
+   being 0 on success) which this wrapper does not work around.  But
+   at least this implementation provides the ability to emulate fchdir
+   correctly.  */
+
+int
+rpl_stat (char const *name, struct stat *st)
+{
+  int result = orig_stat (name, st);
+#if REPLACE_FUNC_STAT_FILE
+  /* Solaris 9 mistakenly succeeds when given a non-directory with a
+     trailing slash.  */
+  if (result == 0 && !S_ISDIR (st->st_mode))
+    {
+      size_t len = strlen (name);
+      if (ISSLASH (name[len - 1]))
+        {
+          errno = ENOTDIR;
+          return -1;
+        }
+    }
+#endif /* REPLACE_FUNC_STAT_FILE */
+#if REPLACE_FUNC_STAT_DIR
+
+  if (result == -1 && errno == ENOENT)
+    {
+      /* Due to mingw's oddities, there are some directories (like
+         c:\) where stat() only succeeds with a trailing slash, and
+         other directories (like c:\windows) where stat() only
+         succeeds without a trailing slash.  But we want the two to be
+         synonymous, since chdir() manages either style.  Likewise, Mingw also
+         reports ENOENT for names longer than PATH_MAX, when we want
+         ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
+         Fortunately, mingw PATH_MAX is small enough for stack
+         allocation.  */
+      char fixed_name[PATH_MAX + 1] = {0};
+      size_t len = strlen (name);
+      bool check_dir = false;
+      verify (PATH_MAX <= 4096);
+      if (PATH_MAX <= len)
+        errno = ENAMETOOLONG;
+      else if (len)
+        {
+          strcpy (fixed_name, name);
+          if (ISSLASH (fixed_name[len - 1]))
+            {
+              check_dir = true;
+              while (len && ISSLASH (fixed_name[len - 1]))
+                fixed_name[--len] = '\0';
+              if (!len)
+                fixed_name[0] = '/';
+            }
+          else
+            fixed_name[len++] = '/';
+          result = orig_stat (fixed_name, st);
+          if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
+            {
+              result = -1;
+              errno = ENOTDIR;
+            }
+        }
+    }
+#endif /* REPLACE_FUNC_STAT_DIR */
+  return result;
+}
diff --git a/gl/tests/symlink.c b/gl/tests/symlink.c
new file mode 100644
index 0000000..2896cc9
--- /dev/null
+++ b/gl/tests/symlink.c
@@ -0,0 +1,57 @@
+/* Stub for symlink().
+   Copyright (C) 2009-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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+
+
+#if HAVE_SYMLINK
+
+# undef symlink
+
+/* Create a symlink, but reject trailing slash.  */
+int
+rpl_symlink (char const *contents, char const *name)
+{
+  size_t len = strlen (name);
+  if (len && name[len - 1] == '/')
+    {
+      struct stat st;
+      if (lstat (name, &st) == 0)
+        errno = EEXIST;
+      return -1;
+    }
+  return symlink (contents, name);
+}
+
+#else /* !HAVE_SYMLINK */
+
+/* The system does not support symlinks.  */
+int
+symlink (char const *contents _GL_UNUSED,
+         char const *name _GL_UNUSED)
+{
+  errno = ENOSYS;
+  return -1;
+}
+
+#endif /* !HAVE_SYMLINK */
diff --git a/gl/tests/sys_ioctl.in.h b/gl/tests/sys_ioctl.in.h
index 77ca86d..dc8aeda 100644
--- a/gl/tests/sys_ioctl.in.h
+++ b/gl/tests/sys_ioctl.in.h
@@ -15,7 +15,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_SYS_IOCTL_H
+#ifndef address@hidden@_SYS_IOCTL_H
 
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
@@ -27,8 +27,8 @@
 # @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
 #endif
 
-#ifndef _GL_SYS_IOCTL_H
-#define _GL_SYS_IOCTL_H
+#ifndef address@hidden@_SYS_IOCTL_H
+#define address@hidden@_SYS_IOCTL_H
 
 /* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
    but not in <sys/ioctl.h>.
@@ -75,5 +75,5 @@ _GL_WARN_ON_USE (ioctl, "ioctl does not portably work on 
sockets - "
 #endif
 
 
-#endif /* _GL_SYS_IOCTL_H */
-#endif /* _GL_SYS_IOCTL_H */
+#endif /* address@hidden@_SYS_IOCTL_H */
+#endif /* address@hidden@_SYS_IOCTL_H */
diff --git a/gl/tests/test-accept.c b/gl/tests/test-accept.c
new file mode 100644
index 0000000..75161a4
--- /dev/null
+++ b/gl/tests/test-accept.c
@@ -0,0 +1,54 @@
+/* Test accepting a connection to a server socket.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (accept, int, (int, struct sockaddr *, socklen_t *));
+
+#include <errno.h>
+#include <netinet/in.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (accept (-1, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (accept (99, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-bind.c b/gl/tests/test-bind.c
new file mode 100644
index 0000000..490c2fb
--- /dev/null
+++ b/gl/tests/test-bind.c
@@ -0,0 +1,56 @@
+/* Test binding a server socket to a port.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (bind, int, (int, const struct sockaddr *, socklen_t));
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
+    addr.sin_port = htons (80);
+    {
+      errno = 0;
+      ASSERT (bind (-1, (const struct sockaddr *) &addr, sizeof (addr)) == -1);
+      ASSERT (errno == EBADF);
+    }
+    {
+      errno = 0;
+      ASSERT (bind (99, (const struct sockaddr *) &addr, sizeof (addr)) == -1);
+      ASSERT (errno == EBADF);
+    }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-close.c b/gl/tests/test-close.c
new file mode 100644
index 0000000..2b87db1
--- /dev/null
+++ b/gl/tests/test-close.c
@@ -0,0 +1,44 @@
+/* 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
+   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/>.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (close, int, (int));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (close (-1) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (close (99) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-connect.c b/gl/tests/test-connect.c
new file mode 100644
index 0000000..84f00b5
--- /dev/null
+++ b/gl/tests/test-connect.c
@@ -0,0 +1,58 @@
+/* Test connecting a client socket.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (connect, int, (int, const struct sockaddr *, socklen_t));
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
+    addr.sin_port = htons (80);
+    {
+      errno = 0;
+      ASSERT (connect (-1, (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+    {
+      errno = 0;
+      ASSERT (connect (99, (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-dup2.c b/gl/tests/test-dup2.c
new file mode 100644
index 0000000..a14807a
--- /dev/null
+++ b/gl/tests/test-dup2.c
@@ -0,0 +1,203 @@
+/* Test duplicating file descriptors.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (dup2, int, (int, int));
+
+#include <errno.h>
+#include <fcntl.h>
+
+#include "binary-io.h"
+
+#if GNULIB_TEST_CLOEXEC
+# include "cloexec.h"
+#endif
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* 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"
+
+/* Return non-zero if FD is open.  */
+static int
+is_open (int fd)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* On Win32, the initial state of unassigned standard file
+     descriptors is that they are open but point to an
+     INVALID_HANDLE_VALUE, and there is no fcntl.  */
+  return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
+#else
+# ifndef F_GETFL
+#  error Please port fcntl to your platform
+# endif
+  return 0 <= fcntl (fd, F_GETFL);
+#endif
+}
+
+#if GNULIB_TEST_CLOEXEC
+/* Return non-zero if FD is open and inheritable across exec/spawn.  */
+static int
+is_inheritable (int fd)
+{
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* On Win32, the initial state of unassigned standard file
+     descriptors is that they are open but point to an
+     INVALID_HANDLE_VALUE, and there is no fcntl.  */
+  HANDLE h = (HANDLE) _get_osfhandle (fd);
+  DWORD flags;
+  if (h == INVALID_HANDLE_VALUE || GetHandleInformation (h, &flags) == 0)
+    return 0;
+  return (flags & HANDLE_FLAG_INHERIT) != 0;
+# else
+#  ifndef F_GETFD
+#   error Please port fcntl to your platform
+#  endif
+  int i = fcntl (fd, F_GETFD);
+  return 0 <= i && (i & FD_CLOEXEC) == 0;
+# endif
+}
+#endif /* GNULIB_TEST_CLOEXEC */
+
+#if !O_BINARY
+# define setmode(f,m) zero ()
+static int zero (void) { return 0; }
+#endif
+
+/* Return non-zero if FD is open in the given MODE, which is either
+   O_TEXT or O_BINARY.  */
+static int
+is_mode (int fd, int mode)
+{
+  int value = setmode (fd, O_BINARY);
+  setmode (fd, value);
+  return mode == value;
+}
+
+int
+main (void)
+{
+  const char *file = "test-dup2.tmp";
+  char buffer[1];
+  int fd = open (file, O_CREAT | O_TRUNC | O_RDWR, 0600);
+
+  /* Assume std descriptors were provided by invoker.  */
+  ASSERT (STDERR_FILENO < fd);
+  ASSERT (is_open (fd));
+  /* Ignore any other fd's leaked into this process.  */
+  close (fd + 1);
+  close (fd + 2);
+  ASSERT (!is_open (fd + 1));
+  ASSERT (!is_open (fd + 2));
+
+  /* Assigning to self must be a no-op.  */
+  ASSERT (dup2 (fd, fd) == fd);
+  ASSERT (is_open (fd));
+
+  /* The source must be valid.  */
+  errno = 0;
+  ASSERT (dup2 (-1, fd) == -1);
+  ASSERT (errno == EBADF);
+  errno = 0;
+  ASSERT (dup2 (99, fd) == -1);
+  ASSERT (errno == EBADF);
+  errno = 0;
+  ASSERT (dup2 (AT_FDCWD, fd) == -1);
+  ASSERT (errno == EBADF);
+  ASSERT (is_open (fd));
+
+  /* If the source is not open, then the destination is unaffected.  */
+  errno = 0;
+  ASSERT (dup2 (fd + 1, fd + 1) == -1);
+  ASSERT (errno == EBADF);
+  ASSERT (!is_open (fd + 1));
+  errno = 0;
+  ASSERT (dup2 (fd + 1, fd) == -1);
+  ASSERT (errno == EBADF);
+  ASSERT (is_open (fd));
+
+  /* The destination must be valid.  */
+  errno = 0;
+  ASSERT (dup2 (fd, -2) == -1);
+  ASSERT (errno == EBADF);
+  errno = 0;
+  ASSERT (dup2 (fd, 10000000) == -1);
+  ASSERT (errno == EBADF);
+
+  /* Using dup2 can skip fds.  */
+  ASSERT (dup2 (fd, fd + 2) == fd + 2);
+  ASSERT (is_open (fd));
+  ASSERT (!is_open (fd + 1));
+  ASSERT (is_open (fd + 2));
+
+  /* Verify that dup2 closes the previous occupant of a fd.  */
+  ASSERT (open ("/dev/null", O_WRONLY, 0600) == fd + 1);
+  ASSERT (dup2 (fd + 1, fd) == fd);
+  ASSERT (close (fd + 1) == 0);
+  ASSERT (write (fd, "1", 1) == 1);
+  ASSERT (dup2 (fd + 2, fd) == fd);
+  ASSERT (lseek (fd, 0, SEEK_END) == 0);
+  ASSERT (write (fd + 2, "2", 1) == 1);
+  ASSERT (lseek (fd, 0, SEEK_SET) == 0);
+  ASSERT (read (fd, buffer, 1) == 1);
+  ASSERT (*buffer == '2');
+
+#if GNULIB_TEST_CLOEXEC
+  /* Any new fd created by dup2 must not be cloexec.  */
+  ASSERT (close (fd + 2) == 0);
+  ASSERT (dup_cloexec (fd) == fd + 1);
+  ASSERT (!is_inheritable (fd + 1));
+  ASSERT (dup2 (fd + 1, fd + 1) == fd + 1);
+  ASSERT (!is_inheritable (fd + 1));
+  ASSERT (dup2 (fd + 1, fd + 2) == fd + 2);
+  ASSERT (!is_inheritable (fd + 1));
+  ASSERT (is_inheritable (fd + 2));
+  errno = 0;
+  ASSERT (dup2 (fd + 1, -1) == -1);
+  ASSERT (errno == EBADF);
+  ASSERT (!is_inheritable (fd + 1));
+#endif
+
+  /* On systems that distinguish between text and binary mode, dup2
+     reuses the mode of the source.  */
+  setmode (fd, O_BINARY);
+  ASSERT (is_mode (fd, O_BINARY));
+  ASSERT (dup2 (fd, fd + 1) == fd + 1);
+  ASSERT (is_mode (fd + 1, O_BINARY));
+  setmode (fd, O_TEXT);
+  ASSERT (is_mode (fd, O_TEXT));
+  ASSERT (dup2 (fd, fd + 1) == fd + 1);
+  ASSERT (is_mode (fd + 1, O_TEXT));
+
+  /* Clean up.  */
+  ASSERT (close (fd + 2) == 0);
+  ASSERT (close (fd + 1) == 0);
+  ASSERT (close (fd) == 0);
+  ASSERT (unlink (file) == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-fcntl-h.c b/gl/tests/test-fcntl-h.c
index dd20fbb..7f350b4 100644
--- a/gl/tests/test-fcntl-h.c
+++ b/gl/tests/test-fcntl-h.c
@@ -29,10 +29,93 @@ int o = O_DIRECT | O_DIRECTORY | O_DSYNC | O_NDELAY | 
O_NOATIME | O_NONBLOCK
 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 
 /* Check that the FD_* macros are defined.  */
-int fd = FD_CLOEXEC;
+int i = FD_CLOEXEC;
+
+/* Check that the types are all defined.  */
+pid_t t1;
+off_t t2;
+mode_t t3;
 
 int
 main (void)
 {
-  return 0;
+  /* Ensure no overlap in SEEK_*. */
+  switch (0)
+    {
+    case SEEK_CUR:
+    case SEEK_END:
+    case SEEK_SET:
+      ;
+    }
+
+  /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
+  switch (O_RDONLY)
+    {
+      /* Access modes */
+    case O_RDONLY:
+    case O_WRONLY:
+    case O_RDWR:
+#if O_EXEC && O_EXEC != O_RDONLY
+    case O_EXEC:
+#endif
+#if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
+    case O_SEARCH:
+#endif
+      i = O_ACCMODE == (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH);
+      break;
+
+      /* Everyone should have these */
+    case O_CREAT:
+    case O_EXCL:
+    case O_TRUNC:
+    case O_APPEND:
+      break;
+
+      /* These might be 0 or O_RDONLY, only test non-zero versions.  */
+#if O_CLOEXEC
+    case O_CLOEXEC:
+#endif
+#if O_DIRECT
+    case O_DIRECT:
+#endif
+#if O_DIRECTORY
+    case O_DIRECTORY:
+#endif
+#if O_DSYNC
+    case O_DSYNC:
+#endif
+#if O_NOATIME
+    case O_NOATIME:
+#endif
+#if O_NONBLOCK
+    case O_NONBLOCK:
+#endif
+#if O_NOCTTY
+    case O_NOCTTY:
+#endif
+#if O_NOFOLLOW
+    case O_NOFOLLOW:
+#endif
+#if O_NOLINKS
+    case O_NOLINKS:
+#endif
+#if O_RSYNC && O_RSYNC != O_DSYNC
+    case O_RSYNC:
+#endif
+#if O_SYNC && O_SYNC != O_RSYNC
+    case O_SYNC:
+#endif
+#if O_TTY_INIT
+    case O_TTY_INIT:
+#endif
+#if O_BINARY
+    case O_BINARY:
+#endif
+#if O_TEXT
+    case O_TEXT:
+#endif
+      ;
+    }
+
+  return !i;
 }
diff --git a/gl/tests/test-fdopen.c b/gl/tests/test-fdopen.c
new file mode 100644
index 0000000..304e520
--- /dev/null
+++ b/gl/tests/test-fdopen.c
@@ -0,0 +1,54 @@
+/* Test opening a stream with a file descriptor.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fdopen, FILE *, (int, const char *));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* 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;
+}
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fgetc.c
new file mode 100644
index 0000000..4df46fb
--- /dev/null
+++ b/gl/tests/test-fgetc.c
@@ -0,0 +1,96 @@
+/* Test of fgetc() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fgetc, 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";
+
+  /* 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";
+    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);
+  }
+
+  /* Test that fgetc() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fgetc (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.  */
+  {
+    FILE *fp = fdopen (-1, "r");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fgetc (fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "r");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fgetc (fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-float.c b/gl/tests/test-float.c
new file mode 100644
index 0000000..57a472f
--- /dev/null
+++ b/gl/tests/test-float.c
@@ -0,0 +1,391 @@
+/* Test of <float.h> substitute.
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include <float.h>
+
+#include "fpucw.h"
+#include "macros.h"
+
+/* Check that FLT_RADIX is a constant expression.  */
+int a[] = { FLT_RADIX };
+
+#if FLT_RADIX == 2
+
+/* Return 2^n.  */
+static float
+pow2f (int n)
+{
+  int k = n;
+  volatile float x = 1;
+  volatile float y = 2;
+  /* Invariant: 2^n == x * y^k.  */
+  if (k < 0)
+    {
+      y = 0.5f;
+      k = - k;
+    }
+  while (k > 0)
+    {
+      if (k != 2 * (k / 2))
+        {
+          x = x * y;
+          k = k - 1;
+        }
+      if (k == 0)
+        break;
+      y = y * y;
+      k = k / 2;
+    }
+  /* Now k == 0, hence x == 2^n.  */
+  return x;
+}
+
+/* Return 2^n.  */
+static double
+pow2d (int n)
+{
+  int k = n;
+  volatile double x = 1;
+  volatile double y = 2;
+  /* Invariant: 2^n == x * y^k.  */
+  if (k < 0)
+    {
+      y = 0.5;
+      k = - k;
+    }
+  while (k > 0)
+    {
+      if (k != 2 * (k / 2))
+        {
+          x = x * y;
+          k = k - 1;
+        }
+      if (k == 0)
+        break;
+      y = y * y;
+      k = k / 2;
+    }
+  /* Now k == 0, hence x == 2^n.  */
+  return x;
+}
+
+/* Return 2^n.  */
+static long double
+pow2l (int n)
+{
+  int k = n;
+  volatile long double x = 1;
+  volatile long double y = 2;
+  /* Invariant: 2^n == x * y^k.  */
+  if (k < 0)
+    {
+      y = 0.5L;
+      k = - k;
+    }
+  while (k > 0)
+    {
+      if (k != 2 * (k / 2))
+        {
+          x = x * y;
+          k = k - 1;
+        }
+      if (k == 0)
+        break;
+      y = y * y;
+      k = k / 2;
+    }
+  /* Now k == 0, hence x == 2^n.  */
+  return x;
+}
+
+/* ----------------------- Check macros for 'float' ----------------------- */
+
+/* Check that the FLT_* macros expand to constant expressions.  */
+int fb[] =
+  {
+    FLT_MANT_DIG, FLT_MIN_EXP, FLT_MAX_EXP,
+    FLT_DIG, FLT_MIN_10_EXP, FLT_MAX_10_EXP
+  };
+float fc[] = { FLT_EPSILON, FLT_MIN, FLT_MAX };
+
+static void
+test_float (void)
+{
+  /* Check that the value of FLT_MIN_EXP is well parenthesized.  */
+  ASSERT ((FLT_MIN_EXP % 101111) == (FLT_MIN_EXP) % 101111);
+
+  /* Check that the value of DBL_MIN_10_EXP is well parenthesized.  */
+  ASSERT ((FLT_MIN_10_EXP % 101111) == (FLT_MIN_10_EXP) % 101111);
+
+  /* Check that 'float' is as specified in IEEE 754.  */
+  ASSERT (FLT_MANT_DIG == 24);
+  ASSERT (FLT_MIN_EXP == -125);
+  ASSERT (FLT_MAX_EXP == 128);
+
+  /* Check the value of FLT_MIN_10_EXP.  */
+  ASSERT (FLT_MIN_10_EXP == - (int) (- (FLT_MIN_EXP - 1) * 0.30103));
+
+  /* Check the value of FLT_DIG.  */
+  ASSERT (FLT_DIG == (int) ((FLT_MANT_DIG - 1) * 0.30103));
+
+  /* Check the value of FLT_MIN_10_EXP.  */
+  ASSERT (FLT_MIN_10_EXP == - (int) (- (FLT_MIN_EXP - 1) * 0.30103));
+
+  /* Check the value of FLT_MAX_10_EXP.  */
+  ASSERT (FLT_MAX_10_EXP == (int) (FLT_MAX_EXP * 0.30103));
+
+  /* Check the value of FLT_MAX.  */
+  {
+    volatile float m = FLT_MAX;
+    int n;
+
+    ASSERT (m + m > m);
+    for (n = 0; n <= 2 * FLT_MANT_DIG; n++)
+      {
+        volatile float pow2_n = pow2f (n); /* 2^n */
+        volatile float x = m + (m / pow2_n);
+        if (x > m)
+          ASSERT (x + x == x);
+        else
+          ASSERT (!(x + x == x));
+      }
+  }
+
+  /* Check the value of FLT_MIN.  */
+  {
+    volatile float m = FLT_MIN;
+    volatile float x = pow2f (FLT_MIN_EXP - 1);
+    ASSERT (m == x);
+  }
+
+  /* Check the value of FLT_EPSILON.  */
+  {
+    volatile float e = FLT_EPSILON;
+    volatile float me;
+    int n;
+
+    me = 1.0f + e;
+    ASSERT (me > 1.0f);
+    ASSERT (me - 1.0f == e);
+    for (n = 0; n <= 2 * FLT_MANT_DIG; n++)
+      {
+        volatile float half_n = pow2f (- n); /* 2^-n */
+        volatile float x = me - half_n;
+        if (x < me)
+          ASSERT (x <= 1.0f);
+      }
+  }
+}
+
+/* ----------------------- Check macros for 'double' ----------------------- */
+
+/* Check that the DBL_* macros expand to constant expressions.  */
+int db[] =
+  {
+    DBL_MANT_DIG, DBL_MIN_EXP, DBL_MAX_EXP,
+    DBL_DIG, DBL_MIN_10_EXP, DBL_MAX_10_EXP
+  };
+double dc[] = { DBL_EPSILON, DBL_MIN, DBL_MAX };
+
+static void
+test_double (void)
+{
+  /* Check that the value of DBL_MIN_EXP is well parenthesized.  */
+  ASSERT ((DBL_MIN_EXP % 101111) == (DBL_MIN_EXP) % 101111);
+
+  /* Check that the value of DBL_MIN_10_EXP is well parenthesized.  */
+  ASSERT ((DBL_MIN_10_EXP % 101111) == (DBL_MIN_10_EXP) % 101111);
+
+  /* Check that 'double' is as specified in IEEE 754.  */
+  ASSERT (DBL_MANT_DIG == 53);
+  ASSERT (DBL_MIN_EXP == -1021);
+  ASSERT (DBL_MAX_EXP == 1024);
+
+  /* Check the value of DBL_MIN_10_EXP.  */
+  ASSERT (DBL_MIN_10_EXP == - (int) (- (DBL_MIN_EXP - 1) * 0.30103));
+
+  /* Check the value of DBL_DIG.  */
+  ASSERT (DBL_DIG == (int) ((DBL_MANT_DIG - 1) * 0.30103));
+
+  /* Check the value of DBL_MIN_10_EXP.  */
+  ASSERT (DBL_MIN_10_EXP == - (int) (- (DBL_MIN_EXP - 1) * 0.30103));
+
+  /* Check the value of DBL_MAX_10_EXP.  */
+  ASSERT (DBL_MAX_10_EXP == (int) (DBL_MAX_EXP * 0.30103));
+
+  /* Check the value of DBL_MAX.  */
+  {
+    volatile double m = DBL_MAX;
+    int n;
+
+    ASSERT (m + m > m);
+    for (n = 0; n <= 2 * DBL_MANT_DIG; n++)
+      {
+        volatile double pow2_n = pow2d (n); /* 2^n */
+        volatile double x = m + (m / pow2_n);
+        if (x > m)
+          ASSERT (x + x == x);
+        else
+          ASSERT (!(x + x == x));
+      }
+  }
+
+  /* Check the value of DBL_MIN.  */
+  {
+    volatile double m = DBL_MIN;
+    volatile double x = pow2d (DBL_MIN_EXP - 1);
+    ASSERT (m == x);
+  }
+
+  /* Check the value of DBL_EPSILON.  */
+  {
+    volatile double e = DBL_EPSILON;
+    volatile double me;
+    int n;
+
+    me = 1.0 + e;
+    ASSERT (me > 1.0);
+    ASSERT (me - 1.0 == e);
+    for (n = 0; n <= 2 * DBL_MANT_DIG; n++)
+      {
+        volatile double half_n = pow2d (- n); /* 2^-n */
+        volatile double x = me - half_n;
+        if (x < me)
+          ASSERT (x <= 1.0);
+      }
+  }
+}
+
+/* -------------------- Check macros for 'long double' -------------------- */
+
+/* Check that the LDBL_* macros expand to constant expressions.  */
+int lb[] =
+  {
+    LDBL_MANT_DIG, LDBL_MIN_EXP, LDBL_MAX_EXP,
+    LDBL_DIG, LDBL_MIN_10_EXP, LDBL_MAX_10_EXP
+  };
+long double lc1 = LDBL_EPSILON;
+long double lc2 = LDBL_MIN;
+#if 0 /* LDBL_MAX is not a constant expression on some platforms.  */
+long double lc3 = LDBL_MAX;
+#endif
+
+static void
+test_long_double (void)
+{
+  /* Check that the value of LDBL_MIN_EXP is well parenthesized.  */
+  ASSERT ((LDBL_MIN_EXP % 101111) == (LDBL_MIN_EXP) % 101111);
+
+  /* Check that the value of LDBL_MIN_10_EXP is well parenthesized.  */
+  ASSERT ((LDBL_MIN_10_EXP % 101111) == (LDBL_MIN_10_EXP) % 101111);
+
+  /* Check that 'long double' is at least as wide as 'double'.  */
+  ASSERT (LDBL_MANT_DIG >= DBL_MANT_DIG);
+
+  /* Normally, we would also assert this:
+       ASSERT (LDBL_MIN_EXP <= DBL_MIN_EXP);
+     but at least on powerpc64 with gcc-4.4.4, it would fail:
+     $ :|gcc -dD -E -include stddef.h -|grep -E 'L?DBL_MIN_EXP'
+     #define __DBL_MIN_EXP__ (-1021)
+     #define __LDBL_MIN_EXP__ (-968)
+  */
+  ASSERT (LDBL_MAX_EXP >= DBL_MAX_EXP);
+
+  /* Check the value of LDBL_DIG.  */
+  ASSERT (LDBL_DIG == (int)((LDBL_MANT_DIG - 1) * 0.30103));
+
+  /* Check the value of LDBL_MIN_10_EXP.  */
+  ASSERT (LDBL_MIN_10_EXP == - (int) (- (LDBL_MIN_EXP - 1) * 0.30103));
+
+  /* Check the value of LDBL_MAX_10_EXP.  */
+  ASSERT (LDBL_MAX_10_EXP == (int) (LDBL_MAX_EXP * 0.30103));
+
+  /* Check the value of LDBL_MAX.  */
+  {
+    volatile long double m = LDBL_MAX;
+    int n;
+
+    ASSERT (m + m > m);
+    for (n = 0; n <= 2 * LDBL_MANT_DIG; n++)
+      {
+        volatile long double pow2_n = pow2l (n); /* 2^n */
+        volatile long double x = m + (m / pow2_n);
+        if (x > m)
+          ASSERT (x + x == x);
+        else
+          ASSERT (!(x + x == x));
+      }
+  }
+
+  /* Check the value of LDBL_MIN.  */
+  {
+    volatile long double m = LDBL_MIN;
+    volatile long double x = pow2l (LDBL_MIN_EXP - 1);
+    ASSERT (m == x);
+  }
+
+  /* Check the value of LDBL_EPSILON.  */
+  {
+    volatile long double e = LDBL_EPSILON;
+    volatile long double me;
+    int n;
+
+    me = 1.0L + e;
+    ASSERT (me > 1.0L);
+    ASSERT (me - 1.0L == e);
+    for (n = 0; n <= 2 * LDBL_MANT_DIG; n++)
+      {
+        volatile long double half_n = pow2l (- n); /* 2^-n */
+        volatile long double x = me - half_n;
+        if (x < me)
+          ASSERT (x <= 1.0L);
+      }
+  }
+}
+
+int
+main ()
+{
+  test_float ();
+  test_double ();
+
+  {
+    DECL_LONG_DOUBLE_ROUNDING
+
+    BEGIN_LONG_DOUBLE_ROUNDING ();
+
+    test_long_double ();
+
+    END_LONG_DOUBLE_ROUNDING ();
+  }
+
+  return 0;
+}
+
+#else
+
+int
+main ()
+{
+  fprintf (stderr, "Skipping test: FLT_RADIX is not 2.\n");
+  return 77;
+}
+
+#endif
diff --git a/gl/tests/test-fputc.c b/gl/tests/test-fputc.c
new file mode 100644
index 0000000..03a3716
--- /dev/null
+++ b/gl/tests/test-fputc.c
@@ -0,0 +1,90 @@
+/* Test of fputc() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-fputc.txt";
+
+  /* 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 fputc() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "w");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fputc ('x', fp) == EOF);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fputc() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-fread.c b/gl/tests/test-fread.c
new file mode 100644
index 0000000..e205c9e
--- /dev/null
+++ b/gl/tests/test-fread.c
@@ -0,0 +1,99 @@
+/* Test of fread() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-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.  */
+  {
+    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);
+  }
+
+  /* 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 (fread (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* 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 (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "r");
+    if (fp != NULL)
+      {
+        char buf[1];
+        errno = 0;
+        ASSERT (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-fseek.c b/gl/tests/test-fseek.c
similarity index 100%
copy from lib/gl/tests/test-fseek.c
copy to gl/tests/test-fseek.c
diff --git a/lib/gl/tests/test-fseek.sh b/gl/tests/test-fseek.sh
similarity index 100%
copy from lib/gl/tests/test-fseek.sh
copy to gl/tests/test-fseek.sh
diff --git a/lib/gl/tests/test-fseek2.sh b/gl/tests/test-fseek2.sh
similarity index 100%
copy from lib/gl/tests/test-fseek2.sh
copy to gl/tests/test-fseek2.sh
diff --git a/lib/gl/tests/test-fseeko3.c b/gl/tests/test-fseeko3.c
similarity index 100%
copy from lib/gl/tests/test-fseeko3.c
copy to gl/tests/test-fseeko3.c
diff --git a/lib/gl/tests/test-fseeko3.sh b/gl/tests/test-fseeko3.sh
similarity index 100%
copy from lib/gl/tests/test-fseeko3.sh
copy to gl/tests/test-fseeko3.sh
diff --git a/gl/tests/test-fseeko4.c b/gl/tests/test-fseeko4.c
new file mode 100644
index 0000000..61559e1
--- /dev/null
+++ b/gl/tests/test-fseeko4.c
@@ -0,0 +1,71 @@
+/* Test of fseeko() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = argv[1];
+
+  /* Test that fseeko() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (ftell (fp) == 0);
+    ASSERT (fseeko (fp, 0, SEEK_END) == 0);
+    ASSERT (ftell (fp) > 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fseeko (fp, 0, SEEK_SET) == -1);
+    ASSERT (errno == EBADF);
+    fclose (fp);
+  }
+
+  /* Test that fseeko() sets errno if the stream was constructed with
+     an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fseeko (fp, 0, SEEK_END) == -1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fseeko (fp, 0, SEEK_END) == -1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-fseeko4.sh b/gl/tests/test-fseeko4.sh
new file mode 100755
index 0000000..e6464ae
--- /dev/null
+++ b/gl/tests/test-fseeko4.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+./test-fseeko4${EXEEXT} "$srcdir/test-fseeko4.sh" || exit 1
+
+exit 0
diff --git a/gl/tests/test-fstat.c b/gl/tests/test-fstat.c
new file mode 100644
index 0000000..6c120d9
--- /dev/null
+++ b/gl/tests/test-fstat.c
@@ -0,0 +1,48 @@
+/* Tests of fstat() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fstat, int, (int, struct stat *));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (-1, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (99, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-ftell.c b/gl/tests/test-ftell.c
similarity index 100%
copy from lib/gl/tests/test-ftell.c
copy to gl/tests/test-ftell.c
diff --git a/lib/gl/tests/test-ftell.sh b/gl/tests/test-ftell.sh
similarity index 100%
copy from lib/gl/tests/test-ftell.sh
copy to gl/tests/test-ftell.sh
diff --git a/lib/gl/tests/test-ftell2.sh b/gl/tests/test-ftell2.sh
similarity index 100%
copy from lib/gl/tests/test-ftell2.sh
copy to gl/tests/test-ftell2.sh
diff --git a/lib/gl/tests/test-ftell3.c b/gl/tests/test-ftell3.c
similarity index 100%
copy from lib/gl/tests/test-ftell3.c
copy to gl/tests/test-ftell3.c
diff --git a/gl/tests/test-ftello4.c b/gl/tests/test-ftello4.c
new file mode 100644
index 0000000..d503f71
--- /dev/null
+++ b/gl/tests/test-ftello4.c
@@ -0,0 +1,68 @@
+/* Test of ftello() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = argv[1];
+
+  /* Test that ftello() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (ftello (fp) == (off_t)-1);
+    ASSERT (errno == EBADF);
+    fclose (fp);
+  }
+
+  /* Test that ftello() sets errno if the stream was constructed with
+     an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (ftello (fp) == (off_t)-1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (ftello (fp) == (off_t)-1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-ftello4.sh b/gl/tests/test-ftello4.sh
new file mode 100755
index 0000000..e3702bb
--- /dev/null
+++ b/gl/tests/test-ftello4.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+./test-ftello4${EXEEXT} "$srcdir/test-ftello4.sh" || exit 1
+
+exit 0
diff --git a/gl/tests/test-ftruncate.c b/gl/tests/test-ftruncate.c
new file mode 100644
index 0000000..c5da4eb
--- /dev/null
+++ b/gl/tests/test-ftruncate.c
@@ -0,0 +1,59 @@
+/* Test truncating a file.
+   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/>.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (ftruncate, int, (int, off_t));
+
+#include <errno.h>
+#include <fcntl.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  const char *filename = argv[1];
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (ftruncate (-1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (ftruncate (99, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  /* Test behaviour for read-only file descriptors.  */
+  {
+    int fd = open (filename, O_RDONLY);
+    ASSERT (fd >= 0);
+    errno = 0;
+    ASSERT (ftruncate (fd, 0) == -1);
+    ASSERT (errno == EBADF || errno == EINVAL
+            || errno == EACCES /* seen on mingw */
+           );
+    close (fd);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-ftruncate.sh b/gl/tests/test-ftruncate.sh
new file mode 100755
index 0000000..d7394d2
--- /dev/null
+++ b/gl/tests/test-ftruncate.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftruncate${EXEEXT} "$srcdir/test-ftruncate.sh"
diff --git a/gl/tests/test-fwrite.c b/gl/tests/test-fwrite.c
new file mode 100644
index 0000000..76ed05c
--- /dev/null
+++ b/gl/tests/test-fwrite.c
@@ -0,0 +1,93 @@
+/* Test of fwrite() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-fwrite.txt";
+
+  /* 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 fwrite() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    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 (fwrite (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fwrite() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-getaddrinfo.c b/gl/tests/test-getaddrinfo.c
index 4826989..d2984e2 100644
--- a/gl/tests/test-getaddrinfo.c
+++ b/gl/tests/test-getaddrinfo.c
@@ -107,7 +107,7 @@ simple (char const *host, char const *service)
 #endif
       /* Provide details if errno was set.  */
       if (res == EAI_SYSTEM)
-        dbgprintf ("system error: %s\n", strerror (err));
+        fprintf (stderr, "system error: %s\n", strerror (err));
 
       return 1;
     }
diff --git a/gl/tests/test-getcwd-lgpl.c b/gl/tests/test-getcwd-lgpl.c
new file mode 100644
index 0000000..69a7b90
--- /dev/null
+++ b/gl/tests/test-getcwd-lgpl.c
@@ -0,0 +1,102 @@
+/* Test of getcwd() function.
+   Copyright (C) 2009-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/>.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (getcwd, char *, (char *, size_t));
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  char *pwd1;
+  char *pwd2;
+  /* If the user provides an argument, attempt to chdir there first.  */
+  if (1 < argc)
+    {
+      if (chdir (argv[1]) == 0)
+        printf ("changed to directory %s\n", argv[1]);
+    }
+
+  pwd1 = getcwd (NULL, 0);
+  ASSERT (pwd1 && *pwd1);
+  if (1 < argc)
+    printf ("cwd=%s\n", pwd1);
+
+  /* Make sure the result is usable.  */
+  ASSERT (chdir (pwd1) == 0);
+  ASSERT (chdir (".//./.") == 0);
+
+  /* Make sure that result is normalized.  */
+  pwd2 = getcwd (NULL, 0);
+  ASSERT (pwd2);
+  ASSERT (strcmp (pwd1, pwd2) == 0);
+  free (pwd2);
+  {
+    size_t len = strlen (pwd1);
+    ssize_t i = len - 10;
+    if (i < 1)
+      i = 1;
+    pwd2 = getcwd (NULL, len + 1);
+    ASSERT (pwd2);
+    free (pwd2);
+    pwd2 = malloc (len + 2);
+    for ( ; i <= len; i++)
+      {
+        char *tmp;
+        errno = 0;
+        ASSERT (getcwd (pwd2, i) == NULL);
+        ASSERT (errno == ERANGE);
+        /* Allow either glibc or BSD behavior, since POSIX allows both.  */
+        errno = 0;
+        tmp = getcwd (NULL, i);
+        if (tmp)
+          {
+            ASSERT (strcmp (pwd1, tmp) == 0);
+            free (tmp);
+          }
+        else
+          {
+            ASSERT (errno == ERANGE);
+          }
+      }
+    ASSERT (getcwd (pwd2, len + 1) == pwd2);
+    pwd2[len] = '/';
+    pwd2[len + 1] = '\0';
+  }
+  ASSERT (strstr (pwd2, "/./") == NULL);
+  ASSERT (strstr (pwd2, "/../") == NULL);
+  ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL);
+
+  /* Validate a POSIX requirement on size.  */
+  errno = 0;
+  ASSERT (getcwd(pwd2, 0) == NULL);
+  ASSERT (errno == EINVAL);
+
+  free (pwd1);
+  free (pwd2);
+
+  return 0;
+}
diff --git a/gl/tests/test-ignore-value.c b/gl/tests/test-ignore-value.c
new file mode 100644
index 0000000..6953f4c
--- /dev/null
+++ b/gl/tests/test-ignore-value.c
@@ -0,0 +1,84 @@
+/* Test the "ignore-value" module.
+
+   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/>.  */
+
+/* Written by Eric Blake.  */
+
+#include <config.h>
+
+#include "ignore-value.h"
+
+#include <stdio.h>
+
+#ifndef _GL_ATTRIBUTE_RETURN_CHECK
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+#  define _GL_ATTRIBUTE_RETURN_CHECK
+# else
+#  define _GL_ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
+# endif
+#endif
+
+struct s { int i; };
+static char doChar (void) _GL_ATTRIBUTE_RETURN_CHECK;
+static int doInt (void) _GL_ATTRIBUTE_RETURN_CHECK;
+static off_t doOff (void) _GL_ATTRIBUTE_RETURN_CHECK;
+static void *doPtr (void) _GL_ATTRIBUTE_RETURN_CHECK;
+static struct s doStruct (void) _GL_ATTRIBUTE_RETURN_CHECK;
+
+static char
+doChar (void)
+{
+  return 0;
+}
+
+static int
+doInt (void)
+{
+  return 0;
+}
+
+static off_t
+doOff (void)
+{
+  return 0;
+}
+
+static void *
+doPtr (void)
+{
+  return NULL;
+}
+
+static struct s
+doStruct (void)
+{
+  static struct s s1;
+  return s1;
+}
+
+int
+main (void)
+{
+  /* If this test can compile with -Werror and the same warnings as
+     the rest of the project, then we are properly silencing warnings
+     about ignored return values.  */
+  ignore_value (doChar ());
+  ignore_value (doInt ());
+  ignore_value (doOff ());
+  ignore_value (doPtr ());
+  ignore_value (doStruct ());
+  return 0;
+}
diff --git a/lib/gl/tests/test-intprops.c b/gl/tests/test-intprops.c
similarity index 100%
copy from lib/gl/tests/test-intprops.c
copy to gl/tests/test-intprops.c
diff --git a/lib/gl/tests/test-inttypes.c b/gl/tests/test-inttypes.c
similarity index 100%
copy from lib/gl/tests/test-inttypes.c
copy to gl/tests/test-inttypes.c
diff --git a/gl/tests/test-ioctl.c b/gl/tests/test-ioctl.c
new file mode 100644
index 0000000..130ee42
--- /dev/null
+++ b/gl/tests/test-ioctl.c
@@ -0,0 +1,49 @@
+/* Test of ioctl() function.
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <sys/ioctl.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (ioctl, int, (int, int, ...));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#ifdef FIONREAD
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    int value;
+    errno = 0;
+    ASSERT (ioctl (-1, FIONREAD, &value) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    int value;
+    errno = 0;
+    ASSERT (ioctl (99, FIONREAD, &value) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-listen.c b/gl/tests/test-listen.c
new file mode 100644
index 0000000..becc453
--- /dev/null
+++ b/gl/tests/test-listen.c
@@ -0,0 +1,47 @@
+/* Test listen() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (listen, int, (int, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (listen (-1, 1) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (listen (99 ,1) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-lock.c b/gl/tests/test-lock.c
new file mode 100644
index 0000000..3f8846b
--- /dev/null
+++ b/gl/tests/test-lock.c
@@ -0,0 +1,601 @@
+/* Test of locking in multithreaded situations.
+   Copyright (C) 2005, 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
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.  */
+
+#include <config.h>
+
+#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || 
USE_WIN32_THREADS
+
+#if USE_POSIX_THREADS
+# define TEST_POSIX_THREADS 1
+#endif
+#if USE_SOLARIS_THREADS
+# define TEST_SOLARIS_THREADS 1
+#endif
+#if USE_PTH_THREADS
+# define TEST_PTH_THREADS 1
+#endif
+#if USE_WIN32_THREADS
+# define TEST_WIN32_THREADS 1
+#endif
+
+/* Whether to enable locking.
+   Uncomment this to get a test program without locking, to verify that
+   it crashes.  */
+#define ENABLE_LOCKING 1
+
+/* Which tests to perform.
+   Uncomment some of these, to verify that all tests crash if no locking
+   is enabled.  */
+#define DO_TEST_LOCK 1
+#define DO_TEST_RWLOCK 1
+#define DO_TEST_RECURSIVE_LOCK 1
+#define DO_TEST_ONCE 1
+
+/* Whether to help the scheduler through explicit yield().
+   Uncomment this to see if the operating system has a fair scheduler.  */
+#define EXPLICIT_YIELD 1
+
+/* Whether to print debugging messages.  */
+#define ENABLE_DEBUGGING 0
+
+/* Number of simultaneous threads.  */
+#define THREAD_COUNT 10
+
+/* Number of operations performed in each thread.
+   This is quite high, because with a smaller count, say 5000, we often get
+   an "OK" result even without ENABLE_LOCKING (on Linux/x86).  */
+#define REPEAT_COUNT 50000
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !ENABLE_LOCKING
+# undef USE_POSIX_THREADS
+# undef USE_SOLARIS_THREADS
+# undef USE_PTH_THREADS
+# undef USE_WIN32_THREADS
+#endif
+#include "glthread/lock.h"
+
+#if !ENABLE_LOCKING
+# if TEST_POSIX_THREADS
+#  define USE_POSIX_THREADS 1
+# endif
+# if TEST_SOLARIS_THREADS
+#  define USE_SOLARIS_THREADS 1
+# endif
+# if TEST_PTH_THREADS
+#  define USE_PTH_THREADS 1
+# endif
+# if TEST_WIN32_THREADS
+#  define USE_WIN32_THREADS 1
+# endif
+#endif
+
+#include "glthread/thread.h"
+#include "glthread/yield.h"
+
+#if ENABLE_DEBUGGING
+# define dbgprintf printf
+#else
+# define dbgprintf if (0) printf
+#endif
+
+#if EXPLICIT_YIELD
+# define yield() gl_thread_yield ()
+#else
+# define yield()
+#endif
+
+#define ACCOUNT_COUNT 4
+
+static int account[ACCOUNT_COUNT];
+
+static int
+random_account (void)
+{
+  return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
+}
+
+static void
+check_accounts (void)
+{
+  int i, sum;
+
+  sum = 0;
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    sum += account[i];
+  if (sum != ACCOUNT_COUNT * 1000)
+    abort ();
+}
+
+
+/* ------------------- Test normal (non-recursive) locks ------------------- */
+
+/* Test normal locks by having several bank accounts and several threads
+   which shuffle around money between the accounts and another thread
+   checking that all the money is still there.  */
+
+gl_lock_define_initialized(static, my_lock)
+
+static void *
+lock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      int i1, i2, value;
+
+      dbgprintf ("Mutator %p before lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      dbgprintf ("Mutator %p after  lock\n", gl_thread_self_pointer ());
+
+      i1 = random_account ();
+      i2 = random_account ();
+      value = ((unsigned int) rand () >> 3) % 10;
+      account[i1] += value;
+      account[i2] -= value;
+
+      dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+
+      dbgprintf ("Mutator %p before check lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      check_accounts ();
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Mutator %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int lock_checker_done;
+
+static void *
+lock_checker_thread (void *arg)
+{
+  while (!lock_checker_done)
+    {
+      dbgprintf ("Checker %p before check lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      check_accounts ();
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_lock (void)
+{
+  int i;
+  gl_thread_t checkerthread;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  lock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  checkerthread = gl_thread_create (lock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (lock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  lock_checker_done = 1;
+  gl_thread_join (checkerthread, NULL);
+  check_accounts ();
+}
+
+
+/* ----------------- Test read-write (non-recursive) locks ----------------- */
+
+/* Test read-write locks by having several bank accounts and several threads
+   which shuffle around money between the accounts and several other threads
+   that check that all the money is still there.  */
+
+gl_rwlock_define_initialized(static, my_rwlock)
+
+static void *
+rwlock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      int i1, i2, value;
+
+      dbgprintf ("Mutator %p before wrlock\n", gl_thread_self_pointer ());
+      gl_rwlock_wrlock (my_rwlock);
+      dbgprintf ("Mutator %p after  wrlock\n", gl_thread_self_pointer ());
+
+      i1 = random_account ();
+      i2 = random_account ();
+      value = ((unsigned int) rand () >> 3) % 10;
+      account[i1] += value;
+      account[i2] -= value;
+
+      dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+      gl_rwlock_unlock (my_rwlock);
+      dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int rwlock_checker_done;
+
+static void *
+rwlock_checker_thread (void *arg)
+{
+  while (!rwlock_checker_done)
+    {
+      dbgprintf ("Checker %p before check rdlock\n", gl_thread_self_pointer 
());
+      gl_rwlock_rdlock (my_rwlock);
+      check_accounts ();
+      gl_rwlock_unlock (my_rwlock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_rwlock (void)
+{
+  int i;
+  gl_thread_t checkerthreads[THREAD_COUNT];
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  rwlock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    checkerthreads[i] = gl_thread_create (rwlock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (rwlock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  rwlock_checker_done = 1;
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (checkerthreads[i], NULL);
+  check_accounts ();
+}
+
+
+/* -------------------------- Test recursive locks -------------------------- 
*/
+
+/* Test recursive locks by having several bank accounts and several threads
+   which shuffle around money between the accounts (recursively) and another
+   thread checking that all the money is still there.  */
+
+gl_recursive_lock_define_initialized(static, my_reclock)
+
+static void
+recshuffle (void)
+{
+  int i1, i2, value;
+
+  dbgprintf ("Mutator %p before lock\n", gl_thread_self_pointer ());
+  gl_recursive_lock_lock (my_reclock);
+  dbgprintf ("Mutator %p after  lock\n", gl_thread_self_pointer ());
+
+  i1 = random_account ();
+  i2 = random_account ();
+  value = ((unsigned int) rand () >> 3) % 10;
+  account[i1] += value;
+  account[i2] -= value;
+
+  /* Recursive with probability 0.5.  */
+  if (((unsigned int) rand () >> 3) % 2)
+    recshuffle ();
+
+  dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+  gl_recursive_lock_unlock (my_reclock);
+  dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+}
+
+static void *
+reclock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      recshuffle ();
+
+      dbgprintf ("Mutator %p before check lock\n", gl_thread_self_pointer ());
+      gl_recursive_lock_lock (my_reclock);
+      check_accounts ();
+      gl_recursive_lock_unlock (my_reclock);
+      dbgprintf ("Mutator %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int reclock_checker_done;
+
+static void *
+reclock_checker_thread (void *arg)
+{
+  while (!reclock_checker_done)
+    {
+      dbgprintf ("Checker %p before check lock\n", gl_thread_self_pointer ());
+      gl_recursive_lock_lock (my_reclock);
+      check_accounts ();
+      gl_recursive_lock_unlock (my_reclock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_recursive_lock (void)
+{
+  int i;
+  gl_thread_t checkerthread;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  reclock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  checkerthread = gl_thread_create (reclock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (reclock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  reclock_checker_done = 1;
+  gl_thread_join (checkerthread, NULL);
+  check_accounts ();
+}
+
+
+/* ------------------------ Test once-only execution ------------------------ 
*/
+
+/* Test once-only execution by having several threads attempt to grab a
+   once-only task simultaneously (triggered by releasing a read-write lock).  
*/
+
+gl_once_define(static, fresh_once)
+static int ready[THREAD_COUNT];
+static gl_lock_t ready_lock[THREAD_COUNT];
+#if ENABLE_LOCKING
+static gl_rwlock_t fire_signal[REPEAT_COUNT];
+#else
+static volatile int fire_signal_state;
+#endif
+static gl_once_t once_control;
+static int performed;
+gl_lock_define_initialized(static, performed_lock)
+
+static void
+once_execute (void)
+{
+  gl_lock_lock (performed_lock);
+  performed++;
+  gl_lock_unlock (performed_lock);
+}
+
+static void *
+once_contender_thread (void *arg)
+{
+  int id = (int) (long) arg;
+  int repeat;
+
+  for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
+    {
+      /* Tell the main thread that we're ready.  */
+      gl_lock_lock (ready_lock[id]);
+      ready[id] = 1;
+      gl_lock_unlock (ready_lock[id]);
+
+      if (repeat == REPEAT_COUNT)
+        break;
+
+      dbgprintf ("Contender %p waiting for signal for round %d\n",
+                 gl_thread_self_pointer (), repeat);
+#if ENABLE_LOCKING
+      /* Wait for the signal to go.  */
+      gl_rwlock_rdlock (fire_signal[repeat]);
+      /* And don't hinder the others (if the scheduler is unfair).  */
+      gl_rwlock_unlock (fire_signal[repeat]);
+#else
+      /* Wait for the signal to go.  */
+      while (fire_signal_state <= repeat)
+        yield ();
+#endif
+      dbgprintf ("Contender %p got the     signal for round %d\n",
+                 gl_thread_self_pointer (), repeat);
+
+      /* Contend for execution.  */
+      gl_once (once_control, once_execute);
+    }
+
+  return NULL;
+}
+
+static void
+test_once (void)
+{
+  int i, repeat;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialize all variables.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    {
+      ready[i] = 0;
+      gl_lock_init (ready_lock[i]);
+    }
+#if ENABLE_LOCKING
+  for (i = 0; i < REPEAT_COUNT; i++)
+    gl_rwlock_init (fire_signal[i]);
+#else
+  fire_signal_state = 0;
+#endif
+
+  /* Block all fire_signals.  */
+  for (i = REPEAT_COUNT-1; i >= 0; i--)
+    gl_rwlock_wrlock (fire_signal[i]);
+
+  /* Spawn the threads.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (once_contender_thread, (void *) (long) i);
+
+  for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
+    {
+      /* Wait until every thread is ready.  */
+      dbgprintf ("Main thread before synchonizing for round %d\n", repeat);
+      for (;;)
+        {
+          int ready_count = 0;
+          for (i = 0; i < THREAD_COUNT; i++)
+            {
+              gl_lock_lock (ready_lock[i]);
+              ready_count += ready[i];
+              gl_lock_unlock (ready_lock[i]);
+            }
+          if (ready_count == THREAD_COUNT)
+            break;
+          yield ();
+        }
+      dbgprintf ("Main thread after  synchonizing for round %d\n", repeat);
+
+      if (repeat > 0)
+        {
+          /* Check that exactly one thread executed the once_execute()
+             function.  */
+          if (performed != 1)
+            abort ();
+        }
+
+      if (repeat == REPEAT_COUNT)
+        break;
+
+      /* Preparation for the next round: Initialize once_control.  */
+      memcpy (&once_control, &fresh_once, sizeof (gl_once_t));
+
+      /* Preparation for the next round: Reset the performed counter.  */
+      performed = 0;
+
+      /* Preparation for the next round: Reset the ready flags.  */
+      for (i = 0; i < THREAD_COUNT; i++)
+        {
+          gl_lock_lock (ready_lock[i]);
+          ready[i] = 0;
+          gl_lock_unlock (ready_lock[i]);
+        }
+
+      /* Signal all threads simultaneously.  */
+      dbgprintf ("Main thread giving signal for round %d\n", repeat);
+#if ENABLE_LOCKING
+      gl_rwlock_unlock (fire_signal[repeat]);
+#else
+      fire_signal_state = repeat + 1;
+#endif
+    }
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+}
+
+
+/* -------------------------------------------------------------------------- 
*/
+
+int
+main ()
+{
+#if TEST_PTH_THREADS
+  if (!pth_init ())
+    abort ();
+#endif
+
+#if DO_TEST_LOCK
+  printf ("Starting test_lock ..."); fflush (stdout);
+  test_lock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_RWLOCK
+  printf ("Starting test_rwlock ..."); fflush (stdout);
+  test_rwlock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_RECURSIVE_LOCK
+  printf ("Starting test_recursive_lock ..."); fflush (stdout);
+  test_recursive_lock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_ONCE
+  printf ("Starting test_once ..."); fflush (stdout);
+  test_once ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+
+  return 0;
+}
+
+#else
+
+/* No multithreading available.  */
+
+#include <stdio.h>
+
+int
+main ()
+{
+  fputs ("Skipping test: multithreading not enabled\n", stderr);
+  return 77;
+}
+
+#endif
diff --git a/gl/tests/test-lseek.c b/gl/tests/test-lseek.c
index 400d3d2..f74516c 100644
--- a/gl/tests/test-lseek.c
+++ b/gl/tests/test-lseek.c
@@ -78,15 +78,27 @@ main (int argc, char **argv)
 
     case '2': /* closed */
       /* Explicitly close file descriptors 0 and 1.  The <&- and >&- in the
-         invoking shell are not enough on HP-UX.
-      close (0);     calling close fails on mingw -- address@hidden
-      close (1);  */
+         invoking shell are not enough on HP-UX.  */
+      close (0);
+      close (1);
+
       errno = 0;
       ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
       ASSERT (errno == EBADF);
+
       errno = 0;
       ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
       ASSERT (errno == EBADF);
+
+      /* Test behaviour for invalid file descriptors.  */
+      errno = 0;
+      ASSERT (lseek (-1, (off_t)0, SEEK_CUR) == -1);
+      ASSERT (errno == EBADF);
+
+      errno = 0;
+      ASSERT (lseek (99, (off_t)0, SEEK_CUR) == -1);
+      ASSERT (errno == EBADF);
+
       break;
 
     default:
diff --git a/gl/tests/test-lstat.c b/gl/tests/test-lstat.c
new file mode 100644
index 0000000..372e056
--- /dev/null
+++ b/gl/tests/test-lstat.c
@@ -0,0 +1,60 @@
+/* Test of lstat() function.
+   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
+   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/>.  */
+
+/* Written by Simon Josefsson, 2008; and Eric Blake, 2009.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+/* Caution: lstat may be a function-like macro.  Although this
+   signature check must pass, it may be the signature of the real (and
+   broken) lstat rather than rpl_lstat.  Most code should not use the
+   address of lstat.  */
+#include "signature.h"
+SIGNATURE_CHECK (lstat, int, (char const *, struct stat *));
+
+#include <fcntl.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "same-inode.h"
+#include "ignore-value.h"
+#include "macros.h"
+
+#define BASE "test-lstat.t"
+
+#include "test-lstat.h"
+
+/* Wrapper around lstat, which works even if lstat is a function-like
+   macro, where test_lstat_func(lstat) would do the wrong thing.  */
+static int
+do_lstat (char const *name, struct stat *st)
+{
+  return lstat (name, st);
+}
+
+int
+main (void)
+{
+  /* Remove any leftovers from a previous partial run.  */
+  ignore_value (system ("rm -rf " BASE "*"));
+
+  return test_lstat_func (do_lstat, true);
+}
diff --git a/gl/tests/test-lstat.h b/gl/tests/test-lstat.h
new file mode 100644
index 0000000..883c4e8
--- /dev/null
+++ b/gl/tests/test-lstat.h
@@ -0,0 +1,116 @@
+/* Test of lstat() function.
+   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
+   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/>.  */
+
+/* Written by Simon Josefsson, 2008; and Eric Blake, 2009.  */
+
+/* This file is designed to test both lstat(n,buf) and
+   fstatat(AT_FDCWD,n,buf,AT_SYMLINK_NOFOLLOW).  FUNC is the function
+   to test.  Assumes that BASE and ASSERT are already defined, and
+   that appropriate headers are already included.  If PRINT, warn
+   before skipping symlink tests with status 77.  */
+
+static int
+test_lstat_func (int (*func) (char const *, struct stat *), bool print)
+{
+  struct stat st1;
+  struct stat st2;
+
+  /* Test for common directories.  */
+  ASSERT (func (".", &st1) == 0);
+  ASSERT (func ("./", &st2) == 0);
+  ASSERT (SAME_INODE (st1, st2));
+  ASSERT (S_ISDIR (st1.st_mode));
+  ASSERT (S_ISDIR (st2.st_mode));
+  ASSERT (func ("/", &st1) == 0);
+  ASSERT (func ("///", &st2) == 0);
+  ASSERT (SAME_INODE (st1, st2));
+  ASSERT (S_ISDIR (st1.st_mode));
+  ASSERT (S_ISDIR (st2.st_mode));
+  ASSERT (func ("..", &st1) == 0);
+  ASSERT (S_ISDIR (st1.st_mode));
+
+  /* Test for error conditions.  */
+  errno = 0;
+  ASSERT (func ("", &st1) == -1);
+  ASSERT (errno == ENOENT);
+  errno = 0;
+  ASSERT (func ("nosuch", &st1) == -1);
+  ASSERT (errno == ENOENT);
+  errno = 0;
+  ASSERT (func ("nosuch/", &st1) == -1);
+  ASSERT (errno == ENOENT);
+
+  ASSERT (close (creat (BASE "file", 0600)) == 0);
+  ASSERT (func (BASE "file", &st1) == 0);
+  ASSERT (S_ISREG (st1.st_mode));
+  errno = 0;
+  ASSERT (func (BASE "file/", &st1) == -1);
+  ASSERT (errno == ENOTDIR);
+
+  /* Now for some symlink tests, where supported.  We set up:
+     link1 -> directory
+     link2 -> file
+     link3 -> dangling
+     link4 -> loop
+     then test behavior both with and without trailing slash.
+  */
+  if (symlink (".", BASE "link1") != 0)
+    {
+      ASSERT (unlink (BASE "file") == 0);
+      if (print)
+        fputs ("skipping test: symlinks not supported on this file system\n",
+               stderr);
+      return 77;
+    }
+  ASSERT (symlink (BASE "file", BASE "link2") == 0);
+  ASSERT (symlink (BASE "nosuch", BASE "link3") == 0);
+  ASSERT (symlink (BASE "link4", BASE "link4") == 0);
+
+  ASSERT (func (BASE "link1", &st1) == 0);
+  ASSERT (S_ISLNK (st1.st_mode));
+  ASSERT (func (BASE "link1/", &st1) == 0);
+  ASSERT (stat (BASE "link1", &st2) == 0);
+  ASSERT (S_ISDIR (st1.st_mode));
+  ASSERT (S_ISDIR (st2.st_mode));
+  ASSERT (SAME_INODE (st1, st2));
+
+  ASSERT (func (BASE "link2", &st1) == 0);
+  ASSERT (S_ISLNK (st1.st_mode));
+  errno = 0;
+  ASSERT (func (BASE "link2/", &st1) == -1);
+  ASSERT (errno == ENOTDIR);
+
+  ASSERT (func (BASE "link3", &st1) == 0);
+  ASSERT (S_ISLNK (st1.st_mode));
+  errno = 0;
+  ASSERT (func (BASE "link3/", &st1) == -1);
+  ASSERT (errno == ENOENT);
+
+  ASSERT (func (BASE "link4", &st1) == 0);
+  ASSERT (S_ISLNK (st1.st_mode));
+  errno = 0;
+  ASSERT (func (BASE "link4/", &st1) == -1);
+  ASSERT (errno == ELOOP);
+
+  /* Cleanup.  */
+  ASSERT (unlink (BASE "file") == 0);
+  ASSERT (unlink (BASE "link1") == 0);
+  ASSERT (unlink (BASE "link2") == 0);
+  ASSERT (unlink (BASE "link3") == 0);
+  ASSERT (unlink (BASE "link4") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-open.c b/gl/tests/test-open.c
new file mode 100644
index 0000000..3c5b2ab
--- /dev/null
+++ b/gl/tests/test-open.c
@@ -0,0 +1,41 @@
+/* Test of opening a file descriptor.
+   Copyright (C) 2007-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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2007.  */
+
+#include <config.h>
+
+#include <fcntl.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (open, int, (char const *, int, ...));
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+#define BASE "test-open.t"
+
+#include "test-open.h"
+
+int
+main (void)
+{
+  return test_open (open, true);
+}
diff --git a/gl/tests/test-open.h b/gl/tests/test-open.h
new file mode 100644
index 0000000..2ba5d13
--- /dev/null
+++ b/gl/tests/test-open.h
@@ -0,0 +1,93 @@
+/* Test of opening a file descriptor.
+   Copyright (C) 2007-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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2007.  */
+
+/* This file is designed to test both open(n,buf[,mode]) and
+   openat(AT_FDCWD,n,buf[,mode]).  FUNC is the function to test.
+   Assumes that BASE and ASSERT are already defined, and that
+   appropriate headers are already included.  If PRINT, warn before
+   skipping symlink tests with status 77.  */
+
+static int
+test_open (int (*func) (char const *, int, ...), bool print)
+{
+  int fd;
+  /* Remove anything from prior partial run.  */
+  unlink (BASE "file");
+
+  /* Cannot create directory.  */
+  errno = 0;
+  ASSERT (func ("nonexist.ent/", O_CREAT | O_RDONLY, 0600) == -1);
+  ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT
+          || errno == EINVAL);
+
+  /* Create a regular file.  */
+  fd = func (BASE "file", O_CREAT | O_RDONLY, 0600);
+  ASSERT (0 <= fd);
+  ASSERT (close (fd) == 0);
+
+  /* Trailing slash handling.  */
+  errno = 0;
+  ASSERT (func (BASE "file/", O_RDONLY) == -1);
+  ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+
+  /* Directories cannot be opened for writing.  */
+  errno = 0;
+  ASSERT (func (".", O_WRONLY) == -1);
+  ASSERT (errno == EISDIR || errno == EACCES);
+
+  /* /dev/null must exist, and be writable.  */
+  fd = func ("/dev/null", O_RDONLY);
+  ASSERT (0 <= fd);
+  {
+    char c;
+    ASSERT (read (fd, &c, 1) == 0);
+  }
+  ASSERT (close (fd) == 0);
+  fd = func ("/dev/null", O_WRONLY);
+  ASSERT (0 <= fd);
+  ASSERT (write (fd, "c", 1) == 1);
+  ASSERT (close (fd) == 0);
+
+  /* Although O_NONBLOCK on regular files can be ignored, it must not
+     cause a failure.  */
+  fd = func (BASE "file", O_NONBLOCK | O_RDONLY);
+  ASSERT (0 <= fd);
+  ASSERT (close (fd) == 0);
+
+  /* Symlink handling, where supported.  */
+  if (symlink (BASE "file", BASE "link") != 0)
+    {
+      ASSERT (unlink (BASE "file") == 0);
+      if (print)
+        fputs ("skipping test: symlinks not supported on this file system\n",
+               stderr);
+      return 77;
+    }
+  errno = 0;
+  ASSERT (func (BASE "link/", O_RDONLY) == -1);
+  ASSERT (errno == ENOTDIR);
+  fd = func (BASE "link", O_RDONLY);
+  ASSERT (0 <= fd);
+  ASSERT (close (fd) == 0);
+
+  /* Cleanup.  */
+  ASSERT (unlink (BASE "file") == 0);
+  ASSERT (unlink (BASE "link") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-pathmax.c b/gl/tests/test-pathmax.c
new file mode 100644
index 0000000..96a1364
--- /dev/null
+++ b/gl/tests/test-pathmax.c
@@ -0,0 +1,32 @@
+/* Test of "pathmax.h".
+   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/>.  */
+
+/* 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
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gl/tests/test-perror.sh b/gl/tests/test-perror.sh
index f2c8fdc..7274d32 100755
--- a/gl/tests/test-perror.sh
+++ b/gl/tests/test-perror.sh
@@ -1,27 +1,24 @@
 #!/bin/sh
-
-tmpfiles=""
-trap 'rm -fr $tmpfiles' 1 2 3 15
+: ${srcdir=.}
+. "$srcdir/init.sh"; path_prepend_ .
 
 # Test NULL prefix. Result should not contain a number.
-tmpfiles="$tmpfiles t-perror.tmp"
-./test-perror${EXEEXT} 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp
-if grep '[0-9]' t-perror.tmp > /dev/null; then
-  rm -fr $tmpfiles; exit 1
-fi
+test-perror 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp
+grep '[0-9]' t-perror.tmp > /dev/null \
+  && fail_ "result should not contain a number"
 
 # Test empty prefix. Result should be the same.
-tmpfiles="$tmpfiles t-perror1.tmp"
-./test-perror${EXEEXT} '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp
-diff t-perror.tmp t-perror1.tmp
-test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+test-perror '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp
+diff t-perror.tmp t-perror1.tmp \
+  || fail_ "empty prefix should behave like NULL argument"
 
 # Test non-empty prefix.
-tmpfiles="$tmpfiles t-perror2.tmp t-perror3.tmp"
-./test-perror${EXEEXT} 'foo' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > 
t-perror3.tmp
+test-perror foo 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp
 sed -e 's/^/foo: /' < t-perror.tmp > t-perror2.tmp
-diff t-perror2.tmp t-perror3.tmp
-test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+diff t-perror2.tmp t-perror3.tmp || fail_ "prefix applied incorrectly"
+
+# Test exit status.
+test-perror >out 2>/dev/null || fail_ "unexpected exit status"
+test -s out && fail_ "unexpected output"
 
-rm -fr $tmpfiles
-exit 0
+Exit 0
diff --git a/gl/tests/test-perror2.c b/gl/tests/test-perror2.c
new file mode 100644
index 0000000..e230f92
--- /dev/null
+++ b/gl/tests/test-perror2.c
@@ -0,0 +1,137 @@
+/* Test of perror() function.
+   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>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+/* This test intentionally parses stderr.  So, we arrange to have fd 10
+   (outside the range of interesting fd's during the test) set up to
+   duplicate the original stderr.  */
+#define BACKUP_STDERR_FILENO 10
+#define ASSERT_STREAM myerr
+#include "macros.h"
+
+static FILE *myerr;
+
+#define BASE "test-perror2"
+
+int
+main (void)
+{
+  /* We change fd 2 later, so save it in fd 10.  */
+  if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
+      || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
+    return 2;
+
+  ASSERT (freopen (BASE ".tmp", "w+", stderr) == stderr);
+
+  /* Test that perror does not clobber strerror buffer.  */
+  {
+    const char *msg1;
+    const char *msg2;
+    const char *msg3;
+    const char *msg4;
+    char *str1;
+    char *str2;
+    char *str3;
+    char *str4;
+
+    msg1 = strerror (ENOENT);
+    ASSERT (msg1);
+    str1 = strdup (msg1);
+    ASSERT (str1);
+
+    msg2 = strerror (ERANGE);
+    ASSERT (msg2);
+    str2 = strdup (msg2);
+    ASSERT (str2);
+
+    msg3 = strerror (-4);
+    ASSERT (msg3);
+    str3 = strdup (msg3);
+    ASSERT (str3);
+
+    msg4 = strerror (1729576);
+    ASSERT (msg4);
+    str4 = strdup (msg4);
+    ASSERT (str4);
+
+    errno = EACCES;
+    perror ("");
+    errno = -5;
+    perror ("");
+    ASSERT (!ferror (stderr));
+    ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
+    ASSERT (msg2 == msg4 || STREQ (msg2, str2));
+    ASSERT (msg3 == msg4 || STREQ (msg3, str3));
+    ASSERT (STREQ (msg4, str4));
+
+    free (str1);
+    free (str2);
+    free (str3);
+    free (str4);
+  }
+
+  /* Test that perror uses the same message as strerror.  */
+  {
+    int errs[] = { EACCES, 0, -3, };
+    int i;
+    for (i = 0; i < SIZEOF (errs); i++)
+      {
+        char buf[256];
+        char *err = strerror (errs[i]);
+
+        ASSERT (err);
+        ASSERT (strlen (err) < sizeof buf);
+        rewind (stderr);
+        ASSERT (ftruncate (fileno (stderr), 0) == 0);
+        errno = errs[i];
+        perror (NULL);
+        ASSERT (!ferror (stderr));
+        rewind (stderr);
+        ASSERT (fgets (buf, sizeof buf, stderr) == buf);
+        ASSERT (strstr (buf, err));
+      }
+  }
+
+  /* Test that perror reports write failure.  */
+  {
+    ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);
+    ASSERT (setvbuf (stderr, NULL, _IONBF, BUFSIZ) == 0);
+    errno = -1;
+    ASSERT (!ferror (stderr));
+    perror (NULL);
+#if 0
+    /* Commented out until cygwin behaves:
+       http://sourceware.org/ml/newlib/2011/msg00228.html */
+    ASSERT (errno > 0);
+    /* Commented out until glibc behaves:
+       http://sourceware.org/bugzilla/show_bug.cgi?id=12792 */
+    ASSERT (ferror (stderr));
+#endif
+  }
+
+  ASSERT (fclose (stderr) == 0);
+  ASSERT (remove (BASE ".tmp") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-pipe.c b/gl/tests/test-pipe.c
index 5302c3e..90f41f9 100644
--- a/gl/tests/test-pipe.c
+++ b/gl/tests/test-pipe.c
@@ -29,6 +29,8 @@ SIGNATURE_CHECK (pipe, int, (int[2]));
 /* Get declarations of the Win32 API functions.  */
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 #endif
 
 #include "binary-io.h"
diff --git a/gl/tests/test-recv.c b/gl/tests/test-recv.c
new file mode 100644
index 0000000..ae811b6
--- /dev/null
+++ b/gl/tests/test-recv.c
@@ -0,0 +1,49 @@
+/* Test the recv() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (recv, ssize_t, (int, void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    char byte;
+    errno = 0;
+    ASSERT (recv (-1, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    char byte;
+    errno = 0;
+    ASSERT (recv (99, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-select.c b/gl/tests/test-select.c
index 5c15320..9c6fb9d 100644
--- a/gl/tests/test-select.c
+++ b/gl/tests/test-select.c
@@ -21,377 +21,14 @@
 #include <sys/select.h>
 
 #include "signature.h"
+
 SIGNATURE_CHECK (select, int, (int, fd_set *, fd_set *, fd_set *,
                                struct timeval *));
-/* The following may be macros without underlying functions, so only
-   check signature if they are not macros.  */
-#ifndef FD_CLR
-SIGNATURE_CHECK (FD_CLR, void, (int, fd_set *));
-#endif
-#ifndef FD_ISSET
-SIGNATURE_CHECK (FD_ISSET, void, (int, fd_set *));
-#endif
-#ifndef FD_SET
-SIGNATURE_CHECK (FD_SET, int, (int, fd_set *));
-#endif
-#ifndef FD_ZERO
-SIGNATURE_CHECK (FD_ZERO, void, (fd_set *));
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-#include "macros.h"
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# define WIN32_NATIVE
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
-#ifndef SO_REUSEPORT
-# define SO_REUSEPORT    SO_REUSEADDR
-#endif
-
-#define TEST_PORT       12345
-
-
-/* Minimal testing infrastructure.  */
-
-static int failures;
-
-static void
-failed (const char *reason)
-{
-  if (++failures > 1)
-    printf ("  ");
-  printf ("failed (%s)\n", reason);
-}
-
-static int
-test (void (*fn) (void), const char *msg)
-{
-  failures = 0;
-  printf ("%s... ", msg);
-  fflush (stdout);
-  fn ();
-
-  if (!failures)
-    printf ("passed\n");
-
-  return failures;
-}
-
-
-/* Funny socket code.  */
-
-static int
-open_server_socket (void)
-{
-  int s, x;
-  struct sockaddr_in ia;
-
-  s = socket (AF_INET, SOCK_STREAM, 0);
-
-  memset (&ia, 0, sizeof (ia));
-  ia.sin_family = AF_INET;
-  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
-  ia.sin_port = htons (TEST_PORT);
-  if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0)
-    {
-      perror ("bind");
-      exit (77);
-    }
-
-  x = 1;
-  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
-
-  if (listen (s, 1) < 0)
-    {
-      perror ("listen");
-      exit (77);
-    }
-
-  return s;
-}
-
-static int
-connect_to_socket (bool blocking)
-{
-  int s;
-  struct sockaddr_in ia;
-
-  s = socket (AF_INET, SOCK_STREAM, 0);
-
-  memset (&ia, 0, sizeof (ia));
-  ia.sin_family = AF_INET;
-  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
-  ia.sin_port = htons (TEST_PORT);
-
-  if (!blocking)
-    {
-#ifdef WIN32_NATIVE
-      unsigned long iMode = 1;
-      ioctl (s, FIONBIO, (char *) &iMode);
-
-#elif defined F_GETFL
-      int oldflags = fcntl (s, F_GETFL, NULL);
-
-      if (!(oldflags & O_NONBLOCK))
-        fcntl (s, F_SETFL, oldflags | O_NONBLOCK);
-#endif
-    }
-
-  if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0
-      && (blocking || errno != EINPROGRESS))
-    {
-      perror ("connect");
-      exit (77);
-    }
-
-  return s;
-}
-
-
-/* A slightly more convenient interface to select(2).
-   Waits until a specific event occurs on a file descriptor FD.
-   EV is a bit mask of events to look for:
-     SEL_IN - input can be polled without blocking,
-     SEL_OUT - output can be provided without blocking,
-     SEL_EXC - an exception occurred,
-   A maximum wait time is specified by TIMEOUT.
-   *TIMEOUT = { 0, 0 } means to return immediately,
-   TIMEOUT = NULL means to wait indefinitely.  */
-
-enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 };
-
-static int
-do_select (int fd, int ev, struct timeval *timeout)
-{
-  fd_set rfds, wfds, xfds;
-  int r, rev;
-
-  FD_ZERO (&rfds);
-  FD_ZERO (&wfds);
-  FD_ZERO (&xfds);
-  if (ev & SEL_IN)
-    FD_SET (fd, &rfds);
-  if (ev & SEL_OUT)
-    FD_SET (fd, &wfds);
-  if (ev & SEL_EXC)
-    FD_SET (fd, &xfds);
-  r = select (fd + 1, &rfds, &wfds, &xfds, timeout);
-  if (r < 0)
-    return r;
-
-  rev = 0;
-  if (FD_ISSET (fd, &rfds))
-    rev |= SEL_IN;
-  if (FD_ISSET (fd, &wfds))
-    rev |= SEL_OUT;
-  if (FD_ISSET (fd, &xfds))
-    rev |= SEL_EXC;
-  if (rev && r == 0)
-    failed ("select returned 0");
-  if (rev & ~ev)
-    failed ("select returned unrequested events");
-
-  return rev;
-}
-
-static int
-do_select_nowait (int fd, int ev)
-{
-  struct timeval tv0;
-  tv0.tv_sec = 0;
-  tv0.tv_usec = 0;
-  return do_select (fd, ev, &tv0);
-}
-
-static int
-do_select_wait (int fd, int ev)
-{
-  return do_select (fd, ev, NULL);
-}
-
-
-/* Test select(2) for TTYs.  */
-
-#ifdef INTERACTIVE
-static void
-test_tty (void)
-{
-  if (do_select_nowait (0, SEL_IN) != 0)
-    failed ("can read");
-  if (do_select_nowait (0, SEL_OUT) == 0)
-    failed ("cannot write");
-
-  if (do_select_wait (0, SEL_IN) == 0)
-    failed ("return with infinite timeout");
-
-  getchar ();
-  if (do_select_nowait (0, SEL_IN) != 0)
-    failed ("can read after getc");
-}
-#endif
-
-
-/* Test select(2) for unconnected nonblocking sockets.  */
-
-static void
-test_connect_first (void)
-{
-  int s = open_server_socket ();
-  struct sockaddr_in ia;
-  socklen_t addrlen;
-
-  int c1, c2;
-
-  if (do_select_nowait (s, SEL_IN | SEL_EXC) != 0)
-    failed ("can read, socket not connected");
-
-  c1 = connect_to_socket (false);
-
-  if (do_select_wait (s, SEL_IN | SEL_EXC) != SEL_IN)
-    failed ("expecting readability on passive socket");
-  if (do_select_nowait (s, SEL_IN | SEL_EXC) != SEL_IN)
-    failed ("expecting readability on passive socket");
-
-  addrlen = sizeof (ia);
-  c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
-  ASSERT (close (s) == 0);
-  ASSERT (close (c1) == 0);
-  ASSERT (close (c2) == 0);
-}
-
-
-/* Test select(2) for unconnected blocking sockets.  */
-
-static void
-test_accept_first (void)
-{
-#ifndef WIN32_NATIVE
-  int s = open_server_socket ();
-  struct sockaddr_in ia;
-  socklen_t addrlen;
-  char buf[3];
-  int c, pid;
-
-  pid = fork ();
-  if (pid < 0)
-    return;
-
-  if (pid == 0)
-    {
-      addrlen = sizeof (ia);
-      c = accept (s, (struct sockaddr *) &ia, &addrlen);
-      ASSERT (close (s) == 0);
-      ASSERT (write (c, "foo", 3) == 3);
-      ASSERT (read (c, buf, 3) == 3);
-      shutdown (c, SHUT_RD);
-      ASSERT (close (c) == 0);
-      exit (0);
-    }
-  else
-    {
-      ASSERT (close (s) == 0);
-      c = connect_to_socket (true);
-      if (do_select_nowait (c, SEL_OUT) != SEL_OUT)
-        failed ("cannot write after blocking connect");
-      ASSERT (write (c, "foo", 3) == 3);
-      wait (&pid);
-      if (do_select_wait (c, SEL_IN) != SEL_IN)
-        failed ("cannot read data left in the socket by closed process");
-      ASSERT (read (c, buf, 3) == 3);
-      ASSERT (write (c, "foo", 3) == 3);
-      (void) close (c); /* may fail with errno = ECONNRESET */
-    }
-#endif
-}
 
-
-/* Common code for pipes and connected sockets.  */
-
-static void
-test_pair (int rd, int wd)
-{
-  char buf[3];
-  if (do_select_wait (wd, SEL_IN | SEL_OUT | SEL_EXC) != SEL_OUT)
-    failed ("expecting writability before writing");
-  if (do_select_nowait (wd, SEL_IN | SEL_OUT | SEL_EXC) != SEL_OUT)
-    failed ("expecting writability before writing");
-
-  ASSERT (write (wd, "foo", 3) == 3);
-  if (do_select_wait (rd, SEL_IN) != SEL_IN)
-    failed ("expecting readability after writing");
-  if (do_select_nowait (rd, SEL_IN) != SEL_IN)
-    failed ("expecting readability after writing");
-
-  ASSERT (read (rd, buf, 3) == 3);
-}
-
-
-/* Test select(2) on connected sockets.  */
-
-static void
-test_socket_pair (void)
-{
-  struct sockaddr_in ia;
-
-  socklen_t addrlen = sizeof (ia);
-  int s = open_server_socket ();
-  int c1 = connect_to_socket (false);
-  int c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
-
-  ASSERT (close (s) == 0);
-
-  test_pair (c1, c2);
-  ASSERT (close (c1) == 0);
-  ASSERT (write (c2, "foo", 3) == 3);
-  (void) close (c2); /* may fail with errno = ECONNRESET */
-}
-
-
-/* Test select(2) on pipes.  */
-
-static void
-test_pipe (void)
-{
-  int fd[2];
-
-  ASSERT (pipe (fd) == 0);
-  test_pair (fd[0], fd[1]);
-  ASSERT (close (fd[0]) == 0);
-  ASSERT (close (fd[1]) == 0);
-}
-
-
-/* Do them all.  */
+#include "test-select.h"
 
 int
 main (void)
 {
-  int result;
-
-#ifdef INTERACTIVE
-  printf ("Please press Enter\n");
-  test (test_tty, "TTY");
-#endif
-
-  result = test (test_connect_first, "Unconnected socket test");
-  result += test (test_socket_pair, "Connected sockets test");
-  result += test (test_accept_first, "General socket test with fork");
-  result += test (test_pipe, "Pipe test");
-
-  exit (result);
+  return test_function (select);
 }
diff --git a/gl/tests/test-select.h b/gl/tests/test-select.h
new file mode 100644
index 0000000..4612dfc
--- /dev/null
+++ b/gl/tests/test-select.h
@@ -0,0 +1,436 @@
+/* Test of select() substitute.
+   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
+   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/>.  */
+
+/* Written by Paolo Bonzini, 2008.  */
+
+#include <stdio.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "macros.h"
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_NATIVE
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
+#ifndef SO_REUSEPORT
+# define SO_REUSEPORT    SO_REUSEADDR
+#endif
+
+#define TEST_PORT       12345
+
+
+typedef int (*select_fn) (int, fd_set *, fd_set *, fd_set *, struct timeval *);
+
+
+/* Minimal testing infrastructure.  */
+
+static int failures;
+
+static void
+failed (const char *reason)
+{
+  if (++failures > 1)
+    printf ("  ");
+  printf ("failed (%s)\n", reason);
+}
+
+static int
+test (void (*fn) (select_fn), select_fn my_select, const char *msg)
+{
+  failures = 0;
+  printf ("%s... ", msg);
+  fflush (stdout);
+  fn (my_select);
+
+  if (!failures)
+    printf ("passed\n");
+
+  return failures;
+}
+
+
+/* Funny socket code.  */
+
+static int
+open_server_socket (void)
+{
+  int s, x;
+  struct sockaddr_in ia;
+
+  s = socket (AF_INET, SOCK_STREAM, 0);
+
+  memset (&ia, 0, sizeof (ia));
+  ia.sin_family = AF_INET;
+  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
+  ia.sin_port = htons (TEST_PORT);
+  if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0)
+    {
+      perror ("bind");
+      exit (77);
+    }
+
+  x = 1;
+  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
+
+  if (listen (s, 1) < 0)
+    {
+      perror ("listen");
+      exit (77);
+    }
+
+  return s;
+}
+
+static int
+connect_to_socket (bool blocking)
+{
+  int s;
+  struct sockaddr_in ia;
+
+  s = socket (AF_INET, SOCK_STREAM, 0);
+
+  memset (&ia, 0, sizeof (ia));
+  ia.sin_family = AF_INET;
+  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
+  ia.sin_port = htons (TEST_PORT);
+
+  if (!blocking)
+    {
+#ifdef WIN32_NATIVE
+      unsigned long iMode = 1;
+      ioctl (s, FIONBIO, (char *) &iMode);
+
+#elif defined F_GETFL
+      int oldflags = fcntl (s, F_GETFL, NULL);
+
+      if (!(oldflags & O_NONBLOCK))
+        fcntl (s, F_SETFL, oldflags | O_NONBLOCK);
+#endif
+    }
+
+  if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0
+      && (blocking || errno != EINPROGRESS))
+    {
+      perror ("connect");
+      exit (77);
+    }
+
+  return s;
+}
+
+
+/* A slightly more convenient interface to select(2).
+   Waits until a specific event occurs on a file descriptor FD.
+   EV is a bit mask of events to look for:
+     SEL_IN - input can be polled without blocking,
+     SEL_OUT - output can be provided without blocking,
+     SEL_EXC - an exception occurred,
+   A maximum wait time is specified by TIMEOUT.
+   *TIMEOUT = { 0, 0 } means to return immediately,
+   TIMEOUT = NULL means to wait indefinitely.  */
+
+enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 };
+
+static int
+do_select (int fd, int ev, struct timeval *timeout, select_fn my_select)
+{
+  fd_set rfds, wfds, xfds;
+  int r, rev;
+
+  FD_ZERO (&rfds);
+  FD_ZERO (&wfds);
+  FD_ZERO (&xfds);
+  if (ev & SEL_IN)
+    FD_SET (fd, &rfds);
+  if (ev & SEL_OUT)
+    FD_SET (fd, &wfds);
+  if (ev & SEL_EXC)
+    FD_SET (fd, &xfds);
+  r = my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
+  if (r < 0)
+    return r;
+
+  rev = 0;
+  if (FD_ISSET (fd, &rfds))
+    rev |= SEL_IN;
+  if (FD_ISSET (fd, &wfds))
+    rev |= SEL_OUT;
+  if (FD_ISSET (fd, &xfds))
+    rev |= SEL_EXC;
+  if (rev && r == 0)
+    failed ("select returned 0");
+  if (rev & ~ev)
+    failed ("select returned unrequested events");
+
+  return rev;
+}
+
+static int
+do_select_nowait (int fd, int ev, select_fn my_select)
+{
+  struct timeval tv0;
+  tv0.tv_sec = 0;
+  tv0.tv_usec = 0;
+  return do_select (fd, ev, &tv0, my_select);
+}
+
+static int
+do_select_wait (int fd, int ev, select_fn my_select)
+{
+  return do_select (fd, ev, NULL, my_select);
+}
+
+
+/* Test select(2) for TTYs.  */
+
+#ifdef INTERACTIVE
+static void
+test_tty (select_fn my_select)
+{
+  if (do_select_nowait (0, SEL_IN, my_select) != 0)
+    failed ("can read");
+  if (do_select_nowait (0, SEL_OUT, my_select) == 0)
+    failed ("cannot write");
+
+  if (do_select_wait (0, SEL_IN, my_select) == 0)
+    failed ("return with infinite timeout");
+
+  getchar ();
+  if (do_select_nowait (0, SEL_IN, my_select) != 0)
+    failed ("can read after getc");
+}
+#endif
+
+
+/* Test select(2) on invalid file descriptors.  */
+
+static int
+do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select)
+{
+  fd_set rfds, wfds, xfds;
+
+  FD_ZERO (&rfds);
+  FD_ZERO (&wfds);
+  FD_ZERO (&xfds);
+  if (ev & SEL_IN)
+    FD_SET (fd, &rfds);
+  if (ev & SEL_OUT)
+    FD_SET (fd, &wfds);
+  if (ev & SEL_EXC)
+    FD_SET (fd, &xfds);
+  return my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
+  /* In this case, when fd is invalid, on some platforms, the bit for fd
+     is left alone in the fd_set, whereas on other platforms it is cleared.
+     So, don't check the bit for fd here.  */
+}
+
+static int
+do_select_bad_fd_nowait (int fd, int ev, select_fn my_select)
+{
+  struct timeval tv0;
+  tv0.tv_sec = 0;
+  tv0.tv_usec = 0;
+  return do_select_bad_fd (fd, ev, &tv0, my_select);
+}
+
+static void
+test_bad_fd (select_fn my_select)
+{
+  /* This tests fails on OSF/1 and native Windows, even with fd = 16.  */
+#if !(defined __osf__ || defined WIN32_NATIVE)
+  int fd;
+
+  /* On Linux, MacOS X, *BSD, values of fd like 99 or 399 are discarded
+     by the kernel early and therefore do *not* lead to EBADF, as required
+     by POSIX.  */
+# if defined __linux__ || (defined __APPLE__ && defined __MACH__) || defined 
__FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
+  fd = 16;
+# else
+  fd = 99;
+# endif
+
+  if (do_select_bad_fd_nowait (fd, SEL_IN, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among rfds");
+  if (do_select_bad_fd_nowait (fd, SEL_OUT, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among wfds");
+  if (do_select_bad_fd_nowait (fd, SEL_EXC, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among xfds");
+#endif
+}
+
+
+/* Test select(2) for unconnected nonblocking sockets.  */
+
+static void
+test_connect_first (select_fn my_select)
+{
+  int s = open_server_socket ();
+  struct sockaddr_in ia;
+  socklen_t addrlen;
+
+  int c1, c2;
+
+  if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != 0)
+    failed ("can read, socket not connected");
+
+  c1 = connect_to_socket (false);
+
+  if (do_select_wait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN)
+    failed ("expecting readability on passive socket");
+  if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN)
+    failed ("expecting readability on passive socket");
+
+  addrlen = sizeof (ia);
+  c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
+  ASSERT (close (s) == 0);
+  ASSERT (close (c1) == 0);
+  ASSERT (close (c2) == 0);
+}
+
+
+/* Test select(2) for unconnected blocking sockets.  */
+
+static void
+test_accept_first (select_fn my_select)
+{
+#ifndef WIN32_NATIVE
+  int s = open_server_socket ();
+  struct sockaddr_in ia;
+  socklen_t addrlen;
+  char buf[3];
+  int c, pid;
+
+  pid = fork ();
+  if (pid < 0)
+    return;
+
+  if (pid == 0)
+    {
+      addrlen = sizeof (ia);
+      c = accept (s, (struct sockaddr *) &ia, &addrlen);
+      ASSERT (close (s) == 0);
+      ASSERT (write (c, "foo", 3) == 3);
+      ASSERT (read (c, buf, 3) == 3);
+      shutdown (c, SHUT_RD);
+      ASSERT (close (c) == 0);
+      exit (0);
+    }
+  else
+    {
+      ASSERT (close (s) == 0);
+      c = connect_to_socket (true);
+      if (do_select_nowait (c, SEL_OUT, my_select) != SEL_OUT)
+        failed ("cannot write after blocking connect");
+      ASSERT (write (c, "foo", 3) == 3);
+      wait (&pid);
+      if (do_select_wait (c, SEL_IN, my_select) != SEL_IN)
+        failed ("cannot read data left in the socket by closed process");
+      ASSERT (read (c, buf, 3) == 3);
+      ASSERT (write (c, "foo", 3) == 3);
+      (void) close (c); /* may fail with errno = ECONNRESET */
+    }
+#endif
+}
+
+
+/* Common code for pipes and connected sockets.  */
+
+static void
+test_pair (int rd, int wd, select_fn my_select)
+{
+  char buf[3];
+  if (do_select_wait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT)
+    failed ("expecting writability before writing");
+  if (do_select_nowait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT)
+    failed ("expecting writability before writing");
+
+  ASSERT (write (wd, "foo", 3) == 3);
+  if (do_select_wait (rd, SEL_IN, my_select) != SEL_IN)
+    failed ("expecting readability after writing");
+  if (do_select_nowait (rd, SEL_IN, my_select) != SEL_IN)
+    failed ("expecting readability after writing");
+
+  ASSERT (read (rd, buf, 3) == 3);
+}
+
+
+/* Test select(2) on connected sockets.  */
+
+static void
+test_socket_pair (select_fn my_select)
+{
+  struct sockaddr_in ia;
+
+  socklen_t addrlen = sizeof (ia);
+  int s = open_server_socket ();
+  int c1 = connect_to_socket (false);
+  int c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
+
+  ASSERT (close (s) == 0);
+
+  test_pair (c1, c2, my_select);
+  ASSERT (close (c1) == 0);
+  ASSERT (write (c2, "foo", 3) == 3);
+  (void) close (c2); /* may fail with errno = ECONNRESET */
+}
+
+
+/* Test select(2) on pipes.  */
+
+static void
+test_pipe (select_fn my_select)
+{
+  int fd[2];
+
+  ASSERT (pipe (fd) == 0);
+  test_pair (fd[0], fd[1], my_select);
+  ASSERT (close (fd[0]) == 0);
+  ASSERT (close (fd[1]) == 0);
+}
+
+
+/* Do them all.  */
+
+static int
+test_function (select_fn my_select)
+{
+  int result = 0;
+
+#ifdef INTERACTIVE
+  printf ("Please press Enter\n");
+  test (test_tty, "TTY", my_select);
+#endif
+
+  result += test (test_bad_fd, my_select, "Invalid fd test");
+  result += test (test_connect_first, my_select, "Unconnected socket test");
+  result += test (test_socket_pair, my_select, "Connected sockets test");
+  result += test (test_accept_first, my_select, "General socket test with 
fork");
+  result += test (test_pipe, my_select, "Pipe test");
+
+  return result;
+}
diff --git a/gl/tests/test-send.c b/gl/tests/test-send.c
new file mode 100644
index 0000000..9fb24d4
--- /dev/null
+++ b/gl/tests/test-send.c
@@ -0,0 +1,49 @@
+/* Test the send() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (send, ssize_t, (int, const void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    char byte = 'x';
+    errno = 0;
+    ASSERT (send (-1, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    char byte = 'x';
+    errno = 0;
+    ASSERT (send (99, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-setsockopt.c b/gl/tests/test-setsockopt.c
new file mode 100644
index 0000000..7a16cfa
--- /dev/null
+++ b/gl/tests/test-setsockopt.c
@@ -0,0 +1,53 @@
+/* Test setsockopt() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (setsockopt, int, (int, int, int, const void *, socklen_t));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    int value = 1;
+
+    errno = 0;
+    ASSERT (setsockopt (-1, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value))
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    int value = 1;
+
+    errno = 0;
+    ASSERT (setsockopt (99, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value))
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-shutdown.c b/gl/tests/test-shutdown.c
new file mode 100644
index 0000000..d154f8e
--- /dev/null
+++ b/gl/tests/test-shutdown.c
@@ -0,0 +1,47 @@
+/* Test the shutdown() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (shutdown, int, (int, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (shutdown (-1, SHUT_RD) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (shutdown (99, SHUT_RD) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-signal-h.c b/gl/tests/test-signal-h.c
new file mode 100644
index 0000000..7103e1f
--- /dev/null
+++ b/gl/tests/test-signal-h.c
@@ -0,0 +1,129 @@
+/* Test of <signal.h> substitute.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <signal.h>
+
+/* Check for required types.  */
+struct
+{
+  size_t a;
+  uid_t b;
+  volatile sig_atomic_t c;
+  sigset_t d;
+  pid_t e;
+#if 0
+  /* Not guaranteed by gnulib.  */
+  pthread_t f;
+  struct timespec g;
+#endif
+} s;
+
+/* Check that NSIG is defined.  */
+int nsig = NSIG;
+
+int
+main (void)
+{
+  switch (0)
+    {
+      /* The following are guaranteed by C.  */
+    case 0:
+    case SIGABRT:
+    case SIGFPE:
+    case SIGILL:
+    case SIGINT:
+    case SIGSEGV:
+    case SIGTERM:
+      /* The following is guaranteed by gnulib.  */
+#if GNULIB_SIGPIPE || defined SIGPIPE
+    case SIGPIPE:
+#endif
+      /* Ensure no conflict with other standardized names.  */
+#ifdef SIGALRM
+    case SIGALRM:
+#endif
+      /* On Haiku, SIGBUS is mistakenly equal to SIGSEGV.  */
+#if defined SIGBUS && SIGBUS != SIGSEGV
+    case SIGBUS:
+#endif
+#ifdef SIGCHLD
+    case SIGCHLD:
+#endif
+#ifdef SIGCONT
+    case SIGCONT:
+#endif
+#ifdef SIGHUP
+    case SIGHUP:
+#endif
+#ifdef SIGKILL
+    case SIGKILL:
+#endif
+#ifdef SIGQUIT
+    case SIGQUIT:
+#endif
+#ifdef SIGSTOP
+    case SIGSTOP:
+#endif
+#ifdef SIGTSTP
+    case SIGTSTP:
+#endif
+#ifdef SIGTTIN
+    case SIGTTIN:
+#endif
+#ifdef SIGTTOU
+    case SIGTTOU:
+#endif
+#ifdef SIGUSR1
+    case SIGUSR1:
+#endif
+#ifdef SIGUSR2
+    case SIGUSR2:
+#endif
+#ifdef SIGSYS
+    case SIGSYS:
+#endif
+#ifdef SIGTRAP
+    case SIGTRAP:
+#endif
+#ifdef SIGURG
+    case SIGURG:
+#endif
+#ifdef SIGVTALRM
+    case SIGVTALRM:
+#endif
+#ifdef SIGXCPU
+    case SIGXCPU:
+#endif
+#ifdef SIGXFSZ
+    case SIGXFSZ:
+#endif
+      /* SIGRTMIN and SIGRTMAX need not be compile-time constants.  */
+#if 0
+# ifdef SIGRTMIN
+    case SIGRTMIN:
+# endif
+# ifdef SIGRTMAX
+    case SIGRTMAX:
+# endif
+#endif
+      ;
+    }
+  return s.a + s.b + s.c + s.e;
+}
diff --git a/gl/tests/test-snprintf.c b/gl/tests/test-snprintf.c
index 95a352d..2b5a54c 100644
--- a/gl/tests/test-snprintf.c
+++ b/gl/tests/test-snprintf.c
@@ -60,5 +60,13 @@ main (int argc, char *argv[])
         }
     }
 
+  /* Test the support of the POSIX/XSI format strings with positions.  */
+  {
+    char result[100];
+    retval = snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
+    ASSERT (strcmp (result, "55 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
   return 0;
 }
diff --git a/gl/tests/test-stat.c b/gl/tests/test-stat.c
new file mode 100644
index 0000000..cd74491
--- /dev/null
+++ b/gl/tests/test-stat.c
@@ -0,0 +1,55 @@
+/* Tests of stat.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+/* Caution: stat may be a function-like macro.  Although this
+   signature check must pass, it may be the signature of the real (and
+   broken) stat rather than rpl_stat.  Most code should not use the
+   address of stat.  */
+#include "signature.h"
+SIGNATURE_CHECK (stat, int, (char const *, struct stat *));
+
+#include <fcntl.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "same-inode.h"
+#include "macros.h"
+
+#define BASE "test-stat.t"
+
+#include "test-stat.h"
+
+/* Wrapper around stat, which works even if stat is a function-like
+   macro, where test_stat_func(stat) would do the wrong thing.  */
+static int
+do_stat (char const *name, struct stat *st)
+{
+  return stat (name, st);
+}
+
+int
+main (void)
+{
+  return test_stat_func (do_stat, true);
+}
diff --git a/gl/tests/test-stat.h b/gl/tests/test-stat.h
new file mode 100644
index 0000000..3c8f7ad
--- /dev/null
+++ b/gl/tests/test-stat.h
@@ -0,0 +1,100 @@
+/* Tests of stat.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+/* This file is designed to test both stat(n,buf) and
+   fstatat(AT_FDCWD,n,buf,0).  FUNC is the function to test.  Assumes
+   that BASE and ASSERT are already defined, and that appropriate
+   headers are already included.  If PRINT, warn before skipping
+   symlink tests with status 77.  */
+
+static int
+test_stat_func (int (*func) (char const *, struct stat *), bool print)
+{
+  struct stat st1;
+  struct stat st2;
+  char *cwd = getcwd (NULL, 0);
+
+  ASSERT (cwd);
+  ASSERT (func (".", &st1) == 0);
+  ASSERT (func ("./", &st2) == 0);
+  ASSERT (SAME_INODE (st1, st2));
+  ASSERT (func (cwd, &st2) == 0);
+  ASSERT (SAME_INODE (st1, st2));
+  ASSERT (func ("/", &st1) == 0);
+  ASSERT (func ("///", &st2) == 0);
+  ASSERT (SAME_INODE (st1, st2));
+
+  errno = 0;
+  ASSERT (func ("", &st1) == -1);
+  ASSERT (errno == ENOENT);
+  errno = 0;
+  ASSERT (func ("nosuch", &st1) == -1);
+  ASSERT (errno == ENOENT);
+  errno = 0;
+  ASSERT (func ("nosuch/", &st1) == -1);
+  ASSERT (errno == ENOENT);
+
+  ASSERT (close (creat (BASE "file", 0600)) == 0);
+  ASSERT (func (BASE "file", &st1) == 0);
+  errno = 0;
+  ASSERT (func (BASE "file/", &st1) == -1);
+  ASSERT (errno == ENOTDIR);
+
+  /* Now for some symlink tests, where supported.  We set up:
+     link1 -> directory
+     link2 -> file
+     link3 -> dangling
+     link4 -> loop
+     then test behavior with trailing slash.
+  */
+  if (symlink (".", BASE "link1") != 0)
+    {
+      ASSERT (unlink (BASE "file") == 0);
+      if (print)
+        fputs ("skipping test: symlinks not supported on this file system\n",
+               stderr);
+      return 77;
+    }
+  ASSERT (symlink (BASE "file", BASE "link2") == 0);
+  ASSERT (symlink (BASE "nosuch", BASE "link3") == 0);
+  ASSERT (symlink (BASE "link4", BASE "link4") == 0);
+
+  ASSERT (func (BASE "link1/", &st1) == 0);
+  ASSERT (S_ISDIR (st1.st_mode));
+
+  errno = 0;
+  ASSERT (func (BASE "link2/", &st1) == -1);
+  ASSERT (errno == ENOTDIR);
+
+  errno = 0;
+  ASSERT (func (BASE "link3/", &st1) == -1);
+  ASSERT (errno == ENOENT);
+
+  errno = 0;
+  ASSERT (func (BASE "link4/", &st1) == -1);
+  ASSERT (errno == ELOOP);
+
+  /* Cleanup.  */
+  ASSERT (unlink (BASE "file") == 0);
+  ASSERT (unlink (BASE "link1") == 0);
+  ASSERT (unlink (BASE "link2") == 0);
+  ASSERT (unlink (BASE "link3") == 0);
+  ASSERT (unlink (BASE "link4") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-strerror.c b/gl/tests/test-strerror.c
index 66dbe82..3ffb12e 100644
--- a/gl/tests/test-strerror.c
+++ b/gl/tests/test-strerror.c
@@ -33,25 +33,44 @@ main (void)
 {
   char *str;
 
+  errno = 0;
   str = strerror (EACCES);
   ASSERT (str);
   ASSERT (*str);
+  ASSERT (errno == 0);
 
+  errno = 0;
   str = strerror (ETIMEDOUT);
   ASSERT (str);
   ASSERT (*str);
+  ASSERT (errno == 0);
 
+  errno = 0;
   str = strerror (EOVERFLOW);
   ASSERT (str);
   ASSERT (*str);
+  ASSERT (errno == 0);
 
+  /* POSIX requires strerror (0) to succeed.  Reject use of "Unknown
+     error", but allow "Success", "No error", or even Solaris' "Error
+     0" which are distinct patterns from true out-of-range strings.
+     http://austingroupbugs.net/view.php?id=382  */
+  errno = 0;
   str = strerror (0);
   ASSERT (str);
   ASSERT (*str);
-
+  ASSERT (errno == 0);
+  ASSERT (strstr (str, "nknown") == NULL);
+  ASSERT (strstr (str, "ndefined") == NULL);
+
+  /* POSIX requires strerror to produce a non-NULL result for all
+     inputs; as an extension, we also guarantee a non-empty reseult.
+     Reporting EINVAL is optional.  */
+  errno = 0;
   str = strerror (-3);
   ASSERT (str);
   ASSERT (*str);
+  ASSERT (errno == 0 || errno == EINVAL);
 
   return 0;
 }
diff --git a/gl/tests/test-strerror_r.c b/gl/tests/test-strerror_r.c
new file mode 100644
index 0000000..956c458
--- /dev/null
+++ b/gl/tests/test-strerror_r.c
@@ -0,0 +1,182 @@
+/* Test of strerror_r() function.
+   Copyright (C) 2007-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>
+
+#include <string.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (strerror_r, int, (int, char *, size_t));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  char buf[100];
+  int ret;
+
+  /* Test results with valid errnum and enough room.  */
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (EACCES, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (ETIMEDOUT, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (EOVERFLOW, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  /* POSIX requires strerror (0) to succeed.  Reject use of "Unknown
+     error", but allow "Success", "No error", or even Solaris' "Error
+     0" which are distinct patterns from true out-of-range strings.
+     http://austingroupbugs.net/view.php?id=382  */
+  errno = 0;
+  buf[0] = '\0';
+  ret = strerror_r (0, buf, sizeof buf);
+  ASSERT (ret == 0);
+  ASSERT (buf[0]);
+  ASSERT (errno == 0);
+  ASSERT (strstr (buf, "nknown") == NULL);
+  ASSERT (strstr (buf, "ndefined") == NULL);
+
+  /* Test results with out-of-range errnum and enough room.  POSIX
+     allows an empty string on success, and allows an unchanged buf on
+     error, but these are not useful, so we guarantee contents.  */
+  errno = 0;
+  buf[0] = '^';
+  ret = strerror_r (-3, buf, sizeof buf);
+  ASSERT (ret == 0 || ret == EINVAL);
+  ASSERT (buf[0] != '^');
+  ASSERT (*buf);
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  /* Test results with a too small buffer.  POSIX requires an error;
+     only ERANGE for 0 and valid errors, and a choice of ERANGE or
+     EINVAL for out-of-range values.  On error, POSIX permits buf to
+     be empty, unchanged, or unterminated, but these are not useful,
+     so we guarantee NUL-terminated truncated contents for all but
+     size 0.  http://austingroupbugs.net/view.php?id=398.  Also ensure
+     that no out-of-bounds writes occur.  */
+  {
+    int errs[] = { EACCES, 0, -3, };
+    int j;
+
+    buf[sizeof buf - 1] = '\0';
+    for (j = 0; j < SIZEOF (errs); j++)
+      {
+        int err = errs[j];
+        char buf2[sizeof buf] = "";
+        size_t len;
+        size_t i;
+
+        strerror_r (err, buf2, sizeof buf2);
+        len = strlen (buf2);
+        ASSERT (len < sizeof buf);
+
+        for (i = 0; i <= len; i++)
+          {
+            memset (buf, '^', sizeof buf - 1);
+            errno = 0;
+            ret = strerror_r (err, buf, i);
+            ASSERT (errno == 0);
+            if (err < 0)
+              ASSERT (ret == ERANGE || ret == EINVAL);
+            else
+              ASSERT (ret == ERANGE);
+            if (i)
+              {
+                ASSERT (strncmp (buf, buf2, i - 1) == 0);
+                ASSERT (buf[i - 1] == '\0');
+              }
+            ASSERT (strspn (buf + i, "^") == sizeof buf - 1 - i);
+          }
+
+        strcpy (buf, "BADFACE");
+        errno = 0;
+        ret = strerror_r (err, buf, len + 1);
+        ASSERT (ret != ERANGE);
+        ASSERT (errno == 0);
+        ASSERT (strcmp (buf, buf2) == 0);
+      }
+  }
+
+#if GNULIB_STRERROR
+  /* Test that strerror_r does not clobber strerror buffer.  On some
+     platforms, this test can only succeed if gnulib also replaces
+     strerror.  */
+  {
+    const char *msg1;
+    const char *msg2;
+    const char *msg3;
+    const char *msg4;
+    char *str1;
+    char *str2;
+    char *str3;
+    char *str4;
+
+    msg1 = strerror (ENOENT);
+    ASSERT (msg1);
+    str1 = strdup (msg1);
+    ASSERT (str1);
+
+    msg2 = strerror (ERANGE);
+    ASSERT (msg2);
+    str2 = strdup (msg2);
+    ASSERT (str2);
+
+    msg3 = strerror (-4);
+    ASSERT (msg3);
+    str3 = strdup (msg3);
+    ASSERT (str3);
+
+    msg4 = strerror (1729576);
+    ASSERT (msg4);
+    str4 = strdup (msg4);
+    ASSERT (str4);
+
+    strerror_r (EACCES, buf, sizeof buf);
+    strerror_r (-5, buf, sizeof buf);
+    ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
+    ASSERT (msg2 == msg4 || STREQ (msg2, str2));
+    ASSERT (msg3 == msg4 || STREQ (msg3, str3));
+    ASSERT (STREQ (msg4, str4));
+
+    free (str1);
+    free (str2);
+    free (str3);
+    free (str4);
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-symlink.c b/gl/tests/test-symlink.c
new file mode 100644
index 0000000..367e045
--- /dev/null
+++ b/gl/tests/test-symlink.c
@@ -0,0 +1,47 @@
+/* Tests of symlink.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (symlink, int, (char const *, char const *));
+
+#include <fcntl.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "ignore-value.h"
+#include "macros.h"
+
+#define BASE "test-symlink.t"
+
+#include "test-symlink.h"
+
+int
+main (void)
+{
+  /* Remove any leftovers from a previous partial run.  */
+  ignore_value (system ("rm -rf " BASE "*"));
+
+  return test_symlink (symlink, true);
+}
diff --git a/gl/tests/test-symlink.h b/gl/tests/test-symlink.h
new file mode 100644
index 0000000..4d93929
--- /dev/null
+++ b/gl/tests/test-symlink.h
@@ -0,0 +1,95 @@
+/* Tests of symlink.
+   Copyright (C) 2009-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/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+/* This file is designed to test both symlink(a,b) and
+   symlinkat(a,AT_FDCWD,b).  FUNC is the function to test.  Assumes
+   that BASE and ASSERT are already defined, and that appropriate
+   headers are already included.  If PRINT, warn before skipping
+   symlink tests with status 77.  */
+
+static int
+test_symlink (int (*func) (char const *, char const *), bool print)
+{
+  if (func ("nowhere", BASE "link1"))
+    {
+      if (print)
+        fputs ("skipping test: symlinks not supported on this file system\n",
+               stderr);
+      return 77;
+    }
+
+  /* Some systems allow the creation of 0-length symlinks as a synonym
+     for "."; but most reject it.  */
+  {
+    int status;
+    errno = 0;
+    status = func ("", BASE "link2");
+    if (status == -1)
+      ASSERT (errno == ENOENT || errno == EINVAL);
+    else
+      {
+        ASSERT (status == 0);
+        ASSERT (unlink (BASE "link2") == 0);
+      }
+  }
+
+  /* Sanity checks of failures.  */
+  errno = 0;
+  ASSERT (func ("nowhere", "") == -1);
+  ASSERT (errno == ENOENT);
+  errno = 0;
+  ASSERT (func ("nowhere", ".") == -1);
+  ASSERT (errno == EEXIST || errno == EINVAL);
+  errno = 0;
+  ASSERT (func ("somewhere", BASE "link1") == -1);
+  ASSERT (errno == EEXIST);
+  errno = 0;
+  ASSERT (func ("nowhere", BASE "link2/") == -1);
+  ASSERT (errno == ENOTDIR || errno == ENOENT);
+  ASSERT (mkdir (BASE "dir", 0700) == 0);
+  errno = 0;
+  ASSERT (func ("nowhere", BASE "dir") == -1);
+  ASSERT (errno == EEXIST);
+  errno = 0;
+  ASSERT (func ("nowhere", BASE "dir/") == -1);
+  ASSERT (errno == EEXIST || errno == EINVAL);
+  ASSERT (close (creat (BASE "file", 0600)) == 0);
+  errno = 0;
+  ASSERT (func ("nowhere", BASE "file") == -1);
+  ASSERT (errno == EEXIST);
+  errno = 0;
+  ASSERT (func ("nowhere", BASE "file/") == -1);
+  ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
+
+  /* Trailing slash must always be rejected.  */
+  ASSERT (unlink (BASE "link1") == 0);
+  ASSERT (func (BASE "link2", BASE "link1") == 0);
+  errno = 0;
+  ASSERT (func (BASE "nowhere", BASE "link1/") == -1);
+  ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
+  errno = 0;
+  ASSERT (unlink (BASE "link2") == -1);
+  ASSERT (errno == ENOENT);
+
+  /* Cleanup.  */
+  ASSERT (rmdir (BASE "dir") == 0);
+  ASSERT (unlink (BASE "file") == 0);
+  ASSERT (unlink (BASE "link1") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-sys_select.c b/gl/tests/test-sys_select.c
index 0dfb8ef..76596db 100644
--- a/gl/tests/test-sys_select.c
+++ b/gl/tests/test-sys_select.c
@@ -20,9 +20,29 @@
 
 #include <sys/select.h>
 
+#include "signature.h"
+
+/* The following may be macros without underlying functions, so only
+   check signature if they are not macros.  */
+#ifndef FD_CLR
+SIGNATURE_CHECK (FD_CLR, void, (int, fd_set *));
+#endif
+#ifndef FD_ISSET
+SIGNATURE_CHECK (FD_ISSET, void, (int, fd_set *));
+#endif
+#ifndef FD_SET
+SIGNATURE_CHECK (FD_SET, int, (int, fd_set *));
+#endif
+#ifndef FD_ZERO
+SIGNATURE_CHECK (FD_ZERO, void, (fd_set *));
+#endif
+
 /* Check that the 'struct timeval' type is defined.  */
 struct timeval t1;
 
+/* Check that sigset_t is defined.  */
+sigset_t t2;
+
 int
 main (void)
 {
diff --git a/gl/tests/test-sys_socket.c b/gl/tests/test-sys_socket.c
index 8f323ca..58c1899 100644
--- a/gl/tests/test-sys_socket.c
+++ b/gl/tests/test-sys_socket.c
@@ -30,6 +30,16 @@ int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
 /* Check that the 'socklen_t' type is defined.  */
 socklen_t t1;
 
+/* Check that the 'size_t' and 'ssize_t' types are defined.  */
+size_t t2;
+ssize_t t3;
+
+/* Check that 'struct iovec' is defined.  */
+struct iovec io;
+
+/* Check that a minimal set of 'struct msghdr' is defined.  */
+struct msghdr msg;
+
 int
 main (void)
 {
@@ -51,10 +61,8 @@ main (void)
 
   x.ss_family = 42;
   i = 42;
+  msg.msg_iov = &io;
 
-  /* Tell the compiler that these variables are used.  */
-  (void) x;
-  (void) i;
-
-  return 0;
+  return (x.ss_family - i + msg.msg_namelen + msg.msg_iov->iov_len
+          + msg.msg_iovlen);
 }
diff --git a/gl/tests/test-sys_stat.c b/gl/tests/test-sys_stat.c
index cd07d86..3303bad 100644
--- a/gl/tests/test-sys_stat.c
+++ b/gl/tests/test-sys_stat.c
@@ -26,11 +26,14 @@
 int a[] =
   {
     S_IFMT,
-    S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFREG,
-#ifdef S_IFLNK /* missing on mingw and djgpp */
+#ifdef S_IFBLK /* missing on MSVC */
+    S_IFBLK,
+#endif
+    S_IFCHR, S_IFDIR, S_IFIFO, S_IFREG,
+#ifdef S_IFLNK /* missing on native Windows and DJGPP */
     S_IFLNK,
 #endif
-#ifdef S_IFSOCK /* missing on mingw and djgpp */
+#ifdef S_IFSOCK /* missing on native Windows and DJGPP */
     S_IFSOCK,
 #endif
     S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR,
@@ -61,7 +64,9 @@ verify (S_IRWXU == (S_IRUSR | S_IWUSR | S_IXUSR));
 verify (S_IRWXG == (S_IRGRP | S_IWGRP | S_IXGRP));
 verify (S_IRWXO == (S_IROTH | S_IWOTH | S_IXOTH));
 
+#ifdef S_IFBLK
 verify (S_ISBLK (S_IFBLK));
+#endif
 verify (!S_ISBLK (S_IFCHR));
 verify (!S_ISBLK (S_IFDIR));
 verify (!S_ISBLK (S_IFIFO));
@@ -73,7 +78,9 @@ verify (!S_ISBLK (S_IFLNK));
 verify (!S_ISBLK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISCHR (S_IFBLK));
+#endif
 verify (S_ISCHR (S_IFCHR));
 verify (!S_ISCHR (S_IFDIR));
 verify (!S_ISCHR (S_IFIFO));
@@ -85,7 +92,9 @@ verify (!S_ISCHR (S_IFLNK));
 verify (!S_ISCHR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISDIR (S_IFBLK));
+#endif
 verify (!S_ISDIR (S_IFCHR));
 verify (S_ISDIR (S_IFDIR));
 verify (!S_ISDIR (S_IFIFO));
@@ -97,7 +106,9 @@ verify (!S_ISDIR (S_IFLNK));
 verify (!S_ISDIR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISFIFO (S_IFBLK));
+#endif
 verify (!S_ISFIFO (S_IFCHR));
 verify (!S_ISFIFO (S_IFDIR));
 verify (S_ISFIFO (S_IFIFO));
@@ -109,7 +120,9 @@ verify (!S_ISFIFO (S_IFLNK));
 verify (!S_ISFIFO (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISREG (S_IFBLK));
+#endif
 verify (!S_ISREG (S_IFCHR));
 verify (!S_ISREG (S_IFDIR));
 verify (!S_ISREG (S_IFIFO));
@@ -121,7 +134,9 @@ verify (!S_ISREG (S_IFLNK));
 verify (!S_ISREG (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISLNK (S_IFBLK));
+#endif
 verify (!S_ISLNK (S_IFCHR));
 verify (!S_ISLNK (S_IFDIR));
 verify (!S_ISLNK (S_IFIFO));
@@ -133,7 +148,9 @@ verify (S_ISLNK (S_IFLNK));
 verify (!S_ISLNK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISSOCK (S_IFBLK));
+#endif
 verify (!S_ISSOCK (S_IFCHR));
 verify (!S_ISSOCK (S_IFDIR));
 verify (!S_ISSOCK (S_IFIFO));
@@ -145,7 +162,9 @@ verify (!S_ISSOCK (S_IFLNK));
 verify (S_ISSOCK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISDOOR (S_IFBLK));
+#endif
 verify (!S_ISDOOR (S_IFCHR));
 verify (!S_ISDOOR (S_IFDIR));
 verify (!S_ISDOOR (S_IFIFO));
@@ -157,7 +176,9 @@ verify (!S_ISDOOR (S_IFLNK));
 verify (!S_ISDOOR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISMPB (S_IFBLK));
+#endif
 verify (!S_ISMPB (S_IFCHR));
 verify (!S_ISMPB (S_IFDIR));
 verify (!S_ISMPB (S_IFIFO));
@@ -169,7 +190,9 @@ verify (!S_ISMPB (S_IFLNK));
 verify (!S_ISMPB (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISNAM (S_IFBLK));
+#endif
 verify (!S_ISNAM (S_IFCHR));
 verify (!S_ISNAM (S_IFDIR));
 verify (!S_ISNAM (S_IFIFO));
@@ -181,7 +204,9 @@ verify (!S_ISNAM (S_IFLNK));
 verify (!S_ISNAM (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISNWK (S_IFBLK));
+#endif
 verify (!S_ISNWK (S_IFCHR));
 verify (!S_ISNWK (S_IFDIR));
 verify (!S_ISNWK (S_IFIFO));
@@ -193,7 +218,9 @@ verify (!S_ISNWK (S_IFLNK));
 verify (!S_ISNWK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISPORT (S_IFBLK));
+#endif
 verify (!S_ISPORT (S_IFCHR));
 verify (!S_ISPORT (S_IFDIR));
 verify (!S_ISPORT (S_IFIFO));
@@ -205,7 +232,9 @@ verify (!S_ISPORT (S_IFLNK));
 verify (!S_ISPORT (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISCTG (S_IFBLK));
+#endif
 verify (!S_ISCTG (S_IFCHR));
 verify (!S_ISCTG (S_IFDIR));
 verify (!S_ISCTG (S_IFIFO));
@@ -217,7 +246,9 @@ verify (!S_ISCTG (S_IFLNK));
 verify (!S_ISCTG (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISOFD (S_IFBLK));
+#endif
 verify (!S_ISOFD (S_IFCHR));
 verify (!S_ISOFD (S_IFDIR));
 verify (!S_ISOFD (S_IFIFO));
@@ -229,7 +260,9 @@ verify (!S_ISOFD (S_IFLNK));
 verify (!S_ISOFD (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISOFL (S_IFBLK));
+#endif
 verify (!S_ISOFL (S_IFCHR));
 verify (!S_ISOFL (S_IFDIR));
 verify (!S_ISOFL (S_IFIFO));
@@ -241,7 +274,9 @@ verify (!S_ISOFL (S_IFLNK));
 verify (!S_ISOFL (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISWHT (S_IFBLK));
+#endif
 verify (!S_ISWHT (S_IFCHR));
 verify (!S_ISWHT (S_IFDIR));
 verify (!S_ISWHT (S_IFIFO));
@@ -278,8 +313,10 @@ invalid UTIME macros
 
 /* Check the existence of some types.  */
 nlink_t t1;
+off_t t2;
+mode_t t3;
 
-struct timespec t2;
+struct timespec st;
 
 int
 main (void)
diff --git a/gl/tests/test-sys_types.c b/gl/tests/test-sys_types.c
new file mode 100644
index 0000000..816c9d6
--- /dev/null
+++ b/gl/tests/test-sys_types.c
@@ -0,0 +1,34 @@
+/* Test of <sys/types.h> substitute.
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include <sys/types.h>
+
+/* Check that the types are all defined.  */
+pid_t t1;
+size_t t2;
+ssize_t t3;
+off_t t4;
+mode_t t5;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/lib/gl/tests/test-sys_uio.c b/gl/tests/test-sys_uio.c
similarity index 100%
copy from lib/gl/tests/test-sys_uio.c
copy to gl/tests/test-sys_uio.c
diff --git a/gl/tests/test-thread_create.c b/gl/tests/test-thread_create.c
new file mode 100644
index 0000000..1348c8c
--- /dev/null
+++ b/gl/tests/test-thread_create.c
@@ -0,0 +1,78 @@
+/* Test of gl_thread_create () macro.
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include "glthread/thread.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+static gl_thread_t main_thread_before;
+static gl_thread_t main_thread_after;
+static gl_thread_t worker_thread;
+
+static int dummy;
+static volatile int work_done;
+
+static void *
+worker_thread_func (void *arg)
+{
+  work_done = 1;
+  return &dummy;
+}
+
+int
+main ()
+{
+  main_thread_before = gl_thread_self ();
+
+  if (glthread_create (&worker_thread, worker_thread_func, NULL) == 0)
+    {
+      void *ret;
+
+      /* Check that gl_thread_self () has the same value before than after the
+         first call to gl_thread_create ().  */
+      main_thread_after = gl_thread_self ();
+      ASSERT (memcmp (&main_thread_before, &main_thread_after,
+                      sizeof (gl_thread_t))
+              == 0);
+
+      gl_thread_join (worker_thread, &ret);
+
+      /* Check the return value of the thread.  */
+      ASSERT (ret == &dummy);
+
+      /* Check that worker_thread_func () has finished executing.  */
+      ASSERT (work_done);
+
+      return 0;
+    }
+  else
+    {
+#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || 
USE_WIN32_THREADS
+      fputs ("glthread_create failed\n", stderr);
+      return 1;
+#else
+      fputs ("Skipping test: multithreading not enabled\n", stderr);
+      return 77;
+#endif
+    }
+}
diff --git a/gl/tests/test-thread_self.c b/gl/tests/test-thread_self.c
new file mode 100644
index 0000000..816ee09
--- /dev/null
+++ b/gl/tests/test-thread_self.c
@@ -0,0 +1,34 @@
+/* Test of gl_thread_self () macro.
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include "glthread/thread.h"
+
+gl_thread_t main_thread;
+
+int
+main ()
+{
+  /* Check that gl_thread_self () can be used with just $(LIBTHREAD), not
+     $(LIBMULTITHREAD), i.e. in libraries that are multithread-safe but don't
+     create threads themselves.  */
+  main_thread = gl_thread_self ();
+
+  return 0;
+}
diff --git a/gl/tests/test-time.c b/gl/tests/test-time.c
index 0c78f36..d499a5c 100644
--- a/gl/tests/test-time.c
+++ b/gl/tests/test-time.c
@@ -22,7 +22,13 @@
 
 #include "verify.h"
 
-struct timespec a;
+/* Check that the types are all defined.  */
+struct timespec t1;
+#if 0
+/* POSIX:2008 does not require pid_t in <time.h> unconditionally, and indeed
+   it's missing on MacOS X 10.5, FreeBSD 6.4, OpenBSD 4.9, mingw.  */
+pid_t t2;
+#endif
 
 /* Check that NULL can be passed through varargs as a pointer type,
    per POSIX 2008.  */
diff --git a/gl/tests/test-update-copyright.sh 
b/gl/tests/test-update-copyright.sh
index 83275ad..a1fce0b 100755
--- a/gl/tests/test-update-copyright.sh
+++ b/gl/tests/test-update-copyright.sh
@@ -102,7 +102,6 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Foundation, Inc.
 EOF
 
-rm -f $TMP.*.bak
 UPDATE_COPYRIGHT_YEAR=2009 \
   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
@@ -145,7 +144,6 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Foundation, Inc.
 EOF
 
-rm -f $TMP.*.bak
 UPDATE_COPYRIGHT_YEAR=2010 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
@@ -184,7 +182,6 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
 EOF
 
-rm -f $TMP.*.bak
 UPDATE_COPYRIGHT_YEAR=2010 UPDATE_COPYRIGHT_FORCE=1 \
   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
diff --git a/gl/tests/test-verify.c b/gl/tests/test-verify.c
index 512c021..454f4f4 100644
--- a/gl/tests/test-verify.c
+++ b/gl/tests/test-verify.c
@@ -55,9 +55,9 @@ function (int n)
   verify (1 == 1); verify (1 == 1); /* should be ok */
 
   if (n)
-    return ((void) verify_true (1 == 1), verify_true (1 == 1) + 7); /* should 
be ok */
+    return ((void) verify_expr (1 == 1, 1), verify_expr (1 == 1, 8)); /* 
should be ok */
 #if EXP_FAIL == 5
-  return (verify_true (1 == 2), 5); /* should give ERROR */
+  return verify_expr (1 == 2, 5); /* should give ERROR */
 #endif
   return 0;
 }
diff --git a/lib/gl/tests/test-wchar.c b/gl/tests/test-wchar.c
similarity index 100%
copy from lib/gl/tests/test-wchar.c
copy to gl/tests/test-wchar.c
diff --git a/gl/tests/w32sock.h b/gl/tests/w32sock.h
index 651a76d..55280d6 100644
--- a/gl/tests/w32sock.h
+++ b/gl/tests/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/gl/time.in.h b/gl/time.in.h
index cb533a4..1fbebf4 100644
--- a/gl/time.in.h
+++ b/gl/time.in.h
@@ -28,13 +28,13 @@
    without adding our own declarations.  */
 #if (defined __need_time_t || defined __need_clock_t \
      || defined __need_timespec \
-     || defined _GL_TIME_H)
+     || defined address@hidden@_TIME_H)
 
 # @INCLUDE_NEXT@ @NEXT_TIME_H@
 
 #else
 
-# define _GL_TIME_H
+# define address@hidden@_TIME_H
 
 # @INCLUDE_NEXT@ @NEXT_TIME_H@
 
diff --git a/gl/timespec.h b/gl/timespec.h
index 74d5749..acf815c 100644
--- a/gl/timespec.h
+++ b/gl/timespec.h
@@ -57,6 +57,25 @@ timespec_cmp (struct timespec a, struct timespec b)
           : (int) (a.tv_nsec - b.tv_nsec));
 }
 
+/* Return -1, 0, 1, depending on the sign of A.  A.tv_nsec must be
+   nonnegative.  */
+static inline int
+timespec_sign (struct timespec a)
+{
+  return a.tv_sec < 0 ? -1 : a.tv_sec || a.tv_nsec;
+}
+
+struct timespec timespec_add (struct timespec, struct timespec);
+struct timespec timespec_sub (struct timespec, struct timespec);
+struct timespec dtotimespec (double);
+
+/* Return an approximation to A, of type 'double'.  */
+static inline double
+timespectod (struct timespec a)
+{
+  return a.tv_sec + a.tv_nsec / 1e9;
+}
+
 void gettime (struct timespec *);
 int settime (struct timespec const *);
 
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
index 15893d7..77e5675 100644
--- a/gl/unistd.in.h
+++ b/gl/unistd.in.h
@@ -36,7 +36,7 @@
 # define _GL_WINSOCK2_H_WITNESS
 
 /* Normal invocation.  */
-#elif !defined _GL_UNISTD_H
+#elif !defined address@hidden@_UNISTD_H
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_UNISTD_H@
@@ -51,8 +51,8 @@
 # undef _GL_INCLUDING_WINSOCK2_H
 #endif
 
-#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
-#define _GL_UNISTD_H
+#if !defined address@hidden@_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
+#define address@hidden@_UNISTD_H
 
 /* NetBSD 5.0 mis-defines NULL.  Also get size_t.  */
 #include <stddef.h>
@@ -75,17 +75,21 @@
 #endif
 
 /* mingw fails to declare _exit in <unistd.h>.  */
-/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
+/* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
+   <unistd.h>.  */
 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
 /* But avoid namespace pollution on glibc systems.  */
 #ifndef __GLIBC__
 # 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>
+# include <io.h>     /* mingw32, mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
 #endif
 
 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
@@ -97,7 +101,14 @@
 # include <netdb.h>
 #endif
 
-#if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
+/* MSVC defines off_t in <sys/types.h>.  */
+#if address@hidden@
+/* Get off_t.  */
+# include <sys/types.h>
+#endif
+
+#if (@GNULIB_READ@ || @GNULIB_WRITE@ \
+     || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
      || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
 /* Get ssize_t.  */
 # include <sys/types.h>
@@ -116,78 +127,77 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
-#if @GNULIB_GETHOSTNAME@
-/* Get all possible declarations of gethostname().  */
-# if @UNISTD_H_HAVE_WINSOCK2_H@
-#  if !defined _GL_SYS_SOCKET_H
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    undef socket
-#    define socket              socket_used_without_including_sys_socket_h
-#    undef connect
-#    define connect             connect_used_without_including_sys_socket_h
-#    undef accept
-#    define accept              accept_used_without_including_sys_socket_h
-#    undef bind
-#    define bind                bind_used_without_including_sys_socket_h
-#    undef getpeername
-#    define getpeername         getpeername_used_without_including_sys_socket_h
-#    undef getsockname
-#    define getsockname         getsockname_used_without_including_sys_socket_h
-#    undef getsockopt
-#    define getsockopt          getsockopt_used_without_including_sys_socket_h
-#    undef listen
-#    define listen              listen_used_without_including_sys_socket_h
-#    undef recv
-#    define recv                recv_used_without_including_sys_socket_h
-#    undef send
-#    define send                send_used_without_including_sys_socket_h
-#    undef recvfrom
-#    define recvfrom            recvfrom_used_without_including_sys_socket_h
-#    undef sendto
-#    define sendto              sendto_used_without_including_sys_socket_h
-#    undef setsockopt
-#    define setsockopt          setsockopt_used_without_including_sys_socket_h
-#    undef shutdown
-#    define shutdown            shutdown_used_without_including_sys_socket_h
-#   else
-     _GL_WARN_ON_USE (socket,
-                      "socket() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (connect,
-                      "connect() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (accept,
-                      "accept() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (bind,
-                      "bind() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (getpeername,
-                      "getpeername() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (getsockname,
-                      "getsockname() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (getsockopt,
-                      "getsockopt() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (listen,
-                      "listen() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (recv,
-                      "recv() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (send,
-                      "send() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (recvfrom,
-                      "recvfrom() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (sendto,
-                      "sendto() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (setsockopt,
-                      "setsockopt() used without including <sys/socket.h>");
-     _GL_WARN_ON_USE (shutdown,
-                      "shutdown() used without including <sys/socket.h>");
-#   endif
+/* Hide some function declarations from <winsock2.h>.  */
+
+#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
+# if !defined address@hidden@_SYS_SOCKET_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef socket
+#   define socket              socket_used_without_including_sys_socket_h
+#   undef connect
+#   define connect             connect_used_without_including_sys_socket_h
+#   undef accept
+#   define accept              accept_used_without_including_sys_socket_h
+#   undef bind
+#   define bind                bind_used_without_including_sys_socket_h
+#   undef getpeername
+#   define getpeername         getpeername_used_without_including_sys_socket_h
+#   undef getsockname
+#   define getsockname         getsockname_used_without_including_sys_socket_h
+#   undef getsockopt
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
+#   undef listen
+#   define listen              listen_used_without_including_sys_socket_h
+#   undef recv
+#   define recv                recv_used_without_including_sys_socket_h
+#   undef send
+#   define send                send_used_without_including_sys_socket_h
+#   undef recvfrom
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
+#   undef sendto
+#   define sendto              sendto_used_without_including_sys_socket_h
+#   undef setsockopt
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
+#   undef shutdown
+#   define shutdown            shutdown_used_without_including_sys_socket_h
+#  else
+    _GL_WARN_ON_USE (socket,
+                     "socket() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (connect,
+                     "connect() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (accept,
+                     "accept() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (bind,
+                     "bind() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getpeername,
+                     "getpeername() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockname,
+                     "getsockname() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockopt,
+                     "getsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (listen,
+                     "listen() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recv,
+                     "recv() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (send,
+                     "send() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recvfrom,
+                     "recvfrom() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (sendto,
+                     "sendto() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (setsockopt,
+                     "setsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (shutdown,
+                     "shutdown() used without including <sys/socket.h>");
 #  endif
-#  if !defined _GL_SYS_SELECT_H
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#    undef select
-#    define select              select_used_without_including_sys_select_h
-#   else
-     _GL_WARN_ON_USE (select,
-                      "select() used without including <sys/select.h>");
-#   endif
+# endif
+# if !defined address@hidden@_SYS_SELECT_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef select
+#   define select              select_used_without_including_sys_select_h
+#  else
+    _GL_WARN_ON_USE (select,
+                     "select() used without including <sys/select.h>");
 #  endif
 # endif
 #endif
@@ -223,12 +233,24 @@ _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.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/chown.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html.  */
 # if @REPLACE_CHOWN@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef chown
@@ -279,24 +301,32 @@ _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@
 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
    Return newfd if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/dup2.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>.  */
 # if @REPLACE_DUP2@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define dup2 rpl_dup2
@@ -425,8 +455,8 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
 /* Change the process' current working directory to the directory on which
    the given file descriptor is open.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>.  */
 # if ! @HAVE_FCHDIR@
 _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
 
@@ -483,11 +513,30 @@ _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
 #endif
 
 
-#if @GNULIB_FSYNC@
+#if @GNULIB_FDATASYNC@
 /* Synchronize changes to a file.
    Return 0 if successful, otherwise -1 and errno set.
-   See POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/fsync.html>.  */
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. 
 */
+# if address@hidden@ || address@hidden@
+_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
+# endif
+_GL_CXXALIAS_SYS (fdatasync, int, (int fd));
+_GL_CXXALIASWARN (fdatasync);
+#elif defined GNULIB_POSIXCHECK
+# undef fdatasync
+# if HAVE_RAW_DECL_FDATASYNC
+_GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
+                 "use gnulib module fdatasync for portability");
+# endif
+#endif
+
+
+#if @GNULIB_FSYNC@
+/* Synchronize changes, including metadata, to a file.
+   Return 0 if successful, otherwise -1 and errno set.
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>.  */
 # if address@hidden@
 _GL_FUNCDECL_SYS (fsync, int, (int fd));
 # endif
@@ -505,8 +554,8 @@ _GL_WARN_ON_USE (fsync, "fsync is unportable - "
 #if @GNULIB_FTRUNCATE@
 /* Change the size of the file to which FD is opened to become equal to LENGTH.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. 
 */
 # if address@hidden@
 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
 # endif
@@ -526,8 +575,8 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
    of BUF.
    Return BUF if successful, or NULL if the directory couldn't be determined
    or SIZE was too small.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getcwd.html>.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
    Additionally, the gnulib module 'getcwd' guarantees the following GNU
    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
@@ -870,12 +919,28 @@ _GL_WARN_ON_USE (endusershell, "endusershell is 
unportable - "
 #endif
 
 
+#if @GNULIB_GROUP_MEMBER@
+/* Determine whether group id is in calling user's group list.  */
+# if address@hidden@
+_GL_FUNCDECL_SYS (group_member, int, (gid_t gid));
+# endif
+_GL_CXXALIAS_SYS (group_member, int, (gid_t gid));
+_GL_CXXALIASWARN (group_member);
+#elif defined GNULIB_POSIXCHECK
+# undef group_member
+# if HAVE_RAW_DECL_GROUP_MEMBER
+_GL_WARN_ON_USE (group_member, "group_member is unportable - "
+                 "use gnulib module group-member for portability");
+# endif
+#endif
+
+
 #if @GNULIB_LCHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
    to GID (if GID is not -1).  Do not follow symbolic links.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/lchown.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>.  */
 # if @REPLACE_LCHOWN@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef lchown
@@ -904,8 +969,8 @@ _GL_WARN_ON_USE (lchown, "lchown is unportable to 
pre-POSIX.1-2001 systems - "
 #if @GNULIB_LINK@
 /* Create a new hard link for an existing file.
    Return 0 if successful, otherwise -1 and errno set.
-   See POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/link.html>.  */
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>.  */
 # if @REPLACE_LINK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define link rpl_link
@@ -970,8 +1035,8 @@ _GL_WARN_ON_USE (linkat, "linkat is unportable - "
 #if @GNULIB_LSEEK@
 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
    Return the new offset if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/lseek.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>.  */
 # if @REPLACE_LSEEK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define lseek rpl_lseek
@@ -1041,10 +1106,12 @@ _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
 #if @GNULIB_PREAD@
 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
    Return the number of bytes placed into BUF if successful, otherwise
-   set errno and return -1.  0 indicates EOF.  See the POSIX:2001
-   specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
+   set errno and return -1.  0 indicates EOF.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>.  */
 # if @REPLACE_PREAD@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pread
 #   define pread rpl_pread
 #  endif
 _GL_FUNCDECL_RPL (pread, ssize_t,
@@ -1075,10 +1142,11 @@ _GL_WARN_ON_USE (pread, "pread is unportable - "
 /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
    Return the number of bytes written if successful, otherwise
    set errno and return -1.  0 indicates nothing written.  See the
-   POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/pwrite.html>.  */
+   POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>.  */
 # if @REPLACE_PWRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pwrite
 #   define pwrite rpl_pwrite
 #  endif
 _GL_FUNCDECL_RPL (pwrite, ssize_t,
@@ -1105,12 +1173,34 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
 #endif
 
 
+#if @GNULIB_READ@
+/* 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@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef read
+#   define read rpl_read
+#  endif
+_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
+                                 _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
+# else
+/* Need to cast, because on mingw, the third parameter is
+                                                          unsigned int count
+   and the return type is 'int'.  */
+_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count));
+# endif
+_GL_CXXALIASWARN (read);
+#endif
+
+
 #if @GNULIB_READLINK@
 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
    bytes of it into BUF.  Return the number of bytes placed into BUF if
    successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/readlink.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>.  
*/
 # if @REPLACE_READLINK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define readlink rpl_readlink
@@ -1181,8 +1271,8 @@ _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
 #if @GNULIB_SLEEP@
 /* Pause the execution of the current thread for N seconds.
    Returns the number of seconds left to sleep.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/sleep.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>.  */
 # if @REPLACE_SLEEP@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef sleep
@@ -1331,7 +1421,7 @@ _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
 /* Pause the execution of the current thread for N microseconds.
    Returns 0 on completion, or -1 on range error.
    See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/sleep.html>.  */
+   <http://www.opengroup.org/susv3xsh/usleep.html>.  */
 # if @REPLACE_USLEEP@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef usleep
@@ -1357,9 +1447,9 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
 
 #if @GNULIB_WRITE@
 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/write.html>.  */
-# if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>.  */
+# if @REPLACE_WRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef write
 #   define write rpl_write
@@ -1377,5 +1467,5 @@ _GL_CXXALIASWARN (write);
 #endif
 
 
-#endif /* _GL_UNISTD_H */
-#endif /* _GL_UNISTD_H */
+#endif /* address@hidden@_UNISTD_H */
+#endif /* address@hidden@_UNISTD_H */
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 83faadb..3f2e91d 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -935,11 +935,11 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
         abort ();
       m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
     }
-#if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
-         precision.  */
+#  if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
+           precision.  */
   if (!(y == 0.0L))
     abort ();
-#endif
+#  endif
   /* Normalise.  */
   while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
     m.nlimbs--;
diff --git a/gl/verify.h b/gl/verify.h
index 5e91abd..9a8caad 100644
--- a/gl/verify.h
+++ b/gl/verify.h
@@ -17,21 +17,41 @@
 
 /* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
 
-#ifndef VERIFY_H
-# define VERIFY_H 1
+#ifndef _GL_VERIFY_H
+# define _GL_VERIFY_H
+
+
+/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per the
+   C1X draft N1548 section 6.7.10.  This is supported by GCC 4.6.0 and
+   later, in C mode, and its use here generates easier-to-read diagnostics
+   when verify (R) fails.
+
+   Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per the
+   C++0X draft N3242 section 7.(4).
+   This will likely be supported by future GCC versions, in C++ mode.
+
+   Use this only with GCC.  If we were willing to slow 'configure'
+   down we could also use it with other compilers, but since this
+   affects only the quality of diagnostics, why bother?  */
+# if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined 
__cplusplus
+#  define _GL_HAVE__STATIC_ASSERT 1
+# endif
+/* The condition (99 < __GNUC__) is temporary, until we know about the
+   first G++ release that supports static_assert.  */
+# if (99 < __GNUC__) && defined __cplusplus
+#  define _GL_HAVE_STATIC_ASSERT 1
+# endif
 
 /* Each of these macros verifies that its argument R is nonzero.  To
    be portable, R should be an integer constant expression.  Unlike
    assert (R), there is no run-time overhead.
 
-   There are two macros, since no single macro can be used in all
-   contexts in C.  verify_true (R) is for scalar contexts, including
-   integer constant expression contexts.  verify (R) is for declaration
-   contexts, e.g., the top level.
-
-   Symbols ending in "__" are private to this header.
+   If _Static_assert works, verify (R) uses it directly.  Similarly,
+   _GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
+   that is an operand of sizeof.
 
-   The code below uses several ideas.
+   The code below uses several ideas for C++ compilers, and for C
+   compilers that do not support _Static_assert:
 
    * The first step is ((R) ? 1 : -1).  Given an expression R, of
      integral or boolean or floating-point type, this yields an
@@ -39,7 +59,9 @@
      constant and nonnegative.
 
    * Next this expression W is wrapped in a type
-     struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
+     struct _gl_verify_type {
+       unsigned int _gl_verify_error_if_negative: W;
+     }.
      If W is negative, this yields a compile-time error.  No compiler can
      deal with a bit-field of negative size.
 
@@ -53,7 +75,7 @@
 
        void function (int n) { verify (n < 0); }
 
-   * For the verify macro, the struct verify_type__ will need to
+   * For the verify macro, the struct _gl_verify_type will need to
      somehow be embedded into a declaration.  To be portable, this
      declaration must declare an object, a constant, a function, or a
      typedef name.  If the declared entity uses the type directly,
@@ -91,11 +113,11 @@
      Which of the following alternatives can be used?
 
        extern int dummy [sizeof (struct {...})];
-       extern int dummy [sizeof (struct verify_type__ {...})];
+       extern int dummy [sizeof (struct _gl_verify_type {...})];
        extern void dummy (int [sizeof (struct {...})]);
-       extern void dummy (int [sizeof (struct verify_type__ {...})]);
+       extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
        extern int (*dummy (void)) [sizeof (struct {...})];
-       extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
+       extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
 
      In the second and sixth case, the struct type is exported to the
      outer scope; two such declarations therefore collide.  GCC warns
@@ -109,15 +131,9 @@
      __COUNTER__ macro that can let us generate unique identifiers for
      each dummy function, to suppress this warning.
 
-   * This implementation exploits the fact that GCC does not warn about
-     the last declaration mentioned above.  If a future version of GCC
-     introduces a warning for this, the problem could be worked around
-     by using code specialized to GCC, just as __COUNTER__ is already
-     being used if available.
-
-       #if 4 <= __GNUC__
-       # define verify(R) [another version to keep GCC happy]
-       #endif
+   * This implementation exploits the fact that older versions of GCC,
+     which do not support _Static_assert, also do not warn about the
+     last declaration mentioned above.
 
    * In C++, any struct definition inside sizeof is invalid.
      Use a template type to work around the problem.  */
@@ -140,24 +156,88 @@
    possible.  */
 # define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
 
-/* Verify requirement R at compile-time, as an integer constant expression.
-   Return 1.  */
+/* Verify requirement R at compile-time, as an integer constant expression
+   that returns 1.  If R is false, fail at compile-time, preferably
+   with a diagnostic that includes the string-literal DIAGNOSTIC.  */
+
+# define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
+    (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
 
 # ifdef __cplusplus
+#  if !GNULIB_defined_struct__gl_verify_type
 template <int w>
-  struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
-#  define verify_true(R) \
-     (!!sizeof (verify_type__<(R) ? 1 : -1>))
+  struct _gl_verify_type {
+    unsigned int _gl_verify_error_if_negative: w;
+  };
+#   define GNULIB_defined_struct__gl_verify_type 1
+#  endif
+#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+    _gl_verify_type<(R) ? 1 : -1>
+# elif defined _GL_HAVE__STATIC_ASSERT
+#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+     struct {                                   \
+       _Static_assert (R, DIAGNOSTIC);          \
+       int _gl_dummy;                          \
+     }
 # else
-#  define verify_true(R) \
-     (!!sizeof \
-      (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+     struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
 # endif
 
 /* Verify requirement R at compile-time, as a declaration without a
+   trailing ';'.  If R is false, fail at compile-time, preferably
+   with a diagnostic that includes the string-literal DIAGNOSTIC.
+
+   Unfortunately, unlike C1X, this implementation must appear as an
+   ordinary declaration, and cannot appear inside struct { ... }.  */
+
+# ifdef _GL_HAVE__STATIC_ASSERT
+#  define _GL_VERIFY _Static_assert
+# else
+#  define _GL_VERIFY(R, DIAGNOSTIC)                                   \
+     extern int (*_GL_GENSYM (_gl_verify_function) (void))            \
+       [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
+# endif
+
+/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
+# ifdef _GL_STATIC_ASSERT_H
+#  if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
+#   define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
+#  endif
+#  if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
+#   define static_assert _Static_assert /* Draft C1X requires this #define.  */
+#  endif
+# endif
+
+/* @assert.h omit start@  */
+
+/* Each of these macros verifies that its argument R is nonzero.  To
+   be portable, R should be an integer constant expression.  Unlike
+   assert (R), there is no run-time overhead.
+
+   There are two macros, since no single macro can be used in all
+   contexts in C.  verify_true (R) is for scalar contexts, including
+   integer constant expression contexts.  verify (R) is for declaration
+   contexts, e.g., the top level.  */
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+   Return 1.  This is equivalent to verify_expr (R, 1).
+
+   verify_true is obsolescent; please use verify_expr instead.  */
+
+# define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
+
+/* Verify requirement R at compile-time.  Return the value of the
+   expression E.  */
+
+# define verify_expr(R, E) \
+    (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
+
+/* Verify requirement R at compile-time, as a declaration without a
    trailing ';'.  */
 
-# define verify(R) \
-    extern int (* _GL_GENSYM (verify_function) (void)) [verify_true (R)]
+# define verify(R) _GL_VERIFY (R, "verify (" #R ")")
+
+/* @assert.h omit end@  */
 
 #endif
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/gl/wchar.in.h b/gl/wchar.in.h
new file mode 100644
index 0000000..1ed4521
--- /dev/null
+++ b/gl/wchar.in.h
@@ -0,0 +1,1006 @@
+/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
+
+   Copyright (C) 2007-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.  */
+
+/* Written by Eric Blake.  */
+
+/*
+ * ISO C 99 <wchar.h> for platforms that have issues.
+ * <http://www.opengroup.org/susv3xbd/wchar.h.html>
+ *
+ * For now, this just ensures proper prerequisite inclusion order and
+ * the declaration of wcwidth().
+ */
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && 
((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined 
_GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
+/* Special invocation convention:
+   - Inside glibc and uClibc header files.
+   - On HP-UX 11.00 we have a sequence of nested includes
+     <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
+     once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
+     and once directly.  In both situations 'wint_t' is not yet defined,
+     therefore we cannot provide the function overrides; instead include only
+     the system's <wchar.h>.
+   - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
+     the latter includes <wchar.h>.  But here, we have no way to detect whether
+     <wctype.h> is completely included or is still being included.  */
+
address@hidden@ @NEXT_WCHAR_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef address@hidden@_WCHAR_H
+
+#define _GL_ALREADY_INCLUDING_WCHAR_H
+
+#if @HAVE_FEATURES_H@
+# include <features.h> /* for __GLIBC__ */
+#endif
+
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.
+   In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
+   by <stddef.h>.
+   But avoid namespace pollution on glibc systems.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <stddef.h>
+#endif
+#ifndef __GLIBC__
+# include <stdio.h>
+# include <time.h>
+#endif
+
+/* Include the original <wchar.h> if it exists.
+   Some builds of uClibc lack it.  */
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_WCHAR_H@
+# @INCLUDE_NEXT@ @NEXT_WCHAR_H@
+#endif
+
+#undef _GL_ALREADY_INCLUDING_WCHAR_H
+
+#ifndef address@hidden@_WCHAR_H
+#define address@hidden@_WCHAR_H
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Define wint_t and WEOF.  (Also done in wctype.in.h.)  */
+#if address@hidden@ && !defined wint_t
+# define wint_t int
+# ifndef WEOF
+#  define WEOF -1
+# endif
+#else
+/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
+   This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
+   "unchanged by default argument promotions".  Override it.  */
+# if defined _MSC_VER
+#  if !GNULIB_defined_wint_t
+#   include <crtdefs.h>
+typedef unsigned int rpl_wint_t;
+#   undef wint_t
+#   define wint_t rpl_wint_t
+#   define GNULIB_defined_wint_t 1
+#  endif
+# endif
+# ifndef WEOF
+#  define WEOF ((wint_t) -1)
+# endif
+#endif
+
+
+/* Override mbstate_t if it is too small.
+   On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
+   implementing mbrtowc for encodings like UTF-8.  */
+#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
+# if !GNULIB_defined_mbstate_t
+typedef int rpl_mbstate_t;
+#  undef mbstate_t
+#  define mbstate_t rpl_mbstate_t
+#  define GNULIB_defined_mbstate_t 1
+# endif
+#endif
+
+
+/* Convert a single-byte character to a wide character.  */
+#if @GNULIB_BTOWC@
+# if @REPLACE_BTOWC@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef btowc
+#   define btowc rpl_btowc
+#  endif
+_GL_FUNCDECL_RPL (btowc, wint_t, (int c));
+_GL_CXXALIAS_RPL (btowc, wint_t, (int c));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (btowc, wint_t, (int c));
+#  endif
+_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
+# endif
+_GL_CXXALIASWARN (btowc);
+#elif defined GNULIB_POSIXCHECK
+# undef btowc
+# if HAVE_RAW_DECL_BTOWC
+_GL_WARN_ON_USE (btowc, "btowc is unportable - "
+                 "use gnulib module btowc for portability");
+# endif
+#endif
+
+
+/* Convert a wide character to a single-byte character.  */
+#if @GNULIB_WCTOB@
+# if @REPLACE_WCTOB@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wctob
+#   define wctob rpl_wctob
+#  endif
+_GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
+_GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
+# else
+#  if !defined wctob && address@hidden@
+/* wctob is provided by gnulib, or wctob exists but is not declared.  */
+_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
+#  endif
+_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
+# endif
+_GL_CXXALIASWARN (wctob);
+#elif defined GNULIB_POSIXCHECK
+# undef wctob
+# if HAVE_RAW_DECL_WCTOB
+_GL_WARN_ON_USE (wctob, "wctob is unportable - "
+                 "use gnulib module wctob for portability");
+# endif
+#endif
+
+
+/* Test whether *PS is in the initial state.  */
+#if @GNULIB_MBSINIT@
+# if @REPLACE_MBSINIT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbsinit
+#   define mbsinit rpl_mbsinit
+#  endif
+_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
+_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
+#  endif
+_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (mbsinit);
+#elif defined GNULIB_POSIXCHECK
+# undef mbsinit
+# if HAVE_RAW_DECL_MBSINIT
+_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
+                 "use gnulib module mbsinit for portability");
+# endif
+#endif
+
+
+/* Convert a multibyte character to a wide character.  */
+#if @GNULIB_MBRTOWC@
+# if @REPLACE_MBRTOWC@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbrtowc
+#   define mbrtowc rpl_mbrtowc
+#  endif
+_GL_FUNCDECL_RPL (mbrtowc, size_t,
+                  (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
+_GL_CXXALIAS_RPL (mbrtowc, size_t,
+                  (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (mbrtowc, size_t,
+                  (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
+#  endif
+_GL_CXXALIAS_SYS (mbrtowc, size_t,
+                  (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (mbrtowc);
+#elif defined GNULIB_POSIXCHECK
+# undef mbrtowc
+# if HAVE_RAW_DECL_MBRTOWC
+_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
+                 "use gnulib module mbrtowc for portability");
+# endif
+#endif
+
+
+/* Recognize a multibyte character.  */
+#if @GNULIB_MBRLEN@
+# if @REPLACE_MBRLEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbrlen
+#   define mbrlen rpl_mbrlen
+#  endif
+_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
+_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
+#  endif
+_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (mbrlen);
+#elif defined GNULIB_POSIXCHECK
+# undef mbrlen
+# if HAVE_RAW_DECL_MBRLEN
+_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
+                 "use gnulib module mbrlen for portability");
+# endif
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSRTOWCS@
+# if @REPLACE_MBSRTOWCS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbsrtowcs
+#   define mbsrtowcs rpl_mbsrtowcs
+#  endif
+_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t len,
+                   mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t len,
+                   mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (mbsrtowcs);
+#elif defined GNULIB_POSIXCHECK
+# undef mbsrtowcs
+# if HAVE_RAW_DECL_MBSRTOWCS
+_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
+                 "use gnulib module mbsrtowcs for portability");
+# endif
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSNRTOWCS@
+# if @REPLACE_MBSNRTOWCS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mbsnrtowcs
+#   define mbsnrtowcs rpl_mbsnrtowcs
+#  endif
+_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
+                  (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (mbsnrtowcs);
+#elif defined GNULIB_POSIXCHECK
+# undef mbsnrtowcs
+# if HAVE_RAW_DECL_MBSNRTOWCS
+_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
+                 "use gnulib module mbsnrtowcs for portability");
+# endif
+#endif
+
+
+/* Convert a wide character to a multibyte character.  */
+#if @GNULIB_WCRTOMB@
+# if @REPLACE_WCRTOMB@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcrtomb
+#   define wcrtomb rpl_wcrtomb
+#  endif
+_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
+_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
+#  endif
+_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (wcrtomb);
+#elif defined GNULIB_POSIXCHECK
+# undef wcrtomb
+# if HAVE_RAW_DECL_WCRTOMB
+_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
+                 "use gnulib module wcrtomb for portability");
+# endif
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSRTOMBS@
+# if @REPLACE_WCSRTOMBS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcsrtombs
+#   define wcsrtombs rpl_wcsrtombs
+#  endif
+_GL_FUNCDECL_RPL (wcsrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (wcsrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t len,
+                   mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (wcsrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (wcsrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t len,
+                   mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (wcsrtombs);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsrtombs
+# if HAVE_RAW_DECL_WCSRTOMBS
+_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
+                 "use gnulib module wcsrtombs for portability");
+# endif
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSNRTOMBS@
+# if @REPLACE_WCSNRTOMBS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcsnrtombs
+#   define wcsnrtombs rpl_wcsnrtombs
+#  endif
+_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps)
+                  _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
+                  (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
+                   mbstate_t *ps));
+# endif
+_GL_CXXALIASWARN (wcsnrtombs);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsnrtombs
+# if HAVE_RAW_DECL_WCSNRTOMBS
+_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
+                 "use gnulib module wcsnrtombs for portability");
+# endif
+#endif
+
+
+/* Return the number of screen columns needed for WC.  */
+#if @GNULIB_WCWIDTH@
+# if @REPLACE_WCWIDTH@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcwidth
+#   define wcwidth rpl_wcwidth
+#  endif
+_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
+_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
+# else
+#  if address@hidden@
+/* wcwidth exists but is not declared.  */
+_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
+#  endif
+_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
+# endif
+_GL_CXXALIASWARN (wcwidth);
+#elif defined GNULIB_POSIXCHECK
+# undef wcwidth
+# if HAVE_RAW_DECL_WCWIDTH
+_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
+                 "use gnulib module wcwidth for portability");
+# endif
+#endif
+
+
+/* Search N wide characters of S for C.  */
+#if @GNULIB_WMEMCHR@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wmemchr, wchar_t *, (const wchar_t *s, wchar_t c, size_t n));
+# endif
+  /* On some systems, this function is defined as an overloaded function:
+       extern "C++" {
+         const wchar_t * std::wmemchr (const wchar_t *, wchar_t, size_t);
+         wchar_t * std::wmemchr (wchar_t *, wchar_t, size_t);
+       }  */
+_GL_CXXALIAS_SYS_CAST2 (wmemchr,
+                        wchar_t *, (const wchar_t *, wchar_t, size_t),
+                        const wchar_t *, (const wchar_t *, wchar_t, size_t));
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
+_GL_CXXALIASWARN1 (wmemchr, const wchar_t *,
+                   (const wchar_t *s, wchar_t c, size_t n));
+# else
+_GL_CXXALIASWARN (wmemchr);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wmemchr
+# if HAVE_RAW_DECL_WMEMCHR
+_GL_WARN_ON_USE (wmemchr, "wmemchr is unportable - "
+                 "use gnulib module wmemchr for portability");
+# endif
+#endif
+
+
+/* Compare N wide characters of S1 and S2.  */
+#if @GNULIB_WMEMCMP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wmemcmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wmemcmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+_GL_CXXALIASWARN (wmemcmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wmemcmp
+# if HAVE_RAW_DECL_WMEMCMP
+_GL_WARN_ON_USE (wmemcmp, "wmemcmp is unportable - "
+                 "use gnulib module wmemcmp for portability");
+# endif
+#endif
+
+
+/* Copy N wide characters of SRC to DEST.  */
+#if @GNULIB_WMEMCPY@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wmemcpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wmemcpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+_GL_CXXALIASWARN (wmemcpy);
+#elif defined GNULIB_POSIXCHECK
+# undef wmemcpy
+# if HAVE_RAW_DECL_WMEMCPY
+_GL_WARN_ON_USE (wmemcpy, "wmemcpy is unportable - "
+                 "use gnulib module wmemcpy for portability");
+# endif
+#endif
+
+
+/* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for
+   overlapping memory areas.  */
+#if @GNULIB_WMEMMOVE@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wmemmove, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wmemmove, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+_GL_CXXALIASWARN (wmemmove);
+#elif defined GNULIB_POSIXCHECK
+# undef wmemmove
+# if HAVE_RAW_DECL_WMEMMOVE
+_GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - "
+                 "use gnulib module wmemmove for portability");
+# endif
+#endif
+
+
+/* Set N wide characters of S to C.  */
+#if @GNULIB_WMEMSET@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
+_GL_CXXALIASWARN (wmemset);
+#elif defined GNULIB_POSIXCHECK
+# undef wmemset
+# if HAVE_RAW_DECL_WMEMSET
+_GL_WARN_ON_USE (wmemset, "wmemset is unportable - "
+                 "use gnulib module wmemset for portability");
+# endif
+#endif
+
+
+/* Return the number of wide characters in S.  */
+#if @GNULIB_WCSLEN@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s));
+# endif
+_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s));
+_GL_CXXALIASWARN (wcslen);
+#elif defined GNULIB_POSIXCHECK
+# undef wcslen
+# if HAVE_RAW_DECL_WCSLEN
+_GL_WARN_ON_USE (wcslen, "wcslen is unportable - "
+                 "use gnulib module wcslen for portability");
+# endif
+#endif
+
+
+/* Return the number of wide characters in S, but at most MAXLEN.  */
+#if @GNULIB_WCSNLEN@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen));
+# endif
+_GL_CXXALIAS_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen));
+_GL_CXXALIASWARN (wcsnlen);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsnlen
+# if HAVE_RAW_DECL_WCSNLEN
+_GL_WARN_ON_USE (wcsnlen, "wcsnlen is unportable - "
+                 "use gnulib module wcsnlen for portability");
+# endif
+#endif
+
+
+/* Copy SRC to DEST.  */
+#if @GNULIB_WCSCPY@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
+# endif
+_GL_CXXALIAS_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
+_GL_CXXALIASWARN (wcscpy);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscpy
+# if HAVE_RAW_DECL_WCSCPY
+_GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - "
+                 "use gnulib module wcscpy for portability");
+# endif
+#endif
+
+
+/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST.  
*/
+#if @GNULIB_WCPCPY@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
+# endif
+_GL_CXXALIAS_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
+_GL_CXXALIASWARN (wcpcpy);
+#elif defined GNULIB_POSIXCHECK
+# undef wcpcpy
+# if HAVE_RAW_DECL_WCPCPY
+_GL_WARN_ON_USE (wcpcpy, "wcpcpy is unportable - "
+                 "use gnulib module wcpcpy for portability");
+# endif
+#endif
+
+
+/* Copy no more than N wide characters of SRC to DEST.  */
+#if @GNULIB_WCSNCPY@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsncpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsncpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+_GL_CXXALIASWARN (wcsncpy);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsncpy
+# if HAVE_RAW_DECL_WCSNCPY
+_GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - "
+                 "use gnulib module wcsncpy for portability");
+# endif
+#endif
+
+
+/* Copy no more than N characters of SRC to DEST, returning the address of
+   the last character written into DEST.  */
+#if @GNULIB_WCPNCPY@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcpncpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcpncpy, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+_GL_CXXALIASWARN (wcpncpy);
+#elif defined GNULIB_POSIXCHECK
+# undef wcpncpy
+# if HAVE_RAW_DECL_WCPNCPY
+_GL_WARN_ON_USE (wcpncpy, "wcpncpy is unportable - "
+                 "use gnulib module wcpncpy for portability");
+# endif
+#endif
+
+
+/* Append SRC onto DEST.  */
+#if @GNULIB_WCSCAT@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src));
+# endif
+_GL_CXXALIAS_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src));
+_GL_CXXALIASWARN (wcscat);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscat
+# if HAVE_RAW_DECL_WCSCAT
+_GL_WARN_ON_USE (wcscat, "wcscat is unportable - "
+                 "use gnulib module wcscat for portability");
+# endif
+#endif
+
+
+/* Append no more than N wide characters of SRC onto DEST.  */
+#if @GNULIB_WCSNCAT@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsncat, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsncat, wchar_t *,
+                  (wchar_t *dest, const wchar_t *src, size_t n));
+_GL_CXXALIASWARN (wcsncat);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsncat
+# if HAVE_RAW_DECL_WCSNCAT
+_GL_WARN_ON_USE (wcsncat, "wcsncat is unportable - "
+                 "use gnulib module wcsncat for portability");
+# endif
+#endif
+
+
+/* Compare S1 and S2.  */
+#if @GNULIB_WCSCMP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
+# endif
+_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
+_GL_CXXALIASWARN (wcscmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscmp
+# if HAVE_RAW_DECL_WCSCMP
+_GL_WARN_ON_USE (wcscmp, "wcscmp is unportable - "
+                 "use gnulib module wcscmp for portability");
+# endif
+#endif
+
+
+/* Compare no more than N wide characters of S1 and S2.  */
+#if @GNULIB_WCSNCMP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsncmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsncmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+_GL_CXXALIASWARN (wcsncmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsncmp
+# if HAVE_RAW_DECL_WCSNCMP
+_GL_WARN_ON_USE (wcsncmp, "wcsncmp is unportable - "
+                 "use gnulib module wcsncmp for portability");
+# endif
+#endif
+
+
+/* Compare S1 and S2, ignoring case.  */
+#if @GNULIB_WCSCASECMP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2));
+# endif
+_GL_CXXALIAS_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2));
+_GL_CXXALIASWARN (wcscasecmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscasecmp
+# if HAVE_RAW_DECL_WCSCASECMP
+_GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - "
+                 "use gnulib module wcscasecmp for portability");
+# endif
+#endif
+
+
+/* Compare no more than N chars of S1 and S2, ignoring case.  */
+#if @GNULIB_WCSNCASECMP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsncasecmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsncasecmp, int,
+                  (const wchar_t *s1, const wchar_t *s2, size_t n));
+_GL_CXXALIASWARN (wcsncasecmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsncasecmp
+# if HAVE_RAW_DECL_WCSNCASECMP
+_GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - "
+                 "use gnulib module wcsncasecmp for portability");
+# endif
+#endif
+
+
+/* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE
+   category of the current locale.  */
+#if @GNULIB_WCSCOLL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
+# endif
+_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
+_GL_CXXALIASWARN (wcscoll);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscoll
+# if HAVE_RAW_DECL_WCSCOLL
+_GL_WARN_ON_USE (wcscoll, "wcscoll is unportable - "
+                 "use gnulib module wcscoll for portability");
+# endif
+#endif
+
+
+/* Transform S2 into array pointed to by S1 such that if wcscmp is applied
+   to two transformed strings the result is the as applying 'wcscoll' to the
+   original strings.  */
+#if @GNULIB_WCSXFRM@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n));
+_GL_CXXALIASWARN (wcsxfrm);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsxfrm
+# if HAVE_RAW_DECL_WCSXFRM
+_GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - "
+                 "use gnulib module wcsxfrm for portability");
+# endif
+#endif
+
+
+/* Duplicate S, returning an identical malloc'd string.  */
+#if @GNULIB_WCSDUP@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s));
+# endif
+_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
+_GL_CXXALIASWARN (wcsdup);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsdup
+# if HAVE_RAW_DECL_WCSDUP
+_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - "
+                 "use gnulib module wcsdup for portability");
+# endif
+#endif
+
+
+/* Find the first occurrence of WC in WCS.  */
+#if @GNULIB_WCSCHR@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcschr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
+# endif
+  /* On some systems, this function is defined as an overloaded function:
+       extern "C++" {
+         const wchar_t * std::wcschr (const wchar_t *, wchar_t);
+         wchar_t * std::wcschr (wchar_t *, wchar_t);
+       }  */
+_GL_CXXALIAS_SYS_CAST2 (wcschr,
+                        wchar_t *, (const wchar_t *, wchar_t),
+                        const wchar_t *, (const wchar_t *, wchar_t));
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc));
+_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
+# else
+_GL_CXXALIASWARN (wcschr);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcschr
+# if HAVE_RAW_DECL_WCSCHR
+_GL_WARN_ON_USE (wcschr, "wcschr is unportable - "
+                 "use gnulib module wcschr for portability");
+# endif
+#endif
+
+
+/* Find the last occurrence of WC in WCS.  */
+#if @GNULIB_WCSRCHR@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsrchr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
+# endif
+  /* On some systems, this function is defined as an overloaded function:
+       extern "C++" {
+         const wchar_t * std::wcsrchr (const wchar_t *, wchar_t);
+         wchar_t * std::wcsrchr (wchar_t *, wchar_t);
+       }  */
+_GL_CXXALIAS_SYS_CAST2 (wcsrchr,
+                        wchar_t *, (const wchar_t *, wchar_t),
+                        const wchar_t *, (const wchar_t *, wchar_t));
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc));
+_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
+# else
+_GL_CXXALIASWARN (wcsrchr);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsrchr
+# if HAVE_RAW_DECL_WCSRCHR
+_GL_WARN_ON_USE (wcsrchr, "wcsrchr is unportable - "
+                 "use gnulib module wcsrchr for portability");
+# endif
+#endif
+
+
+/* Return the length of the initial segmet of WCS which consists entirely
+   of wide characters not in REJECT.  */
+#if @GNULIB_WCSCSPN@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t 
*reject));
+# endif
+_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t 
*reject));
+_GL_CXXALIASWARN (wcscspn);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscspn
+# if HAVE_RAW_DECL_WCSCSPN
+_GL_WARN_ON_USE (wcscspn, "wcscspn is unportable - "
+                 "use gnulib module wcscspn for portability");
+# endif
+#endif
+
+
+/* Return the length of the initial segmet of WCS which consists entirely
+   of wide characters in ACCEPT.  */
+#if @GNULIB_WCSSPN@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
+# endif
+_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
+_GL_CXXALIASWARN (wcsspn);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsspn
+# if HAVE_RAW_DECL_WCSSPN
+_GL_WARN_ON_USE (wcsspn, "wcsspn is unportable - "
+                 "use gnulib module wcsspn for portability");
+# endif
+#endif
+
+
+/* Find the first occurrence in WCS of any character in ACCEPT.  */
+#if @GNULIB_WCSPBRK@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcspbrk, wchar_t *,
+                  (const wchar_t *wcs, const wchar_t *accept));
+# endif
+  /* On some systems, this function is defined as an overloaded function:
+       extern "C++" {
+         const wchar_t * std::wcspbrk (const wchar_t *, const wchar_t *);
+         wchar_t * std::wcspbrk (wchar_t *, const wchar_t *);
+       }  */
+_GL_CXXALIAS_SYS_CAST2 (wcspbrk,
+                        wchar_t *, (const wchar_t *, const wchar_t *),
+                        const wchar_t *, (const wchar_t *, const wchar_t *));
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (wcspbrk, wchar_t *,
+                   (wchar_t *wcs, const wchar_t *accept));
+_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *,
+                   (const wchar_t *wcs, const wchar_t *accept));
+# else
+_GL_CXXALIASWARN (wcspbrk);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcspbrk
+# if HAVE_RAW_DECL_WCSPBRK
+_GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - "
+                 "use gnulib module wcspbrk for portability");
+# endif
+#endif
+
+
+/* Find the first occurrence of NEEDLE in HAYSTACK.  */
+#if @GNULIB_WCSSTR@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcsstr, wchar_t *,
+                  (const wchar_t *haystack, const wchar_t *needle));
+# endif
+  /* On some systems, this function is defined as an overloaded function:
+       extern "C++" {
+         const wchar_t * std::wcsstr (const wchar_t *, const wchar_t *);
+         wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
+       }  */
+_GL_CXXALIAS_SYS_CAST2 (wcsstr,
+                        wchar_t *, (const wchar_t *, const wchar_t *),
+                        const wchar_t *, (const wchar_t *, const wchar_t *));
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (wcsstr, wchar_t *,
+                   (wchar_t *haystack, const wchar_t *needle));
+_GL_CXXALIASWARN1 (wcsstr, const wchar_t *,
+                   (const wchar_t *haystack, const wchar_t *needle));
+# else
+_GL_CXXALIASWARN (wcsstr);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsstr
+# if HAVE_RAW_DECL_WCSSTR
+_GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
+                 "use gnulib module wcsstr for portability");
+# endif
+#endif
+
+
+/* Divide WCS into tokens separated by characters in DELIM.  */
+#if @GNULIB_WCSTOK@
+# if address@hidden@
+_GL_FUNCDECL_SYS (wcstok, wchar_t *,
+                  (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
+# endif
+_GL_CXXALIAS_SYS (wcstok, wchar_t *,
+                  (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
+_GL_CXXALIASWARN (wcstok);
+#elif defined GNULIB_POSIXCHECK
+# undef wcstok
+# if HAVE_RAW_DECL_WCSTOK
+_GL_WARN_ON_USE (wcstok, "wcstok is unportable - "
+                 "use gnulib module wcstok for portability");
+# endif
+#endif
+
+
+/* Determine number of column positions required for first N wide
+   characters (or fewer if S ends before this) in S.  */
+#if @GNULIB_WCSWIDTH@
+# if @REPLACE_WCSWIDTH@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcswidth
+#   define wcswidth rpl_wcswidth
+#  endif
+_GL_FUNCDECL_RPL (wcswidth, int, (const wchar_t *s, size_t n));
+_GL_CXXALIAS_RPL (wcswidth, int, (const wchar_t *s, size_t n));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n));
+#  endif
+_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n));
+# endif
+_GL_CXXALIASWARN (wcswidth);
+#elif defined GNULIB_POSIXCHECK
+# undef wcswidth
+# if HAVE_RAW_DECL_WCSWIDTH
+_GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
+                 "use gnulib module wcswidth for portability");
+# endif
+#endif
+
+
+#endif /* address@hidden@_WCHAR_H */
+#endif /* address@hidden@_WCHAR_H */
+#endif
diff --git a/lib/auth_srp.c b/lib/auth_srp.c
index 714e50c..724cbf0 100644
--- a/lib/auth_srp.c
+++ b/lib/auth_srp.c
@@ -728,7 +728,7 @@ _gnutls_proc_srp_server_kx (gnutls_session_t session, 
opaque * data,
 {
   uint8_t n_s;
   uint16_t n_g, n_n, n_b;
-  size_t _n_s, _n_g, _n_n, _n_b;
+  size_t _n_g, _n_n, _n_b;
   const uint8_t *data_n;
   const uint8_t *data_g;
   const uint8_t *data_s;
@@ -817,7 +817,6 @@ _gnutls_proc_srp_server_kx (gnutls_session_t session, 
opaque * data,
   data_b = &data[i];
   i += n_b;
 
-  _n_s = n_s;
   _n_g = n_g;
   _n_n = n_n;
   _n_b = n_b;
diff --git a/lib/build-aux/config.rpath b/lib/build-aux/config.rpath
index c547c68..8bd7f5d 100755
--- a/lib/build-aux/config.rpath
+++ b/lib/build-aux/config.rpath
@@ -2,7 +2,7 @@
 # Output a system dependent set of variables, describing how to set the
 # run time search path of shared libraries in an executable.
 #
-#   Copyright 1996-2007 Free Software Foundation, Inc.
+#   Copyright 1996-2011 Free Software Foundation, Inc.
 #   Taken from GNU libtool, 2001
 #   Originally by Gordon Matzigkeit <address@hidden>, 1996
 #
@@ -47,7 +47,7 @@ for cc_temp in $CC""; do
 done
 cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'`
 
-# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.
+# Code taken from libtool.m4's _LT_COMPILER_PIC.
 
 wl=
 if test "$GCC" = yes; then
@@ -57,14 +57,7 @@ else
     aix*)
       wl='-Wl,'
       ;;
-    darwin*)
-      case $cc_basename in
-        xlc*)
-          wl='-Wl,'
-          ;;
-      esac
-      ;;
-    mingw* | cygwin* | pw32* | os2*)
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
       ;;
     hpux9* | hpux10* | hpux11*)
       wl='-Wl,'
@@ -72,24 +65,37 @@ else
     irix5* | irix6* | nonstopux*)
       wl='-Wl,'
       ;;
-    newsos6)
-      ;;
-    linux* | k*bsd*-gnu)
+    linux* | k*bsd*-gnu | kopensolaris*-gnu)
       case $cc_basename in
-        icc* | ecc*)
+        ecc*)
           wl='-Wl,'
           ;;
-        pgcc | pgf77 | pgf90)
+        icc* | ifort*)
+          wl='-Wl,'
+          ;;
+        lf95*)
+          wl='-Wl,'
+          ;;
+        nagfor*)
+          wl='-Wl,-Wl,,'
+          ;;
+        pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
           wl='-Wl,'
           ;;
         ccc*)
           wl='-Wl,'
           ;;
+        xl* | bgxl* | bgf* | mpixl*)
+          wl='-Wl,'
+          ;;
         como)
           wl='-lopt='
           ;;
         *)
           case `$CC -V 2>&1 | sed 5q` in
+            *Sun\ F* | *Sun*Fortran*)
+              wl=
+              ;;
             *Sun\ C*)
               wl='-Wl,'
               ;;
@@ -97,13 +103,24 @@ else
           ;;
       esac
       ;;
+    newsos6)
+      ;;
+    *nto* | *qnx*)
+      ;;
     osf3* | osf4* | osf5*)
       wl='-Wl,'
       ;;
     rdos*)
       ;;
     solaris*)
-      wl='-Wl,'
+      case $cc_basename in
+        f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
+          wl='-Qoption ld '
+          ;;
+        *)
+          wl='-Wl,'
+          ;;
+      esac
       ;;
     sunos4*)
       wl='-Qoption ld '
@@ -124,7 +141,7 @@ else
   esac
 fi
 
-# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS.
+# Code taken from libtool.m4's _LT_LINKER_SHLIBS.
 
 hardcode_libdir_flag_spec=
 hardcode_libdir_separator=
@@ -132,7 +149,7 @@ hardcode_direct=no
 hardcode_minus_L=no
 
 case "$host_os" in
-  cygwin* | mingw* | pw32*)
+  cygwin* | mingw* | pw32* | cegcc*)
     # FIXME: the MSVC++ port hasn't been tested in a loooong time
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -158,22 +175,21 @@ if test "$with_gnu_ld" = yes; then
   # option of GNU ld is called -rpath, not --rpath.
   hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
   case "$host_os" in
-    aix3* | aix4* | aix5*)
+    aix[3-9]*)
       # On AIX/PPC, the GNU linker is very broken
       if test "$host_cpu" != ia64; then
         ld_shlibs=no
       fi
       ;;
     amigaos*)
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_minus_L=yes
-      # Samuel A. Falvo II <address@hidden> reports
-      # that the semantics of dynamic libraries on AmigaOS, at least up
-      # to version 4, is to share data among multiple programs linked
-      # with the same dynamic library.  Since this doesn't match the
-      # behavior of shared libraries on other platforms, we cannot use
-      # them.
-      ld_shlibs=no
+      case "$host_cpu" in
+        powerpc)
+          ;;
+        m68k)
+          hardcode_libdir_flag_spec='-L$libdir'
+          hardcode_minus_L=yes
+          ;;
+      esac
       ;;
     beos*)
       if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
@@ -182,7 +198,7 @@ if test "$with_gnu_ld" = yes; then
         ld_shlibs=no
       fi
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | mingw* | pw32* | cegcc*)
       # hardcode_libdir_flag_spec is actually meaningless, as there is
       # no search path for DLLs.
       hardcode_libdir_flag_spec='-L$libdir'
@@ -192,11 +208,13 @@ if test "$with_gnu_ld" = yes; then
         ld_shlibs=no
       fi
       ;;
+    haiku*)
+      ;;
     interix[3-9]*)
       hardcode_direct=no
       hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
       ;;
-    gnu* | linux* | k*bsd*-gnu)
+    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
       if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
         :
       else
@@ -254,7 +272,7 @@ else
         hardcode_direct=unsupported
       fi
       ;;
-    aix4* | aix5*)
+    aix[4-9]*)
       if test "$host_cpu" = ia64; then
         # On IA64, the linker does run time linking by default, so we don't
         # have to do anything special.
@@ -264,7 +282,7 @@ else
         # Test if we are trying to use run time linking or normal
         # AIX style linking. If -brtl is somewhere in LDFLAGS, we
         # need to do runtime linking.
-        case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+        case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
           for ld_flag in $LDFLAGS; do
             if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
               aix_use_runtimelinking=yes
@@ -319,14 +337,18 @@ else
       fi
       ;;
     amigaos*)
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_minus_L=yes
-      # see comment about different semantics on the GNU ld section
-      ld_shlibs=no
+      case "$host_cpu" in
+        powerpc)
+          ;;
+        m68k)
+          hardcode_libdir_flag_spec='-L$libdir'
+          hardcode_minus_L=yes
+          ;;
+      esac
       ;;
     bsdi[45]*)
       ;;
-    cygwin* | mingw* | pw32*)
+    cygwin* | mingw* | pw32* | cegcc*)
       # When not using gcc, we currently assume that we are using
       # Microsoft Visual C++.
       # hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -336,24 +358,15 @@ else
       ;;
     darwin* | rhapsody*)
       hardcode_direct=no
-      if test "$GCC" = yes ; then
+      if { case $cc_basename in ifort*) true;; *) test "$GCC" = yes;; esac; }; 
then
         :
       else
-        case $cc_basename in
-          xlc*)
-            ;;
-          *)
-            ld_shlibs=no
-            ;;
-        esac
+        ld_shlibs=no
       fi
       ;;
     dgux*)
       hardcode_libdir_flag_spec='-L$libdir'
       ;;
-    freebsd1*)
-      ld_shlibs=no
-      ;;
     freebsd2.2*)
       hardcode_libdir_flag_spec='-R$libdir'
       hardcode_direct=yes
@@ -414,6 +427,8 @@ else
       hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
       hardcode_libdir_separator=:
       ;;
+    *nto* | *qnx*)
+      ;;
     openbsd*)
       if test -f /usr/libexec/ld.so; then
         hardcode_direct=yes
@@ -494,7 +509,7 @@ else
 fi
 
 # Check dynamic linker characteristics
-# Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER.
+# Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER.
 # Unlike libtool.m4, here we don't care about _all_ names of the library, but
 # only about the one the linker finds when passed -lNAME. This is the last
 # element of library_names_spec in libtool.m4, or possibly two of them if the
@@ -505,11 +520,16 @@ case "$host_os" in
   aix3*)
     library_names_spec='$libname.a'
     ;;
-  aix4* | aix5*)
+  aix[4-9]*)
     library_names_spec='$libname$shrext'
     ;;
   amigaos*)
-    library_names_spec='$libname.a'
+    case "$host_cpu" in
+      powerpc*)
+        library_names_spec='$libname$shrext' ;;
+      m68k)
+        library_names_spec='$libname.a' ;;
+    esac
     ;;
   beos*)
     library_names_spec='$libname$shrext'
@@ -517,7 +537,7 @@ case "$host_os" in
   bsdi[45]*)
     library_names_spec='$libname$shrext'
     ;;
-  cygwin* | mingw* | pw32*)
+  cygwin* | mingw* | pw32* | cegcc*)
     shrext=.dll
     library_names_spec='$libname.dll.a $libname.lib'
     ;;
@@ -528,8 +548,6 @@ case "$host_os" in
   dgux*)
     library_names_spec='$libname$shrext'
     ;;
-  freebsd1*)
-    ;;
   freebsd* | dragonfly*)
     case "$host_os" in
       freebsd[123]*)
@@ -541,6 +559,9 @@ case "$host_os" in
   gnu*)
     library_names_spec='$libname$shrext'
     ;;
+  haiku*)
+    library_names_spec='$libname$shrext'
+    ;;
   hpux9* | hpux10* | hpux11*)
     case $host_cpu in
       ia64*)
@@ -576,7 +597,7 @@ case "$host_os" in
     ;;
   linux*oldld* | linux*aout* | linux*coff*)
     ;;
-  linux* | k*bsd*-gnu)
+  linux* | k*bsd*-gnu | kopensolaris*-gnu)
     library_names_spec='$libname$shrext'
     ;;
   knetbsd*-gnu)
@@ -588,7 +609,7 @@ case "$host_os" in
   newsos6)
     library_names_spec='$libname$shrext'
     ;;
-  nto-qnx*)
+  *nto* | *qnx*)
     library_names_spec='$libname$shrext'
     ;;
   openbsd*)
@@ -619,6 +640,9 @@ case "$host_os" in
   sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
     library_names_spec='$libname$shrext'
     ;;
+  tpf*)
+    library_names_spec='$libname$shrext'
+    ;;
   uts4*)
     library_names_spec='$libname$shrext'
     ;;
diff --git a/build-aux/snippet/_Noreturn.h b/lib/build-aux/snippet/_Noreturn.h
similarity index 100%
copy from build-aux/snippet/_Noreturn.h
copy to lib/build-aux/snippet/_Noreturn.h
diff --git a/build-aux/arg-nonnull.h b/lib/build-aux/snippet/arg-nonnull.h
similarity index 100%
rename from build-aux/arg-nonnull.h
rename to lib/build-aux/snippet/arg-nonnull.h
diff --git a/build-aux/c++defs.h b/lib/build-aux/snippet/c++defs.h
similarity index 100%
rename from build-aux/c++defs.h
rename to lib/build-aux/snippet/c++defs.h
diff --git a/build-aux/warn-on-use.h b/lib/build-aux/snippet/warn-on-use.h
similarity index 100%
rename from build-aux/warn-on-use.h
rename to lib/build-aux/snippet/warn-on-use.h
diff --git a/lib/ext_session_ticket.c b/lib/ext_session_ticket.c
index b2bf933..b6ca2ba 100644
--- a/lib/ext_session_ticket.c
+++ b/lib/ext_session_ticket.c
@@ -697,7 +697,6 @@ _gnutls_recv_new_session_ticket (gnutls_session_t session)
 {
   uint8_t *data = NULL, *p;
   int data_size;
-  uint32_t lifetime_hint;
   uint16_t ticket_len;
   int ret;
   session_ticket_ext_st *priv = NULL;
@@ -727,7 +726,7 @@ _gnutls_recv_new_session_ticket (gnutls_session_t session)
 
   p = data;
   DECR_LENGTH_COM (data_size, 4, goto error);
-  lifetime_hint = _gnutls_read_uint32 (p);
+  _gnutls_read_uint32 (p);
   p += 4;
 
   DECR_LENGTH_COM (data_size, 2, goto error);
diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am
index e48d3bc..80e4406 100644
--- a/lib/gl/Makefile.am
+++ b/lib/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.
@@ -158,6 +170,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 $@
@@ -167,9 +180,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_liblgnu_la_SOURCES += float.c
+EXTRA_liblgnu_la_SOURCES += float.c itold.c
 
 ## end   gnulib module float
 
@@ -191,6 +204,15 @@ EXTRA_liblgnu_la_SOURCES += fseeko.c
 
 ## end   gnulib module fseeko
 
+## begin gnulib module fstat
+
+
+EXTRA_DIST += fstat.c
+
+EXTRA_liblgnu_la_SOURCES += fstat.c
+
+## end   gnulib module fstat
+
 ## begin gnulib module ftell
 
 
@@ -280,6 +302,24 @@ liblgnu_la_SOURCES += minmax.h
 
 ## end   gnulib module minmax
 
+## begin gnulib module msvc-inval
+
+
+EXTRA_DIST += msvc-inval.c msvc-inval.h
+
+EXTRA_liblgnu_la_SOURCES += msvc-inval.c
+
+## end   gnulib module msvc-inval
+
+## begin gnulib module msvc-nothrow
+
+
+EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h
+
+EXTRA_liblgnu_la_SOURCES += msvc-nothrow.c
+
+## end   gnulib module msvc-nothrow
+
 ## begin gnulib module netdb
 
 BUILT_SOURCES += netdb.h
@@ -554,6 +594,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' \
@@ -578,6 +619,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's/@''GNULIB_GETS''@/$(GNULIB_GETS)/g' \
              -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \
              -e 
's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \
              -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \
              -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \
              -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \
@@ -616,11 +658,14 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
              -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \
              -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|g' \
+             -e 's|@''HAVE_PCLOSE''@|$(HAVE_PCLOSE)|g' \
+             -e 's|@''HAVE_POPEN''@|$(HAVE_POPEN)|g' \
              -e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \
              -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
              -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' \
@@ -873,6 +918,7 @@ strings.h: strings.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(WARN_ON_USE
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
          sed -e 's|@''GUARD_PREFIX''@|GL_LGL|g' \
+             -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
@@ -969,6 +1015,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' \
@@ -1013,6 +1060,30 @@ EXTRA_DIST += sys_stat.in.h
 
 ## end   gnulib module sys_stat
 
+## begin gnulib module sys_types
+
+BUILT_SOURCES += sys/types.h
+
+# We need the following in order to create <sys/types.h> when the system
+# doesn't have one that works with the given compiler.
+sys/types.h: sys_types.in.h $(top_builddir)/config.status
+       $(AM_V_at)$(MKDIR_P) sys
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL_LGL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \
+             < $(srcdir)/sys_types.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += sys/types.h sys/types.h-t
+
+EXTRA_DIST += sys_types.in.h
+
+## end   gnulib module sys_types
+
 ## begin gnulib module sys_uio
 
 BUILT_SOURCES += sys/uio.h
@@ -1105,8 +1176,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' \
@@ -1114,6 +1187,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \
              -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \
              -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \
+             -e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \
              -e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \
              -e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \
              -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \
@@ -1157,6 +1231,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
              -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
              -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
+             -e 's|@''HAVE_FDATASYNC''@|$(HAVE_FDATASYNC)|g' \
              -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
              -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
              -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
@@ -1181,6 +1256,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
              -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
              -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
+             -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
              -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' 
\
              -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
              -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
diff --git a/lib/gl/float.c b/lib/gl/float.c
index 5fc47d0..700bee9 100644
--- a/lib/gl/float.c
+++ b/lib/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/lib/gl/float.in.h b/lib/gl/float.in.h
index a296a9e..824035a 100644
--- a/lib/gl/float.in.h
+++ b/lib/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/lib/gl/fstat.c b/lib/gl/fstat.c
new file mode 100644
index 0000000..7f09c80
--- /dev/null
+++ b/lib/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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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/lib/gl/itold.c b/lib/gl/itold.c
new file mode 100644
index 0000000..ebadae3
--- /dev/null
+++ b/lib/gl/itold.c
@@ -0,0 +1,28 @@
+/* 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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <float.h>
+
+void
+_Qp_itoq (long double *result, int a)
+{
+  /* Convert from 'int' to 'double', then from 'double' to 'long double'.  */
+  *result = (double) a;
+}
diff --git a/lib/gl/lseek.c b/lib/gl/lseek.c
index bcaffe2..b149257 100644
--- a/lib/gl/lseek.c
+++ b/lib/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/lib/gl/m4/fcntl-o.m4 b/lib/gl/m4/fcntl-o.m4
index 88db07e..bee6edc 100644
--- a/lib/gl/m4/fcntl-o.m4
+++ b/lib/gl/m4/fcntl-o.m4
@@ -1,4 +1,4 @@
-# fcntl-o.m4 serial 3
+# fcntl-o.m4 serial 4
 dnl Copyright (C) 2006, 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,
@@ -17,12 +17,21 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
   m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
     [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
     [AC_REQUIRE([AC_GNU_SOURCE])])
+
+  AC_CHECK_HEADERS_ONCE([unistd.h])
+  AC_CHECK_FUNCS_ONCE([symlink])
   AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <sys/types.h>
            #include <sys/stat.h>
-           #include <unistd.h>
+           #if HAVE_UNISTD_H
+           # include <unistd.h>
+           #else /* on Windows with MSVC */
+           # include <io.h>
+           # include <stdlib.h>
+           # defined sleep(n) _sleep ((n) * 1000)
+           #endif
            #include <fcntl.h>
            #ifndef O_NOATIME
             #define O_NOATIME 0
@@ -38,6 +47,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
           ]],
           [[
             int result = !constants;
+            #if HAVE_SYMLINK
             {
               static char const sym[] = "conftest.sym";
               if (symlink (".", sym) != 0)
@@ -53,6 +63,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
                 }
               unlink (sym);
             }
+            #endif
             {
               static char const file[] = "confdefs.h";
               int fd = open (file, O_RDONLY | O_NOATIME);
diff --git a/lib/gl/m4/fcntl_h.m4 b/lib/gl/m4/fcntl_h.m4
index c466da4..03a41e6 100644
--- a/lib/gl/m4/fcntl_h.m4
+++ b/lib/gl/m4/fcntl_h.m4
@@ -1,4 +1,4 @@
-# serial 13
+# serial 15
 # Configure fcntl.h.
 dnl Copyright (C) 2006-2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -13,6 +13,12 @@ AC_DEFUN([gl_FCNTL_H],
   AC_REQUIRE([gl_FCNTL_O_FLAGS])
   gl_NEXT_HEADERS([fcntl.h])
 
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use, if it is not common
   dnl enough to be declared everywhere.
diff --git a/lib/gl/m4/fdopen.m4 b/lib/gl/m4/fdopen.m4
new file mode 100644
index 0000000..8cae2fc
--- /dev/null
+++ b/lib/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/lib/gl/m4/float_h.m4 b/lib/gl/m4/float_h.m4
index 261f1ac..0420e06 100644
--- a/lib/gl/m4/float_h.m4
+++ b/lib/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/lib/gl/m4/fstat.m4 b/lib/gl/m4/fstat.m4
new file mode 100644
index 0000000..0daea88
--- /dev/null
+++ b/lib/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/lib/gl/m4/gnulib-cache.m4 b/lib/gl/m4/gnulib-cache.m4
index 801706d..28cf687 100644
--- a/lib/gl/m4/gnulib-cache.m4
+++ b/lib/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/lib/gl/m4/gnulib-common.m4 b/lib/gl/m4/gnulib-common.m4
index 9dc8fbe..7d83299 100644
--- a/lib/gl/m4/gnulib-common.m4
+++ b/lib/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 29
+# 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,8 +211,33 @@ 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
+# the values.
 AC_DEFUN([gl_PROG_AR_RANLIB],
 [
   dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
@@ -220,24 +245,47 @@ AC_DEFUN([gl_PROG_AR_RANLIB],
   dnl library formats. In particular, the GNU binutils programs ar, ranlib
   dnl produce libraries that work only with gcc, not with cc.
   AC_REQUIRE([AC_PROG_CC])
-  AC_EGREP_CPP([Amsterdam],
+  AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
     [
+      AC_EGREP_CPP([Amsterdam],
+        [
 #ifdef __ACK__
 Amsterdam
 #endif
-    ],
-    [AR='cc -c.a'
-     ARFLAGS='-o'
-     RANLIB=':'
-    ],
-    [dnl Use the Automake-documented default values for AR and ARFLAGS.
-     AR='ar'
-     ARFLAGS='cru'
-     dnl Use the ranlib program if it is available.
-     AC_PROG_RANLIB
+        ],
+        [gl_cv_c_amsterdam_compiler=yes],
+        [gl_cv_c_amsterdam_compiler=no])
     ])
+  if test -z "$AR"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      AR='cc -c.a'
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='-o'
+      fi
+    else
+      dnl Use the Automake-documented default values for AR and ARFLAGS,
+      dnl but prefer ${host}-ar over ar (useful for cross-compiling).
+      AC_CHECK_TOOL([AR], [ar], [ar])
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='cru'
+      fi
+    fi
+  else
+    if test -z "$ARFLAGS"; then
+      ARFLAGS='cru'
+    fi
+  fi
   AC_SUBST([AR])
   AC_SUBST([ARFLAGS])
+  if test -z "$RANLIB"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      RANLIB=':'
+    else
+      dnl Use the ranlib program if it is available.
+      AC_PROG_RANLIB
+    fi
+  fi
+  AC_SUBST([RANLIB])
 ])
 
 # AC_PROG_MKDIR_P
diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4
index eed49ba..bcee3b7 100644
--- a/lib/gl/m4/gnulib-comp.m4
+++ b/lib/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.
@@ -42,16 +54,23 @@ AC_DEFUN([lgl_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 float:
   # Code from module float-tests:
   # 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 fseek:
   # Code from module fseek-tests:
   # Code from module fseeko:
   AC_REQUIRE([AC_FUNC_FSEEKO])
   # Code from module fseeko-tests:
+  # Code from module fstat:
+  # Code from module fstat-tests:
   # Code from module ftell:
   # Code from module ftell-tests:
   # Code from module ftello:
@@ -59,6 +78,7 @@ AC_DEFUN([lgl_EARLY],
   # Code from module ftello-tests:
   # Code from module func:
   # Code from module func-tests:
+  # Code from module fwrite-tests:
   # Code from module getpagesize:
   # Code from module gettext:
   # Code from module gettext-h:
@@ -79,6 +99,8 @@ AC_DEFUN([lgl_EARLY],
   # Code from module memchr-tests:
   # Code from module memmem-simple:
   # 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:
@@ -96,6 +118,7 @@ AC_DEFUN([lgl_EARLY],
   # Code from module sockets:
   # Code from module sockets-tests:
   # Code from module socklen:
+  # Code from module ssize_t:
   # Code from module stdbool:
   # Code from module stdbool-tests:
   # Code from module stddef:
@@ -117,6 +140,8 @@ AC_DEFUN([lgl_EARLY],
   # Code from module sys_socket-tests:
   # Code from module sys_stat:
   # Code from module sys_stat-tests:
+  # Code from module sys_types:
+  # Code from module sys_types-tests:
   # Code from module sys_uio:
   # Code from module sys_uio-tests:
   # Code from module time:
@@ -158,6 +183,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_FSEEK
 if test $REPLACE_FSEEK = 1; then
   AC_LIBOBJ([fseek])
@@ -168,6 +196,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])
@@ -207,6 +241,14 @@ if test $HAVE_MEMMEM = 0 || test $REPLACE_MEMMEM = 1; then
 fi
 gl_STRING_MODULE_INDICATOR([memmem])
 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_PREREQ_READ_FILE
@@ -222,6 +264,7 @@ gl_MODULE_INDICATOR([snprintf])
 gl_SOCKETLIB
 gl_SOCKETS
 gl_TYPE_SOCKLEN_T
+gt_TYPE_SSIZE_T
 AM_STDBOOL_H
 gl_STDDEF_H
 gl_STDINT_H
@@ -248,6 +291,8 @@ gl_HEADER_SYS_SOCKET
 AC_PROG_MKDIR_P
 gl_HEADER_SYS_STAT_H
 AC_PROG_MKDIR_P
+gl_SYS_TYPES_H
+AC_PROG_MKDIR_P
 gl_HEADER_SYS_UIO
 AC_PROG_MKDIR_P
 gl_HEADER_TIME_H
@@ -315,6 +360,12 @@ changequote([, ])dnl
   gl_module_indicator_condition=$lgltests_WITNESS
   m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition])
 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
@@ -445,15 +496,21 @@ AC_DEFUN([lgl_FILE_LIST], [
   lib/float.in.h
   lib/fseek.c
   lib/fseeko.c
+  lib/fstat.c
   lib/ftell.c
   lib/ftello.c
   lib/gettext.h
+  lib/itold.c
   lib/lseek.c
   lib/malloc.c
   lib/memchr.c
   lib/memchr.valgrind
   lib/memmem.c
   lib/minmax.h
+  lib/msvc-inval.c
+  lib/msvc-inval.h
+  lib/msvc-nothrow.c
+  lib/msvc-nothrow.h
   lib/netdb.in.h
   lib/printf-args.c
   lib/printf-args.h
@@ -480,6 +537,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   lib/strverscmp.c
   lib/sys_socket.in.h
   lib/sys_stat.in.h
+  lib/sys_types.in.h
   lib/sys_uio.in.h
   lib/time.in.h
   lib/time_r.c
@@ -500,10 +558,12 @@ AC_DEFUN([lgl_FILE_LIST], [
   m4/extensions.m4
   m4/fcntl-o.m4
   m4/fcntl_h.m4
+  m4/fdopen.m4
   m4/float_h.m4
   m4/fpieee.m4
   m4/fseek.m4
   m4/fseeko.m4
+  m4/fstat.m4
   m4/ftell.m4
   m4/ftello.m4
   m4/func.m4
@@ -538,6 +598,8 @@ AC_DEFUN([lgl_FILE_LIST], [
   m4/memmem.m4
   m4/minmax.m4
   m4/mmap-anon.m4
+  m4/msvc-inval.m4
+  m4/msvc-nothrow.m4
   m4/multiarch.m4
   m4/netdb_h.m4
   m4/nls.m4
@@ -553,6 +615,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   m4/sockets.m4
   m4/socklen.m4
   m4/sockpfaf.m4
+  m4/ssize_t.m4
   m4/stdbool.m4
   m4/stddef_h.m4
   m4/stdint.m4
@@ -565,6 +628,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   m4/strverscmp.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
+  m4/sys_types_h.m4
   m4/sys_uio_h.m4
   m4/threadlib.m4
   m4/time_h.m4
@@ -591,7 +655,11 @@ AC_DEFUN([lgl_FILE_LIST], [
   tests/test-c-ctype.c
   tests/test-errno.c
   tests/test-fcntl-h.c
+  tests/test-fdopen.c
+  tests/test-fgetc.c
   tests/test-float.c
+  tests/test-fputc.c
+  tests/test-fread.c
   tests/test-fseek.c
   tests/test-fseek.sh
   tests/test-fseek2.sh
@@ -600,6 +668,9 @@ AC_DEFUN([lgl_FILE_LIST], [
   tests/test-fseeko2.sh
   tests/test-fseeko3.c
   tests/test-fseeko3.sh
+  tests/test-fseeko4.c
+  tests/test-fseeko4.sh
+  tests/test-fstat.c
   tests/test-ftell.c
   tests/test-ftell.sh
   tests/test-ftell2.sh
@@ -608,7 +679,10 @@ AC_DEFUN([lgl_FILE_LIST], [
   tests/test-ftello.sh
   tests/test-ftello2.sh
   tests/test-ftello3.c
+  tests/test-ftello4.c
+  tests/test-ftello4.sh
   tests/test-func.c
+  tests/test-fwrite.c
   tests/test-intprops.c
   tests/test-inttypes.c
   tests/test-memchr.c
@@ -626,6 +700,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   tests/test-strverscmp.c
   tests/test-sys_socket.c
   tests/test-sys_stat.c
+  tests/test-sys_types.c
   tests/test-sys_uio.c
   tests/test-sys_wait.h
   tests/test-time.c
@@ -640,6 +715,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   tests=lib/binary-io.h
   tests=lib/dummy.c
   tests=lib/fcntl.in.h
+  tests=lib/fdopen.c
   tests=lib/fpucw.h
   tests=lib/getpagesize.c
   tests=lib/intprops.h
diff --git a/lib/gl/m4/iconv.m4 b/lib/gl/m4/iconv.m4
index 085cd06..98fcd64 100644
--- a/lib/gl/m4/iconv.m4
+++ b/lib/gl/m4/iconv.m4
@@ -1,4 +1,4 @@
-# iconv.m4 serial 17 (gettext-0.18.2)
+# iconv.m4 serial 18 (gettext-0.18.2)
 dnl Copyright (C) 2000-2002, 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,
@@ -242,7 +242,7 @@ extern
 #ifdef __cplusplus
 "C"
 #endif
-#if defined(__STDC__) || defined(__cplusplus)
+#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, 
size_t *outbytesleft);
 #else
 size_t iconv();
diff --git a/lib/gl/m4/include_next.m4 b/lib/gl/m4/include_next.m4
index ebf081a..d5230ce 100644
--- a/lib/gl/m4/include_next.m4
+++ b/lib/gl/m4/include_next.m4
@@ -1,4 +1,4 @@
-# include_next.m4 serial 20
+# include_next.m4 serial 22
 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,
@@ -207,17 +207,36 @@ dnl until we can assume autoconf 2.64 or newer.
                  aix*) gl_absname_cpp="$ac_cpp -C" ;;
                  *)    gl_absname_cpp="$ac_cpp" ;;
                esac
+changequote(,)
+               case "$host_os" in
+                 mingw*)
+                   dnl For the sake of native Windows compilers (excluding 
gcc),
+                   dnl treat backslash as a directory separator, like /.
+                   dnl Actually, these compilers use a double-backslash as
+                   dnl directory separator, inside the
+                   dnl   # line "filename"
+                   dnl directives.
+                   gl_dirsep_regex='[/\\]'
+                   ;;
+                 *)
+                   gl_dirsep_regex='/'
+                   ;;
+               esac
+changequote([,])
+               
gl_absolute_header_sed='\|'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[|{
+                   
s|.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*|\1|
+changequote(,)dnl
+                   s|^/[^/]|//&|
+changequote([,])dnl
+                   p
+                   q
+                 }'
                dnl eval is necessary to expand gl_absname_cpp.
                dnl Ultrix and Pyramid sh refuse to redirect output of eval,
                dnl so use subshell.
                AS_VAR_SET(gl_next_header,
                  ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 
2>&AS_MESSAGE_LOG_FD |
-                  sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
-                    s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
-                    s#^/[^/]#//&#
-                    p
-                    q
-                  }'`'"'])
+                      sed -n "$gl_absolute_header_sed"`'"'])
           m4_if([$2], [check],
             [else
                AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>'])
diff --git a/lib/gl/m4/largefile.m4 b/lib/gl/m4/largefile.m4
index 6986244..d83fea1 100644
--- a/lib/gl/m4/largefile.m4
+++ b/lib/gl/m4/largefile.m4
@@ -19,8 +19,8 @@ m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
     incorrectly reject 9223372036854775807.  */
 @%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
   int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
-                      && LARGE_OFF_T % 2147483647 == 1)
-                     ? 1 : -1]];[]dnl
+                       && LARGE_OFF_T % 2147483647 == 1)
+                      ? 1 : -1]];[]dnl
 ])
 
 
@@ -58,7 +58,7 @@ rm -rf conftest*[]dnl
 # http://www.unix-systems.org/version2/whatsnew/lfs20mar.html
 AC_DEFUN([AC_SYS_LARGEFILE],
 [AC_ARG_ENABLE(largefile,
-              [  --disable-largefile     omit support for large files])
+               [  --disable-largefile     omit support for large files])
 if test "$enable_largefile" != no; then
 
   AC_CACHE_CHECK([for special C compiler options needed for large files],
@@ -67,13 +67,13 @@ if test "$enable_largefile" != no; then
      if test "$GCC" != yes; then
        ac_save_CC=$CC
        while :; do
-        # IRIX 6.2 and later do not support large files by default,
-        # so use the C compiler's -n32 option if that helps.
-        AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
-        AC_COMPILE_IFELSE([], [break])
-        CC="$CC -n32"
-        AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
-        break
+         # IRIX 6.2 and later do not support large files by default,
+         # so use the C compiler's -n32 option if that helps.
+         AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
+         AC_COMPILE_IFELSE([], [break])
+         CC="$CC -n32"
+         AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
+         break
        done
        CC=$ac_save_CC
        rm -f conftest.$ac_ext
diff --git a/lib/gl/m4/lseek.m4 b/lib/gl/m4/lseek.m4
index b454884..73c4069 100644
--- a/lib/gl/m4/lseek.m4
+++ b/lib/gl/m4/lseek.m4
@@ -1,4 +1,4 @@
-# lseek.m4 serial 7
+# lseek.m4 serial 8
 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,
@@ -8,12 +8,18 @@ AC_DEFUN([gl_FUNC_LSEEK],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([AC_PROG_CC])
+  AC_CHECK_HEADERS_ONCE([unistd.h])
   AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
     [if test $cross_compiling = no; then
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/types.h> /* for off_t */
 #include <stdio.h> /* for SEEK_CUR */
-#include <unistd.h>]], [[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else /* on Windows with MSVC */
+# include <io.h>
+#endif
+]], [[
   /* Exit with success only if stdin is seekable.  */
   return lseek (0, (off_t)0, SEEK_CUR) < 0;
 ]])],
diff --git a/lib/gl/m4/msvc-inval.m4 b/lib/gl/m4/msvc-inval.m4
new file mode 100644
index 0000000..fb797f0
--- /dev/null
+++ b/lib/gl/m4/msvc-inval.m4
@@ -0,0 +1,19 @@
+# msvc-inval.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_MSVC_INVAL],
+[
+  AC_CHECK_FUNCS_ONCE([_set_invalid_parameter_handler])
+  if test $ac_cv_func__set_invalid_parameter_handler = yes; then
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
+    AC_DEFINE([HAVE_MSVC_INVALID_PARAMETER_HANDLER], [1],
+      [Define to 1 on MSVC platforms that have the "invalid parameter handler"
+       concept.])
+  else
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
+  fi
+  AC_SUBST([HAVE_MSVC_INVALID_PARAMETER_HANDLER])
+])
diff --git a/lib/gl/m4/msvc-nothrow.m4 b/lib/gl/m4/msvc-nothrow.m4
new file mode 100644
index 0000000..b2f6bb4
--- /dev/null
+++ b/lib/gl/m4/msvc-nothrow.m4
@@ -0,0 +1,10 @@
+# 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_MSVC_NOTHROW],
+[
+  AC_REQUIRE([gl_MSVC_INVAL])
+])
diff --git a/lib/gl/m4/printf.m4 b/lib/gl/m4/printf.m4
index 1538d23..d046c11 100644
--- a/lib/gl/m4/printf.m4
+++ b/lib/gl/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 43
+# printf.m4 serial 45
 dnl Copyright (C) 2003, 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,
@@ -178,28 +178,28 @@ static double zero = 0.0;
 int main ()
 {
   int result = 0;
-  if (sprintf (buf, "%f", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%f", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%f", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%f", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%f", zero / zero) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 2;
-  if (sprintf (buf, "%e", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%e", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 4;
-  if (sprintf (buf, "%e", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%e", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 4;
   if (sprintf (buf, "%e", zero / zero) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 8;
-  if (sprintf (buf, "%g", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%g", 1.0 / zero) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 16;
-  if (sprintf (buf, "%g", -1.0 / 0.0) < 0
+  if (sprintf (buf, "%g", -1.0 / zero) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 16;
   if (sprintf (buf, "%g", zero / zero) < 0
@@ -294,28 +294,28 @@ int main ()
 {
   int result = 0;
   nocrash_init();
-  if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 1;
-  if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Le", zeroL / zeroL) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 1;
-  if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
     result |= 1;
-  if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
+  if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
     result |= 1;
   if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
@@ -478,6 +478,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
   int result = 0;
@@ -502,7 +503,7 @@ int main ()
     result |= 4;
   /* This catches a FreeBSD 6.1 bug.  See
      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
-  if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
+  if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
       || buf[0] == '0')
     result |= 8;
   /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug.  */
@@ -562,13 +563,14 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
   int result = 0;
   if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
       || strcmp (buf, "1234567.000000 33") != 0)
     result |= 1;
-  if (sprintf (buf, "%F", 1.0 / 0.0) < 0
+  if (sprintf (buf, "%F", 1.0 / zero) < 0
       || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
     result |= 2;
   /* This catches a Cygwin 1.5.x bug.  */
@@ -615,12 +617,27 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#ifdef _MSC_VER
+/* See page about "Parameter Validation" on msdn.microsoft.com.  */
+static void cdecl
+invalid_parameter_handler (const wchar_t *expression,
+                           const wchar_t *function,
+                           const wchar_t *file, unsigned int line,
+                           uintptr_t dummy)
+{
+  exit (1);
+}
+#endif
 static char fmtstring[10];
 static char buf[100];
 int main ()
 {
   int count = -1;
+#ifdef _MSC_VER
+  _set_invalid_parameter_handler (invalid_parameter_handler);
+#endif
   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
      support %n in format strings in read-only memory but not in writable
      memory.  */
@@ -636,7 +653,8 @@ int main ()
         [
 changequote(,)dnl
          case "$host_os" in
-           *)     gl_cv_func_printf_directive_n="guessing yes";;
+           mingw*) gl_cv_func_printf_directive_n="guessing no";;
+           *)      gl_cv_func_printf_directive_n="guessing yes";;
          esac
 changequote([,])dnl
         ])
@@ -862,9 +880,10 @@ AC_DEFUN([gl_PRINTF_FLAG_ZERO],
 #include <stdio.h>
 #include <string.h>
 static char buf[100];
+static double zero = 0.0;
 int main ()
 {
-  if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
+  if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
       || (strcmp (buf, "       inf") != 0
           && strcmp (buf, "  infinity") != 0))
     return 1;
@@ -1076,6 +1095,7 @@ AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
     [gl_cv_func_snprintf_truncation_c99],
     [
@@ -1083,11 +1103,25 @@ AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char buf[100];
 int main ()
 {
   strcpy (buf, "ABCDEF");
-  snprintf (buf, 3, "%d %d", 4567, 89);
+  my_snprintf (buf, 3, "%d %d", 4567, 89);
   if (memcmp (buf, "45\0DEF", 6) != 0)
     return 1;
   return 0;
@@ -1157,6 +1191,7 @@ AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
     [gl_cv_func_snprintf_retval_c99],
     [
@@ -1164,15 +1199,29 @@ AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char buf[100];
 int main ()
 {
   strcpy (buf, "ABCDEF");
-  if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
     return 1;
-  if (snprintf (buf, 0, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
     return 2;
-  if (snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
+  if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
     return 3;
   return 0;
 }]])],
@@ -1221,6 +1270,7 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
     [gl_cv_func_snprintf_directive_n],
     [
@@ -1228,6 +1278,20 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
         [AC_LANG_SOURCE([[
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 static char fmtstring[10];
 static char buf[100];
 int main ()
@@ -1237,7 +1301,7 @@ int main ()
      support %n in format strings in read-only memory but not in writable
      memory.  */
   strcpy (fmtstring, "%d %n");
-  snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
+  my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
   if (count != 6)
     return 1;
   return 0;
@@ -1289,16 +1353,31 @@ dnl Result is gl_cv_func_snprintf_size1.
 AC_DEFUN([gl_SNPRINTF_SIZE1],
 [
   AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
   AC_CACHE_CHECK([whether snprintf respects a size of 1],
     [gl_cv_func_snprintf_size1],
     [
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
 #include <stdio.h>
+#if HAVE_SNPRINTF
+# define my_snprintf snprintf
+#else
+# include <stdarg.h>
+static int my_snprintf (char *buf, int size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+  va_start (args, format);
+  ret = vsnprintf (buf, size, format, args);
+  va_end (args);
+  return ret;
+}
+#endif
 int main()
 {
   static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
-  snprintf (buf, 1, "%d", 12345);
+  my_snprintf (buf, 1, "%d", 12345);
   return buf[1] != 'E';
 }]])],
         [gl_cv_func_snprintf_size1=yes],
@@ -1484,5 +1563,6 @@ dnl   NetBSD 3.0                     .  .  .  .  #  #  .  
?  #  #  ?  #  .  #  .
 dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  
.  .  ?  .  .  .
 dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  
.  .  ?  .  .  .
 dnl   old mingw / msvcrt             #  #  #  #  #  #  .  .  #  #  .  #  #  ?  
.  #  #  #  .  .
+dnl   MSVC 9                         #  #  #  #  #  #  #  .  #  #  .  #  #  ?  
#  #  #  #  .  .
 dnl   mingw 2009-2011                .  #  .  #  .  .  .  .  #  #  .  .  .  ?  
.  .  .  .  .  .
 dnl   mingw-w64 2011                 #  #  #  #  #  #  .  .  #  #  .  #  #  ?  
.  #  #  #  .  .
diff --git a/lib/gl/m4/ssize_t.m4 b/lib/gl/m4/ssize_t.m4
new file mode 100644
index 0000000..d712752
--- /dev/null
+++ b/lib/gl/m4/ssize_t.m4
@@ -0,0 +1,23 @@
+# ssize_t.m4 serial 5 (gettext-0.18.2)
+dnl Copyright (C) 2001-2003, 2006, 2010-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.
+
+dnl From Bruno Haible.
+dnl Test whether ssize_t is defined.
+
+AC_DEFUN([gt_TYPE_SSIZE_T],
+[
+  AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <sys/types.h>]],
+          [[int x = sizeof (ssize_t *) + sizeof (ssize_t);
+            return !x;]])],
+       [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
+  if test $gt_cv_ssize_t = no; then
+    AC_DEFINE([ssize_t], [int],
+              [Define as a signed type of the same size as size_t.])
+  fi
+])
diff --git a/lib/gl/m4/stdint.m4 b/lib/gl/m4/stdint.m4
index c75e957..092161c 100644
--- a/lib/gl/m4/stdint.m4
+++ b/lib/gl/m4/stdint.m4
@@ -466,6 +466,14 @@ AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
   fi
   gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t],
     [gl_STDINT_INCLUDES])
+
+  dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99
+  dnl requirement that wint_t is "unchanged by default argument promotions".
+  dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
+  dnl Set the variable BITSIZEOF_WINT_T accordingly.
+  if test $BITSIZEOF_WINT_T -lt 32; then
+    BITSIZEOF_WINT_T=32
+  fi
 ])
 
 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
diff --git a/lib/gl/m4/stdio_h.m4 b/lib/gl/m4/stdio_h.m4
index a8326f3..39bf80e 100644
--- a/lib/gl/m4/stdio_h.m4
+++ b/lib/gl/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 37
+# 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,
@@ -74,7 +74,7 @@ AC_DEFUN([gl_STDIO_H],
   dnl corresponding gnulib module is not in use, and which is not
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
-    ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
+    ]], [dprintf fpurge fseeko ftello getdelim getline pclose popen renameat
     snprintf tmpfile vdprintf vsnprintf])
 ])
 
@@ -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])
@@ -115,6 +116,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_GETS=0;                 AC_SUBST([GNULIB_GETS])
   GNULIB_OBSTACK_PRINTF=0;       AC_SUBST([GNULIB_OBSTACK_PRINTF])
   GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
+  GNULIB_PCLOSE=0;               AC_SUBST([GNULIB_PCLOSE])
   GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
   GNULIB_POPEN=0;                AC_SUBST([GNULIB_POPEN])
   GNULIB_PRINTF=0;               AC_SUBST([GNULIB_PRINTF])
@@ -153,11 +155,14 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
   HAVE_FSEEKO=1;                 AC_SUBST([HAVE_FSEEKO])
   HAVE_FTELLO=1;                 AC_SUBST([HAVE_FTELLO])
+  HAVE_PCLOSE=1;                 AC_SUBST([HAVE_PCLOSE])
+  HAVE_POPEN=1;                  AC_SUBST([HAVE_POPEN])
   HAVE_RENAMEAT=1;               AC_SUBST([HAVE_RENAMEAT])
   HAVE_VASPRINTF=1;              AC_SUBST([HAVE_VASPRINTF])
   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/lib/gl/m4/strings_h.m4 b/lib/gl/m4/strings_h.m4
index 12ca5eb..481f8f3 100644
--- a/lib/gl/m4/strings_h.m4
+++ b/lib/gl/m4/strings_h.m4
@@ -1,5 +1,5 @@
 # Configure a replacement for <strings.h>.
-# serial 5
+# serial 6
 
 # Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -16,7 +16,14 @@ AC_DEFUN([gl_HEADER_STRINGS_H],
 AC_DEFUN([gl_HEADER_STRINGS_H_BODY],
 [
   AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
+
   gl_CHECK_NEXT_HEADERS([strings.h])
+  if test $ac_cv_header_strings_h = yes; then
+    HAVE_STRINGS_H=1
+  else
+    HAVE_STRINGS_H=0
+  fi
+  AC_SUBST([HAVE_STRINGS_H])
 
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
diff --git a/lib/gl/m4/sys_stat_h.m4 b/lib/gl/m4/sys_stat_h.m4
index fc41912..83ebac6 100644
--- a/lib/gl/m4/sys_stat_h.m4
+++ b/lib/gl/m4/sys_stat_h.m4
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 24   -*- 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,
@@ -19,6 +19,9 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
 
   gl_CHECK_NEXT_HEADERS([sys/stat.h])
 
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+
   dnl Define types that are supposed to be defined in <sys/types.h> or
   dnl <sys/stat.h>.
   AC_CHECK_TYPE([nlink_t], [],
@@ -30,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
 
@@ -47,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/lib/gl/m4/sys_types_h.m4 b/lib/gl/m4/sys_types_h.m4
new file mode 100644
index 0000000..62113df
--- /dev/null
+++ b/lib/gl/m4/sys_types_h.m4
@@ -0,0 +1,21 @@
+# sys_types_h.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_SYS_TYPES_H],
+[
+  AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
+  gl_NEXT_HEADERS([sys/types.h])
+
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  dnl Ensure the type mode_t gets defined.
+  AC_REQUIRE([AC_TYPE_MODE_T])
+])
+
+AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS],
+[
+])
diff --git a/lib/gl/m4/time_h.m4 b/lib/gl/m4/time_h.m4
index 615da1c..3454b23 100644
--- a/lib/gl/m4/time_h.m4
+++ b/lib/gl/m4/time_h.m4
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
 
-# serial 4
+# serial 6
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
diff --git a/lib/gl/m4/unistd_h.m4 b/lib/gl/m4/unistd_h.m4
index fb6fe07..57c8094 100644
--- a/lib/gl/m4/unistd_h.m4
+++ b/lib/gl/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 56
+# 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,
@@ -21,9 +21,15 @@ AC_DEFUN([gl_UNISTD_H],
   fi
   AC_SUBST([HAVE_UNISTD_H])
 
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
   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 <unistd.h>
+  gl_WARN_ON_USE_PREPARE([[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 /* Some systems declare various items in the wrong headers.  */
 #if !(defined __GLIBC__ && !defined __UCLIBC__)
 # include <fcntl.h>
@@ -33,8 +39,8 @@ AC_DEFUN([gl_UNISTD_H],
 #  include <io.h>
 # endif
 #endif
-    ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
-    fsync ftruncate getcwd getdomainname getdtablesize getgroups
+    ]], [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
     readlink readlinkat rmdir sleep symlink symlinkat ttyname_r unlink unlinkat
@@ -52,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])
@@ -61,6 +69,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_FACCESSAT=0;            AC_SUBST([GNULIB_FACCESSAT])
   GNULIB_FCHDIR=0;               AC_SUBST([GNULIB_FCHDIR])
   GNULIB_FCHOWNAT=0;             AC_SUBST([GNULIB_FCHOWNAT])
+  GNULIB_FDATASYNC=0;            AC_SUBST([GNULIB_FDATASYNC])
   GNULIB_FSYNC=0;                AC_SUBST([GNULIB_FSYNC])
   GNULIB_FTRUNCATE=0;            AC_SUBST([GNULIB_FTRUNCATE])
   GNULIB_GETCWD=0;               AC_SUBST([GNULIB_GETCWD])
@@ -104,6 +113,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_FACCESSAT=1;       AC_SUBST([HAVE_FACCESSAT])
   HAVE_FCHDIR=1;          AC_SUBST([HAVE_FCHDIR])
   HAVE_FCHOWNAT=1;        AC_SUBST([HAVE_FCHOWNAT])
+  HAVE_FDATASYNC=1;       AC_SUBST([HAVE_FDATASYNC])
   HAVE_FSYNC=1;           AC_SUBST([HAVE_FSYNC])
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
   HAVE_GETDTABLESIZE=1;   AC_SUBST([HAVE_GETDTABLESIZE])
@@ -128,6 +138,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_USLEEP=1;          AC_SUBST([HAVE_USLEEP])
   HAVE_DECL_ENVIRON=1;    AC_SUBST([HAVE_DECL_ENVIRON])
   HAVE_DECL_FCHDIR=1;     AC_SUBST([HAVE_DECL_FCHDIR])
+  HAVE_DECL_FDATASYNC=1;  AC_SUBST([HAVE_DECL_FDATASYNC])
   HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME])
   HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
   HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
diff --git a/lib/gl/m4/vasnprintf.m4 b/lib/gl/m4/vasnprintf.m4
index 32ea985..749d708 100644
--- a/lib/gl/m4/vasnprintf.m4
+++ b/lib/gl/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 32
+# vasnprintf.m4 serial 33
 dnl Copyright (C) 2002-2004, 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,
@@ -63,7 +63,7 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
   AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
   dnl Use the _snprintf function only if it is declared (because on NetBSD it
   dnl is defined as a weak alias of snprintf; we prefer to use the latter).
-  AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>])
+  AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
   dnl We can avoid a lot of code by assuming that snprintf's return value
   dnl conforms to ISO C99. So check that.
   AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
diff --git a/lib/gl/msvc-inval.c b/lib/gl/msvc-inval.c
new file mode 100644
index 0000000..e404ac4
--- /dev/null
+++ b/lib/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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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/lib/gl/msvc-inval.h b/lib/gl/msvc-inval.h
new file mode 100644
index 0000000..3fdb13b
--- /dev/null
+++ b/lib/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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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/lib/gl/msvc-nothrow.c b/lib/gl/msvc-nothrow.c
new file mode 100644
index 0000000..5ed55da
--- /dev/null
+++ b/lib/gl/msvc-nothrow.c
@@ -0,0 +1,50 @@
+/* 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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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-nothrow.h"
+
+/* Get declarations of the Win32 API functions.  */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "msvc-inval.h"
+
+#undef _get_osfhandle
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+intptr_t
+_gl_nothrow_get_osfhandle (int fd)
+{
+  intptr_t result;
+
+  TRY_MSVC_INVAL
+    {
+      result = _get_osfhandle (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = (intptr_t) INVALID_HANDLE_VALUE;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#endif
diff --git a/lib/gl/msvc-nothrow.h b/lib/gl/msvc-nothrow.h
new file mode 100644
index 0000000..123ded3
--- /dev/null
+++ b/lib/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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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/lib/gl/sockets.c b/lib/gl/sockets.c
index 64ddf89..a970bf6 100644
--- a/lib/gl/sockets.c
+++ b/lib/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/lib/gl/sockets.h b/lib/gl/sockets.h
index b071c3e..c4eefb0 100644
--- a/lib/gl/sockets.h
+++ b/lib/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/lib/gl/stdio.in.h b/lib/gl/stdio.in.h
index e554be6..6f4bb80 100644
--- a/lib/gl/stdio.in.h
+++ b/lib/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.
@@ -750,6 +770,20 @@ _GL_CXXALIAS_SYS (obstack_vprintf, int,
 _GL_CXXALIASWARN (obstack_vprintf);
 #endif
 
+#if @GNULIB_PCLOSE@
+# if address@hidden@
+_GL_FUNCDECL_SYS (pclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (pclose, int, (FILE *stream));
+_GL_CXXALIASWARN (pclose);
+#elif defined GNULIB_POSIXCHECK
+# undef pclose
+# if HAVE_RAW_DECL_PCLOSE
+_GL_WARN_ON_USE (pclose, "popen is unportable - "
+                 "use gnulib module pclose for more portability");
+# endif
+#endif
+
 #if @GNULIB_PERROR@
 /* Print a message to standard error, describing the value of ERRNO,
    (if STRING is not NULL and not empty) prefixed with STRING and ": ",
@@ -781,6 +815,10 @@ _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const 
char *mode)
                                  _GL_ARG_NONNULL ((1, 2)));
 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
 # else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode)
+                                 _GL_ARG_NONNULL ((1, 2)));
+#  endif
 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
 # endif
 _GL_CXXALIASWARN (popen);
diff --git a/lib/gl/strings.in.h b/lib/gl/strings.in.h
index c6473d2..5e6deaf 100644
--- a/lib/gl/strings.in.h
+++ b/lib/gl/strings.in.h
@@ -30,11 +30,18 @@
 #endif
 
 /* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_STRINGS_H@
+#if @HAVE_STRINGS_H@
+# @INCLUDE_NEXT@ @NEXT_STRINGS_H@
+#endif
 
 #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/lib/gl/sys_stat.in.h b/lib/gl/sys_stat.in.h
index 269edf1..b1b5adc 100644
--- a/lib/gl/sys_stat.in.h
+++ b/lib/gl/sys_stat.in.h
@@ -55,10 +55,17 @@
 /* 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
+# ifdef _S_IFIFO
+#  define S_IFIFO _S_IFIFO
+# endif
 #endif
 
 #ifndef S_IFMT
@@ -312,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/lib/gl/sys_types.in.h b/lib/gl/sys_types.in.h
new file mode 100644
index 0000000..40c61e8
--- /dev/null
+++ b/lib/gl/sys_types.in.h
@@ -0,0 +1,40 @@
+/* Provide a more complete sys/types.h.
+
+   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 Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser 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.  */
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#ifndef address@hidden@_SYS_TYPES_H
+
+/* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_SYS_TYPES_H@
+
+#ifndef address@hidden@_SYS_TYPES_H
+#define address@hidden@_SYS_TYPES_H
+
+/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>.  */
+/* But avoid namespace pollution on glibc systems.  */
+#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
+    && ! defined __GLIBC__
+# include <stddef.h>
+#endif
+
+#endif /* address@hidden@_SYS_TYPES_H */
+#endif /* address@hidden@_SYS_TYPES_H */
diff --git a/lib/gl/sys_uio.in.h b/lib/gl/sys_uio.in.h
index b304712..43db3bd 100644
--- a/lib/gl/sys_uio.in.h
+++ b/lib/gl/sys_uio.in.h
@@ -37,7 +37,7 @@
 
 #if address@hidden@
 /* A platform that lacks <sys/uio.h>.  */
-/* Get 'ssize_t'.  */
+/* Get 'size_t' and 'ssize_t'.  */
 # include <sys/types.h>
 
 # ifdef __cplusplus
diff --git a/lib/gl/tests/Makefile.am b/lib/gl/tests/Makefile.am
index fdf8faa..f9577df 100644
--- a/lib/gl/tests/Makefile.am
+++ b/lib/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.
@@ -139,6 +151,31 @@ 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
+check_PROGRAMS += test-fdopen
+EXTRA_DIST += test-fdopen.c signature.h macros.h
+
+## end   gnulib module fdopen-tests
+
+## begin gnulib module fgetc-tests
+
+TESTS += test-fgetc
+check_PROGRAMS += test-fgetc
+EXTRA_DIST += test-fgetc.c signature.h macros.h
+
+## end   gnulib module fgetc-tests
+
 ## begin gnulib module float-tests
 
 TESTS += test-float
@@ -154,6 +191,22 @@ EXTRA_DIST += fpucw.h
 
 ## end   gnulib module fpucw
 
+## 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 fseek-tests
 
 TESTS += test-fseek.sh test-fseek2.sh
@@ -164,12 +217,20 @@ EXTRA_DIST += test-fseek.c test-fseek.sh test-fseek2.sh 
signature.h macros.h
 
 ## begin gnulib module fseeko-tests
 
-TESTS += test-fseeko.sh test-fseeko2.sh test-fseeko3.sh
-check_PROGRAMS += test-fseeko test-fseeko3
-EXTRA_DIST += test-fseeko.c test-fseeko.sh test-fseeko2.sh test-fseeko3.c 
test-fseeko3.sh signature.h macros.h
+TESTS += test-fseeko.sh test-fseeko2.sh test-fseeko3.sh test-fseeko4.sh
+check_PROGRAMS += test-fseeko test-fseeko3 test-fseeko4
+EXTRA_DIST += test-fseeko.c test-fseeko.sh test-fseeko2.sh test-fseeko3.c 
test-fseeko3.sh test-fseeko4.c test-fseeko4.sh signature.h macros.h
 
 ## end   gnulib module fseeko-tests
 
+## begin gnulib module fstat-tests
+
+TESTS += test-fstat
+check_PROGRAMS += test-fstat
+EXTRA_DIST += test-fstat.c signature.h macros.h
+
+## end   gnulib module fstat-tests
+
 ## begin gnulib module ftell-tests
 
 TESTS += test-ftell.sh test-ftell2.sh test-ftell3
@@ -181,10 +242,10 @@ EXTRA_DIST += test-ftell.c test-ftell.sh test-ftell2.sh 
test-ftell3.c signature.
 
 ## begin gnulib module ftello-tests
 
-TESTS += test-ftello.sh test-ftello2.sh test-ftello3
-check_PROGRAMS += test-ftello test-ftello3
+TESTS += test-ftello.sh test-ftello2.sh test-ftello3 test-ftello4.sh
+check_PROGRAMS += test-ftello test-ftello3 test-ftello4
 MOSTLYCLEANFILES += t-ftello3.tmp
-EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh test-ftello3.c 
signature.h macros.h
+EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh test-ftello3.c 
test-ftello4.c test-ftello4.sh signature.h macros.h
 
 ## end   gnulib module ftello-tests
 
@@ -196,6 +257,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 getpagesize
 
 
@@ -473,6 +542,14 @@ EXTRA_DIST += test-sys_stat.c
 
 ## end   gnulib module sys_stat-tests
 
+## begin gnulib module sys_types-tests
+
+TESTS += test-sys_types
+check_PROGRAMS += test-sys_types
+EXTRA_DIST += test-sys_types.c
+
+## end   gnulib module sys_types-tests
+
 ## begin gnulib module sys_uio-tests
 
 TESTS += test-sys_uio
diff --git a/lib/gl/tests/fdopen.c b/lib/gl/tests/fdopen.c
new file mode 100644
index 0000000..50c889b
--- /dev/null
+++ b/lib/gl/tests/fdopen.c
@@ -0,0 +1,69 @@
+/* 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
+   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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#undef fdopen
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static FILE *
+fdopen_nothrow (int fd, const char *mode)
+{
+  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/lib/gl/tests/init.sh b/lib/gl/tests/init.sh
index 0da6c1e..373d9d4 100644
--- a/lib/gl/tests/init.sh
+++ b/lib/gl/tests/init.sh
@@ -74,7 +74,20 @@ Exit () { set +e; (exit $1); exit $1; }
 # the reason for skip/failure to console, rather than to the .log files.
 : ${stderr_fileno_=2}
 
-warn_ () { echo "$@" 1>&$stderr_fileno_; }
+# Note that correct expansion of "$*" depends on IFS starting with ' '.
+# Always write the full diagnostic to stderr.
+# When stderr_fileno_ is not 2, also emit the first line of the
+# diagnostic to that file descriptor.
+warn_ ()
+{
+  # If IFS does not start with ' ', set it and emit the warning in a subshell.
+  case $IFS in
+    ' '*) printf '%s\n' "$*" >&2
+          test $stderr_fileno_ = 2 \
+            || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
+    *) (IFS=' '; warn_ "$@");;
+  esac
+}
 fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
 skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
 fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }
@@ -208,8 +221,10 @@ export MALLOC_PERTURB_
 # a partition, or to undo any other global state changes.
 cleanup_ () { :; }
 
-if ( diff --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
+if ( diff -u "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
   compare () { diff -u "$@"; }
+elif ( diff -c "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
+  compare () { diff -c "$@"; }
 elif ( cmp --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
   compare () { cmp -s "$@"; }
 else
diff --git a/lib/gl/tests/test-fcntl-h.c b/lib/gl/tests/test-fcntl-h.c
index 648701e..7f350b4 100644
--- a/lib/gl/tests/test-fcntl-h.c
+++ b/lib/gl/tests/test-fcntl-h.c
@@ -31,6 +31,11 @@ int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 /* Check that the FD_* macros are defined.  */
 int i = FD_CLOEXEC;
 
+/* Check that the types are all defined.  */
+pid_t t1;
+off_t t2;
+mode_t t3;
+
 int
 main (void)
 {
diff --git a/lib/gl/tests/test-fdopen.c b/lib/gl/tests/test-fdopen.c
new file mode 100644
index 0000000..304e520
--- /dev/null
+++ b/lib/gl/tests/test-fdopen.c
@@ -0,0 +1,54 @@
+/* Test opening a stream with a file descriptor.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fdopen, FILE *, (int, const char *));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* 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;
+}
diff --git a/lib/gl/tests/test-fgetc.c b/lib/gl/tests/test-fgetc.c
new file mode 100644
index 0000000..4df46fb
--- /dev/null
+++ b/lib/gl/tests/test-fgetc.c
@@ -0,0 +1,96 @@
+/* Test of fgetc() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fgetc, 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";
+
+  /* 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";
+    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);
+  }
+
+  /* Test that fgetc() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fgetc (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.  */
+  {
+    FILE *fp = fdopen (-1, "r");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fgetc (fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "r");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fgetc (fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-float.c b/lib/gl/tests/test-float.c
index 5301813..57a472f 100644
--- a/lib/gl/tests/test-float.c
+++ b/lib/gl/tests/test-float.c
@@ -298,7 +298,14 @@ test_long_double (void)
 
   /* Check that 'long double' is at least as wide as 'double'.  */
   ASSERT (LDBL_MANT_DIG >= DBL_MANT_DIG);
-  ASSERT (LDBL_MIN_EXP <= DBL_MIN_EXP);
+
+  /* Normally, we would also assert this:
+       ASSERT (LDBL_MIN_EXP <= DBL_MIN_EXP);
+     but at least on powerpc64 with gcc-4.4.4, it would fail:
+     $ :|gcc -dD -E -include stddef.h -|grep -E 'L?DBL_MIN_EXP'
+     #define __DBL_MIN_EXP__ (-1021)
+     #define __LDBL_MIN_EXP__ (-968)
+  */
   ASSERT (LDBL_MAX_EXP >= DBL_MAX_EXP);
 
   /* Check the value of LDBL_DIG.  */
diff --git a/lib/gl/tests/test-fputc.c b/lib/gl/tests/test-fputc.c
new file mode 100644
index 0000000..03a3716
--- /dev/null
+++ b/lib/gl/tests/test-fputc.c
@@ -0,0 +1,90 @@
+/* Test of fputc() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-fputc.txt";
+
+  /* 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 fputc() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "w");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fputc ('x', fp) == EOF);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fputc() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-fread.c b/lib/gl/tests/test-fread.c
new file mode 100644
index 0000000..e205c9e
--- /dev/null
+++ b/lib/gl/tests/test-fread.c
@@ -0,0 +1,99 @@
+/* Test of fread() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-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.  */
+  {
+    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);
+  }
+
+  /* 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 (fread (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* 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 (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "r");
+    if (fp != NULL)
+      {
+        char buf[1];
+        errno = 0;
+        ASSERT (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-fseeko4.c b/lib/gl/tests/test-fseeko4.c
new file mode 100644
index 0000000..61559e1
--- /dev/null
+++ b/lib/gl/tests/test-fseeko4.c
@@ -0,0 +1,71 @@
+/* Test of fseeko() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = argv[1];
+
+  /* Test that fseeko() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (ftell (fp) == 0);
+    ASSERT (fseeko (fp, 0, SEEK_END) == 0);
+    ASSERT (ftell (fp) > 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fseeko (fp, 0, SEEK_SET) == -1);
+    ASSERT (errno == EBADF);
+    fclose (fp);
+  }
+
+  /* Test that fseeko() sets errno if the stream was constructed with
+     an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fseeko (fp, 0, SEEK_END) == -1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (fseeko (fp, 0, SEEK_END) == -1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-fseeko4.sh b/lib/gl/tests/test-fseeko4.sh
new file mode 100755
index 0000000..e6464ae
--- /dev/null
+++ b/lib/gl/tests/test-fseeko4.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+./test-fseeko4${EXEEXT} "$srcdir/test-fseeko4.sh" || exit 1
+
+exit 0
diff --git a/lib/gl/tests/test-fstat.c b/lib/gl/tests/test-fstat.c
new file mode 100644
index 0000000..6c120d9
--- /dev/null
+++ b/lib/gl/tests/test-fstat.c
@@ -0,0 +1,48 @@
+/* Tests of fstat() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fstat, int, (int, struct stat *));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (-1, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (99, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-ftello4.c b/lib/gl/tests/test-ftello4.c
new file mode 100644
index 0000000..d503f71
--- /dev/null
+++ b/lib/gl/tests/test-ftello4.c
@@ -0,0 +1,68 @@
+/* Test of ftello() function.
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = argv[1];
+
+  /* Test that ftello() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (ftello (fp) == (off_t)-1);
+    ASSERT (errno == EBADF);
+    fclose (fp);
+  }
+
+  /* Test that ftello() sets errno if the stream was constructed with
+     an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (ftello (fp) == (off_t)-1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        errno = 0;
+        ASSERT (ftello (fp) == (off_t)-1);
+        ASSERT (errno == EBADF);
+        fclose (fp);
+      }
+  }
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-ftello4.sh b/lib/gl/tests/test-ftello4.sh
new file mode 100755
index 0000000..e3702bb
--- /dev/null
+++ b/lib/gl/tests/test-ftello4.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+./test-ftello4${EXEEXT} "$srcdir/test-ftello4.sh" || exit 1
+
+exit 0
diff --git a/lib/gl/tests/test-fwrite.c b/lib/gl/tests/test-fwrite.c
new file mode 100644
index 0000000..76ed05c
--- /dev/null
+++ b/lib/gl/tests/test-fwrite.c
@@ -0,0 +1,93 @@
+/* Test of fwrite() function.
+   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>
+
+#include <stdio.h>
+
+#include "signature.h"
+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-fwrite.txt";
+
+  /* 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 fwrite() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    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 (fwrite (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fwrite() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/lib/gl/tests/test-sys_socket.c b/lib/gl/tests/test-sys_socket.c
index a6e99d6..58c1899 100644
--- a/lib/gl/tests/test-sys_socket.c
+++ b/lib/gl/tests/test-sys_socket.c
@@ -30,6 +30,10 @@ int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
 /* Check that the 'socklen_t' type is defined.  */
 socklen_t t1;
 
+/* Check that the 'size_t' and 'ssize_t' types are defined.  */
+size_t t2;
+ssize_t t3;
+
 /* Check that 'struct iovec' is defined.  */
 struct iovec io;
 
diff --git a/lib/gl/tests/test-sys_stat.c b/lib/gl/tests/test-sys_stat.c
index cd07d86..3303bad 100644
--- a/lib/gl/tests/test-sys_stat.c
+++ b/lib/gl/tests/test-sys_stat.c
@@ -26,11 +26,14 @@
 int a[] =
   {
     S_IFMT,
-    S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFREG,
-#ifdef S_IFLNK /* missing on mingw and djgpp */
+#ifdef S_IFBLK /* missing on MSVC */
+    S_IFBLK,
+#endif
+    S_IFCHR, S_IFDIR, S_IFIFO, S_IFREG,
+#ifdef S_IFLNK /* missing on native Windows and DJGPP */
     S_IFLNK,
 #endif
-#ifdef S_IFSOCK /* missing on mingw and djgpp */
+#ifdef S_IFSOCK /* missing on native Windows and DJGPP */
     S_IFSOCK,
 #endif
     S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR,
@@ -61,7 +64,9 @@ verify (S_IRWXU == (S_IRUSR | S_IWUSR | S_IXUSR));
 verify (S_IRWXG == (S_IRGRP | S_IWGRP | S_IXGRP));
 verify (S_IRWXO == (S_IROTH | S_IWOTH | S_IXOTH));
 
+#ifdef S_IFBLK
 verify (S_ISBLK (S_IFBLK));
+#endif
 verify (!S_ISBLK (S_IFCHR));
 verify (!S_ISBLK (S_IFDIR));
 verify (!S_ISBLK (S_IFIFO));
@@ -73,7 +78,9 @@ verify (!S_ISBLK (S_IFLNK));
 verify (!S_ISBLK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISCHR (S_IFBLK));
+#endif
 verify (S_ISCHR (S_IFCHR));
 verify (!S_ISCHR (S_IFDIR));
 verify (!S_ISCHR (S_IFIFO));
@@ -85,7 +92,9 @@ verify (!S_ISCHR (S_IFLNK));
 verify (!S_ISCHR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISDIR (S_IFBLK));
+#endif
 verify (!S_ISDIR (S_IFCHR));
 verify (S_ISDIR (S_IFDIR));
 verify (!S_ISDIR (S_IFIFO));
@@ -97,7 +106,9 @@ verify (!S_ISDIR (S_IFLNK));
 verify (!S_ISDIR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISFIFO (S_IFBLK));
+#endif
 verify (!S_ISFIFO (S_IFCHR));
 verify (!S_ISFIFO (S_IFDIR));
 verify (S_ISFIFO (S_IFIFO));
@@ -109,7 +120,9 @@ verify (!S_ISFIFO (S_IFLNK));
 verify (!S_ISFIFO (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISREG (S_IFBLK));
+#endif
 verify (!S_ISREG (S_IFCHR));
 verify (!S_ISREG (S_IFDIR));
 verify (!S_ISREG (S_IFIFO));
@@ -121,7 +134,9 @@ verify (!S_ISREG (S_IFLNK));
 verify (!S_ISREG (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISLNK (S_IFBLK));
+#endif
 verify (!S_ISLNK (S_IFCHR));
 verify (!S_ISLNK (S_IFDIR));
 verify (!S_ISLNK (S_IFIFO));
@@ -133,7 +148,9 @@ verify (S_ISLNK (S_IFLNK));
 verify (!S_ISLNK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISSOCK (S_IFBLK));
+#endif
 verify (!S_ISSOCK (S_IFCHR));
 verify (!S_ISSOCK (S_IFDIR));
 verify (!S_ISSOCK (S_IFIFO));
@@ -145,7 +162,9 @@ verify (!S_ISSOCK (S_IFLNK));
 verify (S_ISSOCK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISDOOR (S_IFBLK));
+#endif
 verify (!S_ISDOOR (S_IFCHR));
 verify (!S_ISDOOR (S_IFDIR));
 verify (!S_ISDOOR (S_IFIFO));
@@ -157,7 +176,9 @@ verify (!S_ISDOOR (S_IFLNK));
 verify (!S_ISDOOR (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISMPB (S_IFBLK));
+#endif
 verify (!S_ISMPB (S_IFCHR));
 verify (!S_ISMPB (S_IFDIR));
 verify (!S_ISMPB (S_IFIFO));
@@ -169,7 +190,9 @@ verify (!S_ISMPB (S_IFLNK));
 verify (!S_ISMPB (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISNAM (S_IFBLK));
+#endif
 verify (!S_ISNAM (S_IFCHR));
 verify (!S_ISNAM (S_IFDIR));
 verify (!S_ISNAM (S_IFIFO));
@@ -181,7 +204,9 @@ verify (!S_ISNAM (S_IFLNK));
 verify (!S_ISNAM (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISNWK (S_IFBLK));
+#endif
 verify (!S_ISNWK (S_IFCHR));
 verify (!S_ISNWK (S_IFDIR));
 verify (!S_ISNWK (S_IFIFO));
@@ -193,7 +218,9 @@ verify (!S_ISNWK (S_IFLNK));
 verify (!S_ISNWK (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISPORT (S_IFBLK));
+#endif
 verify (!S_ISPORT (S_IFCHR));
 verify (!S_ISPORT (S_IFDIR));
 verify (!S_ISPORT (S_IFIFO));
@@ -205,7 +232,9 @@ verify (!S_ISPORT (S_IFLNK));
 verify (!S_ISPORT (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISCTG (S_IFBLK));
+#endif
 verify (!S_ISCTG (S_IFCHR));
 verify (!S_ISCTG (S_IFDIR));
 verify (!S_ISCTG (S_IFIFO));
@@ -217,7 +246,9 @@ verify (!S_ISCTG (S_IFLNK));
 verify (!S_ISCTG (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISOFD (S_IFBLK));
+#endif
 verify (!S_ISOFD (S_IFCHR));
 verify (!S_ISOFD (S_IFDIR));
 verify (!S_ISOFD (S_IFIFO));
@@ -229,7 +260,9 @@ verify (!S_ISOFD (S_IFLNK));
 verify (!S_ISOFD (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISOFL (S_IFBLK));
+#endif
 verify (!S_ISOFL (S_IFCHR));
 verify (!S_ISOFL (S_IFDIR));
 verify (!S_ISOFL (S_IFIFO));
@@ -241,7 +274,9 @@ verify (!S_ISOFL (S_IFLNK));
 verify (!S_ISOFL (S_IFSOCK));
 #endif
 
+#ifdef S_IFBLK
 verify (!S_ISWHT (S_IFBLK));
+#endif
 verify (!S_ISWHT (S_IFCHR));
 verify (!S_ISWHT (S_IFDIR));
 verify (!S_ISWHT (S_IFIFO));
@@ -278,8 +313,10 @@ invalid UTIME macros
 
 /* Check the existence of some types.  */
 nlink_t t1;
+off_t t2;
+mode_t t3;
 
-struct timespec t2;
+struct timespec st;
 
 int
 main (void)
diff --git a/lib/gl/tests/test-sys_types.c b/lib/gl/tests/test-sys_types.c
new file mode 100644
index 0000000..816c9d6
--- /dev/null
+++ b/lib/gl/tests/test-sys_types.c
@@ -0,0 +1,34 @@
+/* Test of <sys/types.h> substitute.
+   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/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include <sys/types.h>
+
+/* Check that the types are all defined.  */
+pid_t t1;
+size_t t2;
+ssize_t t3;
+off_t t4;
+mode_t t5;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/lib/gl/tests/test-time.c b/lib/gl/tests/test-time.c
index 0c78f36..d499a5c 100644
--- a/lib/gl/tests/test-time.c
+++ b/lib/gl/tests/test-time.c
@@ -22,7 +22,13 @@
 
 #include "verify.h"
 
-struct timespec a;
+/* Check that the types are all defined.  */
+struct timespec t1;
+#if 0
+/* POSIX:2008 does not require pid_t in <time.h> unconditionally, and indeed
+   it's missing on MacOS X 10.5, FreeBSD 6.4, OpenBSD 4.9, mingw.  */
+pid_t t2;
+#endif
 
 /* Check that NULL can be passed through varargs as a pointer type,
    per POSIX 2008.  */
diff --git a/lib/gl/unistd.in.h b/lib/gl/unistd.in.h
index 97d20d5..8dfff30 100644
--- a/lib/gl/unistd.in.h
+++ b/lib/gl/unistd.in.h
@@ -75,18 +75,21 @@
 #endif
 
 /* mingw fails to declare _exit in <unistd.h>.  */
-/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
+/* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
+   <unistd.h>.  */
 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
 /* But avoid namespace pollution on glibc systems.  */
 #ifndef __GLIBC__
 # 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>.
@@ -98,6 +101,12 @@
 # include <netdb.h>
 #endif
 
+/* MSVC defines off_t in <sys/types.h>.  */
+#if address@hidden@
+/* Get off_t.  */
+# include <sys/types.h>
+#endif
+
 #if (@GNULIB_READ@ || @GNULIB_WRITE@ \
      || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
      || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
@@ -224,12 +233,24 @@ _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.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/chown.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html.  */
 # if @REPLACE_CHOWN@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef chown
@@ -280,24 +301,32 @@ _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@
 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
    Return newfd if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/dup2.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>.  */
 # if @REPLACE_DUP2@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define dup2 rpl_dup2
@@ -426,8 +455,8 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
 /* Change the process' current working directory to the directory on which
    the given file descriptor is open.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>.  */
 # if ! @HAVE_FCHDIR@
 _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
 
@@ -484,11 +513,30 @@ _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
 #endif
 
 
-#if @GNULIB_FSYNC@
+#if @GNULIB_FDATASYNC@
 /* Synchronize changes to a file.
    Return 0 if successful, otherwise -1 and errno set.
-   See POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/fsync.html>.  */
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. 
 */
+# if address@hidden@ || address@hidden@
+_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
+# endif
+_GL_CXXALIAS_SYS (fdatasync, int, (int fd));
+_GL_CXXALIASWARN (fdatasync);
+#elif defined GNULIB_POSIXCHECK
+# undef fdatasync
+# if HAVE_RAW_DECL_FDATASYNC
+_GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
+                 "use gnulib module fdatasync for portability");
+# endif
+#endif
+
+
+#if @GNULIB_FSYNC@
+/* Synchronize changes, including metadata, to a file.
+   Return 0 if successful, otherwise -1 and errno set.
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>.  */
 # if address@hidden@
 _GL_FUNCDECL_SYS (fsync, int, (int fd));
 # endif
@@ -506,8 +554,8 @@ _GL_WARN_ON_USE (fsync, "fsync is unportable - "
 #if @GNULIB_FTRUNCATE@
 /* Change the size of the file to which FD is opened to become equal to LENGTH.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. 
 */
 # if address@hidden@
 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
 # endif
@@ -527,8 +575,8 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
    of BUF.
    Return BUF if successful, or NULL if the directory couldn't be determined
    or SIZE was too small.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getcwd.html>.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
    Additionally, the gnulib module 'getcwd' guarantees the following GNU
    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
@@ -891,8 +939,8 @@ _GL_WARN_ON_USE (group_member, "group_member is unportable 
- "
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
    to GID (if GID is not -1).  Do not follow symbolic links.
    Return 0 if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/lchown.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>.  */
 # if @REPLACE_LCHOWN@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef lchown
@@ -921,8 +969,8 @@ _GL_WARN_ON_USE (lchown, "lchown is unportable to 
pre-POSIX.1-2001 systems - "
 #if @GNULIB_LINK@
 /* Create a new hard link for an existing file.
    Return 0 if successful, otherwise -1 and errno set.
-   See POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/link.html>.  */
+   See POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>.  */
 # if @REPLACE_LINK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define link rpl_link
@@ -987,8 +1035,8 @@ _GL_WARN_ON_USE (linkat, "linkat is unportable - "
 #if @GNULIB_LSEEK@
 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
    Return the new offset if successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/lseek.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>.  */
 # if @REPLACE_LSEEK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define lseek rpl_lseek
@@ -1058,8 +1106,9 @@ _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
 #if @GNULIB_PREAD@
 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
    Return the number of bytes placed into BUF if successful, otherwise
-   set errno and return -1.  0 indicates EOF.  See the POSIX:2001
-   specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
+   set errno and return -1.  0 indicates EOF.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>.  */
 # if @REPLACE_PREAD@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef pread
@@ -1093,8 +1142,8 @@ _GL_WARN_ON_USE (pread, "pread is unportable - "
 /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
    Return the number of bytes written if successful, otherwise
    set errno and return -1.  0 indicates nothing written.  See the
-   POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/pwrite.html>.  */
+   POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>.  */
 # if @REPLACE_PWRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef pwrite
@@ -1126,9 +1175,9 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
 
 #if @GNULIB_READ@
 /* Read up to COUNT bytes from file descriptor FD into the buffer starting
-   at BUF.  See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/read.html>.  */
-# if @REPLACE_READ@ && @GNULIB_UNISTD_H_NONBLOCKING@
+   at BUF.  See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>.  */
+# if @REPLACE_READ@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef read
 #   define read rpl_read
@@ -1150,8 +1199,8 @@ _GL_CXXALIASWARN (read);
 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
    bytes of it into BUF.  Return the number of bytes placed into BUF if
    successful, otherwise -1 and errno set.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/readlink.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>.  
*/
 # if @REPLACE_READLINK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define readlink rpl_readlink
@@ -1222,8 +1271,8 @@ _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
 #if @GNULIB_SLEEP@
 /* Pause the execution of the current thread for N seconds.
    Returns the number of seconds left to sleep.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/sleep.html>.  */
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>.  */
 # if @REPLACE_SLEEP@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef sleep
@@ -1372,7 +1421,7 @@ _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
 /* Pause the execution of the current thread for N microseconds.
    Returns 0 on completion, or -1 on range error.
    See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/sleep.html>.  */
+   <http://www.opengroup.org/susv3xsh/usleep.html>.  */
 # if @REPLACE_USLEEP@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef usleep
@@ -1398,9 +1447,9 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
 
 #if @GNULIB_WRITE@
 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
-   See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/write.html>.  */
-# if @REPLACE_WRITE@ && (@GNULIB_UNISTD_H_NONBLOCKING@ || 
@GNULIB_UNISTD_H_SIGPIPE@)
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>.  */
+# if @REPLACE_WRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef write
 #   define write rpl_write
diff --git a/lib/gl/w32sock.h b/lib/gl/w32sock.h
index 50e9cb6..cd4d5d9 100644
--- a/lib/gl/w32sock.h
+++ b/lib/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/lib/gl/wchar.in.h b/lib/gl/wchar.in.h
index 08fe586..312598a 100644
--- a/lib/gl/wchar.in.h
+++ b/lib/gl/wchar.in.h
@@ -98,6 +98,18 @@
 #  define WEOF -1
 # endif
 #else
+/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
+   This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
+   "unchanged by default argument promotions".  Override it.  */
+# if defined _MSC_VER
+#  if !GNULIB_defined_wint_t
+#   include <crtdefs.h>
+typedef unsigned int rpl_wint_t;
+#   undef wint_t
+#   define wint_t rpl_wint_t
+#   define GNULIB_defined_wint_t 1
+#  endif
+# endif
 # ifndef WEOF
 #  define WEOF ((wint_t) -1)
 # endif
diff --git a/lib/gnutls_compress.c b/lib/gnutls_compress.c
index 2520832..7cd6de8 100644
--- a/lib/gnutls_compress.c
+++ b/lib/gnutls_compress.c
@@ -421,12 +421,10 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
 #ifdef HAVE_LIBZ
         case GNUTLS_COMP_DEFLATE:
           {
-            int err;
-
             if (d)
-              err = inflateEnd (handle->handle);
+              inflateEnd (handle->handle);
             else
-              err = deflateEnd (handle->handle);
+              deflateEnd (handle->handle);
             break;
           }
 #endif
diff --git a/lib/x509/common.c b/lib/x509/common.c
index 1825261..ed842e1 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -1101,12 +1101,9 @@ _gnutls_x509_write_value (ASN1_TYPE c, const char *root,
                           const gnutls_datum_t * data, int str)
 {
   int result;
-  int asize;
   ASN1_TYPE c2 = ASN1_TYPE_EMPTY;
   gnutls_datum_t val = { NULL, 0 };
 
-  asize = data->size + 16;
-
   if (str)
     {
       /* Convert it to OCTET STRING
diff --git a/libextra/gl/gnulib.mk b/libextra/gl/gnulib.mk
index 72c57d3..1dee177 100644
--- a/libextra/gl/gnulib.mk
+++ b/libextra/gl/gnulib.mk
@@ -2,14 +2,26 @@
 ## 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.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libxgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --avoid=dummy --avoid=stdint 
--makefile-name=gnulib.mk --libtool --macro-prefix=xgl --no-vc-files 
crypto/hmac-md5 crypto/md5 extensions havelib lib-msvc-compat 
lib-symbol-versions
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libxgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --avoid=dummy --avoid=stdint 
--makefile-name=gnulib.mk --no-conditional-dependencies --libtool 
--macro-prefix=xgl --no-vc-files crypto/hmac-md5 crypto/md5 extensions havelib 
lib-msvc-compat lib-symbol-versions
 
 
 MOSTLYCLEANFILES += core *.stackdump
@@ -25,19 +37,17 @@ libxgnu_la_LDFLAGS += -no-undefined
 
 ## begin gnulib module crypto/hmac-md5
 
+libxgnu_la_SOURCES += hmac-md5.c
 
-EXTRA_DIST += hmac-md5.c hmac.h
-
-EXTRA_libxgnu_la_SOURCES += hmac-md5.c
+EXTRA_DIST += hmac.h
 
 ## end   gnulib module crypto/hmac-md5
 
 ## begin gnulib module crypto/md5
 
+libxgnu_la_SOURCES += md5.c
 
-EXTRA_DIST += md5.c md5.h
-
-EXTRA_libxgnu_la_SOURCES += md5.c
+EXTRA_DIST += md5.h
 
 ## end   gnulib module crypto/md5
 
@@ -50,10 +60,9 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
 
 ## begin gnulib module memxor
 
+libxgnu_la_SOURCES += memxor.c
 
-EXTRA_DIST += memxor.c memxor.h
-
-EXTRA_libxgnu_la_SOURCES += memxor.c
+EXTRA_DIST += memxor.h
 
 ## end   gnulib module memxor
 
diff --git a/libextra/gl/hmac-md5.c b/libextra/gl/hmac-md5.c
index 2c0edf5..eed1657 100644
--- a/libextra/gl/hmac-md5.c
+++ b/libextra/gl/hmac-md5.c
@@ -58,7 +58,7 @@ hmac_md5 (const void *key, size_t keylen,
   md5_init_ctx (&inner);
 
   memset (block, IPAD, sizeof (block));
-  gl_memxor (block, key, keylen);
+  memxor (block, key, keylen);
 
   md5_process_block (block, 64, &inner);
   md5_process_bytes (in, inlen, &inner);
@@ -70,7 +70,7 @@ hmac_md5 (const void *key, size_t keylen,
   md5_init_ctx (&outer);
 
   memset (block, OPAD, sizeof (block));
-  gl_memxor (block, key, keylen);
+  memxor (block, key, keylen);
 
   md5_process_block (block, 64, &outer);
   md5_process_bytes (innerhash, 16, &outer);
diff --git a/libextra/gl/m4/extensions.m4 b/libextra/gl/m4/extensions.m4
index 1330503..22156e0 100644
--- a/libextra/gl/m4/extensions.m4
+++ b/libextra/gl/m4/extensions.m4
@@ -1,4 +1,4 @@
-# serial 9  -*- Autoconf -*-
+# serial 10  -*- Autoconf -*-
 # Enable extensions on systems that normally disable them.
 
 # Copyright (C) 2003, 2006-2011 Free Software Foundation, Inc.
@@ -67,6 +67,10 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
+/* Enable general extensions on MacOS X.  */
+#ifndef _DARWIN_C_SOURCE
+# undef _DARWIN_C_SOURCE
+#endif
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
@@ -95,6 +99,7 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
   test $ac_cv_safe_to_define___extensions__ = yes &&
     AC_DEFINE([__EXTENSIONS__])
   AC_DEFINE([_ALL_SOURCE])
+  AC_DEFINE([_DARWIN_C_SOURCE])
   AC_DEFINE([_GNU_SOURCE])
   AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
   AC_DEFINE([_TANDEM_SOURCE])
diff --git a/libextra/gl/m4/gnulib-cache.m4 b/libextra/gl/m4/gnulib-cache.m4
index 5e01d55..261dfdf 100644
--- a/libextra/gl/m4/gnulib-cache.m4
+++ b/libextra/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.
@@ -15,7 +27,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libxgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --avoid=dummy --avoid=stdint --makefile-name=gnulib.mk 
--libtool --macro-prefix=xgl --no-vc-files crypto/hmac-md5 crypto/md5 
extensions havelib lib-msvc-compat lib-symbol-versions
+#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libxgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --avoid=dummy --avoid=stdint --makefile-name=gnulib.mk 
--no-conditional-dependencies --libtool --macro-prefix=xgl --no-vc-files 
crypto/hmac-md5 crypto/md5 extensions havelib lib-msvc-compat 
lib-symbol-versions
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([gl/override])
@@ -38,4 +50,5 @@ gl_MAKEFILE_NAME([gnulib.mk])
 gl_LIBTOOL
 gl_MACRO_PREFIX([xgl])
 gl_PO_DOMAIN([])
+gl_WITNESS_C_DOMAIN([])
 gl_VC_FILES([false])
diff --git a/libextra/gl/m4/gnulib-common.m4 b/libextra/gl/m4/gnulib-common.m4
index ecbf336..7d83299 100644
--- a/libextra/gl/m4/gnulib-common.m4
+++ b/libextra/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 23
+# 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,
@@ -12,6 +12,19 @@ AC_DEFUN([gl_COMMON], [
   AC_REQUIRE([gl_COMMON_BODY])
 ])
 AC_DEFUN([gl_COMMON_BODY], [
+  AH_VERBATIM([_Noreturn],
+[/* The _Noreturn keyword of draft C1X.  */
+#ifndef _Noreturn
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+      || 0x5110 <= __SUNPRO_C)
+#  define _Noreturn __attribute__ ((__noreturn__))
+# elif 1200 <= _MSC_VER
+#  define _Noreturn __declspec (noreturn)
+# else
+#  define _Noreturn
+# endif
+#endif
+])
   AH_VERBATIM([isoc99_inline],
 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
@@ -34,6 +47,20 @@ AC_DEFUN([gl_COMMON_BODY], [
 /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
    is a misnomer outside of parameter lists.  */
 #define _UNUSED_PARAMETER_ _GL_UNUSED
+
+/* The __pure__ attribute was added in gcc 2.96.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
+#endif
+
+/* The __const__ attribute was added in gcc 2.95.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
 ])
   dnl Preparation for running test programs:
   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
@@ -47,16 +74,49 @@ AC_DEFUN([gl_COMMON_BODY], [
 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
 # whether a gnulib module that has been requested shall be considered present
 # or not.
-AC_DEFUN([gl_MODULE_INDICATOR_CONDITION], [1])
+m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
 
 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
 # sets the shell variable that indicates the presence of the given module to
 # a C preprocessor expression that will evaluate to 1.
 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
 [
-  GNULIB_[]m4_translit([[$1]],
-    [abcdefghijklmnopqrstuvwxyz./-],
-    [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=gl_MODULE_INDICATOR_CONDITION
+  gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
+    [GNULIB_[]m4_translit([[$1]],
+                          [abcdefghijklmnopqrstuvwxyz./-],
+                          [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
+    [gl_MODULE_INDICATOR_CONDITION])
+])
+
+# gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
+# modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
+# The shell variable's value is a C preprocessor expression that evaluates
+# to 0 or 1.
+AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
+[
+  m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
+    [
+     dnl Simplify the expression VALUE || 1 to 1.
+     $1=1
+    ],
+    [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
+                                             [gl_MODULE_INDICATOR_CONDITION])])
+])
+
+# gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
+# modifies the shell variable to include the given condition.  The shell
+# variable's value is a C preprocessor expression that evaluates to 0 or 1.
+AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
+[
+  dnl Simplify the expression 1 || CONDITION to 1.
+  if test "$[]$1" != 1; then
+    dnl Simplify the expression 0 || CONDITION to CONDITION.
+    if test "$[]$1" = 0; then
+      $1=$2
+    else
+      $1="($[]$1 || $2)"
+    fi
+  fi
 ])
 
 # gl_MODULE_INDICATOR([modulename])
@@ -109,7 +169,8 @@ AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
 [
   dnl Override gl_WARN_ON_USE_PREPARE.
-  AC_DEFUN([gl_WARN_ON_USE_PREPARE], [])
+  dnl But hide this definition from 'aclocal'.
+  AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
 ])
 
 # gl_ASSERT_NO_GNULIB_TESTS
@@ -150,6 +211,83 @@ 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
+# the values.
+AC_DEFUN([gl_PROG_AR_RANLIB],
+[
+  dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
+  dnl as "cc", and GCC as "gcc". They have different object file formats and
+  dnl library formats. In particular, the GNU binutils programs ar, ranlib
+  dnl produce libraries that work only with gcc, not with cc.
+  AC_REQUIRE([AC_PROG_CC])
+  AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
+    [
+      AC_EGREP_CPP([Amsterdam],
+        [
+#ifdef __ACK__
+Amsterdam
+#endif
+        ],
+        [gl_cv_c_amsterdam_compiler=yes],
+        [gl_cv_c_amsterdam_compiler=no])
+    ])
+  if test -z "$AR"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      AR='cc -c.a'
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='-o'
+      fi
+    else
+      dnl Use the Automake-documented default values for AR and ARFLAGS,
+      dnl but prefer ${host}-ar over ar (useful for cross-compiling).
+      AC_CHECK_TOOL([AR], [ar], [ar])
+      if test -z "$ARFLAGS"; then
+        ARFLAGS='cru'
+      fi
+    fi
+  else
+    if test -z "$ARFLAGS"; then
+      ARFLAGS='cru'
+    fi
+  fi
+  AC_SUBST([AR])
+  AC_SUBST([ARFLAGS])
+  if test -z "$RANLIB"; then
+    if test $gl_cv_c_amsterdam_compiler = yes; then
+      RANLIB=':'
+    else
+      dnl Use the ranlib program if it is available.
+      AC_PROG_RANLIB
+    fi
+  fi
+  AC_SUBST([RANLIB])
+])
+
 # AC_PROG_MKDIR_P
 # is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
 # for interoperability with automake-1.9.6 from autoconf-2.62.
diff --git a/libextra/gl/m4/gnulib-comp.m4 b/libextra/gl/m4/gnulib-comp.m4
index d391b3b..707948e 100644
--- a/libextra/gl/m4/gnulib-comp.m4
+++ b/libextra/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.
@@ -25,7 +37,7 @@ AC_DEFUN([xgl_EARLY],
   m4_pattern_allow([^gl_ES$])dnl a valid locale name
   m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
   m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
-  AC_REQUIRE([AC_PROG_RANLIB])
+  AC_REQUIRE([gl_PROG_AR_RANLIB])
   # Code from module crypto/hmac-md5:
   # Code from module crypto/md5:
   # Code from module extensions:
@@ -50,18 +62,10 @@ AC_DEFUN([xgl_INIT],
   m4_pushdef([xgl_LIBSOURCES_DIR], [])
   gl_COMMON
   gl_source_base='gl'
-  # Code from module crypto/hmac-md5:
-  gl_HMAC_MD5
-  # Code from module crypto/md5:
-  gl_MD5
-  # Code from module extensions:
-  # Code from module havelib:
-  # Code from module lib-msvc-compat:
-  gl_LD_OUTPUT_DEF
-  # Code from module lib-symbol-versions:
-  gl_LD_VERSION_SCRIPT
-  # Code from module memxor:
-  gl_MEMXOR
+gl_MD5
+gl_LD_OUTPUT_DEF
+gl_LD_VERSION_SCRIPT
+gl_MEMXOR
   # End of code from modules
   m4_ifval(xgl_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([xgl_LIBSOURCES_DIR])[ ||
@@ -208,7 +212,6 @@ AC_DEFUN([xgl_FILE_LIST], [
   m4/00gnulib.m4
   m4/extensions.m4
   m4/gnulib-common.m4
-  m4/hmac-md5.m4
   m4/ld-output-def.m4
   m4/ld-version-script.m4
   m4/lib-ld.m4
diff --git a/libextra/gl/m4/hmac-md5.m4 b/libextra/gl/m4/hmac-md5.m4
deleted file mode 100644
index 2945555..0000000
--- a/libextra/gl/m4/hmac-md5.m4
+++ /dev/null
@@ -1,10 +0,0 @@
-# hmac-md5.m4 serial 2
-dnl Copyright (C) 2005-2006, 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,
-dnl with or without modifications, as long as this notice is preserved.
-
-AC_DEFUN([gl_HMAC_MD5],
-[
-  AC_LIBOBJ([hmac-md5])
-])
diff --git a/libextra/gl/m4/md5.m4 b/libextra/gl/m4/md5.m4
index ce7671d..4b41a85 100644
--- a/libextra/gl/m4/md5.m4
+++ b/libextra/gl/m4/md5.m4
@@ -1,4 +1,4 @@
-# md5.m4 serial 11
+# md5.m4 serial 12
 dnl Copyright (C) 2002-2006, 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,
@@ -6,8 +6,6 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 AC_DEFUN([gl_MD5],
 [
-  AC_LIBOBJ([md5])
-
   dnl Prerequisites of lib/md5.c.
   AC_REQUIRE([gl_BIGENDIAN])
   AC_REQUIRE([AC_C_INLINE])
diff --git a/libextra/gl/m4/memxor.m4 b/libextra/gl/m4/memxor.m4
index 42789eb..10c3313 100644
--- a/libextra/gl/m4/memxor.m4
+++ b/libextra/gl/m4/memxor.m4
@@ -1,4 +1,4 @@
-# memxor.m4 serial 3
+# memxor.m4 serial 4
 dnl Copyright (C) 2006, 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,
@@ -6,6 +6,5 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 AC_DEFUN([gl_MEMXOR],
 [
-  AC_LIBOBJ([memxor])
   AC_REQUIRE([AC_C_RESTRICT])
 ])
diff --git a/libextra/gl/memxor.c b/libextra/gl/memxor.c
index b80b430..4eeebcb 100644
--- a/libextra/gl/memxor.c
+++ b/libextra/gl/memxor.c
@@ -23,7 +23,7 @@
 #include "memxor.h"
 
 void *
-gl_memxor (void *restrict dest, const void *restrict src, size_t n)
+memxor (void *restrict dest, const void *restrict src, size_t n)
 {
   char const *s = src;
   char *d = dest;
diff --git a/libextra/gl/memxor.h b/libextra/gl/memxor.h
index fbf2ac3..dafa2cf 100644
--- a/libextra/gl/memxor.h
+++ b/libextra/gl/memxor.h
@@ -26,6 +26,6 @@
 /* Compute binary exclusive OR of memory areas DEST and SRC, putting
    the result in DEST, of length N bytes.  Returns a pointer to
    DEST. */
-void *gl_memxor (void *restrict dest, const void *restrict src, size_t n);
+void *memxor (void *restrict dest, const void *restrict src, size_t n);
 
 #endif /* MEMXOR_H */
diff --git a/maint.mk b/maint.mk
index ff2fbbb..51f617b 100644
--- a/maint.mk
+++ b/maint.mk
@@ -33,7 +33,6 @@ GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
 
 GIT = git
 VC = $(GIT)
-VC-tag = git tag -s -m '$(VERSION)' -u '$(gpg_key_ID)'
 
 VC_LIST = $(build_aux)/vc-list-files -C $(srcdir)
 
@@ -57,11 +56,13 @@ endif
 # In order to be able to consistently filter "."-relative names,
 # (i.e., with no $(srcdir) prefix), this definition is careful to
 # remove any $(srcdir) prefix, and to restore what it removes.
+_sc_excl = \
+  $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
 VC_LIST_EXCEPT = \
   $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
        | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
          else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
-       | grep -Ev -e '$(VC_LIST_ALWAYS_EXCLUDE_REGEX)' \
+       | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
        $(_prepend_srcdir_prefix)
 
 ifeq ($(origin prev_version_file), undefined)
@@ -196,6 +197,16 @@ syntax-check: $(local-check)
 #  halt
 #
 #     Message to display before to halting execution.
+#
+# Finally, you may exempt files based on an ERE matching file names.
+# For example, to exempt from the sc_space_tab check all files with the
+# .diff suffix, set this Make variable:
+#
+# exclude_file_name_regexp--sc_space_tab = \.diff$
+#
+# Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
+# when filtering by name via in_files, we explicitly filter out matching
+# names here as well.
 
 # By default, _sc_search_regexp does not ignore case.
 export ignore_case =
@@ -233,7 +244,8 @@ define _sc_search_regexp
                                                                        \
    : Filter by file name;                                              \
    if test -n "$$in_files"; then                                       \
-     files=$$(find $(srcdir) | grep -E "$$in_files");                  \
+     files=$$(find $(srcdir) | grep -E "$$in_files"                    \
+              | grep -Ev '$(exclude_file_name_regexp--$@)');           \
    else                                                                        
\
      files=$$($(VC_LIST_EXCEPT));                                      \
      if test -n "$$in_vc_files"; then                                  \
@@ -393,11 +405,11 @@ sc_prohibit_HAVE_MBRTOWC:
          $(_sc_search_regexp)
 
 # To use this "command" macro, you must first define two shell variables:
-# h: the header, enclosed in <> or ""
+# h: the header name, with no enclosing <> or ""
 # re: a regular expression that matches IFF something provided by $h is used.
 define _sc_header_without_use
   dummy=; : so we do not need a semicolon before each use;             \
-  h_esc=`echo "$$h"|sed 's/\./\\\\./g'`;                               \
+  h_esc=`echo '[<"]'"$$h"'[">]'|sed 's/\./\\\\./g'`;                   \
   if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then             \
     files=$$(grep -l '^# *include '"$$h_esc"                           \
             $$($(VC_LIST_EXCEPT) | grep '\.c$$')) &&                   \
@@ -410,42 +422,42 @@ endef
 
 # Prohibit the inclusion of assert.h without an actual use of assert.
 sc_prohibit_assert_without_use:
-       @h='<assert.h>' re='\<assert *\(' $(_sc_header_without_use)
+       @h='assert.h' re='\<assert *\(' $(_sc_header_without_use)
 
 # Prohibit the inclusion of close-stream.h without an actual use.
 sc_prohibit_close_stream_without_use:
-       @h='"close-stream.h"' re='\<close_stream *\(' $(_sc_header_without_use)
+       @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use)
 
 # Prohibit the inclusion of getopt.h without an actual use.
 sc_prohibit_getopt_without_use:
-       @h='<getopt.h>' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
+       @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
 
 # Don't include quotearg.h unless you use one of its functions.
 sc_prohibit_quotearg_without_use:
-       @h='"quotearg.h"' re='\<quotearg(_[^ ]+)? *\(' $(_sc_header_without_use)
+       @h='quotearg.h' re='\<quotearg(_[^ ]+)? *\(' $(_sc_header_without_use)
 
 # Don't include quote.h unless you use one of its functions.
 sc_prohibit_quote_without_use:
-       @h='"quote.h"' re='\<quote(_n)? *\(' $(_sc_header_without_use)
+       @h='quote.h' re='\<quote(_n)? *\(' $(_sc_header_without_use)
 
 # Don't include this header unless you use one of its functions.
 sc_prohibit_long_options_without_use:
-       @h='"long-options.h"' re='\<parse_long_options *\(' \
+       @h='long-options.h' re='\<parse_long_options *\(' \
          $(_sc_header_without_use)
 
 # Don't include this header unless you use one of its functions.
 sc_prohibit_inttostr_without_use:
-       @h='"inttostr.h"' re='\<(off|[iu]max|uint)tostr *\(' \
+       @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
          $(_sc_header_without_use)
 
 # Don't include this header unless you use one of its functions.
 sc_prohibit_ignore_value_without_use:
-       @h='"ignore-value.h"' re='\<ignore_(value|ptr) *\(' \
+       @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \
          $(_sc_header_without_use)
 
 # Don't include this header unless you use one of its functions.
 sc_prohibit_error_without_use:
-       @h='"error.h"' \
+       @h='error.h' \
        re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? 
*\('\
          $(_sc_header_without_use)
 
@@ -468,7 +480,7 @@ sc_prohibit_error_without_use:
 _xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
 _xa2 = X([CZ]|N?M)ALLOC
 sc_prohibit_xalloc_without_use:
-       @h='"xalloc.h"' \
+       @h='xalloc.h' \
        re='\<($(_xa1)|$(_xa2)) *\('\
          $(_sc_header_without_use)
 
@@ -479,36 +491,46 @@ 
clear|delete|free|get_(first|next)|insert|lookup|print_statistics|reset_tuning
 _hash_fn = \<($(_hash_re)) *\(
 _hash_struct = (struct )?\<[Hh]ash_(table|tuning)\>
 sc_prohibit_hash_without_use:
-       @h='"hash.h"' \
+       @h='hash.h' \
        re='$(_hash_fn)|$(_hash_struct)'\
          $(_sc_header_without_use)
 
+sc_prohibit_cloexec_without_use:
+       @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
+         $(_sc_header_without_use)
+
+sc_prohibit_posixver_without_use:
+       @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use)
+
+sc_prohibit_same_without_use:
+       @h='same.h' re='\<same_name *\(' $(_sc_header_without_use)
+
 sc_prohibit_hash_pjw_without_use:
-       @h='"hash-pjw.h"' \
+       @h='hash-pjw.h' \
        re='\<hash_pjw *\(' \
          $(_sc_header_without_use)
 
 sc_prohibit_safe_read_without_use:
-       @h='"safe-read.h"' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
+       @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
          $(_sc_header_without_use)
 
 sc_prohibit_argmatch_without_use:
-       @h='"argmatch.h"' \
-       
re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<argmatch(_exit_fn|_(in)?valid)
 *\()' \
+       @h='argmatch.h' \
+       
re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?)
 *\()' \
          $(_sc_header_without_use)
 
 sc_prohibit_canonicalize_without_use:
-       @h='"canonicalize.h"' \
+       @h='canonicalize.h' \
        
re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
          $(_sc_header_without_use)
 
 sc_prohibit_root_dev_ino_without_use:
-       @h='"root-dev-ino.h"' \
+       @h='root-dev-ino.h' \
        re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
          $(_sc_header_without_use)
 
 sc_prohibit_openat_without_use:
-       @h='"openat.h"' \
+       @h='openat.h' \
        
re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>'
 \
          $(_sc_header_without_use)
 
@@ -516,7 +538,7 @@ sc_prohibit_openat_without_use:
 ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
 |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
 sc_prohibit_c_ctype_without_use:
-       @h='[<"]c-ctype.h[">]' re='\<c_($(ctype_re)) *\(' \
+       @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
          $(_sc_header_without_use)
 
 _empty =
@@ -552,37 +574,63 @@ _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) 
$(_sig_types_and_consts)))
 
 # Prohibit the inclusion of signal.h without an actual use.
 sc_prohibit_signal_without_use:
-       @h='<signal.h>'                                                 \
+       @h='signal.h'                                                   \
        re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>'          \
          $(_sc_header_without_use)
 
+# Don't include stdio--.h unless you use one of its functions.
+sc_prohibit_stdio--_without_use:
+       @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\('              \
+         $(_sc_header_without_use)
+
+# Don't include stdio-safer.h unless you use one of its functions.
+sc_prohibit_stdio-safer_without_use:
+       @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\('    \
+         $(_sc_header_without_use)
+
 # Prohibit the inclusion of strings.h without a sensible use.
 # Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
 sc_prohibit_strings_without_use:
-       @h='<strings.h>'                                                \
+       @h='strings.h'                                                  \
        re='\<(strn?casecmp|ffs(ll)?)\>'                                \
          $(_sc_header_without_use)
 
 # Get the list of symbol names with this:
-# perl -lne '/^# *define (\w+)\(/ and print $1' lib/intprops.h|grep -v '^s'|fmt
+# perl -lne '/^# *define ([A-Z]\w+)\(/ and print $1' lib/intprops.h|fmt
 _intprops_names =                                                      \
   TYPE_IS_INTEGER TYPE_TWOS_COMPLEMENT TYPE_ONES_COMPLEMENT            \
   TYPE_SIGNED_MAGNITUDE TYPE_SIGNED TYPE_MINIMUM TYPE_MAXIMUM          \
-  INT_STRLEN_BOUND INT_BUFSIZE_BOUND
+  INT_BITS_STRLEN_BOUND INT_STRLEN_BOUND INT_BUFSIZE_BOUND             \
+  INT_ADD_RANGE_OVERFLOW INT_SUBTRACT_RANGE_OVERFLOW                   \
+  INT_NEGATE_RANGE_OVERFLOW INT_MULTIPLY_RANGE_OVERFLOW                        
\
+  INT_DIVIDE_RANGE_OVERFLOW INT_REMAINDER_RANGE_OVERFLOW               \
+  INT_LEFT_SHIFT_RANGE_OVERFLOW INT_ADD_OVERFLOW INT_SUBTRACT_OVERFLOW \
+  INT_NEGATE_OVERFLOW INT_MULTIPLY_OVERFLOW INT_DIVIDE_OVERFLOW                
\
+  INT_REMAINDER_OVERFLOW INT_LEFT_SHIFT_OVERFLOW
 _intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
 # Prohibit the inclusion of intprops.h without an actual use.
 sc_prohibit_intprops_without_use:
-       @h='"intprops.h"'                                               \
+       @h='intprops.h'                                                 \
        re='\<($(_intprops_syms_re)) *\('                               \
          $(_sc_header_without_use)
 
 _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
 # Prohibit the inclusion of stddef.h without an actual use.
 sc_prohibit_stddef_without_use:
-       @h='<stddef.h>'                                                 \
+       @h='stddef.h'                                                   \
        re='\<($(_stddef_syms_re)) *\('                                 \
          $(_sc_header_without_use)
 
+# Prohibit the inclusion of verify.h without an actual use.
+sc_prohibit_verify_without_use:
+       @h='verify.h'                                                   \
+       re='\<(verify(true|expr)?|static_assert) *\('                   \
+         $(_sc_header_without_use)
+
+# Don't include xfreopen.h unless you use one of its functions.
+sc_prohibit_xfreopen_without_use:
+       @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use)
+
 sc_obsolete_symbols:
        @prohibit='\<(HAVE''_FCNTL_H|O''_NDELAY)\>'                     \
        halt='do not use HAVE''_FCNTL_H or O'_NDELAY                    \
@@ -634,12 +682,6 @@ sc_require_test_exit_idiom:
              exit 1; } || :;                                           \
        fi
 
-sc_the_the:
-       @prohibit='\<the ''the\>'                                       \
-       ignore_case=1                                                   \
-       halt='found use of "the ''the";'                                \
-         $(_sc_search_regexp)
-
 sc_trailing_blank:
        @prohibit='[     ]$$'                                           \
        halt='found trailing blank(s)'                                  \
@@ -654,12 +696,17 @@ sc_two_space_separator_in_usage:
        halt='help2man requires at least two spaces between an option and its 
description'\
          $(_sc_search_regexp)
 
+# A regexp matching function names like "error" that may be used
+# to emit translatable messages.
+_gl_translatable_diag_func_re ?= error
+
 # Look for diagnostics that aren't marked for translation.
 # This won't find any for which error's format string is on a separate line.
 sc_unmarked_diagnostics:
        @grep -nE                                                       \
-           '\<error *\([^"]*"[^"]*[a-z]{3}' $$($(VC_LIST_EXCEPT))      \
-         | grep -v '_''(' &&                                           \
+           '\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
+               $$($(VC_LIST_EXCEPT))                                   \
+         | grep -Ev '(_|ngettext ?)\(' &&                              \
          { echo '$(ME): found unmarked diagnostic(s)' 1>&2;            \
            exit 1; } || :
 
@@ -705,7 +752,8 @@ gl_other_headers_ ?= \
 gl_extract_significant_defines_ = \
   /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\
     && $$2 !~ /(?:rpl_|_used_without_)/\
-    && $$1 !~ /^(?:NSIG|ATTRIBUTE_NORETURN)$$/\
+    && $$1 !~ /^(?:NSIG)$$/\
+    && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\
     and print $$1
 
 # Create a list of regular expressions matching the names
@@ -714,10 +762,10 @@ define def_sym_regex
        gen_h=$(gl_generated_headers_);                                 \
        (cd $(gnulib_dir)/lib;                                          \
          for f in *.in.h $(gl_other_headers_); do                      \
-           perl -lne '$(gl_extract_significant_defines_)' $$f;         \
+           test -f $$f                                                 \
+             && perl -lne '$(gl_extract_significant_defines_)' $$f;    \
          done;                                                         \
        ) | sort -u                                                     \
-         | grep -Ev '^ATTRIBUTE_NORETURN'                              \
          | sed 's/^/^ *# *(define|undef)  */;s/$$/\\>/'
 endef
 
@@ -778,17 +826,22 @@ sc_prohibit_cvs_keyword:
 #   perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
 # but that would be far less efficient, reading the entire contents
 # of each file, rather than just the last two bytes of each.
+# In addition, while the code below detects both blank lines and a missing
+# newline at EOF, the above detects only the former.
 #
 # This is a perl script that is expected to be the single-quoted argument
 # to a command-line "-le".  The remaining arguments are file names.
-# Print the name of each file that ends in two or more newline bytes.
+# Print the name of each file that ends in exactly one newline byte.
+# I.e., warn if there are blank lines (2 or more newlines), or if the
+# last byte is not a newline.  However, currently we don't complain
+# about any file that contains exactly one byte.
 # Exit nonzero if at least one such file is found, otherwise, exit 0.
 # Warn about, but otherwise ignore open failure.  Ignore seek/read failure.
 #
 # Use this if you want to remove trailing empty lines from selected files:
 #   perl -pi -0777 -e 's/\n\n+$/\n/' files...
 #
-detect_empty_lines_at_EOF_ =                                           \
+require_exactly_one_NL_at_EOF_ =                                       \
   foreach my $$f (@ARGV)                                               \
     {                                                                  \
       open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next;    \
@@ -798,13 +851,15 @@ detect_empty_lines_at_EOF_ =                              
                \
       defined $$p and $$p = sysread F, $$last_two_bytes, 2;            \
       close F;                                                         \
       $$c = "ignore read failure";                                     \
-      $$p && $$last_two_bytes eq "\n\n" and (print $$f), $$fail=1;     \
+      $$p && ($$last_two_bytes eq "\n\n"                               \
+              || substr ($$last_two_bytes,1) ne "\n")                  \
+          and (print $$f), $$fail=1;                                   \
     }                                                                  \
   END { exit defined $$fail }
 sc_prohibit_empty_lines_at_EOF:
-       @perl -le '$(detect_empty_lines_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
-          || { echo '$(ME): the above files end with empty line(s)'     \
-               1>&2; exit 1; } || :;                                   \
+       @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
+         || { echo '$(ME): empty line(s) or no newline at EOF'         \
+               1>&2; exit 1; } || :
 
 # Make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
 # This is a bit of a kludge, since it prevents use of the string
@@ -821,6 +876,50 @@ sc_prohibit_S_IS_definition:
        halt='do not define S_IS* macros; include <sys/stat.h>'         \
          $(_sc_search_regexp)
 
+# Perl block to convert a match to FILE_NAME:LINENO:TEST,
+# that is shared by two definitions below.
+perl_filename_lineno_text_ =                                           \
+    -e '  {'                                                           \
+    -e '    $$n = ($$` =~ tr/\n/\n/ + 1);'                             \
+    -e '    ($$v = $$&) =~ s/\n/\\n/g;'                                        
\
+    -e '    print "$$ARGV:$$n:$$v\n";'                                 \
+    -e '  }'
+
+prohibit_doubled_word_RE_ ?= \
+  /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
+prohibit_doubled_word_ =                                               \
+    -e 'while ($(prohibit_doubled_word_RE_))'                          \
+    $(perl_filename_lineno_text_)
+
+# Define this to a regular expression that matches
+# any filename:dd:match lines you want to ignore.
+# The default is to ignore no matches.
+ignore_doubled_word_match_RE_ ?= ^$$
+
+sc_prohibit_doubled_word:
+       @perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT))  \
+         | grep -vE '$(ignore_doubled_word_match_RE_)'                 \
+         | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
+
+# A regular expression matching undesirable combinations of words like
+# "can not"; this matches them even when the two words appear on different
+# lines, but not when there is an intervening delimiter like "#" or "*".
+prohibit_undesirable_word_seq_RE_ ?=                                   \
+  /\bcan\s+not\b/gims
+prohibit_undesirable_word_seq_ =                                       \
+    -e 'while ($(prohibit_undesirable_word_seq_RE_))'                  \
+    $(perl_filename_lineno_text_)
+# Define this to a regular expression that matches
+# any filename:dd:match lines you want to ignore.
+# The default is to ignore no matches.
+ignore_undesirable_word_sequence_RE_ ?= ^$$
+
+sc_prohibit_undesirable_word_seq:
+       @perl -n -0777 $(prohibit_undesirable_word_seq_)                \
+            $$($(VC_LIST_EXCEPT))                                      \
+         | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \
+         && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
+
 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
 # Using test's -a and -o operators is not portable.
@@ -897,16 +996,23 @@ update-NEWS-hash: NEWS
 # Ensure that we use only the standard $(VAR) notation,
 # not @...@ in Makefile.am, now that we can rely on automake
 # to emit a definition for each substituted variable.
-# We use perl rather than "grep -nE ..." to exempt a single
-# use of an @address@hidden variable name in src/Makefile.am.
+# However, there is still one case in which @VAR@ use is not just
+# legitimate, but actually required: when augmenting an automake-defined
+# variable with a prefix.  For example, gettext uses this:
+# MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
+# otherwise, makeinfo would put German or French (current locale)
+# navigation hints in the otherwise-English documentation.
+#
 # Allow the package to add exceptions via a hook in cfg.mk;
 # for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
 _makefile_at_at_check_exceptions ?=
 sc_makefile_at_at_check:
-       @perl -ne '/address@hidden@/'$(_makefile_at_at_check_exceptions)        
\
+       @perl -ne '/address@hidden@/'                                   \
+          -e ' && !/([A-Z_0-9]+)address@hidden@$$/'                    \
+          -e ''$(_makefile_at_at_check_exceptions)                     \
          -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}'    \
-           $$($(VC_LIST_EXCEPT) | grep -E '(^|/)Makefile\.am$$')       \
+           $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
          && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
 
 news-check: NEWS
@@ -935,13 +1041,14 @@ fix_po_file_diag = \
 apply the above patch\n'
 
 # Verify that all source files using _() are listed in po/POTFILES.in.
-po_file = po/POTFILES.in
+po_file ?= $(srcdir)/po/POTFILES.in
+generated_files ?= $(srcdir)/lib/*.[ch]
 sc_po_check:
        @if test -f $(po_file); then                                    \
          grep -E -v '^(#|$$)' $(po_file)                               \
            | grep -v '^src/false\.c$$' | sort > address@hidden;                
        \
          files=;                                                       \
-         for file in $$($(VC_LIST_EXCEPT)) lib/*.[ch]; do              \
+         for file in $$($(VC_LIST_EXCEPT)) $(generated_files); do      \
            test -r $$file || continue;                                 \
            case $$file in                                              \
              *.m4|*.mk) continue ;;                                    \
@@ -956,7 +1063,7 @@ sc_po_check:
            files="$$files $$file";                                     \
          done;                                                         \
          grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files          \
-           | sort -u > address@hidden;                                         
\
+           | sed 's|^$(_dot_escaped_srcdir)/||' | sort -u > address@hidden;    
\
          diff -u -L $(po_file) -L $(po_file) address@hidden address@hidden     
                \
            || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; };   \
          rm -f address@hidden address@hidden;                                  
        \
@@ -972,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
@@ -1012,6 +1123,7 @@ sc_copyright_check:
 # the other init.sh-using tests also get it right.
 _hv_file ?= $(srcdir)/tests/help-version
 _hv_regex_weak ?= ^ *\. .*/init\.sh"
+# Fix syntax-highlighters "
 _hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh"
 sc_cross_check_PATH_usage_in_tests:
        @if test -f $(_hv_file); then                                   \
@@ -1039,6 +1151,14 @@ sc_Wundef_boolean:
        halt='Use 0 or 1 for macro values'                              \
          $(_sc_search_regexp)
 
+# Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
+# not be constant, or might overflow a stack.  In general, use PATH_MAX as
+# a limit, not an array or alloca size.
+sc_prohibit_path_max_allocation:
+       @prohibit='(\balloca *\([^)]*|\[[^]]*)PATH_MAX'                 \
+       halt='Avoid stack allocations of size PATH_MAX'                 \
+         $(_sc_search_regexp)
+
 sc_vulnerable_makefile_CVE-2009-4029:
        @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
        in_files=$$(find $(srcdir) -name Makefile.in)                   \
@@ -1072,11 +1192,20 @@ gpg_key_ID ?= \
          | sed -n '/.*key ID \([0-9A-F]*\)/s//\1/p'; rm -f .ann-sig)
 
 translation_project_ ?= address@hidden
-announcement_Cc_ ?= $(translation_project_), $(PACKAGE_BUGREPORT)
-announcement_mail_headers_ ?=                                          \
-To: address@hidden                                                     \
-Cc: $(announcement_Cc_)                                                        
\
-Mail-Followup-To: $(PACKAGE_BUGREPORT)
+
+# Make info-gnu the default only for a stable release.
+ifeq ($(RELEASE_TYPE),stable)
+  announcement_Cc_ ?= $(translation_project_), $(PACKAGE_BUGREPORT)
+  announcement_mail_headers_ ?=                                                
\
+    To: address@hidden                                         \
+    Cc: $(announcement_Cc_)                                            \
+    Mail-Followup-To: $(PACKAGE_BUGREPORT)
+else
+  announcement_Cc_ ?= $(translation_project_)
+  announcement_mail_headers_ ?=                                                
\
+    To: $(PACKAGE_BUGREPORT)                                           \
+    Cc: $(announcement_Cc_)
+endif
 
 announcement: NEWS ChangeLog $(rel-files)
        @$(build_aux)/announce-gen                                      \
@@ -1111,9 +1240,9 @@ emit_upload_commands:
        @echo =====================================
 
 define emit-commit-log
-  printf '%s\n' 'post-release administrivia' '' \
-    '* NEWS: Add header line for next release.' \
-    '* .prev-version: Record previous version.' \
+  printf '%s\n' 'maint: post-release administrivia' ''                 \
+    '* NEWS: Add header line for next release.'                                
\
+    '* .prev-version: Record previous version.'                                
\
     '* cfg.mk (old_NEWS_hash): Auto-update.'
 endef
 
@@ -1177,7 +1306,7 @@ gl_noteworthy_news_ = * Noteworthy changes in release ?.? 
(????-??-??) [?]
 release-prep:
        case $$RELEASE_TYPE in alpha|beta|stable) ;; \
          *) echo "invalid RELEASE_TYPE: $$RELEASE_TYPE" 1>&2; exit 1;; esac
-       $(MAKE) -s announcement > ~/announce-$(my_distdir)
+       $(MAKE) --no-print-directory -s announcement > ~/announce-$(my_distdir)
        if test -d $(release_archive_dir); then                 \
          ln $(rel-files) $(release_archive_dir);               \
          chmod a-w $(rel-files);                               \
@@ -1264,3 +1393,103 @@ update-copyright:
        grep -l -w Copyright                                             \
          $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
          | $(update-copyright-env) xargs $(build_aux)/$@
+
+# This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
+# overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
+
+# NOTE: to override any _gl_TS_* default value, you must
+# define the variable(s) using "export" in cfg.mk.
+_gl_TS_dir ?= src
+
+ALL_RECURSIVE_TARGETS += sc_tight_scope
+sc_tight_scope: tight-scope.mk
+       @fail=0;                                                        \
+       if ! grep '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk        \
+               > /dev/null                                             \
+          && ! grep -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
+               > /dev/null 2>&1; then                                  \
+           echo '$(ME): skipping $@';                                  \
+       else                                                            \
+           $(MAKE) -s -C $(_gl_TS_dir)                                 \
+               -f Makefile                                             \
+               -f $(abs_top_srcdir)/cfg.mk                             \
+               -f $(abs_top_builddir)/$<                               \
+             _gl_tight_scope                                           \
+               || fail=1;                                              \
+       fi;                                                             \
+       rm -f $<;                                                       \
+       exit $$fail
+
+tight-scope.mk: $(ME)
+       @rm -f $@ address@hidden
+       @perl -ne '/^# TS-start/.../^# TS-end/ and print' $(ME) > address@hidden
+       @chmod a=r address@hidden && mv address@hidden $@
+
+ifeq (a,b)
+# TS-start
+
+# Most functions should have static scope.
+# Any that don't must be marked with `extern', but `main'
+# and `usage' are exceptions: they're always extern, but
+# do not need to be marked.  Symbols matching `__.*' are
+# reserved by the compiler, so are automatically excluded below.
+_gl_TS_unmarked_extern_functions ?= main usage
+_gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\S+) *\(/
+
+# If your project uses a macro like "XTERN", then put
+# the following in cfg.mk to override this default:
+# export _gl_TS_extern = extern|XTERN
+_gl_TS_extern ?= extern
+
+# The second nm|grep checks for file-scope variables with `extern' scope.
+# Without gnulib's progname module, you might put program_name here.
+# Symbols matching `__.*' are reserved by the compiler,
+# so are automatically excluded below.
+_gl_TS_unmarked_extern_vars ?=
+
+# NOTE: the _match variables are perl expressions -- not mere regular
+# expressions -- so that you can extend them to match other patterns
+# and easily extract matched variable names.
+# For example, if your project declares some global variables via
+# a macro like this: GLOBAL(type, var_name, initializer), then you
+# can override this definition to automatically extract those names:
+# export _gl_TS_var_match = \
+#   /^(?:$(_gl_TS_extern)) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
+_gl_TS_var_match ?= /^(?:$(_gl_TS_extern)) .*?(\w+)(\[.*?\])?;/
+
+# The names of object files in (or relative to) $(_gl_TS_dir).
+_gl_TS_obj_files ?= *.$(OBJEXT)
+
+# Files in which to search for the one-line style extern declarations.
+# $(_gl_TS_dir)-relative.
+_gl_TS_headers ?= $(noinst_HEADERS)
+
+.PHONY: _gl_tight_scope
+_gl_tight_scope: $(bin_PROGRAMS)
+       t=exceptions-$$$$;                                              \
+       trap 's=$$?; rm -f $$t; exit $$s' 0;                            \
+       for sig in 1 2 3 13 15; do                                      \
+         eval "trap 'v=`expr $$sig + 128`; (exit $$v); exit $$v' $$sig"; \
+       done;                                                           \
+       src=`for f in $(SOURCES); do                                    \
+              test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
+       hdr=`for f in $(_gl_TS_headers); do                             \
+              test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
+       ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_functions);  \
+         grep -h -A1 '^extern .*[^;]$$' $$src                          \
+           | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
+         perl -lne                                                     \
+            '$(_gl_TS_function_match) and print "^$$1\$$"' $$hdr;      \
+       ) | sort -u > $$t;                                              \
+       nm -e $(_gl_TS_obj_files) | sed -n 's/.* T //p'|grep -Ev -f $$t \
+         && { echo the above functions should have static scope >&2;   \
+              exit 1; } || : ;                                         \
+       ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_vars);       \
+         perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"' $$hdr *.h \
+       ) | sort -u > $$t;                                              \
+       nm -e $(_gl_TS_obj_files) | sed -n 's/.* [BCDGRS] //p'          \
+            | sort -u | grep -Ev -f $$t                                        
\
+         && { echo the above variables should have static scope >&2;   \
+              exit 1; } || :
+# TS-end
+endif
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dfebc06..53012fa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,7 +31,7 @@ if WANT_TEST_SUITE
 SUBDIRS += suite
 endif
 
-EXTRA_DIST = libgcrypt.supp eagain-common.h
+EXTRA_DIST = suppressions.valgrind eagain-common.h
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
diff --git a/tests/safe-renegotiation/Makefile.am 
b/tests/safe-renegotiation/Makefile.am
index 8b0c658..17d4684 100644
--- a/tests/safe-renegotiation/Makefile.am
+++ b/tests/safe-renegotiation/Makefile.am
@@ -32,4 +32,4 @@ check_PROGRAMS = $(ctests)
 TESTS = $(ctests)
 TESTS_ENVIRONMENT = $(VALGRIND)
 
-EXTRA_DIST = README
+EXTRA_DIST = README suppressions.valgrind
diff --git a/doc/reference/gnutls.types 
b/tests/safe-renegotiation/suppressions.valgrind
similarity index 100%
copy from doc/reference/gnutls.types
copy to tests/safe-renegotiation/suppressions.valgrind
diff --git a/tests/libgcrypt.supp b/tests/suppressions.valgrind
similarity index 100%
rename from tests/libgcrypt.supp
rename to tests/suppressions.valgrind


hooks/post-receive
-- 
GNU gnutls



reply via email to

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