aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gl/Makefile.am8
-rw-r--r--gl/fsusage.c13
-rw-r--r--gl/m4/fcntl-o.m48
-rw-r--r--gl/m4/fsusage.m428
-rw-r--r--gl/m4/gnulib-comp.m42
-rw-r--r--gl/m4/lib-link.m44
-rw-r--r--gl/m4/malloc.m431
-rw-r--r--gl/m4/stdlib_h.m412
-rw-r--r--gl/stdlib.in.h29
-rw-r--r--gl/str-two-way.h59
-rw-r--r--gl/string.in.h38
11 files changed, 163 insertions, 69 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index e9e23026..edc7db15 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -1182,6 +1182,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_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|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
-e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
-e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
-e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
@@ -1206,13 +1207,12 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
-e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
-e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+ -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
-e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
- -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
-e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
-e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
-e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
-e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
- -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
-e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
-e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
-e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
@@ -1221,7 +1221,6 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
-e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
-e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
- -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
-e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
-e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
-e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
@@ -1232,9 +1231,12 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
-e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
-e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
+ -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
-e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
+ -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
+ -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
-e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
-e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
-e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 10db467d..17102aad 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -94,7 +94,7 @@
int
get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
{
-#if defined STAT_STATVFS /* POSIX */
+#if defined STAT_STATVFS /* POSIX, except glibc/Linux */
struct statvfs fsd;
@@ -156,7 +156,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
: (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
-#elif defined STAT_STATFS3_OSF1
+#elif defined STAT_STATFS3_OSF1 /* OSF/1 */
struct statfs fsd;
@@ -165,7 +165,9 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
-#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
+#elif defined STAT_STATFS2_BSIZE /* glibc/Linux, 4.3BSD, SunOS 4, \
+ MacOS X < 10.4, FreeBSD < 5.0, \
+ NetBSD < 3.0, OpenBSD < 4.4 */
struct statfs fsd;
@@ -189,7 +191,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
}
# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
-#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */
+#elif defined STAT_STATFS2_FSIZE /* 4.4BSD and older NetBSD */
struct statfs fsd;
@@ -198,7 +200,8 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
-#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
+#elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \
+ Dolphin */
# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
# define f_bavail f_bfree
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
index d416a61c..1adacc8a 100644
--- a/gl/m4/fcntl-o.m4
+++ b/gl/m4/fcntl-o.m4
@@ -1,4 +1,4 @@
-# fcntl-o.m4 serial 1
+# fcntl-o.m4 serial 2
dnl Copyright (C) 2006, 2009-2010 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,7 +12,11 @@ dnl Written by Paul Eggert.
AC_DEFUN([gl_FCNTL_O_FLAGS],
[
dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
- AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+ dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
+ dnl AC_GNU_SOURCE.
+ m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
+ [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
+ [AC_REQUIRE([AC_GNU_SOURCE])])
AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
diff --git a/gl/m4/fsusage.m4 b/gl/m4/fsusage.m4
index 216b9dd8..68684c27 100644
--- a/gl/m4/fsusage.m4
+++ b/gl/m4/fsusage.m4
@@ -1,4 +1,4 @@
-# serial 25
+# serial 26
# Obtaining file system usage information.
# Copyright (C) 1997-1998, 2000-2001, 2003-2010 Free Software Foundation, Inc.
@@ -44,7 +44,8 @@ ac_fsusage_space=no
# systems. That system is reported to work fine with STAT_STATFS4 which
# is what it gets when this test fails.
if test $ac_fsusage_space = no; then
- # SVR4
+ # glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
+ # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#if defined __GLIBC__ && defined __linux__
@@ -97,8 +98,13 @@ if test $ac_fsusage_space = no; then
fi
if test $ac_fsusage_space = no; then
-# AIX
- AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
+ # glibc/Linux, MacOS X < 10.4, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
+ # (glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
+ # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
+ # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
+ # <sys/vfs.h>.)
+ # (On Solaris, statfs has 4 arguments.)
+ AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
member (AIX, 4.3BSD)])
AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -131,7 +137,8 @@ member (AIX, 4.3BSD)])
fi
if test $ac_fsusage_space = no; then
-# SVR3
+ # SVR3
+ # (Solaris already handled above.)
AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -150,13 +157,17 @@ if test $ac_fsusage_space = no; then
if test $fu_cv_sys_stat_statfs4 = yes; then
ac_fsusage_space=yes
AC_DEFINE([STAT_STATFS4], [1],
- [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
+ [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
fi
fi
if test $ac_fsusage_space = no; then
-# 4.4BSD and NetBSD
- AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
+ # 4.4BSD and older NetBSD
+ # (OSF/1 already handled above.)
+ # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
+ # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
+ # <sys/mount.h>.)
+ AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
member (4.4BSD and NetBSD)])
AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -223,6 +234,7 @@ fi
if test $ac_fsusage_space = no; then
# SVR2
+ # (AIX, HP-UX, OSF/1 already handled above.)
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
]])],
[AC_DEFINE([STAT_READ_FILSYS], [1],
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index fc3f3538..b5e6b438 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -254,7 +254,7 @@ AC_DEFUN([gl_INIT],
# Code from module locale:
gl_LOCALE_H
# Code from module malloc:
- AC_FUNC_MALLOC
+ gl_FUNC_MALLOC_GNU
AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
# Code from module malloc-posix:
gl_FUNC_MALLOC_POSIX
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
index 59b367df..9f3be3a2 100644
--- a/gl/m4/lib-link.m4
+++ b/gl/m4/lib-link.m4
@@ -1,4 +1,4 @@
-# lib-link.m4 serial 23 (gettext-0.18.2)
+# lib-link.m4 serial 24 (gettext-0.18.2)
dnl Copyright (C) 2001-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -165,7 +165,7 @@ AC_DEFUN([AC_LIB_FROMPACKAGE],
pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
[ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
define([acl_libsinpackage_]PACKUP,
- m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1])
+ m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
popdef([PACKUP])
popdef([PACK])
])
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
index 910ac922..fe5befc2 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,25 +1,40 @@
-# malloc.m4 serial 9
+# malloc.m4 serial 10
dnl Copyright (C) 2007, 2009, 2010 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.
+# gl_FUNC_MALLOC_GNU
+# ------------------
+# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
+# it is not.
+AC_DEFUN([gl_FUNC_MALLOC_GNU],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
+ _AC_FUNC_MALLOC_IF(
+ [AC_DEFINE([HAVE_MALLOC], [1],
+ [Define to 1 if your system has a GNU libc compatible 'malloc'
+ function, and to 0 otherwise.])],
+ [AC_DEFINE([HAVE_MALLOC], [0])
+ gl_REPLACE_MALLOC
+ ])
+])
+
# gl_FUNC_MALLOC_POSIX
# --------------------
# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
# fails), and replace malloc if it is not.
AC_DEFUN([gl_FUNC_MALLOC_POSIX],
[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
if test $gl_cv_func_malloc_posix = yes; then
- HAVE_MALLOC_POSIX=1
AC_DEFINE([HAVE_MALLOC_POSIX], [1],
[Define if the 'malloc' function is POSIX compliant.])
else
- AC_LIBOBJ([malloc])
- HAVE_MALLOC_POSIX=0
+ gl_REPLACE_MALLOC
fi
- AC_SUBST([HAVE_MALLOC_POSIX])
])
# Test whether malloc, realloc, calloc are POSIX compliant,
@@ -39,3 +54,9 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX],
], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
])
])
+
+AC_DEFUN([gl_REPLACE_MALLOC],
+[
+ AC_LIBOBJ([malloc])
+ REPLACE_MALLOC=1
+])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index dd84796d..fc150197 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 28
+# stdlib_h.m4 serial 30
dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -33,7 +33,7 @@ AC_DEFUN([gl_STDLIB_H],
#if HAVE_RANDOM_H
# include <random.h>
#endif
- ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
+ ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
unsetenv])
@@ -50,6 +50,7 @@ AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
AC_DEFUN([gl_STDLIB_H_DEFAULTS],
[
+ GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
@@ -75,13 +76,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
- HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
- HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
@@ -89,7 +89,6 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
- HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
@@ -100,9 +99,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
+ REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC])
REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
+ REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
+ REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])
REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index d74c2518..d4ac4690 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -74,6 +74,12 @@ struct random_data
# include <unistd.h>
#endif
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
+# define __attribute__(Spec) /* empty */
+# endif
+#endif
+
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -95,6 +101,23 @@ struct random_data
#endif
+#if @GNULIB__EXIT@
+/* Terminate the current process with the given return code, without running
+ the 'atexit' handlers. */
+# if !@HAVE__EXIT@
+_GL_FUNCDECL_SYS (_Exit, void, (int status) __attribute__ ((__noreturn__)));
+# endif
+_GL_CXXALIAS_SYS (_Exit, void, (int status));
+_GL_CXXALIASWARN (_Exit);
+#elif defined GNULIB_POSIXCHECK
+# undef _Exit
+# if HAVE_RAW_DECL__EXIT
+_GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
+ "use gnulib module _Exit for portability");
+# endif
+#endif
+
+
#if @GNULIB_ATOLL@
/* Parse a signed decimal integer.
Returns the value of the integer. Errors are not detected. */
@@ -112,7 +135,7 @@ _GL_WARN_ON_USE (atoll, "atoll is unportable - "
#endif
#if @GNULIB_CALLOC_POSIX@
-# if !@HAVE_CALLOC_POSIX@
+# if @REPLACE_CALLOC@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef calloc
# define calloc rpl_calloc
@@ -218,7 +241,7 @@ _GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
#endif
#if @GNULIB_MALLOC_POSIX@
-# if !@HAVE_MALLOC_POSIX@
+# if @REPLACE_MALLOC@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef malloc
# define malloc rpl_malloc
@@ -477,7 +500,7 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
#if @GNULIB_REALLOC_POSIX@
-# if !@HAVE_REALLOC_POSIX@
+# if @REPLACE_REALLOC@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef realloc
# define realloc rpl_realloc
diff --git a/gl/str-two-way.h b/gl/str-two-way.h
index c08f60ef..4d555f92 100644
--- a/gl/str-two-way.h
+++ b/gl/str-two-way.h
@@ -95,26 +95,37 @@
A critical factorization has the property that the local period
equals the global period. All strings have at least one critical
factorization with the left half smaller than the global period.
+ And while some strings have more than one critical factorization,
+ it is provable that with an ordered alphabet, at least one of the
+ critical factorizations corresponds to a maximal suffix.
Given an ordered alphabet, a critical factorization can be computed
in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
- larger of two ordered maximal suffixes. The ordered maximal
- suffixes are determined by lexicographic comparison of
+ shorter of two ordered maximal suffixes. The ordered maximal
+ suffixes are determined by lexicographic comparison while tracking
periodicity. */
static size_t
critical_factorization (const unsigned char *needle, size_t needle_len,
size_t *period)
{
- /* Index of last byte of left half, or SIZE_MAX. */
+ /* Index of last byte of left half. */
size_t max_suffix, max_suffix_rev;
size_t j; /* Index into NEEDLE for current candidate suffix. */
size_t k; /* Offset into current period. */
size_t p; /* Intermediate period. */
unsigned char a, b; /* Current comparison bytes. */
+ /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
+ out 0-length needles. */
+ if (needle_len < 3)
+ {
+ *period = 1;
+ return needle_len - 1;
+ }
+
/* Invariants:
- 0 <= j < NEEDLE_LEN - 1
- -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
+ 1 <= j < NEEDLE_LEN - 1
+ 0 <= max_suffix{,_rev} < j
min(max_suffix, max_suffix_rev) < global period of NEEDLE
1 <= p <= global period of NEEDLE
p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
@@ -122,9 +133,8 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
*/
/* Perform lexicographic search. */
- max_suffix = SIZE_MAX;
- j = 0;
- k = p = 1;
+ max_suffix = 0;
+ j = k = p = 1;
while (j + k < needle_len)
{
a = CANON_ELEMENT (needle[j + k]);
@@ -157,9 +167,8 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
*period = p;
/* Perform reverse lexicographic search. */
- max_suffix_rev = SIZE_MAX;
- j = 0;
- k = p = 1;
+ max_suffix_rev = 0;
+ j = k = p = 1;
while (j + k < needle_len)
{
a = CANON_ELEMENT (needle[j + k]);
@@ -190,8 +199,20 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
}
}
- /* Choose the longer suffix. Return the first byte of the right
- half, rather than the last byte of the left half. */
+ /* Choose the shorter suffix. Return the index of the first byte of
+ the right half, rather than the last byte of the left half.
+
+ For some examples, 'banana' has two critical factorizations, both
+ exposed by the two lexicographic extreme suffixes of 'anana' and
+ 'nana', where both suffixes have a period of 2. On the other
+ hand, with 'aab' and 'bba', both strings have a single critical
+ factorization of the last byte, with the suffix having a period
+ of 1. While the maximal lexicographic suffix of 'aab' is 'b',
+ the maximal lexicographic suffix of 'bba' is 'ba', which is not a
+ critical factorization. Conversely, the maximal reverse
+ lexicographic suffix of 'a' works for 'bba', but not 'ab' for
+ 'aab'. The shorter suffix of the two will always be a critical
+ factorization. */
if (max_suffix_rev + 1 < max_suffix + 1)
return max_suffix + 1;
*period = p;
@@ -226,9 +247,9 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
first. */
if (CMP_FUNC (needle, needle + period, suffix) == 0)
{
- /* Entire needle is periodic; a mismatch can only advance by the
- period, so use memory to avoid rescanning known occurrences
- of the period. */
+ /* Entire needle is periodic; a mismatch in the left half can
+ only advance by the period, so use memory to avoid rescanning
+ known occurrences of the period in the right half. */
size_t memory = 0;
j = 0;
while (AVAILABLE (haystack, haystack_len, j, needle_len))
@@ -330,9 +351,9 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
first. */
if (CMP_FUNC (needle, needle + period, suffix) == 0)
{
- /* Entire needle is periodic; a mismatch can only advance by the
- period, so use memory to avoid rescanning known occurrences
- of the period. */
+ /* Entire needle is periodic; a mismatch in the left half can
+ only advance by the period, so use memory to avoid rescanning
+ known occurrences of the period in the right half. */
size_t memory = 0;
size_t shift;
j = 0;
diff --git a/gl/string.in.h b/gl/string.in.h
index 13c0f095..f64fce30 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -41,10 +41,12 @@
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
+#endif
/* The attribute __pure__ was added in gcc 2.96. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
-# define __pure__ /* empty */
-# endif
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
#endif
@@ -62,13 +64,13 @@
# define memchr rpl_memchr
# endif
_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
# else
# if ! @HAVE_MEMCHR@
_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
# endif
/* On some systems, this function is defined as an overloaded function:
@@ -102,7 +104,8 @@ _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
_GL_FUNCDECL_RPL (memmem, void *,
(void const *__haystack, size_t __haystack_len,
void const *__needle, size_t __needle_len)
- __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1, 3)));
_GL_CXXALIAS_RPL (memmem, void *,
(void const *__haystack, size_t __haystack_len,
void const *__needle, size_t __needle_len));
@@ -111,7 +114,8 @@ _GL_CXXALIAS_RPL (memmem, void *,
_GL_FUNCDECL_SYS (memmem, void *,
(void const *__haystack, size_t __haystack_len,
void const *__needle, size_t __needle_len)
- __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1, 3)));
# endif
_GL_CXXALIAS_SYS (memmem, void *,
(void const *__haystack, size_t __haystack_len,
@@ -152,7 +156,7 @@ _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
#if @GNULIB_MEMRCHR@
# if ! @HAVE_DECL_MEMRCHR@
_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
# endif
/* On some systems, this function is defined as an overloaded function:
@@ -182,7 +186,7 @@ _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
#if @GNULIB_RAWMEMCHR@
# if ! @HAVE_RAWMEMCHR@
_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
# endif
/* On some systems, this function is defined as an overloaded function:
@@ -272,7 +276,7 @@ _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
#if @GNULIB_STRCHRNUL@
# if ! @HAVE_STRCHRNUL@
_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
# endif
/* On some systems, this function is defined as an overloaded function:
@@ -378,13 +382,13 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - "
# define strnlen rpl_strnlen
# endif
_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
# else
# if ! @HAVE_DECL_STRNLEN@
_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1)));
# endif
_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
@@ -414,7 +418,7 @@ _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
#if @GNULIB_STRPBRK@
# if ! @HAVE_STRPBRK@
_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1, 2)));
# endif
/* On some systems, this function is defined as an overloaded function:
@@ -514,7 +518,7 @@ _GL_WARN_ON_USE (strsep, "strsep is unportable - "
# define strstr rpl_strstr
# endif
_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
- __attribute__ ((__pure__))
+ _GL_ATTRIBUTE_PURE
_GL_ARG_NONNULL ((1, 2)));
_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
# else
@@ -556,14 +560,16 @@ _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
# endif
_GL_FUNCDECL_RPL (strcasestr, char *,
(const char *haystack, const char *needle)
- __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1, 2)));
_GL_CXXALIAS_RPL (strcasestr, char *,
(const char *haystack, const char *needle));
# else
# if ! @HAVE_STRCASESTR@
_GL_FUNCDECL_SYS (strcasestr, char *,
(const char *haystack, const char *needle)
- __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1, 2)));
# endif
/* On some systems, this function is defined as an overloaded function:
extern "C++" { const char * strcasestr (const char *, const char *); }