prelude-lml/master: Update GnuLib code

[email protected] Thu, 16 Jul 2009 15:42:30 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 417cbff99881ef2824c6b6bdd6aa8a40d4d674db
Author: Yoann Vandoorselaere <[email protected]>
Date:   Wed Jul 15 17:15:33 2009 +0200

    Update GnuLib code


========================================

 libmissing/Makefile.am              |  411 +++++++++++++++++---
 libmissing/alignof.h                |   53 +++
 libmissing/arpa_inet.in.h           |   10 +
 libmissing/bind.c                   |   40 ++
 libmissing/close-hook.c             |   91 +++++
 libmissing/close-hook.h             |   72 ++++
 libmissing/close.c                  |   11 +-
 libmissing/config.charset           |  683 +++++++++++++++++++++++++++++++++
 libmissing/dirent.in.h              |   98 +++++
 libmissing/dirfd.c                  |   10 +-
 libmissing/dirfd.h                  |   28 --
 libmissing/dummy.c                  |   42 --
 libmissing/errno.in.h               |    9 +-
 libmissing/float.in.h               |    2 +
 libmissing/fnmatch.c                |    4 +-
 libmissing/gai_strerror.c           |    9 +-
 libmissing/getaddrinfo.c            |    2 +-
 libmissing/getaddrinfo.h            |  163 --------
 libmissing/getpagesize.c            |   39 ++
 libmissing/getpeername.c            |   40 ++
 libmissing/gettext.h                |   11 +-
 libmissing/glob.c                   |    4 -
 libmissing/localcharset.c           |  499 ++++++++++++++++++++++++
 libmissing/localcharset.h           |   41 ++
 libmissing/m4/00gnulib.m4           |   30 ++
 libmissing/m4/alloca.m4             |    6 +-
 libmissing/m4/close.m4              |    4 +-
 libmissing/m4/codeset.m4            |   21 +
 libmissing/m4/d-type.m4             |    7 +-
 libmissing/m4/dirent_h.m4           |   43 +++
 libmissing/m4/dirfd.m4              |   19 +-
 libmissing/m4/errno_h.m4            |   30 +-
 libmissing/m4/extensions.m4         |   32 ++-
 libmissing/m4/fnmatch.m4            |  202 +++++-----
 libmissing/m4/getaddrinfo.m4        |   91 +++--
 libmissing/m4/getpagesize.m4        |   29 ++
 libmissing/m4/glibc21.m4            |   30 ++
 libmissing/m4/gnulib-cache.m4       |    7 +-
 libmissing/m4/gnulib-common.m4      |   41 ++-
 libmissing/m4/gnulib-comp.m4        |  133 ++++++--
 libmissing/m4/hostent.m4            |   45 +++
 libmissing/m4/include_next.m4       |  105 ++++--
 libmissing/m4/inet_ntop.m4          |   17 +-
 libmissing/m4/intmax_t.m4           |   16 +-
 libmissing/m4/inttypes_h.m4         |   12 +-
 libmissing/m4/localcharset.m4       |   16 +
 libmissing/m4/locale-fr.m4          |  185 +++++++++
 libmissing/m4/locale-ja.m4          |  107 ++++++
 libmissing/m4/locale-zh.m4          |   92 +++++
 libmissing/m4/longlong.m4           |    8 +-
 libmissing/m4/malloc.m4             |    6 +-
 libmissing/m4/mbrtowc.m4            |  383 +++++++++++++++++++
 libmissing/m4/mbsinit.m4            |   30 ++
 libmissing/m4/mbsrtowcs.m4          |  121 ++++++
 libmissing/m4/mbstate_t.m4          |   16 +-
 libmissing/m4/memchr.m4             |   86 +++++
 libmissing/m4/mempcpy.m4            |    6 +-
 libmissing/m4/memset.m4             |   18 -
 libmissing/m4/mktime.m4             |   30 +-
 libmissing/m4/mmap-anon.m4          |   59 +++
 libmissing/m4/multiarch.m4          |   65 ++++
 libmissing/m4/netdb_h.m4            |   45 +++
 libmissing/m4/pathmax.m4            |    7 +-
 libmissing/m4/printf.m4             |  249 +++++++++----
 libmissing/m4/servent.m4            |   47 +++
 libmissing/m4/signal_h.m4           |   12 +-
 libmissing/m4/signalblocking.m4     |    8 +-
 libmissing/m4/size_max.m4           |   27 +-
 libmissing/m4/sockpfaf.m4           |   20 +-
 libmissing/m4/stdbool.m4            |    4 +-
 libmissing/m4/stdint.m4             |   95 +++++-
 libmissing/m4/stdint_h.m4           |   12 +-
 libmissing/m4/stdio_h.m4            |   13 +-
 libmissing/m4/stdlib_h.m4           |   56 ++-
 libmissing/m4/strcase.m4            |   10 +-
 libmissing/m4/strdup.m4             |   38 --
 libmissing/m4/strerror.m4           |   68 ++++
 libmissing/m4/string_h.m4           |    6 +-
 libmissing/m4/strpbrk.m4            |   18 -
 libmissing/m4/strptime.m4           |    6 +-
 libmissing/m4/strsep.m4             |    6 +-
 libmissing/m4/sys_ioctl_h.m4        |   60 ---
 libmissing/m4/sys_select_h.m4       |    6 +-
 libmissing/m4/sys_socket_h.m4       |   78 +++--
 libmissing/m4/sys_stat_h.m4         |    6 +-
 libmissing/m4/tm_gmtoff.m4          |    6 +-
 libmissing/m4/unistd_h.m4           |   14 +-
 libmissing/m4/vasnprintf.m4         |   56 ++-
 libmissing/m4/wchar.m4              |   43 ++-
 libmissing/m4/wchar_t.m4            |   10 +-
 libmissing/m4/wctob.m4              |   91 +++++
 libmissing/m4/wint_t.m4             |   10 +-
 libmissing/m4/xsize.m4              |    6 +-
 libmissing/mbrtowc.c                |  386 +++++++++++++++++++
 libmissing/mbsinit.c                |   47 +++
 libmissing/mbsrtowcs-state.c        |   37 ++
 libmissing/mbsrtowcs.c              |  136 +++++++
 libmissing/memchr.c                 |  172 +++++++++
 libmissing/memchr.valgrind          |   14 +
 libmissing/memset.c                 |   28 --
 libmissing/netdb.in.h               |  182 +++++++++
 libmissing/netinet_in.in.h          |    2 +
 libmissing/pathmax.h                |    4 +-
 libmissing/raise.c                  |   30 --
 libmissing/recvfrom.c               |   48 +++
 libmissing/ref-add.sin              |   30 ++
 libmissing/ref-del.sin              |   25 ++
 libmissing/sigaction.c              |   13 +
 libmissing/signal.in.h              |   19 +-
 libmissing/sigprocmask.c            |   40 ++-
 libmissing/socket.c                 |   43 +++
 libmissing/stdint.in.h              |  122 ++++--
 libmissing/stdio.in.h               |   54 +++-
 libmissing/stdlib.in.h              |  143 +++++++-
 libmissing/strdup.c                 |   55 ---
 libmissing/streq.h                  |  176 +++++++++
 libmissing/string.in.h              |   19 +-
 libmissing/strings.in.h             |    2 +
 libmissing/strnlen1.c               |   35 ++
 libmissing/strnlen1.h               |   39 ++
 libmissing/strpbrk.c                |   42 --
 libmissing/sys_select.in.h          |   25 +-
 libmissing/sys_socket.in.h          |   47 ++-
 libmissing/sys_stat.in.h            |   76 ++++-
 libmissing/sys_time.in.h            |   10 +
 libmissing/tests/Makefile.am        |  129 ++++++-
 libmissing/tests/strerror.c         |  347 +++++++++++++++++
 libmissing/tests/test-alignof.c     |   59 +++
 libmissing/tests/test-fnmatch.c     |   61 +++
 libmissing/tests/test-getaddrinfo.c |   27 ++-
 libmissing/tests/test-glob.c        |   85 +++++
 libmissing/tests/test-mbrtowc.c     |  330 ++++++++++++++++
 libmissing/tests/test-mbrtowc1.sh   |   15 +
 libmissing/tests/test-mbrtowc2.sh   |   15 +
 libmissing/tests/test-mbrtowc3.sh   |   15 +
 libmissing/tests/test-mbrtowc4.sh   |   15 +
 libmissing/tests/test-mbsinit.c     |   62 +++
 libmissing/tests/test-mbsinit.sh    |   15 +
 libmissing/tests/test-mbsrtowcs.c   |  300 +++++++++++++++
 libmissing/tests/test-mbsrtowcs1.sh |   15 +
 libmissing/tests/test-mbsrtowcs2.sh |   15 +
 libmissing/tests/test-mbsrtowcs3.sh |   15 +
 libmissing/tests/test-mbsrtowcs4.sh |   15 +
 libmissing/tests/test-memchr.c      |  130 +++++++
 libmissing/tests/test-netdb.c       |   29 ++
 libmissing/tests/test-signal.c      |   28 ++
 libmissing/tests/test-stdio.c       |    8 +-
 libmissing/tests/test-stdlib.c      |    8 +-
 libmissing/tests/test-strerror.c    |   65 ++++
 libmissing/tests/test-string.c      |    8 +-
 libmissing/tests/test-sys_socket.c  |    8 +-
 libmissing/tests/test-unistd.c      |   14 +-
 libmissing/tests/verify.h           |  140 -------
 libmissing/tests/wctob.c            |   37 ++
 libmissing/tests/zerosize-ptr.h     |   68 ++++
 libmissing/time.in.h                |    2 +
 libmissing/unistd.in.h              |  171 +++++++++-
 libmissing/vasnprintf.c             |  714 ++++++++++++++++++++++++++++++++---
 libmissing/verify.h                 |  140 +++++++
 libmissing/w32sock.h                |   62 +++
 libmissing/wchar.in.h               |  217 +++++++++++-
 libmissing/wctype.in.h              |    5 +
 libmissing/winsock.c                |  348 -----------------
 link-warning.h                      |   28 ++
 164 files changed, 9793 insertions(+), 1726 deletions(-)

========================================

diff --git a/libmissing/Makefile.am b/libmissing/Makefile.am
index 87b177e..b4075ca 100644
--- a/libmissing/Makefile.am
+++ b/libmissing/Makefile.am
@@ -1,6 +1,6 @@
 ## DO NOT EDIT! GENERATED AUTOMATICALLY!
 ## Process this file with automake to produce Makefile.in.
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 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
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob inet_ntop memset mktime pathmax recvfrom sigaction sleep snprintf socket socklen strdup strptime strsep sys_select
+# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob inet_ntop mktime pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -29,6 +29,7 @@ SUBDIRS += tests
 EXTRA_DIST += m4/gnulib-cache.m4
 
 AM_CPPFLAGS =
+AM_CFLAGS =
 
 noinst_LTLIBRARIES += libmissing.la
 
@@ -38,6 +39,13 @@ libmissing_la_DEPENDENCIES = $(gl_LTLIBOBJS)
 EXTRA_libmissing_la_SOURCES =
 libmissing_la_LDFLAGS = $(AM_LDFLAGS)
 
+## begin gnulib module alignof
+
+
+EXTRA_DIST += alignof.h
+
+## end   gnulib module alignof
+
 ## begin gnulib module alloca
 
 
@@ -72,7 +80,7 @@ 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.h: arpa_inet.in.h
 	@MKDIR_P@ arpa
 	rm -f $@-t $@
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
@@ -98,9 +106,9 @@ EXTRA_DIST += arpa_inet.in.h
 ## begin gnulib module bind
 
 
-EXTRA_DIST += winsock.c
+EXTRA_DIST += bind.c w32sock.h
 
-EXTRA_libmissing_la_SOURCES += winsock.c
+EXTRA_libmissing_la_SOURCES += bind.c
 
 ## end   gnulib module bind
 
@@ -113,10 +121,108 @@ EXTRA_libmissing_la_SOURCES += close.c
 
 ## end   gnulib module close
 
+## begin gnulib module close-hook
+
+libmissing_la_SOURCES += close-hook.c
+
+EXTRA_DIST += close-hook.h
+
+## end   gnulib module close-hook
+
+## begin gnulib module configmake
+
+# Retrieve values of the variables through 'configure' followed by
+# 'make', not directly through 'configure', so that a user who
+# sets some of these variables consistently on the 'make' command
+# line gets correct results.
+#
+# One advantage of this approach, compared to the classical
+# approach of adding -DLIBDIR=\"$(libdir)\" etc. to AM_CPPFLAGS,
+# is that it protects against the use of undefined variables.
+# If, say, $(libdir) is not set in the Makefile, LIBDIR is not
+# defined by this module, and code using LIBDIR gives a
+# compilation error.
+#
+# Another advantage is that 'make' output is shorter.
+#
+# Listed in the same order as the GNU makefile conventions.
+# The Automake-defined pkg* macros are appended, in the order
+# listed in the Automake 1.10a+ documentation.
+configmake.h: Makefile
+	rm -f $@-t
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  echo '#define PREFIX "$(prefix)"'; \
+	  echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
+	  echo '#define BINDIR "$(bindir)"'; \
+	  echo '#define SBINDIR "$(sbindir)"'; \
+	  echo '#define LIBEXECDIR "$(libexecdir)"'; \
+	  echo '#define DATAROOTDIR "$(datarootdir)"'; \
+	  echo '#define DATADIR "$(datadir)"'; \
+	  echo '#define SYSCONFDIR "$(sysconfdir)"'; \
+	  echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \
+	  echo '#define LOCALSTATEDIR "$(localstatedir)"'; \
+	  echo '#define INCLUDEDIR "$(includedir)"'; \
+	  echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \
+	  echo '#define DOCDIR "$(docdir)"'; \
+	  echo '#define INFODIR "$(infodir)"'; \
+	  echo '#define HTMLDIR "$(htmldir)"'; \
+	  echo '#define DVIDIR "$(dvidir)"'; \
+	  echo '#define PDFDIR "$(pdfdir)"'; \
+	  echo '#define PSDIR "$(psdir)"'; \
+	  echo '#define LIBDIR "$(libdir)"'; \
+	  echo '#define LISPDIR "$(lispdir)"'; \
+	  echo '#define LOCALEDIR "$(localedir)"'; \
+	  echo '#define MANDIR "$(mandir)"'; \
+	  echo '#define MANEXT "$(manext)"'; \
+	  echo '#define PKGDATADIR "$(pkgdatadir)"'; \
+	  echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
+	  echo '#define PKGLIBDIR "$(pkglibdir)"'; \
+	  echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
+	} | sed '/""/d' > $@-t
+	if test -f $@ && cmp $@-t $@ > /dev/null; then \
+	  rm -f $@-t; \
+	else \
+	  rm -f $@; mv $@-t $@; \
+	fi
+
+BUILT_SOURCES += configmake.h
+CLEANFILES += configmake.h configmake.h-t
+
+## end   gnulib module configmake
+
+## begin gnulib module dirent
+
+BUILT_SOURCES += $(DIRENT_H)
+
+# We need the following in order to create <dirent.h> when the system
+# doesn't have one that works with the given compiler.
+dirent.h: dirent.in.h
+	rm -f $@-t $@
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_DIRENT_H''@|$(NEXT_DIRENT_H)|g' \
+	      -e 's|@''GNULIB_DIRFD''@|$(GNULIB_DIRFD)|g' \
+	      -e 's|@''GNULIB_SCANDIR''@|$(GNULIB_SCANDIR)|g' \
+	      -e 's|@''GNULIB_ALPHASORT''@|$(GNULIB_ALPHASORT)|g' \
+	      -e 's|@''HAVE_DECL_DIRFD''@|$(HAVE_DECL_DIRFD)|g' \
+	      -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \
+	      -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \
+	      -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
+	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
+	      < $(srcdir)/dirent.in.h; \
+	} > $@-t
+	mv $@-t $@
+MOSTLYCLEANFILES += dirent.h dirent.h-t
+
+EXTRA_DIST += dirent.in.h
+
+## end   gnulib module dirent
+
 ## begin gnulib module dirfd
 
 
-EXTRA_DIST += dirfd.c dirfd.h
+EXTRA_DIST += dirfd.c
 
 EXTRA_libmissing_la_SOURCES += dirfd.c
 
@@ -201,7 +307,7 @@ EXTRA_libmissing_la_SOURCES += fnmatch.c fnmatch_loop.c
 ## begin gnulib module getaddrinfo
 
 
-EXTRA_DIST += gai_strerror.c getaddrinfo.c getaddrinfo.h
+EXTRA_DIST += gai_strerror.c getaddrinfo.c
 
 EXTRA_libmissing_la_SOURCES += gai_strerror.c getaddrinfo.c
 
@@ -216,12 +322,21 @@ EXTRA_libmissing_la_SOURCES += getlogin_r.c
 
 ## end   gnulib module getlogin_r
 
+## begin gnulib module getpagesize
+
+
+EXTRA_DIST += getpagesize.c
+
+EXTRA_libmissing_la_SOURCES += getpagesize.c
+
+## end   gnulib module getpagesize
+
 ## begin gnulib module getpeername
 
 
-EXTRA_DIST += winsock.c
+EXTRA_DIST += getpeername.c w32sock.h
 
-EXTRA_libmissing_la_SOURCES += winsock.c
+EXTRA_libmissing_la_SOURCES += getpeername.c
 
 ## end   gnulib module getpeername
 
@@ -268,6 +383,80 @@ EXTRA_DIST += $(top_srcdir)/./link-warning.h
 
 ## end   gnulib module link-warning
 
+## begin gnulib module localcharset
+
+libmissing_la_SOURCES += localcharset.h localcharset.c
+
+# We need the following in order to install a simple file in $(libdir)
+# which is shared with other installed packages. We use a list of referencing
+# packages so that "make uninstall" will remove the file if and only if it
+# is not used by another installed package.
+# On systems with glibc-2.1 or newer, the file is redundant, therefore we
+# avoid installing it.
+
+all-local: charset.alias ref-add.sed ref-del.sed
+
+charset_alias = $(DESTDIR)$(libdir)/charset.alias
+charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
+install-exec-local: install-exec-localcharset
+install-exec-localcharset: all-local
+	if test $(GLIBC21) = no; then \
+	  case '$(host_os)' in \
+	    darwin[56]*) \
+	      need_charset_alias=true ;; \
+	    darwin* | cygwin* | mingw* | pw32* | cegcc*) \
+	      need_charset_alias=false ;; \
+	    *) \
+	      need_charset_alias=true ;; \
+	  esac ; \
+	else \
+	  need_charset_alias=false ; \
+	fi ; \
+	if $$need_charset_alias; then \
+	  $(mkinstalldirs) $(DESTDIR)$(libdir) ; \
+	fi ; \
+	if test -f $(charset_alias); then \
+	  sed -f ref-add.sed $(charset_alias) > $(charset_tmp) ; \
+	  $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
+	  rm -f $(charset_tmp) ; \
+	else \
+	  if $$need_charset_alias; then \
+	    sed -f ref-add.sed charset.alias > $(charset_tmp) ; \
+	    $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
+	    rm -f $(charset_tmp) ; \
+	  fi ; \
+	fi
+
+uninstall-local: uninstall-localcharset
+uninstall-localcharset: all-local
+	if test -f $(charset_alias); then \
+	  sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \
+	  if grep '^# Packages using this file: $$' $(charset_tmp) \
+	      > /dev/null; then \
+	    rm -f $(charset_alias); \
+	  else \
+	    $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \
+	  fi; \
+	  rm -f $(charset_tmp); \
+	fi
+
+charset.alias: config.charset
+	rm -f t-$@ $@
+	$(SHELL) $(srcdir)/config.charset '$(host)' > t-$@
+	mv t-$@ $@
+
+SUFFIXES += .sed .sin
+.sin.sed:
+	rm -f t-$@ $@
+	sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@
+	mv t-$@ $@
+
+CLEANFILES += charset.alias ref-add.sed ref-del.sed
+
+EXTRA_DIST += config.charset ref-add.sin ref-del.sin
+
+## end   gnulib module localcharset
+
 ## begin gnulib module malloc-posix
 
 
@@ -277,23 +466,50 @@ EXTRA_libmissing_la_SOURCES += malloc.c
 
 ## end   gnulib module malloc-posix
 
-## begin gnulib module mempcpy
+## begin gnulib module mbrtowc
 
 
-EXTRA_DIST += mempcpy.c
+EXTRA_DIST += mbrtowc.c
 
-EXTRA_libmissing_la_SOURCES += mempcpy.c
+EXTRA_libmissing_la_SOURCES += mbrtowc.c
 
-## end   gnulib module mempcpy
+## end   gnulib module mbrtowc
+
+## begin gnulib module mbsinit
+
+
+EXTRA_DIST += mbsinit.c
+
+EXTRA_libmissing_la_SOURCES += mbsinit.c
 
-## begin gnulib module memset
+## end   gnulib module mbsinit
 
+## begin gnulib module mbsrtowcs
 
-EXTRA_DIST += memset.c
 
-EXTRA_libmissing_la_SOURCES += memset.c
+EXTRA_DIST += mbsrtowcs-state.c mbsrtowcs.c
 
-## end   gnulib module memset
+EXTRA_libmissing_la_SOURCES += mbsrtowcs-state.c mbsrtowcs.c
+
+## end   gnulib module mbsrtowcs
+
+## begin gnulib module memchr
+
+
+EXTRA_DIST += memchr.c memchr.valgrind
+
+EXTRA_libmissing_la_SOURCES += memchr.c
+
+## end   gnulib module memchr
+
+## begin gnulib module mempcpy
+
+
+EXTRA_DIST += mempcpy.c
+
+EXTRA_libmissing_la_SOURCES += mempcpy.c
+
+## end   gnulib module mempcpy
 
 ## begin gnulib module mktime
 
@@ -304,6 +520,34 @@ EXTRA_libmissing_la_SOURCES += mktime.c
 
 ## end   gnulib module mktime
 
+## 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
+	rm -f $@-t $@
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|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|@''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' \
+	      < $(srcdir)/netdb.in.h; \
+	} > $@-t
+	mv $@-t $@
+MOSTLYCLEANFILES += netdb.h netdb.h-t
+
+EXTRA_DIST += netdb.in.h
+
+## end   gnulib module netdb
+
 ## begin gnulib module netinet_in
 
 BUILT_SOURCES += $(NETINET_IN_H)
@@ -335,21 +579,12 @@ EXTRA_DIST += pathmax.h
 
 ## end   gnulib module pathmax
 
-## begin gnulib module raise
-
-
-EXTRA_DIST += raise.c
-
-EXTRA_libmissing_la_SOURCES += raise.c
-
-## end   gnulib module raise
-
 ## begin gnulib module recvfrom
 
 
-EXTRA_DIST += winsock.c
+EXTRA_DIST += recvfrom.c w32sock.h
 
-EXTRA_libmissing_la_SOURCES += winsock.c
+EXTRA_libmissing_la_SOURCES += recvfrom.c
 
 ## end   gnulib module recvfrom
 
@@ -382,6 +617,7 @@ signal.h: signal.in.h
 	      -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 '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/signal.in.h; \
 	} > $@-t
@@ -428,9 +664,9 @@ EXTRA_libmissing_la_SOURCES += snprintf.c
 ## begin gnulib module socket
 
 
-EXTRA_DIST += winsock.c
+EXTRA_DIST += socket.c w32sock.h
 
-EXTRA_libmissing_la_SOURCES += winsock.c
+EXTRA_libmissing_la_SOURCES += socket.c
 
 ## end   gnulib module socket
 
@@ -471,6 +707,7 @@ stdint.h: stdint.in.h
 	      -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/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/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
 	      -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \
 	      -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \
 	      -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \
@@ -517,6 +754,8 @@ stdio.h: stdio.in.h
 	      -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_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \
 	      -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
 	      -e 's|@''GNULIB_OBSTACK_PRINTF''@|$(GNULIB_OBSTACK_PRINTF)|g' \
 	      -e 's|@''GNULIB_OBSTACK_PRINTF_POSIX''@|$(GNULIB_OBSTACK_PRINTF_POSIX)|g' \
@@ -527,6 +766,7 @@ stdio.h: stdio.in.h
 	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
 	      -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
 	      -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
+	      -e 's|@''GNULIB_FPURGE''@|$(GNULIB_FPURGE)|g' \
 	      -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
 	      -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
 	      -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
@@ -549,6 +789,10 @@ stdio.h: stdio.in.h
 	      -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
 	      -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
 	      -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
+	      -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
+	      -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
+	      -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
+	      -e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \
 	      -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
 	      -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
 	      -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \
@@ -560,6 +804,8 @@ stdio.h: stdio.in.h
 	      -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
 	      -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
 	      -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
+	      -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \
+	      -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
 	      -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
 	      -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
 	      -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
@@ -589,26 +835,39 @@ stdlib.h: stdlib.in.h
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
+	      -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
 	      -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
 	      -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
 	      -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
+	      -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
+	      -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
 	      -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
 	      -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
 	      -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
 	      -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
+	      -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|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_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+	      -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
 	      -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
 	      -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
 	      -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
 	      -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
 	      -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
+	      -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
 	      -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
 	      -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
 	      -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
+	      -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
+	      -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
+	      -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
+	      -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
 	      -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
+	      -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
 	      -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
 	      -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
 	      -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
@@ -632,14 +891,12 @@ EXTRA_libmissing_la_SOURCES += strcasecmp.c strncasecmp.c
 
 ## end   gnulib module strcase
 
-## begin gnulib module strdup
+## begin gnulib module streq
 
 
-EXTRA_DIST += strdup.c
+EXTRA_DIST += streq.h
 
-EXTRA_libmissing_la_SOURCES += strdup.c
-
-## end   gnulib module strdup
+## end   gnulib module streq
 
 ## begin gnulib module string
 
@@ -667,6 +924,7 @@ string.h: string.in.h
 	      -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' \
@@ -703,6 +961,7 @@ string.h: string.in.h
 	      -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \
 	      -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
 	      -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
+	      -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
 	      -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
 	      -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
 	      -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
@@ -743,14 +1002,11 @@ EXTRA_DIST += strings.in.h
 
 ## end   gnulib module strings
 
-## begin gnulib module strpbrk
-
+## begin gnulib module strnlen1
 
-EXTRA_DIST += strpbrk.c
+libmissing_la_SOURCES += strnlen1.h strnlen1.c
 
-EXTRA_libmissing_la_SOURCES += strpbrk.c
-
-## end   gnulib module strpbrk
+## end   gnulib module strnlen1
 
 ## begin gnulib module strptime
 
@@ -786,6 +1042,7 @@ sys/select.h: sys_select.in.h
 	      -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \
 	      -e 's|@''GNULIB_SELECT''@|$(GNULIB_SELECT)|g' \
 	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/sys_select.in.h; \
 	} > $@-t
@@ -820,13 +1077,15 @@ sys/socket.h: sys_socket.in.h
 	      -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_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|@''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' \
+	      -e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/sys_socket.in.h; \
 	} > $@-t
@@ -834,9 +1093,7 @@ sys/socket.h: sys_socket.in.h
 MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
 MOSTLYCLEANDIRS += sys
 
-EXTRA_DIST += sys_socket.in.h winsock.c
-
-EXTRA_libmissing_la_SOURCES += winsock.c
+EXTRA_DIST += sys_socket.in.h
 
 ## end   gnulib module sys_socket
 
@@ -853,8 +1110,13 @@ sys/stat.h: sys_stat.in.h
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
+	      -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \
+	      -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \
+	      -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
 	      -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
+	      -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
 	      -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
+	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/sys_stat.in.h; \
 	} > $@-t
 	mv $@-t $@
@@ -943,24 +1205,34 @@ unistd.h: unistd.in.h
 	      -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
 	      -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
 	      -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
+	      -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
 	      -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|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_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|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_LSEEK''@|$(GNULIB_LSEEK)|g' \
 	      -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
 	      -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
 	      -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \
 	      -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \
 	      -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
+	      -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
 	      -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
 	      -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
+	      -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \
 	      -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
+	      -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
 	      -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
+	      -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \
+	      -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
 	      -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
 	      -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
 	      -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
@@ -995,6 +1267,12 @@ EXTRA_libmissing_la_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprin
 
 ## end   gnulib module vasnprintf
 
+## begin gnulib module verify
+
+libmissing_la_SOURCES += verify.h
+
+## end   gnulib module verify
+
 ## begin gnulib module wchar
 
 BUILT_SOURCES += $(WCHAR_H)
@@ -1007,10 +1285,41 @@ wchar.h: wchar.in.h
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
-	      -e 's/@''HAVE_WCHAR_H''@/$(HAVE_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/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
+	      -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_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
 	      -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
+	      -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 '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	    < $(srcdir)/wchar.in.h; \
@@ -1053,12 +1362,6 @@ libmissing_la_SOURCES += xsize.h
 
 ## end   gnulib module xsize
 
-## begin gnulib module dummy
-
-libmissing_la_SOURCES += dummy.c
-
-## end   gnulib module dummy
-
 
 mostlyclean-local: mostlyclean-generic
 	@for dir in '' $(MOSTLYCLEANDIRS); do \
@@ -1067,5 +1370,3 @@ mostlyclean-local: mostlyclean-generic
 	  fi; \
 	done; \
 	:
-
--include $(top_srcdir)/git.mk
diff --git a/libmissing/alignof.h b/libmissing/alignof.h
new file mode 100644
index 0000000..28ce79c
--- /dev/null
+++ b/libmissing/alignof.h
@@ -0,0 +1,53 @@
+/* Determine alignment of types.
+   Copyright (C) 2003-2004, 2006, 2009 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, 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 _ALIGNOF_H
+#define _ALIGNOF_H
+
+#include <stddef.h>
+
+/* Determine the alignment of a structure slot (field) of a given type,
+   at compile time.  Note that the result depends on the ABI.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __cplusplus
+  template <class type> struct alignof_helper { char __slot1; type __slot2; };
+# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
+#else
+# 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.
+   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,
+   - when -malign-double is specified:      alignof_slot(double) = 8.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __GNUC__
+# define alignof_type __alignof__
+#else
+# define alignof_type alignof_slot
+#endif
+
+/* alignof is an alias for alignof_slot semantics, since that's what most
+   callers need.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#define alignof alignof_slot
+
+#endif /* _ALIGNOF_H */
diff --git a/libmissing/arpa_inet.in.h b/libmissing/arpa_inet.in.h
index e55df12..85ea0d0 100644
--- a/libmissing/arpa_inet.in.h
+++ b/libmissing/arpa_inet.in.h
@@ -24,7 +24,9 @@
 
 #if @HAVE_ARPA_INET_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
@@ -36,6 +38,10 @@
 
 /* The definition of GL_LINK_WARNING is copied here.  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if @GNULIB_INET_NTOP@
 # if !@HAVE_DECL_INET_NTOP@
 /* Converts an internet address from internal format to a printable,
@@ -76,5 +82,9 @@ extern int inet_pton (int af, const char *restrict src, void *restrict dst);
    inet_pton (af, src, dst))
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _GL_ARPA_INET_H */
 #endif /* _GL_ARPA_INET_H */
diff --git a/libmissing/bind.c b/libmissing/bind.c
new file mode 100644
index 0000000..8cd88db
--- /dev/null
+++ b/libmissing/bind.c
@@ -0,0 +1,40 @@
+/* bind.c --- wrappers for Windows bind function
+
+   Copyright (C) 2008 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 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 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/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef bind
+
+int
+rpl_bind (int fd, struct sockaddr *sockaddr, int len)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = bind (sock, sockaddr, len);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/libmissing/close-hook.c b/libmissing/close-hook.c
new file mode 100644
index 0000000..afe8e56
--- /dev/null
+++ b/libmissing/close-hook.c
@@ -0,0 +1,91 @@
+/* Hook for making the close() function extensible.
+   Copyright (C) 2009 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 2009.
+
+   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 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
+   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 "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/libmissing/close-hook.h b/libmissing/close-hook.h
new file mode 100644
index 0000000..7369be1
--- /dev/null
+++ b/libmissing/close-hook.h
@@ -0,0 +1,72 @@
+/* Hook for making the close() function extensible.
+   Copyright (C) 2009 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 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
+   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/>.  */
+
+
+#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/libmissing/close.c b/libmissing/close.c
index 3a50ff2..9671aca 100644
--- a/libmissing/close.c
+++ b/libmissing/close.c
@@ -1,5 +1,5 @@
 /* close replacement.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 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
@@ -19,10 +19,7 @@
 /* Specification.  */
 #include <unistd.h>
 
-#if GNULIB_SYS_SOCKET
-# include <sys/socket.h>
-#endif
-
+#include "close-hook.h"
 
 /* Override close() to call into other gnulib modules.  */
 
@@ -30,8 +27,8 @@ int
 rpl_close (int fd)
 #undef close
 {
-#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
-  int retval = _gl_close_fd_maybe_socket (fd);
+#if WINDOWS_SOCKETS
+  int retval = execute_all_close_hooks (fd);
 #else
   int retval = close (fd);
 #endif
diff --git a/libmissing/config.charset b/libmissing/config.charset
new file mode 100755
index 0000000..c1a7f5d
--- /dev/null
+++ b/libmissing/config.charset
@@ -0,0 +1,683 @@
+#! /bin/sh
+# Output a system dependent table of character encoding aliases.
+#
+#   Copyright (C) 2000-2004, 2006-2009 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, 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.
+#
+# The table consists of lines of the form
+#    ALIAS  CANONICAL
+#
+# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)".
+# ALIAS is compared in a case sensitive way.
+#
+# CANONICAL is the GNU canonical name for this character encoding.
+# It must be an encoding supported by libiconv. Support by GNU libc is
+# also desirable. CANONICAL is case insensitive. Usually an upper case
+# MIME charset name is preferred.
+# The current list of GNU canonical charset names is as follows.
+#
+#       name              MIME?             used by which systems
+#   ASCII, ANSI_X3.4-1968       glibc solaris freebsd netbsd darwin
+#   ISO-8859-1              Y   glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
+#   ISO-8859-2              Y   glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
+#   ISO-8859-3              Y   glibc solaris
+#   ISO-8859-4              Y   osf solaris freebsd netbsd openbsd darwin
+#   ISO-8859-5              Y   glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
+#   ISO-8859-6              Y   glibc aix hpux solaris
+#   ISO-8859-7              Y   glibc aix hpux irix osf solaris netbsd openbsd darwin
+#   ISO-8859-8              Y   glibc aix hpux osf solaris
+#   ISO-8859-9              Y   glibc aix hpux irix osf solaris darwin
+#   ISO-8859-13                 glibc netbsd openbsd darwin
+#   ISO-8859-14                 glibc
+#   ISO-8859-15                 glibc aix osf solaris freebsd netbsd openbsd darwin
+#   KOI8-R                  Y   glibc solaris freebsd netbsd openbsd darwin
+#   KOI8-U                  Y   glibc freebsd netbsd openbsd darwin
+#   KOI8-T                      glibc
+#   CP437                       dos
+#   CP775                       dos
+#   CP850                       aix osf dos
+#   CP852                       dos
+#   CP855                       dos
+#   CP856                       aix
+#   CP857                       dos
+#   CP861                       dos
+#   CP862                       dos
+#   CP864                       dos
+#   CP865                       dos
+#   CP866                       freebsd netbsd openbsd darwin dos
+#   CP869                       dos
+#   CP874                       woe32 dos
+#   CP922                       aix
+#   CP932                       aix woe32 dos
+#   CP943                       aix
+#   CP949                       osf darwin woe32 dos
+#   CP950                       woe32 dos
+#   CP1046                      aix
+#   CP1124                      aix
+#   CP1125                      dos
+#   CP1129                      aix
+#   CP1131                      darwin
+#   CP1250                      woe32
+#   CP1251                      glibc solaris netbsd openbsd darwin woe32
+#   CP1252                      aix woe32
+#   CP1253                      woe32
+#   CP1254                      woe32
+#   CP1255                      glibc woe32
+#   CP1256                      woe32
+#   CP1257                      woe32
+#   GB2312                  Y   glibc aix hpux irix solaris freebsd netbsd darwin
+#   EUC-JP                  Y   glibc aix hpux irix osf solaris freebsd netbsd darwin
+#   EUC-KR                  Y   glibc aix hpux irix osf solaris freebsd netbsd darwin
+#   EUC-TW                      glibc aix hpux irix osf solaris netbsd
+#   BIG5                    Y   glibc aix hpux osf solaris freebsd netbsd darwin
+#   BIG5-HKSCS                  glibc solaris darwin
+#   GBK                         glibc aix osf solaris darwin woe32 dos
+#   GB18030                     glibc solaris netbsd darwin
+#   SHIFT_JIS               Y   hpux osf solaris freebsd netbsd darwin
+#   JOHAB                       glibc solaris woe32
+#   TIS-620                     glibc aix hpux osf solaris
+#   VISCII                  Y   glibc
+#   TCVN5712-1                  glibc
+#   ARMSCII-8                   glibc darwin
+#   GEORGIAN-PS                 glibc
+#   PT154                       glibc
+#   HP-ROMAN8                   hpux
+#   HP-ARABIC8                  hpux
+#   HP-GREEK8                   hpux
+#   HP-HEBREW8                  hpux
+#   HP-TURKISH8                 hpux
+#   HP-KANA8                    hpux
+#   DEC-KANJI                   osf
+#   DEC-HANYU                   osf
+#   UTF-8                   Y   glibc aix hpux osf solaris netbsd darwin
+#
+# Note: Names which are not marked as being a MIME name should not be used in
+# Internet protocols for information interchange (mail, news, etc.).
+#
+# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
+# must understand both names and treat them as equivalent.
+#
+# The first argument passed to this file is the canonical host specification,
+#    CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or
+#    CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+
+host="$1"
+os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'`
+echo "# This file contains a table of character encoding aliases,"
+echo "# suitable for operating system '${os}'."
+echo "# It was automatically generated from config.charset."
+# List of references, updated during installation:
+echo "# Packages using this file: "
+case "$os" in
+    linux-gnulibc1*)
+	# Linux libc5 doesn't have nl_langinfo(CODESET); therefore
+	# localcharset.c falls back to using the full locale name
+	# from the environment variables.
+	echo "C ASCII"
+	echo "POSIX ASCII"
+	for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \
+	         en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \
+	         en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \
+	         es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \
+	         et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \
+	         fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \
+	         it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \
+	         sv_FI sv_SE; do
+	  echo "$l ISO-8859-1"
+	  echo "$l.iso-8859-1 ISO-8859-1"
+	  echo "$l.iso-8859-15 ISO-8859-15"
+	  echo "$l.iso-8859-15@euro ISO-8859-15"
+	  echo "$l@euro ISO-8859-15"
+	  echo "$l.cp-437 CP437"
+	  echo "$l.cp-850 CP850"
+	  echo "$l.cp-1252 CP1252"
+	  echo "$l.cp-1252@euro CP1252"
+	  #echo "$l.atari-st ATARI-ST" # not a commonly used encoding
+	  echo "$l.utf-8 UTF-8"
+	  echo "$l.utf-8@euro UTF-8"
+	done
+	for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \
+	         sl_SI sr sr_CS sr_YU; do
+	  echo "$l ISO-8859-2"
+	  echo "$l.iso-8859-2 ISO-8859-2"
+	  echo "$l.cp-852 CP852"
+	  echo "$l.cp-1250 CP1250"
+	  echo "$l.utf-8 UTF-8"
+	done
+	for l in mk mk_MK ru ru_RU; do
+	  echo "$l ISO-8859-5"
+	  echo "$l.iso-8859-5 ISO-8859-5"
+	  echo "$l.koi8-r KOI8-R"
+	  echo "$l.cp-866 CP866"
+	  echo "$l.cp-1251 CP1251"
+	  echo "$l.utf-8 UTF-8"
+	done
+	for l in ar ar_SA; do
+	  echo "$l ISO-8859-6"
+	  echo "$l.iso-8859-6 ISO-8859-6"
+	  echo "$l.cp-864 CP864"
+	  #echo "$l.cp-868 CP868" # not a commonly used encoding
+	  echo "$l.cp-1256 CP1256"
+	  echo "$l.utf-8 UTF-8"
+	done
+	for l in el el_GR gr gr_GR; do
+	  echo "$l ISO-8859-7"
+	  echo "$l.iso-8859-7 ISO-8859-7"
+	  echo "$l.cp-869 CP869"
+	  echo "$l.cp-1253 CP1253"
+	  echo "$l.cp-1253@euro CP1253"
+	  echo "$l.utf-8 UTF-8"
+	  echo "$l.utf-8@euro UTF-8"
+	done
+	for l in he he_IL iw iw_IL; do
+	  echo "$l ISO-8859-8"
+	  echo "$l.iso-8859-8 ISO-8859-8"
+	  echo "$l.cp-862 CP862"
+	  echo "$l.cp-1255 CP1255"
+	  echo "$l.utf-8 UTF-8"
+	done
+	for l in tr tr_TR; do
+	  echo "$l ISO-8859-9"
+	  echo "$l.iso-8859-9 ISO-8859-9"
+	  echo "$l.cp-857 CP857"
+	  echo "$l.cp-1254 CP1254"
+	  echo "$l.utf-8 UTF-8"
+	done
+	for l in lt lt_LT lv lv_LV; do
+	  #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name
+	  echo "$l ISO-8859-13"
+	done
+	for l in ru_UA uk uk_UA; do
+	  echo "$l KOI8-U"
+	done
+	for l in zh zh_CN; do
+	  #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name
+	  echo "$l GB2312"
+	done
+	for l in ja ja_JP ja_JP.EUC; do
+	  echo "$l EUC-JP"
+	done
+	for l in ko ko_KR; do
+	  echo "$l EUC-KR"
+	done
+	for l in th th_TH; do
+	  echo "$l TIS-620"
+	done
+	for l in fa fa_IR; do
+	  #echo "$l ISIRI-3342" # a broken encoding
+	  echo "$l.utf-8 UTF-8"
+	done
+	;;
+    linux* | *-gnu*)
+	# With glibc-2.1 or newer, we don't need any canonicalization,
+	# because glibc has iconv and both glibc and libiconv support all
+	# GNU canonical names directly. Therefore, the Makefile does not
+	# need to install the alias file at all.
+	# The following applies only to glibc-2.0.x and older libcs.
+	echo "ISO_646.IRV:1983 ASCII"
+	;;
+    aix*)
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-6 ISO-8859-6"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-8 ISO-8859-8"
+	echo "ISO8859-9 ISO-8859-9"
+	echo "ISO8859-15 ISO-8859-15"
+	echo "IBM-850 CP850"
+	echo "IBM-856 CP856"
+	echo "IBM-921 ISO-8859-13"
+	echo "IBM-922 CP922"
+	echo "IBM-932 CP932"
+	echo "IBM-943 CP943"
+	echo "IBM-1046 CP1046"
+	echo "IBM-1124 CP1124"
+	echo "IBM-1129 CP1129"
+	echo "IBM-1252 CP1252"
+	echo "IBM-eucCN GB2312"
+	echo "IBM-eucJP EUC-JP"
+	echo "IBM-eucKR EUC-KR"
+	echo "IBM-eucTW EUC-TW"
+	echo "big5 BIG5"
+	echo "GBK GBK"
+	echo "TIS-620 TIS-620"
+	echo "UTF-8 UTF-8"
+	;;
+    hpux*)
+	echo "iso88591 ISO-8859-1"
+	echo "iso88592 ISO-8859-2"
+	echo "iso88595 ISO-8859-5"
+	echo "iso88596 ISO-8859-6"
+	echo "iso88597 ISO-8859-7"
+	echo "iso88598 ISO-8859-8"
+	echo "iso88599 ISO-8859-9"
+	echo "iso885915 ISO-8859-15"
+	echo "roman8 HP-ROMAN8"
+	echo "arabic8 HP-ARABIC8"
+	echo "greek8 HP-GREEK8"
+	echo "hebrew8 HP-HEBREW8"
+	echo "turkish8 HP-TURKISH8"
+	echo "kana8 HP-KANA8"
+	echo "tis620 TIS-620"
+	echo "big5 BIG5"
+	echo "eucJP EUC-JP"
+	echo "eucKR EUC-KR"
+	echo "eucTW EUC-TW"
+	echo "hp15CN GB2312"
+	#echo "ccdc ?" # what is this?
+	echo "SJIS SHIFT_JIS"
+	echo "utf8 UTF-8"
+	;;
+    irix*)
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-9 ISO-8859-9"
+	echo "eucCN GB2312"
+	echo "eucJP EUC-JP"
+	echo "eucKR EUC-KR"
+	echo "eucTW EUC-TW"
+	;;
+    osf*)
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-4 ISO-8859-4"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-8 ISO-8859-8"
+	echo "ISO8859-9 ISO-8859-9"
+	echo "ISO8859-15 ISO-8859-15"
+	echo "cp850 CP850"
+	echo "big5 BIG5"
+	echo "dechanyu DEC-HANYU"
+	echo "dechanzi GB2312"
+	echo "deckanji DEC-KANJI"
+	echo "deckorean EUC-KR"
+	echo "eucJP EUC-JP"
+	echo "eucKR EUC-KR"
+	echo "eucTW EUC-TW"
+	echo "GBK GBK"
+	echo "KSC5601 CP949"
+	echo "sdeckanji EUC-JP"
+	echo "SJIS SHIFT_JIS"
+	echo "TACTIS TIS-620"
+	echo "UTF-8 UTF-8"
+	;;
+    solaris*)
+	echo "646 ASCII"
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-3 ISO-8859-3"
+	echo "ISO8859-4 ISO-8859-4"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-6 ISO-8859-6"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-8 ISO-8859-8"
+	echo "ISO8859-9 ISO-8859-9"
+	echo "ISO8859-15 ISO-8859-15"
+	echo "koi8-r KOI8-R"
+	echo "ansi-1251 CP1251"
+	echo "BIG5 BIG5"
+	echo "Big5-HKSCS BIG5-HKSCS"
+	echo "gb2312 GB2312"
+	echo "GBK GBK"
+	echo "GB18030 GB18030"
+	echo "cns11643 EUC-TW"
+	echo "5601 EUC-KR"
+	echo "ko_KR.johap92 JOHAB"
+	echo "eucJP EUC-JP"
+	echo "PCK SHIFT_JIS"
+	echo "TIS620.2533 TIS-620"
+	#echo "sun_eu_greek ?" # what is this?
+	echo "UTF-8 UTF-8"
+	;;
+    freebsd* | os2*)
+	# FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
+	# localcharset.c falls back to using the full locale name
+	# from the environment variables.
+	# Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
+	# reuse FreeBSD's locale data for OS/2.
+	echo "C ASCII"
+	echo "US-ASCII ASCII"
+	for l in la_LN lt_LN; do
+	  echo "$l.ASCII ASCII"
+	done
+	for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
+	         fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
+	         lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
+	  echo "$l.ISO_8859-1 ISO-8859-1"
+	  echo "$l.DIS_8859-15 ISO-8859-15"
+	done
+	for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
+	  echo "$l.ISO_8859-2 ISO-8859-2"
+	done
+	for l in la_LN lt_LT; do
+	  echo "$l.ISO_8859-4 ISO-8859-4"
+	done
+	for l in ru_RU ru_SU; do
+	  echo "$l.KOI8-R KOI8-R"
+	  echo "$l.ISO_8859-5 ISO-8859-5"
+	  echo "$l.CP866 CP866"
+	done
+	echo "uk_UA.KOI8-U KOI8-U"
+	echo "zh_TW.BIG5 BIG5"
+	echo "zh_TW.Big5 BIG5"
+	echo "zh_CN.EUC GB2312"
+	echo "ja_JP.EUC EUC-JP"
+	echo "ja_JP.SJIS SHIFT_JIS"
+	echo "ja_JP.Shift_JIS SHIFT_JIS"
+	echo "ko_KR.EUC EUC-KR"
+	;;
+    netbsd*)
+	echo "646 ASCII"
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-4 ISO-8859-4"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-13 ISO-8859-13"
+	echo "ISO8859-15 ISO-8859-15"
+	echo "eucCN GB2312"
+	echo "eucJP EUC-JP"
+	echo "eucKR EUC-KR"
+	echo "eucTW EUC-TW"
+	echo "BIG5 BIG5"
+	echo "SJIS SHIFT_JIS"
+	;;
+    openbsd*)
+	echo "646 ASCII"
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-4 ISO-8859-4"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-13 ISO-8859-13"
+	echo "ISO8859-15 ISO-8859-15"
+	;;
+    darwin[56]*)
+	# Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore
+	# localcharset.c falls back to using the full locale name
+	# from the environment variables.
+	echo "C ASCII"
+	for l in en_AU en_CA en_GB en_US la_LN; do
+	  echo "$l.US-ASCII ASCII"
+	done
+	for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
+	         fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \
+	         nl_NL no_NO pt_PT sv_SE; do
+	  echo "$l ISO-8859-1"
+	  echo "$l.ISO8859-1 ISO-8859-1"
+	  echo "$l.ISO8859-15 ISO-8859-15"
+	done
+	for l in la_LN; do
+	  echo "$l.ISO8859-1 ISO-8859-1"
+	  echo "$l.ISO8859-15 ISO-8859-15"
+	done
+	for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do
+	  echo "$l.ISO8859-2 ISO-8859-2"
+	done
+	for l in la_LN lt_LT; do
+	  echo "$l.ISO8859-4 ISO-8859-4"
+	done
+	for l in ru_RU; do
+	  echo "$l.KOI8-R KOI8-R"
+	  echo "$l.ISO8859-5 ISO-8859-5"
+	  echo "$l.CP866 CP866"
+	done
+	for l in bg_BG; do
+	  echo "$l.CP1251 CP1251"
+	done
+	echo "uk_UA.KOI8-U KOI8-U"
+	echo "zh_TW.BIG5 BIG5"
+	echo "zh_TW.Big5 BIG5"
+	echo "zh_CN.EUC GB2312"
+	echo "ja_JP.EUC EUC-JP"
+	echo "ja_JP.SJIS SHIFT_JIS"
+	echo "ko_KR.EUC EUC-KR"
+	;;
+    darwin*)
+	# Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
+	# useless:
+	# - It returns the empty string when LANG is set to a locale of the
+	#   form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
+	#   LC_CTYPE file.
+	# - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
+	#   the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
+	# - The documentation says:
+	#     "... all code that calls BSD system routines should ensure
+	#      that the const *char parameters of these routines are in UTF-8
+	#      encoding. All BSD system functions expect their string
+	#      parameters to be in UTF-8 encoding and nothing else."
+	#   It also says
+	#     "An additional caveat is that string parameters for files,
+	#      paths, and other file-system entities must be in canonical
+	#      UTF-8. In a canonical UTF-8 Unicode string, all decomposable
+	#      characters are decomposed ..."
+	#   but this is not true: You can pass non-decomposed UTF-8 strings
+	#   to file system functions, and it is the OS which will convert
+	#   them to decomposed UTF-8 before accessing the file system.
+	# - The Apple Terminal application displays UTF-8 by default.
+	# - However, other applications are free to use different encodings:
+	#   - xterm uses ISO-8859-1 by default.
+	#   - TextEdit uses MacRoman by default.
+	# We prefer UTF-8 over decomposed UTF-8-MAC because one should
+	# minimize the use of decomposed Unicode. Unfortunately, through the
+	# Darwin file system, decomposed UTF-8 strings are leaked into user
+	# space nevertheless.
+	# Then there are also the locales with encodings other than US-ASCII
+	# and UTF-8. These locales can be occasionally useful to users (e.g.
+	# when grepping through ISO-8859-1 encoded text files), when all their
+	# file names are in US-ASCII.
+	echo "ISO8859-1 ISO-8859-1"
+	echo "ISO8859-2 ISO-8859-2"
+	echo "ISO8859-4 ISO-8859-4"
+	echo "ISO8859-5 ISO-8859-5"
+	echo "ISO8859-7 ISO-8859-7"
+	echo "ISO8859-9 ISO-8859-9"
+	echo "ISO8859-13 ISO-8859-13"
+	echo "ISO8859-15 ISO-8859-15"
+	echo "KOI8-R KOI8-R"
+	echo "KOI8-U KOI8-U"
+	echo "CP866 CP866"
+	echo "CP949 CP949"
+	echo "CP1131 CP1131"
+	echo "CP1251 CP1251"
+	echo "eucCN GB2312"
+	echo "GB2312 GB2312"
+	echo "eucJP EUC-JP"
+	echo "eucKR EUC-KR"
+	echo "Big5 BIG5"
+	echo "Big5HKSCS BIG5-HKSCS"
+	echo "GBK GBK"
+	echo "GB18030 GB18030"
+	echo "SJIS SHIFT_JIS"
+	echo "ARMSCII-8 ARMSCII-8"
+	echo "PT154 PT154"
+	#echo "ISCII-DEV ?"
+	echo "* UTF-8"
+	;;
+    beos* | haiku*)
+	# BeOS and Haiku have a single locale, and it has UTF-8 encoding.
+	echo "* UTF-8"
+	;;
+    msdosdjgpp*)
+	# DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
+	# localcharset.c falls back to using the full locale name
+	# from the environment variables.
+	echo "#"
+	echo "# The encodings given here may not all be correct."
+	echo "# If you find that the encoding given for your language and"
+	echo "# country is not the one your DOS machine actually uses, just"
+	echo "# correct it in this file, and send a mail to"
+	echo "# Juan Manuel Guerrero <[email protected]>"
+	echo "# and Bruno Haible <[email protected]>."
+	echo "#"
+	echo "C ASCII"
+	# ISO-8859-1 languages
+	echo "ca CP850"
+	echo "ca_ES CP850"
+	echo "da CP865"    # not CP850 ??
+	echo "da_DK CP865" # not CP850 ??
+	echo "de CP850"
+	echo "de_AT CP850"
+	echo "de_CH CP850"
+	echo "de_DE CP850"
+	echo "en CP850"
+	echo "en_AU CP850" # not CP437 ??
+	echo "en_CA CP850"
+	echo "en_GB CP850"
+	echo "en_NZ CP437"
+	echo "en_US CP437"
+	echo "en_ZA CP850" # not CP437 ??
+	echo "es CP850"
+	echo "es_AR CP850"
+	echo "es_BO CP850"
+	echo "es_CL CP850"
+	echo "es_CO CP850"
+	echo "es_CR CP850"
+	echo "es_CU CP850"
+	echo "es_DO CP850"
+	echo "es_EC CP850"
+	echo "es_ES CP850"
+	echo "es_GT CP850"
+	echo "es_HN CP850"
+	echo "es_MX CP850"
+	echo "es_NI CP850"
+	echo "es_PA CP850"
+	echo "es_PY CP850"
+	echo "es_PE CP850"
+	echo "es_SV CP850"
+	echo "es_UY CP850"
+	echo "es_VE CP850"
+	echo "et CP850"
+	echo "et_EE CP850"
+	echo "eu CP850"
+	echo "eu_ES CP850"
+	echo "fi CP850"
+	echo "fi_FI CP850"
+	echo "fr CP850"
+	echo "fr_BE CP850"
+	echo "fr_CA CP850"
+	echo "fr_CH CP850"
+	echo "fr_FR CP850"
+	echo "ga CP850"
+	echo "ga_IE CP850"
+	echo "gd CP850"
+	echo "gd_GB CP850"
+	echo "gl CP850"
+	echo "gl_ES CP850"
+	echo "id CP850"    # not CP437 ??
+	echo "id_ID CP850" # not CP437 ??
+	echo "is CP861"    # not CP850 ??
+	echo "is_IS CP861" # not CP850 ??
+	echo "it CP850"
+	echo "it_CH CP850"
+	echo "it_IT CP850"
+	echo "lt CP775"
+	echo "lt_LT CP775"
+	echo "lv CP775"
+	echo "lv_LV CP775"
+	echo "nb CP865"    # not CP850 ??
+	echo "nb_NO CP865" # not CP850 ??
+	echo "nl CP850"
+	echo "nl_BE CP850"
+	echo "nl_NL CP850"
+	echo "nn CP865"    # not CP850 ??
+	echo "nn_NO CP865" # not CP850 ??
+	echo "no CP865"    # not CP850 ??
+	echo "no_NO CP865" # not CP850 ??
+	echo "pt CP850"
+	echo "pt_BR CP850"
+	echo "pt_PT CP850"
+	echo "sv CP850"
+	echo "sv_SE CP850"
+	# ISO-8859-2 languages
+	echo "cs CP852"
+	echo "cs_CZ CP852"
+	echo "hr CP852"
+	echo "hr_HR CP852"
+	echo "hu CP852"
+	echo "hu_HU CP852"
+	echo "pl CP852"
+	echo "pl_PL CP852"
+	echo "ro CP852"
+	echo "ro_RO CP852"
+	echo "sk CP852"
+	echo "sk_SK CP852"
+	echo "sl CP852"
+	echo "sl_SI CP852"
+	echo "sq CP852"
+	echo "sq_AL CP852"
+	echo "sr CP852"    # CP852 or CP866 or CP855 ??
+	echo "sr_CS CP852" # CP852 or CP866 or CP855 ??
+	echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
+	# ISO-8859-3 languages
+	echo "mt CP850"
+	echo "mt_MT CP850"
+	# ISO-8859-5 languages
+	echo "be CP866"
+	echo "be_BE CP866"
+	echo "bg CP866"    # not CP855 ??
+	echo "bg_BG CP866" # not CP855 ??
+	echo "mk CP866"    # not CP855 ??
+	echo "mk_MK CP866" # not CP855 ??
+	echo "ru CP866"
+	echo "ru_RU CP866"
+	echo "uk CP1125"
+	echo "uk_UA CP1125"
+	# ISO-8859-6 languages
+	echo "ar CP864"
+	echo "ar_AE CP864"
+	echo "ar_DZ CP864"
+	echo "ar_EG CP864"
+	echo "ar_IQ CP864"
+	echo "ar_IR CP864"
+	echo "ar_JO CP864"
+	echo "ar_KW CP864"
+	echo "ar_MA CP864"
+	echo "ar_OM CP864"
+	echo "ar_QA CP864"
+	echo "ar_SA CP864"
+	echo "ar_SY CP864"
+	# ISO-8859-7 languages
+	echo "el CP869"
+	echo "el_GR CP869"
+	# ISO-8859-8 languages
+	echo "he CP862"
+	echo "he_IL CP862"
+	# ISO-8859-9 languages
+	echo "tr CP857"
+	echo "tr_TR CP857"
+	# Japanese
+	echo "ja CP932"
+	echo "ja_JP CP932"
+	# Chinese
+	echo "zh_CN GBK"
+	echo "zh_TW CP950" # not CP938 ??
+	# Korean
+	echo "kr CP949"    # not CP934 ??
+	echo "kr_KR CP949" # not CP934 ??
+	# Thai
+	echo "th CP874"
+	echo "th_TH CP874"
+	# Other
+	echo "eo CP850"
+	echo "eo_EO CP850"
+	;;
+esac
diff --git a/libmissing/dirent.in.h b/libmissing/dirent.in.h
new file mode 100644
index 0000000..f15a8a3
--- /dev/null
+++ b/libmissing/dirent.in.h
@@ -0,0 +1,98 @@
+/* A GNU-like <dirent.h>.
+   Copyright (C) 2006-2009 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 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 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/>.  */
+
+#ifndef _GL_DIRENT_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+/* The include_next requires a split double-inclusion guard.  */
+#@INCLUDE_NEXT@ @NEXT_DIRENT_H@
+
+#ifndef _GL_DIRENT_H
+#define _GL_DIRENT_H
+
+/* The definition of GL_LINK_WARNING is copied here.  */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Declare overridden functions.  */
+
+#if @REPLACE_FCHDIR@
+# define opendir rpl_opendir
+extern DIR * opendir (const char *);
+# define closedir rpl_closedir
+extern int closedir (DIR *);
+#endif
+
+/* Declare other POSIX functions.  */
+
+#if @GNULIB_DIRFD@
+# if !@HAVE_DECL_DIRFD@ && !defined dirfd
+/* Return the file descriptor associated with the given directory stream,
+   or -1 if none exists.  */
+extern int dirfd (DIR const *dir);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef dirfd
+# define dirfd(d) \
+    (GL_LINK_WARNING ("dirfd is unportable - " \
+                      "use gnulib module dirfd for portability"), \
+     dirfd (d))
+#endif
+
+#if @GNULIB_SCANDIR@
+/* Scan the directory DIR, calling FILTER on each directory entry.
+   Entries for which FILTER returns nonzero are individually malloc'd,
+   sorted using qsort with CMP, and collected in a malloc'd array in
+   *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
+# if !@HAVE_SCANDIR@
+extern int scandir (const char *dir, struct dirent ***namelist,
+		    int (*filter) (const struct dirent *),
+		    int (*cmp) (const struct dirent **, const struct dirent **));
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef scandir
+# define scandir(d,n,f,c) \
+    (GL_LINK_WARNING ("scandir is unportable - " \
+                      "use gnulib module scandir for portability"), \
+     scandir (d, n, f, c))
+#endif
+
+#if @GNULIB_ALPHASORT@
+/* Compare two 'struct dirent' entries alphabetically.  */
+# if !@HAVE_ALPHASORT@
+extern int alphasort (const struct dirent **, const struct dirent **);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef alphasort
+# define alphasort(a,b) \
+    (GL_LINK_WARNING ("alphasort is unportable - " \
+                      "use gnulib module alphasort for portability"), \
+     alphasort (a, b))
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _GL_DIRENT_H */
+#endif /* _GL_DIRENT_H */
diff --git a/libmissing/dirfd.c b/libmissing/dirfd.c
index 2c80a66..6c430c2 100644
--- a/libmissing/dirfd.c
+++ b/libmissing/dirfd.c
@@ -1,6 +1,6 @@
 /* dirfd.c -- return the file descriptor associated with an open DIR*
 
-   Copyright (C) 2001, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2006, 2008-2009 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
@@ -19,10 +19,14 @@
 
 #include <config.h>
 
-#include "dirfd.h"
+#include <dirent.h>
+#include <errno.h>
 
 int
 dirfd (DIR const *dir_p)
 {
-  return DIR_TO_FD (dir_p);
+  int fd = DIR_TO_FD (dir_p);
+  if (fd == -1)
+    errno = ENOTSUP;
+  return fd;
 }
diff --git a/libmissing/dirfd.h b/libmissing/dirfd.h
deleted file mode 100644
index 99c6c7c..0000000
--- a/libmissing/dirfd.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Declare dirfd, if necessary.
-   Copyright (C) 2001, 2002, 2006 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 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 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/>.
-
-   Written by Jim Meyering.  */
-
-#include <sys/types.h>
-
-#include <dirent.h>
-
-#ifndef HAVE_DECL_DIRFD
-"this configure-time declaration test was not run"
-#endif
-#if !HAVE_DECL_DIRFD && !defined dirfd
-int dirfd (DIR const *);
-#endif
diff --git a/libmissing/dummy.c b/libmissing/dummy.c
deleted file mode 100644
index 37fff11..0000000
--- a/libmissing/dummy.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* A dummy file, to prevent empty libraries from breaking builds.
-   Copyright (C) 2004, 2007 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 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 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/>.  */
-
-/* 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/libmissing/errno.in.h b/libmissing/errno.in.h
index 06b3e20..a9b81d5 100644
--- a/libmissing/errno.in.h
+++ b/libmissing/errno.in.h
@@ -1,6 +1,6 @@
 /* A POSIX-like <errno.h>.
 
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 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
@@ -18,7 +18,9 @@
 
 #ifndef _GL_ERRNO_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_ERRNO_H@
@@ -143,6 +145,11 @@
 #  define GNULIB_defined_ENOTSUP 1
 # endif
 
+# ifndef ESTALE
+#  define ESTALE    2009
+#  define GNULIB_defined_ESTALE 1
+# endif
+
 # ifndef ECANCELED
 #  define ECANCELED 2008
 #  define GNULIB_defined_ECANCELED 1
diff --git a/libmissing/float.in.h b/libmissing/float.in.h
index fed85fb..63d55f8 100644
--- a/libmissing/float.in.h
+++ b/libmissing/float.in.h
@@ -17,7 +17,9 @@
 
 #ifndef _GL_FLOAT_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_FLOAT_H@
diff --git a/libmissing/fnmatch.c b/libmissing/fnmatch.c
index 6957045..6efe8a0 100644
--- a/libmissing/fnmatch.c
+++ b/libmissing/fnmatch.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
+/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2009
 	Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -89,7 +89,7 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
 #  define isblank(c) ((c) == ' ' || (c) == '\t')
 # endif
 
-# define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
+# define STREQ(s1, s2) (strcmp (s1, s2) == 0)
 
 # if defined _LIBC || WIDE_CHAR_SUPPORT
 /* The GNU C library provides support for user-defined character classes
diff --git a/libmissing/gai_strerror.c b/libmissing/gai_strerror.c
index d491ed5..ab81d08 100644
--- a/libmissing/gai_strerror.c
+++ b/libmissing/gai_strerror.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Philip Blundell <[email protected]>, 1997.
 
@@ -18,13 +18,10 @@
 
 #ifndef _LIBC
 # include <config.h>
-# include "getaddrinfo.h"
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
+#include <netdb.h>
 
 #ifdef _LIBC
 # include <libintl.h>
@@ -53,7 +50,7 @@ values[] =
     { EAI_SOCKTYPE, N_("ai_socktype not supported") },
     { EAI_SYSTEM, N_("System error") },
     { EAI_OVERFLOW, N_("Argument buffer too small") },
-#ifdef __USE_GNU
+#ifdef EAI_INPROGRESS
     { EAI_INPROGRESS, N_("Processing request in progress") },
     { EAI_CANCELED, N_("Request canceled") },
     { EAI_NOTCANCELED, N_("Request not canceled") },
diff --git a/libmissing/getaddrinfo.c b/libmissing/getaddrinfo.c
index e55b6f0..45366a5 100644
--- a/libmissing/getaddrinfo.c
+++ b/libmissing/getaddrinfo.c
@@ -19,7 +19,7 @@
 
 #include <config.h>
 
-#include "getaddrinfo.h"
+#include <netdb.h>
 
 #if HAVE_NETINET_IN_H
 # include <netinet/in.h>
diff --git a/libmissing/getaddrinfo.h b/libmissing/getaddrinfo.h
deleted file mode 100644
index d101516..0000000
--- a/libmissing/getaddrinfo.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/* Get address information.
-   Copyright (C) 1996-2002, 2003, 2004, 2005, 2006, 2008
-                 Free Software Foundation, Inc.
-   Contributed by Simon Josefsson <[email protected]>.
-
-   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, 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 GETADDRINFO_H
-#define GETADDRINFO_H
-
-/* sys/socket.h in i386-unknown-freebsd4.10 and
-   powerpc-apple-darwin5.5 require sys/types.h, so include it first.
-   Then we'll also get 'socklen_t' and 'struct sockaddr' which are
-   used below. */
-#include <sys/types.h>
-/* Get all getaddrinfo related declarations, if available.  */
-#include <sys/socket.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
-
-#ifndef HAVE_STRUCT_ADDRINFO
-
-/* Structure to contain information about address of a service provider.  */
-struct addrinfo
-{
-  int ai_flags;			/* Input flags.  */
-  int ai_family;		/* Protocol family for socket.  */
-  int ai_socktype;		/* Socket type.  */
-  int ai_protocol;		/* Protocol for socket.  */
-  socklen_t ai_addrlen;		/* Length of socket address.  */
-  struct sockaddr *ai_addr;	/* Socket address for socket.  */
-  char *ai_canonname;		/* Canonical name for service location.  */
-  struct addrinfo *ai_next;	/* Pointer to next in list.  */
-};
-#endif
-
-/* Possible values for `ai_flags' field in `addrinfo' structure.  */
-#ifndef AI_PASSIVE
-# define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
-#endif
-#ifndef AI_CANONNAME
-# define AI_CANONNAME	0x0002	/* Request for canonical name.  */
-#endif
-#ifndef AI_NUMERICSERV
-# define AI_NUMERICSERV	0x0400	/* Don't use name resolution.  */
-#endif
-
-#if 0
-/* The commented out definitions below are not yet implemented in the
-   GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
-   cause conflicts on systems with a getaddrinfo() function which does not
-   define them.
-
-   If they are restored, be sure to protect the definitions with #ifndef.  */
-#define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
-#define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
-#define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */
-#define AI_ADDRCONFIG	0x0020	/* Use configuration of this host to choose
-				   returned address type..  */
-#endif /* 0 */
-
-/* Error values for `getaddrinfo' function.  */
-#ifndef EAI_BADFLAGS
-# define EAI_BADFLAGS	  -1	/* Invalid value for `ai_flags' field.  */
-# define EAI_NONAME	  -2	/* NAME or SERVICE is unknown.  */
-# define EAI_AGAIN	  -3	/* Temporary failure in name resolution.  */
-# define EAI_FAIL	  -4	/* Non-recoverable failure in name res.  */
-# define EAI_NODATA	  -5	/* No address associated with NAME.  */
-# define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
-# define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
-# define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
-# define EAI_MEMORY	  -10	/* Memory allocation failure.  */
-#endif
-
-/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
-   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
-   in favor of EAI_NONAME.  */
-#if !defined EAI_NODATA && defined EAI_NONAME
-# define EAI_NODATA EAI_NONAME
-#endif
-
-#ifndef EAI_OVERFLOW
-/* Not defined on mingw32. */
-# define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
-#endif
-#ifndef EAI_ADDRFAMILY
-/* Not defined on mingw32. */
-# define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
-#endif
-#ifndef EAI_SYSTEM
-/* Not defined on mingw32. */
-# define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
-#endif
-
-#ifdef __USE_GNU
-# ifndef EAI_INPROGRESS
-#  define EAI_INPROGRESS	-100	/* Processing request in progress.  */
-#  define EAI_CANCELED		-101	/* Request canceled.  */
-#  define EAI_NOTCANCELED	-102	/* Request not canceled.  */
-#  define EAI_ALLDONE		-103	/* All requests done.  */
-#  define EAI_INTR		-104	/* Interrupted by a signal.  */
-#  define EAI_IDN_ENCODE	-105	/* IDN encoding failed.  */
-# endif
-#endif
-
-#if !HAVE_DECL_GETADDRINFO
-/* Translate name of a service location and/or a service name to set of
-   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);
-#endif
-
-#if !HAVE_DECL_FREEADDRINFO
-/* 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);
-#endif
-
-#if !HAVE_DECL_GAI_STRERROR
-/* 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);
-#endif
-
-#if !HAVE_DECL_GETNAMEINFO
-/* 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,
-		       char *restrict node, socklen_t nodelen,
-		       char *restrict service, socklen_t servicelen,
-		       int flags);
-
-#endif
-
-/* Possible flags for getnameinfo.  */
-#ifndef NI_NUMERICHOST
-# define NI_NUMERICHOST 1
-#endif
-#ifndef NI_NUMERICSERV
-# define NI_NUMERICSERV 2
-#endif
-
-#endif /* GETADDRINFO_H */
diff --git a/libmissing/getpagesize.c b/libmissing/getpagesize.c
new file mode 100644
index 0000000..82238df
--- /dev/null
+++ b/libmissing/getpagesize.c
@@ -0,0 +1,39 @@
+/* getpagesize emulation for systems where it cannot be done in a C macro.
+
+   Copyright (C) 2007 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 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 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/>.  */
+
+/* Written by Bruno Haible and Martin Lambers.  */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+/* This implementation is only for native Win32 systems.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+int
+getpagesize (void)
+{
+  SYSTEM_INFO system_info;
+  GetSystemInfo (&system_info);
+  return system_info.dwPageSize;
+}
+
+#endif
diff --git a/libmissing/getpeername.c b/libmissing/getpeername.c
new file mode 100644
index 0000000..a54263e
--- /dev/null
+++ b/libmissing/getpeername.c
@@ -0,0 +1,40 @@
+/* getpeername.c --- wrappers for Windows getpeername function
+
+   Copyright (C) 2008 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 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 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/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef getpeername
+
+int
+rpl_getpeername (int fd, struct sockaddr *addr, int *addrlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = getpeername (sock, addr, addrlen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/libmissing/gettext.h b/libmissing/gettext.h
index a2e87a3..72c8727 100644
--- a/libmissing/gettext.h
+++ b/libmissing/gettext.h
@@ -1,5 +1,5 @@
 /* Convenience header for conditional use of GNU <libintl.h>.
-   Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009 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
@@ -63,21 +63,30 @@
    for invalid uses of the value returned from these functions.
    On pre-ANSI systems without 'const', the config.h file is supposed to
    contain "#define const".  */
+# undef gettext
 # define gettext(Msgid) ((const char *) (Msgid))
+# undef dgettext
 # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
+# undef dcgettext
 # define dcgettext(Domainname, Msgid, Category) \
     ((void) (Category), dgettext (Domainname, Msgid))
+# undef ngettext
 # define ngettext(Msgid1, Msgid2, N) \
     ((N) == 1 \
      ? ((void) (Msgid2), (const char *) (Msgid1)) \
      : ((void) (Msgid1), (const char *) (Msgid2)))
+# undef dngettext
 # define dngettext(Domainname, Msgid1, Msgid2, N) \
     ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
+# undef dcngettext
 # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
     ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
+# undef textdomain
 # define textdomain(Domainname) ((const char *) (Domainname))
+# undef bindtextdomain
 # define bindtextdomain(Domainname, Dirname) \
     ((void) (Domainname), (const char *) (Dirname))
+# undef bind_textdomain_codeset
 # define bind_textdomain_codeset(Domainname, Codeset) \
     ((void) (Domainname), (const char *) (Codeset))
 
diff --git a/libmissing/glob.c b/libmissing/glob.c
index c38ee4c..40cc9b3 100644
--- a/libmissing/glob.c
+++ b/libmissing/glob.c
@@ -153,10 +153,6 @@
 
 #include <fnmatch.h>
 
-#ifndef _LIBC
-# include "dirfd.h"
-#endif
-
 #ifdef _SC_GETPW_R_SIZE_MAX
 # define GETPW_R_SIZE_MAX()	sysconf (_SC_GETPW_R_SIZE_MAX)
 #else
diff --git a/libmissing/localcharset.c b/libmissing/localcharset.c
new file mode 100644
index 0000000..93da170
--- /dev/null
+++ b/libmissing/localcharset.c
@@ -0,0 +1,499 @@
+/* Determine a canonical name for the current locale's character encoding.
+
+   Copyright (C) 2000-2006, 2008-2009 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, 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.  */
+
+/* Written by Bruno Haible <[email protected]>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "localcharset.h"
+
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
+# define DARWIN7 /* Darwin 7 or newer, i.e. MacOS X 10.3 or newer */
+#endif
+
+#if defined _WIN32 || defined __WIN32__
+# define WIN32_NATIVE
+#endif
+
+#if defined __EMX__
+/* Assume EMX program runs on OS/2, even if compiled under DOS.  */
+# ifndef OS2
+#  define OS2
+# endif
+#endif
+
+#if !defined WIN32_NATIVE
+# if HAVE_LANGINFO_CODESET
+#  include <langinfo.h>
+# else
+#  if 0 /* see comment below */
+#   include <locale.h>
+#  endif
+# endif
+# ifdef __CYGWIN__
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+# endif
+#elif defined WIN32_NATIVE
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+#if defined OS2
+# define INCL_DOS
+# include <os2.h>
+#endif
+
+#if ENABLE_RELOCATABLE
+# include "relocatable.h"
+#else
+# define relocate(pathname) (pathname)
+#endif
+
+/* Get LIBDIR.  */
+#ifndef LIBDIR
+# include "configmake.h"
+#endif
+
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#endif
+
+#ifndef DIRECTORY_SEPARATOR
+# define DIRECTORY_SEPARATOR '/'
+#endif
+
+#ifndef ISSLASH
+# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
+#endif
+
+#if HAVE_DECL_GETC_UNLOCKED
+# undef getc
+# define getc getc_unlocked
+#endif
+
+/* The following static variable is declared 'volatile' to avoid a
+   possible multithread problem in the function get_charset_aliases. If we
+   are running in a threaded environment, and if two threads initialize
+   'charset_aliases' simultaneously, both will produce the same value,
+   and everything will be ok if the two assignments to 'charset_aliases'
+   are atomic. But I don't know what will happen if the two assignments mix.  */
+#if __STDC__ != 1
+# define volatile /* empty */
+#endif
+/* Pointer to the contents of the charset.alias file, if it has already been
+   read, else NULL.  Its format is:
+   ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0'  */
+static const char * volatile charset_aliases;
+
+/* Return a pointer to the contents of the charset.alias file.  */
+static const char *
+get_charset_aliases (void)
+{
+  const char *cp;
+
+  cp = charset_aliases;
+  if (cp == NULL)
+    {
+#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
+      FILE *fp;
+      const char *dir;
+      const char *base = "charset.alias";
+      char *file_name;
+
+      /* Make it possible to override the charset.alias location.  This is
+	 necessary for running the testsuite before "make install".  */
+      dir = getenv ("CHARSETALIASDIR");
+      if (dir == NULL || dir[0] == '\0')
+	dir = relocate (LIBDIR);
+
+      /* Concatenate dir and base into freshly allocated file_name.  */
+      {
+	size_t dir_len = strlen (dir);
+	size_t base_len = strlen (base);
+	int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
+	file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
+	if (file_name != NULL)
+	  {
+	    memcpy (file_name, dir, dir_len);
+	    if (add_slash)
+	      file_name[dir_len] = DIRECTORY_SEPARATOR;
+	    memcpy (file_name + dir_len + add_slash, base, base_len + 1);
+	  }
+      }
+
+      if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
+	/* Out of memory or file not found, treat it as empty.  */
+	cp = "";
+      else
+	{
+	  /* Parse the file's contents.  */
+	  char *res_ptr = NULL;
+	  size_t res_size = 0;
+
+	  for (;;)
+	    {
+	      int c;
+	      char buf1[50+1];
+	      char buf2[50+1];
+	      size_t l1, l2;
+	      char *old_res_ptr;
+
+	      c = getc (fp);
+	      if (c == EOF)
+		break;
+	      if (c == '\n' || c == ' ' || c == '\t')
+		continue;
+	      if (c == '#')
+		{
+		  /* Skip comment, to end of line.  */
+		  do
+		    c = getc (fp);
+		  while (!(c == EOF || c == '\n'));
+		  if (c == EOF)
+		    break;
+		  continue;
+		}
+	      ungetc (c, fp);
+	      if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
+		break;
+	      l1 = strlen (buf1);
+	      l2 = strlen (buf2);
+	      old_res_ptr = res_ptr;
+	      if (res_size == 0)
+		{
+		  res_size = l1 + 1 + l2 + 1;
+		  res_ptr = (char *) malloc (res_size + 1);
+		}
+	      else
+		{
+		  res_size += l1 + 1 + l2 + 1;
+		  res_ptr = (char *) realloc (res_ptr, res_size + 1);
+		}
+	      if (res_ptr == NULL)
+		{
+		  /* Out of memory. */
+		  res_size = 0;
+		  if (old_res_ptr != NULL)
+		    free (old_res_ptr);
+		  break;
+		}
+	      strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
+	      strcpy (res_ptr + res_size - (l2 + 1), buf2);
+	    }
+	  fclose (fp);
+	  if (res_size == 0)
+	    cp = "";
+	  else
+	    {
+	      *(res_ptr + res_size) = '\0';
+	      cp = res_ptr;
+	    }
+	}
+
+      if (file_name != NULL)
+	free (file_name);
+
+#else
+
+# if defined DARWIN7
+      /* To avoid the trouble of installing a file that is shared by many
+	 GNU packages -- many packaging systems have problems with this --,
+	 simply inline the aliases here.  */
+      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+	   "ISO8859-2" "\0" "ISO-8859-2" "\0"
+	   "ISO8859-4" "\0" "ISO-8859-4" "\0"
+	   "ISO8859-5" "\0" "ISO-8859-5" "\0"
+	   "ISO8859-7" "\0" "ISO-8859-7" "\0"
+	   "ISO8859-9" "\0" "ISO-8859-9" "\0"
+	   "ISO8859-13" "\0" "ISO-8859-13" "\0"
+	   "ISO8859-15" "\0" "ISO-8859-15" "\0"
+	   "KOI8-R" "\0" "KOI8-R" "\0"
+	   "KOI8-U" "\0" "KOI8-U" "\0"
+	   "CP866" "\0" "CP866" "\0"
+	   "CP949" "\0" "CP949" "\0"
+	   "CP1131" "\0" "CP1131" "\0"
+	   "CP1251" "\0" "CP1251" "\0"
+	   "eucCN" "\0" "GB2312" "\0"
+	   "GB2312" "\0" "GB2312" "\0"
+	   "eucJP" "\0" "EUC-JP" "\0"
+	   "eucKR" "\0" "EUC-KR" "\0"
+	   "Big5" "\0" "BIG5" "\0"
+	   "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
+	   "GBK" "\0" "GBK" "\0"
+	   "GB18030" "\0" "GB18030" "\0"
+	   "SJIS" "\0" "SHIFT_JIS" "\0"
+	   "ARMSCII-8" "\0" "ARMSCII-8" "\0"
+	   "PT154" "\0" "PT154" "\0"
+	 /*"ISCII-DEV" "\0" "?" "\0"*/
+	   "*" "\0" "UTF-8" "\0";
+# endif
+
+# if defined VMS
+      /* To avoid the troubles of an extra file charset.alias_vms in the
+	 sources of many GNU packages, simply inline the aliases here.  */
+      /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
+	 "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
+	 section 10.7 "Handling Different Character Sets".  */
+      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+	   "ISO8859-2" "\0" "ISO-8859-2" "\0"
+	   "ISO8859-5" "\0" "ISO-8859-5" "\0"
+	   "ISO8859-7" "\0" "ISO-8859-7" "\0"
+	   "ISO8859-8" "\0" "ISO-8859-8" "\0"
+	   "ISO8859-9" "\0" "ISO-8859-9" "\0"
+	   /* Japanese */
+	   "eucJP" "\0" "EUC-JP" "\0"
+	   "SJIS" "\0" "SHIFT_JIS" "\0"
+	   "DECKANJI" "\0" "DEC-KANJI" "\0"
+	   "SDECKANJI" "\0" "EUC-JP" "\0"
+	   /* Chinese */
+	   "eucTW" "\0" "EUC-TW" "\0"
+	   "DECHANYU" "\0" "DEC-HANYU" "\0"
+	   "DECHANZI" "\0" "GB2312" "\0"
+	   /* Korean */
+	   "DECKOREAN" "\0" "EUC-KR" "\0";
+# endif
+
+# if defined WIN32_NATIVE || defined __CYGWIN__
+      /* To avoid the troubles of installing a separate file in the same
+	 directory as the DLL and of retrieving the DLL's directory at
+	 runtime, simply inline the aliases here.  */
+
+      cp = "CP936" "\0" "GBK" "\0"
+	   "CP1361" "\0" "JOHAB" "\0"
+	   "CP20127" "\0" "ASCII" "\0"
+	   "CP20866" "\0" "KOI8-R" "\0"
+	   "CP20936" "\0" "GB2312" "\0"
+	   "CP21866" "\0" "KOI8-RU" "\0"
+	   "CP28591" "\0" "ISO-8859-1" "\0"
+	   "CP28592" "\0" "ISO-8859-2" "\0"
+	   "CP28593" "\0" "ISO-8859-3" "\0"
+	   "CP28594" "\0" "ISO-8859-4" "\0"
+	   "CP28595" "\0" "ISO-8859-5" "\0"
+	   "CP28596" "\0" "ISO-8859-6" "\0"
+	   "CP28597" "\0" "ISO-8859-7" "\0"
+	   "CP28598" "\0" "ISO-8859-8" "\0"
+	   "CP28599" "\0" "ISO-8859-9" "\0"
+	   "CP28605" "\0" "ISO-8859-15" "\0"
+	   "CP38598" "\0" "ISO-8859-8" "\0"
+	   "CP51932" "\0" "EUC-JP" "\0"
+	   "CP51936" "\0" "GB2312" "\0"
+	   "CP51949" "\0" "EUC-KR" "\0"
+	   "CP51950" "\0" "EUC-TW" "\0"
+	   "CP54936" "\0" "GB18030" "\0"
+	   "CP65001" "\0" "UTF-8" "\0";
+# endif
+#endif
+
+      charset_aliases = cp;
+    }
+
+  return cp;
+}
+
+/* Determine the current locale's character encoding, and canonicalize it
+   into one of the canonical names listed in config.charset.
+   The result must not be freed; it is statically allocated.
+   If the canonical name cannot be determined, the result is a non-canonical
+   name.  */
+
+#ifdef STATIC
+STATIC
+#endif
+const char *
+locale_charset (void)
+{
+  const char *codeset;
+  const char *aliases;
+
+#if !(defined WIN32_NATIVE || defined OS2)
+
+# if HAVE_LANGINFO_CODESET
+
+  /* Most systems support nl_langinfo (CODESET) nowadays.  */
+  codeset = nl_langinfo (CODESET);
+
+#  ifdef __CYGWIN__
+  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
+     returns "US-ASCII".  As long as this is not fixed, return the suffix
+     of the locale name from the environment variables (if present) or
+     the codepage as a number.  */
+  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
+    {
+      const char *locale;
+      static char buf[2 + 10 + 1];
+
+      locale = getenv ("LC_ALL");
+      if (locale == NULL || locale[0] == '\0')
+	{
+	  locale = getenv ("LC_CTYPE");
+	  if (locale == NULL || locale[0] == '\0')
+	    locale = getenv ("LANG");
+	}
+      if (locale != NULL && locale[0] != '\0')
+	{
+	  /* If the locale name contains an encoding after the dot, return
+	     it.  */
+	  const char *dot = strchr (locale, '.');
+
+	  if (dot != NULL)
+	    {
+	      const char *modifier;
+
+	      dot++;
+	      /* Look for the possible @... trailer and remove it, if any.  */
+	      modifier = strchr (dot, '@');
+	      if (modifier == NULL)
+		return dot;
+	      if (modifier - dot < sizeof (buf))
+		{
+		  memcpy (buf, dot, modifier - dot);
+		  buf [modifier - dot] = '\0';
+		  return buf;
+		}
+	    }
+	}
+
+      /* Woe32 has a function returning the locale's codepage as a number.  */
+      sprintf (buf, "CP%u", GetACP ());
+      codeset = buf;
+    }
+#  endif
+
+# else
+
+  /* On old systems which lack it, use setlocale or getenv.  */
+  const char *locale = NULL;
+
+  /* But most old systems don't have a complete set of locales.  Some
+     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
+     use setlocale here; it would return "C" when it doesn't support the
+     locale name the user has set.  */
+#  if 0
+  locale = setlocale (LC_CTYPE, NULL);
+#  endif
+  if (locale == NULL || locale[0] == '\0')
+    {
+      locale = getenv ("LC_ALL");
+      if (locale == NULL || locale[0] == '\0')
+	{
+	  locale = getenv ("LC_CTYPE");
+	  if (locale == NULL || locale[0] == '\0')
+	    locale = getenv ("LANG");
+	}
+    }
+
+  /* On some old systems, one used to set locale = "iso8859_1". On others,
+     you set it to "language_COUNTRY.charset". In any case, we resolve it
+     through the charset.alias file.  */
+  codeset = locale;
+
+# endif
+
+#elif defined WIN32_NATIVE
+
+  static char buf[2 + 10 + 1];
+
+  /* Woe32 has a function returning the locale's codepage as a number.  */
+  sprintf (buf, "CP%u", GetACP ());
+  codeset = buf;
+
+#elif defined OS2
+
+  const char *locale;
+  static char buf[2 + 10 + 1];
+  ULONG cp[3];
+  ULONG cplen;
+
+  /* Allow user to override the codeset, as set in the operating system,
+     with standard language environment variables.  */
+  locale = getenv ("LC_ALL");
+  if (locale == NULL || locale[0] == '\0')
+    {
+      locale = getenv ("LC_CTYPE");
+      if (locale == NULL || locale[0] == '\0')
+	locale = getenv ("LANG");
+    }
+  if (locale != NULL && locale[0] != '\0')
+    {
+      /* If the locale name contains an encoding after the dot, return it.  */
+      const char *dot = strchr (locale, '.');
+
+      if (dot != NULL)
+	{
+	  const char *modifier;
+
+	  dot++;
+	  /* Look for the possible @... trailer and remove it, if any.  */
+	  modifier = strchr (dot, '@');
+	  if (modifier == NULL)
+	    return dot;
+	  if (modifier - dot < sizeof (buf))
+	    {
+	      memcpy (buf, dot, modifier - dot);
+	      buf [modifier - dot] = '\0';
+	      return buf;
+	    }
+	}
+
+      /* Resolve through the charset.alias file.  */
+      codeset = locale;
+    }
+  else
+    {
+      /* OS/2 has a function returning the locale's codepage as a number.  */
+      if (DosQueryCp (sizeof (cp), cp, &cplen))
+	codeset = "";
+      else
+	{
+	  sprintf (buf, "CP%u", cp[0]);
+	  codeset = buf;
+	}
+    }
+
+#endif
+
+  if (codeset == NULL)
+    /* The canonical name cannot be determined.  */
+    codeset = "";
+
+  /* Resolve alias. */
+  for (aliases = get_charset_aliases ();
+       *aliases != '\0';
+       aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
+    if (strcmp (codeset, aliases) == 0
+	|| (aliases[0] == '*' && aliases[1] == '\0'))
+      {
+	codeset = aliases + strlen (aliases) + 1;
+	break;
+      }
+
+  /* Don't return an empty string.  GNU libc and GNU libiconv interpret
+     the empty string as denoting "the locale's character encoding",
+     thus GNU libiconv would call this function a second time.  */
+  if (codeset[0] == '\0')
+    codeset = "ASCII";
+
+  return codeset;
+}
diff --git a/libmissing/localcharset.h b/libmissing/localcharset.h
new file mode 100644
index 0000000..1772a50
--- /dev/null
+++ b/libmissing/localcharset.h
@@ -0,0 +1,41 @@
+/* Determine a canonical name for the current locale's character encoding.
+   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+   This file is part of the GNU CHARSET Library.
+
+   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, 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 _LOCALCHARSET_H
+#define _LOCALCHARSET_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Determine the current locale's character encoding, and canonicalize it
+   into one of the canonical names listed in config.charset.
+   The result must not be freed; it is statically allocated.
+   If the canonical name cannot be determined, the result is a non-canonical
+   name.  */
+extern const char * locale_charset (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _LOCALCHARSET_H */
diff --git a/libmissing/m4/00gnulib.m4 b/libmissing/m4/00gnulib.m4
new file mode 100644
index 0000000..d4d04d1
--- /dev/null
+++ b/libmissing/m4/00gnulib.m4
@@ -0,0 +1,30 @@
+# 00gnulib.m4 serial 2
+dnl Copyright (C) 2009 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 This file must be named something that sorts before all other
+dnl gnulib-provided .m4 files.  It is needed until such time as we can
+dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics.
+
+# AC_DEFUN_ONCE([NAME], VALUE)
+# ----------------------------
+# Define NAME to expand to VALUE on the first use (whether by direct
+# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses.
+# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier.  This
+# definition is slower than the version in Autoconf 2.64, because it
+# can only use interfaces that existed since 2.59; but it achieves the
+# same effect.  Quoting is necessary to avoid confusing Automake.
+m4_version_prereq([2.63.263], [],
+[m4_define([AC][_DEFUN_ONCE],
+  [AC][_DEFUN([$1],
+    [AC_REQUIRE([_gl_DEFUN_ONCE([$1])],
+      [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl
+[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])])
+
+# gl_00GNULIB
+# -----------
+# Witness macro that this file has been included.  Needed to force
+# Automake to include this file prior to all other gnulib .m4 files.
+AC_DEFUN([gl_00GNULIB])
diff --git a/libmissing/m4/alloca.m4 b/libmissing/m4/alloca.m4
index 95f54a6..4b978e1 100644
--- a/libmissing/m4/alloca.m4
+++ b/libmissing/m4/alloca.m4
@@ -1,5 +1,5 @@
-# alloca.m4 serial 8
-dnl Copyright (C) 2002-2004, 2006, 2007 Free Software Foundation, Inc.
+# alloca.m4 serial 9
+dnl Copyright (C) 2002-2004, 2006, 2007, 2009 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.
@@ -26,7 +26,7 @@ AC_DEFUN([gl_FUNC_ALLOCA],
     ])
     if test $gl_cv_rpl_alloca = yes; then
       dnl OK, alloca can be implemented through a compiler built-in.
-      AC_DEFINE([HAVE_ALLOCA], 1,
+      AC_DEFINE([HAVE_ALLOCA], [1],
         [Define to 1 if you have 'alloca' after including <alloca.h>,
          a header that may be supplied by this distribution.])
       ALLOCA_H=alloca.h
diff --git a/libmissing/m4/close.m4 b/libmissing/m4/close.m4
index fcc9fb1..b1189f5 100644
--- a/libmissing/m4/close.m4
+++ b/libmissing/m4/close.m4
@@ -1,5 +1,5 @@
-# close.m4 serial 2
-dnl Copyright (C) 2008 Free Software Foundation, Inc.
+# close.m4 serial 3
+dnl Copyright (C) 2008-2009 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.
diff --git a/libmissing/m4/codeset.m4 b/libmissing/m4/codeset.m4
new file mode 100644
index 0000000..413217b
--- /dev/null
+++ b/libmissing/m4/codeset.m4
@@ -0,0 +1,21 @@
+# codeset.m4 serial 4 (gettext-0.18)
+dnl Copyright (C) 2000-2002, 2006, 2008, 2009 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.
+
+AC_DEFUN([AM_LANGINFO_CODESET],
+[
+  AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset],
+    [AC_TRY_LINK([#include <langinfo.h>],
+      [char* cs = nl_langinfo(CODESET); return !cs;],
+      [am_cv_langinfo_codeset=yes],
+      [am_cv_langinfo_codeset=no])
+    ])
+  if test $am_cv_langinfo_codeset = yes; then
+    AC_DEFINE([HAVE_LANGINFO_CODESET], [1],
+      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
+  fi
+])
diff --git a/libmissing/m4/d-type.m4 b/libmissing/m4/d-type.m4
index 92f9b15..7e99f9c 100644
--- a/libmissing/m4/d-type.m4
+++ b/libmissing/m4/d-type.m4
@@ -1,12 +1,11 @@
-#serial 9
+# serial 10
 
 dnl From Jim Meyering.
 dnl
 dnl Check whether struct dirent has a member named d_type.
 dnl
 
-# Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software
-# Foundation, Inc.
+# Copyright (C) 1997, 1999-2004, 2006, 2009 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -27,7 +26,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE],
      ]
    )
    if test $gl_cv_struct_dirent_d_type = yes; then
-     AC_DEFINE(HAVE_STRUCT_DIRENT_D_TYPE, 1,
+     AC_DEFINE([HAVE_STRUCT_DIRENT_D_TYPE], [1],
        [Define if there is a member named d_type in the struct describing
         directory headers.])
    fi
diff --git a/libmissing/m4/dirent_h.m4 b/libmissing/m4/dirent_h.m4
new file mode 100644
index 0000000..e507e3d
--- /dev/null
+++ b/libmissing/m4/dirent_h.m4
@@ -0,0 +1,43 @@
+# dirent_h.m4 serial 4
+dnl Copyright (C) 2008-2009 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 Written by Bruno Haible.
+
+AC_DEFUN([gl_DIRENT_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+
+  gl_CHECK_NEXT_HEADERS([dirent.h])
+])
+
+dnl Unconditionally enables the replacement of <dirent.h>.
+AC_DEFUN([gl_REPLACE_DIRENT_H],
+[
+  AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+  DIRENT_H='dirent.h'
+])
+
+AC_DEFUN([gl_DIRENT_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_DIRENT_H_DEFAULTS],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
+  GNULIB_DIRFD=0;     AC_SUBST([GNULIB_DIRFD])
+  GNULIB_SCANDIR=0;   AC_SUBST([GNULIB_SCANDIR])
+  GNULIB_ALPHASORT=0; AC_SUBST([GNULIB_ALPHASORT])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_DECL_DIRFD=1; AC_SUBST([HAVE_DECL_DIRFD])
+  HAVE_SCANDIR=1;    AC_SUBST([HAVE_SCANDIR])
+  HAVE_ALPHASORT=1;  AC_SUBST([HAVE_ALPHASORT])
+  DIRENT_H='';       AC_SUBST([DIRENT_H])
+])
diff --git a/libmissing/m4/dirfd.m4 b/libmissing/m4/dirfd.m4
index 125966b..5f845f5 100644
--- a/libmissing/m4/dirfd.m4
+++ b/libmissing/m4/dirfd.m4
@@ -1,9 +1,8 @@
-#serial 14   -*- Autoconf -*-
+# serial 16   -*- Autoconf -*-
 
 dnl Find out how to get the file descriptor associated with an open DIR*.
 
-# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
-# Foundation, Inc.
+# Copyright (C) 2001-2006, 2008-2009 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.
@@ -12,13 +11,23 @@ dnl From Jim Meyering
 
 AC_DEFUN([gl_FUNC_DIRFD],
 [
+  AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+  gl_REPLACE_DIRENT_H
+
+  dnl Persuade glibc <dirent.h> to declare dirfd().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
   dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
   AC_REQUIRE([AC_PROG_CPP])
   AC_REQUIRE([AC_PROG_EGREP])
-  AC_CHECK_FUNCS(dirfd)
+
+  AC_CHECK_FUNCS([dirfd])
   AC_CHECK_DECLS([dirfd], , ,
     [#include <sys/types.h>
      #include <dirent.h>])
+  if test $ac_cv_have_decl_dirfd = no; then
+    HAVE_DECL_DIRFD=0
+  fi
 
   AC_CACHE_CHECK([whether dirfd is a macro],
     gl_cv_func_dirfd_macro,
@@ -59,7 +68,7 @@ AC_DEFUN([gl_FUNC_DIRFD],
       ]
     )
     if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
-      AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
+      AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
 	$gl_cv_sys_dir_fd_member_name,
 	[the name of the file descriptor member of DIR])
     fi
diff --git a/libmissing/m4/errno_h.m4 b/libmissing/m4/errno_h.m4
index b5af078..4ce1ccb 100644
--- a/libmissing/m4/errno_h.m4
+++ b/libmissing/m4/errno_h.m4
@@ -1,21 +1,14 @@
-# errno_h.m4 serial 1
-dnl Copyright (C) 2004, 2006, 2008 Free Software Foundation, Inc.
+# errno_h.m4 serial 6
+dnl Copyright (C) 2004, 2006, 2008, 2009 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_HEADER_ERRNO_H],
-[
-  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
-  dnl once only, before all statements that occur in other macros.
-  AC_REQUIRE([gl_HEADER_ERRNO_H_BODY])
-])
-
-AC_DEFUN([gl_HEADER_ERRNO_H_BODY],
+AC_DEFUN_ONCE([gl_HEADER_ERRNO_H],
 [
   AC_REQUIRE([AC_PROG_CC])
-  AC_CACHE_CHECK([for complete errno.h], gl_cv_header_errno_h_complete, [
-    AC_EGREP_CPP(booboo,[
+  AC_CACHE_CHECK([for complete errno.h], [gl_cv_header_errno_h_complete], [
+    AC_EGREP_CPP([booboo],[
 #include <errno.h>
 #if !defined ENOMSG
 booboo
@@ -41,6 +34,9 @@ booboo
 #if !defined ENOTSUP
 booboo
 #endif
+#if !defined ESTALE
+booboo
+#endif
 #if !defined ECANCELED
 booboo
 #endif
@@ -70,7 +66,7 @@ AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
 [
   if test -n "$ERRNO_H"; then
     AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
-      AC_EGREP_CPP(yes,[
+      AC_EGREP_CPP([yes],[
 #include <errno.h>
 #ifdef ]$1[
 yes
@@ -79,7 +75,7 @@ yes
       [gl_cv_header_errno_h_]$1[=yes],
       [gl_cv_header_errno_h_]$1[=no])
       if test $gl_cv_header_errno_h_]$1[ = no; then
-        AC_EGREP_CPP(yes,[
+        AC_EGREP_CPP([yes],[
 #define _XOPEN_SOURCE_EXTENDED 1
 #include <errno.h>
 #ifdef ]$1[
@@ -111,3 +107,9 @@ yes
     AC_SUBST($1[_VALUE])
   fi
 ])
+
+dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
+dnl Remove this when we can assume autoconf >= 2.61.
+m4_ifdef([AC_COMPUTE_INT], [], [
+  AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
+])
diff --git a/libmissing/m4/extensions.m4 b/libmissing/m4/extensions.m4
index 917af94..ba6d5e1 100644
--- a/libmissing/m4/extensions.m4
+++ b/libmissing/m4/extensions.m4
@@ -1,7 +1,7 @@
-# serial 5  -*- Autoconf -*-
+# serial 8  -*- Autoconf -*-
 # Enable extensions on systems that normally disable them.
 
-# Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2006-2009 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.
@@ -20,10 +20,12 @@
 # AC_DEFINE.  The goal here is to define all known feature-enabling
 # macros, then, if reports of conflicts are made, disable macros that
 # cause problems on some platforms (such as __EXTENSIONS__).
-AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
+AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
 [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
 
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
   AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
   if test "$MINIX" = yes; then
     AC_DEFINE([_POSIX_SOURCE], [1],
@@ -36,6 +38,16 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
       [Define to 1 if on MINIX.])
   fi
 
+  dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500,
+  dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already
+  dnl provided.
+  case "$host_os" in
+    hpux*)
+      AC_DEFINE([_XOPEN_SOURCE], [500],
+        [Define to 500 only on HP-UX.])
+      ;;
+  esac
+
   AH_VERBATIM([__EXTENSIONS__],
 [/* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
@@ -78,5 +90,15 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
 # ------------------------
 # Enable extensions on systems that normally disable them,
 # typically due to standards-conformance issues.
-AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS],
-  [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])])
+AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
+[
+  dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS.
+  dnl gnulib does not need it. But if it gets required by third-party macros
+  dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a
+  dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
+  dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE,
+  dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck.
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+])
diff --git a/libmissing/m4/fnmatch.m4 b/libmissing/m4/fnmatch.m4
index 495cbf9..9481a10 100644
--- a/libmissing/m4/fnmatch.m4
+++ b/libmissing/m4/fnmatch.m4
@@ -1,7 +1,6 @@
-# Check for fnmatch - serial 2.
+# Check for fnmatch - serial 4.
 
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
-# Foundation, Inc.
+# Copyright (C) 2000-2007, 2009 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.
@@ -9,119 +8,114 @@
 # Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent.
 # New applications should use the macros below instead.
 
-# _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
-# -------------------------------------------------------------------------
-# If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
-# IF-FALSE.  Use CACHE_VAR.
-AC_DEFUN([_AC_FUNC_FNMATCH_IF],
-[AC_CACHE_CHECK(
-   [for working $1 fnmatch],
-   [$2],
-  [dnl Some versions of Solaris, SCO, and the GNU C Library
-   dnl have a broken or incompatible fnmatch.
-   dnl So we run a test program.  If we are cross-compiling, take no chance.
-   dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this test.
-   AC_RUN_IFELSE(
-      [AC_LANG_PROGRAM(
-	 [[#include <fnmatch.h>
-	   static int
-	   y (char const *pattern, char const *string, int flags)
-	   {
-	     return fnmatch (pattern, string, flags) == 0;
-	   }
-	   static int
-	   n (char const *pattern, char const *string, int flags)
-	   {
-	     return fnmatch (pattern, string, flags) == FNM_NOMATCH;
-	   }
-	 ]],
-	 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
-	   char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
-	   static char const A_1[] = { 'A' - 1, 0 };
-	   static char const A01[] = { 'A' + 1, 0 };
-	   static char const a_1[] = { 'a' - 1, 0 };
-	   static char const a01[] = { 'a' + 1, 0 };
-	   static char const bs_1[] = { '\\\\' - 1, 0 };
-	   static char const bs01[] = { '\\\\' + 1, 0 };
-	   return
-	    !(n ("a*", "", 0)
-	      && y ("a*", "abc", 0)
-	      && n ("d*/*1", "d/s/1", FNM_PATHNAME)
-	      && y ("a\\\\bc", "abc", 0)
-	      && n ("a\\\\bc", "abc", FNM_NOESCAPE)
-	      && y ("*x", ".x", 0)
-	      && n ("*x", ".x", FNM_PERIOD)
-	      && y (Apat, "\\\\", 0) && y (Apat, "A", 0)
-	      && y (apat, "\\\\", 0) && y (apat, "a", 0)
-	      && n (Apat, A_1, 0) == ('A' < '\\\\')
-	      && n (apat, a_1, 0) == ('a' < '\\\\')
-	      && y (Apat, A01, 0) == ('A' < '\\\\')
-	      && y (apat, a01, 0) == ('a' < '\\\\')
-	      && y (Apat, bs_1, 0) == ('A' < '\\\\')
-	      && y (apat, bs_1, 0) == ('a' < '\\\\')
-	      && n (Apat, bs01, 0) == ('A' < '\\\\')
-	      && n (apat, bs01, 0) == ('a' < '\\\\')
-	      && ]m4_if([$1], [GNU],
-		   [y ("xxXX", "xXxX", FNM_CASEFOLD)
-		    && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
-		    && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
-		    && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
-		    && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
-		    && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
-		   1))[;]])],
-      [$2=yes],
-      [$2=no],
-      [$2=cross])])
-AS_IF([test $$2 = yes], [$3], [$4])
-])# _AC_FUNC_FNMATCH_IF
-
-
-# _AC_LIBOBJ_FNMATCH
-# ------------------
-# Prepare the replacement of fnmatch.
-AC_DEFUN([_AC_LIBOBJ_FNMATCH],
-[AC_REQUIRE([AC_FUNC_ALLOCA])dnl
-AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
-AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
-AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
-AC_CHECK_HEADERS_ONCE([wctype.h])
-AC_LIBOBJ([fnmatch])
-FNMATCH_H=fnmatch.h
-])# _AC_LIBOBJ_FNMATCH
-
-
+# Request a POSIX compliant fnmatch function.
 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
 [
+  m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX])
+
+  dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
+  dnl This is only needed if gl_fnmatch_required = GNU. It would be possible
+  dnl to avoid this dependency for gl_FUNC_FNMATCH_POSIX by putting
+  dnl gl_FUNC_FNMATCH_GNU into a separate .m4 file.
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
   FNMATCH_H=
-  _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
-		      [rm -f lib/fnmatch.h],
-		      [_AC_LIBOBJ_FNMATCH])
-  if test $ac_cv_func_fnmatch_posix != yes; then
+  gl_fnmatch_required_lowercase=`echo $gl_fnmatch_required | tr 'A-Z' 'a-z'`
+  gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}"
+  AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch],
+    [$gl_fnmatch_cache_var],
+    [dnl Some versions of Solaris, SCO, and the GNU C Library
+     dnl have a broken or incompatible fnmatch.
+     dnl So we run a test program.  If we are cross-compiling, take no chance.
+     dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this
+     dnl test.
+     if test $gl_fnmatch_required = GNU; then
+       gl_fnmatch_gnu_start=
+       gl_fnmatch_gnu_end=
+     else
+       gl_fnmatch_gnu_start='#if 0'
+       gl_fnmatch_gnu_end='#endif'
+     fi
+     AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <fnmatch.h>
+            static int
+            y (char const *pattern, char const *string, int flags)
+            {
+              return fnmatch (pattern, string, flags) == 0;
+            }
+            static int
+            n (char const *pattern, char const *string, int flags)
+            {
+              return fnmatch (pattern, string, flags) == FNM_NOMATCH;
+            }
+          ]],
+          [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
+            char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
+            static char const A_1[] = { 'A' - 1, 0 };
+            static char const A01[] = { 'A' + 1, 0 };
+            static char const a_1[] = { 'a' - 1, 0 };
+            static char const a01[] = { 'a' + 1, 0 };
+            static char const bs_1[] = { '\\\\' - 1, 0 };
+            static char const bs01[] = { '\\\\' + 1, 0 };
+            return
+             !(n ("a*", "", 0)
+               && y ("a*", "abc", 0)
+               && n ("d*/*1", "d/s/1", FNM_PATHNAME)
+               && y ("a\\\\bc", "abc", 0)
+               && n ("a\\\\bc", "abc", FNM_NOESCAPE)
+               && y ("*x", ".x", 0)
+               && n ("*x", ".x", FNM_PERIOD)
+               && y (Apat, "\\\\", 0) && y (Apat, "A", 0)
+               && y (apat, "\\\\", 0) && y (apat, "a", 0)
+               && n (Apat, A_1, 0) == ('A' < '\\\\')
+               && n (apat, a_1, 0) == ('a' < '\\\\')
+               && y (Apat, A01, 0) == ('A' < '\\\\')
+               && y (apat, a01, 0) == ('a' < '\\\\')
+               && y (Apat, bs_1, 0) == ('A' < '\\\\')
+               && y (apat, bs_1, 0) == ('a' < '\\\\')
+               && n (Apat, bs01, 0) == ('A' < '\\\\')
+               && n (apat, bs01, 0) == ('a' < '\\\\')
+               $gl_fnmatch_gnu_start
+               && y ("xxXX", "xXxX", FNM_CASEFOLD)
+               && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
+               && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
+               && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
+               && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
+               && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)
+               $gl_fnmatch_gnu_end
+              );
+          ]])],
+       [eval "$gl_fnmatch_cache_var=yes"],
+       [eval "$gl_fnmatch_cache_var=no"],
+       [eval "$gl_fnmatch_cache_var=\"guessing no\""])
+    ])
+  eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\""
+  if test "$gl_fnmatch_result" = yes; then
+    dnl Not strictly necessary. Only to avoid spurious leftover files if people
+    dnl don't do "make distclean".
+    rm -f "$gl_source_base/fnmatch.h"
+  else
+    FNMATCH_H=fnmatch.h
+    AC_LIBOBJ([fnmatch])
     dnl We must choose a different name for our function, since on ELF systems
     dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
     dnl compiled into a shared library.
-    AC_DEFINE([fnmatch], [posix_fnmatch],
+    AC_DEFINE_UNQUOTED([fnmatch], [${gl_fnmatch_required_lowercase}_fnmatch],
       [Define to a replacement function name for fnmatch().])
+    dnl Prerequisites of lib/fnmatch.c.
+    AC_REQUIRE([AC_TYPE_MBSTATE_T])
+    AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
+    AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
+    AC_CHECK_HEADERS_ONCE([wctype.h])
   fi
   AC_SUBST([FNMATCH_H])
 ])
 
-
+# Request a POSIX compliant fnmatch function with GNU extensions.
 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
 [
-  dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
-  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+  m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU])
 
-  FNMATCH_H=
-  _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
-		      [rm -f lib/fnmatch.h],
-		      [_AC_LIBOBJ_FNMATCH])
-  if test $ac_cv_func_fnmatch_gnu != yes; then
-    dnl We must choose a different name for our function, since on ELF systems
-    dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
-    dnl compiled into a shared library.
-    AC_DEFINE([fnmatch], [gnu_fnmatch],
-      [Define to a replacement function name for fnmatch().])
-  fi
-  AC_SUBST([FNMATCH_H])
+  AC_REQUIRE([gl_FUNC_FNMATCH_POSIX])
 ])
diff --git a/libmissing/m4/getaddrinfo.m4 b/libmissing/m4/getaddrinfo.m4
index 52135ba..4088671 100644
--- a/libmissing/m4/getaddrinfo.m4
+++ b/libmissing/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
-# getaddrinfo.m4 serial 15
-dnl Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+# getaddrinfo.m4 serial 20
+dnl Copyright (C) 2004-2009 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.
@@ -7,11 +7,23 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_GETADDRINFO],
 [
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+  AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
   AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
+  GETADDRINFO_LIB=
+  gai_saved_LIBS="$LIBS"
 
-  AC_CHECK_HEADERS_ONCE(netdb.h)
+  dnl Where is getaddrinfo()?
+  dnl - On Solaris, it is in libsocket.
+  dnl - On Haiku, it is in libnetwork.
+  dnl - On BeOS, it is in libnet.
+  dnl - On native Windows, it is in ws2_32.dll.
+  dnl - Otherwise it is in libc.
+  AC_SEARCH_LIBS([getaddrinfo], [socket network net],
+    [if test "$ac_cv_search_getaddrinfo" != "none required"; then
+       GETADDRINFO_LIB="$ac_cv_search_getaddrinfo"
+     fi])
+  LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
 
-  AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
     AC_TRY_LINK([
 #include <sys/types.h>
@@ -26,7 +38,7 @@ AC_DEFUN([gl_GETADDRINFO],
       [gl_cv_func_getaddrinfo=yes],
       [gl_cv_func_getaddrinfo=no])])
   if test $gl_cv_func_getaddrinfo = no; then
-    AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
+    AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32],
 		   gl_cv_w32_getaddrinfo, [
       gl_cv_w32_getaddrinfo=no
       am_save_LIBS="$LIBS"
@@ -37,11 +49,13 @@ AC_DEFUN([gl_GETADDRINFO],
 #endif
 #include <stddef.h>
 ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
-    LIBS="$am_save_LIBS"])
+      LIBS="$am_save_LIBS"
+    ])
     if test "$gl_cv_w32_getaddrinfo" = "yes"; then
-      LIBS="$LIBS -lws2_32"
+      GETADDRINFO_LIB="-lws2_32"
+      LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
     else
-      AC_LIBOBJ(getaddrinfo)
+      AC_LIBOBJ([getaddrinfo])
     fi
   fi
 
@@ -66,34 +80,22 @@ AC_DEFUN([gl_GETADDRINFO],
         [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)
+    AC_LIBOBJ([gai_strerror])
   fi
 
+  LIBS="$gai_saved_LIBS"
+
   gl_PREREQ_GETADDRINFO
+
+  AC_SUBST([GETADDRINFO_LIB])
 ])
 
-# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
+# Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
-  AC_SEARCH_LIBS(gethostbyname, [inet nsl])
-  AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
-  AC_CHECK_FUNCS(gethostbyname,, [
-    AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
-		   gl_cv_w32_gethostbyname, [
-      gl_cv_w32_gethostbyname=no
-      am_save_LIBS="$LIBS"
-      LIBS="$LIBS -lws2_32"
-      AC_TRY_LINK([
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-#include <stddef.h>
-], [gethostbyname(NULL);], gl_cv_w32_gethostbyname=yes)
-    LIBS="$am_save_LIBS"])
-    if test "$gl_cv_w32_gethostbyname" = "yes"; then
-      LIBS="$LIBS -lws2_32"
-    fi
-    ])
+  AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
+  AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
   AC_REQUIRE([AC_C_RESTRICT])
   AC_REQUIRE([gl_SOCKET_FAMILIES])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
@@ -104,7 +106,8 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
   dnl have sa_len so the result is correct anyway.
   AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
 
-  AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
+  AC_CHECK_HEADERS_ONCE([netinet/in.h])
+
   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
@@ -120,6 +123,19 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
 #include <ws2tcpip.h>
 #endif
 ])
+  if test $ac_cv_have_decl_getaddrinfo = no; then
+    HAVE_DECL_GETADDRINFO=0
+  fi
+  if test $ac_cv_have_decl_freeaddrinfo = no; then
+    HAVE_DECL_FREEADDRINFO=0
+  fi
+  if test $ac_cv_have_decl_gai_strerror = no; then
+    HAVE_DECL_GAI_STRERROR=0
+  fi
+  if test $ac_cv_have_decl_getnameinfo = no; then
+    HAVE_DECL_GETNAMEINFO=0
+  fi
+
   AC_CHECK_TYPES([struct addrinfo],,,[
 #include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
@@ -132,4 +148,19 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
 #include <ws2tcpip.h>
 #endif
 ])
+  if test $ac_cv_type_struct_addrinfo = no; then
+    HAVE_STRUCT_ADDRINFO=0
+  fi
+
+  dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
+  case " $GETADDRINFO_LIB " in
+    *" $HOSTENT_LIB "*) ;;
+    *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
+  esac
+
+  dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
+  case " $GETADDRINFO_LIB " in
+    *" $SERVENT_LIB "*) ;;
+    *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
+  esac
 ])
diff --git a/libmissing/m4/getpagesize.m4 b/libmissing/m4/getpagesize.m4
new file mode 100644
index 0000000..0d07a3a
--- /dev/null
+++ b/libmissing/m4/getpagesize.m4
@@ -0,0 +1,29 @@
+# getpagesize.m4 serial 7
+dnl Copyright (C) 2002, 2004-2005, 2007 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_GETPAGESIZE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CHECK_FUNCS([getpagesize])
+  if test $ac_cv_func_getpagesize = no; then
+    HAVE_GETPAGESIZE=0
+    AC_CHECK_HEADERS([OS.h])
+    if test $ac_cv_header_OS_h = yes; then
+      HAVE_OS_H=1
+    fi
+    AC_CHECK_HEADERS([sys/param.h])
+    if test $ac_cv_header_sys_param_h = yes; then
+      HAVE_SYS_PARAM_H=1
+    fi
+  fi
+  case "$host_os" in
+    mingw*)
+      REPLACE_GETPAGESIZE=1
+      AC_LIBOBJ([getpagesize])
+      ;;
+  esac
+])
diff --git a/libmissing/m4/glibc21.m4 b/libmissing/m4/glibc21.m4
new file mode 100644
index 0000000..93fbf47
--- /dev/null
+++ b/libmissing/m4/glibc21.m4
@@ -0,0 +1,30 @@
+# glibc21.m4 serial 4
+dnl Copyright (C) 2000-2002, 2004, 2008 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.
+
+# Test for the GNU C Library, version 2.1 or newer.
+# From Bruno Haible.
+
+AC_DEFUN([gl_GLIBC21],
+  [
+    AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer],
+      [ac_cv_gnu_library_2_1],
+      [AC_EGREP_CPP([Lucky GNU user],
+	[
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
+  Lucky GNU user
+ #endif
+#endif
+	],
+	[ac_cv_gnu_library_2_1=yes],
+	[ac_cv_gnu_library_2_1=no])
+      ]
+    )
+    AC_SUBST([GLIBC21])
+    GLIBC21="$ac_cv_gnu_library_2_1"
+  ]
+)
diff --git a/libmissing/m4/gnulib-cache.m4 b/libmissing/m4/gnulib-cache.m4
index dd26813..8f26ddc 100644
--- a/libmissing/m4/gnulib-cache.m4
+++ b/libmissing/m4/gnulib-cache.m4
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 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
@@ -15,7 +15,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob inet_ntop memset mktime pathmax recvfrom sigaction sleep snprintf socket socklen strdup strptime strsep sys_select
+#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob inet_ntop mktime pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
@@ -26,16 +26,15 @@ gl_MODULES([
   getaddrinfo
   glob
   inet_ntop
-  memset
   mktime
   pathmax
   recvfrom
+  servent
   sigaction
   sleep
   snprintf
   socket
   socklen
-  strdup
   strptime
   strsep
   sys_select
diff --git a/libmissing/m4/gnulib-common.m4 b/libmissing/m4/gnulib-common.m4
index 34d91c7..c8fda20 100644
--- a/libmissing/m4/gnulib-common.m4
+++ b/libmissing/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
-# gnulib-common.m4 serial 5
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# gnulib-common.m4 serial 11
+dnl Copyright (C) 2007-2009 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.
@@ -8,6 +8,7 @@ dnl with or without modifications, as long as this notice is preserved.
 # is expanded unconditionally through gnulib-tool magic.
 AC_DEFUN([gl_COMMON], [
   dnl Use AC_REQUIRE here, so that the code is expanded once only.
+  AC_REQUIRE([gl_00GNULIB])
   AC_REQUIRE([gl_COMMON_BODY])
 ])
 AC_DEFUN([gl_COMMON_BODY], [
@@ -21,6 +22,16 @@ AC_DEFUN([gl_COMMON_BODY], [
 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
 # define __GNUC_STDC_INLINE__ 1
 #endif])
+  AH_VERBATIM([unused_parameter],
+[/* Define as a marker that can be attached to function parameter declarations
+   for parameters that are not used.  This helps to reduce warnings, such as
+   from GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _UNUSED_PARAMETER_ __attribute__ ((__unused__))
+#else
+# define _UNUSED_PARAMETER_
+#endif
+])
 ])
 
 # gl_MODULE_INDICATOR([modulename])
@@ -42,7 +53,7 @@ m4_ifndef([m4_foreach_w],
 # is a backport of autoconf-2.60's AC_PROG_MKDIR_P.
 # Remove this macro when we can assume autoconf >= 2.60.
 m4_ifdef([AC_PROG_MKDIR_P], [], [
-  AC_DEFUN([AC_PROG_MKDIR_P],
+  AC_DEFUN_ONCE([AC_PROG_MKDIR_P],
     [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
      MKDIR_P='$(mkdir_p)'
      AC_SUBST([MKDIR_P])])])
@@ -53,7 +64,7 @@ m4_ifdef([AC_PROG_MKDIR_P], [], [
 # works.
 # This definition can be removed once autoconf >= 2.62 can be assumed.
 AC_DEFUN([AC_C_RESTRICT],
-[AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
+[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
   [ac_cv_c_restrict=no
    # The order here caters to the fact that C++ does not require restrict.
    for ac_kw in __restrict __restrict__ _Restrict restrict; do
@@ -89,3 +100,25 @@ AC_DEFUN([AC_C_RESTRICT],
    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
  esac
 ])
+
+# gl_BIGENDIAN
+# is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
+# Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
+# macros invoke AC_C_BIGENDIAN with arguments.
+AC_DEFUN([gl_BIGENDIAN],
+[
+  AC_C_BIGENDIAN
+])
+
+# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
+# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
+# output a spurious "(cached)" mark in the midst of other configure output.
+# This macro should be used instead of AC_CACHE_VAL when it is not surrounded
+# by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
+AC_DEFUN([gl_CACHE_VAL_SILENT],
+[
+  saved_as_echo_n="$as_echo_n"
+  as_echo_n=':'
+  AC_CACHE_VAL([$1], [$2])
+  as_echo_n="$saved_as_echo_n"
+])
diff --git a/libmissing/m4/gnulib-comp.m4 b/libmissing/m4/gnulib-comp.m4
index a127eca..0be0ee1 100644
--- a/libmissing/m4/gnulib-comp.m4
+++ b/libmissing/m4/gnulib-comp.m4
@@ -1,5 +1,5 @@
 # DO NOT EDIT! GENERATED AUTOMATICALLY!
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 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
@@ -50,47 +50,65 @@ AC_SUBST([LTALLOCA])
   AC_PROG_MKDIR_P
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([winsock])
+    AC_LIBOBJ([bind])
   fi
   gl_SYS_SOCKET_MODULE_INDICATOR([bind])
   gl_FUNC_CLOSE
   gl_UNISTD_MODULE_INDICATOR([close])
   gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE
+  gl_DIRENT_H
   gl_FUNC_DIRFD
+  gl_DIRENT_MODULE_INDICATOR([dirfd])
   gl_HEADER_ERRNO_H
   gl_FUNC_FCLOSE
   gl_STDIO_MODULE_INDICATOR([fclose])
   gl_FLOAT_H
-  # No macro. You should also use one of fnmatch-posix or fnmatch-gnu.
+  gl_FUNC_FNMATCH_POSIX
   gl_FUNC_FNMATCH_GNU
   gl_GETADDRINFO
+  gl_NETDB_MODULE_INDICATOR([getaddrinfo])
   gl_GETLOGIN_R
   gl_UNISTD_MODULE_INDICATOR([getlogin_r])
+  gl_FUNC_GETPAGESIZE
+  gl_UNISTD_MODULE_INDICATOR([getpagesize])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([winsock])
+    AC_LIBOBJ([getpeername])
   fi
   gl_SYS_SOCKET_MODULE_INDICATOR([getpeername])
   AC_SUBST([LIBINTL])
   AC_SUBST([LTLIBINTL])
   gl_GLOB
+  gl_HOSTENT
   gl_INET_NTOP
   gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
+  gl_LOCALCHARSET
+  LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\""
+  AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
   gl_FUNC_MALLOC_POSIX
   gl_STDLIB_MODULE_INDICATOR([malloc-posix])
+  gl_FUNC_MBRTOWC
+  gl_WCHAR_MODULE_INDICATOR([mbrtowc])
+  gl_FUNC_MBSINIT
+  gl_WCHAR_MODULE_INDICATOR([mbsinit])
+  gl_FUNC_MBSRTOWCS
+  gl_WCHAR_MODULE_INDICATOR([mbsrtowcs])
+  gl_FUNC_MEMCHR
+  gl_STRING_MODULE_INDICATOR([memchr])
   gl_FUNC_MEMPCPY
   gl_STRING_MODULE_INDICATOR([mempcpy])
-  gl_FUNC_MEMSET
   gl_FUNC_MKTIME
+  gl_MULTIARCH
+  gl_HEADER_NETDB
   gl_HEADER_NETINET_IN
   AC_PROG_MKDIR_P
   gl_PATHMAX
-  AC_REPLACE_FUNCS(raise)
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([winsock])
+    AC_LIBOBJ([recvfrom])
   fi
   gl_SYS_SOCKET_MODULE_INDICATOR([recvfrom])
+  gl_SERVENT
   gl_SIGACTION
   gl_SIGNAL_MODULE_INDICATOR([sigaction])
   gl_SIGNAL_H
@@ -103,7 +121,7 @@ AC_SUBST([LTALLOCA])
   gl_STDIO_MODULE_INDICATOR([snprintf])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
-    AC_LIBOBJ([winsock])
+    AC_LIBOBJ([socket])
   fi
   gl_SYS_SOCKET_MODULE_INDICATOR([socket])
   gl_TYPE_SOCKLEN_T
@@ -112,19 +130,14 @@ AC_SUBST([LTALLOCA])
   gl_STDIO_H
   gl_STDLIB_H
   gl_STRCASE
-  gl_FUNC_STRDUP
-  gl_STRING_MODULE_INDICATOR([strdup])
   gl_HEADER_STRING_H
   gl_HEADER_STRINGS_H
-  gl_FUNC_STRPBRK
-  gl_STRING_MODULE_INDICATOR([strpbrk])
   gl_FUNC_STRPTIME
   gl_FUNC_STRSEP
   gl_STRING_MODULE_INDICATOR([strsep])
   gl_HEADER_SYS_SELECT
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_SOCKET
-  gl_MODULE_INDICATOR([sys_socket])
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_STAT_H
   AC_PROG_MKDIR_P
@@ -176,9 +189,22 @@ AC_SUBST([LTALLOCA])
   m4_pushdef([gltests_LIBSOURCES_DIR], [])
   gl_COMMON
   gl_source_base='libmissing/tests'
+  gt_LOCALE_FR
+  gt_LOCALE_FR_UTF8
+  gt_LOCALE_JA
+  gt_LOCALE_ZH_CN
+  gt_LOCALE_FR_UTF8
+  gt_LOCALE_FR
+  gt_LOCALE_FR_UTF8
+  gt_LOCALE_JA
+  gt_LOCALE_ZH_CN
   gt_TYPE_WCHAR_T
   gt_TYPE_WINT_T
+  gl_FUNC_STRERROR
+  gl_STRING_MODULE_INDICATOR([strerror])
   AC_CHECK_FUNCS([shutdown])
+  gl_FUNC_WCTOB
+  gl_WCHAR_MODULE_INDICATOR([wctob])
   m4_ifval(gltests_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ ||
       for gl_file in ]gltests_LIBSOURCES_LIST[ ; do
@@ -271,14 +297,18 @@ AC_DEFUN([gltests_LIBSOURCES], [
 # gnulib-tool and may be removed by future gnulib-tool invocations.
 AC_DEFUN([gl_FILE_LIST], [
   build-aux/link-warning.h
+  lib/alignof.h
   lib/alloca.c
   lib/alloca.in.h
   lib/arpa_inet.in.h
   lib/asnprintf.c
+  lib/bind.c
+  lib/close-hook.c
+  lib/close-hook.h
   lib/close.c
+  lib/config.charset
+  lib/dirent.in.h
   lib/dirfd.c
-  lib/dirfd.h
-  lib/dummy.c
   lib/errno.in.h
   lib/fclose.c
   lib/float+.h
@@ -288,24 +318,35 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/fnmatch_loop.c
   lib/gai_strerror.c
   lib/getaddrinfo.c
-  lib/getaddrinfo.h
   lib/getlogin_r.c
+  lib/getpagesize.c
+  lib/getpeername.c
   lib/gettext.h
   lib/glob-libc.h
   lib/glob.c
   lib/glob.in.h
   lib/inet_ntop.c
+  lib/localcharset.c
+  lib/localcharset.h
   lib/malloc.c
+  lib/mbrtowc.c
+  lib/mbsinit.c
+  lib/mbsrtowcs-state.c
+  lib/mbsrtowcs.c
+  lib/memchr.c
+  lib/memchr.valgrind
   lib/mempcpy.c
-  lib/memset.c
   lib/mktime.c
+  lib/netdb.in.h
   lib/netinet_in.in.h
   lib/pathmax.h
   lib/printf-args.c
   lib/printf-args.h
   lib/printf-parse.c
   lib/printf-parse.h
-  lib/raise.c
+  lib/recvfrom.c
+  lib/ref-add.sin
+  lib/ref-del.sin
   lib/sig-handler.h
   lib/sigaction.c
   lib/signal.in.h
@@ -313,17 +354,19 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/size_max.h
   lib/sleep.c
   lib/snprintf.c
+  lib/socket.c
   lib/stdbool.in.h
   lib/stdint.in.h
   lib/stdio-write.c
   lib/stdio.in.h
   lib/stdlib.in.h
   lib/strcasecmp.c
-  lib/strdup.c
+  lib/streq.h
   lib/string.in.h
   lib/strings.in.h
   lib/strncasecmp.c
-  lib/strpbrk.c
+  lib/strnlen1.c
+  lib/strnlen1.h
   lib/strptime.c
   lib/strsep.c
   lib/sys_select.in.h
@@ -335,14 +378,18 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/unistd.in.h
   lib/vasnprintf.c
   lib/vasnprintf.h
+  lib/verify.h
+  lib/w32sock.h
   lib/wchar.in.h
   lib/wctype.in.h
-  lib/winsock.c
   lib/xsize.h
+  m4/00gnulib.m4
   m4/alloca.m4
   m4/arpa_inet_h.m4
   m4/close.m4
+  m4/codeset.m4
   m4/d-type.m4
+  m4/dirent_h.m4
   m4/dirfd.m4
   m4/errno_h.m4
   m4/extensions.m4
@@ -351,22 +398,36 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/fnmatch.m4
   m4/getaddrinfo.m4
   m4/getlogin_r.m4
+  m4/getpagesize.m4
+  m4/glibc21.m4
   m4/glob.m4
   m4/gnulib-common.m4
+  m4/hostent.m4
   m4/include_next.m4
   m4/inet_ntop.m4
   m4/intmax_t.m4
   m4/inttypes_h.m4
+  m4/localcharset.m4
+  m4/locale-fr.m4
+  m4/locale-ja.m4
+  m4/locale-zh.m4
   m4/longlong.m4
   m4/malloc.m4
+  m4/mbrtowc.m4
+  m4/mbsinit.m4
+  m4/mbsrtowcs.m4
   m4/mbstate_t.m4
+  m4/memchr.m4
   m4/mempcpy.m4
-  m4/memset.m4
   m4/mktime.m4
+  m4/mmap-anon.m4
+  m4/multiarch.m4
+  m4/netdb_h.m4
   m4/netinet_in_h.m4
   m4/onceonly.m4
   m4/pathmax.m4
   m4/printf.m4
+  m4/servent.m4
   m4/sigaction.m4
   m4/signal_h.m4
   m4/signalblocking.m4
@@ -381,13 +442,11 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/stdio_h.m4
   m4/stdlib_h.m4
   m4/strcase.m4
-  m4/strdup.m4
+  m4/strerror.m4
   m4/string_h.m4
   m4/strings_h.m4
-  m4/strpbrk.m4
   m4/strptime.m4
   m4/strsep.m4
-  m4/sys_ioctl_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
@@ -399,21 +458,41 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/vasnprintf.m4
   m4/wchar.m4
   m4/wchar_t.m4
+  m4/wctob.m4
   m4/wctype.m4
   m4/wint_t.m4
   m4/xsize.m4
+  tests/test-alignof.c
   tests/test-alloca-opt.c
   tests/test-arpa_inet.c
   tests/test-errno.c
+  tests/test-fnmatch.c
   tests/test-getaddrinfo.c
+  tests/test-glob.c
+  tests/test-mbrtowc.c
+  tests/test-mbrtowc1.sh
+  tests/test-mbrtowc2.sh
+  tests/test-mbrtowc3.sh
+  tests/test-mbrtowc4.sh
+  tests/test-mbsinit.c
+  tests/test-mbsinit.sh
+  tests/test-mbsrtowcs.c
+  tests/test-mbsrtowcs1.sh
+  tests/test-mbsrtowcs2.sh
+  tests/test-mbsrtowcs3.sh
+  tests/test-mbsrtowcs4.sh
+  tests/test-memchr.c
+  tests/test-netdb.c
   tests/test-netinet_in.c
   tests/test-sigaction.c
+  tests/test-signal.c
   tests/test-sleep.c
   tests/test-snprintf.c
   tests/test-stdbool.c
   tests/test-stdint.c
   tests/test-stdio.c
   tests/test-stdlib.c
+  tests/test-strerror.c
   tests/test-string.c
   tests/test-strings.c
   tests/test-sys_select.c
@@ -425,7 +504,9 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-vasnprintf.c
   tests/test-wchar.c
   tests/test-wctype.c
+  tests/zerosize-ptr.h
   tests=lib/dummy.c
   tests=lib/intprops.h
-  tests=lib/verify.h
+  tests=lib/strerror.c
+  tests=lib/wctob.c
 ])
diff --git a/libmissing/m4/hostent.m4 b/libmissing/m4/hostent.m4
new file mode 100644
index 0000000..4a96af7
--- /dev/null
+++ b/libmissing/m4/hostent.m4
@@ -0,0 +1,45 @@
+# hostent.m4 serial 1
+dnl Copyright (C) 2008 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_HOSTENT],
+[
+  dnl Where are gethostent(), sethostent(), endhostent(), gethostbyname(),
+  dnl gethostbyaddr() defined?
+  dnl - On Solaris, they are in libnsl. Ignore libxnet.
+  dnl - On Haiku, they are in libnetwork.
+  dnl - On BeOS, they are in libnet.
+  dnl - On native Windows, they are in ws2_32.dll.
+  dnl - Otherwise they are in libc.
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+  HOSTENT_LIB=
+  gl_saved_libs="$LIBS"
+  AC_SEARCH_LIBS([gethostbyname], [nsl network net],
+    [if test "$ac_cv_search_gethostbyname" != "none required"; then
+       HOSTENT_LIB="$ac_cv_search_gethostbyname"
+     fi])
+  LIBS="$gl_saved_libs"
+  if test -z "$HOSTENT_LIB"; then
+    AC_CHECK_FUNCS([gethostbyname], , [
+      AC_CACHE_CHECK([for gethostbyname in winsock2.h and -lws2_32],
+        [gl_cv_w32_gethostbyname],
+        [gl_cv_w32_gethostbyname=no
+         gl_save_LIBS="$LIBS"
+         LIBS="$LIBS -lws2_32"
+         AC_TRY_LINK([
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#include <stddef.h>
+], [gethostbyname(NULL);], [gl_cv_w32_gethostbyname=yes])
+         LIBS="$gl_save_LIBS"
+        ])
+      if test "$gl_cv_w32_gethostbyname" = "yes"; then
+        HOSTENT_LIB="-lws2_32"
+      fi
+    ])
+  fi
+  AC_SUBST([HOSTENT_LIB])
+])
diff --git a/libmissing/m4/include_next.m4 b/libmissing/m4/include_next.m4
index b6e4d3a..5e22ded 100644
--- a/libmissing/m4/include_next.m4
+++ b/libmissing/m4/include_next.m4
@@ -1,5 +1,5 @@
-# include_next.m4 serial 8
-dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
+# include_next.m4 serial 14
+dnl Copyright (C) 2006-2009 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.
@@ -11,6 +11,10 @@ dnl
 dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
 dnl 'include' otherwise.
 dnl
+dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
+dnl supports it in the special case that it is the first include directive in
+dnl the given file, or to 'include' otherwise.
+dnl
 dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
 dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
 dnl '#pragma GCC system_header' has the same effect as if the file was found
@@ -26,12 +30,27 @@ AC_DEFUN([gl_INCLUDE_NEXT],
   AC_LANG_PREPROC_REQUIRE()
   AC_CACHE_CHECK([whether the preprocessor supports include_next],
     [gl_cv_have_include_next],
-    [rm -rf conftestd1 conftestd2
-     mkdir conftestd1 conftestd2
-     dnl The include of <stdio.h> is because IBM C 9.0 on AIX 6.1 supports
-     dnl include_next when used as first preprocessor directive in a file,
-     dnl but not when preceded by another include directive.
-     cat <<EOF > conftestd1/conftest.h
+    [rm -rf conftestd1a conftestd1b conftestd2
+     mkdir conftestd1a conftestd1b conftestd2
+     dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on
+     dnl AIX 6.1 support include_next when used as first preprocessor directive
+     dnl in a file, but not when preceded by another include directive. Check
+     dnl for this bug by including <stdio.h>.
+     dnl Additionally, with this same compiler, include_next is a no-op when
+     dnl used in a header file that was included by specifying its absolute
+     dnl file name. Despite these two bugs, include_next is used in the
+     dnl compiler's <math.h>. By virtue of the second bug, we need to use
+     dnl include_next as well in this case.
+     cat <<EOF > conftestd1a/conftest.h
+#define DEFINED_IN_CONFTESTD1
+#include_next <conftest.h>
+#ifdef DEFINED_IN_CONFTESTD2
+int foo;
+#else
+#error "include_next doesn't work"
+#endif
+EOF
+     cat <<EOF > conftestd1b/conftest.h
 #define DEFINED_IN_CONFTESTD1
 #include <stdio.h>
 #include_next <conftest.h>
@@ -47,24 +66,36 @@ EOF
 #endif
 #define DEFINED_IN_CONFTESTD2
 EOF
-     save_CPPFLAGS="$CPPFLAGS"
-     CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2"
+     gl_save_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2"
      AC_COMPILE_IFELSE([#include <conftest.h>],
        [gl_cv_have_include_next=yes],
-       [gl_cv_have_include_next=no])
-     CPPFLAGS="$save_CPPFLAGS"
-     rm -rf conftestd1 conftestd2
+       [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2"
+        AC_COMPILE_IFELSE([#include <conftest.h>],
+          [gl_cv_have_include_next=buggy],
+          [gl_cv_have_include_next=no])
+       ])
+     CPPFLAGS="$gl_save_CPPFLAGS"
+     rm -rf conftestd1a conftestd1b conftestd2
     ])
   PRAGMA_SYSTEM_HEADER=
   if test $gl_cv_have_include_next = yes; then
     INCLUDE_NEXT=include_next
+    INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
     if test -n "$GCC"; then
       PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
     fi
   else
-    INCLUDE_NEXT=include
+    if test $gl_cv_have_include_next = buggy; then
+      INCLUDE_NEXT=include
+      INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
+    else
+      INCLUDE_NEXT=include
+      INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
+    fi
   fi
   AC_SUBST([INCLUDE_NEXT])
+  AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
   AC_SUBST([PRAGMA_SYSTEM_HEADER])
 ])
 
@@ -73,8 +104,14 @@ EOF
 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
 # '<foo.h>'; otherwise define it to be
 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
+# Also, if #include_next works as first preprocessing directive in a file,
+# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
+# be
+# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
 # That way, a header file with the following line:
 #	#@INCLUDE_NEXT@ @NEXT_FOO_H@
+# or
+#	#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
 # behaves (after sed substitution) as if it contained
 #	#include_next <foo.h>
 # even if the compiler does not support include_next.
@@ -87,31 +124,43 @@ EOF
 AC_DEFUN([gl_CHECK_NEXT_HEADERS],
 [
   AC_REQUIRE([gl_INCLUDE_NEXT])
+  AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CHECK_HEADERS_ONCE([$1])
 
   m4_foreach_w([gl_HEADER_NAME], [$1],
     [AS_VAR_PUSHDEF([gl_next_header],
-		    [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
+		    [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'>'])
      else
        AC_CACHE_CHECK(
-	 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
-	 m4_quote(m4_defn([gl_next_header])),
+	 [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
+	 m4_defn([gl_next_header]),
 	 [AS_VAR_PUSHDEF([gl_header_exists],
-			 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
+			 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
 	  if test AS_VAR_GET(gl_header_exists) = yes; then
 	    AC_LANG_CONFTEST(
 	      [AC_LANG_SOURCE(
 		 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
 	       )])
-	    dnl eval is necessary to expand ac_cpp.
+	    dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
+	    dnl that contain only a #include of other header files and no
+	    dnl non-comment tokens of their own. This leads to a failure to
+	    dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
+	    dnl and others. The workaround is to force preservation of comments
+	    dnl through option -C. This ensures all necessary #line directives
+	    dnl are present. GCC supports option -C as well.
+	    case "$host_os" in
+	      aix*) gl_absname_cpp="$ac_cpp -C" ;;
+	      *)    gl_absname_cpp="$ac_cpp" ;;
+	    esac
+	    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 "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
-	       sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
-		 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
+	      ['"'`(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
@@ -122,7 +171,17 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
 	  AS_VAR_POPDEF([gl_header_exists])])
      fi
      AC_SUBST(
-       AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
+       AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
        [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])
+     fi
+     AC_SUBST(
+       AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
+       [$gl_next_as_first_directive])
      AS_VAR_POPDEF([gl_next_header])])
 ])
diff --git a/libmissing/m4/inet_ntop.m4 b/libmissing/m4/inet_ntop.m4
index 6f87306..2bbdca1 100644
--- a/libmissing/m4/inet_ntop.m4
+++ b/libmissing/m4/inet_ntop.m4
@@ -1,5 +1,5 @@
-# inet_ntop.m4 serial 7
-dnl Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
+# inet_ntop.m4 serial 9
+dnl Copyright (C) 2005, 2006, 2008, 2009 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.
@@ -11,7 +11,18 @@ AC_DEFUN([gl_INET_NTOP],
 
   gl_REPLACE_ARPA_INET_H
 
-  AC_REPLACE_FUNCS(inet_ntop)
+  dnl The AC_SEARCH_LIBS call is a hack to persuade the Solaris 8 linker to
+  dnl find inet_ntop.
+  dnl
+  dnl It is the responsibility of gl_INET_NTOP's caller to arrange for
+  dnl -lnsl if it is needed.  Normally -lnsl is not needed on Solaris 8,
+  dnl since inet_ntop is needed only by getaddrinfo, and getaddrinfo
+  dnl isn't built on Solaris 8.
+  gl_save_LIBS=$LIBS
+  AC_SEARCH_LIBS([inet_ntop], [nsl], [],
+    [AC_REPLACE_FUNCS([inet_ntop])])
+  LIBS=$gl_save_LIBS
+
   gl_PREREQ_INET_NTOP
 ])
 
diff --git a/libmissing/m4/intmax_t.m4 b/libmissing/m4/intmax_t.m4
index 50ae35d..264cb57 100644
--- a/libmissing/m4/intmax_t.m4
+++ b/libmissing/m4/intmax_t.m4
@@ -1,12 +1,12 @@
-# intmax_t.m4 serial 6
-dnl Copyright (C) 1997-2004, 2006-2007 Free Software Foundation, Inc.
+# intmax_t.m4 serial 7
+dnl Copyright (C) 1997-2004, 2006-2007, 2009 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 Paul Eggert.
 
-AC_PREREQ(2.13)
+AC_PREREQ([2.13])
 
 # Define intmax_t to 'long' or 'long long'
 # if it is not already defined in <stdint.h> or <inttypes.h>.
@@ -22,10 +22,10 @@ AC_DEFUN([gl_AC_TYPE_INTMAX_T],
     test $ac_cv_type_long_long_int = yes \
       && ac_type='long long' \
       || ac_type='long'
-    AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
+    AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
      [Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
   else
-    AC_DEFINE(HAVE_INTMAX_T, 1,
+    AC_DEFINE([HAVE_INTMAX_T], [1],
       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
   fi
 ])
@@ -36,7 +36,7 @@ AC_DEFUN([gt_AC_TYPE_INTMAX_T],
 [
   AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
   AC_REQUIRE([gl_AC_HEADER_STDINT_H])
-  AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
+  AC_CACHE_CHECK([for intmax_t], [gt_cv_c_intmax_t],
     [AC_TRY_COMPILE([
 #include <stddef.h>
 #include <stdlib.h>
@@ -48,14 +48,14 @@ AC_DEFUN([gt_AC_TYPE_INTMAX_T],
 #endif
 ], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
   if test $gt_cv_c_intmax_t = yes; then
-    AC_DEFINE(HAVE_INTMAX_T, 1,
+    AC_DEFINE([HAVE_INTMAX_T], [1],
       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
   else
     AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
     test $ac_cv_type_long_long_int = yes \
       && ac_type='long long' \
       || ac_type='long'
-    AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
+    AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
      [Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
   fi
 ])
diff --git a/libmissing/m4/inttypes_h.m4 b/libmissing/m4/inttypes_h.m4
index edc8ecb..f4ca160 100644
--- a/libmissing/m4/inttypes_h.m4
+++ b/libmissing/m4/inttypes_h.m4
@@ -1,5 +1,5 @@
-# inttypes_h.m4 serial 7
-dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc.
+# inttypes_h.m4 serial 9
+dnl Copyright (C) 1997-2004, 2006, 2008, 2009 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.
@@ -11,15 +11,15 @@ dnl From Paul Eggert.
 
 AC_DEFUN([gl_AC_HEADER_INTTYPES_H],
 [
-  AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h,
+  AC_CACHE_CHECK([for inttypes.h], [gl_cv_header_inttypes_h],
   [AC_TRY_COMPILE(
     [#include <sys/types.h>
 #include <inttypes.h>],
     [uintmax_t i = (uintmax_t) -1; return !i;],
-    gl_cv_header_inttypes_h=yes,
-    gl_cv_header_inttypes_h=no)])
+    [gl_cv_header_inttypes_h=yes],
+    [gl_cv_header_inttypes_h=no])])
   if test $gl_cv_header_inttypes_h = yes; then
-    AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1,
+    AC_DEFINE_UNQUOTED([HAVE_INTTYPES_H_WITH_UINTMAX], [1],
       [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
        and declares uintmax_t. ])
   fi
diff --git a/libmissing/m4/localcharset.m4 b/libmissing/m4/localcharset.m4
new file mode 100644
index 0000000..e960104
--- /dev/null
+++ b/libmissing/m4/localcharset.m4
@@ -0,0 +1,16 @@
+# localcharset.m4 serial 6
+dnl Copyright (C) 2002, 2004, 2006, 2009 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_LOCALCHARSET],
+[
+  dnl Prerequisites of lib/localcharset.c.
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CHECK_DECLS_ONCE([getc_unlocked])
+
+  dnl Prerequisites of the lib/Makefile.am snippet.
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([gl_GLIBC21])
+])
diff --git a/libmissing/m4/locale-fr.m4 b/libmissing/m4/locale-fr.m4
new file mode 100644
index 0000000..653a5bc
--- /dev/null
+++ b/libmissing/m4/locale-fr.m4
@@ -0,0 +1,185 @@
+# locale-fr.m4 serial 11
+dnl Copyright (C) 2003, 2005-2009 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 Determine the name of a french locale with traditional encoding.
+AC_DEFUN([gt_LOCALE_FR],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [
+    AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether in the abbreviation of the second month, the second
+     character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
+     one byte long. This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
+  /* Check whether the decimal separator is a comma.
+     On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+     are nl_langinfo(RADIXCHAR) are both ".".  */
+  if (localeconv () ->decimal_point[0] != ',') return 1;
+  return 0;
+}
+changequote([,])dnl
+      ])])
+    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+      # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+      # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+      # configure script would override the LC_ALL setting. Likewise for
+      # LC_CTYPE, which is also set at the beginning of the configure script.
+      # Test for the usual locale name.
+      if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+        gt_cv_locale_fr=fr_FR
+      else
+        # Test for the locale name with explicit encoding suffix.
+        if (LC_ALL=fr_FR.ISO-8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_fr=fr_FR.ISO-8859-1
+        else
+          # Test for the AIX, OSF/1, FreeBSD, NetBSD, OpenBSD locale name.
+          if (LC_ALL=fr_FR.ISO8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+            gt_cv_locale_fr=fr_FR.ISO8859-1
+          else
+            # Test for the HP-UX locale name.
+            if (LC_ALL=fr_FR.iso88591 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+              gt_cv_locale_fr=fr_FR.iso88591
+            else
+              # Test for the Solaris 7 locale name.
+              if (LC_ALL=fr LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+                gt_cv_locale_fr=fr
+              else
+                # None found.
+                gt_cv_locale_fr=none
+              fi
+            fi
+          fi
+        fi
+      fi
+    fi
+    rm -fr conftest*
+  ])
+  LOCALE_FR=$gt_cv_locale_fr
+  AC_SUBST([LOCALE_FR])
+])
+
+dnl Determine the name of a french locale with UTF-8 encoding.
+AC_DEFUN([gt_LOCALE_FR_UTF8],
+[
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [
+    AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if !(defined __BEOS__ || defined __HAIKU__)
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+# if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+# endif
+# ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+# endif
+  /* Check whether in the abbreviation of the second month, the second
+     character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is
+     two bytes long, with UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%b", &t) < 4
+      || buf[1] != (char) 0xc3 || buf[2] != (char) 0xa9 || buf[3] != 'v')
+    return 1;
+#endif
+  /* Check whether the decimal separator is a comma.
+     On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+     are nl_langinfo(RADIXCHAR) are both ".".  */
+  if (localeconv () ->decimal_point[0] != ',') return 1;
+  return 0;
+}
+changequote([,])dnl
+      ])])
+    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+      # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+      # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+      # configure script would override the LC_ALL setting. Likewise for
+      # LC_CTYPE, which is also set at the beginning of the configure script.
+      # Test for the usual locale name.
+      if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+        gt_cv_locale_fr_utf8=fr_FR
+      else
+        # Test for the locale name with explicit encoding suffix.
+        if (LC_ALL=fr_FR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_fr_utf8=fr_FR.UTF-8
+        else
+          # Test for the Solaris 7 locale name.
+          if (LC_ALL=fr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+            gt_cv_locale_fr_utf8=fr.UTF-8
+          else
+            # None found.
+            gt_cv_locale_fr_utf8=none
+          fi
+        fi
+      fi
+    fi
+    rm -fr conftest*
+  ])
+  LOCALE_FR_UTF8=$gt_cv_locale_fr_utf8
+  AC_SUBST([LOCALE_FR_UTF8])
+])
diff --git a/libmissing/m4/locale-ja.m4 b/libmissing/m4/locale-ja.m4
new file mode 100644
index 0000000..9360576
--- /dev/null
+++ b/libmissing/m4/locale-ja.m4
@@ -0,0 +1,107 @@
+# locale-ja.m4 serial 7
+dnl Copyright (C) 2003, 2005-2009 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 Determine the name of a japanese locale with EUC-JP encoding.
+AC_DEFUN([gt_LOCALE_JA],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
+    AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+  const char *p;
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether MB_CUR_MAX is > 1.  This excludes the dysfunctional locales
+     on Cygwin 1.5.x.  */
+  if (MB_CUR_MAX == 1)
+    return 1;
+  /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+     This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+  for (p = buf; *p != '\0'; p++)
+    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+      return 1;
+  return 0;
+}
+changequote([,])dnl
+      ])])
+    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+      # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+      # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+      # configure script would override the LC_ALL setting. Likewise for
+      # LC_CTYPE, which is also set at the beginning of the configure script.
+      # Test for the AIX locale name.
+      if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+        gt_cv_locale_ja=ja_JP
+      else
+        # Test for the locale name with explicit encoding suffix.
+        if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_ja=ja_JP.EUC-JP
+        else
+          # Test for the HP-UX, OSF/1, NetBSD locale name.
+          if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+            gt_cv_locale_ja=ja_JP.eucJP
+          else
+            # Test for the IRIX, FreeBSD locale name.
+            if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+              gt_cv_locale_ja=ja_JP.EUC
+            else
+              # Test for the Solaris 7 locale name.
+              if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+                gt_cv_locale_ja=ja
+              else
+                # Special test for NetBSD 1.6.
+                if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then
+                  gt_cv_locale_ja=ja_JP.eucJP
+                else
+                  # None found.
+                  gt_cv_locale_ja=none
+                fi
+              fi
+            fi
+          fi
+        fi
+      fi
+    fi
+    rm -fr conftest*
+  ])
+  LOCALE_JA=$gt_cv_locale_ja
+  AC_SUBST([LOCALE_JA])
+])
diff --git a/libmissing/m4/locale-zh.m4 b/libmissing/m4/locale-zh.m4
new file mode 100644
index 0000000..36a5f1d
--- /dev/null
+++ b/libmissing/m4/locale-zh.m4
@@ -0,0 +1,92 @@
+# locale-zh.m4 serial 6
+dnl Copyright (C) 2003, 2005-2009 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 Determine the name of a chinese locale with GB18030 encoding.
+AC_DEFUN([gt_LOCALE_ZH_CN],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
+    AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <stdlib.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+  const char *p;
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+     This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+  for (p = buf; *p != '\0'; p++)
+    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+      return 1;
+  /* Check whether a typical GB18030 multibyte sequence is recognized as a
+     single wide character.  This excludes the GB2312 and GBK encodings.  */
+  if (mblen ("\203\062\332\066", 5) != 4)
+    return 1;
+  return 0;
+}
+changequote([,])dnl
+      ])])
+    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+      # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+      # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+      # configure script would override the LC_ALL setting. Likewise for
+      # LC_CTYPE, which is also set at the beginning of the configure script.
+      # Test for the locale name without encoding suffix.
+      if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+        gt_cv_locale_zh_CN=zh_CN
+      else
+        # Test for the locale name with explicit encoding suffix.
+        if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_zh_CN=zh_CN.GB18030
+        else
+          # None found.
+          gt_cv_locale_zh_CN=none
+        fi
+      fi
+    else
+      # If there was a link error, due to mblen(), the system is so old that
+      # it certainly doesn't have a chinese locale.
+      gt_cv_locale_zh_CN=none
+    fi
+    rm -fr conftest*
+  ])
+  LOCALE_ZH_CN=$gt_cv_locale_zh_CN
+  AC_SUBST([LOCALE_ZH_CN])
+])
diff --git a/libmissing/m4/longlong.m4 b/libmissing/m4/longlong.m4
index 15bf9da..eedc8d5 100644
--- a/libmissing/m4/longlong.m4
+++ b/libmissing/m4/longlong.m4
@@ -1,5 +1,5 @@
-# longlong.m4 serial 13
-dnl Copyright (C) 1999-2007 Free Software Foundation, Inc.
+# longlong.m4 serial 14
+dnl Copyright (C) 1999-2007, 2009 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.
@@ -46,7 +46,7 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT],
 	  [ac_cv_type_long_long_int=yes])],
        [ac_cv_type_long_long_int=no])])
   if test $ac_cv_type_long_long_int = yes; then
-    AC_DEFINE([HAVE_LONG_LONG_INT], 1,
+    AC_DEFINE([HAVE_LONG_LONG_INT], [1],
       [Define to 1 if the system has the type `long long int'.])
   fi
 ])
@@ -69,7 +69,7 @@ AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
        [ac_cv_type_unsigned_long_long_int=yes],
        [ac_cv_type_unsigned_long_long_int=no])])
   if test $ac_cv_type_unsigned_long_long_int = yes; then
-    AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
+    AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
       [Define to 1 if the system has the type `unsigned long long int'.])
   fi
 ])
diff --git a/libmissing/m4/malloc.m4 b/libmissing/m4/malloc.m4
index 764f2a9..8070171 100644
--- a/libmissing/m4/malloc.m4
+++ b/libmissing/m4/malloc.m4
@@ -1,5 +1,5 @@
-# malloc.m4 serial 8
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# malloc.m4 serial 9
+dnl Copyright (C) 2007, 2009 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.
@@ -13,7 +13,7 @@ AC_DEFUN([gl_FUNC_MALLOC_POSIX],
   AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
   if test $gl_cv_func_malloc_posix = yes; then
     HAVE_MALLOC_POSIX=1
-    AC_DEFINE([HAVE_MALLOC_POSIX], 1,
+    AC_DEFINE([HAVE_MALLOC_POSIX], [1],
       [Define if the 'malloc' function is POSIX compliant.])
   else
     AC_LIBOBJ([malloc])
diff --git a/libmissing/m4/mbrtowc.m4 b/libmissing/m4/mbrtowc.m4
new file mode 100644
index 0000000..2fddcc8
--- /dev/null
+++ b/libmissing/m4/mbrtowc.m4
@@ -0,0 +1,383 @@
+# mbrtowc.m4 serial 16
+dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 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_MBRTOWC],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  gl_MBSTATE_T_BROKEN
+  if test $REPLACE_MBSTATE_T = 1; then
+    REPLACE_MBRTOWC=1
+  fi
+  AC_CHECK_FUNCS_ONCE([mbrtowc])
+  if test $ac_cv_func_mbrtowc = no; then
+    HAVE_MBRTOWC=0
+  fi
+  if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then
+    gl_MBRTOWC_NULL_ARG
+    gl_MBRTOWC_RETVAL
+    gl_MBRTOWC_NUL_RETVAL
+    case "$gl_cv_func_mbrtowc_null_arg" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
+           [Define if the mbrtowc function has the NULL string argument bug.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+    case "$gl_cv_func_mbrtowc_retval" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
+           [Define if the mbrtowc function returns a wrong return value.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+    case "$gl_cv_func_mbrtowc_nul_retval" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
+           [Define if the mbrtowc function does not return 0 for a NUL character.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+  fi
+  if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbrtowc])
+    gl_PREREQ_MBRTOWC
+  fi
+])
+
+dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
+dnl redefines the semantics of the given mbstate_t type.
+dnl Result is REPLACE_MBSTATE_T.
+dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
+dnl avoid inconsistencies.
+
+AC_DEFUN([gl_MBSTATE_T_BROKEN],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  AC_CHECK_FUNCS_ONCE([mbsinit])
+  AC_CHECK_FUNCS_ONCE([mbrtowc])
+  if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
+    gl_MBRTOWC_INCOMPLETE_STATE
+    gl_MBRTOWC_SANITYCHECK
+    REPLACE_MBSTATE_T=0
+    case "$gl_cv_func_mbrtowc_incomplete_state" in
+      *yes) ;;
+      *) REPLACE_MBSTATE_T=1 ;;
+    esac
+    case "$gl_cv_func_mbrtowc_sanitycheck" in
+      *yes) ;;
+      *) REPLACE_MBSTATE_T=1 ;;
+    esac
+  else
+    REPLACE_MBSTATE_T=1
+  fi
+  if test $REPLACE_MBSTATE_T = 1; then
+    gl_REPLACE_WCHAR_H
+  fi
+])
+
+dnl Test whether mbrtowc puts the state into non-initial state when parsing an
+dnl incomplete multibyte character.
+dnl Result is gl_cv_func_mbrtowc_incomplete_state.
+
+AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
+    [gl_cv_func_mbrtowc_incomplete_state],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+              # Guess no on AIX and OSF/1.
+        osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
+              # Guess yes otherwise.
+        *)    gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        if (mbsinit (&state))
+          return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_incomplete_state=yes],
+          [gl_cv_func_mbrtowc_incomplete_state=no],
+          [:])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc works not worse than mbtowc.
+dnl Result is gl_cv_func_mbrtowc_sanitycheck.
+
+AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
+    [gl_cv_func_mbrtowc_sanitycheck],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                    # Guess no on Solaris 8.
+        solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
+                    # Guess yes otherwise.
+        *)          gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris 8:
+     mbrtowc returns 2, and sets wc to 0x00F0.
+     mbtowc returns 4 (correct) and sets wc to 0x5EDC.  */
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 3, 6, &state) != 4
+          && mbtowc (&wc, input + 3, 6) == 4)
+        return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_sanitycheck=yes],
+          [gl_cv_func_mbrtowc_sanitycheck=no],
+          [:])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc supports a NULL string argument correctly.
+dnl Result is gl_cv_func_mbrtowc_null_arg.
+
+AC_DEFUN([gl_MBRTOWC_NULL_ARG],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
+    [gl_cv_func_mbrtowc_null_arg],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+              # Guess no on OSF/1.
+        osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
+              # Guess yes otherwise.
+        *)    gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      mbstate_t state;
+      wchar_t wc;
+      int ret;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      wc = (wchar_t) 0xBADFACE;
+      mbrtowc (&wc, NULL, 5, &state);
+      /* Check that wc was not modified.  */
+      if (wc != (wchar_t) 0xBADFACE)
+        return 1;
+    }
+  return 0;
+}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [:])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc, when parsing the end of a multibyte character,
+dnl correctly returns the number of bytes that were needed to complete the
+dnl character (not the total number of bytes of the multibyte character).
+dnl Result is gl_cv_func_mbrtowc_retval.
+
+AC_DEFUN([gl_MBRTOWC_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc has a correct return value],
+    [gl_cv_func_mbrtowc_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                          # Guess no on HP-UX and Solaris.
+        hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
+                          # Guess yes otherwise.
+        *)                gl_cv_func_mbrtowc_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris.  */
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      char input[] = "B\303\274\303\237er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrtowc (&wc, input + 2, 5, &state) != 1)
+            return 1;
+        }
+    }
+  /* This fails on HP-UX 11.11.  */
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrtowc (&wc, input + 2, 5, &state) != 2)
+            return 1;
+        }
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_retval=yes],
+          [gl_cv_func_mbrtowc_retval=no],
+          [:])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
+dnl Result is gl_cv_func_mbrtowc_nul_retval.
+
+AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
+    [gl_cv_func_mbrtowc_nul_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                       # Guess no on Solaris 8 and 9.
+        solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
+                       # Guess yes otherwise.
+        *)             gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris 8 and 9.  */
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, "", 1, &state) != 0)
+        return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_nul_retval=yes],
+          [gl_cv_func_mbrtowc_nul_retval=no],
+          [:])
+      fi
+    ])
+])
+
+# Prerequisites of lib/mbrtowc.c.
+AC_DEFUN([gl_PREREQ_MBRTOWC], [
+  :
+])
+
+
+dnl From Paul Eggert
+
+dnl This override of an autoconf macro can be removed when autoconf 2.60 or
+dnl newer can be assumed everywhere.
+
+m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[
+AC_DEFUN([AC_FUNC_MBRTOWC],
+[
+  dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
+  AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
+    gl_cv_func_mbrtowc,
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+            [[#include <wchar.h>]],
+            [[wchar_t wc;
+              char const s[] = "";
+              size_t n = 1;
+              mbstate_t state;
+              return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
+       gl_cv_func_mbrtowc=yes,
+       gl_cv_func_mbrtowc=no)])
+  if test $gl_cv_func_mbrtowc = yes; then
+    AC_DEFINE([HAVE_MBRTOWC], [1],
+      [Define to 1 if mbrtowc and mbstate_t are properly declared.])
+  fi
+])
+])
diff --git a/libmissing/m4/mbsinit.m4 b/libmissing/m4/mbsinit.m4
new file mode 100644
index 0000000..03b055c
--- /dev/null
+++ b/libmissing/m4/mbsinit.m4
@@ -0,0 +1,30 @@
+# mbsinit.m4 serial 3
+dnl Copyright (C) 2008 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_MBSINIT],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  gl_MBSTATE_T_BROKEN
+  if test $REPLACE_MBSTATE_T = 1; then
+    REPLACE_MBSINIT=1
+  fi
+  AC_CHECK_FUNCS_ONCE([mbsinit])
+  if test $ac_cv_func_mbsinit = no; then
+    HAVE_MBSINIT=0
+  fi
+  if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbsinit])
+    gl_PREREQ_MBSINIT
+  fi
+])
+
+# Prerequisites of lib/mbsinit.c.
+AC_DEFUN([gl_PREREQ_MBSINIT], [
+  :
+])
diff --git a/libmissing/m4/mbsrtowcs.m4 b/libmissing/m4/mbsrtowcs.m4
new file mode 100644
index 0000000..55b87c1
--- /dev/null
+++ b/libmissing/m4/mbsrtowcs.m4
@@ -0,0 +1,121 @@
+# mbsrtowcs.m4 serial 5
+dnl Copyright (C) 2008-2009 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_MBSRTOWCS],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  gl_MBSTATE_T_BROKEN
+  if test $REPLACE_MBSTATE_T = 1; then
+    REPLACE_MBSRTOWCS=1
+  fi
+  AC_CHECK_FUNCS_ONCE([mbsrtowcs])
+  if test $ac_cv_func_mbsrtowcs = no; then
+    HAVE_MBSRTOWCS=0
+  fi
+  if test $HAVE_MBSRTOWCS != 0 && test $REPLACE_MBSRTOWCS != 1; then
+    gl_MBSRTOWCS_WORKS
+    case "$gl_cv_func_mbsrtowcs_works" in
+      *yes) ;;
+      *) REPLACE_MBSRTOWCS=1 ;;
+    esac
+  fi
+  if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbsrtowcs])
+    AC_LIBOBJ([mbsrtowcs-state])
+    gl_PREREQ_MBSRTOWCS
+  fi
+])
+
+dnl Test whether mbsrtowcs works.
+dnl Result is gl_cv_func_mbsrtowcs_works.
+
+AC_DEFUN([gl_MBSRTOWCS_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbsrtowcs works],
+    [gl_cv_func_mbsrtowcs_works],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                          # Guess no on HP-UX and Solaris.
+        hpux* | solaris*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
+                          # Guess yes otherwise.
+        *)                gl_cv_func_mbsrtowcs_works="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* Test whether the function works when started with a conversion state
+     in non-initial state.  This fails on HP-UX 11.11 and Solaris 10.  */
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      const char input[] = "B\303\274\303\237er";
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
+        if (!mbsinit (&state))
+          {
+            const char *src = input + 2;
+            if (mbsrtowcs (NULL, &src, 10, &state) != 4)
+              return 1;
+          }
+    }
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      const char input[] = "<\306\374\313\334\270\354>";
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
+        if (!mbsinit (&state))
+          {
+            const char *src = input + 4;
+            if (mbsrtowcs (NULL, &src, 10, &state) != 3)
+              return 1;
+          }
+    }
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      const char input[] = "B\250\271\201\060\211\070er";
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
+        if (!mbsinit (&state))
+          {
+            const char *src = input + 2;
+            if (mbsrtowcs (NULL, &src, 10, &state) != 4)
+              return 1;
+          }
+    }
+  return 0;
+}],
+          [gl_cv_func_mbsrtowcs_works=yes],
+          [gl_cv_func_mbsrtowcs_works=no],
+          [:])
+      fi
+    ])
+])
+
+# Prerequisites of lib/mbsrtowcs.c.
+AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
+  :
+])
diff --git a/libmissing/m4/mbstate_t.m4 b/libmissing/m4/mbstate_t.m4
index 0da32b6..d4ec6f0 100644
--- a/libmissing/m4/mbstate_t.m4
+++ b/libmissing/m4/mbstate_t.m4
@@ -1,5 +1,5 @@
-# mbstate_t.m4 serial 10
-dnl Copyright (C) 2000-2002, 2008 Free Software Foundation, Inc.
+# mbstate_t.m4 serial 12
+dnl Copyright (C) 2000-2002, 2008, 2009 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.
@@ -13,7 +13,10 @@ dnl with or without modifications, as long as this notice is preserved.
 # AC_TYPE_MBSTATE_T
 # -----------------
 AC_DEFUN([AC_TYPE_MBSTATE_T],
-  [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
+[
+   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) dnl for HP-UX 11.11
+
+   AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],
      [AC_COMPILE_IFELSE(
 	[AC_LANG_PROGRAM(
 	   [AC_INCLUDES_DEFAULT[
@@ -22,9 +25,10 @@ AC_DEFUN([AC_TYPE_MBSTATE_T],
 	[ac_cv_type_mbstate_t=yes],
 	[ac_cv_type_mbstate_t=no])])
    if test $ac_cv_type_mbstate_t = yes; then
-     AC_DEFINE([HAVE_MBSTATE_T], 1,
+     AC_DEFINE([HAVE_MBSTATE_T], [1],
 	       [Define to 1 if <wchar.h> declares mbstate_t.])
    else
-     AC_DEFINE([mbstate_t], int,
+     AC_DEFINE([mbstate_t], [int],
 	       [Define to a type if <wchar.h> does not define.])
-   fi])
+   fi
+])
diff --git a/libmissing/m4/memchr.m4 b/libmissing/m4/memchr.m4
new file mode 100644
index 0000000..1194bac
--- /dev/null
+++ b/libmissing/m4/memchr.m4
@@ -0,0 +1,86 @@
+# memchr.m4 serial 7
+dnl Copyright (C) 2002, 2003, 2004, 2009 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_ONCE([gl_FUNC_MEMCHR],
+[
+  dnl Check for prerequisites for memory fence checks.
+  gl_FUNC_MMAP_ANON
+  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_REPLACE_FUNCS([memchr])
+  if test $ac_cv_func_memchr = no; then
+    gl_PREREQ_MEMCHR
+    REPLACE_MEMCHR=1
+  fi
+
+  if test $ac_cv_func_memchr = yes; then
+    # Detect platform-specific bugs in some versions of glibc:
+    # memchr should not dereference anything with length 0
+    #   http://bugzilla.redhat.com/499689
+    # memchr should not dereference overestimated length after a match
+    #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
+    #   http://sourceware.org/bugzilla/show_bug.cgi?id=10162
+    # Assume that memchr works on platforms that lack mprotect.
+    AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
+      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <string.h>
+#if HAVE_SYS_MMAN_H
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/mman.h>
+# ifndef MAP_FILE
+#  define MAP_FILE 0
+# endif
+#endif
+]], [[
+  char *fence = NULL;
+#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
+# if HAVE_MAP_ANONYMOUS
+  const int flags = MAP_ANONYMOUS | MAP_PRIVATE;
+  const int fd = -1;
+# else /* !HAVE_MAP_ANONYMOUS */
+  const int flags = MAP_FILE | MAP_PRIVATE;
+  int fd = open ("/dev/zero", O_RDONLY, 0666);
+  if (fd >= 0)
+# endif
+    {
+      int pagesize = getpagesize ();
+      char *two_pages =
+	(char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
+		       flags, fd, 0);
+      if (two_pages != (char *)(-1)
+	  && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
+	fence = two_pages + pagesize;
+    }
+#endif
+  if (fence)
+    {
+      if (memchr (fence, 0, 0))
+        return 1;
+      strcpy (fence - 9, "12345678");
+      if (memchr (fence - 9, 0, 79) != fence - 1)
+        return 2;
+    }
+  return 0;
+]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no],
+      [dnl Be pessimistic for now.
+       gl_cv_func_memchr_works="guessing no"])])
+    if test "$gl_cv_func_memchr_works" != yes; then
+      gl_PREREQ_MEMCHR
+      REPLACE_MEMCHR=1
+      AC_LIBOBJ([memchr])
+    fi
+  fi
+])
+
+# Prerequisites of lib/memchr.c.
+AC_DEFUN([gl_PREREQ_MEMCHR], [
+  AC_CHECK_HEADERS([bp-sym.h])
+])
diff --git a/libmissing/m4/mempcpy.m4 b/libmissing/m4/mempcpy.m4
index d1a12eb..a3c022f 100644
--- a/libmissing/m4/mempcpy.m4
+++ b/libmissing/m4/mempcpy.m4
@@ -1,5 +1,5 @@
-# mempcpy.m4 serial 9
-dnl Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
+# mempcpy.m4 serial 10
+dnl Copyright (C) 2003-2004, 2006-2007, 2009 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.
@@ -13,7 +13,7 @@ AC_DEFUN([gl_FUNC_MEMPCPY],
   AC_REQUIRE([AC_C_RESTRICT])
 
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REPLACE_FUNCS(mempcpy)
+  AC_REPLACE_FUNCS([mempcpy])
   if test $ac_cv_func_mempcpy = no; then
     HAVE_MEMPCPY=0
     gl_PREREQ_MEMPCPY
diff --git a/libmissing/m4/memset.m4 b/libmissing/m4/memset.m4
deleted file mode 100644
index 14ac267..0000000
--- a/libmissing/m4/memset.m4
+++ /dev/null
@@ -1,18 +0,0 @@
-# memset.m4 serial 2
-dnl Copyright (C) 2002 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_MEMSET],
-[
-  AC_REPLACE_FUNCS(memset)
-  if test $ac_cv_func_memset = no; then
-    gl_PREREQ_MEMSET
-  fi
-])
-
-# Prerequisites of lib/memset.c.
-AC_DEFUN([gl_PREREQ_MEMSET], [
-  :
-])
diff --git a/libmissing/m4/mktime.m4 b/libmissing/m4/mktime.m4
index 5faf393..1e926e8 100644
--- a/libmissing/m4/mktime.m4
+++ b/libmissing/m4/mktime.m4
@@ -1,5 +1,5 @@
-#serial 13
-dnl Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+# serial 15
+dnl Copyright (C) 2002-2003, 2005-2007, 2009 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.
@@ -13,9 +13,16 @@ dnl From Jim Meyering.
 # AC_FUNC_MKTIME
 # --------------
 AC_DEFUN([AC_FUNC_MKTIME],
-[AC_CHECK_HEADERS_ONCE(unistd.h)
-AC_CHECK_FUNCS_ONCE(alarm)
-AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
+[AC_CHECK_HEADERS_ONCE([unistd.h])
+AC_CHECK_FUNCS_ONCE([alarm])
+AC_REQUIRE([gl_MULTIARCH])
+if test $APPLE_UNIVERSAL_BUILD = 1; then
+  # A universal build on Apple MacOS X platforms.
+  # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode.
+  # But we need a configuration result that is valid in both modes.
+  ac_cv_func_working_mktime=no
+fi
+AC_CACHE_CHECK([for working mktime], [ac_cv_func_working_mktime],
 [AC_RUN_IFELSE([AC_LANG_SOURCE(
 [[/* Test program from Paul Eggert and Tony Leneis.  */
 #include <limits.h>
@@ -68,16 +75,14 @@ spring_forward_gap ()
 }
 
 static int
-mktime_test1 (now)
-     time_t now;
+mktime_test1 (time_t now)
 {
   struct tm *lt;
   return ! (lt = localtime (&now)) || mktime (lt) == now;
 }
 
 static int
-mktime_test (now)
-     time_t now;
+mktime_test (time_t now)
 {
   return (mktime_test1 (now)
 	  && mktime_test1 ((time_t) (time_t_max - now))
@@ -101,8 +106,7 @@ irix_6_4_bug ()
 }
 
 static int
-bigtime_test (j)
-     int j;
+bigtime_test (int j)
 {
   struct tm tm;
   time_t now;
@@ -212,9 +216,9 @@ fi
 AC_DEFUN([gl_FUNC_MKTIME],
 [
   AC_FUNC_MKTIME
-  dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ(mktime).
+  dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
   if test $ac_cv_func_working_mktime = no; then
-    AC_DEFINE(mktime, rpl_mktime,
+    AC_DEFINE([mktime], [rpl_mktime],
       [Define to rpl_mktime if the replacement function should be used.])
     gl_PREREQ_MKTIME
   fi
diff --git a/libmissing/m4/mmap-anon.m4 b/libmissing/m4/mmap-anon.m4
new file mode 100644
index 0000000..14b6270
--- /dev/null
+++ b/libmissing/m4/mmap-anon.m4
@@ -0,0 +1,59 @@
+# mmap-anon.m4 serial 8
+dnl Copyright (C) 2005, 2007, 2009 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.
+
+# Detect how mmap can be used to create anonymous (not file-backed) memory
+# mappings.
+# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
+#   and MAP_ANON exist and have the same value.
+# - On HP-UX, only MAP_ANONYMOUS exists.
+# - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
+# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
+#   used.
+
+AC_DEFUN([gl_FUNC_MMAP_ANON],
+[
+  dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
+  AC_REQUIRE([AC_PROG_CPP])
+  AC_REQUIRE([AC_PROG_EGREP])
+
+  dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
+  # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
+  # irrelevant for anonymous mappings.
+  AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
+
+  # Try to allow MAP_ANONYMOUS.
+  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.], [
+#include <sys/mman.h>
+#ifdef MAP_ANONYMOUS
+    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.], [
+#include <sys/mman.h>
+#ifdef MAP_ANON
+    I cant identify this map.
+#endif
+],
+        [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
+          [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
+         gl_have_mmap_anonymous=yes])
+    fi
+    AC_MSG_RESULT([$gl_have_mmap_anonymous])
+    if test $gl_have_mmap_anonymous = yes; then
+      AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
+        [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
+         config.h and <sys/mman.h>.])
+    fi
+  fi
+])
diff --git a/libmissing/m4/multiarch.m4 b/libmissing/m4/multiarch.m4
new file mode 100644
index 0000000..ec377ba
--- /dev/null
+++ b/libmissing/m4/multiarch.m4
@@ -0,0 +1,65 @@
+# multiarch.m4 serial 5
+dnl Copyright (C) 2008, 2009 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.
+
+# Determine whether the compiler is or may be producing universal binaries.
+#
+# On MacOS X 10.5 and later systems, the user can create libraries and
+# executables that work on multiple system types--known as "fat" or
+# "universal" binaries--by specifying multiple '-arch' options to the
+# compiler but only a single '-arch' option to the preprocessor.  Like
+# this:
+#
+#     ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+#                 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+#                 CPP="gcc -E" CXXCPP="g++ -E"
+#
+# Detect this situation and set the macro AA_APPLE_UNIVERSAL_BUILD at the
+# beginning of config.h and set APPLE_UNIVERSAL_BUILD accordingly.
+
+AC_DEFUN_ONCE([gl_MULTIARCH],
+[
+  dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN.
+  gl_cv_c_multiarch=no
+  AC_COMPILE_IFELSE(
+    [AC_LANG_SOURCE(
+      [[#ifndef __APPLE_CC__
+         not a universal capable compiler
+        #endif
+        typedef int dummy;
+      ]])],
+    [
+     dnl Check for potential -arch flags.  It is not universal unless
+     dnl there are at least two -arch flags with different values.
+     arch=
+     prev=
+     for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
+       if test -n "$prev"; then
+         case $word in
+           i?86 | x86_64 | ppc | ppc64)
+             if test -z "$arch" || test "$arch" = "$word"; then
+               arch="$word"
+             else
+               gl_cv_c_multiarch=yes
+             fi
+             ;;
+         esac
+         prev=
+       else
+         if test "x$word" = "x-arch"; then
+           prev=arch
+         fi
+       fi
+     done
+    ])
+  if test $gl_cv_c_multiarch = yes; then
+    AC_DEFINE([AA_APPLE_UNIVERSAL_BUILD], [1],
+      [Define if the compiler is building for multiple architectures of Apple platforms at once.])
+    APPLE_UNIVERSAL_BUILD=1
+  else
+    APPLE_UNIVERSAL_BUILD=0
+  fi
+  AC_SUBST([APPLE_UNIVERSAL_BUILD])
+])
diff --git a/libmissing/m4/netdb_h.m4 b/libmissing/m4/netdb_h.m4
new file mode 100644
index 0000000..5a12251
--- /dev/null
+++ b/libmissing/m4/netdb_h.m4
@@ -0,0 +1,45 @@
+# netdb_h.m4 serial 5
+dnl Copyright (C) 2008 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_HEADER_NETDB],
+[
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  gl_CHECK_NEXT_HEADERS([netdb.h])
+  if test $ac_cv_header_netdb_h = yes; then
+    AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM([[
+         #include <netdb.h>
+         struct addrinfo a;
+         int b = EAI_OVERFLOW;
+         int c = AI_NUMERICSERV;
+       ]])],
+      [NETDB_H=''], [NETDB_H='netdb.h'])
+    HAVE_NETDB_H=1
+  else
+    NETDB_H='netdb.h'
+    HAVE_NETDB_H=0
+  fi
+  AC_SUBST([HAVE_NETDB_H])
+  AC_SUBST([NETDB_H])
+])
+
+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])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_NETDB_H_DEFAULTS],
+[
+  GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_STRUCT_ADDRINFO=1;   AC_SUBST([HAVE_STRUCT_ADDRINFO])
+  HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO])
+  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])
+])
diff --git a/libmissing/m4/pathmax.m4 b/libmissing/m4/pathmax.m4
index 64bf26f..4651801 100644
--- a/libmissing/m4/pathmax.m4
+++ b/libmissing/m4/pathmax.m4
@@ -1,5 +1,5 @@
-# pathmax.m4 serial 6
-dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+# pathmax.m4 serial 8
+dnl Copyright (C) 2002, 2003, 2005, 2006, 2009 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.
@@ -7,5 +7,6 @@ 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)
+  AC_CHECK_FUNCS_ONCE([pathconf])
+  AC_CHECK_HEADERS_ONCE([sys/param.h])
 ])
diff --git a/libmissing/m4/printf.m4 b/libmissing/m4/printf.m4
index d544edd..87aa45c 100644
--- a/libmissing/m4/printf.m4
+++ b/libmissing/m4/printf.m4
@@ -1,5 +1,5 @@
-# printf.m4 serial 23
-dnl Copyright (C) 2003, 2007-2008 Free Software Foundation, Inc.
+# printf.m4 serial 33
+dnl Copyright (C) 2003, 2007-2009 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.
@@ -125,7 +125,8 @@ changequote([,])dnl
 ])
 
 dnl Test whether the *printf family of functions supports infinite and NaN
-dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
+dnl 'double' arguments and negative zero arguments in the %f, %e, %g
+dnl directives. (ISO C99, POSIX:2001)
 dnl Result is gl_cv_func_printf_infinite.
 
 AC_DEFUN([gl_PRINTF_INFINITE],
@@ -156,6 +157,13 @@ strisnan (const char *string, size_t start_index, size_t end_index)
     }
   return 0;
 }
+static int
+have_minus_zero ()
+{
+  static double plus_zero = 0.0;
+  double minus_zero = - plus_zero;
+  return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
+}
 static char buf[10000];
 static double zero = 0.0;
 int main ()
@@ -187,6 +195,11 @@ int main ()
   if (sprintf (buf, "%g", zero / zero) < 0
       || !strisnan (buf, 0, strlen (buf)))
     return 1;
+  /* This test fails on HP-UX 10.20.  */
+  if (have_minus_zero ())
+    if (sprintf (buf, "%g", - zero) < 0
+        || strcmp (buf, "-0") != 0)
+    return 1;
   return 0;
 }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
       [
@@ -225,12 +238,12 @@ AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
 [
   AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([AC_PROG_CC])
-  AC_REQUIRE([AC_C_BIGENDIAN])
+  AC_REQUIRE([gl_BIGENDIAN])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   dnl The user can set or unset the variable gl_printf_safe to indicate
   dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
   if test -n "$gl_printf_safe"; then
-    AC_DEFINE([CHECK_PRINTF_SAFE], 1,
+    AC_DEFINE([CHECK_PRINTF_SAFE], [1],
       [Define if you wish *printf() functions that have a safe handling of
        non-IEEE-754 'long double' values.])
   fi
@@ -545,7 +558,7 @@ int main ()
   if (sprintf (buf, "%F", 1.0 / 0.0) < 0
       || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
     return 1;
-  /* This catches a Cygwin 2007 bug.  */
+  /* This catches a Cygwin 1.5.x bug.  */
   if (sprintf (buf, "%.F", 1234.0) < 0
       || strcmp (buf, "1234") != 0)
     return 1;
@@ -612,6 +625,84 @@ changequote([,])dnl
     ])
 ])
 
+dnl Test whether the *printf family of functions supports the %ls format
+dnl directive and in particular, when a precision is specified, whether
+dnl the functions stop converting the wide string argument when the number
+dnl of bytes that have been produced by this conversion equals or exceeds
+dnl the precision.
+dnl Result is gl_cv_func_printf_directive_ls.
+
+AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether printf supports the 'ls' directive],
+    [gl_cv_func_printf_directive_ls],
+    [
+      AC_TRY_RUN([
+/* 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>.  */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+#include <string.h>
+int main ()
+{
+  char buf[100];
+  /* Test whether %ls works at all.
+     This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
+     Cygwin 1.5.  */
+  {
+    static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
+    buf[0] = '\0';
+    if (sprintf (buf, "%ls", wstring) < 0
+        || strcmp (buf, "abc") != 0)
+      return 1;
+  }
+  /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
+     assertion failure inside libc), but not on OpenBSD 4.0.  */
+  {
+    static const wchar_t wstring[] = { 'a', 0 };
+    buf[0] = '\0';
+    if (sprintf (buf, "%ls", wstring) < 0
+        || strcmp (buf, "a") != 0)
+      return 1;
+  }
+  /* Test whether precisions in %ls are supported as specified in ISO C 99
+     section 7.19.6.1:
+       "If a precision is specified, no more than that many bytes are written
+        (including shift sequences, if any), and the array shall contain a
+        null wide character if, to equal the multibyte character sequence
+        length given by the precision, the function would need to access a
+        wide character one past the end of the array."
+     This test fails on Solaris 10.  */
+  {
+    static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
+    buf[0] = '\0';
+    if (sprintf (buf, "%.2ls", wstring) < 0
+        || strcmp (buf, "ab") != 0)
+      return 1;
+  }
+  return 0;
+}], [gl_cv_func_printf_directive_ls=yes], [gl_cv_func_printf_directive_ls=no],
+      [
+changequote(,)dnl
+       case "$host_os" in
+         openbsd*)        gl_cv_func_printf_directive_ls="guessing no";;
+         irix*)           gl_cv_func_printf_directive_ls="guessing no";;
+         solaris*)        gl_cv_func_printf_directive_ls="guessing no";;
+         cygwin*)         gl_cv_func_printf_directive_ls="guessing no";;
+         beos* | haiku*)  gl_cv_func_printf_directive_ls="guessing no";;
+         *)               gl_cv_func_printf_directive_ls="guessing yes";;
+       esac
+changequote([,])dnl
+      ])
+    ])
+])
+
 dnl Test whether the *printf family of functions supports POSIX/XSI format
 dnl strings with positions. (POSIX:2001)
 dnl Result is gl_cv_func_printf_positions.
@@ -811,12 +902,15 @@ dnl Result is gl_cv_func_printf_enomem.
 AC_DEFUN([gl_PRINTF_ENOMEM],
 [
   AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gl_MULTIARCH])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
     [gl_cv_func_printf_enomem],
     [
+      gl_cv_func_printf_enomem="guessing no"
       if test "$cross_compiling" = no; then
-        AC_LANG_CONFTEST([AC_LANG_SOURCE([
+        if test $APPLE_UNIVERSAL_BUILD = 0; then
+          AC_LANG_CONFTEST([AC_LANG_SOURCE([
 ]GL_NOCRASH[
 changequote(,)dnl
 #include <stdio.h>
@@ -865,22 +959,29 @@ int main()
 }
 changequote([,])dnl
           ])])
-        if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
-          (./conftest
-           result=$?
-           if test $result != 0 && test $result != 77; then result=1; fi
-           exit $result
-          ) >/dev/null 2>/dev/null
-          case $? in
-            0) gl_cv_func_printf_enomem="yes" ;;
-            77) gl_cv_func_printf_enomem="guessing no" ;;
-            *) gl_cv_func_printf_enomem="no" ;;
-          esac
+          if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+            (./conftest
+             result=$?
+             if test $result != 0 && test $result != 77; then result=1; fi
+             exit $result
+            ) >/dev/null 2>/dev/null
+            case $? in
+              0) gl_cv_func_printf_enomem="yes" ;;
+              77) gl_cv_func_printf_enomem="guessing no" ;;
+              *) gl_cv_func_printf_enomem="no" ;;
+            esac
+          else
+            gl_cv_func_printf_enomem="guessing no"
+          fi
+          rm -fr conftest*
         else
+          dnl A universal build on Apple MacOS X platforms.
+          dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
+          dnl But we need a configuration result that is valid in both modes.
           gl_cv_func_printf_enomem="guessing no"
         fi
-        rm -fr conftest*
-      else
+      fi
+      if test "$gl_cv_func_printf_enomem" = "guessing no"; then
 changequote(,)dnl
         case "$host_os" in
                     # Guess yes on glibc systems.
@@ -901,6 +1002,8 @@ changequote(,)dnl
           osf*)     gl_cv_func_printf_enomem="guessing yes";;
                     # Guess yes on BeOS.
           beos*)    gl_cv_func_printf_enomem="guessing yes";;
+                    # Guess yes on Haiku.
+          haiku*)   gl_cv_func_printf_enomem="guessing yes";;
                     # If we don't know, assume the worst.
           *)        gl_cv_func_printf_enomem="guessing no";;
         esac
@@ -1130,7 +1233,7 @@ AC_DEFUN([gl_SNPRINTF_SIZE1],
 #include <stdio.h>
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
   snprintf (buf, 1, "%d", 12345);
   return buf[1] != 'E';
 }],
@@ -1148,7 +1251,7 @@ dnl     ---------------------------------------------------------------------
 dnl     #include <stdio.h>
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
 dnl       snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1169,7 +1272,7 @@ dnl       return ret;
 dnl     }
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
 dnl       my_snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1197,7 +1300,7 @@ static int my_snprintf (char *buf, int size, const char *format, ...)
 }
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
   my_snprintf (buf, 0, "%d", 12345);
   return buf[0] != 'D';
 }],
@@ -1249,18 +1352,19 @@ dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
 dnl 5 = gl_PRINTF_DIRECTIVE_A
 dnl 6 = gl_PRINTF_DIRECTIVE_F
 dnl 7 = gl_PRINTF_DIRECTIVE_N
-dnl 8 = gl_PRINTF_POSITIONS
-dnl 9 = gl_PRINTF_FLAG_GROUPING
-dnl 10 = gl_PRINTF_FLAG_LEFTADJUST
-dnl 11 = gl_PRINTF_FLAG_ZERO
-dnl 12 = gl_PRINTF_PRECISION
-dnl 13 = gl_PRINTF_ENOMEM
-dnl 14 = gl_SNPRINTF_PRESENCE
-dnl 15 = gl_SNPRINTF_TRUNCATION_C99
-dnl 16 = gl_SNPRINTF_RETVAL_C99
-dnl 17 = gl_SNPRINTF_DIRECTIVE_N
-dnl 18 = gl_SNPRINTF_SIZE1
-dnl 19 = gl_VSNPRINTF_ZEROSIZE_C99
+dnl 8 = gl_PRINTF_DIRECTIVE_LS
+dnl 9 = gl_PRINTF_POSITIONS
+dnl 10 = gl_PRINTF_FLAG_GROUPING
+dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
+dnl 12 = gl_PRINTF_FLAG_ZERO
+dnl 13 = gl_PRINTF_PRECISION
+dnl 14 = gl_PRINTF_ENOMEM
+dnl 15 = gl_SNPRINTF_PRESENCE
+dnl 16 = gl_SNPRINTF_TRUNCATION_C99
+dnl 17 = gl_SNPRINTF_RETVAL_C99
+dnl 18 = gl_SNPRINTF_DIRECTIVE_N
+dnl 19 = gl_SNPRINTF_SIZE1
+dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
 dnl
 dnl 1 = checking whether printf supports size specifiers as in C99...
 dnl 2 = checking whether printf supports 'long double' arguments...
@@ -1269,41 +1373,44 @@ dnl 4 = checking whether printf supports infinite 'long double' arguments...
 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
 dnl 6 = checking whether printf supports the 'F' directive...
 dnl 7 = checking whether printf supports the 'n' directive...
-dnl 8 = checking whether printf supports POSIX/XSI format strings with positions...
-dnl 9 = checking whether printf supports the grouping flag...
-dnl 10 = checking whether printf supports the left-adjust flag correctly...
-dnl 11 = checking whether printf supports the zero flag correctly...
-dnl 12 = checking whether printf supports large precisions...
-dnl 13 = checking whether printf survives out-of-memory conditions...
-dnl 14 = checking for snprintf...
-dnl 15 = checking whether snprintf truncates the result as in C99...
-dnl 16 = checking whether snprintf returns a byte count as in C99...
-dnl 17 = checking whether snprintf fully supports the 'n' directive...
-dnl 18 = checking whether snprintf respects a size of 1...
-dnl 19 = checking whether vsnprintf respects a zero size as in C99...
+dnl 8 = checking whether printf supports the 'ls' directive...
+dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
+dnl 10 = checking whether printf supports the grouping flag...
+dnl 11 = checking whether printf supports the left-adjust flag correctly...
+dnl 12 = checking whether printf supports the zero flag correctly...
+dnl 13 = checking whether printf supports large precisions...
+dnl 14 = checking whether printf survives out-of-memory conditions...
+dnl 15 = checking for snprintf...
+dnl 16 = checking whether snprintf truncates the result as in C99...
+dnl 17 = checking whether snprintf returns a byte count as in C99...
+dnl 18 = checking whether snprintf fully supports the 'n' directive...
+dnl 19 = checking whether snprintf respects a size of 1...
+dnl 20 = checking whether vsnprintf respects a zero size as in C99...
 dnl
 dnl . = yes, # = no.
 dnl
-dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
-dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
-dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .
-dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  #  .  #  .  .  .  .  .  .
-dnl   MacOS X 10.3.9                 .  .  .  .  #  .  .  .  .  .  #  .  #  .  .  .  .  .  .
-dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  .  #  .  #  .  #  .  .  .  .  .  .
-dnl   Cygwin 2007 (= Cygwin 1.5.24)  .  .  .  .  #  #  .  .  .  ?  #  ?  ?  .  .  .  .  .  .
-dnl   Cygwin 2006 (= Cygwin 1.5.19)  #  .  .  .  #  #  .  .  #  ?  #  ?  ?  .  .  .  .  .  .
-dnl   Solaris 10                     .  .  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  .  .  .  #  .  .  #  #  #  #  #  #
-dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  #  .  .  .  .  #  #  .  .
-dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  #  .  .  .  .  #  #  .  #
-dnl   HP-UX 10.20                    #  .  .  .  #  #  .  .  .  #  #  .  .  .  .  #  #  ?  #
-dnl   IRIX 6.5                       #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  #  .  .  .
-dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  #  .  .  #
-dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  #  .  .  #  #  #  #  #  #
-dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
-dnl   NetBSD 3.0                     .  .  .  .  #  #  .  #  #  ?  #  .  #  .  .  .  .  .  .
-dnl   BeOS                           #  #  .  #  #  #  .  #  .  ?  .  #  ?  .  .  .  .  .  .
-dnl   mingw                          #  #  #  #  #  #  .  #  #  .  #  #  ?  .  #  #  #  .  .
+dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
+dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
+dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
+dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
+dnl   MacOS X 10.3.9                 .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
+dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  #  .  #  .  #  .  #  .  .  .  .  .  .
+dnl   Cygwin 1.7.0 (2009)            .  .  .  #  .  .  .  ?  .  .  .  .  .  ?  .  .  .  .  .  .
+dnl   Cygwin 1.5.25 (2008)           .  .  .  #  #  .  .  #  .  .  .  .  .  #  .  .  .  .  .  .
+dnl   Cygwin 1.5.19 (2006)           #  .  .  #  #  #  .  #  .  #  .  #  #  #  .  .  .  .  .  .
+dnl   Solaris 10                     .  .  #  #  #  .  .  #  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  #  #  #  #  #  #
+dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  .  .  #  #  .  .
+dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  .  .  #  #  .  #
+dnl   HP-UX 10.20                    #  .  #  .  #  #  .  ?  .  .  #  #  .  .  .  .  #  #  ?  #
+dnl   IRIX 6.5                       #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  #  .  .  .
+dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  #
+dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  .  #  .  .  #  #  #  #  #  #
+dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  ?  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
+dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  .  .  .  .  .  .
+dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  .  .  .  .
+dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  .  .  .  .
+dnl   mingw                          #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .
diff --git a/libmissing/m4/servent.m4 b/libmissing/m4/servent.m4
new file mode 100644
index 0000000..242f9e3
--- /dev/null
+++ b/libmissing/m4/servent.m4
@@ -0,0 +1,47 @@
+# servent.m4 serial 1
+dnl Copyright (C) 2008 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_SERVENT],
+[
+  dnl Where are getservent(), setservent(), endservent(), getservbyname(),
+  dnl getservbyport() defined?
+  dnl Where are getprotoent(), setprotoent(), endprotoent(), getprotobyname(),
+  dnl getprotobynumber() defined?
+  dnl - On Solaris, they are in libsocket. Ignore libxnet.
+  dnl - On Haiku, they are in libnetwork.
+  dnl - On BeOS, they are in libnet.
+  dnl - On native Windows, they are in ws2_32.dll.
+  dnl - Otherwise they are in libc.
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+  SERVENT_LIB=
+  gl_saved_libs="$LIBS"
+  AC_SEARCH_LIBS([getservbyname], [socket network net],
+    [if test "$ac_cv_search_getservbyname" != "none required"; then
+       SERVENT_LIB="$ac_cv_search_getservbyname"
+     fi])
+  LIBS="$gl_saved_libs"
+  if test -z "$SERVENT_LIB"; then
+    AC_CHECK_FUNCS([getservbyname], , [
+      AC_CACHE_CHECK([for getservbyname in winsock2.h and -lws2_32],
+        [gl_cv_w32_getservbyname],
+        [gl_cv_w32_getservbyname=no
+         gl_save_LIBS="$LIBS"
+         LIBS="$LIBS -lws2_32"
+         AC_TRY_LINK([
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#include <stddef.h>
+], [getservbyname(NULL,NULL);], [gl_cv_w32_getservbyname=yes])
+         LIBS="$gl_save_LIBS"
+        ])
+      if test "$gl_cv_w32_getservbyname" = "yes"; then
+        SERVENT_LIB="-lws2_32"
+      fi
+    ])
+  fi
+  AC_SUBST([SERVENT_LIB])
+])
diff --git a/libmissing/m4/signal_h.m4 b/libmissing/m4/signal_h.m4
index 4ac2e04..e69befd 100644
--- a/libmissing/m4/signal_h.m4
+++ b/libmissing/m4/signal_h.m4
@@ -1,5 +1,5 @@
-# signal_h.m4 serial 6
-dnl Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+# signal_h.m4 serial 7
+dnl Copyright (C) 2007, 2008, 2009 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.
@@ -8,6 +8,12 @@ AC_DEFUN([gl_SIGNAL_H],
 [
   AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
   gl_CHECK_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>
+    ]])
 ])
 
 AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR],
@@ -29,4 +35,6 @@ AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
   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])
 ])
diff --git a/libmissing/m4/signalblocking.m4 b/libmissing/m4/signalblocking.m4
index 300f353..82b0404 100644
--- a/libmissing/m4/signalblocking.m4
+++ b/libmissing/m4/signalblocking.m4
@@ -1,5 +1,5 @@
-# signalblocking.m4 serial 9
-dnl Copyright (C) 2001-2002, 2006-2008 Free Software Foundation, Inc.
+# signalblocking.m4 serial 10
+dnl Copyright (C) 2001-2002, 2006-2009 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.
@@ -13,9 +13,9 @@ AC_DEFUN([gl_SIGNALBLOCKING],
 [
   AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
   signals_not_posix=
-  AC_EGREP_HEADER(sigset_t, signal.h, , signals_not_posix=1)
+  AC_EGREP_HEADER([sigset_t], [signal.h], , [signals_not_posix=1])
   if test -z "$signals_not_posix"; then
-    AC_CHECK_FUNC(sigprocmask, [gl_cv_func_sigprocmask=1])
+    AC_CHECK_FUNC([sigprocmask], [gl_cv_func_sigprocmask=1])
   fi
   if test -z "$gl_cv_func_sigprocmask"; then
     HAVE_POSIX_SIGNALBLOCKING=0
diff --git a/libmissing/m4/size_max.m4 b/libmissing/m4/size_max.m4
index 6cb4868..35bd3d6 100644
--- a/libmissing/m4/size_max.m4
+++ b/libmissing/m4/size_max.m4
@@ -1,5 +1,5 @@
-# size_max.m4 serial 6
-dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
+# size_max.m4 serial 9
+dnl Copyright (C) 2003, 2005-2006, 2008-2009 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.
@@ -8,10 +8,9 @@ dnl From Bruno Haible.
 
 AC_DEFUN([gl_SIZE_MAX],
 [
-  AC_CHECK_HEADERS(stdint.h)
+  AC_CHECK_HEADERS([stdint.h])
   dnl First test whether the system already has SIZE_MAX.
-  AC_MSG_CHECKING([for SIZE_MAX])
-  AC_CACHE_VAL([gl_cv_size_max], [
+  AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
     gl_cv_size_max=
     AC_EGREP_CPP([Found it], [
 #include <limits.h>
@@ -21,16 +20,16 @@ AC_DEFUN([gl_SIZE_MAX],
 #ifdef SIZE_MAX
 Found it
 #endif
-], gl_cv_size_max=yes)
+], [gl_cv_size_max=yes])
     if test -z "$gl_cv_size_max"; then
       dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
       dnl than the type 'unsigned long'. Try hard to find a definition that can
       dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
       AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1],
         [#include <stddef.h>
-#include <limits.h>], size_t_bits_minus_1=)
+#include <limits.h>], [size_t_bits_minus_1=])
       AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)],
-        [#include <stddef.h>], fits_in_uint=)
+        [#include <stddef.h>], [fits_in_uint=])
       if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
         if test $fits_in_uint = 1; then
           dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
@@ -38,7 +37,7 @@ Found it
           AC_TRY_COMPILE([#include <stddef.h>
             extern size_t foo;
             extern unsigned long foo;
-            ], [], fits_in_uint=0)
+            ], [], [fits_in_uint=0])
         fi
         dnl We cannot use 'expr' to simplify this expression, because 'expr'
         dnl works only with 'long' integers in the host environment, while we
@@ -54,11 +53,19 @@ Found it
       fi
     fi
   ])
-  AC_MSG_RESULT([$gl_cv_size_max])
   if test "$gl_cv_size_max" != yes; then
     AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
       [Define as the maximum value of type 'size_t', if the system doesn't define it.])
   fi
+  dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after
+  dnl <stdint.h>. Remember that the #undef in AH_VERBATIM gets replaced with
+  dnl #define by AC_DEFINE_UNQUOTED.
+  AH_VERBATIM([SIZE_MAX],
+[/* Define as the maximum value of type 'size_t', if the system doesn't define
+   it. */
+#ifndef SIZE_MAX
+# undef SIZE_MAX
+#endif])
 ])
 
 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
diff --git a/libmissing/m4/sockpfaf.m4 b/libmissing/m4/sockpfaf.m4
index 25d9755..99ea06f 100644
--- a/libmissing/m4/sockpfaf.m4
+++ b/libmissing/m4/sockpfaf.m4
@@ -1,5 +1,5 @@
-# sockpfaf.m4 serial 5
-dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+# sockpfaf.m4 serial 6
+dnl Copyright (C) 2004, 2006, 2009 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.
@@ -16,8 +16,8 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   AC_CHECK_HEADERS_ONCE([netinet/in.h])
 
-  AC_MSG_CHECKING(for IPv4 sockets)
-  AC_CACHE_VAL(gl_cv_socket_ipv4,
+  AC_MSG_CHECKING([for IPv4 sockets])
+  AC_CACHE_VAL([gl_cv_socket_ipv4],
     [AC_TRY_COMPILE([#include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -31,13 +31,13 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
 [int x = AF_INET; struct in_addr y; struct sockaddr_in z;
  if (&x && &y && &z) return 0;],
        gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
-  AC_MSG_RESULT($gl_cv_socket_ipv4)
+  AC_MSG_RESULT([$gl_cv_socket_ipv4])
   if test $gl_cv_socket_ipv4 = yes; then
-    AC_DEFINE(HAVE_IPV4, 1, [Define to 1 if <sys/socket.h> defines AF_INET.])
+    AC_DEFINE([HAVE_IPV4], [1], [Define to 1 if <sys/socket.h> defines AF_INET.])
   fi
 
-  AC_MSG_CHECKING(for IPv6 sockets)
-  AC_CACHE_VAL(gl_cv_socket_ipv6,
+  AC_MSG_CHECKING([for IPv6 sockets])
+  AC_CACHE_VAL([gl_cv_socket_ipv6],
     [AC_TRY_COMPILE([#include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -51,8 +51,8 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
 [int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;
  if (&x && &y && &z) return 0;],
        gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
-  AC_MSG_RESULT($gl_cv_socket_ipv6)
+  AC_MSG_RESULT([$gl_cv_socket_ipv6])
   if test $gl_cv_socket_ipv6 = yes; then
-    AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if <sys/socket.h> defines AF_INET6.])
+    AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines AF_INET6.])
   fi
 ])
diff --git a/libmissing/m4/stdbool.m4 b/libmissing/m4/stdbool.m4
index 2204ecd..57c804a 100644
--- a/libmissing/m4/stdbool.m4
+++ b/libmissing/m4/stdbool.m4
@@ -1,6 +1,6 @@
 # Check for stdbool.h that conforms to C99.
 
-dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
+dnl Copyright (C) 2002-2006, 2009 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.
@@ -111,5 +111,5 @@ AC_DEFUN([AC_HEADER_STDBOOL],
 	[ac_cv_header_stdbool_h=no])])
    AC_CHECK_TYPES([_Bool])
    if test $ac_cv_header_stdbool_h = yes; then
-     AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
+     AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.])
    fi])
diff --git a/libmissing/m4/stdint.m4 b/libmissing/m4/stdint.m4
index b255692..a2e8bdd 100644
--- a/libmissing/m4/stdint.m4
+++ b/libmissing/m4/stdint.m4
@@ -1,5 +1,5 @@
-# stdint.m4 serial 31
-dnl Copyright (C) 2001-2008 Free Software Foundation, Inc.
+# stdint.m4 serial 34
+dnl Copyright (C) 2001-2009 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.
@@ -9,7 +9,7 @@ dnl Test whether <stdint.h> is supported or must be substituted.
 
 AC_DEFUN([gl_STDINT_H],
 [
-  AC_PREREQ(2.59)dnl
+  AC_PREREQ([2.59])dnl
 
   dnl Check for long long int and unsigned long long int.
   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
@@ -201,7 +201,75 @@ struct s {
   int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1;
 };
          ]])],
-         [gl_cv_header_working_stdint_h=yes])])
+         [dnl Determine whether the various *_MIN, *_MAX macros are usable
+          dnl in preprocessor expression. We could do it by compiling a test
+          dnl program for each of these macros. It is faster to run a program
+          dnl that inspects the macro expansion.
+          dnl This detects a bug on HP-UX 11.23/ia64.
+          AC_RUN_IFELSE([
+            AC_LANG_PROGRAM([[
+#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
+#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
+#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#include <stdint.h>
+]
+gl_STDINT_INCLUDES
+[
+#include <stdio.h>
+#include <string.h>
+#define MVAL(macro) MVAL1(macro)
+#define MVAL1(expression) #expression
+static const char *macro_values[] =
+  {
+#ifdef INT8_MAX
+    MVAL (INT8_MAX),
+#endif
+#ifdef INT16_MAX
+    MVAL (INT16_MAX),
+#endif
+#ifdef INT32_MAX
+    MVAL (INT32_MAX),
+#endif
+#ifdef INT64_MAX
+    MVAL (INT64_MAX),
+#endif
+#ifdef UINT8_MAX
+    MVAL (UINT8_MAX),
+#endif
+#ifdef UINT16_MAX
+    MVAL (UINT16_MAX),
+#endif
+#ifdef UINT32_MAX
+    MVAL (UINT32_MAX),
+#endif
+#ifdef UINT64_MAX
+    MVAL (UINT64_MAX),
+#endif
+    NULL
+  };
+]], [[
+  const char **mv;
+  for (mv = macro_values; *mv != NULL; mv++)
+    {
+      const char *value = *mv;
+      /* Test whether it looks like a cast expression.  */
+      if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0
+          || strncmp (value, "((unsigned short)"/*)*/, 17) == 0
+          || strncmp (value, "((unsigned char)"/*)*/, 16) == 0
+          || strncmp (value, "((int)"/*)*/, 6) == 0
+          || strncmp (value, "((signed short)"/*)*/, 15) == 0
+          || strncmp (value, "((signed char)"/*)*/, 14) == 0)
+        return 1;
+    }
+  return 0;
+]])],
+              [gl_cv_header_working_stdint_h=yes],
+              [],
+              [dnl When cross-compiling, assume it works.
+               gl_cv_header_working_stdint_h=yes
+              ])
+         ])
+      ])
   fi
   if test "$gl_cv_header_working_stdint_h" = yes; then
     STDINT_H=
@@ -229,7 +297,7 @@ struct s {
     gl_STDINT_TYPE_PROPERTIES
     STDINT_H=stdint.h
   fi
-  AC_SUBST(STDINT_H)
+  AC_SUBST([STDINT_H])
 ])
 
 dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
@@ -292,7 +360,7 @@ AC_DEFUN([gl_CHECK_TYPES_SIGNED],
     eval result=\$gl_cv_type_${gltype}_signed
     GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
     if test "$result" = yes; then
-      AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1)
+      AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1])
       eval HAVE_SIGNED_${GLTYPE}=1
     else
       eval HAVE_SIGNED_${GLTYPE}=0
@@ -348,7 +416,7 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
     eval result=\$gl_cv_type_${gltype}_suffix
     test "$result" = no && result=
     eval ${GLTYPE}_SUFFIX=\$result
-    AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], $result)
+    AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result])
   done
   m4_foreach_w([gltype], [$1],
     [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])])
@@ -373,13 +441,22 @@ dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t
 dnl of interest to stdint.in.h.
 AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
 [
-  gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t],
+  AC_REQUIRE([gl_MULTIARCH])
+  if test $APPLE_UNIVERSAL_BUILD = 0; then
+    gl_STDINT_BITSIZEOF([ptrdiff_t size_t],
+      [gl_STDINT_INCLUDES])
+  fi
+  gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t],
     [gl_STDINT_INCLUDES])
   gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t],
     [gl_STDINT_INCLUDES])
   gl_cv_type_ptrdiff_t_signed=yes
   gl_cv_type_size_t_signed=no
-  gl_INTEGER_TYPE_SUFFIX([ptrdiff_t sig_atomic_t size_t wchar_t wint_t],
+  if test $APPLE_UNIVERSAL_BUILD = 0; then
+    gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t],
+      [gl_STDINT_INCLUDES])
+  fi
+  gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t],
     [gl_STDINT_INCLUDES])
 ])
 
diff --git a/libmissing/m4/stdint_h.m4 b/libmissing/m4/stdint_h.m4
index db9a8ac..82f0c24 100644
--- a/libmissing/m4/stdint_h.m4
+++ b/libmissing/m4/stdint_h.m4
@@ -1,5 +1,5 @@
-# stdint_h.m4 serial 6
-dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc.
+# stdint_h.m4 serial 8
+dnl Copyright (C) 1997-2004, 2006, 2008, 2009 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.
@@ -11,15 +11,15 @@ dnl From Paul Eggert.
 
 AC_DEFUN([gl_AC_HEADER_STDINT_H],
 [
-  AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h,
+  AC_CACHE_CHECK([for stdint.h], [gl_cv_header_stdint_h],
   [AC_TRY_COMPILE(
     [#include <sys/types.h>
 #include <stdint.h>],
     [uintmax_t i = (uintmax_t) -1; return !i;],
-    gl_cv_header_stdint_h=yes,
-    gl_cv_header_stdint_h=no)])
+    [gl_cv_header_stdint_h=yes],
+    [gl_cv_header_stdint_h=no])])
   if test $gl_cv_header_stdint_h = yes; then
-    AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1,
+    AC_DEFINE_UNQUOTED([HAVE_STDINT_H_WITH_UINTMAX], [1],
       [Define if <stdint.h> exists, doesn't clash with <sys/types.h>,
        and declares uintmax_t. ])
   fi
diff --git a/libmissing/m4/stdio_h.m4 b/libmissing/m4/stdio_h.m4
index 60b4bd7..fcbe68f 100644
--- a/libmissing/m4/stdio_h.m4
+++ b/libmissing/m4/stdio_h.m4
@@ -1,5 +1,5 @@
-# stdio_h.m4 serial 14
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# stdio_h.m4 serial 16
+dnl Copyright (C) 2007-2009 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.
@@ -53,6 +53,8 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_VPRINTF_POSIX=0;        AC_SUBST([GNULIB_VPRINTF_POSIX])
   GNULIB_VSNPRINTF=0;            AC_SUBST([GNULIB_VSNPRINTF])
   GNULIB_VSPRINTF_POSIX=0;       AC_SUBST([GNULIB_VSPRINTF_POSIX])
+  GNULIB_DPRINTF=0;              AC_SUBST([GNULIB_DPRINTF])
+  GNULIB_VDPRINTF=0;             AC_SUBST([GNULIB_VDPRINTF])
   GNULIB_VASPRINTF=0;            AC_SUBST([GNULIB_VASPRINTF])
   GNULIB_OBSTACK_PRINTF=0;       AC_SUBST([GNULIB_OBSTACK_PRINTF])
   GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
@@ -63,6 +65,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
+  GNULIB_FPURGE=0;               AC_SUBST([GNULIB_FPURGE])
   GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
   GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
   GNULIB_PUTC=0;                 AC_SUBST([GNULIB_PUTC])
@@ -86,6 +89,10 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DECL_VSNPRINTF=1;         AC_SUBST([HAVE_DECL_VSNPRINTF])
   REPLACE_SPRINTF=0;             AC_SUBST([REPLACE_SPRINTF])
   REPLACE_VSPRINTF=0;            AC_SUBST([REPLACE_VSPRINTF])
+  HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
+  REPLACE_DPRINTF=0;             AC_SUBST([REPLACE_DPRINTF])
+  HAVE_VDPRINTF=1;               AC_SUBST([HAVE_VDPRINTF])
+  REPLACE_VDPRINTF=0;            AC_SUBST([REPLACE_VDPRINTF])
   HAVE_VASPRINTF=1;              AC_SUBST([HAVE_VASPRINTF])
   REPLACE_VASPRINTF=0;           AC_SUBST([REPLACE_VASPRINTF])
   HAVE_DECL_OBSTACK_PRINTF=1;    AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
@@ -99,6 +106,8 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   REPLACE_FTELLO=0;              AC_SUBST([REPLACE_FTELLO])
   REPLACE_FTELL=0;               AC_SUBST([REPLACE_FTELL])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
+  REPLACE_FPURGE=0;              AC_SUBST([REPLACE_FPURGE])
+  HAVE_DECL_FPURGE=1;            AC_SUBST([HAVE_DECL_FPURGE])
   REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
   HAVE_DECL_GETDELIM=1;          AC_SUBST([HAVE_DECL_GETDELIM])
   HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
diff --git a/libmissing/m4/stdlib_h.m4 b/libmissing/m4/stdlib_h.m4
index 95e679f..b295f16 100644
--- a/libmissing/m4/stdlib_h.m4
+++ b/libmissing/m4/stdlib_h.m4
@@ -1,5 +1,5 @@
-# stdlib_h.m4 serial 7
-dnl Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+# stdlib_h.m4 serial 15
+dnl Copyright (C) 2007-2009 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.
@@ -8,6 +8,20 @@ AC_DEFUN([gl_STDLIB_H],
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   gl_CHECK_NEXT_HEADERS([stdlib.h])
+  AC_CHECK_HEADERS([random.h], [], [], [AC_INCLUDES_DEFAULT])
+  if test $ac_cv_header_random_h = yes; then
+    HAVE_RANDOM_H=1
+  else
+    HAVE_RANDOM_H=0
+  fi
+  AC_SUBST([HAVE_RANDOM_H])
+  AC_CHECK_TYPES([struct random_data],
+    [], [HAVE_STRUCT_RANDOM_DATA=0],
+    [[#include <stdlib.h>
+      #if HAVE_RANDOM_H
+      # include <random.h>
+      #endif
+    ]])
 ])
 
 AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
@@ -22,26 +36,38 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_MALLOC_POSIX=0;  AC_SUBST([GNULIB_MALLOC_POSIX])
   GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
   GNULIB_CALLOC_POSIX=0;  AC_SUBST([GNULIB_CALLOC_POSIX])
+  GNULIB_ATOLL=0;         AC_SUBST([GNULIB_ATOLL])
+  GNULIB_GETLOADAVG=0;    AC_SUBST([GNULIB_GETLOADAVG])
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
   GNULIB_PUTENV=0;        AC_SUBST([GNULIB_PUTENV])
+  GNULIB_RANDOM_R=0;      AC_SUBST([GNULIB_RANDOM_R])
   GNULIB_RPMATCH=0;       AC_SUBST([GNULIB_RPMATCH])
   GNULIB_SETENV=0;        AC_SUBST([GNULIB_SETENV])
   GNULIB_STRTOD=0;        AC_SUBST([GNULIB_STRTOD])
+  GNULIB_STRTOLL=0;       AC_SUBST([GNULIB_STRTOLL])
+  GNULIB_STRTOULL=0;      AC_SUBST([GNULIB_STRTOULL])
   GNULIB_UNSETENV=0;      AC_SUBST([GNULIB_UNSETENV])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_CALLOC_POSIX=1;    AC_SUBST([HAVE_CALLOC_POSIX])
-  HAVE_GETSUBOPT=1;       AC_SUBST([HAVE_GETSUBOPT])
-  HAVE_MALLOC_POSIX=1;    AC_SUBST([HAVE_MALLOC_POSIX])
-  HAVE_MKDTEMP=1;         AC_SUBST([HAVE_MKDTEMP])
-  HAVE_REALLOC_POSIX=1;   AC_SUBST([HAVE_REALLOC_POSIX])
-  HAVE_RPMATCH=1;         AC_SUBST([HAVE_RPMATCH])
-  HAVE_SETENV=1;          AC_SUBST([HAVE_SETENV])
-  HAVE_STRTOD=1;          AC_SUBST([HAVE_STRTOD])
-  HAVE_UNSETENV=1;        AC_SUBST([HAVE_UNSETENV])
-  REPLACE_MKSTEMP=0;      AC_SUBST([REPLACE_MKSTEMP])
-  REPLACE_PUTENV=0;       AC_SUBST([REPLACE_PUTENV])
-  REPLACE_STRTOD=0;       AC_SUBST([REPLACE_STRTOD])
-  VOID_UNSETENV=0;        AC_SUBST([VOID_UNSETENV])
+  HAVE_ATOLL=1;              AC_SUBST([HAVE_ATOLL])
+  HAVE_CALLOC_POSIX=1;       AC_SUBST([HAVE_CALLOC_POSIX])
+  HAVE_GETSUBOPT=1;          AC_SUBST([HAVE_GETSUBOPT])
+  HAVE_MALLOC_POSIX=1;       AC_SUBST([HAVE_MALLOC_POSIX])
+  HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
+  HAVE_REALLOC_POSIX=1;      AC_SUBST([HAVE_REALLOC_POSIX])
+  HAVE_RANDOM_R=1;           AC_SUBST([HAVE_RANDOM_R])
+  HAVE_RPMATCH=1;            AC_SUBST([HAVE_RPMATCH])
+  HAVE_SETENV=1;             AC_SUBST([HAVE_SETENV])
+  HAVE_STRTOD=1;             AC_SUBST([HAVE_STRTOD])
+  HAVE_STRTOLL=1;            AC_SUBST([HAVE_STRTOLL])
+  HAVE_STRTOULL=1;           AC_SUBST([HAVE_STRTOULL])
+  HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
+  HAVE_SYS_LOADAVG_H=0;      AC_SUBST([HAVE_SYS_LOADAVG_H])
+  HAVE_UNSETENV=1;           AC_SUBST([HAVE_UNSETENV])
+  HAVE_DECL_GETLOADAVG=1;    AC_SUBST([HAVE_DECL_GETLOADAVG])
+  REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
+  REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
+  REPLACE_STRTOD=0;          AC_SUBST([REPLACE_STRTOD])
+  VOID_UNSETENV=0;           AC_SUBST([VOID_UNSETENV])
 ])
diff --git a/libmissing/m4/strcase.m4 b/libmissing/m4/strcase.m4
index 79c525c..0dfdb1a 100644
--- a/libmissing/m4/strcase.m4
+++ b/libmissing/m4/strcase.m4
@@ -1,5 +1,5 @@
-# strcase.m4 serial 9
-dnl Copyright (C) 2002, 2005-2008 Free Software Foundation, Inc.
+# strcase.m4 serial 10
+dnl Copyright (C) 2002, 2005-2009 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.
@@ -13,7 +13,7 @@ AC_DEFUN([gl_STRCASE],
 AC_DEFUN([gl_FUNC_STRCASECMP],
 [
   AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strcasecmp)
+  AC_REPLACE_FUNCS([strcasecmp])
   if test $ac_cv_func_strcasecmp = no; then
     HAVE_STRCASECMP=0
     gl_PREREQ_STRCASECMP
@@ -23,11 +23,11 @@ AC_DEFUN([gl_FUNC_STRCASECMP],
 AC_DEFUN([gl_FUNC_STRNCASECMP],
 [
   AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strncasecmp)
+  AC_REPLACE_FUNCS([strncasecmp])
   if test $ac_cv_func_strncasecmp = no; then
     gl_PREREQ_STRNCASECMP
   fi
-  AC_CHECK_DECLS(strncasecmp)
+  AC_CHECK_DECLS([strncasecmp])
   if test $ac_cv_have_decl_strncasecmp = no; then
     HAVE_DECL_STRNCASECMP=0
   fi
diff --git a/libmissing/m4/strdup.m4 b/libmissing/m4/strdup.m4
deleted file mode 100644
index 0537def..0000000
--- a/libmissing/m4/strdup.m4
+++ /dev/null
@@ -1,38 +0,0 @@
-# strdup.m4 serial 10
-
-dnl Copyright (C) 2002-2008 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_STRDUP],
-[
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strdup)
-  AC_CHECK_DECLS_ONCE(strdup)
-  if test $ac_cv_have_decl_strdup = no; then
-    HAVE_DECL_STRDUP=0
-  fi
-  gl_PREREQ_STRDUP
-])
-
-AC_DEFUN([gl_FUNC_STRDUP_POSIX],
-[
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
-  if test $gl_cv_func_malloc_posix != yes; then
-    REPLACE_STRDUP=1
-    AC_LIBOBJ([strdup])
-  else
-    AC_REPLACE_FUNCS(strdup)
-  fi
-  AC_CHECK_DECLS_ONCE(strdup)
-  if test $ac_cv_have_decl_strdup = no; then
-    HAVE_DECL_STRDUP=0
-  fi
-  gl_PREREQ_STRDUP
-])
-
-# Prerequisites of lib/strdup.c.
-AC_DEFUN([gl_PREREQ_STRDUP], [:])
diff --git a/libmissing/m4/strerror.m4 b/libmissing/m4/strerror.m4
new file mode 100644
index 0000000..8c16ca9
--- /dev/null
+++ b/libmissing/m4/strerror.m4
@@ -0,0 +1,68 @@
+# strerror.m4 serial 9
+dnl Copyright (C) 2002, 2007-2008 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],
+[
+  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_CACHE_CHECK([for working strerror function],
+     [gl_cv_func_working_strerror],
+     [AC_RUN_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#include <string.h>
+           ]],
+           [[return !*strerror (-2);]])],
+        [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])
+      ])
+    ])
+    if test $gl_cv_func_working_strerror = no; then
+      dnl The system's strerror() fails to return a string for out-of-range
+      dnl integers. Replace it.
+      REPLACE_STRERROR=1
+    fi
+  else
+    dnl The system's strerror() cannot know about the new errno values we add
+    dnl to <errno.h>. 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])
+  fi
+])
diff --git a/libmissing/m4/string_h.m4 b/libmissing/m4/string_h.m4
index 2d5553c..11f09c8 100644
--- a/libmissing/m4/string_h.m4
+++ b/libmissing/m4/string_h.m4
@@ -1,11 +1,11 @@
 # Configure a GNU-like replacement for <string.h>.
 
-# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2008, 2009 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.
 
-# serial 6
+# serial 7
 
 # Written by Paul Eggert.
 
@@ -32,6 +32,7 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR],
 
 AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
 [
+  GNULIB_MEMCHR=0;      AC_SUBST([GNULIB_MEMCHR])
   GNULIB_MEMMEM=0;      AC_SUBST([GNULIB_MEMMEM])
   GNULIB_MEMPCPY=0;     AC_SUBST([GNULIB_MEMPCPY])
   GNULIB_MEMRCHR=0;     AC_SUBST([GNULIB_MEMRCHR])
@@ -83,6 +84,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
   HAVE_DECL_STRERROR=1;		AC_SUBST([HAVE_DECL_STRERROR])
   HAVE_DECL_STRSIGNAL=1;	AC_SUBST([HAVE_DECL_STRSIGNAL])
   HAVE_STRVERSCMP=1;		AC_SUBST([HAVE_STRVERSCMP])
+  REPLACE_MEMCHR=0;		AC_SUBST([REPLACE_MEMCHR])
   REPLACE_MEMMEM=0;		AC_SUBST([REPLACE_MEMMEM])
   REPLACE_STRDUP=0;		AC_SUBST([REPLACE_STRDUP])
   REPLACE_STRSTR=0;		AC_SUBST([REPLACE_STRSTR])
diff --git a/libmissing/m4/strpbrk.m4 b/libmissing/m4/strpbrk.m4
deleted file mode 100644
index 0398d45..0000000
--- a/libmissing/m4/strpbrk.m4
+++ /dev/null
@@ -1,18 +0,0 @@
-# strpbrk.m4 serial 4
-dnl Copyright (C) 2002-2003, 2007 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_STRPBRK],
-[
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strpbrk)
-  if test $ac_cv_func_strpbrk = no; then
-    HAVE_STRPBRK=0
-    gl_PREREQ_STRPBRK
-  fi
-])
-
-# Prerequisites of lib/strpbrk.c.
-AC_DEFUN([gl_PREREQ_STRPBRK], [:])
diff --git a/libmissing/m4/strptime.m4 b/libmissing/m4/strptime.m4
index 060f000..ee49a6e 100644
--- a/libmissing/m4/strptime.m4
+++ b/libmissing/m4/strptime.m4
@@ -1,5 +1,5 @@
-# strptime.m4 serial 4
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# strptime.m4 serial 5
+dnl Copyright (C) 2007, 2009 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.
@@ -8,7 +8,7 @@ AC_DEFUN([gl_FUNC_STRPTIME],
 [
   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
   AC_REQUIRE([AC_C_RESTRICT])
-  AC_REPLACE_FUNCS(strptime)
+  AC_REPLACE_FUNCS([strptime])
   AC_REQUIRE([gl_TM_GMTOFF])
   if test $ac_cv_func_strptime = yes; then
     REPLACE_STRPTIME=0
diff --git a/libmissing/m4/strsep.m4 b/libmissing/m4/strsep.m4
index 1231dcb..887d688 100644
--- a/libmissing/m4/strsep.m4
+++ b/libmissing/m4/strsep.m4
@@ -1,5 +1,5 @@
-# strsep.m4 serial 8
-dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+# strsep.m4 serial 9
+dnl Copyright (C) 2002, 2003, 2004, 2007, 2009 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.
@@ -13,7 +13,7 @@ AC_DEFUN([gl_FUNC_STRSEP],
   AC_REQUIRE([AC_C_RESTRICT])
 
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strsep)
+  AC_REPLACE_FUNCS([strsep])
   if test $ac_cv_func_strsep = no; then
     HAVE_STRSEP=0
     gl_PREREQ_STRSEP
diff --git a/libmissing/m4/sys_ioctl_h.m4 b/libmissing/m4/sys_ioctl_h.m4
deleted file mode 100644
index 5488039..0000000
--- a/libmissing/m4/sys_ioctl_h.m4
+++ /dev/null
@@ -1,60 +0,0 @@
-# sys_ioctl_h.m4 serial 1
-dnl Copyright (C) 2008 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 Written by Bruno Haible.
-
-AC_DEFUN([gl_SYS_IOCTL_H],
-[
-  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
-  dnl once only, before all statements that occur in other macros.
-  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
-
-  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
-  if test $ac_cv_header_sys_ioctl_h = yes; then
-    HAVE_SYS_IOCTL_H=1
-    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
-    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
-    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
-      [gl_cv_decl_ioctl_in_sys_ioctl_h],
-      [AC_CHECK_DECL([ioctl],
-         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
-         [gl_cv_decl_ioctl_in_sys_ioctl_h=no],
-         [#include <sys/ioctl.h>])
-      ])
-    if test $gl_cv_decl_ioctl_in_sys_ioctl_h != yes; then
-      SYS_IOCTL_H='sys/ioctl.h'
-    fi
-  else
-    HAVE_SYS_IOCTL_H=0
-    SYS_IOCTL_H='sys/ioctl.h'
-  fi
-  AC_SUBST([HAVE_SYS_IOCTL_H])
-  dnl Execute this unconditionally, because SYS_IOCTL_H may be set by other
-  dnl modules, after this code is executed.
-  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
-])
-
-dnl Unconditionally enables the replacement of <sys/ioctl.h>.
-AC_DEFUN([gl_REPLACE_SYS_IOCTL_H],
-[
-  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
-  SYS_IOCTL_H='sys/ioctl.h'
-])
-
-AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
-[
-  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
-  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
-  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
-])
-
-AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
-[
-  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
-  dnl Assume proper GNU behavior unless another module says otherwise.
-  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
-  SYS_IOCTL_H='';                AC_SUBST([SYS_IOCTL_H])
-])
diff --git a/libmissing/m4/sys_select_h.m4 b/libmissing/m4/sys_select_h.m4
index c537e79..c48be2c 100644
--- a/libmissing/m4/sys_select_h.m4
+++ b/libmissing/m4/sys_select_h.m4
@@ -1,5 +1,5 @@
-# sys_select_h.m4 serial 6
-dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
+# sys_select_h.m4 serial 7
+dnl Copyright (C) 2006-2009 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.
@@ -42,4 +42,6 @@ AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
 AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
 [
   GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
 ])
diff --git a/libmissing/m4/sys_socket_h.m4 b/libmissing/m4/sys_socket_h.m4
index fc43d5c..74e8110 100644
--- a/libmissing/m4/sys_socket_h.m4
+++ b/libmissing/m4/sys_socket_h.m4
@@ -1,5 +1,5 @@
-# sys_socket_h.m4 serial 11
-dnl Copyright (C) 2005-2008 Free Software Foundation, Inc.
+# sys_socket_h.m4 serial 12
+dnl Copyright (C) 2005-2009 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.
@@ -40,39 +40,65 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
   else
     SYS_SOCKET_H='sys/socket.h'
   fi
+  # We need to check for ws2tcpip.h now.
+  gl_PREREQ_SYS_H_SOCKET
+  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
+  /* 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>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+  if test $ac_cv_type_struct_sockaddr_storage = no; then
+    HAVE_STRUCT_SOCKADDR_STORAGE=0
+    SYS_SOCKET_H='sys/socket.h'
+  fi
+  if test $ac_cv_type_sa_family_t = no; then
+    HAVE_SA_FAMILY_T=0
+    SYS_SOCKET_H='sys/socket.h'
+  fi
   if test -n "$SYS_SOCKET_H"; then
-    dnl Check prerequisites of the <sys/socket.h> replacement.
-    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
-        HAVE_WS2TCPIP_H=0
-      fi
-    fi
     gl_PREREQ_SYS_H_WINSOCK2
-    AC_SUBST([HAVE_SYS_SOCKET_H])
-    AC_SUBST([HAVE_WS2TCPIP_H])
   fi
   AC_SUBST([SYS_SOCKET_H])
 ])
 
+AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
+[
+  dnl Check prerequisites of the <sys/socket.h> replacement.
+  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
+      HAVE_WS2TCPIP_H=0
+    fi
+  fi
+  AC_SUBST([HAVE_SYS_SOCKET_H])
+  AC_SUBST([HAVE_WS2TCPIP_H])
+])
+
 # Common prerequisites of of the <sys/socket.h> replacement and of the
 # <sys/select.h> replacement.
 # Sets and substitutes HAVE_WINSOCK2_H.
 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
 [
-  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  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_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
@@ -96,12 +122,10 @@ AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
   AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
-  gl_MODULE_INDICATOR([$1])
 ])
 
 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
 [
-  AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for GNULIB_CLOSE
   GNULIB_SOCKET=0;      AC_SUBST([GNULIB_SOCKET])
   GNULIB_CONNECT=0;     AC_SUBST([GNULIB_CONNECT])
   GNULIB_ACCEPT=0;      AC_SUBST([GNULIB_ACCEPT])
@@ -116,4 +140,6 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
   GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
   GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
   GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
+  HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
+  HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
 ])
diff --git a/libmissing/m4/sys_stat_h.m4 b/libmissing/m4/sys_stat_h.m4
index cfe8011..20c82ed 100644
--- a/libmissing/m4/sys_stat_h.m4
+++ b/libmissing/m4/sys_stat_h.m4
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 8   -*- Autoconf -*-
+# sys_stat_h.m4 serial 10   -*- Autoconf -*-
 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -50,6 +50,10 @@ AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
 
 AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
+  GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
+  GNULIB_LSTAT=0;  AC_SUBST([GNULIB_LSTAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_LCHMOD=1;   AC_SUBST([HAVE_LCHMOD])
+  REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
   REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
 ])
diff --git a/libmissing/m4/tm_gmtoff.m4 b/libmissing/m4/tm_gmtoff.m4
index cb0b3c8..911af0a 100644
--- a/libmissing/m4/tm_gmtoff.m4
+++ b/libmissing/m4/tm_gmtoff.m4
@@ -1,5 +1,5 @@
-# tm_gmtoff.m4 serial 2
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# tm_gmtoff.m4 serial 3
+dnl Copyright (C) 2002, 2009 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.
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_TM_GMTOFF],
 [
  AC_CHECK_MEMBER([struct tm.tm_gmtoff],
-                 [AC_DEFINE(HAVE_TM_GMTOFF, 1,
+                 [AC_DEFINE([HAVE_TM_GMTOFF], [1],
                             [Define if struct tm has the tm_gmtoff member.])],
                  ,
                  [#include <time.h>])
diff --git a/libmissing/m4/unistd_h.m4 b/libmissing/m4/unistd_h.m4
index e9f7a7d..ff9a4ea 100644
--- a/libmissing/m4/unistd_h.m4
+++ b/libmissing/m4/unistd_h.m4
@@ -1,5 +1,5 @@
-# unistd_h.m4 serial 14
-dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
+# unistd_h.m4 serial 17
+dnl Copyright (C) 2006-2009 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.
@@ -36,14 +36,19 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_CLOSE=0;            AC_SUBST([GNULIB_CLOSE])
   GNULIB_DUP2=0;             AC_SUBST([GNULIB_DUP2])
   GNULIB_ENVIRON=0;          AC_SUBST([GNULIB_ENVIRON])
+  GNULIB_EUIDACCESS=0;       AC_SUBST([GNULIB_EUIDACCESS])
   GNULIB_FCHDIR=0;           AC_SUBST([GNULIB_FCHDIR])
   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_GETHOSTNAME=0;      AC_SUBST([GNULIB_GETHOSTNAME])
   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_LSEEK=0;            AC_SUBST([GNULIB_LSEEK])
   GNULIB_READLINK=0;         AC_SUBST([GNULIB_READLINK])
   GNULIB_SLEEP=0;            AC_SUBST([GNULIB_SLEEP])
@@ -51,10 +56,15 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_WRITE=0;            AC_SUBST([GNULIB_WRITE])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DUP2=1;            AC_SUBST([HAVE_DUP2])
+  HAVE_EUIDACCESS=1;      AC_SUBST([HAVE_EUIDACCESS])
   HAVE_FSYNC=1;           AC_SUBST([HAVE_FSYNC])
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
+  HAVE_GETDOMAINNAME=1;   AC_SUBST([HAVE_GETDOMAINNAME])
   HAVE_GETDTABLESIZE=1;   AC_SUBST([HAVE_GETDTABLESIZE])
+  HAVE_GETHOSTNAME=1;     AC_SUBST([HAVE_GETHOSTNAME])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
+  HAVE_GETUSERSHELL=1;    AC_SUBST([HAVE_GETUSERSHELL])
+  HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
   HAVE_READLINK=1;        AC_SUBST([HAVE_READLINK])
   HAVE_SLEEP=1;           AC_SUBST([HAVE_SLEEP])
   HAVE_DECL_ENVIRON=1;    AC_SUBST([HAVE_DECL_ENVIRON])
diff --git a/libmissing/m4/vasnprintf.m4 b/libmissing/m4/vasnprintf.m4
index 536258c..3a1d1e0 100644
--- a/libmissing/m4/vasnprintf.m4
+++ b/libmissing/m4/vasnprintf.m4
@@ -1,5 +1,5 @@
-# vasnprintf.m4 serial 25
-dnl Copyright (C) 2002-2004, 2006-2008 Free Software Foundation, Inc.
+# vasnprintf.m4 serial 29
+dnl Copyright (C) 2002-2004, 2006-2009 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.
@@ -20,7 +20,7 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF],
   AC_LIBOBJ([printf-parse])
   AC_LIBOBJ([asnprintf])
   if test $ac_cv_func_vasnprintf = yes; then
-    AC_DEFINE([REPLACE_VASNPRINTF], 1,
+    AC_DEFINE([REPLACE_VASNPRINTF], [1],
       [Define if vasnprintf exists but is overridden by gnulib.])
   fi
   gl_PREREQ_PRINTF_ARGS
@@ -52,13 +52,13 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
 ])
 
 # Prerequisites of lib/vasnprintf.c.
-AC_DEFUN([gl_PREREQ_VASNPRINTF],
+AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
 [
   AC_REQUIRE([AC_FUNC_ALLOCA])
   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
   AC_REQUIRE([gt_TYPE_WCHAR_T])
   AC_REQUIRE([gt_TYPE_WINT_T])
-  AC_CHECK_FUNCS(snprintf wcslen)
+  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>])
@@ -66,14 +66,14 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF],
 
 # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
 # arguments.
-AC_DEFUN([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
+AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
 [
   AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   case "$gl_cv_func_printf_long_double" in
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          'long double' arguments.])
       ;;
@@ -89,7 +89,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          infinite 'double' arguments.])
       ;;
@@ -110,7 +110,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
         *yes)
           ;;
         *)
-          AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], 1,
+          AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1],
             [Define if the vasnprintf implementation needs special code for
              infinite 'long double' arguments.])
           ;;
@@ -127,7 +127,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1,
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
         [Define if the vasnprintf implementation needs special code for
          the 'a' and 'A' directives.])
       AC_CHECK_FUNCS([nl_langinfo])
@@ -143,13 +143,28 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], 1,
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1],
         [Define if the vasnprintf implementation needs special code for
          the 'F' directive.])
       ;;
   esac
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
+[
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+  case "$gl_cv_func_printf_directive_ls" in
+    *yes)
+      ;;
+    *)
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
+        [Define if the vasnprintf implementation needs special code for
+         the 'ls' directive.])
+      ;;
+  esac
+])
+
 # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
 [
@@ -158,7 +173,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], 1,
+      AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
         [Define if the vasnprintf implementation needs special code for the
          ' flag.])
       ;;
@@ -173,7 +188,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], 1,
+      AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1],
         [Define if the vasnprintf implementation needs special code for the
          '-' flag.])
       ;;
@@ -188,7 +203,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_FLAG_ZERO], 1,
+      AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1],
         [Define if the vasnprintf implementation needs special code for the
          0 flag.])
       ;;
@@ -203,13 +218,13 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], 1,
+      AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1],
         [Define if the vasnprintf implementation needs special code for
          supporting large precisions without arbitrary bounds.])
-      AC_DEFINE([NEED_PRINTF_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          'double' arguments.])
-      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          'long double' arguments.])
       ;;
@@ -225,13 +240,13 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
     *yes)
       ;;
     *)
-      AC_DEFINE([NEED_PRINTF_ENOMEM], 1,
+      AC_DEFINE([NEED_PRINTF_ENOMEM], [1],
         [Define if the vasnprintf implementation needs special code for
          surviving out-of-memory conditions.])
-      AC_DEFINE([NEED_PRINTF_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          'double' arguments.])
-      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
+      AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
         [Define if the vasnprintf implementation needs special code for
          'long double' arguments.])
       ;;
@@ -247,6 +262,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
   gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
   gl_PREREQ_VASNPRINTF_DIRECTIVE_A
   gl_PREREQ_VASNPRINTF_DIRECTIVE_F
+  gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
   gl_PREREQ_VASNPRINTF_FLAG_GROUPING
   gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
   gl_PREREQ_VASNPRINTF_FLAG_ZERO
diff --git a/libmissing/m4/wchar.m4 b/libmissing/m4/wchar.m4
index 5c923fa..2e52a82 100644
--- a/libmissing/m4/wchar.m4
+++ b/libmissing/m4/wchar.m4
@@ -1,13 +1,13 @@
 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
 
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+dnl Copyright (C) 2007-2009 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 Written by Eric Blake.
 
-# wchar.m4 serial 6
+# wchar.m4 serial 23
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -61,9 +61,40 @@ AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
 
 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
 [
-  GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
+  GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
+  GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
+  GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
+  GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
+  GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
+  GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
+  GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
+  GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
+  GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
+  GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
+  GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
-  REPLACE_WCWIDTH=0;   AC_SUBST([REPLACE_WCWIDTH])
-  WCHAR_H='';          AC_SUBST([WCHAR_H])
+  HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
+  HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
+  HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
+  HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
+  HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
+  HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
+  HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
+  HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
+  HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
+  HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
+  HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
+  REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
+  REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
+  REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
+  REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
+  REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
+  REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
+  REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
+  REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
+  REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
+  REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
+  REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
+  REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
+  WCHAR_H='';           AC_SUBST([WCHAR_H])
 ])
diff --git a/libmissing/m4/wchar_t.m4 b/libmissing/m4/wchar_t.m4
index cde2129..fb27a7f 100644
--- a/libmissing/m4/wchar_t.m4
+++ b/libmissing/m4/wchar_t.m4
@@ -1,5 +1,5 @@
-# wchar_t.m4 serial 1 (gettext-0.12)
-dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+# wchar_t.m4 serial 3 (gettext-0.18)
+dnl Copyright (C) 2002-2003, 2008, 2009 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.
@@ -10,11 +10,11 @@ dnl Prerequisite: AC_PROG_CC
 
 AC_DEFUN([gt_TYPE_WCHAR_T],
 [
-  AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t,
+  AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t],
     [AC_TRY_COMPILE([#include <stddef.h>
        wchar_t foo = (wchar_t)'\0';], ,
-       gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)])
+       [gt_cv_c_wchar_t=yes], [gt_cv_c_wchar_t=no])])
   if test $gt_cv_c_wchar_t = yes; then
-    AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.])
+    AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.])
   fi
 ])
diff --git a/libmissing/m4/wctob.m4 b/libmissing/m4/wctob.m4
new file mode 100644
index 0000000..39270c9
--- /dev/null
+++ b/libmissing/m4/wctob.m4
@@ -0,0 +1,91 @@
+# wctob.m4 serial 4
+dnl Copyright (C) 2008-2009 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_WCTOB],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_CHECK_FUNCS_ONCE([wctob])
+  if test $ac_cv_func_wctob = no; then
+    HAVE_DECL_WCTOB=0
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([wctob])
+    gl_PREREQ_WCTOB
+  else
+
+    dnl Solaris 9 has the wctob() function but it does not work.
+    AC_REQUIRE([AC_PROG_CC])
+    AC_REQUIRE([gt_LOCALE_FR])
+    AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+    AC_CACHE_CHECK([whether wctob works],
+      [gl_cv_func_wctob_works],
+      [
+        dnl Initial guess, used when cross-compiling or when no suitable locale
+        dnl is present.
+changequote(,)dnl
+        case "$host_os" in
+            # Guess no on Solaris <= 9.
+          solaris2.[1-9] | solaris2.[1-9].*)
+            gl_cv_func_wctob_works="guessing no" ;;
+            # Guess yes otherwise.
+          *) gl_cv_func_wctob_works="guessing yes" ;;
+        esac
+changequote([,])dnl
+        if test $LOCALE_FR != none; then
+          AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+    {
+      wchar_t wc;
+
+      if (mbtowc (&wc, "\374", 1) == 1)
+        if (wctob (wc) != (unsigned char) '\374')
+          return 1;
+    }
+  return 0;
+}],
+            [gl_cv_func_wctob_works=yes],
+            [gl_cv_func_wctob_works=no],
+            [:])
+        fi
+      ])
+    case "$gl_cv_func_wctob_works" in
+      *yes) ;;
+      *) REPLACE_WCTOB=1 ;;
+    esac
+    if test $REPLACE_WCTOB = 1; then
+      gl_REPLACE_WCHAR_H
+      AC_LIBOBJ([wctob])
+      gl_PREREQ_WCTOB
+    else
+
+      dnl IRIX 6.5 has the wctob() function but does not declare it.
+      AC_CHECK_DECLS([wctob], [], [], [
+/* 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>.  */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+      if test $ac_cv_have_decl_wctob != yes; then
+        HAVE_DECL_WCTOB=0
+        gl_REPLACE_WCHAR_H
+      fi
+    fi
+  fi
+])
+
+# Prerequisites of lib/wctob.c.
+AC_DEFUN([gl_PREREQ_WCTOB], [
+  :
+])
diff --git a/libmissing/m4/wint_t.m4 b/libmissing/m4/wint_t.m4
index af5ed93..47a4363 100644
--- a/libmissing/m4/wint_t.m4
+++ b/libmissing/m4/wint_t.m4
@@ -1,5 +1,5 @@
-# wint_t.m4 serial 2 (gettext-0.17)
-dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+# wint_t.m4 serial 4 (gettext-0.18)
+dnl Copyright (C) 2003, 2007-2009 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.
@@ -10,7 +10,7 @@ dnl Prerequisite: AC_PROG_CC
 
 AC_DEFUN([gt_TYPE_WINT_T],
 [
-  AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t,
+  AC_CACHE_CHECK([for wint_t], [gt_cv_c_wint_t],
     [AC_TRY_COMPILE([
 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
    <wchar.h>.
@@ -21,8 +21,8 @@ AC_DEFUN([gt_TYPE_WINT_T],
 #include <time.h>
 #include <wchar.h>
        wint_t foo = (wchar_t)'\0';], ,
-       gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)])
+       [gt_cv_c_wint_t=yes], [gt_cv_c_wint_t=no])])
   if test $gt_cv_c_wint_t = yes; then
-    AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.])
+    AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.])
   fi
 ])
diff --git a/libmissing/m4/xsize.m4 b/libmissing/m4/xsize.m4
index 85bb721..631893c 100644
--- a/libmissing/m4/xsize.m4
+++ b/libmissing/m4/xsize.m4
@@ -1,5 +1,5 @@
-# xsize.m4 serial 3
-dnl Copyright (C) 2003-2004 Free Software Foundation, Inc.
+# xsize.m4 serial 4
+dnl Copyright (C) 2003-2004, 2008 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.
@@ -9,5 +9,5 @@ AC_DEFUN([gl_XSIZE],
   dnl Prerequisites of lib/xsize.h.
   AC_REQUIRE([gl_SIZE_MAX])
   AC_REQUIRE([AC_C_INLINE])
-  AC_CHECK_HEADERS(stdint.h)
+  AC_CHECK_HEADERS([stdint.h])
 ])
diff --git a/libmissing/mbrtowc.c b/libmissing/mbrtowc.c
new file mode 100644
index 0000000..7b528e8
--- /dev/null
+++ b/libmissing/mbrtowc.c
@@ -0,0 +1,386 @@
+/* Convert multibyte character to wide character.
+   Copyright (C) 1999-2002, 2005-2009 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 2008.
+
+   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 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 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 <wchar.h>
+
+#if GNULIB_defined_mbstate_t
+/* Implement mbrtowc() on top of mbtowc().  */
+
+# include <errno.h>
+# include <stdlib.h>
+
+# include "localcharset.h"
+# include "streq.h"
+# include "verify.h"
+
+
+verify (sizeof (mbstate_t) >= 4);
+
+static char internal_state[4];
+
+size_t
+mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+  char *pstate = (char *)ps;
+
+  if (pstate == NULL)
+    pstate = internal_state;
+
+  if (s == NULL)
+    {
+      pwc = NULL;
+      s = "";
+      n = 1;
+    }
+
+  if (n == 0)
+    return (size_t)(-2);
+
+  /* Here n > 0.  */
+  {
+    size_t nstate = pstate[0];
+    char buf[4];
+    const char *p;
+    size_t m;
+
+    switch (nstate)
+      {
+      case 0:
+	p = s;
+	m = n;
+	break;
+      case 3:
+	buf[2] = pstate[3];
+	/*FALLTHROUGH*/
+      case 2:
+	buf[1] = pstate[2];
+	/*FALLTHROUGH*/
+      case 1:
+	buf[0] = pstate[1];
+	p = buf;
+	m = nstate;
+	buf[m++] = s[0];
+	if (n >= 2 && m < 4)
+	  {
+	    buf[m++] = s[1];
+	    if (n >= 3 && m < 4)
+	      buf[m++] = s[2];
+	  }
+	break;
+      default:
+	errno = EINVAL;
+	return (size_t)(-1);
+      }
+
+    /* Here m > 0.  */
+
+# if __GLIBC__
+    /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
+    mbtowc (NULL, NULL, 0);
+# endif
+    {
+      int res = mbtowc (pwc, p, m);
+
+      if (res >= 0)
+	{
+	  if (pwc != NULL && ((*pwc == 0) != (res == 0)))
+	    abort ();
+	  if (nstate >= (res > 0 ? res : 1))
+	    abort ();
+	  res -= nstate;
+	  pstate[0] = 0;
+	  return res;
+	}
+
+      /* mbtowc does not distinguish between invalid and incomplete multibyte
+	 sequences.  But mbrtowc needs to make this distinction.
+	 There are two possible approaches:
+	   - Use iconv() and its return value.
+	   - Use built-in knowledge about the possible encodings.
+	 Given the low quality of implementation of iconv() on the systems that
+	 lack mbrtowc(), we use the second approach.
+	 The possible encodings are:
+	   - 8-bit encodings,
+	   - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
+	   - UTF-8.
+	 Use specialized code for each.  */
+      if (m >= 4 || m >= MB_CUR_MAX)
+	goto invalid;
+      /* Here MB_CUR_MAX > 1 and 0 < m < 4.  */
+      {
+	const char *encoding = locale_charset ();
+
+	if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
+	  {
+	    /* Cf. unistr/u8-mblen.c.  */
+	    unsigned char c = (unsigned char) p[0];
+
+	    if (c >= 0xc2)
+	      {
+		if (c < 0xe0)
+		  {
+		    if (m == 1)
+		      goto incomplete;
+		  }
+		else if (c < 0xf0)
+		  {
+		    if (m == 1)
+		      goto incomplete;
+		    if (m == 2)
+		      {
+			unsigned char c2 = (unsigned char) p[1];
+
+			if ((c2 ^ 0x80) < 0x40
+			    && (c >= 0xe1 || c2 >= 0xa0)
+			    && (c != 0xed || c2 < 0xa0))
+			  goto incomplete;
+		      }
+		  }
+		else if (c <= 0xf4)
+		  {
+		    if (m == 1)
+		      goto incomplete;
+		    else /* m == 2 || m == 3 */
+		      {
+			unsigned char c2 = (unsigned char) p[1];
+
+			if ((c2 ^ 0x80) < 0x40
+			    && (c >= 0xf1 || c2 >= 0x90)
+			    && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
+			  {
+			    if (m == 2)
+			      goto incomplete;
+			    else /* m == 3 */
+			      {
+				unsigned char c3 = (unsigned char) p[2];
+
+				if ((c3 ^ 0x80) < 0x40)
+				  goto incomplete;
+			      }
+			  }
+		      }
+		  }
+	      }
+	    goto invalid;
+	  }
+
+	/* As a reference for this code, you can use the GNU libiconv
+	   implementation.  Look for uses of the RET_TOOFEW macro.  */
+
+	if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
+	  {
+	    if (m == 1)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
+		  goto incomplete;
+	      }
+	    if (m == 2)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if (c == 0x8f)
+		  {
+		    unsigned char c2 = (unsigned char) p[1];
+
+		    if (c2 >= 0xa1 && c2 < 0xff)
+		      goto incomplete;
+		  }
+	      }
+	    goto invalid;
+	  }
+	if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+	    || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+	    || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
+	  {
+	    if (m == 1)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if (c >= 0xa1 && c < 0xff)
+		  goto incomplete;
+	      }
+	    goto invalid;
+	  }
+	if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
+	  {
+	    if (m == 1)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
+		  goto incomplete;
+	      }
+	    else /* m == 2 || m == 3 */
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if (c == 0x8e)
+		  goto incomplete;
+	      }
+	    goto invalid;
+	  }
+	if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
+	  {
+	    if (m == 1)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
+		  goto incomplete;
+	      }
+	    else /* m == 2 || m == 3 */
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if (c >= 0x90 && c <= 0xe3)
+		  {
+		    unsigned char c2 = (unsigned char) p[1];
+
+		    if (c2 >= 0x30 && c2 <= 0x39)
+		      {
+			if (m == 2)
+			  goto incomplete;
+			else /* m == 3 */
+			  {
+			    unsigned char c3 = (unsigned char) p[2];
+
+			    if (c3 >= 0x81 && c3 <= 0xfe)
+			      goto incomplete;
+			  }
+		      }
+		  }
+	      }
+	    goto invalid;
+	  }
+	if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
+	  {
+	    if (m == 1)
+	      {
+		unsigned char c = (unsigned char) p[0];
+
+		if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
+		    || (c >= 0xf0 && c <= 0xf9))
+		  goto incomplete;
+	      }
+	    goto invalid;
+	  }
+
+	/* An unknown multibyte encoding.  */
+	goto incomplete;
+      }
+
+     incomplete:
+      {
+	size_t k = nstate;
+	/* Here 0 <= k < m < 4.  */
+	pstate[++k] = s[0];
+	if (k < m)
+	  {
+	    pstate[++k] = s[1];
+	    if (k < m)
+	      pstate[++k] = s[2];
+	  }
+	if (k != m)
+	  abort ();
+      }
+      pstate[0] = m;
+      return (size_t)(-2);
+
+     invalid:
+      errno = EILSEQ;
+      /* The conversion state is undefined, says POSIX.  */
+      return (size_t)(-1);
+    }
+  }
+}
+
+#else
+/* Override the system's mbrtowc() function.  */
+
+# undef mbrtowc
+
+size_t
+rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+# if MBRTOWC_NULL_ARG_BUG || MBRTOWC_RETVAL_BUG
+  if (s == NULL)
+    {
+      pwc = NULL;
+      s = "";
+      n = 1;
+    }
+# endif
+
+# if MBRTOWC_RETVAL_BUG
+  {
+    static mbstate_t internal_state;
+
+    /* Override mbrtowc's internal state.  We can not call mbsinit() on the
+       hidden internal state, but we can call it on our variable.  */
+    if (ps == NULL)
+      ps = &internal_state;
+
+    if (!mbsinit (ps))
+      {
+	/* Parse the rest of the multibyte character byte for byte.  */
+	size_t count = 0;
+	for (; n > 0; s++, n--)
+	  {
+	    wchar_t wc;
+	    size_t ret = mbrtowc (&wc, s, 1, ps);
+
+	    if (ret == (size_t)(-1))
+	      return (size_t)(-1);
+	    count++;
+	    if (ret != (size_t)(-2))
+	      {
+		/* The multibyte character has been completed.  */
+		if (pwc != NULL)
+		  *pwc = wc;
+		return (wc == 0 ? 0 : count);
+	      }
+	  }
+	return (size_t)(-2);
+      }
+  }
+# endif
+
+# if MBRTOWC_NUL_RETVAL_BUG
+  {
+    wchar_t wc;
+    size_t ret = mbrtowc (&wc, s, n, ps);
+
+    if (ret != (size_t)(-1) && ret != (size_t)(-2))
+      {
+	if (pwc != NULL)
+	  *pwc = wc;
+	if (wc == 0)
+	  ret = 0;
+      }
+    return ret;
+  }
+# else
+  return mbrtowc (pwc, s, n, ps);
+# endif
+}
+
+#endif
diff --git a/libmissing/mbsinit.c b/libmissing/mbsinit.c
new file mode 100644
index 0000000..7495794
--- /dev/null
+++ b/libmissing/mbsinit.c
@@ -0,0 +1,47 @@
+/* Test for initial conversion state.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 2008.
+
+   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 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 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 <wchar.h>
+
+#include "verify.h"
+
+/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
+   and wcrtomb(), wcsrtombs().
+   We assume that
+     - sizeof (mbstate_t) >= 4,
+     - only stateless encodings are supported (such as UTF-8 and EUC-JP, but
+       not ISO-2022 variants),
+     - for each encoding, the number of bytes for a wide character is <= 4.
+       (This maximum is attained for UTF-8, GB18030, EUC-TW.)
+   We define the meaning of mbstate_t as follows:
+     - In mb -> wc direction, mbstate_t's first byte contains the number of
+       buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
+     - In wc -> mb direction, mbstate_t contains no information. In other
+       words, it is always in the initial state.  */
+
+verify (sizeof (mbstate_t) >= 4);
+
+int
+mbsinit (const mbstate_t *ps)
+{
+  const char *pstate = (const char *)ps;
+
+  return pstate[0] == 0;
+}
diff --git a/libmissing/mbsrtowcs-state.c b/libmissing/mbsrtowcs-state.c
new file mode 100644
index 0000000..b4eee86
--- /dev/null
+++ b/libmissing/mbsrtowcs-state.c
@@ -0,0 +1,37 @@
+/* Convert string to wide string.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 2008.
+
+   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 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 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>
+
+#include <wchar.h>
+
+/* Internal state used by the functions mbsrtowcs() and mbsnrtowcs().  */
+mbstate_t _gl_mbsrtowcs_state
+/* The state must initially be in the "initial state"; so, zero-initialize it.
+   On most systems, putting it into BSS is sufficient.  Not so on MacOS X 10.3,
+   see <http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00329.html>.
+   When it needs an initializer, use 0 or {0} as initializer? 0 only works
+   when mbstate_t is a scalar type (such as when gnulib defines it, or on
+   AIX, IRIX, mingw). {0} works as an initializer in all cases: for a struct
+   or union type, but also for a scalar type (ISO C 99, 6.7.8.(11)).  */
+#if defined __ELF__
+  /* On ELF systems, variables in BSS behave well.  */
+#else
+  /* Use braces, to be on the safe side.  */
+  = { 0 }
+#endif
+  ;
diff --git a/libmissing/mbsrtowcs.c b/libmissing/mbsrtowcs.c
new file mode 100644
index 0000000..66427ab
--- /dev/null
+++ b/libmissing/mbsrtowcs.c
@@ -0,0 +1,136 @@
+/* Convert string to wide string.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 2008.
+
+   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 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 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 <wchar.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "strnlen1.h"
+
+
+extern mbstate_t _gl_mbsrtowcs_state;
+
+size_t
+mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
+{
+  if (ps == NULL)
+    ps = &_gl_mbsrtowcs_state;
+  {
+    const char *src = *srcp;
+
+    if (dest != NULL)
+      {
+	wchar_t *destptr = dest;
+
+	for (; len > 0; destptr++, len--)
+	  {
+	    size_t src_avail;
+	    size_t ret;
+
+	    /* An optimized variant of
+	       src_avail = strnlen1 (src, MB_LEN_MAX);  */
+	    if (src[0] == '\0')
+	      src_avail = 1;
+	    else if (src[1] == '\0')
+	      src_avail = 2;
+	    else if (src[2] == '\0')
+	      src_avail = 3;
+	    else if (MB_LEN_MAX <= 4 || src[3] == '\0')
+	      src_avail = 4;
+	    else
+	      src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4);
+
+	    /* Parse the next multibyte character.  */
+	    ret = mbrtowc (destptr, src, src_avail, ps);
+
+	    if (ret == (size_t)(-2))
+	      /* Encountered a multibyte character that extends past a '\0' byte
+		 or that is longer than MB_LEN_MAX bytes.  Cannot happen.  */
+	      abort ();
+
+	    if (ret == (size_t)(-1))
+	      goto bad_input;
+	    if (ret == 0)
+	      {
+		src = NULL;
+		/* Here mbsinit (ps).  */
+		break;
+	      }
+	    src += ret;
+	  }
+
+	*srcp = src;
+	return destptr - dest;
+      }
+    else
+      {
+	/* Ignore dest and len, don't store *srcp at the end, and
+	   don't clobber *ps.  */
+	mbstate_t state = *ps;
+	size_t totalcount = 0;
+
+	for (;; totalcount++)
+	  {
+	    size_t src_avail;
+	    size_t ret;
+
+	    /* An optimized variant of
+	       src_avail = strnlen1 (src, MB_LEN_MAX);  */
+	    if (src[0] == '\0')
+	      src_avail = 1;
+	    else if (src[1] == '\0')
+	      src_avail = 2;
+	    else if (src[2] == '\0')
+	      src_avail = 3;
+	    else if (MB_LEN_MAX <= 4 || src[3] == '\0')
+	      src_avail = 4;
+	    else
+	      src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4);
+
+	    /* Parse the next multibyte character.  */
+	    ret = mbrtowc (NULL, src, src_avail, &state);
+
+	    if (ret == (size_t)(-2))
+	      /* Encountered a multibyte character that extends past a '\0' byte
+		 or that is longer than MB_LEN_MAX bytes.  Cannot happen.  */
+	      abort ();
+
+	    if (ret == (size_t)(-1))
+	      goto bad_input2;
+	    if (ret == 0)
+	      {
+		/* Here mbsinit (&state).  */
+		break;
+	      }
+	    src += ret;
+	  }
+
+	return totalcount;
+      }
+
+   bad_input:
+    *srcp = src;
+   bad_input2:
+    errno = EILSEQ;
+    return (size_t)(-1);
+  }
+}
diff --git a/libmissing/memchr.c b/libmissing/memchr.c
new file mode 100644
index 0000000..3ea1d5b
--- /dev/null
+++ b/libmissing/memchr.c
@@ -0,0 +1,172 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006, 2008
+   Free Software Foundation, Inc.
+
+   Based on strlen implementation by Torbjorn Granlund ([email protected]),
+   with help from Dan Sahlin ([email protected]) and
+   commentary by Jim Blandy ([email protected]);
+   adaptation to memchr suggested by Dick Karpinski ([email protected]),
+   and implemented by Roland McGrath ([email protected]).
+
+NOTE: The canonical source of this file is maintained with the GNU C Library.
+Bugs can be reported to [email protected].
+
+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 3 of the License, or 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/>.  */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#include <stddef.h>
+
+#if defined _LIBC
+# include <memcopy.h>
+#else
+# define reg_char char
+#endif
+
+#include <limits.h>
+
+#if HAVE_BP_SYM_H || defined _LIBC
+# include <bp-sym.h>
+#else
+# define BP_SYM(sym) sym
+#endif
+
+#undef __memchr
+#ifdef _LIBC
+# undef memchr
+#endif
+
+#ifndef weak_alias
+# define __memchr memchr
+#endif
+
+/* Search no more than N bytes of S for C.  */
+void *
+__memchr (void const *s, int c_in, size_t n)
+{
+  /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+     long instead of a 64-bit uintmax_t tends to give better
+     performance.  On 64-bit hardware, unsigned long is generally 64
+     bits already.  Change this typedef to experiment with
+     performance.  */
+  typedef unsigned long int longword;
+
+  const unsigned char *char_ptr;
+  const longword *longword_ptr;
+  longword repeated_one;
+  longword repeated_c;
+  unsigned reg_char c;
+
+  c = (unsigned char) c_in;
+
+  /* Handle the first few bytes by reading one byte at a time.
+     Do this until CHAR_PTR is aligned on a longword boundary.  */
+  for (char_ptr = (const unsigned char *) s;
+       n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
+       --n, ++char_ptr)
+    if (*char_ptr == c)
+      return (void *) char_ptr;
+
+  longword_ptr = (const longword *) char_ptr;
+
+  /* All these elucidatory comments refer to 4-byte longwords,
+     but the theory applies equally well to any size longwords.  */
+
+  /* Compute auxiliary longword values:
+     repeated_one is a value which has a 1 in every byte.
+     repeated_c has c in every byte.  */
+  repeated_one = 0x01010101;
+  repeated_c = c | (c << 8);
+  repeated_c |= repeated_c << 16;
+  if (0xffffffffU < (longword) -1)
+    {
+      repeated_one |= repeated_one << 31 << 1;
+      repeated_c |= repeated_c << 31 << 1;
+      if (8 < sizeof (longword))
+	{
+	  size_t i;
+
+	  for (i = 64; i < sizeof (longword) * 8; i *= 2)
+	    {
+	      repeated_one |= repeated_one << i;
+	      repeated_c |= repeated_c << i;
+	    }
+	}
+    }
+
+  /* Instead of the traditional loop which tests each byte, we will test a
+     longword at a time.  The tricky part is testing if *any of the four*
+     bytes in the longword in question are equal to c.  We first use an xor
+     with repeated_c.  This reduces the task to testing whether *any of the
+     four* bytes in longword1 is zero.
+
+     We compute tmp =
+       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+     That is, we perform the following operations:
+       1. Subtract repeated_one.
+       2. & ~longword1.
+       3. & a mask consisting of 0x80 in every byte.
+     Consider what happens in each byte:
+       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+         and step 3 transforms it into 0x80.  A carry can also be propagated
+         to more significant bytes.
+       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+         the byte ends in a single bit of value 0 and k bits of value 1.
+         After step 2, the result is just k bits of value 1: 2^k - 1.  After
+         step 3, the result is 0.  And no carry is produced.
+     So, if longword1 has only non-zero bytes, tmp is zero.
+     Whereas if longword1 has a zero byte, call j the position of the least
+     significant zero byte.  Then the result has a zero at positions 0, ...,
+     j-1 and a 0x80 at position j.  We cannot predict the result at the more
+     significant bytes (positions j+1..3), but it does not matter since we
+     already have a non-zero bit at position 8*j+7.
+
+     So, the test whether any byte in longword1 is zero is equivalent to
+     testing whether tmp is nonzero.  */
+
+  while (n >= sizeof (longword))
+    {
+      longword longword1 = *longword_ptr ^ repeated_c;
+
+      if ((((longword1 - repeated_one) & ~longword1)
+	   & (repeated_one << 7)) != 0)
+	break;
+      longword_ptr++;
+      n -= sizeof (longword);
+    }
+
+  char_ptr = (const unsigned char *) longword_ptr;
+
+  /* At this point, we know that either n < sizeof (longword), or one of the
+     sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
+     machines, we could determine the first such byte without any further
+     memory accesses, just by looking at the tmp result from the last loop
+     iteration.  But this does not work on big-endian machines.  Choose code
+     that works in both cases.  */
+
+  for (; n > 0; --n, ++char_ptr)
+    {
+      if (*char_ptr == c)
+	return (void *) char_ptr;
+    }
+
+  return NULL;
+}
+#ifdef weak_alias
+weak_alias (__memchr, BP_SYM (memchr))
+#endif
diff --git a/libmissing/memchr.valgrind b/libmissing/memchr.valgrind
new file mode 100644
index 0000000..60f247e
--- /dev/null
+++ b/libmissing/memchr.valgrind
@@ -0,0 +1,14 @@
+# Suppress a valgrind message about use of uninitialized memory in memchr().
+# POSIX states that when the character is found, memchr must not read extra
+# bytes in an overestimated length (for example, where memchr is used to
+# implement strnlen).  However, we use a safe word read to provide a speedup.
+{
+    memchr-value4
+    Memcheck:Value4
+    fun:rpl_memchr
+}
+{
+    memchr-value8
+    Memcheck:Value8
+    fun:rpl_memchr
+}
diff --git a/libmissing/memset.c b/libmissing/memset.c
deleted file mode 100644
index ad5763e..0000000
--- a/libmissing/memset.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* memset.c -- set an area of memory to a given value
-   Copyright (C) 1991, 2003 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, 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 <stddef.h>
-
-void *
-memset (void *str, int c, size_t len)
-{
-  register char *st = str;
-
-  while (len-- > 0)
-    *st++ = c;
-  return str;
-}
diff --git a/libmissing/netdb.in.h b/libmissing/netdb.in.h
new file mode 100644
index 0000000..ce9f237
--- /dev/null
+++ b/libmissing/netdb.in.h
@@ -0,0 +1,182 @@
+/* Provide a netdb.h header file for systems lacking it (read: MinGW).
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   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, 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.  */
+
+/* This file is supposed to be used on platforms that lack <netdb.h>.
+   It is intended to provide definitions and prototypes needed by an
+   application.  */
+
+#ifndef _GL_NETDB_H
+
+#if @HAVE_NETDB_H@
+
+# if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+# endif
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_NETDB_H@
+
+#endif
+
+#ifndef _GL_NETDB_H
+#define _GL_NETDB_H
+
+/* Get netdb.h definitions such as struct hostent for MinGW.  */
+#include <sys/socket.h>
+
+/* Declarations for a platform that lacks <netdb.h>, or where it is
+   incomplete.  */
+
+#if @GNULIB_GETADDRINFO@
+
+# if !@HAVE_STRUCT_ADDRINFO@
+
+/* Structure to contain information about address of a service provider.  */
+struct addrinfo
+{
+  int ai_flags;			/* Input flags.  */
+  int ai_family;		/* Protocol family for socket.  */
+  int ai_socktype;		/* Socket type.  */
+  int ai_protocol;		/* Protocol for socket.  */
+  socklen_t ai_addrlen;		/* Length of socket address.  */
+  struct sockaddr *ai_addr;	/* Socket address for socket.  */
+  char *ai_canonname;		/* Canonical name for service location.  */
+  struct addrinfo *ai_next;	/* Pointer to next in list.  */
+};
+# endif
+
+/* Possible values for `ai_flags' field in `addrinfo' structure.  */
+# ifndef AI_PASSIVE
+#  define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
+# endif
+# ifndef AI_CANONNAME
+#  define AI_CANONNAME	0x0002	/* Request for canonical name.  */
+# endif
+# ifndef AI_NUMERICSERV
+#  define AI_NUMERICSERV	0x0400	/* Don't use name resolution.  */
+# endif
+
+# if 0
+/* The commented out definitions below are not yet implemented in the
+   GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
+   cause conflicts on systems with a getaddrinfo() function which does not
+   define them.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
+#  define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
+#  define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */
+#  define AI_ADDRCONFIG	0x0020	/* Use configuration of this host to choose
+				   returned address type..  */
+# endif /* 0 */
+
+/* Error values for `getaddrinfo' function.  */
+# ifndef EAI_BADFLAGS
+#  define EAI_BADFLAGS	  -1	/* Invalid value for `ai_flags' field.  */
+#  define EAI_NONAME	  -2	/* NAME or SERVICE is unknown.  */
+#  define EAI_AGAIN	  -3	/* Temporary failure in name resolution.  */
+#  define EAI_FAIL	  -4	/* Non-recoverable failure in name res.  */
+#  define EAI_NODATA	  -5	/* No address associated with NAME.  */
+#  define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
+#  define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
+#  define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
+#  define EAI_MEMORY	  -10	/* Memory allocation failure.  */
+# endif
+
+/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
+   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
+   in favor of EAI_NONAME.  */
+# if !defined EAI_NODATA && defined EAI_NONAME
+#  define EAI_NODATA EAI_NONAME
+# endif
+
+# ifndef EAI_OVERFLOW
+/* Not defined on mingw32 and Haiku. */
+#  define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
+# endif
+# ifndef EAI_ADDRFAMILY
+/* Not defined on mingw32. */
+#  define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
+# endif
+# ifndef EAI_SYSTEM
+/* Not defined on mingw32. */
+#  define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
+# endif
+
+# if 0
+/* The commented out definitions below are not yet implemented in the
+   GNULIB getaddrinfo() replacement, so are not yet needed.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  ifndef EAI_INPROGRESS
+#   define EAI_INPROGRESS	-100	/* Processing request in progress.  */
+#   define EAI_CANCELED		-101	/* Request canceled.  */
+#   define EAI_NOTCANCELED	-102	/* Request not canceled.  */
+#   define EAI_ALLDONE		-103	/* All requests done.  */
+#   define EAI_INTR		-104	/* Interrupted by a signal.  */
+#   define EAI_IDN_ENCODE	-105	/* IDN encoding failed.  */
+#  endif
+# endif
+
+# if !@HAVE_DECL_GETADDRINFO@
+/* Translate name of a service location and/or a service name to set of
+   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);
+# endif
+
+# if !@HAVE_DECL_FREEADDRINFO@
+/* 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);
+# endif
+
+# if !@HAVE_DECL_GAI_STRERROR@
+/* 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);
+# endif
+
+# if !@HAVE_DECL_GETNAMEINFO@
+/* 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,
+		       char *restrict node, socklen_t nodelen,
+		       char *restrict service, socklen_t servicelen,
+		       int flags);
+# endif
+
+/* Possible flags for getnameinfo.  */
+# ifndef NI_NUMERICHOST
+#  define NI_NUMERICHOST 1
+# endif
+# ifndef NI_NUMERICSERV
+#  define NI_NUMERICSERV 2
+# endif
+
+#endif /* @GNULIB_GETADDRINFO@ */
+
+#endif /* _GL_NETDB_H */
+#endif /* _GL_NETDB_H */
diff --git a/libmissing/netinet_in.in.h b/libmissing/netinet_in.in.h
index 1b6b946..8c94f6a 100644
--- a/libmissing/netinet_in.in.h
+++ b/libmissing/netinet_in.in.h
@@ -19,7 +19,9 @@
 
 #if @HAVE_NETINET_IN_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* On many platforms, <netinet/in.h> assumes prior inclusion of
    <sys/types.h>.  */
diff --git a/libmissing/pathmax.h b/libmissing/pathmax.h
index 4cbfa7e..a5d4335 100644
--- a/libmissing/pathmax.h
+++ b/libmissing/pathmax.h
@@ -1,5 +1,5 @@
 /* Define PATH_MAX somehow.  Requires sys/types.h.
-   Copyright (C) 1992, 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009 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
@@ -26,7 +26,7 @@
 #  define _POSIX_PATH_MAX 256
 # endif
 
-# if !defined PATH_MAX && defined _PC_PATH_MAX
+# if !defined PATH_MAX && defined _PC_PATH_MAX && defined HAVE_PATHCONF
 #  define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
 		    : pathconf ("/", _PC_PATH_MAX))
 # endif
diff --git a/libmissing/raise.c b/libmissing/raise.c
deleted file mode 100644
index d88ce1a..0000000
--- a/libmissing/raise.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Provide a non-threads replacement for the POSIX raise function.
-
-   Copyright (C) 2002, 2003, 2005, 2006 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 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 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/>.  */
-
-/* written by Jim Meyering */
-
-#include <config.h>
-
-#include <sys/types.h>
-#include <signal.h>
-#include <unistd.h>
-
-int
-raise (int sig)
-{
-  return kill (getpid (), sig);
-}
diff --git a/libmissing/recvfrom.c b/libmissing/recvfrom.c
new file mode 100644
index 0000000..770183d
--- /dev/null
+++ b/libmissing/recvfrom.c
@@ -0,0 +1,48 @@
+/* recvfrom.c --- wrappers for Windows recvfrom function
+
+   Copyright (C) 2008 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 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 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/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef recvfrom
+
+int
+rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
+	      int *fromlen)
+{
+  int frombufsize = *fromlen;
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = recvfrom (sock, buf, len, flags, from, fromlen);
+
+  if (r < 0)
+    set_winsock_errno ();
+
+  /* Winsock recvfrom() only returns a valid 'from' when the socket is
+     connectionless.  POSIX gives a valid 'from' for all types of sockets.  */
+  else if (*fromlen == frombufsize)
+    rpl_getpeername (fd, from, fromlen);
+
+  return r;
+}
diff --git a/libmissing/ref-add.sin b/libmissing/ref-add.sin
new file mode 100644
index 0000000..3acdcc8
--- /dev/null
+++ b/libmissing/ref-add.sin
@@ -0,0 +1,30 @@
+# Add this package to a list of references stored in a text file.
+#
+#   Copyright (C) 2000 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, 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.
+#
+# Written by Bruno Haible <[email protected]>.
+#
+/^# Packages using this file: / {
+  s/# Packages using this file://
+  ta
+  :a
+  s/ @PACKAGE@ / @PACKAGE@ /
+  tb
+  s/ $/ @PACKAGE@ /
+  :b
+  s/^/# Packages using this file:/
+}
diff --git a/libmissing/ref-del.sin b/libmissing/ref-del.sin
new file mode 100644
index 0000000..7923d06
--- /dev/null
+++ b/libmissing/ref-del.sin
@@ -0,0 +1,25 @@
+# Remove this package from a list of references stored in a text file.
+#
+#   Copyright (C) 2000 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, 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.
+#
+# Written by Bruno Haible <[email protected]>.
+#
+/^# Packages using this file: / {
+  s/# Packages using this file://
+  s/ @PACKAGE@ / /
+  s/^/# Packages using this file:/
+}
diff --git a/libmissing/sigaction.c b/libmissing/sigaction.c
index a77dbf6..9727f58 100644
--- a/libmissing/sigaction.c
+++ b/libmissing/sigaction.c
@@ -64,6 +64,14 @@
 # define SIGSTOP (-1)
 #endif
 
+/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
+   for the signal SIGABRT.  Only one signal handler is stored for both
+   SIGABRT and SIGABRT_COMPAT.  SIGABRT_COMPAT is not a signal of its own.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef SIGABRT_COMPAT
+# define SIGABRT_COMPAT 6
+#endif
+
 /* A signal handler.  */
 typedef void (*handler_t) (int signal);
 
@@ -134,6 +142,11 @@ sigaction (int sig, const struct sigaction *restrict act,
       return -1;
     }
 
+  #ifdef SIGABRT_COMPAT
+  if (sig == SIGABRT_COMPAT)
+    sig = SIGABRT;
+  #endif
+
   /* POSIX requires sigaction() to be async-signal-safe.  In other
      words, if an asynchronous signal can occur while we are anywhere
      inside this function, the user's handler could then call
diff --git a/libmissing/signal.in.h b/libmissing/signal.in.h
index fbc88d9..6dc922d 100644
--- a/libmissing/signal.in.h
+++ b/libmissing/signal.in.h
@@ -1,6 +1,6 @@
 /* A GNU-like <signal.h>.
 
-   Copyright (C) 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2006-2009 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
@@ -15,7 +15,9 @@
    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 __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_sig_atomic_t || defined __need_sigset_t
 /* Special invocation convention inside glibc header files.  */
@@ -39,6 +41,15 @@
    Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.  */
 #include <sys/types.h>
 
+/* 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@
+typedef int rpl_sig_atomic_t;
+# undef sig_atomic_t
+# define sig_atomic_t rpl_sig_atomic_t
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -176,6 +187,12 @@ extern int sigaction (int, const struct sigaction *restrict,
 #endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
 
 
+/* Some systems don't have SA_NODEFER.  */
+#ifndef SA_NODEFER
+# define SA_NODEFER 0
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libmissing/sigprocmask.c b/libmissing/sigprocmask.c
index 2e66f24..b46d4f3 100644
--- a/libmissing/sigprocmask.c
+++ b/libmissing/sigprocmask.c
@@ -43,6 +43,19 @@
 # define SIGSTOP (-1)
 #endif
 
+/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
+   for the signal SIGABRT.  Only one signal handler is stored for both
+   SIGABRT and SIGABRT_COMPAT.  SIGABRT_COMPAT is not a signal of its own.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef SIGABRT_COMPAT
+# define SIGABRT_COMPAT 6
+#endif
+#ifdef SIGABRT_COMPAT
+# define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT)
+#else
+# define SIGABRT_COMPAT_MASK 0
+#endif
+
 typedef void (*handler_t) (int);
 
 /* Handling of gnulib defined signals.  */
@@ -74,7 +87,14 @@ int
 sigismember (const sigset_t *set, int sig)
 {
   if (sig >= 0 && sig < NSIG)
-    return (*set >> sig) & 1;
+    {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
+      return (*set >> sig) & 1;
+    }
   else
     return 0;
 }
@@ -91,6 +111,11 @@ sigaddset (sigset_t *set, int sig)
 {
   if (sig >= 0 && sig < NSIG)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       *set |= 1U << sig;
       return 0;
     }
@@ -106,6 +131,11 @@ sigdelset (sigset_t *set, int sig)
 {
   if (sig >= 0 && sig < NSIG)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       *set &= ~(1U << sig);
       return 0;
     }
@@ -116,10 +146,11 @@ sigdelset (sigset_t *set, int sig)
     }
 }
 
+
 int
 sigfillset (sigset_t *set)
 {
-  *set = (2U << (NSIG - 1)) - 1;
+  *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK;
   return 0;
 }
 
@@ -241,6 +272,11 @@ rpl_signal (int sig, handler_t handler)
   if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP
       && handler != SIG_ERR)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       if (blocked_set & (1U << sig))
 	{
 	  /* POSIX states that sigprocmask and signal are both
diff --git a/libmissing/socket.c b/libmissing/socket.c
new file mode 100644
index 0000000..9585309
--- /dev/null
+++ b/libmissing/socket.c
@@ -0,0 +1,43 @@
+/* socket.c --- wrappers for Windows socket function
+
+   Copyright (C) 2008 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 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 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/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+int
+rpl_socket (int domain, int type, int protocol)
+{
+  /* We have to use WSASocket() to create non-overlapped IO sockets.
+     Overlapped IO sockets cannot be used with read/write.  */
+  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+
+  if (fh == INVALID_SOCKET)
+    {
+      set_winsock_errno ();
+      return -1;
+    }
+  else
+    return SOCKET_TO_FD (fh);
+}
diff --git a/libmissing/stdint.in.h b/libmissing/stdint.in.h
index d0cbdac..11a2117 100644
--- a/libmissing/stdint.in.h
+++ b/libmissing/stdint.in.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2002, 2004-2008 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2002, 2004-2009 Free Software Foundation, Inc.
    Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
    This file is part of gnulib.
 
@@ -49,7 +49,9 @@
      in <inttypes.h> would reinclude us, skipping our contents because
      _GL_STDINT_H is defined.
      The include_next requires a split double-inclusion guard.  */
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 # @INCLUDE_NEXT@ @NEXT_STDINT_H@
 #endif
 
@@ -87,15 +89,6 @@
 # include <sys/bitypes.h>
 #endif
 
-#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
-
-/* Get WCHAR_MIN, WCHAR_MAX.  */
-# if ! (defined WCHAR_MIN && defined WCHAR_MAX)
-#  include <wchar.h>
-# endif
-
-#endif
-
 #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
 
 /* Minimum and maximum values for a integer type under the usual assumption.
@@ -120,46 +113,58 @@
 
 #undef int8_t
 #undef uint8_t
-#define int8_t signed char
-#define uint8_t unsigned char
+typedef signed char gl_int8_t;
+typedef unsigned char gl_uint8_t;
+#define int8_t gl_int8_t
+#define uint8_t gl_uint8_t
 
 #undef int16_t
 #undef uint16_t
-#define int16_t short int
-#define uint16_t unsigned short int
+typedef short int gl_int16_t;
+typedef unsigned short int gl_uint16_t;
+#define int16_t gl_int16_t
+#define uint16_t gl_uint16_t
 
 #undef int32_t
 #undef uint32_t
-#define int32_t int
-#define uint32_t unsigned int
+typedef int gl_int32_t;
+typedef unsigned int gl_uint32_t;
+#define int32_t gl_int32_t
+#define uint32_t gl_uint32_t
 
 /* Do not undefine int64_t if gnulib is not being used with 64-bit
    types, since otherwise it breaks platforms like Tandem/NSK.  */
 #if LONG_MAX >> 31 >> 31 == 1
 # undef int64_t
-# define int64_t long int
+typedef long int gl_int64_t;
+# define int64_t gl_int64_t
 # define GL_INT64_T
 #elif defined _MSC_VER
 # undef int64_t
-# define int64_t __int64
+typedef __int64 gl_int64_t;
+# define int64_t gl_int64_t
 # define GL_INT64_T
 #elif @HAVE_LONG_LONG_INT@
 # undef int64_t
-# define int64_t long long int
+typedef long long int gl_int64_t;
+# define int64_t gl_int64_t
 # define GL_INT64_T
 #endif
 
 #if ULONG_MAX >> 31 >> 31 >> 1 == 1
 # undef uint64_t
-# define uint64_t unsigned long int
+typedef unsigned long int gl_uint64_t;
+# define uint64_t gl_uint64_t
 # define GL_UINT64_T
 #elif defined _MSC_VER
 # undef uint64_t
-# define uint64_t unsigned __int64
+typedef unsigned __int64 gl_uint64_t;
+# define uint64_t gl_uint64_t
 # define GL_UINT64_T
 #elif @HAVE_UNSIGNED_LONG_LONG_INT@
 # undef uint64_t
-# define uint64_t unsigned long long int
+typedef unsigned long long int gl_uint64_t;
+# define uint64_t gl_uint64_t
 # define GL_UINT64_T
 #endif
 
@@ -214,12 +219,18 @@
 #undef uint_fast32_t
 #undef int_fast64_t
 #undef uint_fast64_t
-#define int_fast8_t long int
-#define uint_fast8_t unsigned int_fast8_t
-#define int_fast16_t long int
-#define uint_fast16_t unsigned int_fast16_t
-#define int_fast32_t long int
-#define uint_fast32_t unsigned int_fast32_t
+typedef long int gl_int_fast8_t;
+typedef unsigned long int gl_uint_fast8_t;
+typedef long int gl_int_fast16_t;
+typedef unsigned long int gl_uint_fast16_t;
+typedef long int gl_int_fast32_t;
+typedef unsigned long int gl_uint_fast32_t;
+#define int_fast8_t gl_int_fast8_t
+#define uint_fast8_t gl_uint_fast8_t
+#define int_fast16_t gl_int_fast16_t
+#define uint_fast16_t gl_uint_fast16_t
+#define int_fast32_t gl_int_fast32_t
+#define uint_fast32_t gl_uint_fast32_t
 #ifdef GL_INT64_T
 # define int_fast64_t int64_t
 #endif
@@ -231,8 +242,10 @@
 
 #undef intptr_t
 #undef uintptr_t
-#define intptr_t long int
-#define uintptr_t unsigned long int
+typedef long int gl_intptr_t;
+typedef unsigned long int gl_uintptr_t;
+#define intptr_t gl_intptr_t
+#define uintptr_t gl_uintptr_t
 
 /* 7.18.1.5. Greatest-width integer types */
 
@@ -241,20 +254,24 @@
 
 #undef intmax_t
 #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
-# define intmax_t long long int
+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 long int
+typedef long int gl_intmax_t;
+# define intmax_t gl_intmax_t
 #endif
 
 #undef uintmax_t
 #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
-# define uintmax_t unsigned long long int
+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 unsigned long int
+typedef unsigned long int gl_uintmax_t;
+# define uintmax_t gl_uintmax_t
 #endif
 
 /* Verify that intmax_t and uintmax_t have the same size.  Too much code
@@ -417,10 +434,20 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) -
 /* ptrdiff_t limits */
 #undef PTRDIFF_MIN
 #undef PTRDIFF_MAX
-#define PTRDIFF_MIN  \
-   _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
-#define PTRDIFF_MAX  \
-   _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
+#if @APPLE_UNIVERSAL_BUILD@
+# ifdef _LP64
+#  define PTRDIFF_MIN  _STDINT_MIN (1, 64, 0l)
+#  define PTRDIFF_MAX  _STDINT_MAX (1, 64, 0l)
+# else
+#  define PTRDIFF_MIN  _STDINT_MIN (1, 32, 0)
+#  define PTRDIFF_MAX  _STDINT_MAX (1, 32, 0)
+# endif
+#else
+# define PTRDIFF_MIN  \
+    _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
+# define PTRDIFF_MAX  \
+    _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
+#endif
 
 /* sig_atomic_t limits */
 #undef SIG_ATOMIC_MIN
@@ -435,9 +462,26 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) -
 
 /* size_t limit */
 #undef SIZE_MAX
-#define SIZE_MAX  _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
+#if @APPLE_UNIVERSAL_BUILD@
+# ifdef _LP64
+#  define SIZE_MAX  _STDINT_MAX (0, 64, 0ul)
+# else
+#  define SIZE_MAX  _STDINT_MAX (0, 32, 0ul)
+# endif
+#else
+# define SIZE_MAX  _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
+#endif
 
 /* wchar_t limits */
+/* Get WCHAR_MIN, WCHAR_MAX.
+   This include is not on the top, above, because on OSF/1 4.0 we have a sequence of nested
+   includes <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
+   <stdint.h> and assumes its types are already defined.  */
+#if ! (defined WCHAR_MIN && defined WCHAR_MAX)
+# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
+# include <wchar.h>
+# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
+#endif
 #undef WCHAR_MIN
 #undef WCHAR_MAX
 #define WCHAR_MIN  \
diff --git a/libmissing/stdio.in.h b/libmissing/stdio.in.h
index a99e678..ae681fc 100644
--- a/libmissing/stdio.in.h
+++ b/libmissing/stdio.in.h
@@ -1,6 +1,6 @@
 /* A GNU-like <stdio.h>.
 
-   Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007-2009 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
@@ -16,7 +16,9 @@
    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
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_FILE || defined __need___FILE
 /* Special invocation convention inside glibc header files.  */
@@ -214,6 +216,38 @@ extern int vsprintf (char *str, const char *format, va_list args)
      vsprintf (b, f, a))
 #endif
 
+#if @GNULIB_DPRINTF@
+# if @REPLACE_DPRINTF@
+#  define dprintf rpl_dprintf
+# endif
+# if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
+extern int dprintf (int fd, const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 2, 3)));
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef dprintf
+# define dprintf(d,f,a) \
+    (GL_LINK_WARNING ("dprintf is unportable - " \
+                      "use gnulib module dprintf for portability"), \
+     dprintf (d, f, a))
+#endif
+
+#if @GNULIB_VDPRINTF@
+# if @REPLACE_VDPRINTF@
+#  define vdprintf rpl_vdprintf
+# endif
+# if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
+extern int vdprintf (int fd, const char *format, va_list args)
+       __attribute__ ((__format__ (__printf__, 2, 0)));
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef vdprintf
+# define vdprintf(d,f,a) \
+    (GL_LINK_WARNING ("vdprintf is unportable - " \
+                      "use gnulib module vdprintf for portability"), \
+     vdprintf (d, f, a))
+#endif
+
 #if @GNULIB_VASPRINTF@
 # if @REPLACE_VASPRINTF@
 #  define asprintf rpl_asprintf
@@ -373,6 +407,24 @@ extern long rpl_ftell (FILE *fp);
     fflush (f))
 #endif
 
+#if @GNULIB_FPURGE@
+# if @REPLACE_FPURGE@
+#  define fpurge rpl_fpurge
+# endif
+# if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
+  /* Discard all pending buffered I/O data on STREAM.
+     STREAM must not be wide-character oriented.
+     Return 0 if successful.  Upon error, return -1 and set errno.  */
+  extern int fpurge (FILE *gl_stream);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fpurge
+# define fpurge(f) \
+   (GL_LINK_WARNING ("fpurge is not always present - " \
+                     "use gnulib module fpurge for portability"), \
+    fpurge (f))
+#endif
+
 #if @GNULIB_FCLOSE@
 # if @REPLACE_FCLOSE@
 #  define fclose rpl_fclose
diff --git a/libmissing/stdlib.in.h b/libmissing/stdlib.in.h
index 41ab70b..23325b5 100644
--- a/libmissing/stdlib.in.h
+++ b/libmissing/stdlib.in.h
@@ -1,6 +1,6 @@
 /* A GNU-like <stdlib.h>.
 
-   Copyright (C) 1995, 2001-2004, 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 1995, 2001-2004, 2006-2009 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
@@ -15,7 +15,9 @@
    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 __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_malloc_and_calloc
 /* Special invocation convention inside glibc header files.  */
@@ -34,6 +36,34 @@
 #define _GL_STDLIB_H
 
 
+/* Solaris declares getloadavg() in <sys/loadavg.h>.  */
+#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
+# include <sys/loadavg.h>
+#endif
+
+/* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
+   from <stdlib.h> if _REENTRANT is defined.  Include it always.  */
+#if @HAVE_RANDOM_H@
+# include <random.h>
+#endif
+
+#if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@
+# include <stdint.h>
+#endif
+
+#if !@HAVE_STRUCT_RANDOM_DATA@
+struct random_data
+{
+  int32_t *fptr;		/* Front pointer.  */
+  int32_t *rptr;		/* Rear pointer.  */
+  int32_t *state;		/* Array of state values.  */
+  int rand_type;		/* Type of random number generator.  */
+  int rand_deg;			/* Degree of random number generator.  */
+  int rand_sep;			/* Distance between front and rear.  */
+  int32_t *end_ptr;		/* Pointer behind state table.  */
+};
+#endif
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
@@ -101,6 +131,38 @@ extern void * calloc (size_t nmemb, size_t size);
 #endif
 
 
+#if @GNULIB_ATOLL@
+# if !@HAVE_ATOLL@
+/* Parse a signed decimal integer.
+   Returns the value of the integer.  Errors are not detected.  */
+extern long long atoll (const char *string);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef atoll
+# define atoll(s) \
+    (GL_LINK_WARNING ("atoll is unportable - " \
+                      "use gnulib module atoll for portability"), \
+     atoll (s))
+#endif
+
+
+#if @GNULIB_GETLOADAVG@
+# if !@HAVE_DECL_GETLOADAVG@
+/* Store max(NELEM,3) load average numbers in LOADAVG[].
+   The three numbers are the load average of the last 1 minute, the last 5
+   minutes, and the last 15 minutes, respectively.
+   LOADAVG is an array of NELEM numbers.  */
+extern int getloadavg (double loadavg[], int nelem);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getloadavg
+# define getloadavg(l,n) \
+    (GL_LINK_WARNING ("getloadavg is not portable - " \
+                      "use gnulib module getloadavg for portability"), \
+     getloadavg (l, n))
+#endif
+
+
 #if @GNULIB_GETSUBOPT@
 /* Assuming *OPTIONP is a comma separated list of elements of the form
    "token" or "token=value", getsubopt parses the first of these elements.
@@ -178,6 +240,43 @@ extern int putenv (char *string);
 #endif
 
 
+#if @GNULIB_RANDOM_R@
+# if !@HAVE_RANDOM_R@
+
+#  ifndef RAND_MAX
+#   define RAND_MAX 2147483647
+#  endif
+
+int srandom_r (unsigned int seed, struct random_data *rand_state);
+int initstate_r (unsigned int seed, char *buf, size_t buf_size,
+		 struct random_data *rand_state);
+int setstate_r (char *arg_state, struct random_data *rand_state);
+int random_r (struct random_data *buf, int32_t *result);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef random_r
+# define random_r(b,r)				  \
+    (GL_LINK_WARNING ("random_r is unportable - " \
+                      "use gnulib module random_r for portability"), \
+     random_r (b,r))
+# undef initstate_r
+# define initstate_r(s,b,sz,r)			     \
+    (GL_LINK_WARNING ("initstate_r is unportable - " \
+                      "use gnulib module random_r for portability"), \
+     initstate_r (s,b,sz,r))
+# undef srandom_r
+# define srandom_r(s,r)				   \
+    (GL_LINK_WARNING ("srandom_r is unportable - " \
+                      "use gnulib module random_r for portability"), \
+     srandom_r (s,r))
+# undef setstate_r
+# define setstate_r(a,r)				    \
+    (GL_LINK_WARNING ("setstate_r is unportable - " \
+                      "use gnulib module random_r for portability"), \
+     setstate_r (a,r))
+#endif
+
+
 #if @GNULIB_RPMATCH@
 # if !@HAVE_RPMATCH@
 /* Test a user response to a question.
@@ -233,6 +332,48 @@ extern double strtod (const char *str, char **endp);
 #endif
 
 
+#if @GNULIB_STRTOLL@
+# if !@HAVE_STRTOLL@
+/* Parse a signed integer whose textual representation starts at STRING.
+   The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
+   it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
+   "0x").
+   If ENDPTR is not NULL, the address of the first byte after the integer is
+   stored in *ENDPTR.
+   Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
+   to ERANGE.  */
+extern long long strtoll (const char *string, char **endptr, int base);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strtoll
+# define strtoll(s,e,b) \
+    (GL_LINK_WARNING ("strtoll is unportable - " \
+                      "use gnulib module strtoll for portability"), \
+     strtoll (s, e, b))
+#endif
+
+
+#if @GNULIB_STRTOULL@
+# if !@HAVE_STRTOULL@
+/* Parse an unsigned integer whose textual representation starts at STRING.
+   The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
+   it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
+   "0x").
+   If ENDPTR is not NULL, the address of the first byte after the integer is
+   stored in *ENDPTR.
+   Upon overflow, the return value is ULLONG_MAX, and errno is set to
+   ERANGE.  */
+extern unsigned long long strtoull (const char *string, char **endptr, int base);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strtoull
+# define strtoull(s,e,b) \
+    (GL_LINK_WARNING ("strtoull is unportable - " \
+                      "use gnulib module strtoull for portability"), \
+     strtoull (s, e, b))
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libmissing/strdup.c b/libmissing/strdup.c
deleted file mode 100644
index e4067c0..0000000
--- a/libmissing/strdup.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007 Free
-   Software Foundation, Inc.
-
-   This file is part of the GNU C Library.
-
-   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, 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 _LIBC
-# include <config.h>
-#endif
-
-/* Get specification.  */
-#include <string.h>
-
-#include <stdlib.h>
-
-#undef __strdup
-#ifdef _LIBC
-# undef strdup
-#endif
-
-#ifndef weak_alias
-# define __strdup strdup
-#endif
-
-/* Duplicate S, returning an identical malloc'd string.  */
-char *
-__strdup (const char *s)
-{
-  size_t len = strlen (s) + 1;
-  void *new = malloc (len);
-
-  if (new == NULL)
-    return NULL;
-
-  return (char *) memcpy (new, s, len);
-}
-#ifdef libc_hidden_def
-libc_hidden_def (__strdup)
-#endif
-#ifdef weak_alias
-weak_alias (__strdup, strdup)
-#endif
diff --git a/libmissing/streq.h b/libmissing/streq.h
new file mode 100644
index 0000000..1b4b1c5
--- /dev/null
+++ b/libmissing/streq.h
@@ -0,0 +1,176 @@
+/* Optimized string comparison.
+   Copyright (C) 2001-2002, 2007 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 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
+   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/>.  */
+
+/* Written by Bruno Haible <[email protected]>.  */
+
+#ifndef _GL_STREQ_H
+#define _GL_STREQ_H
+
+#include <string.h>
+
+/* STREQ allows to optimize string comparison with a small literal string.
+     STREQ (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+   is semantically equivalent to
+     strcmp (s, "EUC-KR") == 0
+   just faster.  */
+
+/* Help GCC to generate good code for string comparisons with
+   immediate strings. */
+#if defined (__GNUC__) && defined (__OPTIMIZE__)
+
+static inline int
+streq9 (const char *s1, const char *s2)
+{
+  return strcmp (s1 + 9, s2 + 9) == 0;
+}
+
+static inline int
+streq8 (const char *s1, const char *s2, char s28)
+{
+  if (s1[8] == s28)
+    {
+      if (s28 == 0)
+        return 1;
+      else
+        return streq9 (s1, s2);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq7 (const char *s1, const char *s2, char s27, char s28)
+{
+  if (s1[7] == s27)
+    {
+      if (s27 == 0)
+        return 1;
+      else
+        return streq8 (s1, s2, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
+{
+  if (s1[6] == s26)
+    {
+      if (s26 == 0)
+        return 1;
+      else
+        return streq7 (s1, s2, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
+{
+  if (s1[5] == s25)
+    {
+      if (s25 == 0)
+        return 1;
+      else
+        return streq6 (s1, s2, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
+{
+  if (s1[4] == s24)
+    {
+      if (s24 == 0)
+        return 1;
+      else
+        return streq5 (s1, s2, s25, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+  if (s1[3] == s23)
+    {
+      if (s23 == 0)
+        return 1;
+      else
+        return streq4 (s1, s2, s24, s25, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+  if (s1[2] == s22)
+    {
+      if (s22 == 0)
+        return 1;
+      else
+        return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+  if (s1[1] == s21)
+    {
+      if (s21 == 0)
+        return 1;
+      else
+        return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+static inline int
+streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+  if (s1[0] == s20)
+    {
+      if (s20 == 0)
+        return 1;
+      else
+        return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
+    }
+  else
+    return 0;
+}
+
+#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+  streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
+
+#else
+
+#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+  (strcmp (s1, s2) == 0)
+
+#endif
+
+#endif /* _GL_STREQ_H */
diff --git a/libmissing/string.in.h b/libmissing/string.in.h
index 0d8b095..fe11425 100644
--- a/libmissing/string.in.h
+++ b/libmissing/string.in.h
@@ -1,6 +1,6 @@
 /* A GNU-like <string.h>.
 
-   Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 2001-2009 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
@@ -18,7 +18,9 @@
 
 #ifndef _GL_STRING_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_STRING_H@
@@ -47,6 +49,21 @@ extern "C" {
 #endif
 
 
+/* Return the first instance of C within N bytes of S, or NULL.  */
+#if @GNULIB_MEMCHR@
+# if @REPLACE_MEMCHR@
+#  define memchr rpl_memchr
+extern void *memchr (void const *__s, int __c, size_t __n)
+  __attribute__ ((__pure__));
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef memchr
+# define memchr(s,c,n) \
+    (GL_LINK_WARNING ("memchr has platform-specific bugs - " \
+                      "use gnulib module memchr for portability" ), \
+     memchr (s, c, n))
+#endif
+
 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
 #if @GNULIB_MEMMEM@
 # if @REPLACE_MEMMEM@
diff --git a/libmissing/strings.in.h b/libmissing/strings.in.h
index 7344d60..bd767de 100644
--- a/libmissing/strings.in.h
+++ b/libmissing/strings.in.h
@@ -18,7 +18,9 @@
 
 #ifndef _GL_STRINGS_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_STRINGS_H@
diff --git a/libmissing/strnlen1.c b/libmissing/strnlen1.c
new file mode 100644
index 0000000..0b678e9
--- /dev/null
+++ b/libmissing/strnlen1.c
@@ -0,0 +1,35 @@
+/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
+   Copyright (C) 2005-2006 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 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 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 "strnlen1.h"
+
+#include <string.h>
+
+/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
+   If no '\0' terminator is found in that many characters, return MAXLEN.  */
+/* This is the same as strnlen (string, maxlen - 1) + 1.  */
+size_t
+strnlen1 (const char *string, size_t maxlen)
+{
+  const char *end = (const char *) memchr (string, '\0', maxlen);
+  if (end != NULL)
+    return end - string + 1;
+  else
+    return maxlen;
+}
diff --git a/libmissing/strnlen1.h b/libmissing/strnlen1.h
new file mode 100644
index 0000000..1171781
--- /dev/null
+++ b/libmissing/strnlen1.h
@@ -0,0 +1,39 @@
+/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
+   Copyright (C) 2005 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 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 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/>.  */
+
+#ifndef _STRNLEN1_H
+#define _STRNLEN1_H
+
+#include <stddef.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
+   If no '\0' terminator is found in that many characters, return MAXLEN.  */
+/* This is the same as strnlen (string, maxlen - 1) + 1.  */
+extern size_t strnlen1 (const char *string, size_t maxlen);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _STRNLEN1_H */
diff --git a/libmissing/strpbrk.c b/libmissing/strpbrk.c
deleted file mode 100644
index 08de115..0000000
--- a/libmissing/strpbrk.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Copyright (C) 1991, 1994, 2000, 2002-2003, 2006 Free Software
-   Foundation, Inc.
-
-   NOTE: The canonical source of this file is maintained with the GNU C Library.
-   Bugs can be reported to [email protected].
-
-   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, 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>
-
-#include <stddef.h>
-#include <string.h>
-
-#undef strpbrk
-
-/* Find the first occurrence in S of any character in ACCEPT.  */
-char *
-strpbrk (const char *s, const char *accept)
-{
-  while (*s != '\0')
-    {
-      const char *a = accept;
-      while (*a != '\0')
-	if (*a++ == *s)
-	  return (char *) s;
-      ++s;
-    }
-
-  return NULL;
-}
diff --git a/libmissing/sys_select.in.h b/libmissing/sys_select.in.h
index f92353f..e80db7b 100644
--- a/libmissing/sys_select.in.h
+++ b/libmissing/sys_select.in.h
@@ -1,5 +1,5 @@
 /* Substitute for <sys/select.h>.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 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
@@ -15,12 +15,28 @@
    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
+@PRAGMA_SYSTEM_HEADER@
+# endif
+
+/* On OSF/1, <sys/types.h> and <sys/time.h> include <sys/select.h>.
+   Simply delegate to the system's header in this case.  */
+#if @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TYPES_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H) && defined _OSF_SOURCE
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#elif @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TIME_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H) && defined _OSF_SOURCE
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#else
+
 #ifndef _GL_SYS_SELECT_H
 
 #if @HAVE_SYS_SELECT_H@
 
-@PRAGMA_SYSTEM_HEADER@
-
 /* On many platforms, <sys/select.h> assumes prior inclusion of
    <sys/types.h>.  */
 # include <sys/types.h>
@@ -50,7 +66,7 @@ extern "C" {
 # endif
 
 # if @GNULIB_SELECT@
-#  if @HAVE_WINSOCK2_H@
+#  if @HAVE_WINSOCK2_H@ || @REPLACE_SELECT@
 #   undef select
 #   define select rpl_select
 extern int rpl_select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
@@ -74,3 +90,4 @@ extern int rpl_select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
 
 #endif /* _GL_SYS_SELECT_H */
 #endif /* _GL_SYS_SELECT_H */
+#endif /* OSF/1 */
diff --git a/libmissing/sys_socket.in.h b/libmissing/sys_socket.in.h
index 84acdb2..67b926e 100644
--- a/libmissing/sys_socket.in.h
+++ b/libmissing/sys_socket.in.h
@@ -1,6 +1,6 @@
 /* Provide a sys/socket header file for systems lacking it (read: MinGW)
    and for systems where it is incomplete.
-   Copyright (C) 2005-2008 Free Software Foundation, Inc.
+   Copyright (C) 2005-2009 Free Software Foundation, Inc.
    Written by Simon Josefsson.
 
    This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,9 @@
 
 #if @HAVE_SYS_SOCKET_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* On many platforms, <sys/socket.h> assumes prior inclusion of
    <sys/types.h>.  */
@@ -41,6 +43,30 @@
 #ifndef _GL_SYS_SOCKET_H
 #define _GL_SYS_SOCKET_H
 
+#if !@HAVE_SA_FAMILY_T@
+typedef unsigned short  sa_family_t;
+#endif
+
+#if !@HAVE_STRUCT_SOCKADDR_STORAGE@
+# include <alignof.h>
+/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
+   2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
+# define __ss_aligntype unsigned long int
+# define _SS_SIZE 256
+# define _SS_PADSIZE \
+    (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype)	\
+		  ? sizeof (sa_family_t)				\
+		  : alignof (__ss_aligntype))				\
+		 + sizeof (__ss_aligntype)))
+
+struct sockaddr_storage
+{
+  sa_family_t ss_family;      /* Address family, etc.  */
+  __ss_aligntype __ss_align;  /* Force desired alignment.  */
+  char __ss_padding[_SS_PADSIZE];
+};
+#endif
+
 #if @HAVE_SYS_SOCKET_H@
 
 /* A platform that has <sys/socket.h>.  */
@@ -118,9 +144,9 @@ extern "C" {
 /* Re-define FD_ISSET to avoid a WSA call while we are not using
    network sockets.  */
 static inline int
-rpl_fd_isset (int fd, fd_set * set)
+rpl_fd_isset (SOCKET fd, fd_set * set)
 {
-  int i;
+  u_int i;
   if (set == NULL)
     return 0;
 
@@ -143,6 +169,11 @@ rpl_fd_isset (int fd, fd_set * set)
 #  define close close_used_without_including_unistd_h
 # endif
 
+# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
+#  undef gethostname
+#  define gethostname gethostname_used_without_including_unistd_h
+# endif
+
 # if @GNULIB_SOCKET@
 #  if @HAVE_WINSOCK2_H@
 #   undef socket
@@ -249,7 +280,7 @@ extern int rpl_getsockname (int, struct sockaddr *, int *);
 #  if @HAVE_WINSOCK2_H@
 #   undef getsockopt
 #   define getsockopt		rpl_getsockopt
-extern int rpl_getsockopt (int, int, int, void *, int *);
+extern int rpl_getsockopt (int, int, int, void *, socklen_t *);
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef getsockopt
@@ -351,7 +382,7 @@ extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int);
 #  if @HAVE_WINSOCK2_H@
 #   undef setsockopt
 #   define setsockopt		rpl_setsockopt
-extern int rpl_setsockopt (int, int, int, const void *, int);
+extern int rpl_setsockopt (int, int, int, const void *, socklen_t);
 #  endif
 # elif @HAVE_WINSOCK2_H@
 #  undef setsockopt
@@ -386,12 +417,6 @@ extern int rpl_shutdown (int, int);
 #  define select		select_used_without_including_sys_select_h
 # endif
 
-# if @GNULIB_CLOSE@ && @HAVE_WINSOCK2_H@
-/* gnulib internal function.  */
-#  define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
-extern int _gl_close_fd_maybe_socket (int fd);
-# endif
-
 # ifdef __cplusplus
 }
 # endif
diff --git a/libmissing/sys_stat.in.h b/libmissing/sys_stat.in.h
index 6f300c0..270fce5 100644
--- a/libmissing/sys_stat.in.h
+++ b/libmissing/sys_stat.in.h
@@ -1,5 +1,5 @@
 /* Provide a more complete sys/stat header file.
-   Copyright (C) 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2005-2009 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
@@ -21,9 +21,22 @@
    incomplete.  It is intended to provide definitions and prototypes
    needed by an application.  Start with what the system provides.  */
 
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+#if defined __need_system_sys_stat_h
+/* Special invocation convention.  */
+
+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
+
+#else
+/* Normal invocation convention.  */
+
 #ifndef _GL_SYS_STAT_H
 
-@PRAGMA_SYSTEM_HEADER@
+/* Get nlink_t.  */
+#include <sys/types.h>
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
@@ -31,6 +44,8 @@
 #ifndef _GL_SYS_STAT_H
 #define _GL_SYS_STAT_H
 
+/* The definition of GL_LINK_WARNING is copied here.  */
+
 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
    headers that may declare mkdir().  */
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
@@ -263,12 +278,31 @@
 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
 #endif
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_LSTAT@
+# if ! @HAVE_LSTAT@
 /* mingw does not support symlinks, therefore it does not have lstat.  But
    without links, stat does just fine.  */
-#if ! @HAVE_LSTAT@
-# define lstat stat
+#  define lstat stat
+# elif @REPLACE_LSTAT@
+#  undef lstat
+#  define lstat rpl_lstat
+extern int rpl_lstat (const char *name, struct stat *buf);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lstat
+# define lstat(p,b)							\
+  (GL_LINK_WARNING ("lstat is unportable - "				\
+		    "use gnulib module lstat for portability"),		\
+   lstat (p, b))
 #endif
 
+
 #if @REPLACE_MKDIR@
 # undef mkdir
 # define mkdir rpl_mkdir
@@ -289,5 +323,39 @@ rpl_mkdir (char const *name, mode_t mode)
 # endif
 #endif
 
+
+/* Declare BSD extensions.  */
+
+#if @GNULIB_LCHMOD@
+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
+   denotes a symbolic link.  */
+# if !@HAVE_LCHMOD@
+/* The lchmod replacement follows symbolic links.  Callers should take
+   this into account; lchmod should be applied only to arguments that
+   are known to not be symbolic links.  On hosts that lack lchmod,
+   this can lead to race conditions between the check and the
+   invocation of lchmod, but we know of no workarounds that are
+   reliable in general.  You might try requesting support for lchmod
+   from your operating system supplier.  */
+#  define lchmod chmod
+# endif
+# if 0 /* assume already declared */
+extern int lchmod (const char *filename, mode_t mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lchmod
+# define lchmod(f,m) \
+    (GL_LINK_WARNING ("lchmod is unportable - " \
+                      "use gnulib module lchmod for portability"), \
+     lchmod (f, m))
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif /* _GL_SYS_STAT_H */
 #endif /* _GL_SYS_STAT_H */
+#endif
diff --git a/libmissing/sys_time.in.h b/libmissing/sys_time.in.h
index e93e75e..44f9b59 100644
--- a/libmissing/sys_time.in.h
+++ b/libmissing/sys_time.in.h
@@ -18,7 +18,9 @@
 
 /* Written by Paul Eggert.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined _GL_SYS_TIME_H
 
@@ -37,6 +39,10 @@
 #  include <time.h>
 # endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 # if ! @HAVE_STRUCT_TIMEVAL@
 struct timeval
 {
@@ -51,4 +57,8 @@ struct timeval
 int gettimeofday (struct timeval *restrict, void *restrict);
 # endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _GL_SYS_TIME_H */
diff --git a/libmissing/tests/Makefile.am b/libmissing/tests/Makefile.am
index f429a55..5da2f84 100644
--- a/libmissing/tests/Makefile.am
+++ b/libmissing/tests/Makefile.am
@@ -1,6 +1,6 @@
 ## DO NOT EDIT! GENERATED AUTOMATICALLY!
 ## Process this file with automake to produce Makefile.in.
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 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
@@ -42,6 +42,15 @@ libtests_a_DEPENDENCIES = $(gltests_LIBOBJS)
 EXTRA_libtests_a_SOURCES =
 AM_LIBTOOLFLAGS = --preserve-dup-deps
 
+## begin gnulib module alignof-tests
+
+TESTS += test-alignof
+check_PROGRAMS += test-alignof
+
+EXTRA_DIST += test-alignof.c
+
+## end   gnulib module alignof-tests
+
 ## begin gnulib module alloca-opt-tests
 
 TESTS += test-alloca-opt
@@ -69,16 +78,32 @@ EXTRA_DIST += test-errno.c
 
 ## end   gnulib module errno-tests
 
+## begin gnulib module fnmatch-tests
+
+TESTS += test-fnmatch
+check_PROGRAMS += test-fnmatch
+EXTRA_DIST += test-fnmatch.c
+
+## end   gnulib module fnmatch-tests
+
 ## begin gnulib module getaddrinfo-tests
 
 TESTS += test-getaddrinfo
 check_PROGRAMS += test-getaddrinfo
-test_getaddrinfo_LDADD = $(LDADD) @LIBINTL@
+test_getaddrinfo_LDADD = $(LDADD) @GETADDRINFO_LIB@ @LIBINTL@
 
 EXTRA_DIST += test-getaddrinfo.c
 
 ## end   gnulib module getaddrinfo-tests
 
+## begin gnulib module glob-tests
+
+TESTS += test-glob
+check_PROGRAMS += test-glob
+EXTRA_DIST += test-glob.c
+
+## end   gnulib module glob-tests
+
 ## begin gnulib module intprops
 
 
@@ -86,6 +111,63 @@ EXTRA_DIST += intprops.h
 
 ## end   gnulib module intprops
 
+## begin gnulib module mbrtowc-tests
+
+TESTS += test-mbrtowc1.sh test-mbrtowc2.sh test-mbrtowc3.sh test-mbrtowc4.sh
+TESTS_ENVIRONMENT += \
+  EXEEXT='@EXEEXT@' \
+  LOCALE_FR='@LOCALE_FR@' \
+  LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
+  LOCALE_JA='@LOCALE_JA@' \
+  LOCALE_ZH_CN='@LOCALE_ZH_CN@'
+check_PROGRAMS += test-mbrtowc
+
+EXTRA_DIST += test-mbrtowc1.sh test-mbrtowc2.sh test-mbrtowc3.sh test-mbrtowc4.sh test-mbrtowc.c
+
+## end   gnulib module mbrtowc-tests
+
+## begin gnulib module mbsinit-tests
+
+TESTS += test-mbsinit.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
+check_PROGRAMS += test-mbsinit
+
+EXTRA_DIST += test-mbsinit.sh test-mbsinit.c
+
+## end   gnulib module mbsinit-tests
+
+## begin gnulib module mbsrtowcs-tests
+
+TESTS += test-mbsrtowcs1.sh test-mbsrtowcs2.sh test-mbsrtowcs3.sh test-mbsrtowcs4.sh
+TESTS_ENVIRONMENT += \
+  EXEEXT='@EXEEXT@' \
+  LOCALE_FR='@LOCALE_FR@' \
+  LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
+  LOCALE_JA='@LOCALE_JA@' \
+  LOCALE_ZH_CN='@LOCALE_ZH_CN@'
+check_PROGRAMS += test-mbsrtowcs
+
+EXTRA_DIST += test-mbsrtowcs1.sh test-mbsrtowcs2.sh test-mbsrtowcs3.sh test-mbsrtowcs4.sh test-mbsrtowcs.c
+
+## end   gnulib module mbsrtowcs-tests
+
+## begin gnulib module memchr-tests
+
+TESTS += test-memchr
+check_PROGRAMS += test-memchr
+EXTRA_DIST += test-memchr.c zerosize-ptr.h
+
+## end   gnulib module memchr-tests
+
+## begin gnulib module netdb-tests
+
+TESTS += test-netdb
+check_PROGRAMS += test-netdb
+
+EXTRA_DIST += test-netdb.c
+
+## end   gnulib module netdb-tests
+
 ## begin gnulib module netinet_in-tests
 
 TESTS += test-netinet_in
@@ -103,6 +185,15 @@ EXTRA_DIST += test-sigaction.c
 
 ## end   gnulib module sigaction-tests
 
+## begin gnulib module signal-tests
+
+TESTS += test-signal
+check_PROGRAMS += test-signal
+
+EXTRA_DIST += test-signal.c
+
+## end   gnulib module signal-tests
+
 ## begin gnulib module sleep-tests
 
 TESTS += test-sleep
@@ -157,6 +248,23 @@ EXTRA_DIST += test-stdlib.c
 
 ## end   gnulib module stdlib-tests
 
+## begin gnulib module strerror
+
+
+EXTRA_DIST += strerror.c
+
+EXTRA_libtests_a_SOURCES += strerror.c
+
+## end   gnulib module strerror
+
+## begin gnulib module strerror-tests
+
+TESTS += test-strerror
+check_PROGRAMS += test-strerror
+EXTRA_DIST += test-strerror.c
+
+## end   gnulib module strerror-tests
+
 ## begin gnulib module string-tests
 
 TESTS += test-string
@@ -238,12 +346,6 @@ EXTRA_DIST += test-vasnprintf.c
 
 ## end   gnulib module vasnprintf-tests
 
-## begin gnulib module verify
-
-libtests_a_SOURCES += verify.h
-
-## end   gnulib module verify
-
 ## begin gnulib module wchar-tests
 
 TESTS += test-wchar
@@ -253,6 +355,15 @@ EXTRA_DIST += test-wchar.c
 
 ## end   gnulib module wchar-tests
 
+## begin gnulib module wctob
+
+
+EXTRA_DIST += wctob.c
+
+EXTRA_libtests_a_SOURCES += wctob.c
+
+## end   gnulib module wctob
+
 ## begin gnulib module wctype-tests
 
 TESTS += test-wctype
@@ -279,5 +390,3 @@ mostlyclean-local: mostlyclean-generic
 	  fi; \
 	done; \
 	:
-
--include $(top_srcdir)/git.mk
diff --git a/libmissing/tests/strerror.c b/libmissing/tests/strerror.c
new file mode 100644
index 0000000..dfe6c25
--- /dev/null
+++ b/libmissing/tests/strerror.c
@@ -0,0 +1,347 @@
+/* strerror.c --- POSIX compatible system error routine
+
+   Copyright (C) 2007-2009 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 <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 "intprops.h"
+
+# undef strerror
+# if ! HAVE_DECL_STRERROR
+#  define strerror(n) NULL
+# endif
+
+char *
+rpl_strerror (int n)
+{
+  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_ECANCELED
+    case ECANCELED:
+      msg = "Operation canceled";
+      break;
+# endif
+    }
+
+  if (msg)
+    return (char *) msg;
+
+  {
+    char *result = 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;
+      }
+
+    return result;
+  }
+}
+
+#endif
diff --git a/libmissing/tests/test-alignof.c b/libmissing/tests/test-alignof.c
new file mode 100644
index 0000000..d42bdf5
--- /dev/null
+++ b/libmissing/tests/test-alignof.c
@@ -0,0 +1,59 @@
+/* Test of <alignof.h>.
+   Copyright (C) 2009 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 <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <alignof.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "verify.h"
+
+typedef long double longdouble;
+typedef struct { char a[1]; } struct1;
+typedef struct { char a[2]; } struct2;
+typedef struct { char a[3]; } struct3;
+typedef struct { char a[4]; } struct4;
+
+#define CHECK(type) \
+  typedef struct { char slot1; type slot2; } type##_helper; \
+  verify (alignof_slot (type) == offsetof (type##_helper, slot2)); \
+  const int type##_slot_alignment = alignof_slot (type); \
+  const int type##_type_alignment = alignof_type (type);
+
+CHECK (char)
+CHECK (short)
+CHECK (int)
+CHECK (long)
+CHECK (float)
+CHECK (double)
+CHECK (longdouble)
+#ifdef INT64_MAX
+CHECK (int64_t)
+#endif
+CHECK (struct1)
+CHECK (struct2)
+CHECK (struct3)
+CHECK (struct4)
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/libmissing/tests/test-fnmatch.c b/libmissing/tests/test-fnmatch.c
new file mode 100644
index 0000000..9d0aaae
--- /dev/null
+++ b/libmissing/tests/test-fnmatch.c
@@ -0,0 +1,61 @@
+/* Test of fnmatch string matching function.
+   Copyright (C) 2009 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 <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <fnmatch.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ASSERT(expr)							\
+  do									\
+    {									\
+      if (!(expr))							\
+	{								\
+	  fprintf (stderr, "%s:%d: assertion failed\n",			\
+		   __FILE__, __LINE__);					\
+	  fflush (stderr);						\
+	  abort ();							\
+	}								\
+    }									\
+  while (0)
+
+int
+main ()
+{
+  int res;
+
+  ASSERT (res = fnmatch ("", "", 0) == 0);
+
+  ASSERT (res = fnmatch ("*", "", 0) == 0);
+  ASSERT (res = fnmatch ("*", "foo", 0) == 0);
+  ASSERT (res = fnmatch ("*", "bar", 0) == 0);
+  ASSERT (res = fnmatch ("*", "*", 0) == 0);
+  ASSERT (res = fnmatch ("**", "f", 0) == 0);
+  ASSERT (res = fnmatch ("**", "foo.txt", 0) == 0);
+  ASSERT (res = fnmatch ("*.*", "foo.txt", 0) == 0);
+
+  ASSERT (res = fnmatch ("foo*.txt", "foobar.txt", 0) == 0);
+
+  ASSERT (res = fnmatch ("foo.txt", "foo.txt", 0) == 0);
+  ASSERT (res = fnmatch ("foo\\.txt", "foo.txt", 0) == 0);
+  ASSERT (res = fnmatch ("foo\\.txt", "foo.txt", FNM_NOESCAPE) == FNM_NOMATCH);
+
+  return 0;
+}
diff --git a/libmissing/tests/test-getaddrinfo.c b/libmissing/tests/test-getaddrinfo.c
index bfdb9cf..eeea3f7 100644
--- a/libmissing/tests/test-getaddrinfo.c
+++ b/libmissing/tests/test-getaddrinfo.c
@@ -1,6 +1,6 @@
 /* Test the getaddrinfo module.
 
-   Copyright (C) 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2006-2009 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
@@ -18,8 +18,10 @@
 /* Written by Simon Josefsson.  */
 
 #include <config.h>
-#include "getaddrinfo.h"
+#include <netdb.h>
+
 #include <arpa/inet.h>
+#include <errno.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>
@@ -45,9 +47,15 @@
 int simple (char *host, char *service)
 {
   char buf[BUFSIZ];
+  static int skip = 0;
   struct addrinfo hints;
   struct addrinfo *ai0, *ai;
   int res;
+  int err;
+
+  /* Once we skipped the test, do not try anything else */
+  if (skip)
+    return 0;
 
   dbgprintf ("Finding %s service %s...\n", host, service);
 
@@ -59,23 +67,36 @@ int simple (char *host, char *service)
   hints.ai_socktype = SOCK_STREAM;
 
   res = getaddrinfo (host, service, 0, &ai0);
+  err = errno;
 
   dbgprintf ("res %d: %s\n", res, gai_strerror (res));
 
   if (res != 0)
     {
+      /* EAI_AGAIN is returned if no network is available. Don't fail
+	 the test merely because someone is down the country on their
+	 in-law's farm. */
+      if (res == EAI_AGAIN)
+	{
+	  skip++;
+	  fprintf (stderr, "skipping getaddrinfo test: no network?\n");
+	  return 77;
+	}
       /* IRIX reports EAI_NONAME for "https".  Don't fail the test
 	 merely because of this.  */
       if (res == EAI_NONAME)
 	return 0;
       /* Solaris reports EAI_SERVICE for "http" and "https".  Don't
-         fail the test merely because of this.  */
+	 fail the test merely because of this.  */
       if (res == EAI_SERVICE)
 	return 0;
       /* AIX reports EAI_NODATA for "https".  Don't fail the test
 	 merely because of this.  */
       if (res == EAI_NODATA)
 	return 0;
+      /* Provide details if errno was set.  */
+      if (res == EAI_SYSTEM)
+	dbgprintf ("system error: %s\n", strerror (err));
 
       return 1;
     }
diff --git a/libmissing/tests/test-glob.c b/libmissing/tests/test-glob.c
new file mode 100644
index 0000000..fc5ec30
--- /dev/null
+++ b/libmissing/tests/test-glob.c
@@ -0,0 +1,85 @@
+/* Test of glob/globfree functions.
+   Copyright (C) 2009 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 <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <glob.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(expr)							\
+  do									\
+    {									\
+      if (!(expr))							\
+	{								\
+	  fprintf (stderr, "%s:%d: assertion failed\n",			\
+		   __FILE__, __LINE__);					\
+	  fflush (stderr);						\
+	  abort ();							\
+	}								\
+    }									\
+  while (0)
+
+#define GL_NO_SUCH_FILE "/gnulib-magic-does-not-exist"
+
+int
+main ()
+{
+  int res;
+  glob_t g;
+
+  /* Make sure glob_t struct members exists. */
+  ASSERT (sizeof (g.gl_pathc));
+  ASSERT (sizeof (g.gl_pathv));
+  ASSERT (sizeof (g.gl_offs));
+
+  res = glob (".", 0, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 1);
+  globfree (&g);
+
+  res = glob (".", GLOB_NOSORT, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 1);
+  globfree (&g);
+
+  res = glob (".", GLOB_MARK, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 1);
+
+  res = glob (".", GLOB_APPEND, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 2);
+  globfree (&g);
+
+  res = glob (".", GLOB_NOESCAPE, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 1);
+  globfree (&g);
+
+  res = glob ("./*", 0, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc >= 1);
+  globfree (&g);
+
+  res = glob (GL_NO_SUCH_FILE, 0, NULL, &g);
+  ASSERT (res == GLOB_NOMATCH);
+
+  res = glob (GL_NO_SUCH_FILE, GLOB_NOCHECK, NULL, &g);
+  ASSERT (res == 0 && g.gl_pathc == 1);
+  ASSERT (strcmp (g.gl_pathv[0], GL_NO_SUCH_FILE) == 0);
+  globfree (&g);
+
+  return 0;
+}
diff --git a/libmissing/tests/test-mbrtowc.c b/libmissing/tests/test-mbrtowc.c
new file mode 100644
index 0000000..8f1f1be
--- /dev/null
+++ b/libmissing/tests/test-mbrtowc.c
@@ -0,0 +1,330 @@
+/* Test of conversion of multibyte character to wide character.
+   Copyright (C) 2008 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 <[email protected]>, 2008.  */
+
+#include <config.h>
+
+#include <wchar.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+        {								     \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          fflush (stderr);						     \
+          abort ();							     \
+        }								     \
+    }									     \
+  while (0)
+
+int
+main (int argc, char *argv[])
+{
+  mbstate_t state;
+  wchar_t wc;
+  size_t ret;
+
+  /* configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Test zero-length input.  */
+  {
+    memset (&state, '\0', sizeof (mbstate_t));
+    wc = (wchar_t) 0xBADFACE;
+    ret = mbrtowc (&wc, "x", 0, &state);
+    /* gnulib's implementation returns (size_t)(-2).
+       The AIX 5.1 implementation returns (size_t)(-1).
+       glibc's implementation returns 0.  */
+    ASSERT (ret == (size_t)(-2) || ret == (size_t)(-1) || ret == 0);
+    ASSERT (mbsinit (&state));
+  }
+
+  /* Test NUL byte input.  */
+  {
+    memset (&state, '\0', sizeof (mbstate_t));
+    wc = (wchar_t) 0xBADFACE;
+    ret = mbrtowc (&wc, "", 1, &state);
+    ASSERT (ret == 0);
+    ASSERT (wc == 0);
+    ASSERT (mbsinit (&state));
+    ret = mbrtowc (NULL, "", 1, &state);
+    ASSERT (ret == 0);
+    ASSERT (mbsinit (&state));
+  }
+
+  /* Test single-byte input.  */
+  {
+    int c;
+    char buf[1];
+
+    memset (&state, '\0', sizeof (mbstate_t));
+    for (c = 0; c < 0x100; c++)
+      switch (c)
+	{
+	case '\t': case '\v': case '\f':
+	case ' ': case '!': case '"': case '#': case '%':
+	case '&': case '\'': case '(': case ')': case '*':
+	case '+': case ',': case '-': case '.': case '/':
+	case '0': case '1': case '2': case '3': case '4':
+	case '5': case '6': case '7': case '8': case '9':
+	case ':': case ';': case '<': case '=': case '>':
+	case '?':
+	case 'A': case 'B': case 'C': case 'D': case 'E':
+	case 'F': case 'G': case 'H': case 'I': case 'J':
+	case 'K': case 'L': case 'M': case 'N': case 'O':
+	case 'P': case 'Q': case 'R': case 'S': case 'T':
+	case 'U': case 'V': case 'W': case 'X': case 'Y':
+	case 'Z':
+	case '[': case '\\': case ']': case '^': case '_':
+	case 'a': case 'b': case 'c': case 'd': case 'e':
+	case 'f': case 'g': case 'h': case 'i': case 'j':
+	case 'k': case 'l': case 'm': case 'n': case 'o':
+	case 'p': case 'q': case 'r': case 's': case 't':
+	case 'u': case 'v': case 'w': case 'x': case 'y':
+	case 'z': case '{': case '|': case '}': case '~':
+	  /* c is in the ISO C "basic character set".  */
+	  buf[0] = c;
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, buf, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == c);
+	  ASSERT (mbsinit (&state));
+	  ret = mbrtowc (NULL, buf, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (mbsinit (&state));
+	  break;
+	}
+  }
+
+  /* Test special calling convention, passing a NULL pointer.  */
+  {
+    memset (&state, '\0', sizeof (mbstate_t));
+    wc = (wchar_t) 0xBADFACE;
+    ret = mbrtowc (&wc, NULL, 5, &state);
+    ASSERT (ret == 0);
+    ASSERT (wc == (wchar_t) 0xBADFACE);
+    ASSERT (mbsinit (&state));
+  }
+
+  if (argc > 1)
+    switch (argv[1][0])
+      {
+      case '1':
+	/* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
+	{
+	  char input[] = "B\374\337er"; /* "Büßer" */
+	  memset (&state, '\0', sizeof (mbstate_t));
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'B');
+	  ASSERT (mbsinit (&state));
+	  input[0] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 1, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wctob (wc) == (unsigned char) '\374');
+	  ASSERT (mbsinit (&state));
+	  input[1] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 2, 3, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wctob (wc) == (unsigned char) '\337');
+	  ASSERT (mbsinit (&state));
+	  input[2] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 3, 2, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'e');
+	  ASSERT (mbsinit (&state));
+	  input[3] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 4, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'r');
+	  ASSERT (mbsinit (&state));
+	}
+	return 0;
+
+      case '2':
+	/* Locale encoding is UTF-8.  */
+	{
+	  char input[] = "B\303\274\303\237er"; /* "Büßer" */
+	  memset (&state, '\0', sizeof (mbstate_t));
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'B');
+	  ASSERT (mbsinit (&state));
+	  input[0] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 1, 1, &state);
+	  ASSERT (ret == (size_t)(-2));
+	  ASSERT (wc == (wchar_t) 0xBADFACE);
+	  ASSERT (!mbsinit (&state));
+	  input[1] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 2, 5, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[2] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 3, 4, &state);
+	  ASSERT (ret == 2);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[3] = '\0';
+	  input[4] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 5, 2, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'e');
+	  ASSERT (mbsinit (&state));
+	  input[5] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 6, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'r');
+	  ASSERT (mbsinit (&state));
+	}
+	return 0;
+
+      case '3':
+	/* Locale encoding is EUC-JP.  */
+	{
+	  char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */
+	  memset (&state, '\0', sizeof (mbstate_t));
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == '<');
+	  ASSERT (mbsinit (&state));
+	  input[0] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 1, 2, &state);
+	  ASSERT (ret == 2);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[1] = '\0';
+	  input[2] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 3, 1, &state);
+	  ASSERT (ret == (size_t)(-2));
+	  ASSERT (wc == (wchar_t) 0xBADFACE);
+	  ASSERT (!mbsinit (&state));
+	  input[3] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 4, 4, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[4] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 5, 3, &state);
+	  ASSERT (ret == 2);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[5] = '\0';
+	  input[6] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 7, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == '>');
+	  ASSERT (mbsinit (&state));
+	}
+	return 0;
+
+      case '4':
+	/* Locale encoding is GB18030.  */
+	{
+	  char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
+	  memset (&state, '\0', sizeof (mbstate_t));
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'B');
+	  ASSERT (mbsinit (&state));
+	  input[0] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 1, 1, &state);
+	  ASSERT (ret == (size_t)(-2));
+	  ASSERT (wc == (wchar_t) 0xBADFACE);
+	  ASSERT (!mbsinit (&state));
+	  input[1] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 2, 7, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[2] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 3, 6, &state);
+	  ASSERT (ret == 4);
+	  ASSERT (wctob (wc) == EOF);
+	  ASSERT (mbsinit (&state));
+	  input[3] = '\0';
+	  input[4] = '\0';
+	  input[5] = '\0';
+	  input[6] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 7, 2, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'e');
+	  ASSERT (mbsinit (&state));
+	  input[5] = '\0';
+
+	  wc = (wchar_t) 0xBADFACE;
+	  ret = mbrtowc (&wc, input + 8, 1, &state);
+	  ASSERT (ret == 1);
+	  ASSERT (wc == 'r');
+	  ASSERT (mbsinit (&state));
+	}
+	return 0;
+      }
+
+  return 1;
+}
diff --git a/libmissing/tests/test-mbrtowc1.sh b/libmissing/tests/test-mbrtowc1.sh
new file mode 100755
index 0000000..3becba3
--- /dev/null
+++ b/libmissing/tests/test-mbrtowc1.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test in an ISO-8859-1 or ISO-8859-15 locale.
+: ${LOCALE_FR=fr_FR}
+if test $LOCALE_FR = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no traditional french locale is installed"
+  else
+    echo "Skipping test: no traditional french locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_FR \
+./test-mbrtowc${EXEEXT} 1
diff --git a/libmissing/tests/test-mbrtowc2.sh b/libmissing/tests/test-mbrtowc2.sh
new file mode 100755
index 0000000..0405aba
--- /dev/null
+++ b/libmissing/tests/test-mbrtowc2.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific UTF-8 locale is installed.
+: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
+if test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no french Unicode locale is installed"
+  else
+    echo "Skipping test: no french Unicode locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_FR_UTF8 \
+./test-mbrtowc${EXEEXT} 2
diff --git a/libmissing/tests/test-mbrtowc3.sh b/libmissing/tests/test-mbrtowc3.sh
new file mode 100755
index 0000000..63a89a2
--- /dev/null
+++ b/libmissing/tests/test-mbrtowc3.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific EUC-JP locale is installed.
+: ${LOCALE_JA=ja_JP}
+if test $LOCALE_JA = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no traditional japanese locale is installed"
+  else
+    echo "Skipping test: no traditional japanese locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_JA \
+./test-mbrtowc${EXEEXT} 3
diff --git a/libmissing/tests/test-mbrtowc4.sh b/libmissing/tests/test-mbrtowc4.sh
new file mode 100755
index 0000000..b299a2c
--- /dev/null
+++ b/libmissing/tests/test-mbrtowc4.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific GB18030 locale is installed.
+: ${LOCALE_ZH_CN=zh_CN.GB18030}
+if test $LOCALE_ZH_CN = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no transitional chinese locale is installed"
+  else
+    echo "Skipping test: no transitional chinese locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_ZH_CN \
+./test-mbrtowc${EXEEXT} 4
diff --git a/libmissing/tests/test-mbsinit.c b/libmissing/tests/test-mbsinit.c
new file mode 100644
index 0000000..5d4c9c3
--- /dev/null
+++ b/libmissing/tests/test-mbsinit.c
@@ -0,0 +1,62 @@
+/* Test of test for initial conversion state.
+   Copyright (C) 2008 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 <[email protected]>, 2008.  */
+
+#include <config.h>
+
+#include <wchar.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+        {								     \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          fflush (stderr);						     \
+          abort ();							     \
+        }								     \
+    }									     \
+  while (0)
+
+int
+main (int argc, char *argv[])
+{
+  static mbstate_t state;
+
+  ASSERT (mbsinit (&state));
+
+  if (argc > 1)
+    {
+      static const char input[1] = "\303";
+      wchar_t wc;
+      size_t ret;
+
+      /* configure should already have checked that the locale is supported.  */
+      if (setlocale (LC_ALL, "") == NULL)
+	return 1;
+
+      ret = mbrtowc (&wc, input, 1, &state);
+      ASSERT (ret == (size_t)(-2));
+      ASSERT (!mbsinit (&state));
+    }
+
+  return 0;
+}
diff --git a/libmissing/tests/test-mbsinit.sh b/libmissing/tests/test-mbsinit.sh
new file mode 100755
index 0000000..bbda48d
--- /dev/null
+++ b/libmissing/tests/test-mbsinit.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific UTF-8 locale is installed.
+: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
+if test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no french Unicode locale is installed"
+  else
+    echo "Skipping test: no french Unicode locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_FR_UTF8 \
+./test-mbsinit${EXEEXT}
diff --git a/libmissing/tests/test-mbsrtowcs.c b/libmissing/tests/test-mbsrtowcs.c
new file mode 100644
index 0000000..81e67c1
--- /dev/null
+++ b/libmissing/tests/test-mbsrtowcs.c
@@ -0,0 +1,300 @@
+/* Test of conversion of string to wide string.
+   Copyright (C) 2008 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 <[email protected]>, 2008.  */
+
+#include <config.h>
+
+#include <wchar.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+        {								     \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          fflush (stderr);						     \
+          abort ();							     \
+        }								     \
+    }									     \
+  while (0)
+
+int
+main (int argc, char *argv[])
+{
+  mbstate_t state;
+  wchar_t wc;
+  size_t ret;
+
+  /* configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Test NUL byte input.  */
+  {
+    const char *src;
+
+    memset (&state, '\0', sizeof (mbstate_t));
+
+    src = "";
+    ret = mbsrtowcs (NULL, &src, 0, &state);
+    ASSERT (ret == 0);
+    ASSERT (mbsinit (&state));
+
+    src = "";
+    ret = mbsrtowcs (NULL, &src, 1, &state);
+    ASSERT (ret == 0);
+    ASSERT (mbsinit (&state));
+
+    wc = (wchar_t) 0xBADFACE;
+    src = "";
+    ret = mbsrtowcs (&wc, &src, 0, &state);
+    ASSERT (ret == 0);
+    ASSERT (wc == (wchar_t) 0xBADFACE);
+    ASSERT (mbsinit (&state));
+
+    wc = (wchar_t) 0xBADFACE;
+    src = "";
+    ret = mbsrtowcs (&wc, &src, 1, &state);
+    ASSERT (ret == 0);
+    ASSERT (wc == 0);
+    ASSERT (mbsinit (&state));
+  }
+
+  if (argc > 1)
+    {
+      int unlimited;
+
+      for (unlimited = 0; unlimited < 2; unlimited++)
+	{
+	  #define BUFSIZE 10
+	  wchar_t buf[BUFSIZE];
+	  const char *src;
+	  mbstate_t temp_state;
+
+	  {
+	    size_t i;
+	    for (i = 0; i < BUFSIZE; i++)
+	      buf[i] = (wchar_t) 0xBADFACE;
+	  }
+
+	  switch (argv[1][0])
+	    {
+	    case '1':
+	      /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
+	      {
+		char input[] = "B\374\337er"; /* "Büßer" */
+		memset (&state, '\0', sizeof (mbstate_t));
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input, 1, &state);
+		ASSERT (ret == 1);
+		ASSERT (wc == 'B');
+		ASSERT (mbsinit (&state));
+		input[0] = '\0';
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input + 1, 1, &state);
+		ASSERT (ret == 1);
+		ASSERT (wctob (wc) == (unsigned char) '\374');
+		ASSERT (mbsinit (&state));
+		input[1] = '\0';
+
+		src = input + 2;
+		temp_state = state;
+		ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state);
+		ASSERT (ret == 3);
+		ASSERT (src == input + 2);
+		ASSERT (mbsinit (&state));
+
+		src = input + 2;
+		ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 1, &state);
+		ASSERT (ret == (unlimited ? 3 : 1));
+		ASSERT (src == (unlimited ? NULL : input + 3));
+		ASSERT (wctob (buf[0]) == (unsigned char) '\337');
+		if (unlimited)
+		  {
+		    ASSERT (buf[1] == 'e');
+		    ASSERT (buf[2] == 'r');
+		    ASSERT (buf[3] == 0);
+		    ASSERT (buf[4] == (wchar_t) 0xBADFACE);
+		  }
+		else
+		  ASSERT (buf[1] == (wchar_t) 0xBADFACE);
+		ASSERT (mbsinit (&state));
+	      }
+	      break;
+
+	    case '2':
+	      /* Locale encoding is UTF-8.  */
+	      {
+		char input[] = "B\303\274\303\237er"; /* "Büßer" */
+		memset (&state, '\0', sizeof (mbstate_t));
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input, 1, &state);
+		ASSERT (ret == 1);
+		ASSERT (wc == 'B');
+		ASSERT (mbsinit (&state));
+		input[0] = '\0';
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input + 1, 1, &state);
+		ASSERT (ret == (size_t)(-2));
+		ASSERT (wc == (wchar_t) 0xBADFACE);
+		ASSERT (!mbsinit (&state));
+		input[1] = '\0';
+
+		src = input + 2;
+		temp_state = state;
+		ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
+		ASSERT (ret == 4);
+		ASSERT (src == input + 2);
+		ASSERT (!mbsinit (&state));
+
+		src = input + 2;
+		ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state);
+		ASSERT (ret == (unlimited ? 4 : 2));
+		ASSERT (src == (unlimited ? NULL : input + 5));
+		ASSERT (wctob (buf[0]) == EOF);
+		ASSERT (wctob (buf[1]) == EOF);
+		if (unlimited)
+		  {
+		    ASSERT (buf[2] == 'e');
+		    ASSERT (buf[3] == 'r');
+		    ASSERT (buf[4] == 0);
+		    ASSERT (buf[5] == (wchar_t) 0xBADFACE);
+		  }
+		else
+		  ASSERT (buf[2] == (wchar_t) 0xBADFACE);
+		ASSERT (mbsinit (&state));
+	      }
+	      break;
+
+	    case '3':
+	      /* Locale encoding is EUC-JP.  */
+	      {
+		char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */
+		memset (&state, '\0', sizeof (mbstate_t));
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input, 1, &state);
+		ASSERT (ret == 1);
+		ASSERT (wc == '<');
+		ASSERT (mbsinit (&state));
+		input[0] = '\0';
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input + 1, 2, &state);
+		ASSERT (ret == 2);
+		ASSERT (wctob (wc) == EOF);
+		ASSERT (mbsinit (&state));
+		input[1] = '\0';
+		input[2] = '\0';
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input + 3, 1, &state);
+		ASSERT (ret == (size_t)(-2));
+		ASSERT (wc == (wchar_t) 0xBADFACE);
+		ASSERT (!mbsinit (&state));
+		input[3] = '\0';
+
+		src = input + 4;
+		temp_state = state;
+		ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
+		ASSERT (ret == 3);
+		ASSERT (src == input + 4);
+		ASSERT (!mbsinit (&state));
+
+		src = input + 4;
+		ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state);
+		ASSERT (ret == (unlimited ? 3 : 2));
+		ASSERT (src == (unlimited ? NULL : input + 7));
+		ASSERT (wctob (buf[0]) == EOF);
+		ASSERT (wctob (buf[1]) == EOF);
+		if (unlimited)
+		  {
+		    ASSERT (buf[2] == '>');
+		    ASSERT (buf[3] == 0);
+		    ASSERT (buf[4] == (wchar_t) 0xBADFACE);
+		  }
+		else
+		  ASSERT (buf[2] == (wchar_t) 0xBADFACE);
+		ASSERT (mbsinit (&state));
+	      }
+	      break;
+
+	    case '4':
+	      /* Locale encoding is GB18030.  */
+	      {
+		char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
+		memset (&state, '\0', sizeof (mbstate_t));
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input, 1, &state);
+		ASSERT (ret == 1);
+		ASSERT (wc == 'B');
+		ASSERT (mbsinit (&state));
+		input[0] = '\0';
+
+		wc = (wchar_t) 0xBADFACE;
+		ret = mbrtowc (&wc, input + 1, 1, &state);
+		ASSERT (ret == (size_t)(-2));
+		ASSERT (wc == (wchar_t) 0xBADFACE);
+		ASSERT (!mbsinit (&state));
+		input[1] = '\0';
+
+		src = input + 2;
+		temp_state = state;
+		ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
+		ASSERT (ret == 4);
+		ASSERT (src == input + 2);
+		ASSERT (!mbsinit (&state));
+
+		src = input + 2;
+		ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state);
+		ASSERT (ret == (unlimited ? 4 : 2));
+		ASSERT (src == (unlimited ? NULL : input + 7));
+		ASSERT (wctob (buf[0]) == EOF);
+		ASSERT (wctob (buf[1]) == EOF);
+		if (unlimited)
+		  {
+		    ASSERT (buf[2] == 'e');
+		    ASSERT (buf[3] == 'r');
+		    ASSERT (buf[4] == 0);
+		    ASSERT (buf[5] == (wchar_t) 0xBADFACE);
+		  }
+		else
+		  ASSERT (buf[2] == (wchar_t) 0xBADFACE);
+		ASSERT (mbsinit (&state));
+	      }
+	      break;
+
+	    default:
+	      return 1;
+	    }
+	}
+
+      return 0;
+    }
+
+  return 1;
+}
diff --git a/libmissing/tests/test-mbsrtowcs1.sh b/libmissing/tests/test-mbsrtowcs1.sh
new file mode 100755
index 0000000..01916e7
--- /dev/null
+++ b/libmissing/tests/test-mbsrtowcs1.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test in an ISO-8859-1 or ISO-8859-15 locale.
+: ${LOCALE_FR=fr_FR}
+if test $LOCALE_FR = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no traditional french locale is installed"
+  else
+    echo "Skipping test: no traditional french locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_FR \
+./test-mbsrtowcs${EXEEXT} 1
diff --git a/libmissing/tests/test-mbsrtowcs2.sh b/libmissing/tests/test-mbsrtowcs2.sh
new file mode 100755
index 0000000..f72ceb6
--- /dev/null
+++ b/libmissing/tests/test-mbsrtowcs2.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific UTF-8 locale is installed.
+: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
+if test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no french Unicode locale is installed"
+  else
+    echo "Skipping test: no french Unicode locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_FR_UTF8 \
+./test-mbsrtowcs${EXEEXT} 2
diff --git a/libmissing/tests/test-mbsrtowcs3.sh b/libmissing/tests/test-mbsrtowcs3.sh
new file mode 100755
index 0000000..b3c01d4
--- /dev/null
+++ b/libmissing/tests/test-mbsrtowcs3.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific EUC-JP locale is installed.
+: ${LOCALE_JA=ja_JP}
+if test $LOCALE_JA = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no traditional japanese locale is installed"
+  else
+    echo "Skipping test: no traditional japanese locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_JA \
+./test-mbsrtowcs${EXEEXT} 3
diff --git a/libmissing/tests/test-mbsrtowcs4.sh b/libmissing/tests/test-mbsrtowcs4.sh
new file mode 100755
index 0000000..226d6ff
--- /dev/null
+++ b/libmissing/tests/test-mbsrtowcs4.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific GB18030 locale is installed.
+: ${LOCALE_ZH_CN=zh_CN.GB18030}
+if test $LOCALE_ZH_CN = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no transitional chinese locale is installed"
+  else
+    echo "Skipping test: no transitional chinese locale is supported"
+  fi
+  exit 77
+fi
+
+LC_ALL=$LOCALE_ZH_CN \
+./test-mbsrtowcs${EXEEXT} 4
diff --git a/libmissing/tests/test-memchr.c b/libmissing/tests/test-memchr.c
new file mode 100644
index 0000000..1124f8b
--- /dev/null
+++ b/libmissing/tests/test-memchr.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2008-2009 Free Software Foundation
+ * Written by Eric Blake and Bruno Haible
+ *
+ * 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 <string.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "zerosize-ptr.h"
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+	{								     \
+	  fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+	  fflush (stderr);						     \
+	  abort ();							     \
+	}								     \
+    }									     \
+  while (0)
+
+/* Calculating void * + int is not portable, so this wrapper converts
+   to char * to make the tests easier to write.  */
+#define MEMCHR (char *) memchr
+
+int
+main ()
+{
+  size_t n = 0x100000;
+  char *input = malloc (n);
+  ASSERT (input);
+
+  input[0] = 'a';
+  input[1] = 'b';
+  memset (input + 2, 'c', 1024);
+  memset (input + 1026, 'd', n - 1028);
+  input[n - 2] = 'e';
+  input[n - 1] = 'a';
+
+  /* Basic behavior tests.  */
+  ASSERT (MEMCHR (input, 'a', n) == input);
+
+  ASSERT (MEMCHR (input, 'a', 0) == NULL);
+  ASSERT (MEMCHR (zerosize_ptr (), 'a', 0) == NULL);
+
+  ASSERT (MEMCHR (input, 'b', n) == input + 1);
+  ASSERT (MEMCHR (input, 'c', n) == input + 2);
+  ASSERT (MEMCHR (input, 'd', n) == input + 1026);
+
+  ASSERT (MEMCHR (input + 1, 'a', n - 1) == input + n - 1);
+  ASSERT (MEMCHR (input + 1, 'e', n - 1) == input + n - 2);
+
+  ASSERT (MEMCHR (input, 'f', n) == NULL);
+  ASSERT (MEMCHR (input, '\0', n) == NULL);
+
+  /* Check that a very long haystack is handled quickly if the byte is
+     found near the beginning.  */
+  {
+    size_t repeat = 10000;
+    for (; repeat > 0; repeat--)
+      {
+	ASSERT (MEMCHR (input, 'c', n) == input + 2);
+      }
+  }
+
+  /* Alignment tests.  */
+  {
+    int i, j;
+    for (i = 0; i < 32; i++)
+      {
+	for (j = 0; j < 256; j++)
+	  input[i + j] = j;
+	for (j = 0; j < 256; j++)
+	  {
+	    ASSERT (MEMCHR (input + i, j, 256) == input + i + j);
+	  }
+      }
+  }
+
+  /* Check that memchr() does not read past the first occurrence of the
+     byte being searched.  See the Austin Group's clarification
+     <http://www.opengroup.org/austin/docs/austin_454.txt>.  */
+  {
+    char *page_boundary = (char *) zerosize_ptr ();
+
+    if (page_boundary != NULL)
+      {
+	int n;
+
+	for (n = 1; n <= 500; n++)
+	  {
+	    char *mem = page_boundary - n;
+	    memset (mem, 'X', n);
+	    ASSERT (MEMCHR (mem, 'U', n) == NULL);
+
+	    {
+	      int i;
+
+	      for (i = 0; i < n; i++)
+		{
+		  mem[i] = 'U';
+		  ASSERT (MEMCHR (mem, 'U', 4000) == mem + i);
+		  mem[i] = 'X';
+		}
+	    }
+	  }
+      }
+  }
+
+  free (input);
+
+  return 0;
+}
diff --git a/libmissing/tests/test-netdb.c b/libmissing/tests/test-netdb.c
new file mode 100644
index 0000000..cde9105
--- /dev/null
+++ b/libmissing/tests/test-netdb.c
@@ -0,0 +1,29 @@
+/* Test of <netdb.h> substitute.
+   Copyright (C) 2007-2008 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 <[email protected]>, 2008.  */
+
+#include <config.h>
+#include <netdb.h>
+
+/* Check that the 'struct hostent' type is defined.  */
+struct hostent t1;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/libmissing/tests/test-signal.c b/libmissing/tests/test-signal.c
new file mode 100644
index 0000000..4bc13ab
--- /dev/null
+++ b/libmissing/tests/test-signal.c
@@ -0,0 +1,28 @@
+/* Test of <signal.h> substitute.
+   Copyright (C) 2009 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 <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <signal.h>
+
+volatile sig_atomic_t s;
+
+int main ()
+{
+  return s;
+}
diff --git a/libmissing/tests/test-stdio.c b/libmissing/tests/test-stdio.c
index a5efa32..dcfe38d 100644
--- a/libmissing/tests/test-stdio.c
+++ b/libmissing/tests/test-stdio.c
@@ -1,5 +1,5 @@
 /* Test of <stdio.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 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
@@ -20,9 +20,15 @@
 
 #include <stdio.h>
 
+#include "verify.h"
+
 /* Check that the various SEEK_* macros are defined.  */
 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 int
 main ()
 {
diff --git a/libmissing/tests/test-stdlib.c b/libmissing/tests/test-stdlib.c
index e103d46..ae46ba1 100644
--- a/libmissing/tests/test-stdlib.c
+++ b/libmissing/tests/test-stdlib.c
@@ -1,5 +1,5 @@
 /* Test of <stdlib.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 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
@@ -20,8 +20,14 @@
 
 #include <stdlib.h>
 
+#include "verify.h"
+
 int exitcode;
 
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 int
 main ()
 {
diff --git a/libmissing/tests/test-strerror.c b/libmissing/tests/test-strerror.c
new file mode 100644
index 0000000..3d9814d
--- /dev/null
+++ b/libmissing/tests/test-strerror.c
@@ -0,0 +1,65 @@
+/* Test of strerror() function.
+   Copyright (C) 2007-2008 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 <[email protected]>, 2007.  */
+
+#include <config.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+        {								     \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          fflush (stderr);						     \
+          abort ();							     \
+        }								     \
+    }									     \
+  while (0)
+
+int
+main (int argc, char **argv)
+{
+  char *str;
+
+  str = strerror (EACCES);
+  ASSERT (str);
+  ASSERT (*str);
+
+  str = strerror (ETIMEDOUT);
+  ASSERT (str);
+  ASSERT (*str);
+
+  str = strerror (EOVERFLOW);
+  ASSERT (str);
+  ASSERT (*str);
+
+  str = strerror (0);
+  ASSERT (str);
+  ASSERT (*str);
+
+  str = strerror (-3);
+  ASSERT (str);
+  ASSERT (*str);
+
+  return 0;
+}
diff --git a/libmissing/tests/test-string.c b/libmissing/tests/test-string.c
index 68014f5..fe53cd9 100644
--- a/libmissing/tests/test-string.c
+++ b/libmissing/tests/test-string.c
@@ -1,5 +1,5 @@
 /* Test of <string.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 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
@@ -20,6 +20,12 @@
 
 #include <string.h>
 
+#include "verify.h"
+
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 int
 main ()
 {
diff --git a/libmissing/tests/test-sys_socket.c b/libmissing/tests/test-sys_socket.c
index b7395b3..3d946a8 100644
--- a/libmissing/tests/test-sys_socket.c
+++ b/libmissing/tests/test-sys_socket.c
@@ -1,5 +1,5 @@
 /* Test of <sys/socket.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 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
@@ -30,6 +30,9 @@ int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
 int
 main ()
 {
+  struct sockaddr_storage x;
+  sa_family_t i;
+
   /* Check some errno values.  */
   switch (0)
     {
@@ -43,5 +46,8 @@ main ()
       break;
     }
 
+  x.ss_family = 42;
+  i = 4711;
+
   return 0;
 }
diff --git a/libmissing/tests/test-unistd.c b/libmissing/tests/test-unistd.c
index dc15bda..129367b 100644
--- a/libmissing/tests/test-unistd.c
+++ b/libmissing/tests/test-unistd.c
@@ -1,5 +1,5 @@
 /* Test of <unistd.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 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
@@ -20,9 +20,21 @@
 
 #include <unistd.h>
 
+#include "verify.h"
+
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 /* Check that the various SEEK_* macros are defined.  */
 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 
+/* Check that the various *_FILENO macros are defined.  */
+#if ! (defined STDIN_FILENO                                     \
+       && (STDIN_FILENO + STDOUT_FILENO + STDERR_FILENO == 3))
+missing or broken *_FILENO macros
+#endif
+
 /* Check that the types are all defined.  */
 size_t t1;
 ssize_t t2;
diff --git a/libmissing/tests/verify.h b/libmissing/tests/verify.h
deleted file mode 100644
index fac53f6..0000000
--- a/libmissing/tests/verify.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Compile-time assert-like macros.
-
-   Copyright (C) 2005, 2006 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, Bruno Haible, and Jim Meyering.  */
-
-#ifndef VERIFY_H
-# define VERIFY_H 1
-
-/* 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.
-
-   The code below uses several ideas.
-
-   * The first step is ((R) ? 1 : -1).  Given an expression R, of
-     integral or boolean or floating-point type, this yields an
-     expression of integral type, whose value is later verified to be
-     constant and nonnegative.
-
-   * Next this expression W is wrapped in a type
-     struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
-     If W is negative, this yields a compile-time error.  No compiler can
-     deal with a bit-field of negative size.
-
-     One might think that an array size check would have the same
-     effect, that is, that the type struct { unsigned int dummy[W]; }
-     would work as well.  However, inside a function, some compilers
-     (such as C++ compilers and GNU C) allow local parameters and
-     variables inside array size expressions.  With these compilers,
-     an array size check would not properly diagnose this misuse of
-     the verify macro:
-
-       void function (int n) { verify (n < 0); }
-
-   * For the verify macro, the struct 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,
-     such as in
-
-       struct dummy {...};
-       typedef struct {...} dummy;
-       extern struct {...} *dummy;
-       extern void dummy (struct {...} *);
-       extern struct {...} *dummy (void);
-
-     two uses of the verify macro would yield colliding declarations
-     if the entity names are not disambiguated.  A workaround is to
-     attach the current line number to the entity name:
-
-       #define GL_CONCAT0(x, y) x##y
-       #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
-       extern struct {...} * GL_CONCAT(dummy,__LINE__);
-
-     But this has the problem that two invocations of verify from
-     within the same macro would collide, since the __LINE__ value
-     would be the same for both invocations.
-
-     A solution is to use the sizeof operator.  It yields a number,
-     getting rid of the identity of the type.  Declarations like
-
-       extern int dummy [sizeof (struct {...})];
-       extern void dummy (int [sizeof (struct {...})]);
-       extern int (*dummy (void)) [sizeof (struct {...})];
-
-     can be repeated.
-
-   * Should the implementation use a named struct or an unnamed struct?
-     Which of the following alternatives can be used?
-
-       extern int dummy [sizeof (struct {...})];
-       extern int dummy [sizeof (struct verify_type__ {...})];
-       extern void dummy (int [sizeof (struct {...})]);
-       extern void dummy (int [sizeof (struct verify_type__ {...})]);
-       extern int (*dummy (void)) [sizeof (struct {...})];
-       extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
-
-     In the second and sixth case, the struct type is exported to the
-     outer scope; two such declarations therefore collide.  GCC warns
-     about the first, third, and fourth cases.  So the only remaining
-     possibility is the fifth case:
-
-       extern int (*dummy (void)) [sizeof (struct {...})];
-
-   * 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, e.g.,:
-
-       #if 4 <= __GNUC__
-       # define verify(R) \
-	   extern int (* verify_function__ (void)) \
-		      [__builtin_constant_p (R) && (R) ? 1 : -1]
-       #endif
-
-   * In C++, any struct definition inside sizeof is invalid.
-     Use a template type to work around the problem.  */
-
-
-/* Verify requirement R at compile-time, as an integer constant expression.
-   Return 1.  */
-
-# ifdef __cplusplus
-template <int w>
-  struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
-#  define verify_true(R) \
-     (!!sizeof (verify_type__<(R) ? 1 : -1>))
-# else
-#  define verify_true(R) \
-     (!!sizeof \
-      (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
-# endif
-
-/* Verify requirement R at compile-time, as a declaration without a
-   trailing ';'.  */
-
-# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
-
-#endif
diff --git a/libmissing/tests/wctob.c b/libmissing/tests/wctob.c
new file mode 100644
index 0000000..4fa71b0
--- /dev/null
+++ b/libmissing/tests/wctob.c
@@ -0,0 +1,37 @@
+/* Convert wide character to unibyte character.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Bruno Haible <[email protected]>, 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 <wchar.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+wctob (wint_t wc)
+{
+  char buf[64];
+
+  if (!(MB_CUR_MAX <= sizeof (buf)))
+    abort ();
+  if (wctomb (buf, wc) == 1)
+    return (unsigned char) buf[0];
+  else
+    return EOF;
+}
diff --git a/libmissing/tests/zerosize-ptr.h b/libmissing/tests/zerosize-ptr.h
new file mode 100644
index 0000000..a38a2cf
--- /dev/null
+++ b/libmissing/tests/zerosize-ptr.h
@@ -0,0 +1,68 @@
+/* Return a pointer to a zero-size object in memory.
+   Copyright (C) 2009 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/>.  */
+
+/* ISO C 99 does not allow memcmp(), memchr() etc. to be invoked with a NULL
+   argument.  Therefore this file produces a non-NULL pointer which cannot
+   be dereferenced, if possible.  */
+
+#include <stdlib.h>
+
+/* Test whether mmap() and mprotect() are available.
+   We don't use HAVE_MMAP, because AC_FUNC_MMAP would not define it on HP-UX.
+   HAVE_MPROTECT is not enough, because mingw does not have mmap() but has an
+   mprotect() function in libgcc.a.  */
+#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/mman.h>
+/* Define MAP_FILE when it isn't otherwise.  */
+# ifndef MAP_FILE
+#  define MAP_FILE 0
+# endif
+#endif
+
+/* Return a pointer to a zero-size object in memory (that is, actually, a
+   pointer to a page boundary where the previous page is readable and writable
+   and the next page is neither readable not writable), if possible.
+   Return NULL otherwise.  */
+
+static void *
+zerosize_ptr (void)
+{
+/* Use mmap and mprotect when they exist.  Don't test HAVE_MMAP, because it is
+   not defined on HP-UX 11 (since it does not support MAP_FIXED).  */
+#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
+# if HAVE_MAP_ANONYMOUS
+  const int flags = MAP_ANONYMOUS | MAP_PRIVATE;
+  const int fd = -1;
+# else /* !HAVE_MAP_ANONYMOUS */
+  const int flags = MAP_FILE | MAP_PRIVATE;
+  int fd = open ("/dev/zero", O_RDONLY, 0666);
+  if (fd >= 0)
+# endif
+    {
+      int pagesize = getpagesize ();
+      char *two_pages =
+	(char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
+		       flags, fd, 0);
+      if (two_pages != (char *)(-1)
+	  && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
+	return two_pages + pagesize;
+    }
+#endif
+  return NULL;
+}
diff --git a/libmissing/time.in.h b/libmissing/time.in.h
index fea9d40..7da429a 100644
--- a/libmissing/time.in.h
+++ b/libmissing/time.in.h
@@ -16,7 +16,9 @@
    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
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* Don't get in the way of glibc when it includes time.h merely to
    declare a few standard symbols, rather than to declare all the
diff --git a/libmissing/unistd.in.h b/libmissing/unistd.in.h
index f92f714..2e42c0b 100644
--- a/libmissing/unistd.in.h
+++ b/libmissing/unistd.in.h
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   Copyright (C) 2004-2008 Free Software Foundation, Inc.
+   Copyright (C) 2003-2009 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
@@ -17,7 +17,9 @@
 
 #ifndef _GL_UNISTD_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_UNISTD_H@
@@ -27,12 +29,13 @@
 #ifndef _GL_UNISTD_H
 #define _GL_UNISTD_H
 
-/* mingw doesn't define the SEEK_* macros in <unistd.h>.  */
+/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
 # include <stdio.h>
 #endif
 
 /* mingw fails to declare _exit in <unistd.h>.  */
+/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
 #include <stdlib.h>
 
 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
@@ -40,9 +43,61 @@
 # include <sys/types.h>
 #endif
 
+#if @GNULIB_GETHOSTNAME@
+/* Get all possible declarations of gethostname().  */
+# if @UNISTD_H_HAVE_WINSOCK2_H@
+#  include <winsock2.h>
+#  if !defined _GL_SYS_SOCKET_H
+#   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
+#  endif
+#  if !defined _GL_SYS_SELECT_H
+#   undef select
+#   define select		select_used_without_including_sys_select_h
+#  endif
+# endif
+#endif
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
+/* OS/2 EMX lacks these macros.  */
+#ifndef STDIN_FILENO
+# define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+# define STDOUT_FILENO 1
+#endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
+
 /* Declare overridden functions.  */
 
 #ifdef __cplusplus
@@ -132,6 +187,21 @@ extern char **environ;
 #endif
 
 
+#if @GNULIB_EUIDACCESS@
+# if !@HAVE_EUIDACCESS@
+/* Like access(), except that is uses the effective user id and group id of
+   the current process.  */
+extern int euidaccess (const char *filename, int mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef euidaccess
+# define euidaccess(f,m) \
+    (GL_LINK_WARNING ("euidaccess is unportable - " \
+                      "use gnulib module euidaccess for portability"), \
+     euidaccess (f, m))
+#endif
+
+
 #if @GNULIB_FCHDIR@
 # if @REPLACE_FCHDIR@
 
@@ -218,6 +288,29 @@ extern char * getcwd (char *buf, size_t size);
 #endif
 
 
+#if @GNULIB_GETDOMAINNAME@
+/* Return the NIS domain name of the machine.
+   WARNING! The NIS domain name is unrelated to the fully qualified host name
+            of the machine.  It is also unrelated to email addresses.
+   WARNING! The NIS domain name is usually the empty string or "(none)" when
+            not using NIS.
+
+   Put up to LEN bytes of the NIS domain name into NAME.
+   Null terminate it if the name is shorter than LEN.
+   If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
+   Return 0 if successful, otherwise set errno and return -1.  */
+# if !@HAVE_GETDOMAINNAME@
+extern int getdomainname(char *name, size_t len);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getdomainname
+# define getdomainname(n,l) \
+    (GL_LINK_WARNING ("getdomainname is unportable - " \
+                      "use gnulib module getdomainname for portability"), \
+     getdomainname (n, l))
+#endif
+
+
 #if @GNULIB_GETDTABLESIZE@
 # if !@HAVE_GETDTABLESIZE@
 /* Return the maximum number of file descriptors in the current process.  */
@@ -232,6 +325,33 @@ extern int getdtablesize (void);
 #endif
 
 
+#if @GNULIB_GETHOSTNAME@
+/* Return the standard host name of the machine.
+   WARNING! The host name may or may not be fully qualified.
+
+   Put up to LEN bytes of the host name into NAME.
+   Null terminate it if the name is shorter than LEN.
+   If the host name is longer than LEN, set errno = EINVAL and return -1.
+   Return 0 if successful, otherwise set errno and return -1.  */
+# if @UNISTD_H_HAVE_WINSOCK2_H@
+#  undef gethostname
+#  define gethostname rpl_gethostname
+# endif
+# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
+extern int gethostname(char *name, size_t len);
+# endif
+#elif @UNISTD_H_HAVE_WINSOCK2_H@
+# undef gethostname
+# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
+#elif defined GNULIB_POSIXCHECK
+# undef gethostname
+# define gethostname(n,l) \
+    (GL_LINK_WARNING ("gethostname is unportable - " \
+                      "use gnulib module gethostname for portability"), \
+     gethostname (n, l))
+#endif
+
+
 #if @GNULIB_GETLOGIN_R@
 /* Copies the user's login name to NAME.
    The array pointed to by NAME has room for SIZE bytes.
@@ -313,6 +433,36 @@ extern int getpagesize (void);
 #endif
 
 
+#if @GNULIB_GETUSERSHELL@
+# if !@HAVE_GETUSERSHELL@
+/* Return the next valid login shell on the system, or NULL when the end of
+   the list has been reached.  */
+extern char *getusershell (void);
+/* Rewind to pointer that is advanced at each getusershell() call.  */
+extern void setusershell (void);
+/* Free the pointer that is advanced at each getusershell() call and
+   associated resources.  */
+extern void endusershell (void);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getusershell
+# define getusershell() \
+    (GL_LINK_WARNING ("getusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     getusershell ())
+# undef setusershell
+# define setusershell() \
+    (GL_LINK_WARNING ("setusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     setusershell ())
+# undef endusershell
+# define endusershell() \
+    (GL_LINK_WARNING ("endusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     endusershell ())
+#endif
+
+
 #if @GNULIB_LCHOWN@
 # if @REPLACE_LCHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
@@ -332,6 +482,23 @@ extern int lchown (char const *file, uid_t owner, gid_t group);
 #endif
 
 
+#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>.  */
+# if !@HAVE_LINK@
+extern int link (const char *path1, const char *path2);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef link
+# define link(path1,path2) \
+    (GL_LINK_WARNING ("link is unportable - " \
+                      "use gnulib module link for portability"), \
+     link (path1, path2))
+#endif
+
+
 #if @GNULIB_LSEEK@
 # if @REPLACE_LSEEK@
 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
diff --git a/libmissing/vasnprintf.c b/libmissing/vasnprintf.c
index 07cd9ea..c620b4c 100644
--- a/libmissing/vasnprintf.c
+++ b/libmissing/vasnprintf.c
@@ -1,5 +1,5 @@
 /* vsprintf with automatic memory allocation.
-   Copyright (C) 1999, 2002-2008 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002-2009 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
@@ -117,29 +117,6 @@
 # include "fpucw.h"
 #endif
 
-#if HAVE_WCHAR_T
-# if HAVE_WCSLEN
-#  define local_wcslen wcslen
-# else
-   /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
-      a dependency towards this library, here is a local substitute.
-      Define this substitute only once, even if this file is included
-      twice in the same compilation unit.  */
-#  ifndef local_wcslen_defined
-#   define local_wcslen_defined 1
-static size_t
-local_wcslen (const wchar_t *s)
-{
-  const wchar_t *ptr;
-
-  for (ptr = s; *ptr != (wchar_t) 0; ptr++)
-    ;
-  return ptr - s;
-}
-#  endif
-# endif
-#endif
-
 /* Default parameters.  */
 #ifndef VASNPRINTF
 # if WIDE_CHAR_VERSION
@@ -152,6 +129,7 @@ local_wcslen (const wchar_t *s)
 #  define DIRECTIVES wchar_t_directives
 #  define PRINTF_PARSE wprintf_parse
 #  define DCHAR_CPY wmemcpy
+#  define DCHAR_SET wmemset
 # else
 #  define VASNPRINTF vasnprintf
 #  define FCHAR_T char
@@ -162,6 +140,7 @@ local_wcslen (const wchar_t *s)
 #  define DIRECTIVES char_directives
 #  define PRINTF_PARSE printf_parse
 #  define DCHAR_CPY memcpy
+#  define DCHAR_SET memset
 # endif
 #endif
 #if WIDE_CHAR_VERSION
@@ -215,6 +194,64 @@ local_wcslen (const wchar_t *s)
 #undef remainder
 #define remainder rem
 
+#if !USE_SNPRINTF && !WIDE_CHAR_VERSION
+# if (HAVE_STRNLEN && !defined _AIX)
+#  define local_strnlen strnlen
+# else
+#  ifndef local_strnlen_defined
+#   define local_strnlen_defined 1
+static size_t
+local_strnlen (const char *string, size_t maxlen)
+{
+  const char *end = memchr (string, '\0', maxlen);
+  return end ? (size_t) (end - string) : maxlen;
+}
+#  endif
+# endif
+#endif
+
+#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T && (WIDE_CHAR_VERSION || DCHAR_IS_TCHAR)
+# if HAVE_WCSLEN
+#  define local_wcslen wcslen
+# else
+   /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
+      a dependency towards this library, here is a local substitute.
+      Define this substitute only once, even if this file is included
+      twice in the same compilation unit.  */
+#  ifndef local_wcslen_defined
+#   define local_wcslen_defined 1
+static size_t
+local_wcslen (const wchar_t *s)
+{
+  const wchar_t *ptr;
+
+  for (ptr = s; *ptr != (wchar_t) 0; ptr++)
+    ;
+  return ptr - s;
+}
+#  endif
+# endif
+#endif
+
+#if !USE_SNPRINTF && HAVE_WCHAR_T && WIDE_CHAR_VERSION
+# if HAVE_WCSNLEN
+#  define local_wcsnlen wcsnlen
+# else
+#  ifndef local_wcsnlen_defined
+#   define local_wcsnlen_defined 1
+static size_t
+local_wcsnlen (const wchar_t *s, size_t maxlen)
+{
+  const wchar_t *ptr;
+
+  for (ptr = s; maxlen > 0 && *ptr != (wchar_t) 0; ptr++, maxlen--)
+    ;
+  return ptr - s;
+}
+#  endif
+# endif
+#endif
+
 #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
 /* Determine the decimal-point character according to the current locale.  */
 # ifndef decimal_point_char_defined
@@ -376,7 +413,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
        Normalise [q[m-1],...,q[0]], yields q.
      If m>=n>1, perform a multiple-precision division:
        We have a/b < beta^(m-n+1).
-       s:=intDsize-1-(hightest bit in b[n-1]), 0<=s<intDsize.
+       s:=intDsize-1-(highest bit in b[n-1]), 0<=s<intDsize.
        Shift a and b left by s bits, copying them. r:=a.
        r=[r[m],...,r[0]], b=[b[n-1],...,b[0]] with b[n-1]>=beta/2.
        For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).}
@@ -1762,18 +1799,18 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 			size_t converted_len = allocated - length;
 #  if DCHAR_IS_TCHAR
 			/* Convert from UTF-8 to locale encoding.  */
-			if (u8_conv_to_encoding (locale_charset (),
-						 iconveh_question_mark,
-						 arg, arg_end - arg, NULL,
-						 &converted, &converted_len)
-			    < 0)
+			converted =
+			  u8_conv_to_encoding (locale_charset (),
+					       iconveh_question_mark,
+					       arg, arg_end - arg, NULL,
+					       converted, &converted_len);
 #  else
 			/* Convert from UTF-8 to UTF-16/UTF-32.  */
 			converted =
 			  U8_TO_DCHAR (arg, arg_end - arg,
 				       converted, &converted_len);
-			if (converted == NULL)
 #  endif
+			if (converted == NULL)
 			  {
 			    int saved_errno = errno;
 			    if (!(result == resultbuf || result == NULL))
@@ -1890,18 +1927,18 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 			size_t converted_len = allocated - length;
 #  if DCHAR_IS_TCHAR
 			/* Convert from UTF-16 to locale encoding.  */
-			if (u16_conv_to_encoding (locale_charset (),
-						  iconveh_question_mark,
-						  arg, arg_end - arg, NULL,
-						  &converted, &converted_len)
-			    < 0)
+			converted =
+			  u16_conv_to_encoding (locale_charset (),
+						iconveh_question_mark,
+						arg, arg_end - arg, NULL,
+						converted, &converted_len);
 #  else
 			/* Convert from UTF-16 to UTF-8/UTF-32.  */
 			converted =
 			  U16_TO_DCHAR (arg, arg_end - arg,
 					converted, &converted_len);
-			if (converted == NULL)
 #  endif
+			if (converted == NULL)
 			  {
 			    int saved_errno = errno;
 			    if (!(result == resultbuf || result == NULL))
@@ -2018,18 +2055,18 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 			size_t converted_len = allocated - length;
 #  if DCHAR_IS_TCHAR
 			/* Convert from UTF-32 to locale encoding.  */
-			if (u32_conv_to_encoding (locale_charset (),
-						  iconveh_question_mark,
-						  arg, arg_end - arg, NULL,
-						  &converted, &converted_len)
-			    < 0)
+			converted =
+			  u32_conv_to_encoding (locale_charset (),
+						iconveh_question_mark,
+						arg, arg_end - arg, NULL,
+						converted, &converted_len);
 #  else
 			/* Convert from UTF-32 to UTF-8/UTF-16.  */
 			converted =
 			  U32_TO_DCHAR (arg, arg_end - arg,
 					converted, &converted_len);
-			if (converted == NULL)
 #  endif
+			if (converted == NULL)
 			  {
 			    int saved_errno = errno;
 			    if (!(result == resultbuf || result == NULL))
@@ -2066,6 +2103,522 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 		  }
 	      }
 #endif
+#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
+	    else if (dp->conversion == 's'
+# if WIDE_CHAR_VERSION
+		     && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
+# else
+		     && a.arg[dp->arg_index].type == TYPE_WIDE_STRING
+# endif
+		    )
+	      {
+		/* The normal handling of the 's' directive below requires
+		   allocating a temporary buffer.  The determination of its
+		   length (tmp_length), in the case when a precision is
+		   specified, below requires a conversion between a char[]
+		   string and a wchar_t[] wide string.  It could be done, but
+		   we have no guarantee that the implementation of sprintf will
+		   use the exactly same algorithm.  Without this guarantee, it
+		   is possible to have buffer overrun bugs.  In order to avoid
+		   such bugs, we implement the entire processing of the 's'
+		   directive ourselves.  */
+		int flags = dp->flags;
+		int has_width;
+		size_t width;
+		int has_precision;
+		size_t precision;
+
+		has_width = 0;
+		width = 0;
+		if (dp->width_start != dp->width_end)
+		  {
+		    if (dp->width_arg_index != ARG_NONE)
+		      {
+			int arg;
+
+			if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+			  abort ();
+			arg = a.arg[dp->width_arg_index].a.a_int;
+			if (arg < 0)
+			  {
+			    /* "A negative field width is taken as a '-' flag
+			        followed by a positive field width."  */
+			    flags |= FLAG_LEFT;
+			    width = (unsigned int) (-arg);
+			  }
+			else
+			  width = arg;
+		      }
+		    else
+		      {
+			const FCHAR_T *digitp = dp->width_start;
+
+			do
+			  width = xsum (xtimes (width, 10), *digitp++ - '0');
+			while (digitp != dp->width_end);
+		      }
+		    has_width = 1;
+		  }
+
+		has_precision = 0;
+		precision = 6;
+		if (dp->precision_start != dp->precision_end)
+		  {
+		    if (dp->precision_arg_index != ARG_NONE)
+		      {
+			int arg;
+
+			if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+			  abort ();
+			arg = a.arg[dp->precision_arg_index].a.a_int;
+			/* "A negative precision is taken as if the precision
+			    were omitted."  */
+			if (arg >= 0)
+			  {
+			    precision = arg;
+			    has_precision = 1;
+			  }
+		      }
+		    else
+		      {
+			const FCHAR_T *digitp = dp->precision_start + 1;
+
+			precision = 0;
+			while (digitp != dp->precision_end)
+			  precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+			has_precision = 1;
+		      }
+		  }
+
+# if WIDE_CHAR_VERSION
+		/* %s in vasnwprintf.  See the specification of fwprintf.  */
+		{
+		  const char *arg = a.arg[dp->arg_index].a.a_string;
+		  const char *arg_end;
+		  size_t characters;
+
+		  if (has_precision)
+		    {
+		      /* Use only as many bytes as needed to produce PRECISION
+			 wide characters, from the left.  */
+#  if HAVE_MBRTOWC
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      arg_end = arg;
+		      characters = 0;
+		      for (; precision > 0; precision--)
+			{
+			  int count;
+#  if HAVE_MBRTOWC
+			  count = mbrlen (arg_end, MB_CUR_MAX, &state);
+#  else
+			  count = mblen (arg_end, MB_CUR_MAX);
+#  endif
+			  if (count == 0)
+			    /* Found the terminating NUL.  */
+			    break;
+			  if (count < 0)
+			    {
+			      /* Invalid or incomplete multibyte character.  */
+			      if (!(result == resultbuf || result == NULL))
+				free (result);
+			      if (buf_malloced != NULL)
+				free (buf_malloced);
+			      CLEANUP ();
+			      errno = EILSEQ;
+			      return NULL;
+			    }
+			  arg_end += count;
+			  characters++;
+			}
+		    }
+		  else if (has_width)
+		    {
+		      /* Use the entire string, and count the number of wide
+			 characters.  */
+#  if HAVE_MBRTOWC
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      arg_end = arg;
+		      characters = 0;
+		      for (;;)
+			{
+			  int count;
+#  if HAVE_MBRTOWC
+			  count = mbrlen (arg_end, MB_CUR_MAX, &state);
+#  else
+			  count = mblen (arg_end, MB_CUR_MAX);
+#  endif
+			  if (count == 0)
+			    /* Found the terminating NUL.  */
+			    break;
+			  if (count < 0)
+			    {
+			      /* Invalid or incomplete multibyte character.  */
+			      if (!(result == resultbuf || result == NULL))
+				free (result);
+			      if (buf_malloced != NULL)
+				free (buf_malloced);
+			      CLEANUP ();
+			      errno = EILSEQ;
+			      return NULL;
+			    }
+			  arg_end += count;
+			  characters++;
+			}
+		    }
+		  else
+		    {
+		      /* Use the entire string.  */
+		      arg_end = arg + strlen (arg);
+		      /* The number of characters doesn't matter.  */
+		      characters = 0;
+		    }
+
+		  if (has_width && width > characters
+		      && !(dp->flags & FLAG_LEFT))
+		    {
+		      size_t n = width - characters;
+		      ENSURE_ALLOCATION (xsum (length, n));
+		      DCHAR_SET (result + length, ' ', n);
+		      length += n;
+		    }
+
+		  if (has_precision || has_width)
+		    {
+		      /* We know the number of wide characters in advance.  */
+		      size_t remaining;
+#  if HAVE_MBRTOWC
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      ENSURE_ALLOCATION (xsum (length, characters));
+		      for (remaining = characters; remaining > 0; remaining--)
+			{
+			  wchar_t wc;
+			  int count;
+#  if HAVE_MBRTOWC
+			  count = mbrtowc (&wc, arg, arg_end - arg, &state);
+#  else
+			  count = mbtowc (&wc, arg, arg_end - arg);
+#  endif
+			  if (count <= 0)
+			    /* mbrtowc not consistent with mbrlen, or mbtowc
+			       not consistent with mblen.  */
+			    abort ();
+			  result[length++] = wc;
+			  arg += count;
+			}
+		      if (!(arg == arg_end))
+			abort ();
+		    }
+		  else
+		    {
+#  if HAVE_MBRTOWC
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      while (arg < arg_end)
+			{
+			  wchar_t wc;
+			  int count;
+#  if HAVE_MBRTOWC
+			  count = mbrtowc (&wc, arg, arg_end - arg, &state);
+#  else
+			  count = mbtowc (&wc, arg, arg_end - arg);
+#  endif
+			  if (count <= 0)
+			    /* mbrtowc not consistent with mbrlen, or mbtowc
+			       not consistent with mblen.  */
+			    abort ();
+			  ENSURE_ALLOCATION (xsum (length, 1));
+			  result[length++] = wc;
+			  arg += count;
+			}
+		    }
+
+		  if (has_width && width > characters
+		      && (dp->flags & FLAG_LEFT))
+		    {
+		      size_t n = width - characters;
+		      ENSURE_ALLOCATION (xsum (length, n));
+		      DCHAR_SET (result + length, ' ', n);
+		      length += n;
+		    }
+		}
+# else
+		/* %ls in vasnprintf.  See the specification of fprintf.  */
+		{
+		  const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
+		  const wchar_t *arg_end;
+		  size_t characters;
+#  if !DCHAR_IS_TCHAR
+		  /* This code assumes that TCHAR_T is 'char'.  */
+		  typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1];
+		  TCHAR_T *tmpsrc;
+		  DCHAR_T *tmpdst;
+		  size_t tmpdst_len;
+#  endif
+		  size_t w;
+
+		  if (has_precision)
+		    {
+		      /* Use only as many wide characters as needed to produce
+			 at most PRECISION bytes, from the left.  */
+#  if HAVE_WCRTOMB
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      arg_end = arg;
+		      characters = 0;
+		      while (precision > 0)
+			{
+			  char buf[64]; /* Assume MB_CUR_MAX <= 64.  */
+			  int count;
+
+			  if (*arg_end == 0)
+			    /* Found the terminating null wide character.  */
+			    break;
+#  if HAVE_WCRTOMB
+			  count = wcrtomb (buf, *arg_end, &state);
+#  else
+			  count = wctomb (buf, *arg_end);
+#  endif
+			  if (count < 0)
+			    {
+			      /* Cannot convert.  */
+			      if (!(result == resultbuf || result == NULL))
+				free (result);
+			      if (buf_malloced != NULL)
+				free (buf_malloced);
+			      CLEANUP ();
+			      errno = EILSEQ;
+			      return NULL;
+			    }
+			  if (precision < count)
+			    break;
+			  arg_end++;
+			  characters += count;
+			  precision -= count;
+			}
+		    }
+#  if DCHAR_IS_TCHAR
+		  else if (has_width)
+#  else
+		  else
+#  endif
+		    {
+		      /* Use the entire string, and count the number of
+			 bytes.  */
+#  if HAVE_WCRTOMB
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#  endif
+		      arg_end = arg;
+		      characters = 0;
+		      for (;;)
+			{
+			  char buf[64]; /* Assume MB_CUR_MAX <= 64.  */
+			  int count;
+
+			  if (*arg_end == 0)
+			    /* Found the terminating null wide character.  */
+			    break;
+#  if HAVE_WCRTOMB
+			  count = wcrtomb (buf, *arg_end, &state);
+#  else
+			  count = wctomb (buf, *arg_end);
+#  endif
+			  if (count < 0)
+			    {
+			      /* Cannot convert.  */
+			      if (!(result == resultbuf || result == NULL))
+				free (result);
+			      if (buf_malloced != NULL)
+				free (buf_malloced);
+			      CLEANUP ();
+			      errno = EILSEQ;
+			      return NULL;
+			    }
+			  arg_end++;
+			  characters += count;
+			}
+		    }
+#  if DCHAR_IS_TCHAR
+		  else
+		    {
+		      /* Use the entire string.  */
+		      arg_end = arg + local_wcslen (arg);
+		      /* The number of bytes doesn't matter.  */
+		      characters = 0;
+		    }
+#  endif
+
+#  if !DCHAR_IS_TCHAR
+		  /* Convert the string into a piece of temporary memory.  */
+		  tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T));
+		  if (tmpsrc == NULL)
+		    goto out_of_memory;
+		  {
+		    TCHAR_T *tmpptr = tmpsrc;
+		    size_t remaining;
+#   if HAVE_WCRTOMB
+		    mbstate_t state;
+		    memset (&state, '\0', sizeof (mbstate_t));
+#   endif
+		    for (remaining = characters; remaining > 0; )
+		      {
+			char buf[64]; /* Assume MB_CUR_MAX <= 64.  */
+			int count;
+
+			if (*arg == 0)
+			  abort ();
+#   if HAVE_WCRTOMB
+			count = wcrtomb (buf, *arg, &state);
+#   else
+			count = wctomb (buf, *arg);
+#   endif
+			if (count <= 0)
+			  /* Inconsistency.  */
+			  abort ();
+			memcpy (tmpptr, buf, count);
+			tmpptr += count;
+			arg++;
+			remaining -= count;
+		      }
+		    if (!(arg == arg_end))
+		      abort ();
+		  }
+
+		  /* Convert from TCHAR_T[] to DCHAR_T[].  */
+		  tmpdst =
+		    DCHAR_CONV_FROM_ENCODING (locale_charset (),
+					      iconveh_question_mark,
+					      tmpsrc, characters,
+					      NULL,
+					      NULL, &tmpdst_len);
+		  if (tmpdst == NULL)
+		    {
+		      int saved_errno = errno;
+		      free (tmpsrc);
+		      if (!(result == resultbuf || result == NULL))
+			free (result);
+		      if (buf_malloced != NULL)
+			free (buf_malloced);
+		      CLEANUP ();
+		      errno = saved_errno;
+		      return NULL;
+		    }
+		  free (tmpsrc);
+#  endif
+
+		  if (has_width)
+		    {
+#  if ENABLE_UNISTDIO
+		      /* Outside POSIX, it's preferrable to compare the width
+			 against the number of _characters_ of the converted
+			 value.  */
+		      w = DCHAR_MBSNLEN (result + length, characters);
+#  else
+		      /* The width is compared against the number of _bytes_
+			 of the converted value, says POSIX.  */
+		      w = characters;
+#  endif
+		    }
+		  else
+		    /* w doesn't matter.  */
+		    w = 0;
+
+		  if (has_width && width > w
+		      && !(dp->flags & FLAG_LEFT))
+		    {
+		      size_t n = width - w;
+		      ENSURE_ALLOCATION (xsum (length, n));
+		      DCHAR_SET (result + length, ' ', n);
+		      length += n;
+		    }
+
+#  if DCHAR_IS_TCHAR
+		  if (has_precision || has_width)
+		    {
+		      /* We know the number of bytes in advance.  */
+		      size_t remaining;
+#   if HAVE_WCRTOMB
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#   endif
+		      ENSURE_ALLOCATION (xsum (length, characters));
+		      for (remaining = characters; remaining > 0; )
+			{
+			  char buf[64]; /* Assume MB_CUR_MAX <= 64.  */
+			  int count;
+
+			  if (*arg == 0)
+			    abort ();
+#   if HAVE_WCRTOMB
+			  count = wcrtomb (buf, *arg, &state);
+#   else
+			  count = wctomb (buf, *arg);
+#   endif
+			  if (count <= 0)
+			    /* Inconsistency.  */
+			    abort ();
+			  memcpy (result + length, buf, count);
+			  length += count;
+			  arg++;
+			  remaining -= count;
+			}
+		      if (!(arg == arg_end))
+			abort ();
+		    }
+		  else
+		    {
+#   if HAVE_WCRTOMB
+		      mbstate_t state;
+		      memset (&state, '\0', sizeof (mbstate_t));
+#   endif
+		      while (arg < arg_end)
+			{
+			  char buf[64]; /* Assume MB_CUR_MAX <= 64.  */
+			  int count;
+
+			  if (*arg == 0)
+			    abort ();
+#   if HAVE_WCRTOMB
+			  count = wcrtomb (buf, *arg, &state);
+#   else
+			  count = wctomb (buf, *arg);
+#   endif
+			  if (count <= 0)
+			    /* Inconsistency.  */
+			    abort ();
+			  ENSURE_ALLOCATION (xsum (length, count));
+			  memcpy (result + length, buf, count);
+			  length += count;
+			  arg++;
+			}
+		    }
+#  else
+		  ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+		  DCHAR_CPY (result + length, tmpdst, tmpdst_len);
+		  free (tmpdst);
+		  length += tmpdst_len;
+#  endif
+
+		  if (has_width && width > w
+		      && (dp->flags & FLAG_LEFT))
+		    {
+		      size_t n = width - w;
+		      ENSURE_ALLOCATION (xsum (length, n));
+		      DCHAR_SET (result + length, ' ', n);
+		      length += n;
+		    }
+		}
+	      }
+# endif
+#endif
 #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
 	    else if ((dp->conversion == 'a' || dp->conversion == 'A')
 # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
@@ -4032,16 +4585,64 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # if HAVE_WCHAR_T
 		      if (type == TYPE_WIDE_STRING)
 			{
-			  tmp_length =
-			    local_wcslen (a.arg[dp->arg_index].a.a_wide_string);
-
-#  if !WIDE_CHAR_VERSION
-			  tmp_length = xtimes (tmp_length, MB_CUR_MAX);
+#  if WIDE_CHAR_VERSION
+			  /* ISO C says about %ls in fwprintf:
+			       "If the precision is not specified or is greater
+				than the size of the array, the array shall
+				contain a null wide character."
+			     So if there is a precision, we must not use
+			     wcslen.  */
+			  const wchar_t *arg =
+			    a.arg[dp->arg_index].a.a_wide_string;
+
+			  if (has_precision)
+			    tmp_length = local_wcsnlen (arg, precision);
+			  else
+			    tmp_length = local_wcslen (arg);
+#  else
+			  /* ISO C says about %ls in fprintf:
+			       "If a precision is specified, no more than that
+				many bytes are written (including shift
+				sequences, if any), and the array shall contain
+				a null wide character if, to equal the
+				multibyte character sequence length given by
+				the precision, the function would need to
+				access a wide character one past the end of the
+				array."
+			     So if there is a precision, we must not use
+			     wcslen.  */
+			  /* This case has already been handled above.  */
+			  abort ();
 #  endif
 			}
 		      else
 # endif
-			tmp_length = strlen (a.arg[dp->arg_index].a.a_string);
+			{
+# if WIDE_CHAR_VERSION
+			  /* ISO C says about %s in fwprintf:
+			       "If the precision is not specified or is greater
+				than the size of the converted array, the
+				converted array shall contain a null wide
+				character."
+			     So if there is a precision, we must not use
+			     strlen.  */
+			  /* This case has already been handled above.  */
+			  abort ();
+# else
+			  /* ISO C says about %s in fprintf:
+			       "If the precision is not specified or greater
+				than the size of the array, the array shall
+				contain a null character."
+			     So if there is a precision, we must not use
+			     strlen.  */
+			  const char *arg = a.arg[dp->arg_index].a.a_string;
+
+			  if (has_precision)
+			    tmp_length = local_strnlen (arg, precision);
+			  else
+			    tmp_length = strlen (arg);
+# endif
+			}
 		      break;
 
 		    case 'p':
@@ -4614,14 +5215,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # else
 			tmpsrc = tmp;
 # endif
-			tmpdst = NULL;
-			tmpdst_len = 0;
-			if (DCHAR_CONV_FROM_ENCODING (locale_charset (),
-						      iconveh_question_mark,
-						      tmpsrc, count,
-						      NULL,
-						      &tmpdst, &tmpdst_len)
-			    < 0)
+			tmpdst =
+			  DCHAR_CONV_FROM_ENCODING (locale_charset (),
+						    iconveh_question_mark,
+						    tmpsrc, count,
+						    NULL,
+						    NULL, &tmpdst_len);
+			if (tmpdst == NULL)
 			  {
 			    int saved_errno = errno;
 			    if (!(result == resultbuf || result == NULL))
diff --git a/libmissing/verify.h b/libmissing/verify.h
new file mode 100644
index 0000000..e82fa02
--- /dev/null
+++ b/libmissing/verify.h
@@ -0,0 +1,140 @@
+/* Compile-time assert-like macros.
+
+   Copyright (C) 2005, 2006 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 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 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/>.  */
+
+/* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
+
+#ifndef VERIFY_H
+# define VERIFY_H 1
+
+/* 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.
+
+   The code below uses several ideas.
+
+   * The first step is ((R) ? 1 : -1).  Given an expression R, of
+     integral or boolean or floating-point type, this yields an
+     expression of integral type, whose value is later verified to be
+     constant and nonnegative.
+
+   * Next this expression W is wrapped in a type
+     struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
+     If W is negative, this yields a compile-time error.  No compiler can
+     deal with a bit-field of negative size.
+
+     One might think that an array size check would have the same
+     effect, that is, that the type struct { unsigned int dummy[W]; }
+     would work as well.  However, inside a function, some compilers
+     (such as C++ compilers and GNU C) allow local parameters and
+     variables inside array size expressions.  With these compilers,
+     an array size check would not properly diagnose this misuse of
+     the verify macro:
+
+       void function (int n) { verify (n < 0); }
+
+   * For the verify macro, the struct 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,
+     such as in
+
+       struct dummy {...};
+       typedef struct {...} dummy;
+       extern struct {...} *dummy;
+       extern void dummy (struct {...} *);
+       extern struct {...} *dummy (void);
+
+     two uses of the verify macro would yield colliding declarations
+     if the entity names are not disambiguated.  A workaround is to
+     attach the current line number to the entity name:
+
+       #define GL_CONCAT0(x, y) x##y
+       #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
+       extern struct {...} * GL_CONCAT(dummy,__LINE__);
+
+     But this has the problem that two invocations of verify from
+     within the same macro would collide, since the __LINE__ value
+     would be the same for both invocations.
+
+     A solution is to use the sizeof operator.  It yields a number,
+     getting rid of the identity of the type.  Declarations like
+
+       extern int dummy [sizeof (struct {...})];
+       extern void dummy (int [sizeof (struct {...})]);
+       extern int (*dummy (void)) [sizeof (struct {...})];
+
+     can be repeated.
+
+   * Should the implementation use a named struct or an unnamed struct?
+     Which of the following alternatives can be used?
+
+       extern int dummy [sizeof (struct {...})];
+       extern int dummy [sizeof (struct verify_type__ {...})];
+       extern void dummy (int [sizeof (struct {...})]);
+       extern void dummy (int [sizeof (struct verify_type__ {...})]);
+       extern int (*dummy (void)) [sizeof (struct {...})];
+       extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
+
+     In the second and sixth case, the struct type is exported to the
+     outer scope; two such declarations therefore collide.  GCC warns
+     about the first, third, and fourth cases.  So the only remaining
+     possibility is the fifth case:
+
+       extern int (*dummy (void)) [sizeof (struct {...})];
+
+   * 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, e.g.,:
+
+       #if 4 <= __GNUC__
+       # define verify(R) \
+	   extern int (* verify_function__ (void)) \
+		      [__builtin_constant_p (R) && (R) ? 1 : -1]
+       #endif
+
+   * In C++, any struct definition inside sizeof is invalid.
+     Use a template type to work around the problem.  */
+
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+   Return 1.  */
+
+# ifdef __cplusplus
+template <int w>
+  struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
+#  define verify_true(R) \
+     (!!sizeof (verify_type__<(R) ? 1 : -1>))
+# else
+#  define verify_true(R) \
+     (!!sizeof \
+      (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+# endif
+
+/* Verify requirement R at compile-time, as a declaration without a
+   trailing ';'.  */
+
+# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
+
+#endif
diff --git a/libmissing/w32sock.h b/libmissing/w32sock.h
new file mode 100644
index 0000000..060ebd4
--- /dev/null
+++ b/libmissing/w32sock.h
@@ -0,0 +1,62 @@
+/* w32sock.h --- internal auxilliary functions for Windows socket functions
+
+   Copyright (C) 2008 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 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 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/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <errno.h>
+
+/* Get O_RDWR and O_BINARY.  */
+#include <fcntl.h>
+
+/* Get _get_osfhandle() and _open_osfhandle().  */
+#include <io.h>
+
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+
+static inline void
+set_winsock_errno (void)
+{
+  int err = WSAGetLastError ();
+  WSASetLastError (0);
+
+  /* Map some WSAE* errors to the runtime library's error codes.  */
+  switch (err)
+    {
+    case WSA_INVALID_HANDLE:
+      errno = EBADF;
+      break;
+    case WSA_NOT_ENOUGH_MEMORY:
+      errno = ENOMEM;
+      break;
+    case WSA_INVALID_PARAMETER:
+      errno = EINVAL;
+      break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAENAMETOOLONG:
+      errno = ENAMETOOLONG;
+      break;
+    case WSAENOTEMPTY:
+      errno = ENOTEMPTY;
+      break;
+    default:
+      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
+      break;
+    }
+}
diff --git a/libmissing/wchar.in.h b/libmissing/wchar.in.h
index a9d412b..1f1f130 100644
--- a/libmissing/wchar.in.h
+++ b/libmissing/wchar.in.h
@@ -1,6 +1,6 @@
 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
 
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 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
@@ -26,10 +26,22 @@
  * the declaration of wcwidth().
  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
-#ifdef __need_mbstate_t
-/* Special invocation convention inside uClibc header files.  */
+#if defined __need_mbstate_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 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.  */
 
 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
 
@@ -38,6 +50,8 @@
 
 #ifndef _GL_WCHAR_H
 
+#define _GL_ALREADY_INCLUDING_WCHAR_H
+
 /* 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
@@ -53,6 +67,8 @@
 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
 #endif
 
+#undef _GL_ALREADY_INCLUDING_WCHAR_H
+
 #ifndef _GL_WCHAR_H
 #define _GL_WCHAR_H
 
@@ -66,6 +82,201 @@ extern "C" {
 /* Define wint_t.  (Also done in wctype.in.h.)  */
 #if !@HAVE_WINT_T@ && !defined wint_t
 # define wint_t int
+# ifndef WEOF
+#  define WEOF -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@
+typedef int rpl_mbstate_t;
+# undef mbstate_t
+# define mbstate_t rpl_mbstate_t
+# define GNULIB_defined_mbstate_t 1
+#endif
+
+
+/* Convert a single-byte character to a wide character.  */
+#if @GNULIB_BTOWC@
+# if @REPLACE_BTOWC@
+#  undef btowc
+#  define btowc rpl_btowc
+# endif
+# if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
+extern wint_t btowc (int c);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef btowc
+# define btowc(c) \
+    (GL_LINK_WARNING ("btowc is unportable - " \
+                      "use gnulib module btowc for portability"), \
+     btowc (c))
+#endif
+
+
+/* Convert a wide character to a single-byte character.  */
+#if @GNULIB_WCTOB@
+# if @REPLACE_WCTOB@
+#  undef wctob
+#  define wctob rpl_wctob
+# endif
+# if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
+/* wctob is provided by gnulib, or wctob exists but is not declared.  */
+extern int wctob (wint_t wc);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wctob
+# define wctob(w) \
+    (GL_LINK_WARNING ("wctob is unportable - " \
+                      "use gnulib module wctob for portability"), \
+     wctob (w))
+#endif
+
+
+/* Test whether *PS is in the initial state.  */
+#if @GNULIB_MBSINIT@
+# if @REPLACE_MBSINIT@
+#  undef mbsinit
+#  define mbsinit rpl_mbsinit
+# endif
+# if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
+extern int mbsinit (const mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsinit
+# define mbsinit(p) \
+    (GL_LINK_WARNING ("mbsinit is unportable - " \
+                      "use gnulib module mbsinit for portability"), \
+     mbsinit (p))
+#endif
+
+
+/* Convert a multibyte character to a wide character.  */
+#if @GNULIB_MBRTOWC@
+# if @REPLACE_MBRTOWC@
+#  undef mbrtowc
+#  define mbrtowc rpl_mbrtowc
+# endif
+# if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
+extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbrtowc
+# define mbrtowc(w,s,n,p) \
+    (GL_LINK_WARNING ("mbrtowc is unportable - " \
+                      "use gnulib module mbrtowc for portability"), \
+     mbrtowc (w, s, n, p))
+#endif
+
+
+/* Recognize a multibyte character.  */
+#if @GNULIB_MBRLEN@
+# if @REPLACE_MBRLEN@
+#  undef mbrlen
+#  define mbrlen rpl_mbrlen
+# endif
+# if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
+extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbrlen
+# define mbrlen(s,n,p) \
+    (GL_LINK_WARNING ("mbrlen is unportable - " \
+                      "use gnulib module mbrlen for portability"), \
+     mbrlen (s, n, p))
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSRTOWCS@
+# if @REPLACE_MBSRTOWCS@
+#  undef mbsrtowcs
+#  define mbsrtowcs rpl_mbsrtowcs
+# endif
+# if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
+extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsrtowcs
+# define mbsrtowcs(d,s,l,p) \
+    (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
+                      "use gnulib module mbsrtowcs for portability"), \
+     mbsrtowcs (d, s, l, p))
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSNRTOWCS@
+# if @REPLACE_MBSNRTOWCS@
+#  undef mbsnrtowcs
+#  define mbsnrtowcs rpl_mbsnrtowcs
+# endif
+# if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
+extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsnrtowcs
+# define mbsnrtowcs(d,s,n,l,p) \
+    (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
+                      "use gnulib module mbsnrtowcs for portability"), \
+     mbsnrtowcs (d, s, n, l, p))
+#endif
+
+
+/* Convert a wide character to a multibyte character.  */
+#if @GNULIB_WCRTOMB@
+# if @REPLACE_WCRTOMB@
+#  undef wcrtomb
+#  define wcrtomb rpl_wcrtomb
+# endif
+# if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
+extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcrtomb
+# define wcrtomb(s,w,p) \
+    (GL_LINK_WARNING ("wcrtomb is unportable - " \
+                      "use gnulib module wcrtomb for portability"), \
+     wcrtomb (s, w, p))
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSRTOMBS@
+# if @REPLACE_WCSRTOMBS@
+#  undef wcsrtombs
+#  define wcsrtombs rpl_wcsrtombs
+# endif
+# if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
+extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsrtombs
+# define wcsrtombs(d,s,l,p) \
+    (GL_LINK_WARNING ("wcsrtombs is unportable - " \
+                      "use gnulib module wcsrtombs for portability"), \
+     wcsrtombs (d, s, l, p))
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSNRTOMBS@
+# if @REPLACE_WCSNRTOMBS@
+#  undef wcsnrtombs
+#  define wcsnrtombs rpl_wcsnrtombs
+# endif
+# if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@
+extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsnrtombs
+# define wcsnrtombs(d,s,n,l,p) \
+    (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
+                      "use gnulib module wcsnrtombs for portability"), \
+     wcsnrtombs (d, s, n, l, p))
 #endif
 
 
diff --git a/libmissing/wctype.in.h b/libmissing/wctype.in.h
index 6353156..a583a04 100644
--- a/libmissing/wctype.in.h
+++ b/libmissing/wctype.in.h
@@ -28,7 +28,9 @@
 
 #ifndef _GL_WCTYPE_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if @HAVE_WINT_T@
 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
@@ -55,6 +57,9 @@
 /* Define wint_t.  (Also done in wchar.in.h.)  */
 #if !@HAVE_WINT_T@ && !defined wint_t
 # define wint_t int
+# ifndef WEOF
+#  define WEOF -1
+# endif
 #endif
 
 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
diff --git a/libmissing/winsock.c b/libmissing/winsock.c
deleted file mode 100644
index d4a1e81..0000000
--- a/libmissing/winsock.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/* winsock.c --- wrappers for Windows socket functions
-
-   Copyright (C) 2008 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 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 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/>.  */
-
-/* Written by Paolo Bonzini */
-
-#include <config.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <io.h>
-#include <sys/socket.h>
-#if GNULIB_IOCTL
-#include <sys/ioctl.h>
-#endif
-
-#undef socket
-#undef connect
-#undef accept
-#undef bind
-#undef getpeername
-#undef getsockname
-#undef getsockopt
-#undef listen
-#undef recv
-#undef send
-#undef recvfrom
-#undef sendto
-#undef setsockopt
-#undef shutdown
-
-#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
-
-
-static inline void
-set_winsock_errno (void)
-{
-  int err = WSAGetLastError ();
-  WSASetLastError (0);
-
-  /* Map some WSAE* errors to the runtime library's error codes.  */
-  switch (err)
-    {
-    case WSA_INVALID_HANDLE:
-      errno = EBADF;
-      break;
-    case WSA_NOT_ENOUGH_MEMORY:
-      errno = ENOMEM;
-      break;
-    case WSA_INVALID_PARAMETER:
-      errno = EINVAL;
-      break;
-    case WSAEWOULDBLOCK:
-      errno = EWOULDBLOCK;
-      break;
-    case WSAENAMETOOLONG:
-      errno = ENAMETOOLONG;
-      break;
-    case WSAENOTEMPTY:
-      errno = ENOTEMPTY;
-      break;
-    default:
-      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
-      break;
-    }
-}
-
-
-/* Hook for gnulib module close.  */
-
-#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
-int
-_gl_close_fd_maybe_socket (int fd)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  WSANETWORKEVENTS ev;
-
-  ev.lNetworkEvents = 0xDEADBEEF;
-  WSAEnumNetworkEvents (sock, NULL, &ev);
-  if (ev.lNetworkEvents != 0xDEADBEEF)
-    {
-      /* FIXME: other applications, like squid, use an undocumented
-	 _free_osfhnd free function.  But this is not enough: The 'osfile'
-	 flags for fd also needs to be cleared, but it is hard to access it.
-	 Instead, here we just close twice the file descriptor.  */
-      if (closesocket (sock))
-	{
-	  set_winsock_errno ();
-	  return -1;
-	}
-      else
-	{
-	  /* This call frees the file descriptor and does a
-	     CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
-	  _close (fd);
-	  return 0;
-	}
-    }
-  else
-    return _close (fd);
-}
-#endif
-
-
-/* Wrappers for WinSock functions.  */
-
-#if GNULIB_SOCKET
-int
-rpl_socket (int domain, int type, int protocol)
-{
-  /* We have to use WSASocket() to create non-overlapped IO sockets.
-     Overlapped IO sockets cannot be used with read/write.  */
-  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
-
-  if (fh == INVALID_SOCKET)
-    {
-      set_winsock_errno ();
-      return -1;
-    }
-  else
-    return SOCKET_TO_FD (fh);
-}
-#endif
-
-#if GNULIB_CONNECT
-int
-rpl_connect (int fd, struct sockaddr *sockaddr, int 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 ();
-    }
-
-  return r;
-}
-#endif
-
-#if GNULIB_ACCEPT
-int
-rpl_accept (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
-  if (fh == INVALID_SOCKET)
-    {
-      set_winsock_errno ();
-      return -1;
-    }
-  else
-    return SOCKET_TO_FD (fh);
-}
-#endif
-
-#if GNULIB_BIND
-int
-rpl_bind (int fd, struct sockaddr *sockaddr, int len)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = bind (sock, sockaddr, len);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETPEERNAME
-int
-rpl_getpeername (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getpeername (sock, addr, addrlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETSOCKNAME
-int
-rpl_getsockname (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getsockname (sock, addr, addrlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETSOCKOPT
-int
-rpl_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getsockopt (sock, level, optname, optval, optlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_LISTEN
-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;
-}
-#endif
-
-#if GNULIB_IOCTL
-int
-rpl_ioctl (int fd, int req, ...)
-{
-  void *buf;
-  va_list args;
-  SOCKET sock;
-  int r;
-
-  va_start (args, req);
-  buf = 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;
-}
-#endif
-
-#if GNULIB_RECV
-int
-rpl_recv (int fd, void *buf, int len, int flags)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = recv (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_SEND
-int
-rpl_send (int fd, const void *buf, int len, int flags)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = send (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_RECVFROM
-int
-rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
-	      int *fromlen)
-{
-  int frombufsize = *fromlen;
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = recvfrom (sock, buf, len, flags, from, fromlen);
-
-  if (r < 0)
-    set_winsock_errno ();
-
-  /* Winsock recvfrom() only returns a valid 'from' when the socket is
-     connectionless.  POSIX gives a valid 'from' for all types of sockets.  */
-  else if (*fromlen == frombufsize)
-    rpl_getpeername (fd, from, fromlen);
-
-  return r;
-}
-#endif
-
-#if GNULIB_SENDTO
-int
-rpl_sendto (int fd, const void *buf, int len, int flags,
-	    struct sockaddr *to, int tolen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = sendto (sock, buf, len, flags, to, tolen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_SETSOCKOPT
-int
-rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = setsockopt (sock, level, optname, optval, optlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_SHUTDOWN
-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;
-}
-#endif
diff --git a/link-warning.h b/link-warning.h
new file mode 100644
index 0000000..fda0194
--- /dev/null
+++ b/link-warning.h
@@ -0,0 +1,28 @@
+/* GL_LINK_WARNING("literal string") arranges to emit the literal string as
+   a linker warning on most glibc systems.
+   We use a linker warning rather than a preprocessor warning, because
+   #warning cannot be used inside macros.  */
+#ifndef GL_LINK_WARNING
+  /* This works on platforms with GNU ld and ELF object format.
+     Testing __GLIBC__ is sufficient for asserting that GNU ld is in use.
+     Testing __ELF__ guarantees the ELF object format.
+     Testing __GNUC__ is necessary for the compound expression syntax.  */
+# if defined __GLIBC__ && defined __ELF__ && defined __GNUC__
+#  define GL_LINK_WARNING(message) \
+     GL_LINK_WARNING1 (__FILE__, __LINE__, message)
+#  define GL_LINK_WARNING1(file, line, message) \
+     GL_LINK_WARNING2 (file, line, message)  /* macroexpand file and line */
+#  define GL_LINK_WARNING2(file, line, message) \
+     GL_LINK_WARNING3 (file ":" #line ": warning: " message)
+#  define GL_LINK_WARNING3(message) \
+     ({ static const char warning[sizeof (message)]		\
+          __attribute__ ((__unused__,				\
+                          __section__ (".gnu.warning"),		\
+                          __aligned__ (1)))			\
+          = message "\n";					\
+        (void)0;						\
+     })
+# else
+#  define GL_LINK_WARNING(message) ((void) 0)
+# endif
+#endif

_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog