From 29114a419a8edcc45ac2a71517cc198081ccb341 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Wed, 2 Jan 2008 16:04:37 +0100 Subject: Update gnulib files. --- gl/fseeko.c | 3 + gl/m4/gnulib-comp.m4 | 69 +++++++++++++++- gl/progname.c | 4 +- gl/version-etc.c | 4 +- lgl/Makefile.am | 39 +++++++-- lgl/float.in.h | 2 +- lgl/m4/float_h.m4 | 4 +- lgl/m4/gnulib-comp.m4 | 82 +++++++++++++++++- lgl/m4/memmem.m4 | 14 +++- lgl/m4/stdlib_h.m4 | 7 +- lgl/m4/string_h.m4 | 3 + lgl/m4/unistd_h.m4 | 1 + lgl/memmem.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++---- lgl/stdint.in.h | 10 ++- lgl/stdlib.in.h | 25 +++++- lgl/string.in.h | 5 +- lgl/unistd.in.h | 5 +- 17 files changed, 461 insertions(+), 41 deletions(-) diff --git a/gl/fseeko.c b/gl/fseeko.c index 8fffb2b0f6..0e6dfab169 100644 --- a/gl/fseeko.c +++ b/gl/fseeko.c @@ -111,6 +111,9 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) #if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ fp->_offset = pos; fp->_flags |= __SOFF; + fp->_flags &= ~__SEOF; +#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */ + fp->_flag &= ~_IOEOF; #endif return 0; } diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 39dc6ebc3e..1c484848da 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -39,11 +39,11 @@ AC_DEFUN([gl_EARLY], # "Check for header files, types and library functions". AC_DEFUN([gl_INIT], [ + AM_CONDITIONAL([GL_COND_LIBTOOL], [true]) + gl_cond_libtool=true m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) - AM_CONDITIONAL([GL_COND_LIBTOOL], [true]) - gl_cond_libtool=true gl_source_base='gl' gl_HEADER_ARPA_INET AC_PROG_MKDIR_P @@ -89,6 +89,29 @@ AC_DEFUN([gl_INIT], AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) ]) + gltests_libdeps= + gltests_ltlibdeps= + m4_pushdef([AC_LIBOBJ], m4_defn([gltests_LIBOBJ])) + m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gltests_REPLACE_FUNCS])) + m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES])) + gl_source_base='gl/tests' + m4_popdef([AC_LIBSOURCES]) + m4_popdef([AC_REPLACE_FUNCS]) + m4_popdef([AC_LIBOBJ]) + AC_CONFIG_COMMANDS_PRE([ + gltests_libobjs= + gltests_ltlibobjs= + if test -n "$gltests_LIBOBJS"; then + # Remove the extension. + sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do + gltests_libobjs="$gltests_libobjs $i.$ac_objext" + gltests_ltlibobjs="$gltests_ltlibobjs $i.lo" + done + fi + AC_SUBST([gltests_LIBOBJS], [$gltests_libobjs]) + AC_SUBST([gltests_LTLIBOBJS], [$gltests_ltlibobjs]) + ]) ]) # Like AC_LIBOBJ, except that the module name goes @@ -98,6 +121,13 @@ AC_DEFUN([gl_LIBOBJ], [ gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext" ]) +# m4_foreach_w is provided by autoconf-2.59c and later. +# This definition is to accommodate developers using versions +# of autoconf older than that. +m4_ifndef([m4_foreach_w], + [m4_define([m4_foreach_w], + [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + # Like AC_REPLACE_FUNCS, except that the module name goes # into gl_LIBOBJS instead of into LIBOBJS. AC_DEFUN([gl_REPLACE_FUNCS], [ @@ -119,6 +149,41 @@ AC_DEFUN([gl_LIBSOURCES], [ ]) ]) +# Like AC_LIBOBJ, except that the module name goes +# into gltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gltests_LIBOBJ], [ + AS_LITERAL_IF([$1], [gltests_LIBSOURCES([$1.c])])dnl + gltests_LIBOBJS="$gltests_LIBOBJS $1.$ac_objext" +]) + +# m4_foreach_w is provided by autoconf-2.59c and later. +# This definition is to accommodate developers using versions +# of autoconf older than that. +m4_ifndef([m4_foreach_w], + [m4_define([m4_foreach_w], + [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + +# Like AC_REPLACE_FUNCS, except that the module name goes +# into gltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gltests_REPLACE_FUNCS], [ + m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl + AC_CHECK_FUNCS([$1], , [gltests_LIBOBJ($ac_func)]) +]) + +# Like AC_LIBSOURCES, except the directory where the source file is +# expected is derived from the gnulib-tool parametrization, +# and alloca is special cased (for the alloca-opt module). +# We could also entirely rely on EXTRA_lib..._SOURCES. +AC_DEFUN([gltests_LIBSOURCES], [ + m4_foreach([_gl_NAME], [$1], [ + m4_if(_gl_NAME, [alloca.c], [], [ + m4_syscmd([test -r gl/tests/]_gl_NAME[ || test ! -d gl/tests])dnl + m4_if(m4_sysval, [0], [], + [AC_FATAL([missing gl/tests/]_gl_NAME)]) + ]) + ]) +]) + # This macro records the list of files which have been installed by # gnulib-tool and may be removed by future gnulib-tool invocations. AC_DEFUN([gl_FILE_LIST], [ diff --git a/gl/progname.c b/gl/progname.c index fa5aa8bec7..47d08c65d5 100644 --- a/gl/progname.c +++ b/gl/progname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2007 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -41,7 +41,7 @@ set_program_name (const char *argv0) slash = strrchr (argv0, '/'); base = (slash != NULL ? slash + 1 : argv0); - if (base - argv0 >= 7 && memcmp (base - 7, "/.libs/", 7) == 0) + if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0) argv0 = base; if (strncmp (base, "lt-", 3) == 0) argv0 = base + 3; diff --git a/gl/version-etc.c b/gl/version-etc.c index 293aaba1f3..823e08562c 100644 --- a/gl/version-etc.c +++ b/gl/version-etc.c @@ -1,5 +1,5 @@ /* Utility to help print --version output in a consistent format. - Copyright (C) 1999-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2008 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -enum { COPYRIGHT_YEAR = 2007 }; +enum { COPYRIGHT_YEAR = 2008 }; /* Like version_etc, below, but with the NULL-terminated author list provided via a variable of type va_list. */ diff --git a/lgl/Makefile.am b/lgl/Makefile.am index af1d330ac0..66004e71bc 100644 --- a/lgl/Makefile.am +++ b/lgl/Makefile.am @@ -230,6 +230,32 @@ EXTRA_DIST += $(top_srcdir)/build-aux/link-warning.h ## end gnulib module link-warning +## begin gnulib module malloca + +liblgnu_la_SOURCES += malloca.c + +EXTRA_DIST += malloca.h malloca.valgrind + +## end gnulib module malloca + +## begin gnulib module memchr + + +EXTRA_DIST += memchr.c + +EXTRA_liblgnu_la_SOURCES += memchr.c + +## end gnulib module memchr + +## begin gnulib module memcmp + + +EXTRA_DIST += memcmp.c + +EXTRA_liblgnu_la_SOURCES += memcmp.c + +## end gnulib module memcmp + ## begin gnulib module memmem @@ -424,13 +450,18 @@ stdlib.h: stdlib.in.h -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ + -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ + -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ + -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/stdlib.in.h; \ } > $@-t @@ -495,6 +526,7 @@ string.h: string.in.h -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ + -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/string.in.h; \ @@ -633,6 +665,7 @@ unistd.h: unistd.in.h -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ + -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ < $(srcdir)/unistd.in.h; \ @@ -693,12 +726,6 @@ liblgnu_la_SOURCES += xsize.h ## end gnulib module xsize -## begin gnulib module dummy - -liblgnu_la_SOURCES += dummy.c - -## end gnulib module dummy - mostlyclean-local: mostlyclean-generic @for dir in '' $(MOSTLYCLEANDIRS); do \ diff --git a/lgl/float.in.h b/lgl/float.in.h index 7cf07915fa..1984fd7342 100644 --- a/lgl/float.in.h +++ b/lgl/float.in.h @@ -24,7 +24,7 @@ #define _GL_FLOAT_H /* 'long double' properties. */ -#if defined __i386__ && defined __BEOS__ +#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) /* Number of mantissa units, in base FLT_RADIX. */ # undef LDBL_MANT_DIG # define LDBL_MANT_DIG 64 diff --git a/lgl/m4/float_h.m4 b/lgl/m4/float_h.m4 index 1b1ad103e9..d36e3a46ca 100644 --- a/lgl/m4/float_h.m4 +++ b/lgl/m4/float_h.m4 @@ -1,4 +1,4 @@ -# float_h.m4 serial 2 +# float_h.m4 serial 3 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,7 +10,7 @@ AC_DEFUN([gl_FLOAT_H], AC_REQUIRE([AC_CANONICAL_HOST]) FLOAT_H= case "$host_os" in - beos*) + beos* | openbsd*) FLOAT_H=float.h gl_CHECK_NEXT_HEADERS([float.h]) ;; diff --git a/lgl/m4/gnulib-comp.m4 b/lgl/m4/gnulib-comp.m4 index b6ade09e21..da6970ce89 100644 --- a/lgl/m4/gnulib-comp.m4 +++ b/lgl/m4/gnulib-comp.m4 @@ -33,11 +33,11 @@ AC_DEFUN([lgl_EARLY], # "Check for header files, types and library functions". AC_DEFUN([lgl_INIT], [ + AM_CONDITIONAL([GL_COND_LIBTOOL], [true]) + gl_cond_libtool=true m4_pushdef([AC_LIBOBJ], m4_defn([lgl_LIBOBJ])) m4_pushdef([AC_REPLACE_FUNCS], m4_defn([lgl_REPLACE_FUNCS])) m4_pushdef([AC_LIBSOURCES], m4_defn([lgl_LIBSOURCES])) - AM_CONDITIONAL([GL_COND_LIBTOOL], [true]) - gl_cond_libtool=true gl_source_base='lgl' gl_FUNC_ALLOCA gl_GC @@ -76,6 +76,9 @@ AC_DEFUN([lgl_INIT], AM_GNU_GETTEXT_VERSION([0.17]) AC_SUBST([LIBINTL]) AC_SUBST([LTLIBINTL]) + gl_MALLOCA + gl_FUNC_MEMCHR + gl_FUNC_MEMCMP gl_FUNC_MEMMEM gl_STRING_MODULE_INDICATOR([memmem]) gl_FUNC_MEMMOVE @@ -125,6 +128,29 @@ AC_DEFUN([lgl_INIT], AC_SUBST([lgl_LIBOBJS], [$lgl_libobjs]) AC_SUBST([lgl_LTLIBOBJS], [$lgl_ltlibobjs]) ]) + gltests_libdeps= + gltests_ltlibdeps= + m4_pushdef([AC_LIBOBJ], m4_defn([lgltests_LIBOBJ])) + m4_pushdef([AC_REPLACE_FUNCS], m4_defn([lgltests_REPLACE_FUNCS])) + m4_pushdef([AC_LIBSOURCES], m4_defn([lgltests_LIBSOURCES])) + gl_source_base='tests' + m4_popdef([AC_LIBSOURCES]) + m4_popdef([AC_REPLACE_FUNCS]) + m4_popdef([AC_LIBOBJ]) + AC_CONFIG_COMMANDS_PRE([ + lgltests_libobjs= + lgltests_ltlibobjs= + if test -n "$lgltests_LIBOBJS"; then + # Remove the extension. + sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $lgltests_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do + lgltests_libobjs="$lgltests_libobjs $i.$ac_objext" + lgltests_ltlibobjs="$lgltests_ltlibobjs $i.lo" + done + fi + AC_SUBST([lgltests_LIBOBJS], [$lgltests_libobjs]) + AC_SUBST([lgltests_LTLIBOBJS], [$lgltests_ltlibobjs]) + ]) ]) # Like AC_LIBOBJ, except that the module name goes @@ -134,6 +160,13 @@ AC_DEFUN([lgl_LIBOBJ], [ lgl_LIBOBJS="$lgl_LIBOBJS $1.$ac_objext" ]) +# m4_foreach_w is provided by autoconf-2.59c and later. +# This definition is to accommodate developers using versions +# of autoconf older than that. +m4_ifndef([m4_foreach_w], + [m4_define([m4_foreach_w], + [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + # Like AC_REPLACE_FUNCS, except that the module name goes # into lgl_LIBOBJS instead of into LIBOBJS. AC_DEFUN([lgl_REPLACE_FUNCS], [ @@ -155,6 +188,41 @@ AC_DEFUN([lgl_LIBSOURCES], [ ]) ]) +# Like AC_LIBOBJ, except that the module name goes +# into lgltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([lgltests_LIBOBJ], [ + AS_LITERAL_IF([$1], [lgltests_LIBSOURCES([$1.c])])dnl + lgltests_LIBOBJS="$lgltests_LIBOBJS $1.$ac_objext" +]) + +# m4_foreach_w is provided by autoconf-2.59c and later. +# This definition is to accommodate developers using versions +# of autoconf older than that. +m4_ifndef([m4_foreach_w], + [m4_define([m4_foreach_w], + [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + +# Like AC_REPLACE_FUNCS, except that the module name goes +# into lgltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([lgltests_REPLACE_FUNCS], [ + m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl + AC_CHECK_FUNCS([$1], , [lgltests_LIBOBJ($ac_func)]) +]) + +# Like AC_LIBSOURCES, except the directory where the source file is +# expected is derived from the gnulib-tool parametrization, +# and alloca is special cased (for the alloca-opt module). +# We could also entirely rely on EXTRA_lib..._SOURCES. +AC_DEFUN([lgltests_LIBSOURCES], [ + m4_foreach([_gl_NAME], [$1], [ + m4_if(_gl_NAME, [alloca.c], [], [ + m4_syscmd([test -r tests/]_gl_NAME[ || test ! -d tests])dnl + m4_if(m4_sysval, [0], [], + [AC_FATAL([missing tests/]_gl_NAME)]) + ]) + ]) +]) + # This macro records the list of files which have been installed by # gnulib-tool and may be removed by future gnulib-tool invocations. AC_DEFUN([lgl_FILE_LIST], [ @@ -169,7 +237,6 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/asprintf.c lib/des.c lib/des.h - lib/dummy.c lib/float+.h lib/float.in.h lib/gc-gnulib.c @@ -180,12 +247,17 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/hmac-md5.c lib/hmac-sha1.c lib/hmac.h + lib/malloca.c + lib/malloca.h + lib/malloca.valgrind lib/md2.c lib/md2.h lib/md4.c lib/md4.h lib/md5.c lib/md5.h + lib/memchr.c + lib/memcmp.c lib/memmem.c lib/memmove.c lib/memxor.c @@ -229,6 +301,7 @@ AC_DEFUN([lgl_FILE_LIST], [ m4/arctwo.m4 m4/codeset.m4 m4/des.m4 + m4/eealloc.m4 m4/eoverflow.m4 m4/extensions.m4 m4/float_h.m4 @@ -269,9 +342,12 @@ AC_DEFUN([lgl_FILE_LIST], [ m4/lock.m4 m4/longlong.m4 m4/malloc.m4 + m4/malloca.m4 m4/md2.m4 m4/md4.m4 m4/md5.m4 + m4/memchr.m4 + m4/memcmp.m4 m4/memmem.m4 m4/memmove.m4 m4/memxor.m4 diff --git a/lgl/m4/memmem.m4 b/lgl/m4/memmem.m4 index e6a3da193c..a529af3bec 100644 --- a/lgl/m4/memmem.m4 +++ b/lgl/m4/memmem.m4 @@ -1,4 +1,4 @@ -# memmem.m4 serial 5 +# memmem.m4 serial 6 dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,6 +14,18 @@ AC_DEFUN([gl_FUNC_MEMMEM], AC_CHECK_DECLS_ONCE(memmem) if test $ac_cv_have_decl_memmem = no; then HAVE_DECL_MEMMEM=0 + else + AC_CACHE_CHECK([whether memmem works], [gl_cv_func_memmem_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], + [return !memmem ("a", 1, NULL, 0);])], + [gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no], + [dnl pessimistically assume the worst, since even glibc 2.6.1 + dnl has quadratic complexity in its memmem + gl_cv_func_memmem_works=no])]) + if test $gl_cv_func_memmem_works = no; then + REPLACE_MEMMEM=1 + AC_LIBOBJ([memmem]) + fi fi gl_PREREQ_MEMMEM ]) diff --git a/lgl/m4/stdlib_h.m4 b/lgl/m4/stdlib_h.m4 index 278df744c7..fe4ce122e9 100644 --- a/lgl/m4/stdlib_h.m4 +++ b/lgl/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 4 +# stdlib_h.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -26,12 +26,17 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) + GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV]) + GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX]) HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX]) + HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) + HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) + VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV]) ]) diff --git a/lgl/m4/string_h.m4 b/lgl/m4/string_h.m4 index 83711799a1..99a0dabbcb 100644 --- a/lgl/m4/string_h.m4 +++ b/lgl/m4/string_h.m4 @@ -5,6 +5,8 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. +# serial 2 + # Written by Paul Eggert. AC_DEFUN([gl_HEADER_STRING_H], @@ -75,4 +77,5 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) + REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) ]) diff --git a/lgl/m4/unistd_h.m4 b/lgl/m4/unistd_h.m4 index 91c02e7c83..4b8857ca5b 100644 --- a/lgl/m4/unistd_h.m4 +++ b/lgl/m4/unistd_h.m4 @@ -55,6 +55,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) + REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) ]) diff --git a/lgl/memmem.c b/lgl/memmem.c index d891fbd13d..def0fa7454 100644 --- a/lgl/memmem.c +++ b/lgl/memmem.c @@ -21,24 +21,147 @@ #include #include +#include + +#include "malloca.h" #ifndef _LIBC # define __builtin_expect(expr, val) (expr) #endif -#undef memmem +/* Knuth-Morris-Pratt algorithm. + See http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm + Return a boolean indicating success. */ + +static bool +knuth_morris_pratt (const char *haystack, const char *last_haystack, + const char *needle, size_t m, + const char **resultp) +{ + /* Allocate the table. */ + size_t *table = (size_t *) nmalloca (m, sizeof (size_t)); + if (table == NULL) + return false; + /* Fill the table. + For 0 < i < m: + 0 < table[i] <= i is defined such that + forall 0 < x < table[i]: needle[x..i-1] != needle[0..i-1-x], + and table[i] is as large as possible with this property. + This implies: + 1) For 0 < i < m: + If table[i] < i, + needle[table[i]..i-1] = needle[0..i-1-table[i]]. + 2) For 0 < i < m: + rhaystack[0..i-1] == needle[0..i-1] + and exists h, i <= h < m: rhaystack[h] != needle[h] + implies + forall 0 <= x < table[i]: rhaystack[x..x+m-1] != needle[0..m-1]. + table[0] remains uninitialized. */ + { + size_t i, j; + + /* i = 1: Nothing to verify for x = 0. */ + table[1] = 1; + j = 0; + + for (i = 2; i < m; i++) + { + /* Here: j = i-1 - table[i-1]. + The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold + for x < table[i-1], by induction. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + unsigned char b = (unsigned char) needle[i - 1]; + + for (;;) + { + /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] + is known to hold for x < i-1-j. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + if (b == (unsigned char) needle[j]) + { + /* Set table[i] := i-1-j. */ + table[i] = i - ++j; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for x = i-1-j, because + needle[i-1] != needle[j] = needle[i-1-x]. */ + if (j == 0) + { + /* The inequality holds for all possible x. */ + table[i] = i; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for i-1-j < x < i-1-j+table[j], because for these x: + needle[x..i-2] + = needle[x-(i-1-j)..j-1] + != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) + = needle[0..i-2-x], + hence needle[x..i-1] != needle[0..i-1-x]. + Furthermore + needle[i-1-j+table[j]..i-2] + = needle[table[j]..j-1] + = needle[0..j-1-table[j]] (by definition of table[j]). */ + j = j - table[j]; + } + /* Here: j = i - table[i]. */ + } + } + + /* Search, using the table to accelerate the processing. */ + { + size_t j; + const char *rhaystack; + const char *phaystack; + + *resultp = NULL; + j = 0; + rhaystack = haystack; + phaystack = haystack; + /* Invariant: phaystack = rhaystack + j. */ + while (phaystack != last_haystack) + if ((unsigned char) needle[j] == (unsigned char) *phaystack) + { + j++; + phaystack++; + if (j == m) + { + /* The entire needle has been found. */ + *resultp = rhaystack; + break; + } + } + else if (j > 0) + { + /* Found a match of needle[0..j-1], mismatch at needle[j]. */ + rhaystack += table[j]; + j -= table[j]; + } + else + { + /* Found a mismatch at needle[0] already. */ + rhaystack++; + phaystack++; + } + } -/* Return the first occurrence of NEEDLE in HAYSTACK. */ + freea (table); + return true; +} + +/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK + if NEEDLE_LEN is 0, otherwise NULL if NEEDLE is not found in + HAYSTACK. */ void * -memmem (haystack, haystack_len, needle, needle_len) - const void *haystack; - size_t haystack_len; - const void *needle; - size_t needle_len; +memmem (const void *haystack_start, size_t haystack_len, + const void *needle_start, size_t needle_len) { - const char *begin; - const char *const last_possible - = (const char *) haystack + haystack_len - needle_len; + /* Operating with void * is awkward. */ + const char *haystack = (const char *) haystack_start; + const char *needle = (const char *) needle_start; + const char *last_haystack = haystack + haystack_len; + const char *last_needle = needle + needle_len; if (needle_len == 0) /* The first occurrence of the empty string is deemed to occur at @@ -50,12 +173,82 @@ memmem (haystack, haystack_len, needle, needle_len) if (__builtin_expect (haystack_len < needle_len, 0)) return NULL; - for (begin = (const char *) haystack; begin <= last_possible; ++begin) - if (begin[0] == ((const char *) needle)[0] && - !memcmp ((const void *) &begin[1], - (const void *) ((const char *) needle + 1), - needle_len - 1)) - return (void *) begin; + /* Use optimizations in memchr when possible. */ + if (__builtin_expect (needle_len == 1, 0)) + return memchr (haystack, (unsigned char) *needle, haystack_len); + + /* Minimizing the worst-case complexity: + Let n = haystack_len, m = needle_len. + The naïve algorithm is O(n*m) worst-case. + The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a + memory allocation. + To achieve linear complexity and yet amortize the cost of the + memory allocation, we activate the Knuth-Morris-Pratt algorithm + only once the naïve algorithm has already run for some time; more + precisely, when + - the outer loop count is >= 10, + - the average number of comparisons per outer loop is >= 5, + - the total number of comparisons is >= m. + But we try it only once. If the memory allocation attempt failed, + we don't retry it. */ + { + bool try_kmp = true; + size_t outer_loop_count = 0; + size_t comparison_count = 0; + + /* Speed up the following searches of needle by caching its first + byte. */ + char b = *needle++; + + for (;; haystack++) + { + if (haystack == last_haystack) + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + if (comparison_count >= needle_len) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + if (knuth_morris_pratt (haystack, last_haystack, + needle - 1, needle_len, &result)) + return (void *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + if (*haystack == b) + /* The first byte matches. */ + { + const char *rhaystack = haystack + 1; + const char *rneedle = needle; + + for (;; rhaystack++, rneedle++) + { + if (rneedle == last_needle) + /* Found a match. */ + return (void *) haystack; + if (rhaystack == last_haystack) + /* No match. */ + return NULL; + comparison_count++; + if (*rhaystack != *rneedle) + /* Nothing in this round. */ + break; + } + } + } + } return NULL; } diff --git a/lgl/stdint.in.h b/lgl/stdint.in.h index af316488d4..fbe39c5447 100644 --- a/lgl/stdint.in.h +++ b/lgl/stdint.in.h @@ -23,6 +23,12 @@ #ifndef _GL_STDINT_H +/* When including a system file that in turn includes , + use the system , not our substitute. This avoids + problems with (for example) VMS, whose includes + . */ +#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H + /* Get those types that are already defined in other system include files, so that we can "#define int8_t signed char" below without worrying about a later system include file containing a "typedef @@ -66,9 +72,7 @@ /* In OpenBSD 3.8, includes , which defines int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. also defines intptr_t and uintptr_t. */ -# define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H # include -# undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H #elif @HAVE_SYS_INTTYPES_H@ /* Solaris 7 has the types except the *_fast*_t types, and the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ @@ -91,6 +95,8 @@ #endif +#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H + /* Minimum and maximum values for a integer type under the usual assumption. Return an unspecified value if BITS == 0, adding a check to pacify picky compilers. */ diff --git a/lgl/stdlib.in.h b/lgl/stdlib.in.h index baebcce973..bc7dc4f9a3 100644 --- a/lgl/stdlib.in.h +++ b/lgl/stdlib.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995, 2001-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1995, 2001-2004, 2006-2007 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -176,6 +176,29 @@ extern int putenv (char *string); #endif +#if @GNULIB_SETENV@ +# if !@HAVE_SETENV@ +/* Set NAME to VALUE in the environment. + If REPLACE is nonzero, overwrite an existing value. */ +extern int setenv (const char *name, const char *value, int replace); +# endif +#endif + + +#if @GNULIB_UNSETENV@ +# if @HAVE_UNSETENV@ +# if @VOID_UNSETENV@ +/* On some systems, unsetenv() returns void. + This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ +# define unsetenv(name) ((unsetenv)(name), 0) +# endif +# else +/* Remove the variable NAME from the environment. */ +extern int unsetenv (const char *name); +# endif +#endif + + #ifdef __cplusplus } #endif diff --git a/lgl/string.in.h b/lgl/string.in.h index a371e5c696..779bb6c0cf 100644 --- a/lgl/string.in.h +++ b/lgl/string.in.h @@ -35,7 +35,10 @@ extern "C" { /* Return the first occurrence of NEEDLE in HAYSTACK. */ #if @GNULIB_MEMMEM@ -# if ! @HAVE_DECL_MEMMEM@ +# if @REPLACE_MEMMEM@ +# define memmem rpl_memmem +# endif +# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ extern void *memmem (void const *__haystack, size_t __haystack_len, void const *__needle, size_t __needle_len); # endif diff --git a/lgl/unistd.in.h b/lgl/unistd.in.h index 4916f75ced..10678f4c99 100644 --- a/lgl/unistd.in.h +++ b/lgl/unistd.in.h @@ -181,7 +181,10 @@ extern int getlogin_r (char *name, size_t size); #if @GNULIB_GETPAGESIZE@ -# if !@HAVE_GETPAGESIZE@ +# if @REPLACE_GETPAGESIZE@ +# define getpagesize rpl_getpagesize +extern int getpagesize (void); +# elif !@HAVE_GETPAGESIZE@ /* This is for POSIX systems. */ # if !defined getpagesize && defined _SC_PAGESIZE # if ! (defined __VMS && __VMS_VER < 70000000) -- cgit v1.2.1