From 50b3ff7b91e78a61aca93247bee586d6d7eb27c8 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 20 May 2009 00:32:10 +0200 Subject: Sync with the latest Gnulib code (cb75dc5) Signed-off-by: Holger Weiss diff --git a/gl/Makefile.am b/gl/Makefile.am index cae814f..87fe031 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -28,6 +28,7 @@ MAINTAINERCLEANFILES = EXTRA_DIST += m4/gnulib-cache.m4 AM_CPPFLAGS = +AM_CFLAGS = noinst_LIBRARIES += libgnu.a @@ -36,6 +37,13 @@ libgnu_a_LIBADD = $(gl_LIBOBJS) libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) EXTRA_libgnu_a_SOURCES = +## begin gnulib module alignof + + +EXTRA_DIST += alignof.h + +## end gnulib module alignof + ## begin gnulib module alloca @@ -70,7 +78,7 @@ BUILT_SOURCES += $(ARPA_INET_H) # We need the following in order to create 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! */'; \ @@ -146,7 +154,7 @@ EXTRA_libgnu_a_SOURCES += cloexec.c # The Automake-defined pkg* macros are appended, in the order # listed in the Automake 1.10a+ documentation. configmake.h: Makefile - rm -f $@-t $@ + rm -f $@-t { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ echo '#define PREFIX "$(prefix)"'; \ echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ @@ -176,7 +184,12 @@ configmake.h: Makefile echo '#define PKGLIBDIR "$(pkglibdir)"'; \ echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ } | sed '/""/d' > $@-t - mv $@-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 @@ -433,21 +446,37 @@ 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: all-local - test $(GLIBC21) != no || $(mkinstalldirs) $(DESTDIR)$(libdir) +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 test $(GLIBC21) = no; then \ + 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: all-local +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) \ @@ -794,6 +823,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' \ @@ -826,6 +857,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' \ @@ -866,6 +901,7 @@ 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' \ @@ -912,6 +948,15 @@ EXTRA_DIST += stdlib.in.h ## end gnulib module stdlib +## begin gnulib module strdup-posix + + +EXTRA_DIST += strdup.c + +EXTRA_libgnu_a_SOURCES += strdup.c + +## end gnulib module strdup-posix + ## begin gnulib module streq @@ -1054,6 +1099,7 @@ sys/socket.h: sys_socket.in.h -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 '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/sys_socket.in.h; \ } > $@-t @@ -1139,6 +1185,7 @@ unistd.h: unistd.in.h -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' \ @@ -1153,6 +1200,7 @@ unistd.h: unistd.in.h -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' \ @@ -1266,6 +1314,7 @@ wchar.h: wchar.in.h -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; \ diff --git a/gl/alignof.h b/gl/alignof.h new file mode 100644 index 0000000..896382b --- /dev/null +++ b/gl/alignof.h @@ -0,0 +1,33 @@ +/* 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 General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _ALIGNOF_H +#define _ALIGNOF_H + +#include + +/* Determine the alignment of a type at compile time. */ +#if defined __GNUC__ +# define alignof __alignof__ +#elif defined __cplusplus + template struct alignof_helper { char __slot1; type __slot2; }; +# define alignof(type) offsetof (alignof_helper, __slot2) +#else +# define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2) +#endif + +#endif /* _ALIGNOF_H */ diff --git a/gl/arpa_inet.in.h b/gl/arpa_inet.in.h index 4b95b94..ac93399 100644 --- a/gl/arpa_inet.in.h +++ b/gl/arpa_inet.in.h @@ -38,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, @@ -78,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/gl/c-strtod.c b/gl/c-strtod.c index 95624cc..51e996e 100644 --- a/gl/c-strtod.c +++ b/gl/c-strtod.c @@ -1,6 +1,6 @@ /* Convert string to double, using the C locale. - Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. + 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 General Public License as published by @@ -21,10 +21,10 @@ #include "c-strtod.h" +#include #include #include - -#include "xalloc.h" +#include #if LONG # define C_STRTOD c_strtold @@ -43,6 +43,25 @@ # define STRTOD strtod #endif +#ifdef LC_ALL_MASK + +/* Cache for the C locale object. + Marked volatile so that different threads see the same value + (avoids locking). */ +static volatile locale_t c_locale_cache; + +/* Return the C locale object, or (locale_t) 0 with errno set + if it cannot be created. */ +static inline locale_t +c_locale (void) +{ + if (!c_locale_cache) + c_locale_cache = newlocale (LC_ALL_MASK, "C", (locale_t) 0); + return c_locale_cache; +} + +#endif + DOUBLE C_STRTOD (char const *nptr, char **endptr) { @@ -50,9 +69,15 @@ C_STRTOD (char const *nptr, char **endptr) #ifdef LC_ALL_MASK - locale_t c_locale = newlocale (LC_ALL_MASK, "C", 0); - r = STRTOD_L (nptr, endptr, c_locale); - freelocale (c_locale); + locale_t locale = c_locale (); + if (!locale) + { + if (endptr) + *endptr = (char *) nptr; + return 0; /* errno is set here */ + } + + r = STRTOD_L (nptr, endptr, locale); #else @@ -60,7 +85,13 @@ C_STRTOD (char const *nptr, char **endptr) if (saved_locale) { - saved_locale = xstrdup (saved_locale); + saved_locale = strdup (saved_locale); + if (saved_locale == NULL) + { + if (endptr) + *endptr = (char *) nptr; + return 0; /* errno is set here */ + } setlocale (LC_NUMERIC, "C"); } @@ -68,8 +99,11 @@ C_STRTOD (char const *nptr, char **endptr) if (saved_locale) { + int saved_errno = errno; + setlocale (LC_NUMERIC, saved_locale); free (saved_locale); + errno = saved_errno; } #endif diff --git a/gl/c-strtod.h b/gl/c-strtod.h index ca9a9e7..2b3f847 100644 --- a/gl/c-strtod.h +++ b/gl/c-strtod.h @@ -1,2 +1,37 @@ -double c_strtod (char const *, char **); -long double c_strtold (char const *, char **); +/* Convert string to double, using the C locale. + + Copyright (C) 2003-2004, 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 . */ + +/* Parse the initial portion of the string pointed to by NPTR as a floating- + point number (in decimal or hexadecimal notation), like in the C locale: + accepting only the ASCII digits '0'..'9', and only '.' as decimal point + character. + If ENDPTR is not NULL, set *ENDPTR to point to the first byte beyond the + parsed number or to NPTR if the string does not start with a parseable + number. + Return value: + - If successful, return the value as a double or 'long double', + respectively, and don't modify errno. + - In case of overflow, return ±HUGE_VAL or ±HUGE_VALL, respectively, and + set errno to ERANGE. + - In case of underflow, return a value very near to 0 and set errno to + ERANGE. + - If the string does not start with a number at all, return 0 (and recall + that if ENDPTR != NULL, *ENDPTR is set to NPTR), and maybe set errno to + EINVAL. + - In case of other error, return 0 and set errno, for example to ENOMEM. */ +extern double c_strtod (char const *nptr, char **endptr); +extern long double c_strtold (char const *nptr, char **endptr); diff --git a/gl/config.charset b/gl/config.charset index 36ba683..7f91212 100755 --- a/gl/config.charset +++ b/gl/config.charset @@ -1,7 +1,7 @@ #! /bin/sh # Output a system dependent table of character encoding aliases. # -# Copyright (C) 2000-2004, 2006-2008 Free Software Foundation, Inc. +# 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 General Public License as published by @@ -63,12 +63,13 @@ # CP922 aix # CP932 aix woe32 dos # CP943 aix -# CP949 osf woe32 dos +# 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 @@ -82,15 +83,17 @@ # 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 -# GBK glibc aix osf solaris woe32 dos -# GB18030 glibc solaris netbsd +# 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 @@ -449,7 +452,8 @@ case "$os" in echo "ko_KR.EUC EUC-KR" ;; darwin*) - # Darwin 7.5 has nl_langinfo(CODESET), but it is useless: + # 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. @@ -476,6 +480,36 @@ case "$os" in # 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*) diff --git a/gl/dup-safer.c b/gl/dup-safer.c index a690851..7d9b2be 100644 --- a/gl/dup-safer.c +++ b/gl/dup-safer.c @@ -1,6 +1,7 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2004, 2005, 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 @@ -24,9 +25,6 @@ #include #include -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif /* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ diff --git a/gl/fd-safer.c b/gl/fd-safer.c index df38c8f..fb99001 100644 --- a/gl/fd-safer.c +++ b/gl/fd-safer.c @@ -1,6 +1,6 @@ /* Return a safer copy of a file descriptor. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 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 @@ -24,12 +24,6 @@ #include #include -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif /* Return FD, unless FD would be a copy of standard input, output, or error; in that case, return a duplicate of FD, closing FD. On diff --git a/gl/fsusage.c b/gl/fsusage.c index 23d40ea..db0d3bc 100644 --- a/gl/fsusage.c +++ b/gl/fsusage.c @@ -1,6 +1,6 @@ /* fsusage.c -- return space usage of mounted file systems - Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005, 2006 + Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -232,6 +232,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) #endif + (void) disk; /* avoid argument-unused warning */ return 0; } diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c index 78a8edf..afbcdbb 100644 --- a/gl/gai_strerror.c +++ b/gl/gai_strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008 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 , 1997. @@ -50,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/gl/getloadavg.c b/gl/getloadavg.c index 5c32f9f..5a4005c 100644 --- a/gl/getloadavg.c +++ b/gl/getloadavg.c @@ -1,8 +1,8 @@ /* Get the system load averages. Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, - 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008 Free Software - Foundation, Inc. + 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free + Software Foundation, Inc. NOTE: The canonical source of this file is maintained with gnulib. Bugs can be reported to bug-gnulib@gnu.org. @@ -621,8 +621,11 @@ getloadavg (double loadavg[], int nelem) for (elem = 0; elem < nelem; elem++) { char *endptr; - double d = c_strtod (ptr, &endptr); - if (ptr == endptr) + double d; + + errno = 0; + d = c_strtod (ptr, &endptr); + if (ptr == endptr || (d == 0 && errno != 0)) { if (elem == 0) return -1; diff --git a/gl/getopt1.c b/gl/getopt1.c index d6a3ecf..ba115c4 100644 --- a/gl/getopt1.c +++ b/gl/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006 + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -91,7 +91,7 @@ main (int argc, char **argv) { int this_option_optind = optind ? optind : 1; int option_index = 0; - static struct option long_options[] = + static const struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, diff --git a/gl/gettext.h b/gl/gettext.h index 763dd3c..8cf2dca 100644 --- a/gl/gettext.h +++ b/gl/gettext.h @@ -1,5 +1,5 @@ /* Convenience header for conditional use of GNU . - 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 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/gl/localcharset.c b/gl/localcharset.c index 68679cf..a7ca94c 100644 --- a/gl/localcharset.c +++ b/gl/localcharset.c @@ -1,6 +1,6 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2006, 2008 Free Software Foundation, Inc. + 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 General Public License as published by @@ -28,6 +28,10 @@ #include #include +#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 @@ -112,7 +116,7 @@ get_charset_aliases (void) cp = charset_aliases; if (cp == NULL) { -#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) +#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) FILE *fp; const char *dir; const char *base = "charset.alias"; @@ -213,6 +217,39 @@ get_charset_aliases (void) #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. */ diff --git a/gl/m4/00gnulib.m4 b/gl/m4/00gnulib.m4 new file mode 100644 index 0000000..d4d04d1 --- /dev/null +++ b/gl/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/gl/m4/btowc.m4 b/gl/m4/btowc.m4 index 64ff829..b46f74f 100644 --- a/gl/m4/btowc.m4 +++ b/gl/m4/btowc.m4 @@ -1,5 +1,5 @@ -# btowc.m4 serial 3 -dnl Copyright (C) 2008 Free Software Foundation, Inc. +# btowc.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. @@ -47,7 +47,7 @@ int main () }], [gl_cv_func_btowc_eof=yes], [gl_cv_func_btowc_eof=no], - []) + [:]) fi ]) case "$gl_cv_func_btowc_eof" in diff --git a/gl/m4/c-strtod.m4 b/gl/m4/c-strtod.m4 index 0514f2d..ba95435 100644 --- a/gl/m4/c-strtod.m4 +++ b/gl/m4/c-strtod.m4 @@ -1,4 +1,4 @@ -# c-strtod.m4 serial 10 +# c-strtod.m4 serial 11 # Copyright (C) 2004, 2005, 2006, 2009 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -39,6 +39,8 @@ AC_DEFUN([gl_C_STRTOD], dnl Prerequisites of lib/c-strtod.c. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([AC_C_INLINE]) : ]) @@ -49,5 +51,7 @@ AC_DEFUN([gl_C_STRTOLD], dnl Prerequisites of lib/c-strtold.c. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([gl_C99_STRTOLD]) + + AC_REQUIRE([AC_C_INLINE]) : ]) diff --git a/gl/m4/errno_h.m4 b/gl/m4/errno_h.m4 index 0682d1a..16188d9 100644 --- a/gl/m4/errno_h.m4 +++ b/gl/m4/errno_h.m4 @@ -1,17 +1,10 @@ -# errno_h.m4 serial 3 +# errno_h.m4 serial 5 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], [ diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4 index 611fcfd..ba6d5e1 100644 --- a/gl/m4/extensions.m4 +++ b/gl/m4/extensions.m4 @@ -1,7 +1,7 @@ -# serial 6 -*- 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,7 +20,7 @@ # 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 @@ -90,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/gl/m4/fcntl_h.m4 b/gl/m4/fcntl_h.m4 index 4a7fc42..1ae0b15 100644 --- a/gl/m4/fcntl_h.m4 +++ b/gl/m4/fcntl_h.m4 @@ -9,6 +9,8 @@ dnl Written by Paul Eggert. AC_DEFUN([gl_FCNTL_H], [ AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + dnl Persuade glibc to define O_NOATIME and O_NOFOLLOW. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( diff --git a/gl/m4/floorf.m4 b/gl/m4/floorf.m4 index 8cdaa94..915e566 100644 --- a/gl/m4/floorf.m4 +++ b/gl/m4/floorf.m4 @@ -1,5 +1,5 @@ -# floorf.m4 serial 3 -dnl Copyright (C) 2007 Free Software Foundation, Inc. +# floorf.m4 serial 4 +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. @@ -34,7 +34,7 @@ AC_DEFUN([gl_FUNC_FLOORF], # Sets FLOORF_LIBM. AC_DEFUN([gl_FUNC_FLOORF_LIBS], [ - AC_CACHE_VAL([gl_cv_func_floorf_libm], [ + gl_CACHE_VAL_SILENT([gl_cv_func_floorf_libm], [ gl_cv_func_floorf_libm=? AC_TRY_LINK([ #ifndef __NO_MATH_INLINES diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4 index 5804eb9..c8fda20 100644 --- a/gl/m4/gnulib-common.m4 +++ b/gl/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 7 +# 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, @@ -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], [ @@ -52,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])])]) @@ -99,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/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index c6171de..005cc4e 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -25,7 +25,6 @@ AC_DEFUN([gl_EARLY], m4_pattern_allow([^gl_LIBOBJS$])dnl a variable m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable AC_REQUIRE([AC_PROG_RANLIB]) - AC_REQUIRE([AC_GNU_SOURCE]) AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) ]) @@ -116,6 +115,8 @@ AC_DEFUN([gl_INIT], gl_STDINT_H gl_STDIO_H gl_STDLIB_H + gl_FUNC_STRDUP_POSIX + gl_STRING_MODULE_INDICATOR([strdup]) gl_FUNC_STRERROR gl_STRING_MODULE_INDICATOR([strerror]) gl_HEADER_STRING_H @@ -124,7 +125,6 @@ AC_DEFUN([gl_INIT], gl_FUNC_STRNLEN gl_STRING_MODULE_INDICATOR([strnlen]) gl_HEADER_SYS_SOCKET - gl_MODULE_INDICATOR([sys_socket]) AC_PROG_MKDIR_P gl_HEADER_TIME_H gl_TIME_R @@ -282,6 +282,7 @@ AC_DEFUN([gltests_LIBSOURCES], [ AC_DEFUN([gl_FILE_LIST], [ build-aux/config.rpath build-aux/link-warning.h + lib/alignof.h lib/alloca.c lib/alloca.in.h lib/arpa_inet.in.h @@ -367,6 +368,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/stdio-write.c lib/stdio.in.h lib/stdlib.in.h + lib/strdup.c lib/streq.h lib/strerror.c lib/string.in.h @@ -395,6 +397,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/xsize.h lib/xstrndup.c lib/xstrndup.h + m4/00gnulib.m4 m4/alloca.m4 m4/arpa_inet_h.m4 m4/base64.m4 @@ -478,6 +481,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/stdint_h.m4 m4/stdio_h.m4 m4/stdlib_h.m4 + m4/strdup.m4 m4/strerror.m4 m4/string_h.m4 m4/strndup.m4 diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4 index 062753c..d6101fe 100644 --- a/gl/m4/include_next.m4 +++ b/gl/m4/include_next.m4 @@ -1,5 +1,5 @@ -# include_next.m4 serial 10 -dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. +# include_next.m4 serial 12 +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. @@ -32,14 +32,15 @@ AC_DEFUN([gl_INCLUDE_NEXT], [gl_cv_have_include_next], [rm -rf conftestd1a conftestd1b conftestd2 mkdir conftestd1a conftestd1b conftestd2 - dnl The include of 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. Additionally, - dnl with this same compiler, include_next is a no-op when used in a - dnl header file that was included by specifying its absolute file name. - dnl Despite these two bugs, include_next is used in the compiler's - dnl . By virtue of the second bug, we need to use include_next - dnl as well in this case. + 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 . + 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 . By virtue of the second bug, we need to use + dnl include_next as well in this case. cat < conftestd1a/conftest.h #define DEFINED_IN_CONFTESTD1 #include_next diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4 index 42bfc5e..2bbdca1 100644 --- a/gl/m4/inet_ntop.m4 +++ b/gl/m4/inet_ntop.m4 @@ -1,4 +1,4 @@ -# inet_ntop.m4 serial 8 +# 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, @@ -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/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4 index fcd3391..2144203 100644 --- a/gl/m4/lib-link.m4 +++ b/gl/m4/lib-link.m4 @@ -1,4 +1,4 @@ -# lib-link.m4 serial 18 (gettext-0.18) +# lib-link.m4 serial 19 (gettext-0.18) 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, @@ -43,12 +43,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS], popdef([Name]) ]) -dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) +dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message]) dnl searches for libname and the libraries corresponding to explicit and dnl implicit dependencies, together with the specified include files and -dnl the ability to compile and link the specified testcode. If found, it -dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and -dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and +dnl the ability to compile and link the specified testcode. The missing-message +dnl defaults to 'no' and may contain additional hints for the user. +dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} +dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname @@ -74,12 +75,14 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ ac_save_LIBS="$LIBS" LIBS="$LIBS $LIB[]NAME" - AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) + AC_TRY_LINK([$3], [$4], + [ac_cv_lib[]Name=yes], + [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])']) LIBS="$ac_save_LIBS" ]) if test "$ac_cv_lib[]Name" = yes; then HAVE_LIB[]NAME=yes - AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) + AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib[]$1 library.]) AC_MSG_CHECKING([how to link with lib[]$1]) AC_MSG_RESULT([$LIB[]NAME]) else diff --git a/gl/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4 index 3bdc0fc..4b7ee33 100644 --- a/gl/m4/lib-prefix.m4 +++ b/gl/m4/lib-prefix.m4 @@ -1,5 +1,5 @@ -# lib-prefix.m4 serial 6 (gettext-0.18) -dnl Copyright (C) 2001-2005, 2008 Free Software Foundation, Inc. +# lib-prefix.m4 serial 7 (gettext-0.18) +dnl Copyright (C) 2001-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. @@ -206,6 +206,9 @@ sixtyfour bits if test -d "$searchdir"; then case "$searchdir" in */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; + */../ | */.. ) + # Better ignore directories of this form. They are misleading. + ;; *) searchdir=`cd "$searchdir" && pwd` case "$searchdir" in */lib64 ) acl_libdirstem=lib64 ;; diff --git a/gl/m4/locale-fr.m4 b/gl/m4/locale-fr.m4 index e471839..653a5bc 100644 --- a/gl/m4/locale-fr.m4 +++ b/gl/m4/locale-fr.m4 @@ -1,4 +1,4 @@ -# locale-fr.m4 serial 10 +# 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, @@ -12,25 +12,7 @@ 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], [ - macosx= -changequote(,)dnl - case "$host_os" in - darwin[56]*) ;; - darwin*) macosx=yes;; - esac -changequote([,])dnl - if test -n "$macosx"; then - # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8 - # encodings, but the kernel does not support them. 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." - # See the comments in config.charset. Therefore we bypass the test. - gt_cv_locale_fr=none - else - AC_LANG_CONFTEST([AC_LANG_SOURCE([ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ changequote(,)dnl #include #include @@ -75,42 +57,41 @@ int main () { 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 + ])]) + 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 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 + # 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 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 + # 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 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 + # 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 - # 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 + # None found. + gt_cv_locale_fr=none fi fi fi fi fi - rm -fr conftest* fi + rm -fr conftest* ]) LOCALE_FR=$gt_cv_locale_fr AC_SUBST([LOCALE_FR]) diff --git a/gl/m4/locale-ja.m4 b/gl/m4/locale-ja.m4 index c80c5af..9360576 100644 --- a/gl/m4/locale-ja.m4 +++ b/gl/m4/locale-ja.m4 @@ -1,4 +1,4 @@ -# locale-ja.m4 serial 6 +# 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, @@ -12,25 +12,7 @@ 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], [ - macosx= -changequote(,)dnl - case "$host_os" in - darwin[56]*) ;; - darwin*) macosx=yes;; - esac -changequote([,])dnl - if test -n "$macosx"; then - # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8 - # encodings, but the kernel does not support them. 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." - # See the comments in config.charset. Therefore we bypass the test. - gt_cv_locale_ja=none - else - AC_LANG_CONFTEST([AC_LANG_SOURCE([ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ changequote(,)dnl #include #include @@ -79,47 +61,46 @@ int main () 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 + ])]) + 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 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 + # 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 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 + # 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 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 + # 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 - # 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 + # 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 - # 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 + # None found. + gt_cv_locale_ja=none fi fi fi fi fi fi - rm -fr conftest* fi + rm -fr conftest* ]) LOCALE_JA=$gt_cv_locale_ja AC_SUBST([LOCALE_JA]) diff --git a/gl/m4/locale-zh.m4 b/gl/m4/locale-zh.m4 index ba7f9c5..36a5f1d 100644 --- a/gl/m4/locale-zh.m4 +++ b/gl/m4/locale-zh.m4 @@ -1,4 +1,4 @@ -# locale-zh.m4 serial 5 +# 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, @@ -12,25 +12,7 @@ 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], [ - macosx= -changequote(,)dnl - case "$host_os" in - darwin[56]*) ;; - darwin*) macosx=yes;; - esac -changequote([,])dnl - if test -n "$macosx"; then - # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8 - # encodings, but the kernel does not support them. 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." - # See the comments in config.charset. Therefore we bypass the test. - gt_cv_locale_zh_CN=none - else - AC_LANG_CONFTEST([AC_LANG_SOURCE([ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ changequote(,)dnl #include #include @@ -80,31 +62,30 @@ int main () 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 + ])]) + 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 - # 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 + # None found. + gt_cv_locale_zh_CN=none 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* + 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/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4 index 726497b..11d7d23 100644 --- a/gl/m4/mbrtowc.m4 +++ b/gl/m4/mbrtowc.m4 @@ -1,4 +1,4 @@ -# mbrtowc.m4 serial 13 +# mbrtowc.m4 serial 15 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, @@ -65,9 +65,15 @@ AC_DEFUN([gl_MBSTATE_T_BROKEN], 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=0 ;; - *) REPLACE_MBSTATE_T=1 ;; + *yes) ;; + *) REPLACE_MBSTATE_T=1 ;; + esac + case "$gl_cv_func_mbrtowc_sanitycheck" in + *yes) ;; + *) REPLACE_MBSTATE_T=1 ;; esac else REPLACE_MBSTATE_T=1 @@ -121,7 +127,58 @@ int main () }], [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 +#include +#include +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 ]) ]) @@ -168,7 +225,7 @@ int main () return 1; } return 0; -}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], []) +}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [:]) fi ]) ]) @@ -238,7 +295,7 @@ int main () }], [gl_cv_func_mbrtowc_retval=yes], [gl_cv_func_mbrtowc_retval=no], - []) + [:]) fi ]) ]) @@ -258,10 +315,10 @@ AC_DEFUN([gl_MBRTOWC_NUL_RETVAL], dnl is present. changequote(,)dnl case "$host_os" in - # Guess no on Solaris 9. - solaris2.9) gl_cv_func_mbrtowc_nul_retval="guessing no" ;; - # Guess yes otherwise. - *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;; + # 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 @@ -271,7 +328,7 @@ changequote([,])dnl #include int main () { - /* This fails on Solaris 9. */ + /* This fails on Solaris 8 and 9. */ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) { mbstate_t state; @@ -285,7 +342,7 @@ int main () }], [gl_cv_func_mbrtowc_nul_retval=yes], [gl_cv_func_mbrtowc_nul_retval=no], - []) + [:]) fi ]) ]) diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4 index 223b9f1..1e926e8 100644 --- a/gl/m4/mktime.m4 +++ b/gl/m4/mktime.m4 @@ -1,4 +1,4 @@ -# serial 14 +# 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, @@ -15,6 +15,13 @@ dnl From Jim Meyering. AC_DEFUN([AC_FUNC_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. */ diff --git a/gl/m4/multiarch.m4 b/gl/m4/multiarch.m4 index 7b73e15..ec377ba 100644 --- a/gl/m4/multiarch.m4 +++ b/gl/m4/multiarch.m4 @@ -1,5 +1,5 @@ -# multiarch.m4 serial 3 -dnl Copyright (C) 2008 Free Software Foundation, Inc. +# 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. @@ -19,16 +19,7 @@ dnl with or without modifications, as long as this notice is preserved. # 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([gl_MULTIARCH], -[ - dnl This AC_REQUIRE is not necessary in theory. It works around a bug in - dnl autoconf <= 2.63: AC_REQUIRE invocations inside AC_REQUIREd macros are - dnl being handled better than AC_REQUIRE invocations inside normally invoked - dnl macros. - AC_REQUIRE([gl_MULTIARCH_BODY]) -]) - -AC_DEFUN([gl_MULTIARCH_BODY], +AC_DEFUN_ONCE([gl_MULTIARCH], [ dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN. gl_cv_c_multiarch=no diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4 index 4d10993..87aa45c 100644 --- a/gl/m4/printf.m4 +++ b/gl/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 26 +# 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, @@ -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,7 +238,7 @@ 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. @@ -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: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +#include +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. @@ -1142,7 +1233,7 @@ AC_DEFUN([gl_SNPRINTF_SIZE1], #include 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'; }], @@ -1160,7 +1251,7 @@ dnl --------------------------------------------------------------------- dnl #include 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 } @@ -1181,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 } @@ -1209,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'; }], @@ -1261,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... @@ -1281,42 +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 Haiku . . . # # # . . . . . . ? . . . . . . -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/gl/m4/regex.m4 b/gl/m4/regex.m4 index 43b0463..aef53d2 100644 --- a/gl/m4/regex.m4 +++ b/gl/m4/regex.m4 @@ -1,4 +1,4 @@ -# serial 53 +# serial 54 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008, 2009 Free Software Foundation, Inc. @@ -18,12 +18,9 @@ AC_DEFUN([gl_REGEX], AC_ARG_WITH([included-regex], [AS_HELP_STRING([--without-included-regex], - [don't compile regex; this is the default on 32-bit - systems with recent-enough versions of the GNU C - Library (use with caution on other systems). - On systems with 64-bit ptrdiff_t and 32-bit int, - --with-included-regex is the default, in case - regex functions operate on very long strings (>2GB)])]) + [don't compile regex; this is the default on systems + with recent-enough versions of the GNU C Library + (use with caution on other systems).])]) case $with_included_regex in #( yes|no) ac_use_included_regex=$with_included_regex diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4 index b4194c8..a2e8bdd 100644 --- a/gl/m4/stdint.m4 +++ b/gl/m4/stdint.m4 @@ -1,4 +1,4 @@ -# stdint.m4 serial 33 +# 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, @@ -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 +] +gl_STDINT_INCLUDES +[ +#include +#include +#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= diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4 index 60b4bd7..846b65d 100644 --- a/gl/m4/stdio_h.m4 +++ b/gl/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 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. @@ -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]) @@ -86,6 +88,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]) diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4 index 582db13..b295f16 100644 --- a/gl/m4/stdlib_h.m4 +++ b/gl/m4/stdlib_h.m4 @@ -1,5 +1,5 @@ -# stdlib_h.m4 serial 13 -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,9 +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 ]]) + [[#include + #if HAVE_RANDOM_H + # include + #endif + ]]) ]) AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], diff --git a/gl/m4/strdup.m4 b/gl/m4/strdup.m4 new file mode 100644 index 0000000..d7daac2 --- /dev/null +++ b/gl/m4/strdup.m4 @@ -0,0 +1,38 @@ +# strdup.m4 serial 11 + +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. + +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/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4 index 85a0ace..d1cb9c2 100644 --- a/gl/m4/sys_socket_h.m4 +++ b/gl/m4/sys_socket_h.m4 @@ -1,5 +1,5 @@ # sys_socket_h.m4 serial 12 -dnl Copyright (C) 2005-2008 Free Software Foundation, Inc. +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,32 +40,54 @@ 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],,,[ + /* 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 +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#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 -n "$SYS_SOCKET_H"; then - dnl Check prerequisites of the 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 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 replacement and of the # replacement. # Sets and substitutes HAVE_WINSOCK2_H. @@ -114,4 +136,5 @@ 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]) ]) diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4 index 5685273..ff9a4ea 100644 --- a/gl/m4/unistd_h.m4 +++ b/gl/m4/unistd_h.m4 @@ -1,5 +1,5 @@ -# unistd_h.m4 serial 16 -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. @@ -48,6 +48,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], 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]) @@ -63,6 +64,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], 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/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4 index 9e839d2..3a1d1e0 100644 --- a/gl/m4/vasnprintf.m4 +++ b/gl/m4/vasnprintf.m4 @@ -1,4 +1,4 @@ -# vasnprintf.m4 serial 26 +# 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, @@ -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 ]) @@ -66,7 +66,7 @@ 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 @@ -150,6 +150,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F], 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], [ @@ -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/gl/m4/wchar.m4 b/gl/m4/wchar.m4 index ba8ee6a..2e52a82 100644 --- a/gl/m4/wchar.m4 +++ b/gl/m4/wchar.m4 @@ -1,13 +1,13 @@ dnl A placeholder for ISO C99 , 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 22 +# wchar.m4 serial 23 AC_DEFUN([gl_WCHAR_H], [ @@ -73,27 +73,28 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], 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_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_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/gl/m4/wcrtomb.m4 b/gl/m4/wcrtomb.m4 index 22d9433..cb7d926 100644 --- a/gl/m4/wcrtomb.m4 +++ b/gl/m4/wcrtomb.m4 @@ -1,5 +1,5 @@ -# wcrtomb.m4 serial 2 -dnl Copyright (C) 2008 Free Software Foundation, Inc. +# wcrtomb.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. @@ -9,12 +9,16 @@ AC_DEFUN([gl_FUNC_WCRTOMB], AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) AC_REQUIRE([AC_TYPE_MBSTATE_T]) + gl_MBSTATE_T_BROKEN + if test $REPLACE_MBSTATE_T = 1; then + REPLACE_WCRTOMB=1 + fi AC_CHECK_FUNCS_ONCE([wcrtomb]) if test $ac_cv_func_wcrtomb = no; then HAVE_WCRTOMB=0 - else - - dnl On OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes + fi + if test $HAVE_WCRTOMB != 0 && test $REPLACE_WCRTOMB != 1; then + dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes dnl returns 0 instead of 1. AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([gt_LOCALE_FR]) @@ -29,10 +33,10 @@ AC_DEFUN([gl_FUNC_WCRTOMB], dnl is present. changequote(,)dnl case "$host_os" in - # Guess no on OSF/1 and Solaris. - osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;; - # Guess yes otherwise. - *) gl_cv_func_wcrtomb_retval="guessing yes" ;; + # Guess no on AIX 4, OSF/1 and Solaris. + aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_wcrtomb_retval="guessing yes" ;; esac changequote([,])dnl if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then @@ -67,7 +71,7 @@ int main () }], [gl_cv_func_wcrtomb_retval=yes], [gl_cv_func_wcrtomb_retval=no], - []) + [:]) fi ]) case "$gl_cv_func_wcrtomb_retval" in diff --git a/gl/math.in.h b/gl/math.in.h index 6e1b9a2..a0efefd 100644 --- a/gl/math.in.h +++ b/gl/math.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 2002-2003, 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 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 @@ -518,7 +518,8 @@ extern int gl_signbitf (float arg); extern int gl_signbitd (double arg); extern int gl_signbitl (long double arg); # if __GNUC__ >= 2 && !__STRICT_ANSI__ -# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT +# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf +# define gl_signbitf_OPTIMIZED_MACRO # define gl_signbitf(arg) \ ({ union { float _value; \ unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ @@ -527,7 +528,8 @@ extern int gl_signbitl (long double arg); (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ }) # endif -# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT +# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd +# define gl_signbitd_OPTIMIZED_MACRO # define gl_signbitd(arg) \ ({ union { double _value; \ unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ @@ -536,7 +538,8 @@ extern int gl_signbitl (long double arg); (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ }) # endif -# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT +# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl +# define gl_signbitl_OPTIMIZED_MACRO # define gl_signbitl(arg) \ ({ union { long double _value; \ unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ diff --git a/gl/mbrtowc.c b/gl/mbrtowc.c index 603f006..0fec5f1 100644 --- a/gl/mbrtowc.c +++ b/gl/mbrtowc.c @@ -1,5 +1,5 @@ /* Convert multibyte character to wide character. - Copyright (C) 1999-2002, 2005-2008 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2005-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify @@ -89,7 +89,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) return (size_t)(-1); } - /* Here 0 < m ≤ 4. */ + /* Here m > 0. */ # if __GLIBC__ /* Work around bug */ @@ -118,7 +118,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) lack mbrtowc(), we use the second approach. The possible encodings are: - 8-bit encodings, - - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, SJIS, + - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, - UTF-8. Use specialized code for each. */ if (m >= 4 || m >= MB_CUR_MAX) @@ -238,6 +238,39 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) } 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) @@ -258,10 +291,14 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) incomplete: { size_t k = nstate; - /* Here 0 < k < m < 4. */ + /* Here 0 <= k < m < 4. */ pstate[++k] = s[0]; if (k < m) - pstate[++k] = s[1]; + { + pstate[++k] = s[1]; + if (k < m) + pstate[++k] = s[2]; + } if (k != m) abort (); } diff --git a/gl/mountlist.c b/gl/mountlist.c index 4c975c6..50e90ee 100644 --- a/gl/mountlist.c +++ b/gl/mountlist.c @@ -1,7 +1,6 @@ /* mountlist.c -- return a list of mounted file systems - Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1991, 1992, 1997-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 @@ -24,6 +23,7 @@ #include #include #include +#include #include "xalloc.h" @@ -134,10 +134,6 @@ # include "unlocked-io.h" #endif -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - /* The results of open() in this file are not used with fchdir, therefore save some unnecessary work in fchdir.c. */ #undef open @@ -300,7 +296,6 @@ fstype_to_string (int t) /* Return the device number from MOUNT_OPTIONS, if possible. Otherwise return (dev_t) -1. */ - static dev_t dev_from_mount_options (char const *mount_options) { @@ -327,7 +322,7 @@ dev_from_mount_options (char const *mount_options) } # endif - + (void) mount_options; return -1; } @@ -344,6 +339,7 @@ read_file_system_list (bool need_fs_type) struct mount_entry *mount_list; struct mount_entry *me; struct mount_entry **mtail = &mount_list; + (void) need_fs_type; #ifdef MOUNTED_LISTMNTENT { @@ -378,7 +374,7 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ { struct mntent *mnt; - char *table = MOUNTED; + char const *table = MOUNTED; FILE *fp; fp = setmntent (table, "r"); diff --git a/gl/regex_internal.h b/gl/regex_internal.h index ac34811..dc322ec 100644 --- a/gl/regex_internal.h +++ b/gl/regex_internal.h @@ -184,10 +184,6 @@ typedef unsigned long int bitset_word_t; # if BITSET_WORD_BITS <= SBC_MAX # error "Invalid SBC_MAX" # endif -#elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff -/* Work around a bug in 64-bit PGC (before version 6.1-2), where the - preprocessor mishandles large unsigned values as if they were signed. */ -# define BITSET_WORD_BITS 64 #else # error "Add case for new bitset_word_t size" #endif diff --git a/gl/stdint.in.h b/gl/stdint.in.h index f141c8f..53aa34a 100644 --- a/gl/stdint.in.h +++ b/gl/stdint.in.h @@ -435,7 +435,7 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - #undef PTRDIFF_MIN #undef PTRDIFF_MAX #if @APPLE_UNIVERSAL_BUILD@ -# if _LP64 +# ifdef _LP64 # define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l) # define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l) # else @@ -463,7 +463,7 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - /* size_t limit */ #undef SIZE_MAX #if @APPLE_UNIVERSAL_BUILD@ -# if _LP64 +# ifdef _LP64 # define SIZE_MAX _STDINT_MAX (0, 64, 0ul) # else # define SIZE_MAX _STDINT_MAX (0, 32, 0ul) diff --git a/gl/stdio.in.h b/gl/stdio.in.h index 96cb257..cb273d7 100644 --- a/gl/stdio.in.h +++ b/gl/stdio.in.h @@ -216,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 diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h index 3820b10..f99767f 100644 --- a/gl/stdlib.in.h +++ b/gl/stdlib.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - 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 General Public License as published by @@ -41,6 +41,12 @@ # include #endif +/* OSF/1 5.1 declares 'struct random_data' in , which is included + from if _REENTRANT is defined. Include it always. */ +#if @HAVE_RANDOM_H@ +# include +#endif + #if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@ # include #endif diff --git a/gl/strdup.c b/gl/strdup.c new file mode 100644 index 0000000..bebe5c8 --- /dev/null +++ b/gl/strdup.c @@ -0,0 +1,55 @@ +/* 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 General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _LIBC +# include +#endif + +/* Get specification. */ +#include + +#include + +#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/gl/strerror.c b/gl/strerror.c index 787575f..798d854 100644 --- a/gl/strerror.c +++ b/gl/strerror.c @@ -1,6 +1,6 @@ /* strerror.c --- POSIX compatible system error routine - 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 General Public License as published by @@ -40,94 +40,133 @@ 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: - return "Text file busy"; + msg = "Text file busy"; + break; # endif # if GNULIB_defined_ESOCK /* native Windows platforms */ /* EWOULDBLOCK is the same as EAGAIN. */ case EINPROGRESS: - return "Operation now in progress"; + msg = "Operation now in progress"; + break; case EALREADY: - return "Operation already in progress"; + msg = "Operation already in progress"; + break; case ENOTSOCK: - return "Socket operation on non-socket"; + msg = "Socket operation on non-socket"; + break; case EDESTADDRREQ: - return "Destination address required"; + msg = "Destination address required"; + break; case EMSGSIZE: - return "Message too long"; + msg = "Message too long"; + break; case EPROTOTYPE: - return "Protocol wrong type for socket"; + msg = "Protocol wrong type for socket"; + break; case ENOPROTOOPT: - return "Protocol not available"; + msg = "Protocol not available"; + break; case EPROTONOSUPPORT: - return "Protocol not supported"; + msg = "Protocol not supported"; + break; case ESOCKTNOSUPPORT: - return "Socket type not supported"; + msg = "Socket type not supported"; + break; case EOPNOTSUPP: - return "Operation not supported"; + msg = "Operation not supported"; + break; case EPFNOSUPPORT: - return "Protocol family not supported"; + msg = "Protocol family not supported"; + break; case EAFNOSUPPORT: - return "Address family not supported by protocol"; + msg = "Address family not supported by protocol"; + break; case EADDRINUSE: - return "Address already in use"; + msg = "Address already in use"; + break; case EADDRNOTAVAIL: - return "Cannot assign requested address"; + msg = "Cannot assign requested address"; + break; case ENETDOWN: - return "Network is down"; + msg = "Network is down"; + break; case ENETUNREACH: - return "Network is unreachable"; + msg = "Network is unreachable"; + break; case ENETRESET: - return "Network dropped connection on reset"; + msg = "Network dropped connection on reset"; + break; case ECONNABORTED: - return "Software caused connection abort"; + msg = "Software caused connection abort"; + break; case ECONNRESET: - return "Connection reset by peer"; + msg = "Connection reset by peer"; + break; case ENOBUFS: - return "No buffer space available"; + msg = "No buffer space available"; + break; case EISCONN: - return "Transport endpoint is already connected"; + msg = "Transport endpoint is already connected"; + break; case ENOTCONN: - return "Transport endpoint is not connected"; + msg = "Transport endpoint is not connected"; + break; case ESHUTDOWN: - return "Cannot send after transport endpoint shutdown"; + msg = "Cannot send after transport endpoint shutdown"; + break; case ETOOMANYREFS: - return "Too many references: cannot splice"; + msg = "Too many references: cannot splice"; + break; case ETIMEDOUT: - return "Connection timed out"; + msg = "Connection timed out"; + break; case ECONNREFUSED: - return "Connection refused"; + msg = "Connection refused"; + break; case ELOOP: - return "Too many levels of symbolic links"; + msg = "Too many levels of symbolic links"; + break; case EHOSTDOWN: - return "Host is down"; + msg = "Host is down"; + break; case EHOSTUNREACH: - return "No route to host"; + msg = "No route to host"; + break; case EPROCLIM: - return "Too many processes"; + msg = "Too many processes"; + break; case EUSERS: - return "Too many users"; + msg = "Too many users"; + break; case EDQUOT: - return "Disk quota exceeded"; + msg = "Disk quota exceeded"; + break; case ESTALE: - return "Stale NFS file handle"; + msg = "Stale NFS file handle"; + break; case EREMOTE: - return "Object is remote"; + 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: - return "Overlapped operation aborted"; + msg = "Overlapped operation aborted"; + break; case WSA_IO_INCOMPLETE: - return "Overlapped I/O event object not in signaled state"; + msg = "Overlapped I/O event object not in signaled state"; + break; case WSA_IO_PENDING: - return "Overlapped operations will complete later"; + msg = "Overlapped operations will complete later"; + break; /* WSAEINTR maps to EINTR */ /* WSAEBADF maps to EBADF */ /* WSAEACCES maps to EACCES */ @@ -172,98 +211,127 @@ rpl_strerror (int n) /* WSAESTALE is ESTALE */ /* WSAEREMOTE is EREMOTE */ case WSASYSNOTREADY: - return "Network subsystem is unavailable"; + msg = "Network subsystem is unavailable"; + break; case WSAVERNOTSUPPORTED: - return "Winsock.dll version out of range"; + msg = "Winsock.dll version out of range"; + break; case WSANOTINITIALISED: - return "Successful WSAStartup not yet performed"; + msg = "Successful WSAStartup not yet performed"; + break; case WSAEDISCON: - return "Graceful shutdown in progress"; + msg = "Graceful shutdown in progress"; + break; case WSAENOMORE: case WSA_E_NO_MORE: - return "No more results"; + msg = "No more results"; + break; case WSAECANCELLED: case WSA_E_CANCELLED: - return "Call was canceled"; + msg = "Call was canceled"; + break; case WSAEINVALIDPROCTABLE: - return "Procedure call table is invalid"; + msg = "Procedure call table is invalid"; + break; case WSAEINVALIDPROVIDER: - return "Service provider is invalid"; + msg = "Service provider is invalid"; + break; case WSAEPROVIDERFAILEDINIT: - return "Service provider failed to initialize"; + msg = "Service provider failed to initialize"; + break; case WSASYSCALLFAILURE: - return "System call failure"; + msg = "System call failure"; + break; case WSASERVICE_NOT_FOUND: - return "Service not found"; + msg = "Service not found"; + break; case WSATYPE_NOT_FOUND: - return "Class type not found"; + msg = "Class type not found"; + break; case WSAEREFUSED: - return "Database query was refused"; + msg = "Database query was refused"; + break; case WSAHOST_NOT_FOUND: - return "Host not found"; + msg = "Host not found"; + break; case WSATRY_AGAIN: - return "Nonauthoritative host not found"; + msg = "Nonauthoritative host not found"; + break; case WSANO_RECOVERY: - return "Nonrecoverable error"; + msg = "Nonrecoverable error"; + break; case WSANO_DATA: - return "Valid name, no data record of requested type"; + msg = "Valid name, no data record of requested type"; + break; /* WSA_QOS_* omitted */ # endif # endif # if GNULIB_defined_ENOMSG case ENOMSG: - return "No message of desired type"; + msg = "No message of desired type"; + break; # endif # if GNULIB_defined_EIDRM case EIDRM: - return "Identifier removed"; + msg = "Identifier removed"; + break; # endif # if GNULIB_defined_ENOLINK case ENOLINK: - return "Link has been severed"; + msg = "Link has been severed"; + break; # endif # if GNULIB_defined_EPROTO case EPROTO: - return "Protocol error"; + msg = "Protocol error"; + break; # endif # if GNULIB_defined_EMULTIHOP case EMULTIHOP: - return "Multihop attempted"; + msg = "Multihop attempted"; + break; # endif # if GNULIB_defined_EBADMSG case EBADMSG: - return "Bad message"; + msg = "Bad message"; + break; # endif # if GNULIB_defined_EOVERFLOW case EOVERFLOW: - return "Value too large for defined data type"; + msg = "Value too large for defined data type"; + break; # endif # if GNULIB_defined_ENOTSUP case ENOTSUP: - return "Not supported"; + msg = "Not supported"; + break; # endif # if GNULIB_defined_ case ECANCELED: - return "Operation canceled"; + 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 mesg[sizeof fmt + INT_STRLEN_BOUND (n)]; - sprintf (mesg, fmt, n); - return mesg; + static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)]; + sprintf (msg_buf, fmt, n); + return msg_buf; } return result; diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h index 5d9b3cd..dadd56a 100644 --- a/gl/sys_socket.in.h +++ b/gl/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 @@ -43,6 +43,26 @@ #ifndef _GL_SYS_SOCKET_H #define _GL_SYS_SOCKET_H +#if !@HAVE_STRUCT_SOCKADDR_STORAGE@ +# include +/* 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 . */ @@ -256,7 +276,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 @@ -358,7 +378,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 diff --git a/gl/unistd.in.h b/gl/unistd.in.h index 1b2f80e..fa8d84a 100644 --- a/gl/unistd.in.h +++ b/gl/unistd.in.h @@ -1,5 +1,5 @@ /* Substitute for and wrapper around . - Copyright (C) 2003-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 General Public License as published by @@ -29,7 +29,7 @@ #ifndef _GL_UNISTD_H #define _GL_UNISTD_H -/* mingw doesn't define the SEEK_* macros in . */ +/* mingw doesn't define the SEEK_* or *_FILENO macros in . */ #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) # include #endif @@ -87,6 +87,17 @@ /* 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 @@ -120,10 +131,6 @@ extern int chown (const char *file, uid_t uid, gid_t gid); #if @GNULIB_CLOSE@ -# if @UNISTD_H_HAVE_WINSOCK2_H@ -/* Need a gnulib internal function. */ -# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1 -# endif # if @REPLACE_CLOSE@ /* Automatically included by modules that need a replacement for close. */ # undef close @@ -475,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 + . */ +# 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/gl/vasnprintf.c b/gl/vasnprintf.c index 93aef6f..7ac9f43 100644 --- a/gl/vasnprintf.c +++ b/gl/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 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=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/gl/wchar.in.h b/gl/wchar.in.h index cc436b1..cc5baad 100644 --- a/gl/wchar.in.h +++ b/gl/wchar.in.h @@ -264,7 +264,11 @@ extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t /* Convert a wide string to a string. */ #if @GNULIB_WCSNRTOMBS@ -# if !@HAVE_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 diff --git a/gl/xmalloc.c b/gl/xmalloc.c index 89ecf17..585fb4b 100644 --- a/gl/xmalloc.c +++ b/gl/xmalloc.c @@ -1,7 +1,7 @@ /* xmalloc.c -- malloc with out of memory checking Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, + 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2008-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -28,10 +28,6 @@ #include #include -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - /* 1 if calloc is known to be compatible with GNU calloc. This matters if we are not also using the calloc module, which defines HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ -- cgit v0.10-9-g596f