summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Fontana <sick_soul@users.sourceforge.net>2006-07-21 23:40:02 +0000
committerClaudio Fontana <sick_soul@users.sourceforge.net>2006-07-21 23:40:02 +0000
commit9a72ecd6dc36eab0497dc428d10a6ad1dd87a19a (patch)
treea528fd617cda36f619bc076429b0995bcda12e2c
parentee29ecd605b329c38ab4c6c6c89d6288693495de (diff)
downloadidutils-9a72ecd6dc36eab0497dc428d10a6ad1dd87a19a.tar.gz
idutils-9a72ecd6dc36eab0497dc428d10a6ad1dd87a19a.tar.bz2
idutils-9a72ecd6dc36eab0497dc428d10a6ad1dd87a19a.zip
* upgraded gnulib
-rw-r--r--ChangeLog4
-rwxr-xr-xconfig.rpath133
-rw-r--r--lib/Makefile.am56
-rw-r--r--lib/alloca_.h26
-rw-r--r--lib/basename.c104
-rw-r--r--lib/closeout.c10
-rw-r--r--lib/dirname.c112
-rw-r--r--lib/dirname.h29
-rw-r--r--lib/exclude.c52
-rw-r--r--lib/exclude.h5
-rw-r--r--lib/exit.h2
-rw-r--r--lib/fnmatch.c34
-rw-r--r--lib/fnmatch_loop.c24
-rw-r--r--lib/getcwd.c153
-rw-r--r--lib/getopt.c2
-rw-r--r--lib/lstat.c45
-rw-r--r--lib/mbchar.h4
-rw-r--r--lib/regcomp.c629
-rw-r--r--lib/regex.c7
-rw-r--r--lib/regex.h510
-rw-r--r--lib/regex_internal.c271
-rw-r--r--lib/regex_internal.h197
-rw-r--r--lib/regexec.c669
-rw-r--r--lib/stat-macros.h21
-rw-r--r--lib/stripslash.c27
-rw-r--r--lib/verify.h106
-rw-r--r--lib/xalloc-die.c3
-rw-r--r--m4/Makefile.am8
-rw-r--r--m4/d-ino.m422
-rw-r--r--m4/dirname.m45
-rw-r--r--m4/dos.m441
-rw-r--r--m4/double-slash-root.m443
-rw-r--r--m4/exclude.m49
-rw-r--r--m4/extensions.m416
-rw-r--r--m4/fnmatch.m47
-rw-r--r--m4/getcwd-abort-bug.m4106
-rw-r--r--m4/getcwd-path-max.m410
-rw-r--r--m4/getcwd.m412
-rw-r--r--m4/getopt.m44
-rw-r--r--m4/gnulib-cache.m47
-rw-r--r--m4/gnulib-comp.m424
-rw-r--r--m4/longdouble.m47
-rw-r--r--m4/longlong.m439
-rw-r--r--m4/onceonly_2_57.m412
-rw-r--r--m4/regex.m484
-rw-r--r--m4/size_max.m445
-rw-r--r--m4/ssize_t.m421
-rw-r--r--m4/stdbool.m44
-rw-r--r--m4/strerror_r.m41
-rw-r--r--m4/strndup.m451
-rw-r--r--m4/strnlen.m429
-rw-r--r--m4/ulonglong.m438
-rw-r--r--m4/unistd_h.m418
-rw-r--r--m4/wcwidth.m426
-rw-r--r--m4/xstrndup.m415
55 files changed, 2275 insertions, 1664 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a04096..610ecfe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2006-07-22 Claudio Fontana <claudio@gnu.org>
+ upgraded gnulib.
+
+2006-07-22 Claudio Fontana <claudio@gnu.org>
+
removed generated files from CVS
* src/lid.c (get_editor_argv): new function that
diff --git a/config.rpath b/config.rpath
index 3f1bef3..c492a93 100755
--- a/config.rpath
+++ b/config.rpath
@@ -2,7 +2,7 @@
# Output a system dependent set of variables, describing how to set the
# run time search path of shared libraries in an executable.
#
-# Copyright 1996-2005 Free Software Foundation, Inc.
+# Copyright 1996-2006 Free Software Foundation, Inc.
# Taken from GNU libtool, 2001
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
@@ -25,7 +25,7 @@
# known workaround is to choose shorter directory names for the build
# directory and/or the installation directory.
-# All known linkers require a `.a' archive for static linking (except M$VC,
+# All known linkers require a `.a' archive for static linking (except MSVC,
# which needs '.lib').
libext=a
shrext=.so
@@ -35,7 +35,17 @@ host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
-cc_basename=`echo "$CC" | sed -e 's%^.*/%%'`
+# Code taken from libtool.m4's _LT_CC_BASENAME.
+
+for cc_temp in $CC""; do
+ case $cc_temp in
+ compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+ distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+ \-*) ;;
+ *) break;;
+ esac
+done
+cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'`
# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.
@@ -48,7 +58,7 @@ else
wl='-Wl,'
;;
darwin*)
- case "$cc_basename" in
+ case $cc_basename in
xlc*)
wl='-Wl,'
;;
@@ -78,6 +88,13 @@ else
como)
wl='-lopt='
;;
+ *)
+ case `$CC -V 2>&1 | sed 5q` in
+ *Sun\ C*)
+ wl='-Wl,'
+ ;;
+ esac
+ ;;
esac
;;
osf3* | osf4* | osf5*)
@@ -120,6 +137,10 @@ case "$host_os" in
with_gnu_ld=no
fi
;;
+ interix*)
+ # we just hope/assume this is gcc and not c89 (= MSVC++)
+ with_gnu_ld=yes
+ ;;
openbsd*)
with_gnu_ld=no
;;
@@ -127,6 +148,12 @@ esac
ld_shlibs=yes
if test "$with_gnu_ld" = yes; then
+ # Set some defaults for GNU ld with shared library support. These
+ # are reset later if shared libraries are not supported. Putting them
+ # here allows them to be overridden if necessary.
+ # Unlike libtool, we use -rpath here, not --rpath, since the documented
+ # option of GNU ld is called -rpath, not --rpath.
+ hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
case "$host_os" in
aix3* | aix4* | aix5*)
# On AIX/PPC, the GNU linker is very broken
@@ -162,9 +189,20 @@ if test "$with_gnu_ld" = yes; then
ld_shlibs=no
fi
;;
+ interix3*)
+ hardcode_direct=no
+ hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+ ;;
+ linux*)
+ if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+ :
+ else
+ ld_shlibs=no
+ fi
+ ;;
netbsd*)
;;
- solaris* | sysv5*)
+ solaris*)
if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
ld_shlibs=no
elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
@@ -173,16 +211,23 @@ if test "$with_gnu_ld" = yes; then
ld_shlibs=no
fi
;;
+ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+ case `$LD -v 2>&1` in
+ *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+ ld_shlibs=no
+ ;;
+ *)
+ if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+ hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+ else
+ ld_shlibs=no
+ fi
+ ;;
+ esac
+ ;;
sunos4*)
hardcode_direct=yes
;;
- linux*)
- if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
- :
- else
- ld_shlibs=no
- fi
- ;;
*)
if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
:
@@ -191,10 +236,8 @@ if test "$with_gnu_ld" = yes; then
fi
;;
esac
- if test "$ld_shlibs" = yes; then
- # Unlike libtool, we use -rpath here, not --rpath, since the documented
- # option of GNU ld is called -rpath, not --rpath.
- hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+ if test "$ld_shlibs" = no; then
+ hardcode_libdir_flag_spec=
fi
else
case "$host_os" in
@@ -225,6 +268,7 @@ else
break
fi
done
+ ;;
esac
fi
hardcode_direct=yes
@@ -244,6 +288,7 @@ else
hardcode_libdir_flag_spec='-L$libdir'
hardcode_libdir_separator=
fi
+ ;;
esac
fi
# Begin _LT_AC_SYS_LIBPATH_AIX.
@@ -291,7 +336,7 @@ else
if test "$GCC" = yes ; then
:
else
- case "$cc_basename" in
+ case $cc_basename in
xlc*)
;;
*)
@@ -326,24 +371,25 @@ else
# but as the default location of the library.
hardcode_minus_L=yes
;;
- hpux10* | hpux11*)
+ hpux10*)
if test "$with_gnu_ld" = no; then
- case "$host_cpu" in
- hppa*64*)
- hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
- hardcode_libdir_separator=:
- hardcode_direct=no
- ;;
- ia64*)
- hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_libdir_separator=:
+ hardcode_direct=yes
+ # hardcode_minus_L: Not really in the search PATH,
+ # but as the default location of the library.
+ hardcode_minus_L=yes
+ fi
+ ;;
+ hpux11*)
+ if test "$with_gnu_ld" = no; then
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_libdir_separator=:
+ case $host_cpu in
+ hppa*64*|ia64*)
hardcode_direct=no
- # hardcode_minus_L: Not really in the search PATH,
- # but as the default location of the library.
- hardcode_minus_L=yes
;;
*)
- hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
- hardcode_libdir_separator=:
hardcode_direct=yes
# hardcode_minus_L: Not really in the search PATH,
# but as the default location of the library.
@@ -397,8 +443,6 @@ else
fi
hardcode_libdir_separator=:
;;
- sco3.2v5*)
- ;;
solaris*)
hardcode_libdir_flag_spec='-R$libdir'
;;
@@ -427,14 +471,11 @@ else
ld_shlibs=yes
fi
;;
- sysv4.2uw2*)
- hardcode_direct=yes
- hardcode_minus_L=no
- ;;
- sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[78]* | unixware7*)
+ sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7*)
;;
- sysv5*)
- hardcode_libdir_flag_spec=
+ sysv5* | sco3.2v5* | sco5v6*)
+ hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+ hardcode_libdir_separator=':'
;;
uts4*)
hardcode_libdir_flag_spec='-L$libdir'
@@ -471,12 +512,12 @@ case "$host_os" in
;;
kfreebsd*-gnu)
;;
- freebsd*)
+ freebsd* | dragonfly*)
;;
gnu*)
;;
hpux9* | hpux10* | hpux11*)
- case "$host_cpu" in
+ case $host_cpu in
ia64*)
shrext=.so
;;
@@ -488,6 +529,8 @@ case "$host_os" in
;;
esac
;;
+ interix3*)
+ ;;
irix5* | irix6* | nonstopux*)
case "$host_os" in
irix5* | nonstopux*)
@@ -523,16 +566,16 @@ case "$host_os" in
;;
osf3* | osf4* | osf5*)
;;
- sco3.2v5*)
- ;;
solaris*)
;;
sunos4*)
;;
- sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+ sysv4 | sysv4.3*)
;;
sysv4*MP*)
;;
+ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+ ;;
uts4*)
;;
esac
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1b346fd..6a13fa1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,14 +1,14 @@
## Process this file with automake to produce Makefile.in.
-# Copyright (C) 2004 Free Software Foundation, Inc.
+# Copyright (C) 2004-2006 Free Software Foundation, Inc.
#
# This file is free software, distributed under the terms of the GNU
# General Public License. As a special exception to the GNU General
# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Automake, under
+# that contains a configuration script generated by Autoconf, under
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout dirname error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --aux-dir=. --macro-prefix=gl --assume-autoconf=2.59 alloca alloca-opt atexit closeout dirname error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd
AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies
@@ -16,16 +16,18 @@ noinst_LIBRARIES = libgnu.a
libgnu_a_SOURCES =
libgnu_a_LIBADD = @LIBOBJS@
-AM_CPPFLAGS =
noinst_HEADERS =
EXTRA_DIST =
BUILT_SOURCES =
SUFFIXES =
MOSTLYCLEANFILES =
+MOSTLYCLEANDIRS =
CLEANFILES =
DISTCLEANFILES =
MAINTAINERCLEANFILES =
+AM_CPPFLAGS =
+
## begin gnulib module alloca
@@ -88,6 +90,14 @@ MOSTLYCLEANFILES += getopt.h getopt.h-t
## begin gnulib module gettext
+# This is for those projects which use "gettextize --intl" to put a source-code
+# copy of libintl into their package. In such projects, every Makefile.am needs
+# -I$(top_builddir)/intl, so that <libintl.h> can be found in this directory.
+# For the Makefile.ams in other directories it is the maintainer's
+# responsibility; for the one from gnulib we do it here.
+# This option has no effect when the user disables NLS (because then the intl
+# directory contains no libintl.h file) or when the project does not use
+# "gettextize --intl".
AM_CPPFLAGS += -I$(top_builddir)/intl
## end gnulib module gettext
@@ -98,6 +108,12 @@ libgnu_a_SOURCES += gettext.h
## end gnulib module gettext-h
+## begin gnulib module intprops
+
+EXTRA_DIST += intprops.h
+
+## end gnulib module intprops
+
## begin gnulib module inttostr
EXTRA_DIST += inttostr.c
@@ -160,17 +176,49 @@ libgnu_a_SOURCES += strstr.h
## end gnulib module strstr
+## begin gnulib module unistd
+
+BUILT_SOURCES += $(UNISTD_H)
+
+# We need the following in order to create an empty placeholder for
+# <unistd.h> when the system doesn't have one.
+unistd.h:
+ echo '/* Empty placeholder for $@. */' >$@
+MOSTLYCLEANFILES += unistd.h
+
+## end gnulib module unistd
+
## begin gnulib module verify
libgnu_a_SOURCES += verify.h
## end gnulib module verify
+## begin gnulib module wcwidth
+
+libgnu_a_SOURCES += wcwidth.h
+
+## end gnulib module wcwidth
+
## begin gnulib module xalloc-die
libgnu_a_SOURCES += xalloc-die.c
## end gnulib module xalloc-die
+## begin gnulib module xstrndup
+
+libgnu_a_SOURCES += xstrndup.h xstrndup.c
+
+## end gnulib module xstrndup
+
+
+mostlyclean-local:
+ @test -z "$(MOSTLYCLEANDIRS)" || \
+ for dir in $(MOSTLYCLEANDIRS); do \
+ if test -d $$dir; then \
+ echo "rmdir $$dir"; rmdir $$dir; \
+ fi; \
+ done
# Makefile.am ends here
diff --git a/lib/alloca_.h b/lib/alloca_.h
index 3e3fdf4..dd0b3e9 100644
--- a/lib/alloca_.h
+++ b/lib/alloca_.h
@@ -1,6 +1,6 @@
/* Memory allocation on the stack.
- Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
+ Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -34,19 +34,21 @@
request, the program just crashes.
*/
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-#elif defined _AIX
-# define alloca __alloca
-#elif defined _MSC_VER
-# include <malloc.h>
-# define alloca _alloca
-#else
-# include <stddef.h>
-# ifdef __cplusplus
+#ifndef alloca
+# ifdef __GNUC__
+# define alloca __builtin_alloca
+# elif defined _AIX
+# define alloca __alloca
+# elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+# else
+# include <stddef.h>
+# ifdef __cplusplus
extern "C"
-# endif
+# endif
void *alloca (size_t);
+# endif
#endif
#endif /* _GNULIB_ALLOCA_H */
diff --git a/lib/basename.c b/lib/basename.c
index 5cc97cd..8c3dbec 100644
--- a/lib/basename.c
+++ b/lib/basename.c
@@ -1,6 +1,6 @@
/* basename.c -- return the last element in a file name
- Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
+ Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -22,58 +22,110 @@
#endif
#include "dirname.h"
-#include <string.h>
-/* In general, we can't use the builtin `basename' function if available,
- since it has different meanings in different environments.
- In some environments the builtin `basename' modifies its argument.
+#include <string.h>
+#include "xalloc.h"
+#include "xstrndup.h"
- Return the address of the last file name component of NAME. If
- NAME has no file name components because it is all slashes, return
- NAME if it is empty, the address of its last slash otherwise. */
+/* Return the address of the last file name component of NAME. If
+ NAME has no relative file name components because it is a file
+ system root, return the empty string. */
char *
-base_name (char const *name)
+last_component (char const *name)
{
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
char const *p;
+ bool saw_slash = false;
+
+ while (ISSLASH (*base))
+ base++;
for (p = base; *p; p++)
{
if (ISSLASH (*p))
+ saw_slash = true;
+ else if (saw_slash)
{
- /* Treat multiple adjacent slashes like a single slash. */
- do p++;
- while (ISSLASH (*p));
-
- /* If the file name ends in slash, use the trailing slash as
- the basename if no non-slashes have been found. */
- if (! *p)
- {
- if (ISSLASH (*base))
- base = p - 1;
- break;
- }
-
- /* *P is a non-slash preceded by a slash. */
base = p;
+ saw_slash = false;
}
}
return (char *) base;
}
-/* Return the length of of the basename NAME. Typically NAME is the
- value returned by base_name. Act like strlen (NAME), except omit
- redundant trailing slashes. */
+
+/* In general, we can't use the builtin `basename' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `basename' modifies its argument.
+
+ Return the last file name component of NAME, allocated with
+ xmalloc. On systems with drive letters, a leading "./"
+ distinguishes relative names that would otherwise look like a drive
+ letter. Unlike POSIX basename(), NAME cannot be NULL,
+ base_name("") returns "", and the first trailing slash is not
+ stripped.
+
+ If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
+ lstat (base_name (NAME)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (NAME));
+ rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
+ to "foo" in the same directory NAME was in. */
+
+char *
+base_name (char const *name)
+{
+ char const *base = last_component (name);
+ size_t length;
+
+ /* If there is no last component, then name is a file system root or the
+ empty string. */
+ if (! *base)
+ return xstrndup (name, base_len (name));
+
+ /* Collapse a sequence of trailing slashes into one. */
+ length = base_len (base);
+ if (ISSLASH (base[length]))
+ length++;
+
+ /* On systems with drive letters, `a/b:c' must return `./b:c' rather
+ than `b:c' to avoid confusion with a drive letter. On systems
+ with pure POSIX semantics, this is not an issue. */
+ if (FILE_SYSTEM_PREFIX_LEN (base))
+ {
+ char *p = xmalloc (length + 3);
+ p[0] = '.';
+ p[1] = '/';
+ memcpy (p + 2, base, length);
+ p[length + 2] = '\0';
+ return p;
+ }
+
+ /* Finally, copy the basename. */
+ return xstrndup (base, length);
+}
+
+/* Return the length of the basename NAME. Typically NAME is the
+ value returned by base_name or last_component. Act like strlen
+ (NAME), except omit all trailing slashes. */
size_t
base_len (char const *name)
{
size_t len;
+ size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
continue;
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
+ && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
+ return 2;
+
+ if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
+ && len == prefix_len && ISSLASH (name[prefix_len]))
+ return prefix_len + 1;
+
return len;
}
diff --git a/lib/closeout.c b/lib/closeout.c
index 5d0509d..2137fd4 100644
--- a/lib/closeout.c
+++ b/lib/closeout.c
@@ -1,7 +1,7 @@
/* closeout.c - close standard output
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software
- Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free
+ Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -73,9 +73,9 @@ close_stdout_set_file_name (const char *file)
void
close_stdout (void)
{
- bool prev_fail = ferror (stdout);
- bool none_pending = (0 == __fpending (stdout));
- bool fclose_fail = fclose (stdout);
+ bool none_pending = (__fpending (stdout) == 0);
+ bool prev_fail = (ferror (stdout) != 0);
+ bool fclose_fail = (fclose (stdout) != 0);
if (prev_fail || fclose_fail)
{
diff --git a/lib/dirname.c b/lib/dirname.c
index e2b9d64..e3c762c 100644
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -1,6 +1,6 @@
/* dirname.c -- return all but the last element in a file name
- Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005 Free Software
+ Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -26,96 +26,62 @@
#include <string.h>
#include "xalloc.h"
-/* Return the length of `dirname (FILE)', or zero if FILE is
- in the working directory. Works properly even if
- there are trailing slashes (by effectively ignoring them). */
+/* Return the length of the prefix of FILE that will be used by
+ dir_name. If FILE is in the working directory, this returns zero
+ even though `dir_name (FILE)' will return ".". Works properly even
+ if there are trailing slashes (by effectively ignoring them). */
+
size_t
dir_len (char const *file)
{
size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
size_t length;
+ /* Advance prefix_length beyond important leading slashes. */
+ prefix_length += (prefix_length != 0
+ ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && ISSLASH (file[prefix_length]))
+ : (ISSLASH (file[0])
+ ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && ISSLASH (file[1]) && ! ISSLASH (file[2])
+ ? 2 : 1))
+ : 0));
+
/* Strip the basename and any redundant slashes before it. */
- for (length = base_name (file) - file; prefix_length < length; length--)
+ for (length = last_component (file) - file;
+ prefix_length < length; length--)
if (! ISSLASH (file[length - 1]))
- return length;
-
- /* But don't strip the only slash from "/". */
- return prefix_length + ISSLASH (file[prefix_length]);
+ break;
+ return length;
}
-/* Return the leading directories part of FILE,
- allocated with xmalloc.
- Works properly even if there are trailing slashes
- (by effectively ignoring them). */
+
+/* In general, we can't use the builtin `dirname' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `dirname' modifies its argument.
+
+ Return the leading directories part of FILE, allocated with xmalloc.
+ Works properly even if there are trailing slashes (by effectively
+ ignoring them). Unlike POSIX dirname(), FILE cannot be NULL.
+
+ If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
+ lstat (base_name (FILE)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (FILE));
+ rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
+ to "foo" in the same directory FILE was in. */
char *
dir_name (char const *file)
{
size_t length = dir_len (file);
- bool append_dot = (length == FILE_SYSTEM_PREFIX_LEN (file));
+ bool append_dot = (length == 0
+ || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && length == FILE_SYSTEM_PREFIX_LEN (file)
+ && file[2] != '\0' && ! ISSLASH (file[2])));
char *dir = xmalloc (length + append_dot + 1);
memcpy (dir, file, length);
if (append_dot)
dir[length++] = '.';
- dir[length] = 0;
+ dir[length] = '\0';
return dir;
}
-
-#ifdef TEST_DIRNAME
-/*
-
-Run the test like this (expect no output):
- gcc -DHAVE_CONFIG_H -DTEST_DIRNAME -I.. -O -Wall \
- basename.c dirname.c xmalloc.c error.c
- sed -n '/^BEGIN-DATA$/,/^END-DATA$/p' dirname.c|grep -v DATA|./a.out
-
-If it's been built on a DOS or Windows platforms, run another test like
-this (again, expect no output):
- sed -n '/^BEGIN-DOS-DATA$/,/^END-DOS-DATA$/p' dirname.c|grep -v DATA|./a.out
-
-BEGIN-DATA
-foo//// .
-bar/foo//// bar
-foo/ .
-/ /
-. .
-a .
-END-DATA
-
-BEGIN-DOS-DATA
-c:///// c:/
-c:/ c:/
-c:/. c:/
-c:foo c:.
-c:foo/bar c:foo
-END-DOS-DATA
-
-*/
-
-# define MAX_BUFF_LEN 1024
-# include <stdio.h>
-
-char *program_name;
-
-int
-main (int argc, char *argv[])
-{
- char buff[MAX_BUFF_LEN + 1];
-
- program_name = argv[0];
-
- buff[MAX_BUFF_LEN] = 0;
- while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
- {
- char file[MAX_BUFF_LEN];
- char expected_result[MAX_BUFF_LEN];
- char const *result;
- sscanf (buff, "%s %s", file, expected_result);
- result = dir_name (file);
- if (strcmp (result, expected_result))
- printf ("%s: got %s, expected %s\n", file, result, expected_result);
- }
- return 0;
-}
-#endif
diff --git a/lib/dirname.h b/lib/dirname.h
index 1688ae8..f9189c3 100644
--- a/lib/dirname.h
+++ b/lib/dirname.h
@@ -1,6 +1,6 @@
/* Take file names apart into directory and base names.
- Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,16 +31,39 @@
# endif
# ifndef FILE_SYSTEM_PREFIX_LEN
-# define FILE_SYSTEM_PREFIX_LEN(File_name) 0
+# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
+ /* This internal macro assumes ASCII, but all hosts that support drive
+ letters use ASCII. */
+# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
+ <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(Filename) \
+ (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
+# else
+# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
+# endif
# endif
-# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
+# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
+# endif
+
+# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
+# define DOUBLE_SLASH_IS_DISTINCT_ROOT 1
+# endif
+
+# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
+# else
+# define IS_ABSOLUTE_FILE_NAME(F) \
+ (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
+# endif
# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
char *base_name (char const *file);
char *dir_name (char const *file);
size_t base_len (char const *file);
size_t dir_len (char const *file);
+char *last_component (char const *file);
bool strip_trailing_slashes (char *file);
diff --git a/lib/exclude.c b/lib/exclude.c
index 6a0c149..f5978a9 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -1,7 +1,7 @@
/* exclude.c -- exclude file names
Copyright (C) 1992, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005 Free Software Foundation, Inc.
+ 2004, 2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -43,18 +43,6 @@
# include "unlocked-io.h"
#endif
-#if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
-# define IN_CTYPE_DOMAIN(c) true
-#else
-# define IN_CTYPE_DOMAIN(c) isascii (c)
-#endif
-
-static inline bool
-is_space (unsigned char c)
-{
- return IN_CTYPE_DOMAIN (c) && isspace (c);
-}
-
/* Non-GNU systems lack these options, so we don't need to check them. */
#ifndef FNM_CASEFOLD
# define FNM_CASEFOLD 0
@@ -129,6 +117,24 @@ fnmatch_no_wildcards (char const *pattern, char const *f, int options)
}
}
+bool
+exclude_fnmatch (char const *pattern, char const *f, int options)
+{
+ int (*matcher) (char const *, char const *, int) =
+ (options & EXCLUDE_WILDCARDS
+ ? fnmatch
+ : fnmatch_no_wildcards);
+ bool matched = ((*matcher) (pattern, f, options) == 0);
+ char const *p;
+
+ if (! (options & EXCLUDE_ANCHORED))
+ for (p = f; *p && ! matched; p++)
+ if (*p == '/' && p[1] != '/')
+ matched = ((*matcher) (pattern, p + 1, options) == 0);
+
+ return matched;
+}
+
/* Return true if EX excludes F. */
bool
@@ -154,21 +160,7 @@ excluded_file_name (struct exclude const *ex, char const *f)
char const *pattern = exclude[i].pattern;
int options = exclude[i].options;
if (excluded == !! (options & EXCLUDE_INCLUDE))
- {
- int (*matcher) (char const *, char const *, int) =
- (options & EXCLUDE_WILDCARDS
- ? fnmatch
- : fnmatch_no_wildcards);
- bool matched = ((*matcher) (pattern, f, options) == 0);
- char const *p;
-
- if (! (options & EXCLUDE_ANCHORED))
- for (p = f; *p && ! matched; p++)
- if (*p == '/' && p[1] != '/')
- matched = ((*matcher) (pattern, p + 1, options) == 0);
-
- excluded ^= matched;
- }
+ excluded ^= exclude_fnmatch (pattern, f, options);
}
return excluded;
@@ -240,12 +232,12 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int),
{
char *pattern_end = p;
- if (is_space (line_end))
+ if (isspace ((unsigned char) line_end))
{
for (; ; pattern_end--)
if (pattern_end == pattern)
goto next_pattern;
- else if (! is_space (pattern_end[-1]))
+ else if (! isspace ((unsigned char) pattern_end[-1]))
break;
}
diff --git a/lib/exclude.h b/lib/exclude.h
index 6923efa..203e384 100644
--- a/lib/exclude.h
+++ b/lib/exclude.h
@@ -1,7 +1,7 @@
/* exclude.h -- declarations for excluding file names
- Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003, 2005,
+ 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -41,3 +41,4 @@ void add_exclude (struct exclude *, char const *, int);
int add_exclude_file (void (*) (struct exclude *, char const *, int),
struct exclude *, char const *, int, char);
bool excluded_file_name (struct exclude const *, char const *);
+bool exclude_fnmatch (char const *pattern, char const *f, int options);
diff --git a/lib/exit.h b/lib/exit.h
index 9dbfb7c..e8f7738 100644
--- a/lib/exit.h
+++ b/lib/exit.h
@@ -21,7 +21,7 @@
/* Get exit() declaration. */
#include <stdlib.h>
-/* Some systems do not define EXIT_*, even with STDC_HEADERS. */
+/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
#endif
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index c5a4e40..bd41358 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -86,34 +86,10 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
#if defined _LIBC || !defined __GNU_LIBRARY__ || !HAVE_FNMATCH_GNU
-# if defined STDC_HEADERS || !defined isascii
-# define ISASCII(c) 1
-# else
-# define ISASCII(c) isascii(c)
-# endif
-
-# ifdef isblank
-# define ISBLANK(c) (ISASCII (c) && isblank (c))
-# else
-# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
-# endif
-# ifdef isgraph
-# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
-# else
-# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
+# if ! (defined isblank || HAVE_DECL_ISBLANK)
+# define isblank(c) ((c) == ' ' || (c) == '\t')
# endif
-# define ISPRINT(c) (ISASCII (c) && isprint (c))
-# define ISDIGIT(c) (ISASCII (c) && isdigit (c))
-# define ISALNUM(c) (ISASCII (c) && isalnum (c))
-# define ISALPHA(c) (ISASCII (c) && isalpha (c))
-# define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
-# define ISLOWER(c) (ISASCII (c) && islower (c))
-# define ISPUNCT(c) (ISASCII (c) && ispunct (c))
-# define ISSPACE(c) (ISASCII (c) && isspace (c))
-# define ISUPPER(c) (ISASCII (c) && isupper (c))
-# define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
-
# define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
# if defined _LIBC || WIDE_CHAR_SUPPORT
@@ -169,11 +145,7 @@ static int posixly_correct;
# endif
/* Note that this evaluates C many times. */
-# ifdef _LIBC
-# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))
-# else
-# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c))
-# endif
+# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))
# define CHAR char
# define UCHAR unsigned char
# define INT int
diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c
index 2b5897c..308d311 100644
--- a/lib/fnmatch_loop.c
+++ b/lib/fnmatch_loop.c
@@ -288,18 +288,18 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
goto matched;
# endif
#else
- if ((STREQ (str, L_("alnum")) && ISALNUM ((UCHAR) *n))
- || (STREQ (str, L_("alpha")) && ISALPHA ((UCHAR) *n))
- || (STREQ (str, L_("blank")) && ISBLANK ((UCHAR) *n))
- || (STREQ (str, L_("cntrl")) && ISCNTRL ((UCHAR) *n))
- || (STREQ (str, L_("digit")) && ISDIGIT ((UCHAR) *n))
- || (STREQ (str, L_("graph")) && ISGRAPH ((UCHAR) *n))
- || (STREQ (str, L_("lower")) && ISLOWER ((UCHAR) *n))
- || (STREQ (str, L_("print")) && ISPRINT ((UCHAR) *n))
- || (STREQ (str, L_("punct")) && ISPUNCT ((UCHAR) *n))
- || (STREQ (str, L_("space")) && ISSPACE ((UCHAR) *n))
- || (STREQ (str, L_("upper")) && ISUPPER ((UCHAR) *n))
- || (STREQ (str, L_("xdigit")) && ISXDIGIT ((UCHAR) *n)))
+ if ((STREQ (str, L_("alnum")) && isalnum ((UCHAR) *n))
+ || (STREQ (str, L_("alpha")) && isalpha ((UCHAR) *n))
+ || (STREQ (str, L_("blank")) && isblank ((UCHAR) *n))
+ || (STREQ (str, L_("cntrl")) && iscntrl ((UCHAR) *n))
+ || (STREQ (str, L_("digit")) && isdigit ((UCHAR) *n))
+ || (STREQ (str, L_("graph")) && isgraph ((UCHAR) *n))
+ || (STREQ (str, L_("lower")) && islower ((UCHAR) *n))
+ || (STREQ (str, L_("print")) && isprint ((UCHAR) *n))
+ || (STREQ (str, L_("punct")) && ispunct ((UCHAR) *n))
+ || (STREQ (str, L_("space")) && isspace ((UCHAR) *n))
+ || (STREQ (str, L_("upper")) && isupper ((UCHAR) *n))
+ || (STREQ (str, L_("xdigit")) && isxdigit ((UCHAR) *n)))
goto matched;
#endif
c = *p++;
diff --git a/lib/getcwd.c b/lib/getcwd.c
index ec1771b..614ded1 100644
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2004,2005 Free Software
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2004,2005,2006 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
@@ -36,25 +36,9 @@
# define __set_errno(val) (errno = (val))
#endif
-#if HAVE_DIRENT_H || _LIBC
-# include <dirent.h>
-# ifndef _D_EXACT_NAMLEN
-# define _D_EXACT_NAMLEN(d) strlen ((d)->d_name)
-# endif
-#else
-# define dirent direct
-# if HAVE_SYS_NDIR_H
-# include <sys/ndir.h>
-# endif
-# if HAVE_SYS_DIR_H
-# include <sys/dir.h>
-# endif
-# if HAVE_NDIR_H
-# include <ndir.h>
-# endif
-#endif
+#include <dirent.h>
#ifndef _D_EXACT_NAMLEN
-# define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
+# define _D_EXACT_NAMLEN(d) strlen ((d)->d_name)
#endif
#ifndef _D_ALLOC_NAMLEN
# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
@@ -74,6 +58,14 @@
#include <limits.h>
+/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
+ value exceeds INT_MAX, so its use as an int doesn't conform to the
+ C standard, and GCC and Sun C complain in some cases. */
+#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
+# undef AT_FDCWD
+# define AT_FDCWD (-3041965)
+#endif
+
#ifdef ENAMETOOLONG
# define is_ENAMETOOLONG(x) ((x) == ENAMETOOLONG)
#else
@@ -203,6 +195,7 @@ __getcwd (char *buf, size_t size)
int parent_status;
size_t dirroom;
size_t namlen;
+ bool use_d_ino = true;
/* Look at the parent directory. */
#ifdef AT_FDCWD
@@ -249,11 +242,26 @@ __getcwd (char *buf, size_t size)
NULL. */
__set_errno (0);
d = __readdir (dirstream);
+
+ /* When we've iterated through all directory entries without finding
+ one with a matching d_ino, rewind the stream and consider each
+ name again, but this time, using lstat. This is necessary in a
+ chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where
+ .., ../.., ../../.., etc. all had the same device number, yet the
+ d_ino values for entries in / did not match those obtained
+ via lstat. */
+ if (d == NULL && errno == 0 && use_d_ino)
+ {
+ use_d_ino = false;
+ rewinddir (dirstream);
+ d = __readdir (dirstream);
+ }
+
if (d == NULL)
{
if (errno == 0)
- /* EOF on dirstream, which means that the current directory
- has been removed. */
+ /* EOF on dirstream, which can mean e.g., that the current
+ directory has been removed. */
__set_errno (ENOENT);
goto lose;
}
@@ -261,58 +269,65 @@ __getcwd (char *buf, size_t size)
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
- if (MATCHING_INO (d, thisino) || mount_point)
+
+ if (use_d_ino)
{
- int entry_status;
+ bool match = (MATCHING_INO (d, thisino) || mount_point);
+ if (! match)
+ continue;
+ }
+
+ {
+ int entry_status;
#ifdef AT_FDCWD
- entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW);
+ entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW);
#else
- /* Compute size needed for this file name, or for the file
- name ".." in the same directory, whichever is larger.
- Room for ".." might be needed the next time through
- the outer loop. */
- size_t name_alloc = _D_ALLOC_NAMLEN (d);
- size_t filesize = dotlen + MAX (sizeof "..", name_alloc);
-
- if (filesize < dotlen)
- goto memory_exhausted;
-
- if (dotsize < filesize)
- {
- /* My, what a deep directory tree you have, Grandma. */
- size_t newsize = MAX (filesize, dotsize * 2);
- size_t i;
- if (newsize < dotsize)
- goto memory_exhausted;
- if (dotlist != dots)
- free (dotlist);
- dotlist = malloc (newsize);
- if (dotlist == NULL)
- goto lose;
- dotsize = newsize;
-
- i = 0;
- do
- {
- dotlist[i++] = '.';
- dotlist[i++] = '.';
- dotlist[i++] = '/';
- }
- while (i < dotlen);
- }
-
- strcpy (dotlist + dotlen, d->d_name);
- entry_status = __lstat (dotlist, &st);
+ /* Compute size needed for this file name, or for the file
+ name ".." in the same directory, whichever is larger.
+ Room for ".." might be needed the next time through
+ the outer loop. */
+ size_t name_alloc = _D_ALLOC_NAMLEN (d);
+ size_t filesize = dotlen + MAX (sizeof "..", name_alloc);
+
+ if (filesize < dotlen)
+ goto memory_exhausted;
+
+ if (dotsize < filesize)
+ {
+ /* My, what a deep directory tree you have, Grandma. */
+ size_t newsize = MAX (filesize, dotsize * 2);
+ size_t i;
+ if (newsize < dotsize)
+ goto memory_exhausted;
+ if (dotlist != dots)
+ free (dotlist);
+ dotlist = malloc (newsize);
+ if (dotlist == NULL)
+ goto lose;
+ dotsize = newsize;
+
+ i = 0;
+ do
+ {
+ dotlist[i++] = '.';
+ dotlist[i++] = '.';
+ dotlist[i++] = '/';
+ }
+ while (i < dotlen);
+ }
+
+ memcpy (dotlist + dotlen, d->d_name, _D_ALLOC_NAMLEN (d));
+ entry_status = __lstat (dotlist, &st);
#endif
- /* We don't fail here if we cannot stat() a directory entry.
- This can happen when (network) file systems fail. If this
- entry is in fact the one we are looking for we will find
- out soon as we reach the end of the directory without
- having found anything. */
- if (entry_status == 0 && S_ISDIR (st.st_mode)
- && st.st_dev == thisdev && st.st_ino == thisino)
- break;
- }
+ /* We don't fail here if we cannot stat() a directory entry.
+ This can happen when (network) file systems fail. If this
+ entry is in fact the one we are looking for we will find
+ out soon as we reach the end of the directory without
+ having found anything. */
+ if (entry_status == 0 && S_ISDIR (st.st_mode)
+ && st.st_dev == thisdev && st.st_ino == thisino)
+ break;
+ }
}
dirroom = dirp - dir;
diff --git a/lib/getopt.c b/lib/getopt.c
index 83bd6db..f37a837 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -31,7 +31,7 @@
#include <string.h>
#include <unistd.h>
-#ifdef VMS
+#ifdef __VMS
# include <unixlib.h>
#endif
diff --git a/lib/lstat.c b/lib/lstat.c
index f5a22b0..9b9c33e 100644
--- a/lib/lstat.c
+++ b/lib/lstat.c
@@ -1,6 +1,6 @@
/* Work around a bug of lstat on some systems
- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -30,28 +30,28 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "stat-macros.h"
-#include "xalloc.h"
/* lstat works differently on Linux and Solaris systems. POSIX (see
- `pathname resolution' in the glossary) requires that programs like `ls'
- take into consideration the fact that FILE has a trailing slash when
- FILE is a symbolic link. On Linux systems, the lstat function already
- has the desired semantics (in treating `lstat("symlink/",sbuf)' just like
- `lstat("symlink/.",sbuf)', but on Solaris it does not.
+ `pathname resolution' in the glossary) requires that programs like
+ `ls' take into consideration the fact that FILE has a trailing slash
+ when FILE is a symbolic link. On Linux and Solaris 10 systems, the
+ lstat function already has the desired semantics (in treating
+ `lstat ("symlink/", sbuf)' just like `lstat ("symlink/.", sbuf)',
+ but on Solaris 9 and earlier it does not.
If FILE has a trailing slash and specifies a symbolic link,
- then append a `.' to FILE and call lstat a second time. */
+ then use stat() to get more info on the referent of FILE.
+ If the referent is a non-directory, then set errno to ENOTDIR
+ and return -1. Otherwise, return stat's result. */
int
rpl_lstat (const char *file, struct stat *sbuf)
{
size_t len;
- char *new_file;
-
int lstat_result = lstat (file, sbuf);
if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode))
@@ -59,19 +59,22 @@ rpl_lstat (const char *file, struct stat *sbuf)
len = strlen (file);
if (len == 0 || file[len - 1] != '/')
- return lstat_result;
+ return 0;
/* FILE refers to a symbolic link and the name ends with a slash.
- Append a `.' to FILE and repeat the lstat call. */
+ Call stat() to get info about the link's referent. */
- /* Add one for the `.' we'll append, and one more for the trailing NUL. */
- new_file = xmalloc (len + 1 + 1);
- memcpy (new_file, file, len);
- new_file[len] = '.';
- new_file[len + 1] = 0;
+ /* If stat fails, then we do the same. */
+ if (stat (file, sbuf) != 0)
+ return -1;
- lstat_result = lstat (new_file, sbuf);
- free (new_file);
+ /* If FILE references a directory, return 0. */
+ if (S_ISDIR (sbuf->st_mode))
+ return 0;
- return lstat_result;
+ /* Here, we know stat succeeded and FILE references a non-directory.
+ But it was specified via a name including a trailing slash.
+ Fail with errno set to ENOTDIR to indicate the contradiction. */
+ errno = ENOTDIR;
+ return -1;
}
diff --git a/lib/mbchar.h b/lib/mbchar.h
index 4472aa0..738efd9 100644
--- a/lib/mbchar.h
+++ b/lib/mbchar.h
@@ -1,5 +1,5 @@
/* Multibyte character data type.
- Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -158,6 +158,8 @@
#include <wctype.h>
+#include "wcwidth.h"
+
#define MBCHAR_BUF_SIZE 24
struct mbchar
diff --git a/lib/regcomp.c b/lib/regcomp.c
index 279b20c..6e317f5 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -1,5 +1,5 @@
/* Extended regular expression matching and search library.
- Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
@@ -18,11 +18,11 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
- Idx length, reg_syntax_t syntax);
+ size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
const re_dfastate_t *init_state,
char *fastmap);
-static reg_errcode_t init_dfa (re_dfa_t *dfa, Idx pat_len);
+static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
#ifdef RE_ENABLE_I18N
static void free_charset (re_charset_t *cset);
#endif /* RE_ENABLE_I18N */
@@ -55,7 +55,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
static Idx fetch_number (re_string_t *input, re_token_t *token,
reg_syntax_t syntax);
static int peek_token (re_token_t *token, re_string_t *input,
- reg_syntax_t syntax);
+ reg_syntax_t syntax) internal_function;
static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
reg_syntax_t syntax, reg_errcode_t *err);
static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
@@ -86,26 +86,26 @@ static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
re_string_t *regexp,
re_token_t *token);
#ifdef RE_ENABLE_I18N
-static reg_errcode_t build_equiv_class (bitset sbcset,
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
re_charset_t *mbcset,
Idx *equiv_class_alloc,
const unsigned char *name);
-static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
- bitset sbcset,
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
re_charset_t *mbcset,
Idx *char_class_alloc,
const unsigned char *class_name,
reg_syntax_t syntax);
#else /* not RE_ENABLE_I18N */
-static reg_errcode_t build_equiv_class (bitset sbcset,
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
const unsigned char *name);
-static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
- bitset sbcset,
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
const unsigned char *class_name,
reg_syntax_t syntax);
#endif /* not RE_ENABLE_I18N */
static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
- unsigned REG_TRANSLATE_TYPE trans,
+ RE_TRANSLATE_TYPE trans,
const unsigned char *class_name,
const unsigned char *extra,
bool non_match, reg_errcode_t *err);
@@ -125,7 +125,7 @@ static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node);
POSIX doesn't require that we do anything for REG_NOERROR,
but why not be nice? */
-const char __re_error_msgid[] attribute_hidden =
+static const char __re_error_msgid[] =
{
#define REG_NOERROR_IDX 0
gettext_noop ("Success") /* REG_NOERROR */
@@ -179,7 +179,7 @@ const char __re_error_msgid[] attribute_hidden =
gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
};
-const size_t __re_error_msgid_idx[] attribute_hidden =
+static const size_t __re_error_msgid_idx[] =
{
REG_NOERROR_IDX,
REG_NOMATCH_IDX,
@@ -206,22 +206,30 @@ const size_t __re_error_msgid_idx[] attribute_hidden =
compiles PATTERN (of length LENGTH) and puts the result in BUFP.
Returns 0 if the pattern was valid, otherwise an error string.
- Assumes the `re_allocated' (and perhaps `re_buffer') and `translate' fields
+ Assumes the `allocated' (and perhaps `buffer') and `translate' fields
are set in BUFP on entry. */
+#ifdef _LIBC
+const char *
+re_compile_pattern (pattern, length, bufp)
+ const char *pattern;
+ size_t length;
+ struct re_pattern_buffer *bufp;
+#else /* size_t might promote */
const char *
re_compile_pattern (const char *pattern, size_t length,
struct re_pattern_buffer *bufp)
+#endif
{
reg_errcode_t ret;
/* And GNU code determines whether or not to get register information
by passing null for the REGS argument to re_match, etc., not by
- setting re_no_sub, unless REG_NO_SUB is set. */
- bufp->re_no_sub = !!(re_syntax_options & REG_NO_SUB);
+ setting no_sub, unless RE_NO_SUB is set. */
+ bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
/* Match anchors at newline. */
- bufp->re_newline_anchor = 1;
+ bufp->newline_anchor = 1;
ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
@@ -249,7 +257,8 @@ reg_syntax_t re_syntax_options;
defined in regex.h. We return the old syntax. */
reg_syntax_t
-re_set_syntax (reg_syntax_t syntax)
+re_set_syntax (syntax)
+ reg_syntax_t syntax;
{
reg_syntax_t ret = re_syntax_options;
@@ -261,10 +270,11 @@ weak_alias (__re_set_syntax, re_set_syntax)
#endif
int
-re_compile_fastmap (struct re_pattern_buffer *bufp)
+re_compile_fastmap (bufp)
+ struct re_pattern_buffer *bufp;
{
- re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
- char *fastmap = bufp->re_fastmap;
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+ char *fastmap = bufp->fastmap;
memset (fastmap, '\0', sizeof (char) * SBC_MAX);
re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
@@ -274,7 +284,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
if (dfa->init_state != dfa->init_state_begbuf)
re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
- bufp->re_fastmap_accurate = 1;
+ bufp->fastmap_accurate = 1;
return 0;
}
#ifdef _LIBC
@@ -297,9 +307,9 @@ static void
re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
char *fastmap)
{
- re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
Idx node_cnt;
- bool icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE));
+ bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
{
Idx node = init_state->nodes.elems[node_cnt];
@@ -309,7 +319,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
{
re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
#ifdef RE_ENABLE_I18N
- if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
{
unsigned char buf[MB_LEN_MAX];
unsigned char *p;
@@ -322,7 +332,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
&& dfa->nodes[node].type == CHARACTER
&& dfa->nodes[node].mb_partial)
*p++ = dfa->nodes[node].opr.c;
- memset (&state, 0, sizeof (state));
+ memset (&state, '\0', sizeof (state));
if (mbrtowc (&wc, (const char *) buf, p - buf,
&state) == p - buf
&& (__wcrtomb ((char *) buf, towlower (wc), &state)
@@ -333,11 +343,15 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
}
else if (type == SIMPLE_BRACKET)
{
- int i, j, ch;
+ int i, ch;
for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
- for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
- if (dfa->nodes[node].opr.sbcset[i] & ((bitset_word) 1 << j))
- re_set_fastmap (fastmap, icase, ch);
+ {
+ int j;
+ bitset_word_t w = dfa->nodes[node].opr.sbcset[i];
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ if (w & ((bitset_word_t) 1 << j))
+ re_set_fastmap (fastmap, icase, ch);
+ }
}
#ifdef RE_ENABLE_I18N
else if (type == COMPLEX_BRACKET)
@@ -376,7 +390,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
memset (&state, '\0', sizeof (state));
if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
- if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
{
if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
!= (size_t) -1)
@@ -393,7 +407,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
{
memset (fastmap, '\1', sizeof (char) * SBC_MAX);
if (type == END_OF_RE)
- bufp->re_can_be_null = 1;
+ bufp->can_be_null = 1;
return;
}
}
@@ -405,14 +419,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
PREG is a regex_t *. We do not expect any fields to be initialized,
since POSIX says we shouldn't. Thus, we set
- `re_buffer' to the compiled pattern;
- `re_used' to the length of the compiled pattern;
- `re_syntax' to REG_SYNTAX_POSIX_EXTENDED if the
+ `buffer' to the compiled pattern;
+ `used' to the length of the compiled pattern;
+ `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
REG_EXTENDED bit in CFLAGS is set; otherwise, to
- REG_SYNTAX_POSIX_BASIC;
- `re_newline_anchor' to REG_NEWLINE being set in CFLAGS;
- `re_fastmap' to an allocated space for the fastmap;
- `re_fastmap_accurate' to zero;
+ RE_SYNTAX_POSIX_BASIC;
+ `newline_anchor' to REG_NEWLINE being set in CFLAGS;
+ `fastmap' to an allocated space for the fastmap;
+ `fastmap_accurate' to zero;
`re_nsub' to the number of subexpressions in PATTERN.
PATTERN is the address of the pattern string.
@@ -436,35 +450,38 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
the return codes and their meanings.) */
int
-regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
+regcomp (preg, pattern, cflags)
+ regex_t *__restrict preg;
+ const char *__restrict pattern;
+ int cflags;
{
reg_errcode_t ret;
- reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? REG_SYNTAX_POSIX_EXTENDED
- : REG_SYNTAX_POSIX_BASIC);
+ reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
+ : RE_SYNTAX_POSIX_BASIC);
- preg->re_buffer = NULL;
- preg->re_allocated = 0;
- preg->re_used = 0;
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ preg->used = 0;
/* Try to allocate space for the fastmap. */
- preg->re_fastmap = re_malloc (char, SBC_MAX);
- if (BE (preg->re_fastmap == NULL, 0))
+ preg->fastmap = re_malloc (char, SBC_MAX);
+ if (BE (preg->fastmap == NULL, 0))
return REG_ESPACE;
- syntax |= (cflags & REG_ICASE) ? REG_IGNORE_CASE : 0;
+ syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
/* If REG_NEWLINE is set, newlines are treated differently. */
if (cflags & REG_NEWLINE)
{ /* REG_NEWLINE implies neither . nor [^...] match newline. */
- syntax &= ~REG_DOT_NEWLINE;
- syntax |= REG_HAT_LISTS_NOT_NEWLINE;
+ syntax &= ~RE_DOT_NEWLINE;
+ syntax |= RE_HAT_LISTS_NOT_NEWLINE;
/* It also changes the matching behavior. */
- preg->re_newline_anchor = 1;
+ preg->newline_anchor = 1;
}
else
- preg->re_newline_anchor = 0;
- preg->re_no_sub = !!(cflags & REG_NOSUB);
- preg->re_translate = NULL;
+ preg->newline_anchor = 0;
+ preg->no_sub = !!(cflags & REG_NOSUB);
+ preg->translate = NULL;
ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
@@ -473,7 +490,7 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
if (ret == REG_ERPAREN)
ret = REG_EPAREN;
- /* We have already checked preg->re_fastmap != NULL. */
+ /* We have already checked preg->fastmap != NULL. */
if (BE (ret == REG_NOERROR, 1))
/* Compute the fastmap now, since regexec cannot modify the pattern
buffer. This function never fails in this implementation. */
@@ -481,8 +498,8 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
else
{
/* Some error occurred while compiling the expression. */
- re_free (preg->re_fastmap);
- preg->re_fastmap = NULL;
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
}
return (int) ret;
@@ -494,9 +511,18 @@ weak_alias (__regcomp, regcomp)
/* Returns a message corresponding to an error code, ERRCODE, returned
from either regcomp or regexec. We don't use PREG here. */
+#ifdef _LIBC
+size_t
+regerror (errcode, preg, errbuf, errbuf_size)
+ int errcode;
+ const regex_t *__restrict preg;
+ char *__restrict errbuf;
+ size_t errbuf_size;
+#else /* size_t might promote */
size_t
regerror (int errcode, const regex_t *__restrict preg,
char *__restrict errbuf, size_t errbuf_size)
+#endif
{
const char *msg;
size_t msg_size;
@@ -541,21 +567,18 @@ weak_alias (__regerror, regerror)
UTF-8 is used. Otherwise we would allocate memory just to initialize
it the same all the time. UTF-8 is the preferred encoding so this is
a worthwhile optimization. */
-static const bitset utf8_sb_map =
+static const bitset_t utf8_sb_map =
{
/* Set the first 128 bits. */
-# if 2 < BITSET_WORDS
- BITSET_WORD_MAX,
-# endif
-# if 4 < BITSET_WORDS
- BITSET_WORD_MAX,
-# endif
-# if 6 < BITSET_WORDS
+# if 4 * BITSET_WORD_BITS < ASCII_CHARS
+# error "bitset_word_t is narrower than 32 bits"
+# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
BITSET_WORD_MAX,
# endif
-# if 8 < BITSET_WORDS
-# error "Invalid BITSET_WORDS"
-# endif
(BITSET_WORD_MAX
>> (SBC_MAX % BITSET_WORD_BITS == 0
? 0
@@ -615,19 +638,20 @@ free_dfa_content (re_dfa_t *dfa)
/* Free dynamically allocated space used by PREG. */
void
-regfree (regex_t *preg)
+regfree (preg)
+ regex_t *preg;
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
if (BE (dfa != NULL, 1))
free_dfa_content (dfa);
- preg->re_buffer = NULL;
- preg->re_allocated = 0;
+ preg->buffer = NULL;
+ preg->allocated = 0;
- re_free (preg->re_fastmap);
- preg->re_fastmap = NULL;
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
- re_free (preg->re_translate);
- preg->re_translate = NULL;
+ re_free (preg->translate);
+ preg->translate = NULL;
}
#ifdef _LIBC
weak_alias (__regfree, regfree)
@@ -648,31 +672,32 @@ char *
regcomp/regexec above without link errors. */
weak_function
# endif
-re_comp (const char *s)
+re_comp (s)
+ const char *s;
{
reg_errcode_t ret;
char *fastmap;
if (!s)
{
- if (!re_comp_buf.re_buffer)
+ if (!re_comp_buf.buffer)
return gettext ("No previous regular expression");
return 0;
}
- if (re_comp_buf.re_buffer)
+ if (re_comp_buf.buffer)
{
- fastmap = re_comp_buf.re_fastmap;
- re_comp_buf.re_fastmap = NULL;
+ fastmap = re_comp_buf.fastmap;
+ re_comp_buf.fastmap = NULL;
__regfree (&re_comp_buf);
memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
- re_comp_buf.re_fastmap = fastmap;
+ re_comp_buf.fastmap = fastmap;
}
- if (re_comp_buf.re_fastmap == NULL)
+ if (re_comp_buf.fastmap == NULL)
{
- re_comp_buf.re_fastmap = (char *) malloc (SBC_MAX);
- if (re_comp_buf.re_fastmap == NULL)
+ re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
+ if (re_comp_buf.fastmap == NULL)
return (char *) gettext (__re_error_msgid
+ __re_error_msgid_idx[(int) REG_ESPACE]);
}
@@ -681,7 +706,7 @@ re_comp (const char *s)
don't need to initialize the pattern buffer fields which affect it. */
/* Match anchors at newlines. */
- re_comp_buf.re_newline_anchor = 1;
+ re_comp_buf.newline_anchor = 1;
ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
@@ -706,7 +731,7 @@ libc_freeres_fn (free_mem)
SYNTAX indicate regular expression's syntax. */
static reg_errcode_t
-re_compile_internal (regex_t *preg, const char *pattern, Idx length,
+re_compile_internal (regex_t *preg, const char * pattern, size_t length,
reg_syntax_t syntax)
{
reg_errcode_t err = REG_NOERROR;
@@ -714,55 +739,56 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
re_string_t regexp;
/* Initialize the pattern buffer. */
- preg->re_fastmap_accurate = 0;
- preg->re_syntax = syntax;
- preg->re_not_bol = preg->re_not_eol = 0;
- preg->re_used = 0;
+ preg->fastmap_accurate = 0;
+ preg->syntax = syntax;
+ preg->not_bol = preg->not_eol = 0;
+ preg->used = 0;
preg->re_nsub = 0;
- preg->re_can_be_null = 0;
- preg->re_regs_allocated = REG_UNALLOCATED;
+ preg->can_be_null = 0;
+ preg->regs_allocated = REGS_UNALLOCATED;
/* Initialize the dfa. */
- dfa = (re_dfa_t *) preg->re_buffer;
- if (BE (preg->re_allocated < sizeof (re_dfa_t), 0))
+ dfa = (re_dfa_t *) preg->buffer;
+ if (BE (preg->allocated < sizeof (re_dfa_t), 0))
{
/* If zero allocated, but buffer is non-null, try to realloc
enough space. This loses if buffer's address is bogus, but
- that is the user's responsibility. If buffer is null this
+ that is the user's responsibility. If ->buffer is NULL this
is a simple allocation. */
- dfa = re_realloc (preg->re_buffer, re_dfa_t, 1);
+ dfa = re_realloc (preg->buffer, re_dfa_t, 1);
if (dfa == NULL)
return REG_ESPACE;
- preg->re_allocated = sizeof (re_dfa_t);
- preg->re_buffer = (unsigned char *) dfa;
+ preg->allocated = sizeof (re_dfa_t);
+ preg->buffer = (unsigned char *) dfa;
}
- preg->re_used = sizeof (re_dfa_t);
-
- __libc_lock_init (dfa->lock);
+ preg->used = sizeof (re_dfa_t);
err = init_dfa (dfa, length);
if (BE (err != REG_NOERROR, 0))
{
free_dfa_content (dfa);
- preg->re_buffer = NULL;
- preg->re_allocated = 0;
+ preg->buffer = NULL;
+ preg->allocated = 0;
return err;
}
#ifdef DEBUG
+ /* Note: length+1 will not overflow since it is checked in init_dfa. */
dfa->re_str = re_malloc (char, length + 1);
strncpy (dfa->re_str, pattern, length + 1);
#endif
- err = re_string_construct (&regexp, pattern, length, preg->re_translate,
- syntax & REG_IGNORE_CASE, dfa);
+ __libc_lock_init (dfa->lock);
+
+ err = re_string_construct (&regexp, pattern, length, preg->translate,
+ syntax & RE_ICASE, dfa);
if (BE (err != REG_NOERROR, 0))
{
re_compile_internal_free_return:
free_workarea_compile (preg);
re_string_destruct (&regexp);
free_dfa_content (dfa);
- preg->re_buffer = NULL;
- preg->re_allocated = 0;
+ preg->buffer = NULL;
+ preg->allocated = 0;
return err;
}
@@ -779,7 +805,7 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
#ifdef RE_ENABLE_I18N
/* If possible, do searching in single byte encoding to speed things up. */
- if (dfa->is_utf8 && !(syntax & REG_IGNORE_CASE) && preg->re_translate == NULL)
+ if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
optimize_utf8 (dfa);
#endif
@@ -793,8 +819,8 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
if (BE (err != REG_NOERROR, 0))
{
free_dfa_content (dfa);
- preg->re_buffer = NULL;
- preg->re_allocated = 0;
+ preg->buffer = NULL;
+ preg->allocated = 0;
}
return err;
@@ -804,27 +830,45 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
as the initial length of some arrays. */
static reg_errcode_t
-init_dfa (re_dfa_t *dfa, Idx pat_len)
+init_dfa (re_dfa_t *dfa, size_t pat_len)
{
__re_size_t table_size;
#ifndef _LIBC
char *codeset_name;
#endif
+#ifdef RE_ENABLE_I18N
+ size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
+#else
+ size_t max_i18n_object_size = 0;
+#endif
+ size_t max_object_size =
+ MAX (sizeof (struct re_state_table_entry),
+ MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ MAX (sizeof (regmatch_t),
+ max_i18n_object_size))));
memset (dfa, '\0', sizeof (re_dfa_t));
/* Force allocation of str_tree_storage the first time. */
dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+ /* Avoid overflows. The extra "/ 2" is for the table_size doubling
+ calculation below, and for similar doubling calculations
+ elsewhere. And it's <= rather than <, because some of the
+ doubling calculations add 1 afterwards. */
+ if (BE (SIZE_MAX / max_object_size / 2 <= pat_len, 0))
+ return REG_ESPACE;
+
dfa->nodes_alloc = pat_len + 1;
- dfa->nodes = re_xmalloc (re_token_t, dfa->nodes_alloc);
+ dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
/* table_size = 2 ^ ceil(log pat_len) */
- for (table_size = 1; table_size <= pat_len; table_size <<= 1)
- if (0 < (Idx) -1 && table_size == 0)
- return REG_ESPACE;
+ for (table_size = 1; ; table_size <<= 1)
+ if (table_size > pat_len)
+ break;
- dfa->state_table = re_calloc (struct re_state_table_entry, table_size);
+ dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
dfa->state_hash_mask = table_size - 1;
dfa->mb_cur_max = MB_CUR_MAX;
@@ -867,7 +911,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
{
int i, j, ch;
- dfa->sb_char = re_calloc (bitset_word, BITSET_WORDS);
+ dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
if (BE (dfa->sb_char == NULL, 0))
return REG_ESPACE;
@@ -877,7 +921,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
{
wint_t wch = __btowc (ch);
if (wch != WEOF)
- dfa->sb_char[i] |= (bitset_word) 1 << j;
+ dfa->sb_char[i] |= (bitset_word_t) 1 << j;
# ifndef _LIBC
if (isascii (ch) && wch != ch)
dfa->map_notascii = 1;
@@ -897,6 +941,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
character used by some operators like "\<", "\>", etc. */
static void
+internal_function
init_word_char (re_dfa_t *dfa)
{
int i, j, ch;
@@ -904,7 +949,7 @@ init_word_char (re_dfa_t *dfa)
for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
if (isalnum (ch) || ch == '_')
- dfa->word_char[i] |= (bitset_word) 1 << j;
+ dfa->word_char[i] |= (bitset_word_t) 1 << j;
}
/* Free the work area which are only used while compiling. */
@@ -912,7 +957,7 @@ init_word_char (re_dfa_t *dfa)
static void
free_workarea_compile (regex_t *preg)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_storage_t *storage, *next;
for (storage = dfa->str_tree_storage; storage; storage = next)
{
@@ -1022,7 +1067,7 @@ optimize_utf8 (re_dfa_t *dfa)
switch (dfa->nodes[node].type)
{
case CHARACTER:
- if (dfa->nodes[node].opr.c >= 0x80)
+ if (dfa->nodes[node].opr.c >= ASCII_CHARS)
mb_chars = true;
break;
case ANCHOR:
@@ -1053,11 +1098,10 @@ optimize_utf8 (re_dfa_t *dfa)
case SIMPLE_BRACKET:
/* Just double check. */
{
- int rshift =
- (SBC_MAX / 2 % BITSET_WORD_BITS == 0
- ? 0
- : BITSET_WORD_BITS - SBC_MAX / 2 % BITSET_WORD_BITS);
- for (i = SBC_MAX / 2 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
+ int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
+ ? 0
+ : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
+ for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
{
if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
return;
@@ -1073,7 +1117,7 @@ optimize_utf8 (re_dfa_t *dfa)
for (node = 0; node < dfa->nodes_len; ++node)
{
if (dfa->nodes[node].type == CHARACTER
- && dfa->nodes[node].opr.c >= 0x80)
+ && dfa->nodes[node].opr.c >= ASCII_CHARS)
dfa->nodes[node].mb_partial = 0;
else if (dfa->nodes[node].type == OP_PERIOD)
dfa->nodes[node].type = OP_UTF8_PERIOD;
@@ -1092,19 +1136,19 @@ optimize_utf8 (re_dfa_t *dfa)
static reg_errcode_t
analyze (regex_t *preg)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
reg_errcode_t ret;
/* Allocate arrays. */
dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
- dfa->edests = re_xmalloc (re_node_set, dfa->nodes_alloc);
+ dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
|| dfa->eclosures == NULL, 0))
return REG_ESPACE;
- dfa->subexp_map = re_xmalloc (Idx, preg->re_nsub);
+ dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
if (dfa->subexp_map != NULL)
{
Idx i;
@@ -1137,10 +1181,10 @@ analyze (regex_t *preg)
/* We only need this during the prune_impossible_nodes pass in regexec.c;
skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
- if ((!preg->re_no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
+ if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
|| dfa->nbackref)
{
- dfa->inveclosures = re_xmalloc (re_node_set, dfa->nodes_len);
+ dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
if (BE (dfa->inveclosures == NULL, 0))
return REG_ESPACE;
ret = calc_inveclosure (dfa);
@@ -1240,7 +1284,7 @@ optimize_subexps (void *extra, bin_tree_t *node)
dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
if (other_idx < BITSET_WORD_BITS)
- dfa->used_bkref_map &= ~ ((bitset_word) 1 << other_idx);
+ dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
}
return REG_NOERROR;
@@ -1273,18 +1317,19 @@ lower_subexps (void *extra, bin_tree_t *node)
static bin_tree_t *
lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *body = node->left;
bin_tree_t *op, *cls, *tree1, *tree;
- if (preg->re_no_sub
+ if (preg->no_sub
/* We do not optimize empty subexpressions, because otherwise we may
have bad CONCAT nodes with NULL children. This is obviously not
very common, so we do not lose much. An example that triggers
this case is the sed "script" /\(\)/x. */
&& node->left != NULL
- && ! (node->token.opr.idx < BITSET_WORD_BITS
- && dfa->used_bkref_map & ((bitset_word) 1 << node->token.opr.idx)))
+ && (node->token.opr.idx >= BITSET_WORD_BITS
+ || !(dfa->used_bkref_map
+ & ((bitset_word_t) 1 << node->token.opr.idx))))
return node->left;
/* Convert the SUBEXP node to the concatenation of an
@@ -1410,9 +1455,9 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
to their own constraint. */
static reg_errcode_t
-duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node,
- Idx top_clone_node, Idx root_node,
- unsigned int init_constraint)
+internal_function
+duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
+ Idx root_node, unsigned int init_constraint)
{
Idx org_node, clone_node;
bool ok;
@@ -1458,8 +1503,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node,
/* ...but if the node is root_node itself, it means the
epsilon closure have a loop, then tie it to the
destination of the root_node. */
- ok = re_node_set_insert (dfa->edests + clone_node,
- org_dest);
+ ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
if (BE (! ok, 0))
return REG_ESPACE;
break;
@@ -1652,8 +1696,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
&& dfa->edests[node].nelem
&& !dfa->nodes[dfa->edests[node].elems[0]].duplicated)
{
- Idx org_node, cur_node;
- org_node = cur_node = node;
err = duplicate_node_closure (dfa, node, node, node, constraint);
if (BE (err != REG_NOERROR, 0))
return err;
@@ -1711,6 +1753,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
We must not use this function inside bracket expressions. */
static void
+internal_function
fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
{
re_string_skip_bytes (input, peek_token (result, input, syntax));
@@ -1720,6 +1763,7 @@ fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
We must not use this function inside bracket expressions. */
static int
+internal_function
peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
{
unsigned char c;
@@ -1770,97 +1814,97 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
switch (c2)
{
case '|':
- if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_NO_BK_VBAR))
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
token->type = OP_ALT;
break;
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
- if (!(syntax & REG_NO_BK_REFS))
+ if (!(syntax & RE_NO_BK_REFS))
{
token->type = OP_BACK_REF;
token->opr.idx = c2 - '1';
}
break;
case '<':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_FIRST;
}
break;
case '>':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_LAST;
}
break;
case 'b':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_DELIM;
}
break;
case 'B':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = NOT_WORD_DELIM;
}
break;
case 'w':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_WORD;
break;
case 'W':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_NOTWORD;
break;
case 's':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_SPACE;
break;
case 'S':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_NOTSPACE;
break;
case '`':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = BUF_FIRST;
}
break;
case '\'':
- if (!(syntax & REG_NO_GNU_OPS))
+ if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = BUF_LAST;
}
break;
case '(':
- if (!(syntax & REG_NO_BK_PARENS))
+ if (!(syntax & RE_NO_BK_PARENS))
token->type = OP_OPEN_SUBEXP;
break;
case ')':
- if (!(syntax & REG_NO_BK_PARENS))
+ if (!(syntax & RE_NO_BK_PARENS))
token->type = OP_CLOSE_SUBEXP;
break;
case '+':
- if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_PLUS;
break;
case '?':
- if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_QUESTION;
break;
case '{':
- if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
token->type = OP_OPEN_DUP_NUM;
break;
case '}':
- if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
token->type = OP_CLOSE_DUP_NUM;
break;
default:
@@ -1883,38 +1927,38 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
switch (c)
{
case '\n':
- if (syntax & REG_NEWLINE_ALT)
+ if (syntax & RE_NEWLINE_ALT)
token->type = OP_ALT;
break;
case '|':
- if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_NO_BK_VBAR))
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
token->type = OP_ALT;
break;
case '*':
token->type = OP_DUP_ASTERISK;
break;
case '+':
- if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_PLUS;
break;
case '?':
- if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_QUESTION;
break;
case '{':
- if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
token->type = OP_OPEN_DUP_NUM;
break;
case '}':
- if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
token->type = OP_CLOSE_DUP_NUM;
break;
case '(':
- if (syntax & REG_NO_BK_PARENS)
+ if (syntax & RE_NO_BK_PARENS)
token->type = OP_OPEN_SUBEXP;
break;
case ')':
- if (syntax & REG_NO_BK_PARENS)
+ if (syntax & RE_NO_BK_PARENS)
token->type = OP_CLOSE_SUBEXP;
break;
case '[':
@@ -1924,18 +1968,18 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
token->type = OP_PERIOD;
break;
case '^':
- if (!(syntax & (REG_CONTEXT_INDEP_ANCHORS | REG_CARET_ANCHORS_HERE)) &&
+ if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
re_string_cur_idx (input) != 0)
{
char prev = re_string_peek_byte (input, -1);
- if (!(syntax & REG_NEWLINE_ALT) || prev != '\n')
+ if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
break;
}
token->type = ANCHOR;
token->opr.ctx_type = LINE_FIRST;
break;
case '$':
- if (!(syntax & REG_CONTEXT_INDEP_ANCHORS) &&
+ if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
re_string_cur_idx (input) + 1 != re_string_length (input))
{
re_token_t next;
@@ -1958,6 +2002,7 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
We must not use this function out of bracket expressions. */
static int
+internal_function
peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
{
unsigned char c;
@@ -1978,7 +2023,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
}
#endif /* RE_ENABLE_I18N */
- if (c == '\\' && (syntax & REG_BACKSLASH_ESCAPE_IN_LISTS)
+ if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
&& re_string_cur_idx (input) + 1 < re_string_length (input))
{
/* In this case, '\' escape a character. */
@@ -2008,7 +2053,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
token->type = OP_OPEN_EQUIV_CLASS;
break;
case ':':
- if (syntax & REG_CHAR_CLASSES)
+ if (syntax & RE_CHAR_CLASSES)
{
token->type = OP_OPEN_CHAR_CLASS;
break;
@@ -2057,11 +2102,11 @@ static bin_tree_t *
parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
reg_errcode_t *err)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree, *eor, *root;
re_token_t current_token;
dfa->syntax = syntax;
- fetch_token (&current_token, regexp, syntax | REG_CARET_ANCHORS_HERE);
+ fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
@@ -2091,7 +2136,7 @@ static bin_tree_t *
parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree, *branch = NULL;
tree = parse_branch (regexp, preg, token, syntax, nest, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
@@ -2099,7 +2144,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
while (token->type == OP_ALT)
{
- fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
if (token->type != OP_ALT && token->type != END_OF_RE
&& (nest == 0 || token->type != OP_CLOSE_SUBEXP))
{
@@ -2133,7 +2178,7 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
bin_tree_t *tree, *exp;
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
tree = parse_expression (regexp, preg, token, syntax, nest, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
@@ -2172,7 +2217,7 @@ static bin_tree_t *
parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree;
switch (token->type)
{
@@ -2229,7 +2274,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
dfa->has_mb_node = 1;
break;
case OP_OPEN_DUP_NUM:
- if (syntax & REG_CONTEXT_INVALID_DUP)
+ if (syntax & RE_CONTEXT_INVALID_DUP)
{
*err = REG_BADRPT;
return NULL;
@@ -2238,12 +2283,12 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
case OP_DUP_ASTERISK:
case OP_DUP_PLUS:
case OP_DUP_QUESTION:
- if (syntax & REG_CONTEXT_INVALID_OPS)
+ if (syntax & RE_CONTEXT_INVALID_OPS)
{
*err = REG_BADRPT;
return NULL;
}
- else if (syntax & REG_CONTEXT_INDEP_OPS)
+ else if (syntax & RE_CONTEXT_INDEP_OPS)
{
fetch_token (token, regexp, syntax);
return parse_expression (regexp, preg, token, syntax, nest, err);
@@ -2251,7 +2296,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
/* else fall through */
case OP_CLOSE_SUBEXP:
if ((token->type == OP_CLOSE_SUBEXP) &&
- !(syntax & REG_UNMATCHED_RIGHT_PAREN_ORD))
+ !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
{
*err = REG_ERPAREN;
return NULL;
@@ -2365,7 +2410,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
/* In BRE consecutive duplications are not allowed. */
- if ((syntax & REG_CONTEXT_INVALID_DUP)
+ if ((syntax & RE_CONTEXT_INVALID_DUP)
&& (token->type == OP_DUP_ASTERISK
|| token->type == OP_OPEN_DUP_NUM))
{
@@ -2388,12 +2433,12 @@ static bin_tree_t *
parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree;
size_t cur_nsub;
cur_nsub = preg->re_nsub++;
- fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
/* The subexpression may be a null string. */
if (token->type == OP_CLOSE_SUBEXP)
@@ -2454,7 +2499,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
if (BE (start == REG_ERROR || end == REG_ERROR, 0))
{
/* Invalid sequence. */
- if (BE (!(syntax & REG_INVALID_INTERVAL_ORD), 0))
+ if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
{
if (token->type == END_OF_RE)
*err = REG_EBRACE;
@@ -2565,11 +2610,14 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
update it. */
static reg_errcode_t
-build_range_exp (bitset sbcset,
+internal_function
# ifdef RE_ENABLE_I18N
- re_charset_t *mbcset, Idx *range_alloc,
-# endif
+build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc,
bracket_elem_t *start_elem, bracket_elem_t *end_elem)
+# else /* not RE_ENABLE_I18N */
+build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
+ bracket_elem_t *end_elem)
+# endif /* not RE_ENABLE_I18N */
{
unsigned int start_ch, end_ch;
/* Equivalence Classes and Character Classes can't be a range start/end. */
@@ -2589,7 +2637,8 @@ build_range_exp (bitset sbcset,
# ifdef RE_ENABLE_I18N
{
wchar_t wc;
- wint_t start_wc, end_wc;
+ wint_t start_wc;
+ wint_t end_wc;
wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
@@ -2623,11 +2672,12 @@ build_range_exp (bitset sbcset,
wchar_t *new_array_start, *new_array_end;
Idx new_nranges;
- new_nranges = mbcset->nranges;
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
/* Use realloc since mbcset->range_starts and mbcset->range_ends
are NULL if *range_alloc == 0. */
- new_array_start = re_x2realloc (mbcset->range_starts, wchar_t,
- &new_nranges);
+ new_array_start = re_realloc (mbcset->range_starts, wchar_t,
+ new_nranges);
new_array_end = re_realloc (mbcset->range_ends, wchar_t,
new_nranges);
@@ -2681,7 +2731,8 @@ build_range_exp (bitset sbcset,
pointer argument since we may update it. */
static reg_errcode_t
-build_collating_symbol (bitset sbcset,
+internal_function
+build_collating_symbol (bitset_t sbcset,
# ifdef RE_ENABLE_I18N
re_charset_t *mbcset, Idx *coll_sym_alloc,
# endif
@@ -2719,27 +2770,34 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline int32_t
__attribute ((always_inline))
- seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
+ seek_collating_symbol_entry (name, name_len)
+ const unsigned char *name;
+ size_t name_len;
{
int32_t hash = elem_hash ((const char *) name, name_len);
int32_t elem = hash % table_size;
- int32_t second = hash % (table_size - 2);
- while (symb_table[2 * elem] != 0)
- {
- /* First compare the hashing value. */
- if (symb_table[2 * elem] == hash
- /* Compare the length of the name. */
- && name_len == extra[symb_table[2 * elem + 1]]
- /* Compare the name. */
- && memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
- name_len) == 0)
+ if (symb_table[2 * elem] != 0)
+ {
+ int32_t second = hash % (table_size - 2) + 1;
+
+ do
{
- /* Yep, this is the entry. */
- break;
- }
+ /* First compare the hashing value. */
+ if (symb_table[2 * elem] == hash
+ /* Compare the length of the name. */
+ && name_len == extra[symb_table[2 * elem + 1]]
+ /* Compare the name. */
+ && memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
+ name_len) == 0)
+ {
+ /* Yep, this is the entry. */
+ break;
+ }
- /* Next entry. */
- elem += second;
+ /* Next entry. */
+ elem += second;
+ }
+ while (symb_table[2 * elem] != 0);
}
return elem;
}
@@ -2750,7 +2808,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline unsigned int
__attribute ((always_inline))
- lookup_collation_sequence_value (bracket_elem_t *br_elem)
+ lookup_collation_sequence_value (br_elem)
+ bracket_elem_t *br_elem;
{
if (br_elem->type == SB_CHAR)
{
@@ -2817,9 +2876,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline reg_errcode_t
__attribute ((always_inline))
- build_range_exp (bitset sbcset, re_charset_t *mbcset,
- Idx *range_alloc,
- bracket_elem_t *start_elem, bracket_elem_t *end_elem)
+ build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem)
+ re_charset_t *mbcset;
+ Idx *range_alloc;
+ bitset_t sbcset;
+ bracket_elem_t *start_elem, *end_elem;
{
unsigned int ch;
uint32_t start_collseq;
@@ -2837,7 +2898,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
/* Check start/end collation sequence values. */
if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
return REG_ECOLLATE;
- if (BE ((syntax & REG_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
+ if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
return REG_ERANGE;
/* Got valid collation sequence values, add them as a new entry.
@@ -2854,9 +2915,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
uint32_t *new_array_end;
Idx new_nranges;
- new_nranges = mbcset->nranges;
- new_array_start = re_x2realloc (mbcset->range_starts, uint32_t,
- &new_nranges);
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
+ new_array_start = re_realloc (mbcset->range_starts, uint32_t,
+ new_nranges);
new_array_end = re_realloc (mbcset->range_ends, uint32_t,
new_nranges);
@@ -2897,8 +2959,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline reg_errcode_t
__attribute ((always_inline))
- build_collating_symbol (bitset sbcset, re_charset_t *mbcset,
- Idx *coll_sym_alloc, const unsigned char *name)
+ build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name)
+ re_charset_t *mbcset;
+ Idx *coll_sym_alloc;
+ bitset_t sbcset;
+ const unsigned char *name;
{
int32_t elem, idx;
size_t name_len = strlen ((const char *) name);
@@ -2927,11 +2992,12 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
{
/* Not enough, realloc it. */
- Idx new_coll_sym_alloc = mbcset->ncoll_syms;
+ /* +1 in case of mbcset->ncoll_syms is 0. */
+ Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
/* Use realloc since mbcset->coll_syms is NULL
if *alloc == 0. */
- int32_t *new_coll_syms = re_x2realloc (mbcset->coll_syms, int32_t,
- &new_coll_sym_alloc);
+ int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
+ new_coll_sym_alloc);
if (BE (new_coll_syms == NULL, 0))
return REG_ESPACE;
mbcset->coll_syms = new_coll_syms;
@@ -2973,7 +3039,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
/*
if (MB_CUR_MAX > 1)
*/
- collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+ collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE,
_NL_COLLATE_SYMB_TABLEMB);
@@ -2981,9 +3047,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
_NL_COLLATE_SYMB_EXTRAMB);
}
#endif
- sbcset = re_calloc (bitset_word, BITSET_WORDS);
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
#ifdef RE_ENABLE_I18N
- mbcset = re_calloc (re_charset_t, 1);
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
#endif /* RE_ENABLE_I18N */
#ifdef RE_ENABLE_I18N
if (BE (sbcset == NULL || mbcset == NULL, 0))
@@ -3007,7 +3073,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
mbcset->non_match = 1;
#endif /* not RE_ENABLE_I18N */
non_match = true;
- if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
+ if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
bitset_set (sbcset, '\0');
re_string_skip_bytes (regexp, token_len); /* Skip a token. */
token_len = peek_token_bracket (token, regexp, syntax);
@@ -3115,10 +3181,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
{
wchar_t *new_mbchars;
/* Not enough, realloc it. */
- mbchar_alloc = mbcset->nmbchars;
+ /* +1 in case of mbcset->nmbchars is 0. */
+ mbchar_alloc = 2 * mbcset->nmbchars + 1;
/* Use realloc since array is NULL if *alloc == 0. */
- new_mbchars = re_x2realloc (mbcset->mbchars, wchar_t,
- &mbchar_alloc);
+ new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
+ mbchar_alloc);
if (BE (new_mbchars == NULL, 0))
goto parse_bracket_exp_espace;
mbcset->mbchars = new_mbchars;
@@ -3331,13 +3398,14 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
is a pointer argument sinse we may update it. */
static reg_errcode_t
-build_equiv_class (bitset sbcset,
#ifdef RE_ENABLE_I18N
- re_charset_t *mbcset, Idx *equiv_class_alloc,
-#endif
- const unsigned char *name)
+build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
+ Idx *equiv_class_alloc, const unsigned char *name)
+#else /* not RE_ENABLE_I18N */
+build_equiv_class (bitset_t sbcset, const unsigned char *name)
+#endif /* not RE_ENABLE_I18N */
{
-#if defined _LIBC
+#ifdef _LIBC
uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
if (nrules != 0)
{
@@ -3392,11 +3460,12 @@ build_equiv_class (bitset sbcset,
if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0))
{
/* Not enough, realloc it. */
- Idx new_equiv_class_alloc = mbcset->nequiv_classes;
+ /* +1 in case of mbcset->nequiv_classes is 0. */
+ Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
/* Use realloc since the array is NULL if *alloc == 0. */
- int32_t *new_equiv_classes = re_x2realloc (mbcset->equiv_classes,
- int32_t,
- &new_equiv_class_alloc);
+ int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
+ int32_t,
+ new_equiv_class_alloc);
if (BE (new_equiv_classes == NULL, 0))
return REG_ESPACE;
mbcset->equiv_classes = new_equiv_classes;
@@ -3421,18 +3490,21 @@ build_equiv_class (bitset sbcset,
is a pointer argument sinse we may update it. */
static reg_errcode_t
-build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
#ifdef RE_ENABLE_I18N
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
re_charset_t *mbcset, Idx *char_class_alloc,
-#endif
const unsigned char *class_name, reg_syntax_t syntax)
+#else /* not RE_ENABLE_I18N */
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
+ const unsigned char *class_name, reg_syntax_t syntax)
+#endif /* not RE_ENABLE_I18N */
{
int i;
const char *name = (const char *) class_name;
/* In case of REG_ICASE "upper" and "lower" match the both of
upper and lower cases. */
- if ((syntax & REG_IGNORE_CASE)
+ if ((syntax & RE_ICASE)
&& (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
name = "alpha";
@@ -3441,10 +3513,11 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
if (BE (*char_class_alloc == mbcset->nchar_classes, 0))
{
/* Not enough, realloc it. */
- Idx new_char_class_alloc = mbcset->nchar_classes;
+ /* +1 in case of mbcset->nchar_classes is 0. */
+ Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
/* Use realloc since array is NULL if *alloc == 0. */
- wctype_t *new_char_classes = re_x2realloc (mbcset->char_classes, wctype_t,
- &new_char_class_alloc);
+ wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
+ new_char_class_alloc);
if (BE (new_char_classes == NULL, 0))
return REG_ESPACE;
mbcset->char_classes = new_char_classes;
@@ -3454,39 +3527,45 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
#endif /* RE_ENABLE_I18N */
#define BUILD_CHARCLASS_LOOP(ctype_func) \
- for (i = 0; i < SBC_MAX; ++i) \
+ do { \
+ if (BE (trans != NULL, 0)) \
{ \
- if (ctype_func (i)) \
- { \
- int ch = trans ? trans[i] : i; \
- bitset_set (sbcset, ch); \
- } \
- }
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, trans[i]); \
+ } \
+ else \
+ { \
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, i); \
+ } \
+ } while (0)
if (strcmp (name, "alnum") == 0)
- BUILD_CHARCLASS_LOOP (isalnum)
+ BUILD_CHARCLASS_LOOP (isalnum);
else if (strcmp (name, "cntrl") == 0)
- BUILD_CHARCLASS_LOOP (iscntrl)
+ BUILD_CHARCLASS_LOOP (iscntrl);
else if (strcmp (name, "lower") == 0)
- BUILD_CHARCLASS_LOOP (islower)
+ BUILD_CHARCLASS_LOOP (islower);
else if (strcmp (name, "space") == 0)
- BUILD_CHARCLASS_LOOP (isspace)
+ BUILD_CHARCLASS_LOOP (isspace);
else if (strcmp (name, "alpha") == 0)
- BUILD_CHARCLASS_LOOP (isalpha)
+ BUILD_CHARCLASS_LOOP (isalpha);
else if (strcmp (name, "digit") == 0)
- BUILD_CHARCLASS_LOOP (isdigit)
+ BUILD_CHARCLASS_LOOP (isdigit);
else if (strcmp (name, "print") == 0)
- BUILD_CHARCLASS_LOOP (isprint)
+ BUILD_CHARCLASS_LOOP (isprint);
else if (strcmp (name, "upper") == 0)
- BUILD_CHARCLASS_LOOP (isupper)
+ BUILD_CHARCLASS_LOOP (isupper);
else if (strcmp (name, "blank") == 0)
- BUILD_CHARCLASS_LOOP (isblank)
+ BUILD_CHARCLASS_LOOP (isblank);
else if (strcmp (name, "graph") == 0)
- BUILD_CHARCLASS_LOOP (isgraph)
+ BUILD_CHARCLASS_LOOP (isgraph);
else if (strcmp (name, "punct") == 0)
- BUILD_CHARCLASS_LOOP (ispunct)
+ BUILD_CHARCLASS_LOOP (ispunct);
else if (strcmp (name, "xdigit") == 0)
- BUILD_CHARCLASS_LOOP (isxdigit)
+ BUILD_CHARCLASS_LOOP (isxdigit);
else
return REG_ECTYPE;
@@ -3494,10 +3573,10 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
}
static bin_tree_t *
-build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
+build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
const unsigned char *class_name,
- const unsigned char *extra,
- bool non_match, reg_errcode_t *err)
+ const unsigned char *extra, bool non_match,
+ reg_errcode_t *err)
{
re_bitset_ptr_t sbcset;
#ifdef RE_ENABLE_I18N
@@ -3508,9 +3587,9 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
re_token_t br_token;
bin_tree_t *tree;
- sbcset = re_calloc (bitset_word, BITSET_WORDS);
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
#ifdef RE_ENABLE_I18N
- mbcset = re_calloc (re_charset_t, 1);
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
#endif /* RE_ENABLE_I18N */
#ifdef RE_ENABLE_I18N
@@ -3527,7 +3606,7 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
{
#ifdef RE_ENABLE_I18N
/*
- if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
+ if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
bitset_set(cset->sbcset, '\0');
*/
mbcset->non_match = 1;
@@ -3627,7 +3706,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
|| num == REG_ERROR)
? REG_ERROR
: ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0'));
- num = (num > REG_DUP_MAX) ? REG_ERROR : num;
+ num = (num > RE_DUP_MAX) ? REG_ERROR : num;
}
return num;
}
diff --git a/lib/regex.c b/lib/regex.c
index 82e76c0..70ee70e 100644
--- a/lib/regex.c
+++ b/lib/regex.c
@@ -1,5 +1,5 @@
/* Extended regular expression matching and search library.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
@@ -21,6 +21,11 @@
# include <config.h>
#endif
+/* Make sure noone compiles this code with a C++ compiler. */
+#if defined __cplusplus && defined _LIBC
+# error "This is C code, use a C compiler"
+#endif
+
#ifdef _LIBC
/* We have to keep the namespace clean. */
# define regfree(preg) __regfree (preg)
diff --git a/lib/regex.h b/lib/regex.h
index c06a062..51857e5 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -1,6 +1,6 @@
/* Definitions for data structures and routines for the regular
expression library.
- Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005
+ Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -28,16 +28,16 @@
extern "C" {
#endif
-/* Define _REGEX_SOURCE to get definitions that are incompatible with
- POSIX. */
-#if (!defined _REGEX_SOURCE \
- && (defined _GNU_SOURCE \
- || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \
- && !defined _XOPEN_SOURCE)))
-# define _REGEX_SOURCE 1
+/* Define __USE_GNU_REGEX to declare GNU extensions that violate the
+ POSIX name space rules. */
+#undef __USE_GNU_REGEX
+#if (defined _GNU_SOURCE \
+ || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \
+ && !defined _XOPEN_SOURCE))
+# define __USE_GNU_REGEX 1
#endif
-#if defined _REGEX_SOURCE && defined VMS
+#ifdef __VMS
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
should be there. */
# include <stddef.h>
@@ -53,11 +53,13 @@ extern "C" {
/* The type of the offset of a byte within a string.
For historical reasons POSIX 1003.1-2004 requires that regoff_t be
- at least as wide as off_t. This is a bit odd (and many common
- POSIX platforms set it to the more-sensible ssize_t) but we might
- as well conform. We don't know of any hosts where ssize_t is wider
- than off_t, so off_t is safe. */
-typedef off_t regoff_t;
+ at least as wide as off_t. However, many common POSIX platforms set
+ regoff_t to the more-sensible ssize_t and the Open Group has
+ signalled its intention to change the requirement to be that
+ regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN
+ 60 (2005-08-25). We don't know of any hosts where ssize_t or
+ ptrdiff_t is wider than ssize_t, so ssize_t is safe. */
+typedef ssize_t regoff_t;
/* The type of nonnegative object indexes. Traditionally, GNU regex
uses 'int' for these. Code that uses __re_idx_t should work
@@ -97,20 +99,22 @@ typedef unsigned long int active_reg_t;
add or remove a bit, only one other definition need change. */
typedef unsigned long int reg_syntax_t;
+#ifdef __USE_GNU_REGEX
+
/* If this bit is not set, then \ inside a bracket expression is literal.
If set, then such a \ quotes the following character. */
-#define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul
+# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
/* If this bit is not set, then + and ? are operators, and \+ and \? are
literals.
If set, then \+ and \? are operators and + and ? are literals. */
-#define REG_BK_PLUS_QM (1ul << 1)
+# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
/* If this bit is set, then character classes are supported. They are:
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
If not set, then character classes are not supported. */
-#define REG_CHAR_CLASSES (1ul << 2)
+# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
@@ -120,11 +124,11 @@ typedef unsigned long int reg_syntax_t;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
- This bit could be (re)combined with REG_CONTEXT_INDEP_OPS, because
+ This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
We already implemented a previous draft which made those constructs
invalid, though, so we haven't changed the code back. */
-#define REG_CONTEXT_INDEP_ANCHORS (1ul << 3)
+# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
/* If this bit is set, then special characters are always special
regardless of where they are in the pattern.
@@ -132,70 +136,71 @@ typedef unsigned long int reg_syntax_t;
some contexts; otherwise they are ordinary. Specifically,
* + ? and intervals are only special when not after the beginning,
open-group, or alternation operator. */
-#define REG_CONTEXT_INDEP_OPS (1ul << 4)
+# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
immediately after an alternation or begin-group operator. */
-#define REG_CONTEXT_INVALID_OPS (1ul << 5)
+# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
/* If this bit is set, then . matches newline.
If not set, then it doesn't. */
-#define REG_DOT_NEWLINE (1ul << 6)
+# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
/* If this bit is set, then . doesn't match NUL.
If not set, then it does. */
-#define REG_DOT_NOT_NULL (1ul << 7)
+# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
/* If this bit is set, nonmatching lists [^...] do not match newline.
If not set, they do. */
-#define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8)
+# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
/* If this bit is set, either \{...\} or {...} defines an
- interval, depending on REG_NO_BK_BRACES.
+ interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
-#define REG_INTERVALS (1ul << 9)
+# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
/* If this bit is set, +, ? and | aren't recognized as operators.
If not set, they are. */
-#define REG_LIMITED_OPS (1ul << 10)
+# define RE_LIMITED_OPS (RE_INTERVALS << 1)
/* If this bit is set, newline is an alternation operator.
If not set, newline is literal. */
-#define REG_NEWLINE_ALT (1ul << 11)
+# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
-#define REG_NO_BK_BRACES (1ul << 12)
+# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
/* If this bit is set, (...) defines a group, and \( and \) are literals.
If not set, \(...\) defines a group, and ( and ) are literals. */
-#define REG_NO_BK_PARENS (1ul << 13)
+# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
/* If this bit is set, then \<digit> matches <digit>.
If not set, then \<digit> is a back-reference. */
-#define REG_NO_BK_REFS (1ul << 14)
+# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
/* If this bit is set, then | is an alternation operator, and \| is literal.
If not set, then \| is an alternation operator, and | is literal. */
-#define REG_NO_BK_VBAR (1ul << 15)
+# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
/* If this bit is set, then an ending range point collating higher
than the starting range point, as in [z-a], is invalid.
- If not set, the containing range is empty and does not match any string. */
-#define REG_NO_EMPTY_RANGES (1ul << 16)
+ If not set, then when ending range point collates higher than the
+ starting range point, the range is ignored. */
+# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
/* If this bit is set, then an unmatched ) is ordinary.
If not set, then an unmatched ) is invalid. */
-#define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17)
+# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
/* If this bit is set, succeed as soon as we match the whole pattern,
without further backtracking. */
-#define REG_NO_POSIX_BACKTRACKING (1ul << 18)
+# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
/* If this bit is set, do not process the GNU regex operators.
If not set, then the GNU regex operators are recognized. */
-#define REG_NO_GNU_OPS (1ul << 19)
+# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
/* If this bit is set, turn on internal regex debugging.
If not set, and debugging was on, turn it off.
@@ -203,29 +208,31 @@ typedef unsigned long int reg_syntax_t;
We define this bit always, so that all that's needed to turn on
debugging is to recompile regex.c; the calling code can always have
this bit set, and it won't affect anything in the normal case. */
-#define REG_DEBUG (1ul << 20)
+# define RE_DEBUG (RE_NO_GNU_OPS << 1)
/* If this bit is set, a syntactically invalid interval is treated as
a string of ordinary characters. For example, the ERE 'a{1' is
treated as 'a\{1'. */
-#define REG_INVALID_INTERVAL_ORD (1ul << 21)
+# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
/* If this bit is set, then ignore case when matching.
If not set, then case is significant. */
-#define REG_IGNORE_CASE (1ul << 22)
+# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
-/* This bit is used internally like REG_CONTEXT_INDEP_ANCHORS but only
+/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
for ^, because it is difficult to scan the regex backwards to find
whether ^ should be special. */
-#define REG_CARET_ANCHORS_HERE (1ul << 23)
+# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
/* If this bit is set, then \{ cannot be first in an bre or
immediately after an alternation or begin-group operator. */
-#define REG_CONTEXT_INVALID_DUP (1ul << 24)
+# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
/* If this bit is set, then no_sub will be set to 1 during
re_compile_pattern. */
-#define REG_NO_SUB (1ul << 25)
+# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
+
+#endif /* defined __USE_GNU_REGEX */
/* This global variable defines the particular regexp syntax to use (for
some interfaces). When a regexp is compiled, the syntax used is
@@ -233,82 +240,99 @@ typedef unsigned long int reg_syntax_t;
already-compiled regexps. */
extern reg_syntax_t re_syntax_options;
+#ifdef __USE_GNU_REGEX
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so
don't delete them!) */
/* [[[begin syntaxes]]] */
-#define REG_SYNTAX_EMACS 0
-
-#define REG_SYNTAX_AWK \
- (REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \
- | REG_NO_BK_PARENS | REG_NO_BK_REFS \
- | REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \
- | REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \
- | REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS)
-
-#define REG_SYNTAX_GNU_AWK \
- ((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \
- | REG_DEBUG) \
- & ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \
- | REG_CONTEXT_INVALID_OPS ))
-
-#define REG_SYNTAX_POSIX_AWK \
- (REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \
- | REG_INTERVALS | REG_NO_GNU_OPS)
-
-#define REG_SYNTAX_GREP \
- (REG_BK_PLUS_QM | REG_CHAR_CLASSES \
- | REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \
- | REG_NEWLINE_ALT)
-
-#define REG_SYNTAX_EGREP \
- (REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \
- | REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \
- | REG_NEWLINE_ALT | REG_NO_BK_PARENS \
- | REG_NO_BK_VBAR)
-
-#define REG_SYNTAX_POSIX_EGREP \
- (REG_SYNTAX_EGREP | REG_INTERVALS | REG_NO_BK_BRACES \
- | REG_INVALID_INTERVAL_ORD)
+# define RE_SYNTAX_EMACS 0
+
+# define RE_SYNTAX_AWK \
+ (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
+ | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
+
+# define RE_SYNTAX_GNU_AWK \
+ ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
+ & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
+ | RE_CONTEXT_INVALID_OPS ))
+
+# define RE_SYNTAX_POSIX_AWK \
+ (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
+ | RE_INTERVALS | RE_NO_GNU_OPS)
+
+# define RE_SYNTAX_GREP \
+ (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
+ | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
+ | RE_NEWLINE_ALT)
+
+# define RE_SYNTAX_EGREP \
+ (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
+ | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
+ | RE_NO_BK_VBAR)
+
+# define RE_SYNTAX_POSIX_EGREP \
+ (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
+ | RE_INVALID_INTERVAL_ORD)
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
-#define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC
+# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
-#define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC
+# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
/* Syntax bits common to both basic and extended POSIX regex syntax. */
-#define _REG_SYNTAX_POSIX_COMMON \
- (REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \
- | REG_INTERVALS | REG_NO_EMPTY_RANGES)
+# define _RE_SYNTAX_POSIX_COMMON \
+ (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
+ | RE_INTERVALS | RE_NO_EMPTY_RANGES)
-#define REG_SYNTAX_POSIX_BASIC \
- (_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP)
+# define RE_SYNTAX_POSIX_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
-/* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes
- REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
+ RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
isn't minimal, since other operators, such as \`, aren't disabled. */
-#define REG_SYNTAX_POSIX_MINIMAL_BASIC \
- (_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS)
-
-#define REG_SYNTAX_POSIX_EXTENDED \
- (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \
- | REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \
- | REG_NO_BK_PARENS | REG_NO_BK_VBAR \
- | REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD)
-
-/* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is
- removed and REG_NO_BK_REFS is added. */
-#define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \
- (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \
- | REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \
- | REG_NO_BK_PARENS | REG_NO_BK_REFS \
- | REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD)
+# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
+
+# define RE_SYNTAX_POSIX_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
+ | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
+ removed and RE_NO_BK_REFS is added. */
+# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* [[[end syntaxes]]] */
+
+#endif /* defined __USE_GNU_REGEX */
-/* Maximum number of duplicates an interval can allow. This is
- distinct from RE_DUP_MAX, to conform to POSIX name space rules and
- to avoid collisions with <limits.h>. */
-#define REG_DUP_MAX 32767
+#ifdef __USE_GNU_REGEX
+
+/* Maximum number of duplicates an interval can allow. POSIX-conforming
+ systems might define this in <limits.h>, but we want our
+ value, so remove any previous define. */
+# ifdef RE_DUP_MAX
+# undef RE_DUP_MAX
+# endif
+
+/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
+ the counter as a 2-byte signed integer. This is no longer true, so
+ RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
+ ((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined.
+ However, there would be a huge performance problem if someone
+ actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
+ its historical value. */
+# define RE_DUP_MAX (0x7fff)
+
+#endif /* defined __USE_GNU_REGEX */
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
@@ -354,72 +378,55 @@ extern reg_syntax_t re_syntax_options;
typedef enum
{
_REG_ENOSYS = -1, /* This will never happen for this implementation. */
-#define REG_ENOSYS _REG_ENOSYS
-
- _REG_NOERROR, /* Success. */
-#define REG_NOERROR _REG_NOERROR
-
+ _REG_NOERROR = 0, /* Success. */
_REG_NOMATCH, /* Didn't find a match (for regexec). */
-#define REG_NOMATCH _REG_NOMATCH
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
-
_REG_BADPAT, /* Invalid pattern. */
-#define REG_BADPAT _REG_BADPAT
-
- _REG_ECOLLATE, /* Inalid collating element. */
-#define REG_ECOLLATE _REG_ECOLLATE
-
+ _REG_ECOLLATE, /* Invalid collating element. */
_REG_ECTYPE, /* Invalid character class name. */
-#define REG_ECTYPE _REG_ECTYPE
-
_REG_EESCAPE, /* Trailing backslash. */
-#define REG_EESCAPE _REG_EESCAPE
-
_REG_ESUBREG, /* Invalid back reference. */
-#define REG_ESUBREG _REG_ESUBREG
-
_REG_EBRACK, /* Unmatched left bracket. */
-#define REG_EBRACK _REG_EBRACK
-
_REG_EPAREN, /* Parenthesis imbalance. */
-#define REG_EPAREN _REG_EPAREN
-
_REG_EBRACE, /* Unmatched \{. */
-#define REG_EBRACE _REG_EBRACE
-
_REG_BADBR, /* Invalid contents of \{\}. */
-#define REG_BADBR _REG_BADBR
-
_REG_ERANGE, /* Invalid range end. */
-#define REG_ERANGE _REG_ERANGE
-
_REG_ESPACE, /* Ran out of memory. */
-#define REG_ESPACE _REG_ESPACE
-
_REG_BADRPT, /* No preceding re for repetition op. */
-#define REG_BADRPT _REG_BADRPT
/* Error codes we've added. */
-
_REG_EEND, /* Premature end. */
-#define REG_EEND _REG_EEND
-
_REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
-#define REG_ESIZE _REG_ESIZE
-
_REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
-#define REG_ERPAREN _REG_ERPAREN
-
} reg_errcode_t;
+
+#ifdef _XOPEN_SOURCE
+# define REG_ENOSYS _REG_ENOSYS
+#endif
+#define REG_NOERROR _REG_NOERROR
+#define REG_NOMATCH _REG_NOMATCH
+#define REG_BADPAT _REG_BADPAT
+#define REG_ECOLLATE _REG_ECOLLATE
+#define REG_ECTYPE _REG_ECTYPE
+#define REG_EESCAPE _REG_EESCAPE
+#define REG_ESUBREG _REG_ESUBREG
+#define REG_EBRACK _REG_EBRACK
+#define REG_EPAREN _REG_EPAREN
+#define REG_EBRACE _REG_EBRACE
+#define REG_BADBR _REG_BADBR
+#define REG_ERANGE _REG_ERANGE
+#define REG_ESPACE _REG_ESPACE
+#define REG_BADRPT _REG_BADRPT
+#define REG_EEND _REG_EEND
+#define REG_ESIZE _REG_ESIZE
+#define REG_ERPAREN _REG_ERPAREN
-/* In the traditional GNU implementation, regex.h defined member names
- like `buffer' that POSIX does not allow. These members now have
- names with leading `re_' (e.g., `re_buffer'). Support the old
- names only if _REGEX_SOURCE is defined. New programs should use
- the new names. */
-#ifdef _REGEX_SOURCE
+/* struct re_pattern_buffer normally uses member names like `buffer'
+ that POSIX does not allow. In POSIX mode these members have names
+ with leading `re_' (e.g., `re_buffer'). */
+#ifdef __USE_GNU_REGEX
# define _REG_RE_NAME(id) id
# define _REG_RM_NAME(id) id
#else
@@ -428,88 +435,87 @@ typedef enum
#endif
/* The user can specify the type of the re_translate member by
- defining the macro REG_TRANSLATE_TYPE. In the traditional GNU
- implementation, this macro was named RE_TRANSLATE_TYPE, but POSIX
- does not allow this. Support the old name only if _REGEX_SOURCE
- and if the new name is not defined. New programs should use the new
- name. */
-#ifndef REG_TRANSLATE_TYPE
-# if defined _REGEX_SOURCE && defined RE_TRANSLATE_TYPE
-# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
-# else
-# define REG_TRANSLATE_TYPE char *
+ defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned
+ char *. This pollutes the POSIX name space, so in POSIX mode just
+ use unsigned char *. */
+#ifdef __USE_GNU_REGEX
+# ifndef RE_TRANSLATE_TYPE
+# define RE_TRANSLATE_TYPE unsigned char *
# endif
+# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
+#else
+# define REG_TRANSLATE_TYPE unsigned char *
#endif
/* This data structure represents a compiled pattern. Before calling
- the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap',
- `re_translate', and `re_no_sub' can be set. After the pattern has been
+ the pattern compiler, the fields `buffer', `allocated', `fastmap',
+ `translate', and `no_sub' can be set. After the pattern has been
compiled, the `re_nsub' field is available. All other fields are
private to the regex routines. */
struct re_pattern_buffer
{
-/* [[[begin pattern_buffer]]] */
- /* Space that holds the compiled pattern. It is declared as
- `unsigned char *' because its elements are
- sometimes used as array indexes. */
+ /* Space that holds the compiled pattern. It is declared as
+ `unsigned char *' because its elements are sometimes used as
+ array indexes. */
unsigned char *_REG_RE_NAME (buffer);
- /* Number of bytes to which `re_buffer' points. */
+ /* Number of bytes to which `buffer' points. */
__re_long_size_t _REG_RE_NAME (allocated);
- /* Number of bytes actually used in `re_buffer'. */
+ /* Number of bytes actually used in `buffer'. */
__re_long_size_t _REG_RE_NAME (used);
- /* Syntax setting with which the pattern was compiled. */
+ /* Syntax setting with which the pattern was compiled. */
reg_syntax_t _REG_RE_NAME (syntax);
- /* Pointer to a fastmap, if any, otherwise zero. re_search uses
- the fastmap, if there is one, to skip over impossible
- starting points for matches. */
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
+ fastmap, if there is one, to skip over impossible starting points
+ for matches. */
char *_REG_RE_NAME (fastmap);
- /* Either a translate table to apply to all characters before
- comparing them, or zero for no translation. The translation
- is applied to a pattern when it is compiled and to a string
- when it is matched. */
+ /* Either a translate table to apply to all characters before
+ comparing them, or zero for no translation. The translation is
+ applied to a pattern when it is compiled and to a string when it
+ is matched. */
REG_TRANSLATE_TYPE _REG_RE_NAME (translate);
- /* Number of subexpressions found by the compiler. */
+ /* Number of subexpressions found by the compiler. */
size_t re_nsub;
- /* Zero if this pattern cannot match the empty string, one else.
- Well, in truth it's used only in `re_search_2', to see
- whether or not we should use the fastmap, so we don't set
- this absolutely perfectly; see `re_compile_fastmap' (the
- `duplicate' case). */
+ /* Zero if this pattern cannot match the empty string, one else.
+ Well, in truth it's used only in `re_search_2', to see whether or
+ not we should use the fastmap, so we don't set this absolutely
+ perfectly; see `re_compile_fastmap' (the `duplicate' case). */
unsigned int _REG_RE_NAME (can_be_null) : 1;
- /* If REG_UNALLOCATED, allocate space in the `regs' structure
- for `max (REG_NREGS, re_nsub + 1)' groups.
- If REG_REALLOCATE, reallocate space if necessary.
- If REG_FIXED, use what's there. */
-#define REG_UNALLOCATED 0
-#define REG_REALLOCATE 1
-#define REG_FIXED 2
+ /* If REGS_UNALLOCATED, allocate space in the `regs' structure
+ for `max (RE_NREGS, re_nsub + 1)' groups.
+ If REGS_REALLOCATE, reallocate space if necessary.
+ If REGS_FIXED, use what's there. */
+#ifdef __USE_GNU_REGEX
+# define REGS_UNALLOCATED 0
+# define REGS_REALLOCATE 1
+# define REGS_FIXED 2
+#endif
unsigned int _REG_RE_NAME (regs_allocated) : 2;
- /* Set to zero when `regex_compile' compiles a pattern; set to one
- by `re_compile_fastmap' if it updates the fastmap. */
+ /* Set to zero when `regex_compile' compiles a pattern; set to one
+ by `re_compile_fastmap' if it updates the fastmap. */
unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
- /* If set, `re_match_2' does not return information about
- subexpressions. */
+ /* If set, `re_match_2' does not return information about
+ subexpressions. */
unsigned int _REG_RE_NAME (no_sub) : 1;
- /* If set, a beginning-of-line anchor doesn't match at the
- beginning of the string. */
+ /* If set, a beginning-of-line anchor doesn't match at the beginning
+ of the string. */
unsigned int _REG_RE_NAME (not_bol) : 1;
- /* Similarly for an end-of-line anchor. */
+ /* Similarly for an end-of-line anchor. */
unsigned int _REG_RE_NAME (not_eol) : 1;
- /* If true, an anchor at a newline matches. */
+ /* If true, an anchor at a newline matches. */
unsigned int _REG_RE_NAME (newline_anchor) : 1;
/* [[[end pattern_buffer]]] */
@@ -527,11 +533,11 @@ struct re_registers
};
-/* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer,
+/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
`re_match_2' returns information about at least this many registers
the first time a `regs' structure is passed. */
-#ifndef REG_NREGS
-# define REG_NREGS 30
+#if !defined RE_NREGS && defined __USE_GNU_REGEX
+# define RE_NREGS 30
#endif
@@ -567,7 +573,7 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
compiled into BUFFER. Start searching at position START, for RANGE
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
- information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */
+ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern regoff_t re_search (struct re_pattern_buffer *__buffer,
const char *__string, __re_idx_t __length,
__re_idx_t __start, regoff_t __range,
@@ -660,110 +666,8 @@ extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
extern void regfree (regex_t *__preg);
-#ifdef _REGEX_SOURCE
-
-/* Define the POSIX-compatible member names in terms of the
- incompatible (and deprecated) names established by _REG_RE_NAME.
- New programs should use the re_* names. */
-
-# define re_allocated allocated
-# define re_buffer buffer
-# define re_can_be_null can_be_null
-# define re_fastmap fastmap
-# define re_fastmap_accurate fastmap_accurate
-# define re_newline_anchor newline_anchor
-# define re_no_sub no_sub
-# define re_not_bol not_bol
-# define re_not_eol not_eol
-# define re_regs_allocated regs_allocated
-# define re_syntax syntax
-# define re_translate translate
-# define re_used used
-
-/* Similarly for _REG_RM_NAME. */
-
-# define rm_end end
-# define rm_num_regs num_regs
-# define rm_start start
-
-/* Undef RE_DUP_MAX first, in case the user has already included a
- <limits.h> with an incompatible definition.
-
- On GNU systems, the most common spelling for RE_DUP_MAX's value in
- <limits.h> is (0x7ffff), so define RE_DUP_MAX to that, not to
- REG_DUP_MAX. This avoid some duplicate-macro-definition warnings
- with programs that include <limits.h> after this file.
-
- New programs should not assume that regex.h defines RE_DUP_MAX; to
- get the value of RE_DUP_MAX, they should instead include <limits.h>
- and possibly invoke the sysconf function. */
-
-# undef RE_DUP_MAX
-# define RE_DUP_MAX (0x7fff)
-
-/* Define the following symbols for backward source compatibility.
- These symbols violate the POSIX name space rules, and new programs
- should avoid them. */
-
-# define REGS_FIXED REG_FIXED
-# define REGS_REALLOCATE REG_REALLOCATE
-# define REGS_UNALLOCATED REG_UNALLOCATED
-# define RE_BACKSLASH_ESCAPE_IN_LISTS REG_BACKSLASH_ESCAPE_IN_LISTS
-# define RE_BK_PLUS_QM REG_BK_PLUS_QM
-# define RE_CARET_ANCHORS_HERE REG_CARET_ANCHORS_HERE
-# define RE_CHAR_CLASSES REG_CHAR_CLASSES
-# define RE_CONTEXT_INDEP_ANCHORS REG_CONTEXT_INDEP_ANCHORS
-# define RE_CONTEXT_INDEP_OPS REG_CONTEXT_INDEP_OPS
-# define RE_CONTEXT_INVALID_DUP REG_CONTEXT_INVALID_DUP
-# define RE_CONTEXT_INVALID_OPS REG_CONTEXT_INVALID_OPS
-# define RE_DEBUG REG_DEBUG
-# define RE_DOT_NEWLINE REG_DOT_NEWLINE
-# define RE_DOT_NOT_NULL REG_DOT_NOT_NULL
-# define RE_HAT_LISTS_NOT_NEWLINE REG_HAT_LISTS_NOT_NEWLINE
-# define RE_ICASE REG_IGNORE_CASE /* avoid collision with REG_ICASE */
-# define RE_INTERVALS REG_INTERVALS
-# define RE_INVALID_INTERVAL_ORD REG_INVALID_INTERVAL_ORD
-# define RE_LIMITED_OPS REG_LIMITED_OPS
-# define RE_NEWLINE_ALT REG_NEWLINE_ALT
-# define RE_NO_BK_BRACES REG_NO_BK_BRACES
-# define RE_NO_BK_PARENS REG_NO_BK_PARENS
-# define RE_NO_BK_REFS REG_NO_BK_REFS
-# define RE_NO_BK_VBAR REG_NO_BK_VBAR
-# define RE_NO_EMPTY_RANGES REG_NO_EMPTY_RANGES
-# define RE_NO_GNU_OPS REG_NO_GNU_OPS
-# define RE_NO_POSIX_BACKTRACKING REG_NO_POSIX_BACKTRACKING
-# define RE_NO_SUB REG_NO_SUB
-# define RE_NREGS REG_NREGS
-# define RE_SYNTAX_AWK REG_SYNTAX_AWK
-# define RE_SYNTAX_ED REG_SYNTAX_ED
-# define RE_SYNTAX_EGREP REG_SYNTAX_EGREP
-# define RE_SYNTAX_EMACS REG_SYNTAX_EMACS
-# define RE_SYNTAX_GNU_AWK REG_SYNTAX_GNU_AWK
-# define RE_SYNTAX_GREP REG_SYNTAX_GREP
-# define RE_SYNTAX_POSIX_AWK REG_SYNTAX_POSIX_AWK
-# define RE_SYNTAX_POSIX_BASIC REG_SYNTAX_POSIX_BASIC
-# define RE_SYNTAX_POSIX_EGREP REG_SYNTAX_POSIX_EGREP
-# define RE_SYNTAX_POSIX_EXTENDED REG_SYNTAX_POSIX_EXTENDED
-# define RE_SYNTAX_POSIX_MINIMAL_BASIC REG_SYNTAX_POSIX_MINIMAL_BASIC
-# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED REG_SYNTAX_POSIX_MINIMAL_EXTENDED
-# define RE_SYNTAX_SED REG_SYNTAX_SED
-# define RE_UNMATCHED_RIGHT_PAREN_ORD REG_UNMATCHED_RIGHT_PAREN_ORD
-# ifndef RE_TRANSLATE_TYPE
-# define RE_TRANSLATE_TYPE REG_TRANSLATE_TYPE
-# endif
-
-#endif /* defined _REGEX_SOURCE */
-
#ifdef __cplusplus
}
#endif /* C++ */
#endif /* regex.h */
-
-/*
-Local variables:
-make-backup-files: t
-version-control: t
-trim-versions-without-asking: nil
-End:
-*/
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index ad618cf..55fe298 100644
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -1,5 +1,5 @@
/* Extended regular expression matching and search library.
- Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
@@ -19,7 +19,7 @@
static void re_string_construct_common (const char *str, Idx len,
re_string_t *pstr,
- REG_TRANSLATE_TYPE trans, bool icase,
+ RE_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa) internal_function;
static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
const re_node_set *nodes,
@@ -37,7 +37,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
static reg_errcode_t
internal_function
re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
- REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
Idx init_buf_len;
@@ -65,7 +65,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
static reg_errcode_t
internal_function
re_string_construct (re_string_t *pstr, const char *str, Idx len,
- REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
memset (pstr, '\0', sizeof (re_string_t));
@@ -132,13 +132,20 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
#ifdef RE_ENABLE_I18N
if (pstr->mb_cur_max > 1)
{
- wint_t *new_wcs = re_xrealloc (pstr->wcs, wint_t, new_buf_len);
+ wint_t *new_wcs;
+
+ /* Avoid overflow. */
+ size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
+ if (BE (SIZE_MAX / max_object_size < new_buf_len, 0))
+ return REG_ESPACE;
+
+ new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
if (BE (new_wcs == NULL, 0))
return REG_ESPACE;
pstr->wcs = new_wcs;
if (pstr->offsets != NULL)
{
- Idx *new_offsets = re_xrealloc (pstr->offsets, Idx, new_buf_len);
+ Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
if (BE (new_offsets == NULL, 0))
return REG_ESPACE;
pstr->offsets = new_offsets;
@@ -161,13 +168,13 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
static void
internal_function
re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
- REG_TRANSLATE_TYPE trans, bool icase,
+ RE_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa)
{
pstr->raw_mbs = (const unsigned char *) str;
pstr->len = len;
pstr->raw_len = len;
- pstr->trans = (unsigned REG_TRANSLATE_TYPE) trans;
+ pstr->trans = trans;
pstr->icase = icase;
pstr->mbs_allocated = (trans != NULL || icase);
pstr->mb_cur_max = dfa->mb_cur_max;
@@ -301,7 +308,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
mbclen = mbrtowc (&wc,
((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
+ byte_idx), remain_len, &pstr->cur_state);
- if (BE ((size_t) (mbclen + 2) > 2, 1))
+ if (BE (mbclen < (size_t) -2, 1))
{
wchar_t wcu = wc;
if (iswlower (wc))
@@ -369,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
else
p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state);
- if (BE ((size_t) (mbclen + 2) > 2, 1))
+ if (BE (mbclen < (size_t) -2, 1))
{
wchar_t wcu = wc;
if (iswlower (wc))
@@ -392,7 +399,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
if (pstr->offsets == NULL)
{
- pstr->offsets = re_xmalloc (Idx, pstr->bufs_len);
+ pstr->offsets = re_malloc (Idx, pstr->bufs_len);
if (pstr->offsets == NULL)
return REG_ESPACE;
@@ -635,37 +642,50 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
byte other than 0x80 - 0xbf. */
raw = pstr->raw_mbs + pstr->raw_mbs_idx;
end = raw + (offset - pstr->mb_cur_max);
- for (p = raw + offset - 1; p >= end; --p)
- if ((*p & 0xc0) != 0x80)
- {
- mbstate_t cur_state;
- wchar_t wc2;
- Idx mlen = raw + pstr->len - p;
- unsigned char buf[6];
- size_t mbclen;
-
- q = p;
- if (BE (pstr->trans != NULL, 0))
- {
- int i = mlen < 6 ? mlen : 6;
- while (--i >= 0)
- buf[i] = pstr->trans[p[i]];
- q = buf;
- }
- /* XXX Don't use mbrtowc, we know which conversion
- to use (UTF-8 -> UCS4). */
- memset (&cur_state, 0, sizeof (cur_state));
- mbclen = mbrtowc (&wc2, (const char *) p, mlen,
- &cur_state);
- if (raw + offset - p <= mbclen && mbclen < (size_t) -2)
- {
- memset (&pstr->cur_state, '\0',
- sizeof (mbstate_t));
- pstr->valid_len = mbclen - (raw + offset - p);
- wc = wc2;
- }
- break;
- }
+ p = raw + offset - 1;
+#ifdef _LIBC
+ /* We know the wchar_t encoding is UCS4, so for the simple
+ case, ASCII characters, skip the conversion step. */
+ if (isascii (*p) && BE (pstr->trans == NULL, 1))
+ {
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+ pstr->valid_len = 0;
+ wc = (wchar_t) *p;
+ }
+ else
+#endif
+ for (; p >= end; --p)
+ if ((*p & 0xc0) != 0x80)
+ {
+ mbstate_t cur_state;
+ wchar_t wc2;
+ Idx mlen = raw + pstr->len - p;
+ unsigned char buf[6];
+ size_t mbclen;
+
+ q = p;
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i = mlen < 6 ? mlen : 6;
+ while (--i >= 0)
+ buf[i] = pstr->trans[p[i]];
+ q = buf;
+ }
+ /* XXX Don't use mbrtowc, we know which conversion
+ to use (UTF-8 -> UCS4). */
+ memset (&cur_state, 0, sizeof (cur_state));
+ mbclen = mbrtowc (&wc2, (const char *) p, mlen,
+ &cur_state);
+ if (raw + offset - p <= mbclen
+ && mbclen < (size_t) -2)
+ {
+ memset (&pstr->cur_state, '\0',
+ sizeof (mbstate_t));
+ pstr->valid_len = mbclen - (raw + offset - p);
+ wc = wc2;
+ }
+ break;
+ }
}
if (wc == WEOF)
@@ -719,15 +739,15 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
}
else
#endif /* RE_ENABLE_I18N */
- if (BE (pstr->mbs_allocated, 0))
- {
- if (pstr->icase)
- build_upper_buffer (pstr);
- else if (pstr->trans != NULL)
- re_string_translate_buffer (pstr);
- }
- else
- pstr->valid_len = pstr->len;
+ if (BE (pstr->mbs_allocated, 0))
+ {
+ if (pstr->icase)
+ build_upper_buffer (pstr);
+ else if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ else
+ pstr->valid_len = pstr->len;
pstr->cur_idx = 0;
return REG_NOERROR;
@@ -873,7 +893,7 @@ re_node_set_alloc (re_node_set *set, Idx size)
{
set->alloc = size;
set->nelem = 0;
- set->elems = re_xmalloc (Idx, size);
+ set->elems = re_malloc (Idx, size);
if (BE (set->elems == NULL, 0))
return REG_ESPACE;
return REG_NOERROR;
@@ -939,7 +959,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
dest->alloc = dest->nelem = 0;
return REG_ESPACE;
}
- memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]);
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
}
else
re_node_set_init_empty (dest);
@@ -964,12 +984,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
{
Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
- Idx *new_elems;
- if (sizeof (Idx) < 3
- && (new_alloc < dest->alloc
- || ((Idx) (src1->nelem + src2->nelem) < src1->nelem)))
- return REG_ESPACE;
- new_elems = re_xrealloc (dest->elems, Idx, new_alloc);
+ Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
if (BE (new_elems == NULL, 0))
return REG_ESPACE;
dest->elems = new_elems;
@@ -1038,7 +1053,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
}
/* Copy remaining SRC elements. */
- memcpy (dest->elems, dest->elems + sbase, delta * sizeof dest->elems[0]);
+ memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
return REG_NOERROR;
}
@@ -1055,9 +1070,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
{
dest->alloc = src1->nelem + src2->nelem;
- if (sizeof (Idx) < 2 && dest->alloc < src1->nelem)
- return REG_ESPACE;
- dest->elems = re_xmalloc (Idx, dest->alloc);
+ dest->elems = re_malloc (Idx, dest->alloc);
if (BE (dest->elems == NULL, 0))
return REG_ESPACE;
}
@@ -1085,13 +1098,13 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
if (i1 < src1->nelem)
{
memcpy (dest->elems + id, src1->elems + i1,
- (src1->nelem - i1) * sizeof dest->elems[0]);
+ (src1->nelem - i1) * sizeof (Idx));
id += src1->nelem - i1;
}
else if (i2 < src2->nelem)
{
memcpy (dest->elems + id, src2->elems + i2,
- (src2->nelem - i2) * sizeof dest->elems[0]);
+ (src2->nelem - i2) * sizeof (Idx));
id += src2->nelem - i2;
}
dest->nelem = id;
@@ -1108,17 +1121,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
Idx is, id, sbase, delta;
if (src == NULL || src->nelem == 0)
return REG_NOERROR;
- if (sizeof (Idx) < 3
- && ((Idx) (2 * src->nelem) < src->nelem
- || (Idx) (2 * src->nelem + dest->nelem) < dest->nelem))
- return REG_ESPACE;
if (dest->alloc < 2 * src->nelem + dest->nelem)
{
- Idx new_alloc = src->nelem + dest->alloc;
- Idx *new_buffer;
- if (sizeof (Idx) < 4 && new_alloc < dest->alloc)
- return REG_ESPACE;
- new_buffer = re_x2realloc (dest->elems, Idx, &new_alloc);
+ Idx new_alloc = 2 * (src->nelem + dest->alloc);
+ Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
if (BE (new_buffer == NULL, 0))
return REG_ESPACE;
dest->elems = new_buffer;
@@ -1128,7 +1134,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
if (BE (dest->nelem == 0, 0))
{
dest->nelem = src->nelem;
- memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]);
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
return REG_NOERROR;
}
@@ -1150,8 +1156,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
{
/* If DEST is exhausted, the remaining items of SRC must be unique. */
sbase -= is + 1;
- memcpy (dest->elems + sbase, src->elems,
- (is + 1) * sizeof dest->elems[0]);
+ memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
}
id = dest->nelem - 1;
@@ -1180,7 +1185,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
{
/* Copy remaining SRC elements. */
memcpy (dest->elems, dest->elems + sbase,
- delta * sizeof dest->elems[0]);
+ delta * sizeof (Idx));
break;
}
}
@@ -1200,7 +1205,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
Idx idx;
/* In case the set is empty. */
if (set->alloc == 0)
- return re_node_set_init_1 (set, elem) == REG_NOERROR;
+ return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
if (BE (set->nelem, 0) == 0)
{
@@ -1213,7 +1218,9 @@ re_node_set_insert (re_node_set *set, Idx elem)
/* Realloc if we need. */
if (set->alloc == set->nelem)
{
- Idx *new_elems = re_x2realloc (set->elems, Idx, &set->alloc);
+ Idx *new_elems;
+ set->alloc = set->alloc * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
return false;
set->elems = new_elems;
@@ -1251,7 +1258,8 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
if (set->alloc == set->nelem)
{
Idx *new_elems;
- new_elems = re_x2realloc (set->elems, Idx, &set->alloc);
+ set->alloc = (set->alloc + 1) * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
return false;
set->elems = new_elems;
@@ -1324,18 +1332,26 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
int type = token.type;
if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
{
- Idx new_nodes_alloc = dfa->nodes_alloc;
+ size_t new_nodes_alloc = dfa->nodes_alloc * 2;
Idx *new_nexts, *new_indices;
re_node_set *new_edests, *new_eclosures;
+ re_token_t *new_nodes;
+ size_t max_object_size =
+ MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ sizeof (Idx)));
+
+ /* Avoid overflows. */
+ if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0))
+ return REG_MISSING;
- re_token_t *new_nodes = re_x2realloc (dfa->nodes, re_token_t,
- &new_nodes_alloc);
+ new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
if (BE (new_nodes == NULL, 0))
return REG_MISSING;
dfa->nodes = new_nodes;
new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
- new_edests = re_xrealloc (dfa->edests, re_node_set, new_nodes_alloc);
+ new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
if (BE (new_nexts == NULL || new_indices == NULL
|| new_edests == NULL || new_eclosures == NULL, 0))
@@ -1378,9 +1394,10 @@ calc_state_hash (const re_node_set *nodes, unsigned int context)
- We never return non-NULL value in case of any errors, it is for
optimization. */
-static re_dfastate_t*
+static re_dfastate_t *
internal_function
-re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
+re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
+ const re_node_set *nodes)
{
re_hashval_t hash;
re_dfastate_t *new_state;
@@ -1409,13 +1426,10 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
/* There are no appropriate state in the dfa, create the new one. */
new_state = create_ci_newstate (dfa, nodes, hash);
- if (BE (new_state != NULL, 1))
- return new_state;
- else
- {
- *err = REG_ESPACE;
- return NULL;
- }
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
}
/* Search for the state whose node_set is equivalent to NODES and
@@ -1428,9 +1442,9 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
- We never return non-NULL value in case of any errors, it is for
optimization. */
-static re_dfastate_t*
+static re_dfastate_t *
internal_function
-re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
+re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
const re_node_set *nodes, unsigned int context)
{
re_hashval_t hash;
@@ -1459,13 +1473,10 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
}
/* There are no appropriate state in `dfa', create the new one. */
new_state = create_cd_newstate (dfa, nodes, context, hash);
- if (BE (new_state != NULL, 1))
- return new_state;
- else
- {
- *err = REG_ESPACE;
- return NULL;
- }
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
}
/* Finish initialization of the new state NEWSTATE, and using its hash value
@@ -1473,8 +1484,8 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
indicates the error code if failed. */
static reg_errcode_t
-internal_function
-register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
+register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
+ re_hashval_t hash)
{
struct re_state_table_entry *spot;
reg_errcode_t err;
@@ -1488,19 +1499,16 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
{
Idx elem = newstate->nodes.elems[i];
if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
- {
- bool ok = re_node_set_insert_last (&newstate->non_eps_nodes, elem);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
+ if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0))
+ return REG_ESPACE;
}
spot = dfa->state_table + (hash & dfa->state_hash_mask);
if (BE (spot->alloc <= spot->num, 0))
{
- Idx new_alloc = spot->num;
- re_dfastate_t **new_array = re_x2realloc (spot->array, re_dfastate_t *,
- &new_alloc);
+ Idx new_alloc = 2 * spot->num + 2;
+ re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
+ new_alloc);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
spot->array = new_array;
@@ -1510,6 +1518,22 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
return REG_NOERROR;
}
+static void
+free_state (re_dfastate_t *state)
+{
+ re_node_set_free (&state->non_eps_nodes);
+ re_node_set_free (&state->inveclosure);
+ if (state->entrance_nodes != &state->nodes)
+ {
+ re_node_set_free (state->entrance_nodes);
+ re_free (state->entrance_nodes);
+ }
+ re_node_set_free (&state->nodes);
+ re_free (state->word_trtable);
+ re_free (state->trtable);
+ re_free (state);
+}
+
/* Create the new state which is independ of contexts.
Return the new state if succeeded, otherwise return NULL. */
@@ -1522,7 +1546,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
- newstate = re_calloc (re_dfastate_t, 1);
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
if (BE (newstate == NULL, 0))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
@@ -1572,7 +1596,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
- newstate = re_calloc (re_dfastate_t, 1);
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
if (BE (newstate == NULL, 0))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
@@ -1637,20 +1661,3 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
}
return newstate;
}
-
-static void
-internal_function
-free_state (re_dfastate_t *state)
-{
- re_node_set_free (&state->non_eps_nodes);
- re_node_set_free (&state->inveclosure);
- if (state->entrance_nodes != &state->nodes)
- {
- re_node_set_free (state->entrance_nodes);
- re_free (state->entrance_nodes);
- }
- re_node_set_free (&state->nodes);
- re_free (state->word_trtable);
- re_free (state->trtable);
- re_free (state);
-}
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 04be143..993c992 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -43,6 +43,9 @@
#if defined HAVE_WCTYPE_H || defined _LIBC
# include <wctype.h>
#endif /* HAVE_WCTYPE_H || _LIBC */
+#if defined HAVE_STDINT_H || defined _LIBC
+# include <stdint.h>
+#endif /* HAVE_STDINT_H || _LIBC */
#if defined _LIBC
# include <bits/libc-lock.h>
#else
@@ -53,7 +56,7 @@
#endif
/* In case that the system doesn't have isblank(). */
-#if !defined _LIBC && !defined HAVE_ISBLANK && !defined isblank
+#if !defined _LIBC && !HAVE_DECL_ISBLANK && !defined isblank
# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
#endif
@@ -84,6 +87,11 @@
# define gettext_noop(String) String
#endif
+/* For loser systems without the definition. */
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
#if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC
# define RE_ENABLE_I18N
#endif
@@ -92,10 +100,16 @@
# define BE(expr, val) __builtin_expect (expr, val)
#else
# define BE(expr, val) (expr)
+# ifdef _LIBC
+# define inline
+# endif
#endif
-/* Number of single byte character. */
-#define SBC_MAX 256
+/* Number of ASCII characters. */
+#define ASCII_CHARS 0x80
+
+/* Number of single byte characters. */
+#define SBC_MAX (UCHAR_MAX + 1)
#define COLL_ELEM_LEN_MAX 8
@@ -122,9 +136,6 @@
# define __attribute(arg)
#endif
-extern const char __re_error_msgid[] attribute_hidden;
-extern const size_t __re_error_msgid_idx[] attribute_hidden;
-
typedef __re_idx_t Idx;
/* Special return value for failure to match. */
@@ -152,15 +163,15 @@ typedef __re_size_t re_hashval_t;
/* An integer used to represent a set of bits. It must be unsigned,
and must be at least as wide as unsigned int. */
-typedef unsigned long int bitset_word;
-
-/* Maximum value of a bitset word. It must be useful in preprocessor
- contexts, and must be consistent with bitset_word. */
+typedef unsigned long int bitset_word_t;
+/* All bits set in a bitset_word_t. */
#define BITSET_WORD_MAX ULONG_MAX
-/* Number of bits in a bitset word. Avoid greater-than-32-bit
- integers and unconditional shifts by more than 31 bits, as they're
- not portable. */
+/* Number of bits in a bitset_word_t. For portability to hosts with
+ padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
+ instead, deduce it directly from BITSET_WORD_MAX. Avoid
+ greater-than-32-bit integers and unconditional shifts by more than
+ 31 bits, as they're not portable. */
#if BITSET_WORD_MAX == 0xffffffff
# define BITSET_WORD_BITS 32
#elif BITSET_WORD_MAX >> 31 >> 5 == 1
@@ -182,20 +193,20 @@ typedef unsigned long int bitset_word;
# if BITSET_WORD_BITS <= SBC_MAX
# error "Invalid SBC_MAX"
# endif
- #elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff
+#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 size"
+# error "Add case for new bitset_word_t size"
#endif
-/* Number of bitset words in a bitset. */
+/* Number of bitset_word_t values in a bitset_t. */
#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
-typedef bitset_word bitset[BITSET_WORDS];
-typedef bitset_word *re_bitset_ptr_t;
-typedef const bitset_word *re_const_bitset_ptr_t;
+typedef bitset_word_t bitset_t[BITSET_WORDS];
+typedef bitset_word_t *re_bitset_ptr_t;
+typedef const bitset_word_t *re_const_bitset_ptr_t;
#define PREV_WORD_CONSTRAINT 0x0001
#define PREV_NOTWORD_CONSTRAINT 0x0002
@@ -401,7 +412,7 @@ struct re_string_t
the beginning of the input string. */
unsigned int tip_context;
/* The translation passed as a part of an argument of re_compile_pattern. */
- unsigned REG_TRANSLATE_TYPE trans;
+ RE_TRANSLATE_TYPE trans;
/* Copy of re_dfa_t's word_char. */
re_const_bitset_ptr_t word_char;
/* true if REG_ICASE. */
@@ -438,10 +449,9 @@ static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
#endif /* RE_ENABLE_I18N */
static void build_upper_buffer (re_string_t *pstr) internal_function;
static void re_string_translate_buffer (re_string_t *pstr) internal_function;
-static unsigned int re_string_context_at (const re_string_t *input,
- Idx idx, int eflags)
+static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
+ int eflags)
internal_function __attribute ((pure));
-
#define re_string_peek_byte(pstr, offset) \
((pstr)->mbs[(pstr)->cur_idx + offset])
#define re_string_fetch_byte(pstr) \
@@ -474,71 +484,14 @@ static unsigned int re_string_context_at (const re_string_t *input,
# endif
#endif
+#ifndef MAX
+# define MAX(a,b) ((a) < (b) ? (b) : (a))
+#endif
+
#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
-#define re_xmalloc(t,n) ((t *) re_xnmalloc (n, sizeof (t)))
-#define re_calloc(t,n) ((t *) calloc (n, sizeof (t)))
#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
-#define re_xrealloc(p,t,n) ((t *) re_xnrealloc (p, n, sizeof (t)))
-#define re_x2realloc(p,t,pn) ((t *) re_x2nrealloc (p, pn, sizeof (t)))
#define re_free(p) free (p)
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-/* Return true if an array of N objects, each of size S, cannot exist
- due to size arithmetic overflow. S must be nonzero. */
-static inline bool
-re_alloc_oversized (size_t n, size_t s)
-{
- return BE (SIZE_MAX / s < n, 0);
-}
-
-/* Return true if an array of (2 * N + 1) objects, each of size S,
- cannot exist due to size arithmetic overflow. S must be nonzero. */
-static inline bool
-re_x2alloc_oversized (size_t n, size_t s)
-{
- return BE ((SIZE_MAX / s - 1) / 2 < n, 0);
-}
-
-/* Allocate an array of N objects, each with S bytes of memory,
- dynamically, with error checking. S must be nonzero. */
-static inline void *
-re_xnmalloc (size_t n, size_t s)
-{
- return re_alloc_oversized (n, s) ? NULL : malloc (n * s);
-}
-
-/* Change the size of an allocated block of memory P to an array of N
- objects each of S bytes, with error checking. S must be nonzero. */
-static inline void *
-re_xnrealloc (void *p, size_t n, size_t s)
-{
- return re_alloc_oversized (n, s) ? NULL : realloc (p, n * s);
-}
-
-/* Reallocate a block of memory P to an array of (2 * (*PN) + 1)
- objects each of S bytes, with error checking. S must be nonzero.
- If the allocation is successful, set *PN to the new allocation
- count and return the resulting pointer. Otherwise, return
- NULL. */
-static inline void *
-re_x2nrealloc (void *p, size_t *pn, size_t s)
-{
- if (re_x2alloc_oversized (*pn, s))
- return NULL;
- else
- {
- /* Add 1 in case *PN is zero. */
- size_t n1 = 2 * *pn + 1;
- p = realloc (p, n1 * s);
- if (BE (p != NULL, 1))
- *pn = n1;
- return p;
- }
-}
-
struct bin_tree_t
{
struct bin_tree_t *parent;
@@ -668,9 +621,9 @@ typedef struct
/* The string object corresponding to the input string. */
re_string_t input;
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
- re_dfa_t *const dfa;
+ const re_dfa_t *const dfa;
#else
- re_dfa_t *dfa;
+ const re_dfa_t *dfa;
#endif
/* EFLAGS of the argument of regexec. */
int eflags;
@@ -717,8 +670,8 @@ struct re_fail_stack_t
struct re_dfa_t
{
re_token_t *nodes;
- Idx nodes_alloc;
- Idx nodes_len;
+ size_t nodes_alloc;
+ size_t nodes_len;
Idx *nexts;
Idx *org_indices;
re_node_set *edests;
@@ -740,8 +693,8 @@ struct re_dfa_t
Idx nbackref; /* The number of backreference in this dfa. */
/* Bitmap expressing which backreference is used. */
- bitset_word used_bkref_map;
- bitset_word completed_bkref_map;
+ bitset_word_t used_bkref_map;
+ bitset_word_t completed_bkref_map;
unsigned int has_plural_match : 1;
/* If this dfa has "multibyte node", which is a backreference or
@@ -752,7 +705,7 @@ struct re_dfa_t
unsigned int map_notascii : 1;
unsigned int word_ops_used : 1;
int mb_cur_max;
- bitset word_char;
+ bitset_t word_char;
reg_syntax_t syntax;
Idx *subexp_map;
#ifdef DEBUG
@@ -766,8 +719,6 @@ struct re_dfa_t
(re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
#define re_node_set_empty(p) ((p)->nelem = 0)
#define re_node_set_free(set) re_free ((set)->elems)
-
-static void free_state (re_dfastate_t *state) internal_function;
typedef enum
@@ -791,76 +742,76 @@ typedef struct
} bracket_elem_t;
-/* Inline functions for bitset operation. */
+/* Inline functions for bitset_t operation. */
static inline void
-bitset_set (bitset set, Idx i)
+bitset_set (bitset_t set, Idx i)
{
- set[i / BITSET_WORD_BITS] |= (bitset_word) 1 << i % BITSET_WORD_BITS;
+ set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
}
static inline void
-bitset_clear (bitset set, Idx i)
+bitset_clear (bitset_t set, Idx i)
{
- set[i / BITSET_WORD_BITS] &= ~ ((bitset_word) 1 << i % BITSET_WORD_BITS);
+ set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
}
static inline bool
-bitset_contain (const bitset set, Idx i)
+bitset_contain (const bitset_t set, Idx i)
{
return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
}
static inline void
-bitset_empty (bitset set)
+bitset_empty (bitset_t set)
{
- memset (set, 0, sizeof (bitset));
+ memset (set, '\0', sizeof (bitset_t));
}
static inline void
-bitset_set_all (bitset set)
+bitset_set_all (bitset_t set)
{
- memset (set, -1, sizeof (bitset_word) * (SBC_MAX / BITSET_WORD_BITS));
+ memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
if (SBC_MAX % BITSET_WORD_BITS != 0)
set[BITSET_WORDS - 1] =
- ((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
+ ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
}
static inline void
-bitset_copy (bitset dest, const bitset src)
+bitset_copy (bitset_t dest, const bitset_t src)
{
- memcpy (dest, src, sizeof (bitset));
+ memcpy (dest, src, sizeof (bitset_t));
}
static inline void
-bitset_not (bitset set)
+bitset_not (bitset_t set)
{
- int i;
- for (i = 0; i < SBC_MAX / BITSET_WORD_BITS; ++i)
- set[i] = ~set[i];
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
+ set[bitset_i] = ~set[bitset_i];
if (SBC_MAX % BITSET_WORD_BITS != 0)
set[BITSET_WORDS - 1] =
- ((((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
+ ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
& ~set[BITSET_WORDS - 1]);
}
static inline void
-bitset_merge (bitset dest, const bitset src)
+bitset_merge (bitset_t dest, const bitset_t src)
{
- int i;
- for (i = 0; i < BITSET_WORDS; ++i)
- dest[i] |= src[i];
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] |= src[bitset_i];
}
static inline void
-bitset_mask (bitset dest, const bitset src)
+bitset_mask (bitset_t dest, const bitset_t src)
{
- int i;
- for (i = 0; i < BITSET_WORDS; ++i)
- dest[i] &= src[i];
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] &= src[bitset_i];
}
-#if defined RE_ENABLE_I18N
+#ifdef RE_ENABLE_I18N
/* Inline functions for re_string. */
static inline int
internal_function __attribute ((pure))
@@ -888,11 +839,11 @@ static int
internal_function __attribute ((pure))
re_string_elem_size_at (const re_string_t *pstr, Idx idx)
{
-#ifdef _LIBC
+# ifdef _LIBC
const unsigned char *p, *extra;
const int32_t *table, *indirect;
int32_t tmp;
-# include <locale/weight.h>
+# include <locale/weight.h>
uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
if (nrules != 0)
@@ -907,7 +858,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
return p - pstr->mbs - idx;
}
else
-#endif /* _LIBC */
+# endif /* _LIBC */
return 1;
}
#endif /* RE_ENABLE_I18N */
diff --git a/lib/regexec.c b/lib/regexec.c
index a85077c..84c3aed 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -1,5 +1,5 @@
/* Extended regular expression matching and search library.
- Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
@@ -51,68 +51,79 @@ static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
regoff_t range, Idx stop,
struct re_registers *regs,
bool ret_len) internal_function;
-static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
- Idx nregs, int regs_allocated) internal_function;
+static unsigned int re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
+ Idx nregs, int regs_allocated)
+ internal_function;
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
internal_function;
static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
- Idx *p_match_first)
- internal_function;
+ Idx *p_match_first) internal_function;
static Idx check_halt_state_context (const re_match_context_t *mctx,
const re_dfastate_t *state, Idx idx)
internal_function;
-static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch,
+static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
regmatch_t *prev_idx_match, Idx cur_node,
Idx cur_idx, Idx nmatch) internal_function;
static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
Idx str_idx, Idx dest_node, Idx nregs,
regmatch_t *regs,
- re_node_set *eps_via_nodes) internal_function;
+ re_node_set *eps_via_nodes)
+ internal_function;
static reg_errcode_t set_regs (const regex_t *preg,
const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch,
bool fl_backtrack) internal_function;
-static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function;
+static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
+ internal_function;
#ifdef RE_ENABLE_I18N
static int sift_states_iter_mb (const re_match_context_t *mctx,
re_sift_context_t *sctx,
- Idx node_idx, Idx str_idx, Idx max_str_idx) internal_function;
+ Idx node_idx, Idx str_idx, Idx max_str_idx)
+ internal_function;
#endif /* RE_ENABLE_I18N */
-static reg_errcode_t sift_states_backward (re_match_context_t *mctx,
- re_sift_context_t *sctx) internal_function;
-static reg_errcode_t build_sifted_states (re_match_context_t *mctx,
+static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
+ re_sift_context_t *sctx)
+ internal_function;
+static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
re_sift_context_t *sctx, Idx str_idx,
- re_node_set *cur_dest) internal_function;
-static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx,
+ re_node_set *cur_dest)
+ internal_function;
+static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
re_sift_context_t *sctx,
Idx str_idx,
- re_node_set *dest_nodes) internal_function;
-static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
+ re_node_set *dest_nodes)
+ internal_function;
+static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
re_node_set *dest_nodes,
- const re_node_set *candidates) internal_function;
+ const re_node_set *candidates)
+ internal_function;
static bool check_dst_limits (const re_match_context_t *mctx,
const re_node_set *limits,
Idx dst_node, Idx dst_idx, Idx src_node,
Idx src_idx) internal_function;
static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
int boundaries, Idx subexp_idx,
- Idx from_node, Idx bkref_idx) internal_function;
+ Idx from_node, Idx bkref_idx)
+ internal_function;
static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
Idx limit, Idx subexp_idx,
Idx node, Idx str_idx,
Idx bkref_idx) internal_function;
-static reg_errcode_t check_subexp_limits (re_dfa_t *dfa,
+static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates,
re_node_set *limits,
struct re_backref_cache_entry *bkref_ents,
Idx str_idx) internal_function;
-static reg_errcode_t sift_states_bkref (re_match_context_t *mctx,
+static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
re_sift_context_t *sctx,
- Idx str_idx, const re_node_set *candidates) internal_function;
-static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
- re_dfastate_t **src, Idx num) internal_function;
+ Idx str_idx, const re_node_set *candidates)
+ internal_function;
+static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
+ re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
+ internal_function;
static re_dfastate_t *find_recover_state (reg_errcode_t *err,
re_match_context_t *mctx) internal_function;
static re_dfastate_t *transit_state (reg_errcode_t *err,
@@ -120,27 +131,33 @@ static re_dfastate_t *transit_state (reg_errcode_t *err,
re_dfastate_t *state) internal_function;
static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
re_match_context_t *mctx,
- re_dfastate_t *next_state) internal_function;
+ re_dfastate_t *next_state)
+ internal_function;
static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
re_node_set *cur_nodes,
Idx str_idx) internal_function;
#if 0
static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
re_match_context_t *mctx,
- re_dfastate_t *pstate) internal_function;
+ re_dfastate_t *pstate)
+ internal_function;
#endif
#ifdef RE_ENABLE_I18N
static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
- re_dfastate_t *pstate) internal_function;
+ re_dfastate_t *pstate)
+ internal_function;
#endif /* RE_ENABLE_I18N */
static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
- const re_node_set *nodes) internal_function;
+ const re_node_set *nodes)
+ internal_function;
static reg_errcode_t get_subexp (re_match_context_t *mctx,
- Idx bkref_node, Idx bkref_str_idx) internal_function;
+ Idx bkref_node, Idx bkref_str_idx)
+ internal_function;
static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
const re_sub_match_top_t *sub_top,
re_sub_match_last_t *sub_last,
- Idx bkref_node, Idx bkref_str) internal_function;
+ Idx bkref_node, Idx bkref_str)
+ internal_function;
static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
Idx subexp_idx, int type) internal_function;
static reg_errcode_t check_arrival (re_match_context_t *mctx,
@@ -150,35 +167,41 @@ static reg_errcode_t check_arrival (re_match_context_t *mctx,
static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
Idx str_idx,
re_node_set *cur_nodes,
- re_node_set *next_nodes) internal_function;
-static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa,
+ re_node_set *next_nodes)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
re_node_set *cur_nodes,
- Idx ex_subexp, int type) internal_function;
-static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa,
+ Idx ex_subexp, int type)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
re_node_set *dst_nodes,
Idx target, Idx ex_subexp,
int type) internal_function;
static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
re_node_set *cur_nodes, Idx cur_str,
- Idx subexp_num, int type) internal_function;
-static bool build_trtable (re_dfa_t *dfa,
+ Idx subexp_num, int type)
+ internal_function;
+static bool build_trtable (const re_dfa_t *dfa,
re_dfastate_t *state) internal_function;
#ifdef RE_ENABLE_I18N
-static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
- const re_string_t *input, Idx idx) internal_function;
+static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+ const re_string_t *input, Idx idx)
+ internal_function;
# ifdef _LIBC
static unsigned int find_collation_sequence_value (const unsigned char *mbs,
- size_t name_len) internal_function;
+ size_t name_len)
+ internal_function;
# endif /* _LIBC */
#endif /* RE_ENABLE_I18N */
static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
const re_dfastate_t *state,
re_node_set *states_node,
- bitset *states_ch) internal_function;
+ bitset_t *states_ch) internal_function;
static bool check_node_accept (const re_match_context_t *mctx,
const re_token_t *node, Idx idx)
internal_function;
-static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function;
+static reg_errcode_t extend_buffers (re_match_context_t *mctx)
+ internal_function;
/* Entry point for POSIX code. */
@@ -197,13 +220,17 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function
We return 0 if we find a match and REG_NOMATCH if not. */
int
-regexec (const regex_t *__restrict preg, const char *__restrict string,
- size_t nmatch, regmatch_t pmatch[], int eflags)
+regexec (preg, string, nmatch, pmatch, eflags)
+ const regex_t *__restrict preg;
+ const char *__restrict string;
+ size_t nmatch;
+ regmatch_t pmatch[];
+ int eflags;
{
reg_errcode_t err;
Idx start, length;
#ifdef _LIBC
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
#endif
if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
@@ -221,7 +248,7 @@ regexec (const regex_t *__restrict preg, const char *__restrict string,
}
__libc_lock_lock (dfa->lock);
- if (preg->re_no_sub)
+ if (preg->no_sub)
err = re_search_internal (preg, string, length, start, length,
length, 0, NULL, eflags);
else
@@ -271,8 +298,8 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
the first STOP characters of the concatenation of the strings should be
concerned.
- If REGS is not NULL, and BUFP->re_no_sub is not set, the offsets of the match
- and all groups is stroed in REGS. (For the "_2" variants, the offsets are
+ If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
+ and all groups is stored in REGS. (For the "_2" variants, the offsets are
computed relative to the concatenation, not relative to the individual
strings.)
@@ -281,8 +308,11 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
match was found and -2 indicates an internal error. */
regoff_t
-re_match (struct re_pattern_buffer *bufp, const char *string,
- Idx length, Idx start, struct re_registers *regs)
+re_match (bufp, string, length, start, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ struct re_registers *regs;
{
return re_search_stub (bufp, string, length, start, 0, length, regs, true);
}
@@ -291,8 +321,12 @@ weak_alias (__re_match, re_match)
#endif
regoff_t
-re_search (struct re_pattern_buffer *bufp, const char *string,
- Idx length, Idx start, regoff_t range, struct re_registers *regs)
+re_search (bufp, string, length, start, range, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ regoff_t range;
+ struct re_registers *regs;
{
return re_search_stub (bufp, string, length, start, range, length, regs,
false);
@@ -302,10 +336,11 @@ weak_alias (__re_search, re_search)
#endif
regoff_t
-re_match_2 (struct re_pattern_buffer *bufp,
- const char *string1, Idx length1,
- const char *string2, Idx length2,
- Idx start, struct re_registers *regs, Idx stop)
+re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ struct re_registers *regs;
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
start, 0, regs, stop, true);
@@ -315,10 +350,12 @@ weak_alias (__re_match_2, re_match_2)
#endif
regoff_t
-re_search_2 (struct re_pattern_buffer *bufp,
- const char *string1, Idx length1,
- const char *string2, Idx length2,
- Idx start, regoff_t range, struct re_registers *regs, Idx stop)
+re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ regoff_t range;
+ struct re_registers *regs;
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
start, range, regs, stop, false);
@@ -351,8 +388,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
if (BE (s == NULL, 0))
return -2;
+#ifdef _LIBC
+ memcpy (__mempcpy (s, string1, length1), string2, length2);
+#else
memcpy (s, string1, length1);
memcpy (s + length1, string2, length2);
+#endif
str = s;
}
else
@@ -384,59 +425,37 @@ re_search_stub (struct re_pattern_buffer *bufp,
regoff_t rval;
int eflags = 0;
#ifdef _LIBC
- re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
#endif
Idx last_start = start + range;
/* Check for out-of-range. */
if (BE (start < 0 || start > length, 0))
return -1;
- if (sizeof start < sizeof range)
- {
- regoff_t length_offset = length;
- regoff_t start_offset = start;
- if (BE (length_offset - start_offset < range, 0))
- last_start = length;
- else if (BE (range < - start_offset, 0))
- last_start = 0;
- }
- else
- {
- if (BE ((last_start < start) != (range < 0), 0))
- {
- /* Overflow occurred when computing last_start; substitute
- the extreme value. */
- last_start = range < 0 ? 0 : length;
- }
- else
- {
- if (BE (length < last_start, 0))
- last_start = length;
- else if (BE (last_start < 0, 0))
- last_start = 0;
- }
- }
+ if (BE (length < last_start || (0 <= range && last_start < start), 0))
+ last_start = length;
+ else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
+ last_start = 0;
__libc_lock_lock (dfa->lock);
- eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0;
- eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0;
+ eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
+ eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
/* Compile fastmap if we haven't yet. */
- if (start < last_start && bufp->re_fastmap != NULL
- && !bufp->re_fastmap_accurate)
+ if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
re_compile_fastmap (bufp);
- if (BE (bufp->re_no_sub, 0))
+ if (BE (bufp->no_sub, 0))
regs = NULL;
/* We need at least 1 register. */
if (regs == NULL)
nregs = 1;
- else if (BE (bufp->re_regs_allocated == REG_FIXED
- && regs->rm_num_regs <= bufp->re_nsub, 0))
+ else if (BE (bufp->regs_allocated == REGS_FIXED
+ && regs->num_regs <= bufp->re_nsub, 0))
{
- nregs = regs->rm_num_regs;
+ nregs = regs->num_regs;
if (BE (nregs < 1, 0))
{
/* Nothing can be copied to regs. */
@@ -446,7 +465,7 @@ re_search_stub (struct re_pattern_buffer *bufp,
}
else
nregs = bufp->re_nsub + 1;
- pmatch = re_xmalloc (regmatch_t, nregs);
+ pmatch = re_malloc (regmatch_t, nregs);
if (BE (pmatch == NULL, 0))
{
rval = -2;
@@ -464,9 +483,9 @@ re_search_stub (struct re_pattern_buffer *bufp,
else if (regs != NULL)
{
/* If caller wants register contents data back, copy them. */
- bufp->re_regs_allocated = re_copy_regs (regs, pmatch, nregs,
- bufp->re_regs_allocated);
- if (BE (bufp->re_regs_allocated == REG_UNALLOCATED, 0))
+ bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
+ bufp->regs_allocated);
+ if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
rval = -2;
}
@@ -486,58 +505,68 @@ re_search_stub (struct re_pattern_buffer *bufp,
return rval;
}
-static unsigned
+static unsigned int
internal_function
re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
int regs_allocated)
{
- int rval = REG_REALLOCATE;
+ int rval = REGS_REALLOCATE;
Idx i;
Idx need_regs = nregs + 1;
- /* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code
+ /* We need one extra element beyond `num_regs' for the `-1' marker GNU code
uses. */
/* Have the register data arrays been allocated? */
- if (regs_allocated == REG_UNALLOCATED)
+ if (regs_allocated == REGS_UNALLOCATED)
{ /* No. So allocate them with malloc. */
- regs->rm_start = re_xmalloc (regoff_t, need_regs);
- regs->rm_end = re_malloc (regoff_t, need_regs);
- if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0))
- return REG_UNALLOCATED;
- regs->rm_num_regs = need_regs;
+ regs->start = re_malloc (regoff_t, need_regs);
+ if (BE (regs->start == NULL, 0))
+ return REGS_UNALLOCATED;
+ regs->end = re_malloc (regoff_t, need_regs);
+ if (BE (regs->end == NULL, 0))
+ {
+ re_free (regs->start);
+ return REGS_UNALLOCATED;
+ }
+ regs->num_regs = need_regs;
}
- else if (regs_allocated == REG_REALLOCATE)
+ else if (regs_allocated == REGS_REALLOCATE)
{ /* Yes. If we need more elements than were already
allocated, reallocate them. If we need fewer, just
leave it alone. */
- if (BE (need_regs > regs->rm_num_regs, 0))
+ if (BE (need_regs > regs->num_regs, 0))
{
- regoff_t *new_start =
- re_xrealloc (regs->rm_start, regoff_t, need_regs);
- regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs);
- if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0))
- return REG_UNALLOCATED;
- regs->rm_start = new_start;
- regs->rm_end = new_end;
- regs->rm_num_regs = need_regs;
+ regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
+ regoff_t *new_end;
+ if (BE (new_start == NULL, 0))
+ return REGS_UNALLOCATED;
+ new_end = re_realloc (regs->end, regoff_t, need_regs);
+ if (BE (new_end == NULL, 0))
+ {
+ re_free (new_start);
+ return REGS_UNALLOCATED;
+ }
+ regs->start = new_start;
+ regs->end = new_end;
+ regs->num_regs = need_regs;
}
}
else
{
- assert (regs_allocated == REG_FIXED);
- /* This function may not be called with REG_FIXED and nregs too big. */
- assert (regs->rm_num_regs >= nregs);
- rval = REG_FIXED;
+ assert (regs_allocated == REGS_FIXED);
+ /* This function may not be called with REGS_FIXED and nregs too big. */
+ assert (regs->num_regs >= nregs);
+ rval = REGS_FIXED;
}
/* Copy the regs. */
for (i = 0; i < nregs; ++i)
{
- regs->rm_start[i] = pmatch[i].rm_so;
- regs->rm_end[i] = pmatch[i].rm_eo;
+ regs->start[i] = pmatch[i].rm_so;
+ regs->end[i] = pmatch[i].rm_eo;
}
- for ( ; i < regs->rm_num_regs; ++i)
- regs->rm_start[i] = regs->rm_end[i] = -1;
+ for ( ; i < regs->num_regs; ++i)
+ regs->start[i] = regs->end[i] = -1;
return rval;
}
@@ -556,21 +585,24 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
freeing the old data. */
void
-re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
- __re_size_t num_regs, regoff_t *starts, regoff_t *ends)
+re_set_registers (bufp, regs, num_regs, starts, ends)
+ struct re_pattern_buffer *bufp;
+ struct re_registers *regs;
+ __re_size_t num_regs;
+ regoff_t *starts, *ends;
{
if (num_regs)
{
- bufp->re_regs_allocated = REG_REALLOCATE;
- regs->rm_num_regs = num_regs;
- regs->rm_start = starts;
- regs->rm_end = ends;
+ bufp->regs_allocated = REGS_REALLOCATE;
+ regs->num_regs = num_regs;
+ regs->start = starts;
+ regs->end = ends;
}
else
{
- bufp->re_regs_allocated = REG_UNALLOCATED;
- regs->rm_num_regs = 0;
- regs->rm_start = regs->rm_end = NULL;
+ bufp->regs_allocated = REGS_UNALLOCATED;
+ regs->num_regs = 0;
+ regs->start = regs->end = NULL;
}
}
#ifdef _LIBC
@@ -585,7 +617,8 @@ int
# ifdef _LIBC
weak_function
# endif
-re_exec (const char *s)
+re_exec (s)
+ const char *s;
{
return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
}
@@ -611,12 +644,13 @@ re_search_internal (const regex_t *preg,
int eflags)
{
reg_errcode_t err;
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
Idx left_lim, right_lim;
int incr;
bool fl_longest_match;
int match_kind;
- Idx match_first, match_last = REG_MISSING;
+ Idx match_first;
+ Idx match_last = REG_MISSING;
Idx extra_nmatch;
bool sb;
int ch;
@@ -625,11 +659,10 @@ re_search_internal (const regex_t *preg,
#else
re_match_context_t mctx;
#endif
- char *fastmap = ((preg->re_fastmap != NULL && preg->re_fastmap_accurate
- && start != last_start && !preg->re_can_be_null)
- ? preg->re_fastmap : NULL);
- unsigned REG_TRANSLATE_TYPE t =
- (unsigned REG_TRANSLATE_TYPE) preg->re_translate;
+ char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
+ && start != last_start && !preg->can_be_null)
+ ? preg->fastmap : NULL);
+ RE_TRANSLATE_TYPE t = preg->translate;
#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
memset (&mctx, '\0', sizeof (re_match_context_t));
@@ -640,7 +673,7 @@ re_search_internal (const regex_t *preg,
nmatch -= extra_nmatch;
/* Check if the DFA haven't been compiled. */
- if (BE (preg->re_used == 0 || dfa->init_state == NULL
+ if (BE (preg->used == 0 || dfa->init_state == NULL
|| dfa->init_state_word == NULL || dfa->init_state_nl == NULL
|| dfa->init_state_begbuf == NULL, 0))
return REG_NOMATCH;
@@ -651,12 +684,12 @@ re_search_internal (const regex_t *preg,
#endif
/* If initial states with non-begbuf contexts have no elements,
- the regex must be anchored. If preg->re_newline_anchor is set,
+ the regex must be anchored. If preg->newline_anchor is set,
we'll never use init_state_nl, so do not check it. */
if (dfa->init_state->nodes.nelem == 0
&& dfa->init_state_word->nodes.nelem == 0
&& (dfa->init_state_nl->nodes.nelem == 0
- || !preg->re_newline_anchor))
+ || !preg->newline_anchor))
{
if (start != 0 && last_start != 0)
return REG_NOMATCH;
@@ -667,13 +700,12 @@ re_search_internal (const regex_t *preg,
fl_longest_match = (nmatch != 0 || dfa->nbackref);
err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
- preg->re_translate,
- preg->re_syntax & REG_IGNORE_CASE, dfa);
+ preg->translate, preg->syntax & RE_ICASE, dfa);
if (BE (err != REG_NOERROR, 0))
goto free_return;
mctx.input.stop = stop;
mctx.input.raw_stop = stop;
- mctx.input.newline_anchor = preg->re_newline_anchor;
+ mctx.input.newline_anchor = preg->newline_anchor;
err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
if (BE (err != REG_NOERROR, 0))
@@ -685,7 +717,14 @@ re_search_internal (const regex_t *preg,
multi character collating element. */
if (nmatch > 1 || dfa->has_mb_node)
{
- mctx.state_log = re_xmalloc (re_dfastate_t *, mctx.input.bufs_len + 1);
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+
+ mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
if (BE (mctx.state_log == NULL, 0))
{
err = REG_ESPACE;
@@ -706,7 +745,7 @@ re_search_internal (const regex_t *preg,
sb = dfa->mb_cur_max == 1;
match_kind =
(fastmap
- ? ((sb || !(preg->re_syntax & REG_IGNORE_CASE || t) ? 4 : 0)
+ ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
| (start <= last_start ? 2 : 0)
| (t != NULL ? 1 : 0))
: 8);
@@ -828,13 +867,13 @@ re_search_internal (const regex_t *preg,
else
{
mctx.match_last = match_last;
- if ((!preg->re_no_sub && nmatch > 1) || dfa->nbackref)
+ if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
{
re_dfastate_t *pstate = mctx.state_log[match_last];
mctx.last_node = check_halt_state_context (&mctx, pstate,
match_last);
}
- if ((!preg->re_no_sub && nmatch > 1 && dfa->has_plural_match)
+ if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
|| dfa->nbackref)
{
err = prune_impossible_nodes (&mctx);
@@ -873,7 +912,7 @@ re_search_internal (const regex_t *preg,
the maximum possible regoff_t value. We need a new error
code REG_OVERFLOW. */
- if (!preg->re_no_sub && nmatch > 1)
+ if (!preg->no_sub && nmatch > 1)
{
err = set_regs (preg, &mctx, nmatch, pmatch,
dfa->has_plural_match && dfa->nbackref > 0);
@@ -934,7 +973,7 @@ static reg_errcode_t
internal_function
prune_impossible_nodes (re_match_context_t *mctx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx halt_node, match_last;
reg_errcode_t ret;
re_dfastate_t **sifted_states;
@@ -945,7 +984,12 @@ prune_impossible_nodes (re_match_context_t *mctx)
#endif
match_last = mctx->match_last;
halt_node = mctx->last_node;
- sifted_states = re_xmalloc (re_dfastate_t *, match_last + 1);
+
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0))
+ return REG_ESPACE;
+
+ sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
if (BE (sifted_states == NULL, 0))
{
ret = REG_ESPACE;
@@ -953,7 +997,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
}
if (dfa->nbackref)
{
- lim_states = re_xmalloc (re_dfastate_t *, match_last + 1);
+ lim_states = re_malloc (re_dfastate_t *, match_last + 1);
if (BE (lim_states == NULL, 0))
{
ret = REG_ESPACE;
@@ -1021,7 +1065,7 @@ __attribute ((always_inline)) internal_function
acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
Idx idx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
if (dfa->init_state->has_constraint)
{
unsigned int context;
@@ -1063,7 +1107,7 @@ internal_function
check_matching (re_match_context_t *mctx, bool fl_longest_match,
Idx *p_match_first)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx match = 0;
Idx match_last = REG_MISSING;
@@ -1233,11 +1277,11 @@ check_halt_state_context (const re_match_context_t *mctx,
static Idx
internal_function
-proceed_next_node (const re_match_context_t *mctx,
- Idx nregs, regmatch_t *regs, Idx *pidx, Idx node,
- re_node_set *eps_via_nodes, struct re_fail_stack_t *fs)
+proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
+ Idx *pidx, Idx node, re_node_set *eps_via_nodes,
+ struct re_fail_stack_t *fs)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx i;
bool ok;
if (IS_EPSILON_NODE (dfa->nodes[node].type))
@@ -1342,15 +1386,17 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
Idx num = fs->num++;
if (fs->num == fs->alloc)
{
- struct re_fail_stack_ent_t *new_array =
- re_x2realloc (fs->stack, struct re_fail_stack_ent_t, &fs->alloc);
+ struct re_fail_stack_ent_t *new_array;
+ new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
+ * fs->alloc * 2));
if (new_array == NULL)
return REG_ESPACE;
+ fs->alloc *= 2;
fs->stack = new_array;
}
fs->stack[num].idx = str_idx;
fs->stack[num].node = dest_node;
- fs->stack[num].regs = re_xmalloc (regmatch_t, nregs);
+ fs->stack[num].regs = re_malloc (regmatch_t, nregs);
if (fs->stack[num].regs == NULL)
return REG_ESPACE;
memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
@@ -1360,8 +1406,8 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
static Idx
internal_function
-pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx,
- Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
+pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
+ regmatch_t *regs, re_node_set *eps_via_nodes)
{
Idx num = --fs->num;
assert (REG_VALID_INDEX (num));
@@ -1380,10 +1426,10 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx,
static reg_errcode_t
internal_function
-set_regs (const regex_t *preg, const re_match_context_t *mctx,
- size_t nmatch, regmatch_t *pmatch, bool fl_backtrack)
+set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
+ regmatch_t *pmatch, bool fl_backtrack)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
Idx idx, cur_node;
re_node_set eps_via_nodes;
struct re_fail_stack_t *fs;
@@ -1398,7 +1444,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx,
if (fl_backtrack)
{
fs = &fs_body;
- fs->stack = re_xmalloc (struct re_fail_stack_ent_t, fs->alloc);
+ fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
if (fs->stack == NULL)
return REG_ESPACE;
}
@@ -1408,11 +1454,6 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx,
cur_node = dfa->init_node;
re_node_set_init_empty (&eps_via_nodes);
- if (re_alloc_oversized (nmatch, sizeof (regmatch_t)))
- {
- free_fail_stack_return (fs);
- return REG_ESPACE;
- }
if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
else
@@ -1509,8 +1550,8 @@ free_fail_stack_return (struct re_fail_stack_t *fs)
static void
internal_function
-update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match,
- Idx cur_node, Idx cur_idx, Idx nmatch)
+update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
+ regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
{
int type = dfa->nodes[cur_node].type;
if (type == OP_OPEN_SUBEXP)
@@ -1581,7 +1622,7 @@ update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match,
static reg_errcode_t
internal_function
-sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx)
+sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
{
reg_errcode_t err;
int null_cnt = 0;
@@ -1639,11 +1680,11 @@ sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx)
static reg_errcode_t
internal_function
-build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx,
+build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx str_idx, re_node_set *cur_dest)
{
- re_dfa_t *const dfa = mctx->dfa;
- re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
Idx i;
/* Then build the next sifted state.
@@ -1726,8 +1767,8 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
static reg_errcode_t
internal_function
-merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src,
- Idx num)
+merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
{
Idx st_idx;
reg_errcode_t err;
@@ -1753,11 +1794,12 @@ merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src,
static reg_errcode_t
internal_function
-update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx,
- Idx str_idx, re_node_set *dest_nodes)
+update_cur_sifted_state (const re_match_context_t *mctx,
+ re_sift_context_t *sctx, Idx str_idx,
+ re_node_set *dest_nodes)
{
- re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
const re_node_set *candidates;
candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
: &mctx->state_log[str_idx]->nodes);
@@ -1800,7 +1842,7 @@ update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx,
static reg_errcode_t
internal_function
-add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes,
+add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
const re_node_set *candidates)
{
reg_errcode_t err = REG_NOERROR;
@@ -1825,7 +1867,7 @@ add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes,
static reg_errcode_t
internal_function
-sub_epsilon_src_nodes (re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
+sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
const re_node_set *candidates)
{
Idx ecl_idx;
@@ -1877,7 +1919,7 @@ internal_function
check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx lim_idx, src_pos, dst_pos;
Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
@@ -1913,8 +1955,8 @@ internal_function
check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
Idx subexp_idx, Idx from_node, Idx bkref_idx)
{
- re_dfa_t *const dfa = mctx->dfa;
- re_node_set *eclosures = dfa->eclosures + from_node;
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *eclosures = dfa->eclosures + from_node;
Idx node_idx;
/* Else, we are on the boundary: examine the nodes on the epsilon
@@ -1938,7 +1980,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
if (subexp_idx < BITSET_WORD_BITS
&& !(ent->eps_reachable_subexps_map
- & ((bitset_word) 1 << subexp_idx)))
+ & ((bitset_word_t) 1 << subexp_idx)))
continue;
/* Recurse trying to reach the OP_OPEN_SUBEXP and
@@ -1965,8 +2007,8 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
return 0;
if (subexp_idx < BITSET_WORD_BITS)
- ent->eps_reachable_subexps_map &=
- ~ ((bitset_word) 1 << subexp_idx);
+ ent->eps_reachable_subexps_map
+ &= ~((bitset_word_t) 1 << subexp_idx);
}
while (ent++->more);
}
@@ -1992,9 +2034,9 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
static int
internal_function
-check_dst_limits_calc_pos (const re_match_context_t *mctx,
- Idx limit, Idx subexp_idx,
- Idx from_node, Idx str_idx, Idx bkref_idx)
+check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
+ Idx subexp_idx, Idx from_node, Idx str_idx,
+ Idx bkref_idx)
{
struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
int boundaries;
@@ -2022,7 +2064,7 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx,
static reg_errcode_t
internal_function
-check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes,
+check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
const re_node_set *candidates, re_node_set *limits,
struct re_backref_cache_entry *bkref_ents, Idx str_idx)
{
@@ -2110,10 +2152,10 @@ check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes,
static reg_errcode_t
internal_function
-sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx,
+sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx str_idx, const re_node_set *candidates)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx node_idx, node;
re_sift_context_t local_sctx;
@@ -2141,8 +2183,10 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx,
enabled_idx = first_idx;
do
{
+ Idx subexp_len;
+ Idx to_idx;
+ Idx dst_node;
bool ok;
- Idx subexp_len, to_idx, dst_node;
re_dfastate_t *cur_state;
if (entry->node != node)
@@ -2211,7 +2255,7 @@ internal_function
sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx node_idx, Idx str_idx, Idx max_str_idx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
int naccepted;
/* Check the node can accept `multi byte'. */
naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
@@ -2299,7 +2343,7 @@ internal_function
merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
re_dfastate_t *next_state)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx cur_idx = re_string_cur_idx (&mctx->input);
if (cur_idx > mctx->state_log_top)
@@ -2377,7 +2421,7 @@ static re_dfastate_t *
internal_function
find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
{
- re_dfastate_t *cur_state = NULL;
+ re_dfastate_t *cur_state;
do
{
Idx max = mctx->state_log_top;
@@ -2409,7 +2453,7 @@ internal_function
check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
Idx str_idx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx node_idx;
reg_errcode_t err;
@@ -2424,7 +2468,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
if (dfa->nodes[node].type == OP_OPEN_SUBEXP
&& dfa->nodes[node].opr.idx < BITSET_WORD_BITS
&& (dfa->used_bkref_map
- & ((bitset_word) 1 << dfa->nodes[node].opr.idx)))
+ & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
{
err = match_ctx_add_subtop (mctx, node, str_idx);
if (BE (err != REG_NOERROR, 0))
@@ -2442,7 +2486,7 @@ static re_dfastate_t *
transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
re_dfastate_t *state)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
re_node_set next_nodes;
re_dfastate_t *next_state;
Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
@@ -2481,7 +2525,7 @@ static reg_errcode_t
internal_function
transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx i;
@@ -2535,7 +2579,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
if (BE (err != REG_NOERROR, 0))
return err;
}
- context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags);
+ context = re_string_context_at (&mctx->input, dest_idx - 1,
+ mctx->eflags);
mctx->state_log[dest_idx]
= re_acquire_state_context (&err, dfa, &dest_nodes, context);
if (dest_state != NULL)
@@ -2551,7 +2596,7 @@ static reg_errcode_t
internal_function
transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx i;
Idx cur_str_idx = re_string_cur_idx (&mctx->input);
@@ -2665,14 +2710,15 @@ static reg_errcode_t
internal_function
get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
Idx subexp_num, sub_top_idx;
const char *buf = (const char *) re_string_get_buffer (&mctx->input);
/* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
if (cache_idx != REG_MISSING)
{
- const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx;
+ const struct re_backref_cache_entry *entry
+ = mctx->bkref_ents + cache_idx;
do
if (entry->node == bkref_node)
return REG_NOERROR; /* We already checked it. */
@@ -2719,7 +2765,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
buf = (const char *) re_string_get_buffer (&mctx->input);
}
if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
- break; /* We don't need to search this sub expression any more. */
+ /* We don't need to search this sub expression any more. */
+ break;
}
bkref_str_off += sl_str_diff;
sl_str += sl_str_diff;
@@ -2771,20 +2818,22 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
continue;
/* Does this state have a ')' of the sub expression? */
nodes = &mctx->state_log[sl_str]->nodes;
- cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP);
+ cls_node = find_subexp_node (dfa, nodes, subexp_num,
+ OP_CLOSE_SUBEXP);
if (cls_node == REG_MISSING)
continue; /* No. */
if (sub_top->path == NULL)
{
- sub_top->path = re_calloc (state_array_t,
- sl_str - sub_top->str_idx + 1);
+ sub_top->path = calloc (sizeof (state_array_t),
+ sl_str - sub_top->str_idx + 1);
if (sub_top->path == NULL)
return REG_ESPACE;
}
/* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
in the current context? */
err = check_arrival (mctx, sub_top->path, sub_top->node,
- sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP);
+ sub_top->str_idx, cls_node, sl_str,
+ OP_CLOSE_SUBEXP);
if (err == REG_NOMATCH)
continue;
if (BE (err != REG_NOERROR, 0))
@@ -2816,7 +2865,8 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
Idx to_idx;
/* Can the subexpression arrive the back reference? */
err = check_arrival (mctx, &sub_last->path, sub_last->node,
- sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP);
+ sub_last->str_idx, bkref_node, bkref_str,
+ OP_OPEN_SUBEXP);
if (err != REG_NOERROR)
return err;
err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
@@ -2859,12 +2909,11 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
static reg_errcode_t
internal_function
-check_arrival (re_match_context_t *mctx, state_array_t *path,
- Idx top_node, Idx top_str, Idx last_node, Idx last_str,
- int type)
+check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
+ Idx top_str, Idx last_node, Idx last_str, int type)
{
- re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
re_dfastate_t *cur_state = NULL;
re_node_set *cur_nodes, next_nodes;
@@ -2878,18 +2927,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
re_dfastate_t **new_array;
Idx old_alloc = path->alloc;
Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1;
- if (BE (new_alloc < old_alloc, 0))
+ if (BE (new_alloc < old_alloc, 0)
+ || BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
return REG_ESPACE;
- new_array = re_xrealloc (path->array, re_dfastate_t *, new_alloc);
+ new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
path->array = new_array;
path->alloc = new_alloc;
memset (new_array + old_alloc, '\0',
- sizeof (re_dfastate_t *) * (new_alloc - old_alloc));
+ sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
}
- str_idx = path->next_idx == 0 ? top_str : path->next_idx;
+ str_idx = path->next_idx ? path->next_idx : top_str;
/* Temporary modify MCTX. */
backup_state_log = mctx->state_log;
@@ -2917,7 +2967,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
if (cur_state && cur_state->has_backref)
{
err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
return err;
}
else
@@ -2929,7 +2979,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
{
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
@@ -2960,7 +3010,8 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
if (cur_state)
{
err = check_arrival_add_next_nodes (mctx, str_idx,
- &cur_state->non_eps_nodes, &next_nodes);
+ &cur_state->non_eps_nodes,
+ &next_nodes);
if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
@@ -2978,7 +3029,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
}
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
- if (BE ( err != REG_NOERROR, 0))
+ if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
@@ -3021,13 +3072,12 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
static reg_errcode_t
internal_function
check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
- re_node_set *cur_nodes,
- re_node_set *next_nodes)
+ re_node_set *cur_nodes, re_node_set *next_nodes)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
bool ok;
Idx cur_idx;
- reg_errcode_t err;
+ reg_errcode_t err = REG_NOERROR;
re_node_set union_set;
re_node_set_init_empty (&union_set);
for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
@@ -3100,7 +3150,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
static reg_errcode_t
internal_function
-check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
+check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
Idx ex_subexp, int type)
{
reg_errcode_t err;
@@ -3118,7 +3168,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
for (idx = 0; idx < cur_nodes->nelem; ++idx)
{
Idx cur_node = cur_nodes->elems[idx];
- re_node_set *eclosure = dfa->eclosures + cur_node;
+ const re_node_set *eclosure = dfa->eclosures + cur_node;
outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
if (outside_node == REG_MISSING)
{
@@ -3153,7 +3203,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
static reg_errcode_t
internal_function
-check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes,
+check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
Idx target, Idx ex_subexp, int type)
{
Idx cur_node;
@@ -3179,12 +3229,12 @@ check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes,
break;
if (dfa->edests[cur_node].nelem == 2)
{
- reg_errcode_t ret =
- check_arrival_expand_ecl_sub (dfa, dst_nodes,
- dfa->edests[cur_node].elems[1],
- ex_subexp, type);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
+ reg_errcode_t err;
+ err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
+ dfa->edests[cur_node].elems[1],
+ ex_subexp, type);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
}
cur_node = dfa->edests[cur_node].elems[0];
}
@@ -3201,7 +3251,7 @@ internal_function
expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
Idx cur_str, Idx subexp_num, int type)
{
- re_dfa_t *const dfa = mctx->dfa;
+ const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
struct re_backref_cache_entry *ent;
@@ -3287,25 +3337,26 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
static bool
internal_function
-build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
+build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
{
reg_errcode_t err;
Idx i, j;
int ch;
bool need_word_trtable = false;
- bitset_word elem, mask;
- bool dests_node_malloced = false, dest_states_malloced = false;
+ bitset_word_t elem, mask;
+ bool dests_node_malloced = false;
+ bool dest_states_malloced = false;
Idx ndests; /* Number of the destination states from `state'. */
re_dfastate_t **trtable;
re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
re_node_set follows, *dests_node;
- bitset *dests_ch;
- bitset acceptable;
+ bitset_t *dests_ch;
+ bitset_t acceptable;
struct dests_alloc
{
re_node_set dests_node[SBC_MAX];
- bitset dests_ch[SBC_MAX];
+ bitset_t dests_ch[SBC_MAX];
} *dests_alloc;
/* We build DFA states which corresponds to the destination nodes
@@ -3313,7 +3364,7 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
destination state contains, and `dests_ch[i]' represents the
characters which i-th destination state accepts. */
if (__libc_use_alloca (sizeof (struct dests_alloc)))
- dests_alloc = (struct dests_alloc *) alloca (sizeof dests_alloc[0]);
+ dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
else
{
dests_alloc = re_malloc (struct dests_alloc, 1);
@@ -3336,7 +3387,8 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
free (dests_alloc);
if (ndests == 0)
{
- state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
+ state->trtable = (re_dfastate_t **)
+ calloc (sizeof (re_dfastate_t *), SBC_MAX);
return true;
}
return false;
@@ -3347,12 +3399,13 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
goto out_free;
/* Avoid arithmetic overflow in size calculation. */
- if (BE (((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX)
- / (3 * sizeof (re_dfastate_t *)))
- < ndests, 0))
+ if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
+ / (3 * sizeof (re_dfastate_t *)))
+ < ndests),
+ 0))
goto out_free;
- if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX
+ if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
+ ndests * 3 * sizeof (re_dfastate_t *)))
dest_states = (re_dfastate_t **)
alloca (ndests * 3 * sizeof (re_dfastate_t *));
@@ -3428,7 +3481,8 @@ out_free:
character, or we are in a single-byte character set so we can
discern by looking at the character code: allocate a
256-entry transition table. */
- trtable = state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
+ trtable = state->trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
@@ -3458,7 +3512,8 @@ out_free:
by looking at the character code: build two 256-entry
transition tables, one starting at trtable[0] and one
starting at trtable[SBC_MAX]. */
- trtable = state->word_trtable = re_calloc (re_dfastate_t *, 2 * SBC_MAX);
+ trtable = state->word_trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
@@ -3518,13 +3573,13 @@ out_free:
static Idx
internal_function
group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
- re_node_set *dests_node, bitset *dests_ch)
+ re_node_set *dests_node, bitset_t *dests_ch)
{
reg_errcode_t err;
bool ok;
Idx i, j, k;
Idx ndests; /* Number of the destinations from `state'. */
- bitset accepts; /* Characters a node can accept. */
+ bitset_t accepts; /* Characters a node can accept. */
const re_node_set *cur_nodes = &state->nodes;
bitset_empty (accepts);
ndests = 0;
@@ -3551,21 +3606,21 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
else
#endif
bitset_set_all (accepts);
- if (!(dfa->syntax & REG_DOT_NEWLINE))
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
bitset_clear (accepts, '\n');
- if (dfa->syntax & REG_DOT_NOT_NULL)
+ if (dfa->syntax & RE_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#ifdef RE_ENABLE_I18N
else if (type == OP_UTF8_PERIOD)
{
- if (SBC_MAX / 2 % BITSET_WORD_BITS == 0)
- memset (accepts, -1, sizeof accepts / 2);
+ if (ASCII_CHARS % BITSET_WORD_BITS == 0)
+ memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
else
bitset_merge (accepts, utf8_sb_map);
- if (!(dfa->syntax & REG_DOT_NEWLINE))
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
bitset_clear (accepts, '\n');
- if (dfa->syntax & REG_DOT_NOT_NULL)
+ if (dfa->syntax & RE_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#endif
@@ -3593,7 +3648,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
if (constraint & NEXT_WORD_CONSTRAINT)
{
- bitset_word any_set = 0;
+ bitset_word_t any_set = 0;
if (type == CHARACTER && !node->word_char)
{
bitset_empty (accepts);
@@ -3612,7 +3667,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
}
if (constraint & NEXT_NOTWORD_CONSTRAINT)
{
- bitset_word any_set = 0;
+ bitset_word_t any_set = 0;
if (type == CHARACTER && node->word_char)
{
bitset_empty (accepts);
@@ -3635,10 +3690,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
state. Above, we make sure that accepts is not empty. */
for (j = 0; j < ndests; ++j)
{
- bitset intersec; /* Intersection sets, see below. */
- bitset remains;
+ bitset_t intersec; /* Intersection sets, see below. */
+ bitset_t remains;
/* Flags, see below. */
- bitset_word has_intersec, not_subset, not_consumed;
+ bitset_word_t has_intersec, not_subset, not_consumed;
/* Optimization, skip if this state doesn't accept the character. */
if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
@@ -3710,7 +3765,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
static int
internal_function
-check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
+check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
const re_string_t *input, Idx str_idx)
{
const re_token_t *node = dfa->nodes + node_idx;
@@ -3776,9 +3831,9 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
/* FIXME: I don't think this if is needed, as both '\n'
and '\0' are char_len == 1. */
/* '.' accepts any one character except the following two cases. */
- if ((!(dfa->syntax & REG_DOT_NEWLINE) &&
+ if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
re_string_byte_at (input, str_idx) == '\n') ||
- ((dfa->syntax & REG_DOT_NOT_NULL) &&
+ ((dfa->syntax & RE_DOT_NOT_NULL) &&
re_string_byte_at (input, str_idx) == '\0'))
return 0;
return char_len;
@@ -3945,6 +4000,7 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
# ifdef _LIBC
static unsigned int
+internal_function
find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
{
uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -4028,13 +4084,13 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
#ifdef RE_ENABLE_I18N
case OP_UTF8_PERIOD:
- if (ch >= 0x80)
+ if (ch >= ASCII_CHARS)
return false;
/* FALLTHROUGH */
#endif
case OP_PERIOD:
- if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE))
- || (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL)))
+ if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
+ || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
return false;
break;
@@ -4064,6 +4120,10 @@ extend_buffers (re_match_context_t *mctx)
reg_errcode_t ret;
re_string_t *pstr = &mctx->input;
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
+ return REG_ESPACE;
+
/* Double the lengthes of the buffers. */
ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
if (BE (ret != REG_NOERROR, 0))
@@ -4075,8 +4135,8 @@ extend_buffers (re_match_context_t *mctx)
/* XXX We have no indication of the size of this buffer. If this
allocation fail we have no indication that the state_log array
does not have the right size. */
- re_dfastate_t **new_array = re_xrealloc (mctx->state_log, re_dfastate_t *,
- pstr->bufs_len + 1);
+ re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
+ pstr->bufs_len + 1);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
mctx->state_log = new_array;
@@ -4124,8 +4184,15 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
mctx->match_last = REG_MISSING;
if (n > 0)
{
- mctx->bkref_ents = re_xmalloc (struct re_backref_cache_entry, n);
- mctx->sub_tops = re_xmalloc (re_sub_match_top_t *, n);
+ /* Avoid overflow. */
+ size_t max_object_size =
+ MAX (sizeof (struct re_backref_cache_entry),
+ sizeof (re_sub_match_top_t *));
+ if (BE (SIZE_MAX / max_object_size < n, 0))
+ return REG_ESPACE;
+
+ mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
+ mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
return REG_ESPACE;
}
@@ -4191,14 +4258,14 @@ match_ctx_free (re_match_context_t *mctx)
static reg_errcode_t
internal_function
-match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx,
- Idx from, Idx to)
+match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
+ Idx to)
{
if (mctx->nbkref_ents >= mctx->abkref_ents)
{
struct re_backref_cache_entry* new_entry;
- new_entry = re_x2realloc (mctx->bkref_ents, struct re_backref_cache_entry,
- &mctx->abkref_ents);
+ new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
+ mctx->abkref_ents * 2);
if (BE (new_entry == NULL, 0))
{
re_free (mctx->bkref_ents);
@@ -4206,8 +4273,8 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx,
}
mctx->bkref_ents = new_entry;
memset (mctx->bkref_ents + mctx->nbkref_ents, '\0',
- (sizeof (struct re_backref_cache_entry)
- * (mctx->abkref_ents - mctx->nbkref_ents)));
+ sizeof (struct re_backref_cache_entry) * mctx->abkref_ents);
+ mctx->abkref_ents *= 2;
}
if (mctx->nbkref_ents > 0
&& mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx)
@@ -4271,16 +4338,16 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
#endif
if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
{
- Idx new_asub_tops = mctx->asub_tops;
- re_sub_match_top_t **new_array = re_x2realloc (mctx->sub_tops,
- re_sub_match_top_t *,
- &new_asub_tops);
+ Idx new_asub_tops = mctx->asub_tops * 2;
+ re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
+ re_sub_match_top_t *,
+ new_asub_tops);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
mctx->sub_tops = new_array;
mctx->asub_tops = new_asub_tops;
}
- mctx->sub_tops[mctx->nsub_tops] = re_calloc (re_sub_match_top_t, 1);
+ mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
return REG_ESPACE;
mctx->sub_tops[mctx->nsub_tops]->node = node;
@@ -4298,16 +4365,16 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
re_sub_match_last_t *new_entry;
if (BE (subtop->nlasts == subtop->alasts, 0))
{
- Idx new_alasts = subtop->alasts;
- re_sub_match_last_t **new_array = re_x2realloc (subtop->lasts,
- re_sub_match_last_t *,
- &new_alasts);
+ Idx new_alasts = 2 * subtop->alasts + 1;
+ re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
+ re_sub_match_last_t *,
+ new_alasts);
if (BE (new_array == NULL, 0))
return NULL;
subtop->lasts = new_array;
subtop->alasts = new_alasts;
}
- new_entry = re_calloc (re_sub_match_last_t, 1);
+ new_entry = calloc (1, sizeof (re_sub_match_last_t));
if (BE (new_entry != NULL, 1))
{
subtop->lasts[subtop->nlasts] = new_entry;
@@ -4320,10 +4387,8 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
static void
internal_function
-sift_ctx_init (re_sift_context_t *sctx,
- re_dfastate_t **sifted_sts,
- re_dfastate_t **limited_sts,
- Idx last_node, Idx last_str_idx)
+sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
+ re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
{
sctx->sifted_states = sifted_sts;
sctx->limited_states = limited_sts;
diff --git a/lib/stat-macros.h b/lib/stat-macros.h
index 0957a22..829ddd3 100644
--- a/lib/stat-macros.h
+++ b/lib/stat-macros.h
@@ -1,6 +1,7 @@
/* stat-related macros
- Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1994, 2001, 2002, 2004, 2006 Free Software
+ Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,7 +34,6 @@
# undef S_ISBLK
# undef S_ISCHR
# undef S_ISDIR
-# undef S_ISDOOR
# undef S_ISFIFO
# undef S_ISLNK
# undef S_ISNAM
@@ -70,11 +70,7 @@
# endif
# ifndef S_ISDOOR /* Solaris 2.5 and up */
-# ifdef S_IFDOOR
-# define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
-# else
-# define S_ISDOOR(m) 0
-# endif
+# define S_ISDOOR(m) 0
# endif
# ifndef S_ISFIFO
@@ -119,6 +115,10 @@
# endif
# endif
+# ifndef S_ISPORT /* Solaris 10 and up */
+# define S_ISPORT(m) 0
+# endif
+
# ifndef S_ISREG
# ifdef S_IFREG
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
@@ -161,7 +161,7 @@
# endif
# endif
-/* contiguous */
+/* high performance ("contiguous data") */
# ifndef S_ISCTG
# define S_ISCTG(p) 0
# endif
@@ -176,6 +176,11 @@
# define S_ISOFL(p) 0
# endif
+/* 4.4BSD whiteout */
+# ifndef S_ISWHT
+# define S_ISWHT(m) 0
+# endif
+
/* If any of the following are undefined,
define them to their de facto standard values. */
# if !S_ISUID
diff --git a/lib/stripslash.c b/lib/stripslash.c
index 9b55da4..4ba5dad 100644
--- a/lib/stripslash.c
+++ b/lib/stripslash.c
@@ -1,6 +1,6 @@
/* stripslash.c -- remove redundant trailing slashes from a file name
- Copyright (C) 1990, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,19 +22,26 @@
#include "dirname.h"
-/* Remove trailing slashes from FILE.
- Return true if a trailing slash was removed.
- This is useful when using file name completion from a shell that
- adds a "/" after directory names (such as tcsh and bash), because
- the Unix rename and rmdir system calls return an "Invalid argument" error
- when given a file that ends in "/" (except for the root directory). */
+/* Remove trailing slashes from FILE. Return true if a trailing slash
+ was removed. This is useful when using file name completion from a
+ shell that adds a "/" after directory names (such as tcsh and
+ bash), because on symlinks to directories, several system calls
+ have different semantics according to whether a trailing slash is
+ present. */
bool
strip_trailing_slashes (char *file)
{
- char *base = base_name (file);
- char *base_lim = base + base_len (base);
- bool had_slash = (*base_lim != '\0');
+ char *base = last_component (file);
+ char *base_lim;
+ bool had_slash;
+
+ /* last_component returns "" for file system roots, but we need to turn
+ `///' into `/'. */
+ if (! *base)
+ base = file;
+ base_lim = base + base_len (base);
+ had_slash = (*base_lim != '\0');
*base_lim = '\0';
return had_slash;
}
diff --git a/lib/verify.h b/lib/verify.h
index 328980f..d603b17 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -1,6 +1,6 @@
/* Compile-time assert-like macros.
- Copyright (C) 2005 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,25 +16,111 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-/* Written by Paul Eggert and Jim Meyering. */
+/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
#ifndef VERIFY_H
# define VERIFY_H 1
-/* Each of these macros verifies that its argument R is a nonzero
- constant expression. To be portable, R's type must be integer (or
- boolean). Unlike assert, there is no run-time overhead.
+/* Each of these macros verifies that its argument R is nonzero. To
+ be portable, R should be an integer constant expression. Unlike
+ assert (R), there is no run-time overhead.
There are two macros, since no single macro can be used in all
- contexts in C. verify_true (R) is for scalar contexts, where it
- may be cast to void if need be. verify (R) is for declaration
+ contexts in C. verify_true (R) is for scalar contexts, including
+ integer constant expression contexts. verify (R) is for declaration
contexts, e.g., the top level.
- The symbols verify_error_if_negative_size__ and verify_function__
- are private to this header. */
+ Symbols ending in "__" are private to this header.
+
+ The code below uses several ideas.
+
+ * The first step is ((R) ? 1 : -1). Given an expression R, of
+ integral or boolean or floating-point type, this yields an
+ expression of integral type, whose value is later verified to be
+ constant and nonnegative.
+
+ * Next this expression W is wrapped in a type
+ struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
+ If W is negative, this yields a compile-time error. No compiler can
+ deal with a bit-field of negative size.
+
+ One might think that an array size check would have the same
+ effect, that is, that the type struct { unsigned int dummy[W]; }
+ would work as well. However, inside a function, some compilers
+ (such as C++ compilers and GNU C) allow local parameters and
+ variables inside array size expressions. With these compilers,
+ an array size check would not properly diagnose this misuse of
+ the verify macro:
+
+ void function (int n) { verify (n < 0); }
+
+ * For the verify macro, the struct verify_type__ will need to
+ somehow be embedded into a declaration. To be portable, this
+ declaration must declare an object, a constant, a function, or a
+ typedef name. If the declared entity uses the type directly,
+ such as in
+
+ struct dummy {...};
+ typedef struct {...} dummy;
+ extern struct {...} *dummy;
+ extern void dummy (struct {...} *);
+ extern struct {...} *dummy (void);
+
+ two uses of the verify macro would yield colliding declarations
+ if the entity names are not disambiguated. A workaround is to
+ attach the current line number to the entity name:
+
+ #define GL_CONCAT0(x, y) x##y
+ #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
+ extern struct {...} * GL_CONCAT(dummy,__LINE__);
+
+ But this has the problem that two invocations of verify from
+ within the same macro would collide, since the __LINE__ value
+ would be the same for both invocations.
+
+ A solution is to use the sizeof operator. It yields a number,
+ getting rid of the identity of the type. Declarations like
+
+ extern int dummy [sizeof (struct {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ can be repeated.
+
+ * Should the implementation use a named struct or an unnamed struct?
+ Which of the following alternatives can be used?
+
+ extern int dummy [sizeof (struct {...})];
+ extern int dummy [sizeof (struct verify_type__ {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern void dummy (int [sizeof (struct verify_type__ {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+ extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
+
+ In the second and sixth case, the struct type is exported to the
+ outer scope; two such declarations therefore collide. GCC warns
+ about the first, third, and fourth cases. So the only remaining
+ possibility is the fifth case:
+
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ * This implementation exploits the fact that GCC does not warn about
+ the last declaration mentioned above. If a future version of GCC
+ introduces a warning for this, the problem could be worked around
+ by using code specialized to GCC, e.g.,:
+
+ #if 4 <= __GNUC__
+ # define verify(R) \
+ extern int (* verify_function__ (void)) \
+ [__builtin_constant_p (R) && (R) ? 1 : -1]
+ #endif
+
+ * In C++, any struct definition inside sizeof is invalid.
+ Use a template type to work around the problem. */
+
/* Verify requirement R at compile-time, as an integer constant expression.
- Return true. */
+ Return 1. */
# ifdef __cplusplus
template <int w>
diff --git a/lib/xalloc-die.c b/lib/xalloc-die.c
index ff5ac9e..9b4a76c 100644
--- a/lib/xalloc-die.c
+++ b/lib/xalloc-die.c
@@ -1,6 +1,6 @@
/* Report a memory allocation failure and exit.
- Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free
+ Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -30,7 +30,6 @@
#include "gettext.h"
#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
void
xalloc_die (void)
diff --git a/m4/Makefile.am b/m4/Makefile.am
index 6b8a6a2..c70178b 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -6,12 +6,14 @@ EXTRA_DIST = \
d-ino.m4 \
dirname.m4 \
dos.m4 \
+ double-slash-root.m4 \
error.m4 \
exclude.m4 \
exitfail.m4 \
extensions.m4 \
fnmatch.m4 \
fpending.m4 \
+ getcwd-abort-bug.m4 \
getcwd-path-max.m4 \
getcwd.m4 \
getopt.m4 \
@@ -57,6 +59,7 @@ EXTRA_DIST = \
restrict.m4 \
signed.m4 \
size_max.m4 \
+ ssize_t.m4 \
stat-macros.m4 \
stdbool.m4 \
stdint_h.m4 \
@@ -64,14 +67,19 @@ EXTRA_DIST = \
strcspn.m4 \
strdup.m4 \
strerror_r.m4 \
+ strndup.m4 \
+ strnlen.m4 \
strpbrk.m4 \
strsep.m4 \
strstr.m4 \
uintmax_t.m4 \
ulonglong.m4 \
+ unistd_h.m4 \
wchar_t.m4 \
+ wcwidth.m4 \
wint_t.m4 \
xalloc.m4 \
xgetcwd.m4 \
xsize.m4 \
+ xstrndup.m4 \
extra_dist.sh
diff --git a/m4/d-ino.m4 b/m4/d-ino.m4
index 4d2c4db..d87b4db 100644
--- a/m4/d-ino.m4
+++ b/m4/d-ino.m4
@@ -1,11 +1,11 @@
-#serial 7
+#serial 8
dnl From Jim Meyering.
dnl
dnl Check whether struct dirent has a member named d_ino.
dnl
-# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004 Free Software
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2006 Free Software
# Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -13,26 +13,12 @@ dnl
# with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO],
- [AC_REQUIRE([AC_HEADER_DIRENT])dnl
- AC_CACHE_CHECK([for d_ino member in directory struct],
+ [AC_CACHE_CHECK([for d_ino member in directory struct],
jm_cv_struct_dirent_d_ino,
[AC_TRY_LINK(dnl
[
#include <sys/types.h>
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#else /* not HAVE_DIRENT_H */
-# define dirent direct
-# ifdef HAVE_SYS_NDIR_H
-# include <sys/ndir.h>
-# endif /* HAVE_SYS_NDIR_H */
-# ifdef HAVE_SYS_DIR_H
-# include <sys/dir.h>
-# endif /* HAVE_SYS_DIR_H */
-# ifdef HAVE_NDIR_H
-# include <ndir.h>
-# endif /* HAVE_NDIR_H */
-#endif /* HAVE_DIRENT_H */
+#include <dirent.h>
],
[struct dirent dp; dp.d_ino = 0;],
diff --git a/m4/dirname.m4 b/m4/dirname.m4
index e36937d..f3412ad 100644
--- a/m4/dirname.m4
+++ b/m4/dirname.m4
@@ -1,5 +1,5 @@
-# dirname.m4 serial 5
-dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+#serial 6 -*- autoconf -*-
+dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -11,6 +11,7 @@ AC_DEFUN([gl_DIRNAME],
dnl Prerequisites of lib/dirname.h.
AC_REQUIRE([gl_AC_DOS])
+ AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c.
])
diff --git a/m4/dos.m4 b/m4/dos.m4
index 0713cf1..dd59571 100644
--- a/m4/dos.m4
+++ b/m4/dos.m4
@@ -1,9 +1,9 @@
-#serial 9
+#serial 10 -*- autoconf -*-
# Define some macros required for proper operation of code in lib/*.c
# on MSDOS/Windows systems.
-# Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2004, 2005, 2006 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.
@@ -14,30 +14,38 @@ AC_DEFUN([gl_AC_DOS],
[
AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos],
[
- AC_TRY_COMPILE([],
- [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__
+ AC_TRY_COMPILE([],
+ [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__
neither MSDOS nor Windows
#endif],
- [ac_cv_win_or_dos=yes],
- [ac_cv_win_or_dos=no])
+ [ac_cv_win_or_dos=yes],
+ [ac_cv_win_or_dos=no])
])
if test x"$ac_cv_win_or_dos" = xyes; then
ac_fs_accepts_drive_letter_prefix=1
ac_fs_backslash_is_file_name_separator=1
+ AC_CACHE_CHECK([whether drive letter can start relative path],
+ [ac_cv_drive_letter_can_be_relative],
+ [
+ AC_TRY_COMPILE([],
+ [#if defined __CYGWIN__
+drive letters are always absolute
+#endif],
+ [ac_cv_drive_letter_can_be_relative=yes],
+ [ac_cv_drive_letter_can_be_relative=no])
+ ])
+ if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then
+ ac_fs_drive_letter_can_be_relative=1
+ else
+ ac_fs_drive_letter_can_be_relative=0
+ fi
else
ac_fs_accepts_drive_letter_prefix=0
ac_fs_backslash_is_file_name_separator=0
+ ac_fs_drive_letter_can_be_relative=0
fi
- AH_VERBATIM(FILE_SYSTEM_PREFIX_LEN,
- [#if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
-# define FILE_SYSTEM_PREFIX_LEN(Filename) \
- ((Filename)[0] && (Filename)[1] == ':' ? 2 : 0)
-#else
-# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
-#endif])
-
AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX],
$ac_fs_accepts_drive_letter_prefix,
[Define on systems for which file names may have a so-called
@@ -55,4 +63,9 @@ neither MSDOS nor Windows
$ac_fs_backslash_is_file_name_separator,
[Define if the backslash character may also serve as a file name
component separator.])
+
+ AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE],
+ $ac_fs_drive_letter_can_be_relative,
+ [Define if a drive letter prefix denotes a relative path if it is
+ not followed by a file name component separator.])
])
diff --git a/m4/double-slash-root.m4 b/m4/double-slash-root.m4
new file mode 100644
index 0000000..f8cbd54
--- /dev/null
+++ b/m4/double-slash-root.m4
@@ -0,0 +1,43 @@
+#serial 1 -*- autoconf -*-
+dnl Copyright (C) 2006 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_DOUBLE_SLASH_ROOT],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_CACHE_CHECK([whether // is distinct from /], [ac_cv_double_slash_root],
+ [ if test x"$cross_compiling" = xyes ; then
+ # When cross-compiling, there is no way to tell whether // is special
+ # short of a list of hosts. However, the only known hosts to date
+ # that have a distinct // are Apollo DomainOS (too old to port to)
+ # and Cygwin. If anyone knows of another system for which // has
+ # special semantics and is distinct from /, please report it to
+ # <bug-coreutils@gnu.org>.
+ case $host in
+ *-cygwin)
+ ac_cv_double_slash_root=yes ;;
+ *)
+ # Be optimistic and assume that / and // are the same when we
+ # don't know.
+ ac_cv_double_slash_root='unknown, assuming no' ;;
+ esac
+ else
+ set x `ls -di / //`
+ if test $[2] = $[4]; then
+ ac_cv_double_slash_root=no
+ else
+ ac_cv_double_slash_root=yes
+ fi
+ fi])
+ if test x"$ac_cv_double_slash_root" = xyes; then
+ ac_double_slash_root=1
+ else
+ ac_double_slash_root=0
+ fi
+
+ AC_DEFINE_UNQUOTED([DOUBLE_SLASH_IS_DISTINCT_ROOT],
+ $ac_double_slash_root,
+ [Define to 1 if // is a file system root distinct from /.])
+])
diff --git a/m4/exclude.m4 b/m4/exclude.m4
index ecb0f54..87acf84 100644
--- a/m4/exclude.m4
+++ b/m4/exclude.m4
@@ -1,5 +1,5 @@
-# exclude.m4 serial 5
-dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+# exclude.m4 serial 6
+dnl Copyright (C) 2002, 2003, 2005, 2006 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,4 @@ AC_DEFUN([gl_EXCLUDE],
[
AC_LIBSOURCES([exclude.c, exclude.h])
AC_LIBOBJ([exclude])
-
- dnl Prerequisites of lib/exclude.c.
- AC_REQUIRE([AC_C_INLINE])
- AC_REQUIRE([AC_HEADER_STDC])
- AC_CHECK_FUNCS_ONCE(isascii)
])
diff --git a/m4/extensions.m4 b/m4/extensions.m4
index e71845f..4976079 100644
--- a/m4/extensions.m4
+++ b/m4/extensions.m4
@@ -1,10 +1,13 @@
# Enable extensions on systems that normally disable them.
-# Copyright (C) 2003 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2006 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.
+# This file is only needed in autoconf <= 2.59. Newer versions of autoconf
+# have a macro AC_USE_SYSTEM_EXTENSIONS with identical semantics.
+
# gl_USE_SYSTEM_EXTENSIONS
# ------------------------
# Enable extensions on systems that normally disable them,
@@ -25,6 +28,15 @@ AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif])
- AC_DEFINE([__EXTENSIONS__])
+ AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
+ [ac_cv_safe_to_define___extensions__],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([
+ #define __EXTENSIONS__ 1
+ AC_INCLUDES_DEFAULT])],
+ [ac_cv_safe_to_define___extensions__=yes],
+ [ac_cv_safe_to_define___extensions__=no])])
+ test $ac_cv_safe_to_define___extensions__ = yes &&
+ AC_DEFINE([__EXTENSIONS__])
AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
])
diff --git a/m4/fnmatch.m4 b/m4/fnmatch.m4
index e879bbd..ce94c84 100644
--- a/m4/fnmatch.m4
+++ b/m4/fnmatch.m4
@@ -3,7 +3,7 @@
# This is a modified version of autoconf's AC_FUNC_FNMATCH.
# This file should be simplified after Autoconf 2.57 is required.
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
+# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
# Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -61,10 +61,9 @@ AS_IF([test $$2 = yes], [$3], [$4])
# ------------------
# Prepare the replacement of fnmatch.
AC_DEFUN([_AC_LIBOBJ_FNMATCH],
-[AC_REQUIRE([AC_C_CONST])dnl
-AC_REQUIRE([AC_FUNC_ALLOCA])dnl
+[AC_REQUIRE([AC_FUNC_ALLOCA])dnl
AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
-AC_CHECK_DECLS([getenv])
+AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
AC_CHECK_HEADERS([wchar.h wctype.h])
AC_LIBOBJ([fnmatch])
diff --git a/m4/getcwd-abort-bug.m4 b/m4/getcwd-abort-bug.m4
new file mode 100644
index 0000000..a431a7c
--- /dev/null
+++ b/m4/getcwd-abort-bug.m4
@@ -0,0 +1,106 @@
+#serial 1
+# Determine whether getcwd aborts when the length of the working directory
+# name is unusually large. Any length between 4k and 16k trigger the bug
+# when using glibc-2.4.90-9 or older.
+
+# Copyright (C) 2006 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.
+
+# From Jim Meyering
+
+# gl_FUNC_GETCWD_ABORT_BUG([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG],
+[
+ AC_CHECK_DECLS_ONCE(getcwd)
+ AC_CHECK_FUNCS(getpagesize)
+ AC_CACHE_CHECK([whether getcwd aborts when 4k < cwd_length < 16k],
+ gl_cv_func_getcwd_abort_bug,
+ [# Remove any remnants of a previous test.
+ rm -rf confdir-14B---
+ # Arrange for deletion of the temporary directory this test creates.
+ ac_clean_files="$ac_clean_files confdir-14B---"
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE(
+ [[
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <sys/stat.h>
+
+/* Don't get link errors because mkdir is redefined to rpl_mkdir. */
+#undef mkdir
+
+#ifndef S_IRWXU
+# define S_IRWXU 0700
+#endif
+
+/* FIXME: skip the run-test altogether on systems without getpagesize. */
+#if ! HAVE_GETPAGESIZE
+# define getpagesize() 0
+#endif
+
+/* This size is chosen to be larger than PATH_MAX (4k), yet smaller than
+ the 16kB pagesize on ia64 linux. Those conditions make the code below
+ trigger a bug in glibc's getcwd implementation before 2.4.90-10. */
+#define TARGET_LEN (5 * 1024)
+
+int
+main ()
+{
+ char const *dir_name = "confdir-14B---";
+ char *cwd;
+ size_t initial_cwd_len;
+ int fail = 0;
+ size_t desired_depth;
+ size_t d;
+
+ /* The bug is triggered when PATH_MAX < getpagesize (), so skip
+ this relative expensive and invasive test if that's not true. */
+ if (getpagesize () <= PATH_MAX)
+ return 0;
+
+ cwd = getcwd (NULL, 0);
+ if (cwd == NULL)
+ return 0;
+
+ initial_cwd_len = strlen (cwd);
+ free (cwd);
+ desired_depth = ((TARGET_LEN - 1 - initial_cwd_len)
+ / (1 + strlen (dir_name)));
+ for (d = 0; d < desired_depth; d++)
+ {
+ if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0)
+ {
+ fail = 3; /* Unable to construct deep hierarchy. */
+ break;
+ }
+ }
+
+ /* If libc has the bug in question, this invocation of getcwd
+ results in a failed assertion. */
+ cwd = getcwd (NULL, 0);
+ if (cwd == NULL)
+ fail = 4; /* getcwd failed. This is ok, and expected. */
+ free (cwd);
+
+ /* Call rmdir first, in case the above chdir failed. */
+ rmdir (dir_name);
+ while (0 < d--)
+ {
+ if (chdir ("..") < 0)
+ break;
+ rmdir (dir_name);
+ }
+
+ return 0;
+}
+ ]])],
+ [gl_cv_func_getcwd_abort_bug=no],
+ [gl_cv_func_getcwd_abort_bug=yes],
+ [gl_cv_func_getcwd_abort_bug=yes])
+ ])
+ AS_IF([test $gl_cv_func_getcwd_abort_bug = yes], [$1], [$2])
+])
diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4
index 5a6c43a..3d0af87 100644
--- a/m4/getcwd-path-max.m4
+++ b/m4/getcwd-path-max.m4
@@ -1,4 +1,4 @@
-#serial 10
+#serial 12
# Check for several getcwd bugs with long file names.
# If so, arrange to compile the wrapper function.
@@ -6,7 +6,7 @@
# I've heard that this is due to a Linux kernel bug, and that it has
# been fixed between 2.4.21-pre3 and 2.4.21-pre4. */
-# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2006 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.
@@ -61,7 +61,7 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX],
#define BUF_SLOP 20
int
-main (void)
+main ()
{
#ifndef PATH_MAX
/* The Hurd doesn't define this, so getcwd can't exhibit the bug --
@@ -157,8 +157,8 @@ main (void)
{
size_t i;
- /* Unlink first, in case the chdir failed. */
- unlink (DIR_NAME);
+ /* Try rmdir first, in case the chdir failed. */
+ rmdir (DIR_NAME);
for (i = 0; i <= n_chdirs; i++)
{
if (chdir ("..") < 0)
diff --git a/m4/getcwd.m4 b/m4/getcwd.m4
index 35d0b53..2a19a08 100644
--- a/m4/getcwd.m4
+++ b/m4/getcwd.m4
@@ -1,6 +1,6 @@
# getcwd.m4 - check for working getcwd that is compatible with glibc
-# Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2004, 2005, 2006 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.
@@ -40,12 +40,15 @@ AC_DEFUN([gl_FUNC_GETCWD],
[
AC_REQUIRE([gl_FUNC_GETCWD_NULL])
+ gl_abort_bug=no
case $gl_cv_func_getcwd_null in
- yes) gl_FUNC_GETCWD_PATH_MAX;;
+ yes)
+ gl_FUNC_GETCWD_PATH_MAX
+ gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
esac
- case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max in
- yes,yes) ;;
+ case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in
+ yes,yes,no) ;;
*)
AC_LIBOBJ([getcwd])
AC_DEFINE([__GETCWD_PREFIX], [[rpl_]],
@@ -58,7 +61,6 @@ AC_DEFUN([gl_FUNC_GETCWD],
AC_DEFUN([gl_PREREQ_GETCWD],
[
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- AC_REQUIRE([AC_HEADER_DIRENT])
AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
:
])
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index e60b746..c0a73b2 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -1,11 +1,11 @@
-# getopt.m4 serial 12
+# getopt.m4 serial 13
dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 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.
# The getopt module assume you want GNU getopt, with getopt_long etc,
-# rather than vanilla POSIX getopt. This means your your code should
+# rather than vanilla POSIX getopt. This means your code should
# always include <getopt.h> for the getopt prototypes.
AC_DEFUN([gl_GETOPT_SUBSTITUTE],
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 2257882..05a05ef 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -1,4 +1,5 @@
-# Copyright (C) 2004 Free Software Foundation, Inc.
+# Copyright (C) 2004-2006 Free Software Foundation, Inc.
+#
# This file is free software, distributed under the terms of the GNU
# General Public License. As a special exception to the GNU General
# Public License, this file may be distributed as part of a program
@@ -14,13 +15,15 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout dirname error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd
+# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --aux-dir=. --macro-prefix=gl --assume-autoconf=2.59 alloca alloca-opt atexit closeout dirname error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_MODULES([alloca alloca-opt atexit closeout dirname error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd])
gl_AVOID([])
gl_SOURCE_BASE([lib])
gl_M4_BASE([m4])
+gl_DOC_BASE([doc])
gl_TESTS_BASE([tests])
gl_LIB([libgnu])
gl_MACRO_PREFIX([gl])
+gl_AUTOCONF_MINVERSION([2.59])
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 8a04e09..6e7afd6 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -1,4 +1,5 @@
-# Copyright (C) 2004 Free Software Foundation, Inc.
+# Copyright (C) 2004-2006 Free Software Foundation, Inc.
+#
# This file is free software, distributed under the terms of the GNU
# General Public License. As a special exception to the GNU General
# Public License, this file may be distributed as part of a program
@@ -58,16 +59,22 @@ AC_DEFUN([gl_INIT],
AC_FUNC_REALLOC
gl_REGEX
gl_C_RESTRICT
+ gt_TYPE_SSIZE_T
gl_STAT_MACROS
AM_STDBOOL_H
gl_STRCASE
gl_FUNC_STRCSPN
gl_FUNC_STRDUP
+ gl_FUNC_STRNDUP
+ gl_FUNC_STRNLEN
gl_FUNC_STRPBRK
gl_FUNC_STRSEP
gl_FUNC_STRSTR
+ gl_HEADER_UNISTD
+ gl_FUNC_WCWIDTH
gl_XALLOC
gl_XGETCWD
+ gl_XSTRNDUP
])
# This macro records the list of files which have been installed by
@@ -138,6 +145,10 @@ AC_DEFUN([gl_FILE_LIST], [
lib/strdup.h
lib/stripslash.c
lib/strncasecmp.c
+ lib/strndup.c
+ lib/strndup.h
+ lib/strnlen.c
+ lib/strnlen.h
lib/strnlen1.c
lib/strnlen1.h
lib/strpbrk.c
@@ -148,11 +159,14 @@ AC_DEFUN([gl_FILE_LIST], [
lib/strstr.h
lib/umaxtostr.c
lib/verify.h
+ lib/wcwidth.h
lib/xalloc-die.c
lib/xalloc.h
lib/xgetcwd.c
lib/xgetcwd.h
lib/xmalloc.c
+ lib/xstrndup.c
+ lib/xstrndup.h
m4/alloca.m4
m4/atexit.m4
m4/closeout.m4
@@ -160,12 +174,14 @@ AC_DEFUN([gl_FILE_LIST], [
m4/d-ino.m4
m4/dirname.m4
m4/dos.m4
+ m4/double-slash-root.m4
m4/error.m4
m4/exclude.m4
m4/exitfail.m4
m4/extensions.m4
m4/fnmatch.m4
m4/fpending.m4
+ m4/getcwd-abort-bug.m4
m4/getcwd-path-max.m4
m4/getcwd.m4
m4/getopt.m4
@@ -208,6 +224,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/restrict.m4
m4/signed.m4
m4/size_max.m4
+ m4/ssize_t.m4
m4/stat-macros.m4
m4/stdbool.m4
m4/stdint_h.m4
@@ -215,14 +232,19 @@ AC_DEFUN([gl_FILE_LIST], [
m4/strcspn.m4
m4/strdup.m4
m4/strerror_r.m4
+ m4/strndup.m4
+ m4/strnlen.m4
m4/strpbrk.m4
m4/strsep.m4
m4/strstr.m4
m4/uintmax_t.m4
m4/ulonglong.m4
+ m4/unistd_h.m4
m4/wchar_t.m4
+ m4/wcwidth.m4
m4/wint_t.m4
m4/xalloc.m4
m4/xgetcwd.m4
m4/xsize.m4
+ m4/xstrndup.m4
])
diff --git a/m4/longdouble.m4 b/m4/longdouble.m4
index 40cd7ce..25590f4 100644
--- a/m4/longdouble.m4
+++ b/m4/longdouble.m4
@@ -1,5 +1,5 @@
-# longdouble.m4 serial 1 (gettext-0.12)
-dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+# longdouble.m4 serial 2 (gettext-0.15)
+dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -8,6 +8,9 @@ dnl From Bruno Haible.
dnl Test whether the compiler supports the 'long double' type.
dnl Prerequisite: AC_PROG_CC
+dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf
+dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics.
+
AC_DEFUN([gt_TYPE_LONGDOUBLE],
[
AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
diff --git a/m4/longlong.m4 b/m4/longlong.m4
index 7b399e0..ea7c485 100644
--- a/m4/longlong.m4
+++ b/m4/longlong.m4
@@ -1,21 +1,42 @@
-# longlong.m4 serial 5
-dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
+# longlong.m4 serial 6
+dnl Copyright (C) 1999-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Paul Eggert.
-# Define HAVE_LONG_LONG if 'long long' works.
+# Define HAVE_LONG_LONG_INT if 'long long int' works.
+# This fixes a bug in Autoconf 2.60, but can be removed once we
+# assume 2.61 everywhere.
+AC_DEFUN([AC_TYPE_LONG_LONG_INT],
+[
+ AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[long long int ll = 9223372036854775807ll;
+ long long int nll = -9223372036854775807LL;
+ typedef int a[((-9223372036854775807LL < 0
+ && 0 < 9223372036854775807ll)
+ ? 1 : -1)];
+ int i = 63;]],
+ [[long long int llmax = 9223372036854775807ll;
+ return (ll << 63 | ll >> 63 | ll < i | ll > i
+ | llmax / ll | llmax % ll);]])],
+ [ac_cv_type_long_long_int=yes],
+ [ac_cv_type_long_long_int=no])])
+ if test $ac_cv_type_long_long_int = yes; then
+ AC_DEFINE([HAVE_LONG_LONG_INT], 1,
+ [Define to 1 if the system has the type `long long int'.])
+ fi
+])
+
+# This macro is obsolescent and should go away soon.
AC_DEFUN([gl_AC_TYPE_LONG_LONG],
[
- AC_CACHE_CHECK([for long long], ac_cv_type_long_long,
- [AC_TRY_LINK([long long ll = 1LL; int i = 63;],
- [long long llmax = (long long) -1;
- return ll << i | ll >> i | llmax / ll | llmax % ll;],
- ac_cv_type_long_long=yes,
- ac_cv_type_long_long=no)])
+ AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
+ ac_cv_type_long_long=$ac_cv_type_long_long_int
if test $ac_cv_type_long_long = yes; then
AC_DEFINE(HAVE_LONG_LONG, 1,
[Define if you have the 'long long' type.])
diff --git a/m4/onceonly_2_57.m4 b/m4/onceonly_2_57.m4
index 14d3c0b..15884b3 100644
--- a/m4/onceonly_2_57.m4
+++ b/m4/onceonly_2_57.m4
@@ -1,5 +1,5 @@
-# onceonly_2_57.m4 serial 3
-dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
+# onceonly_2_57.m4 serial 4
+dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
@@ -7,10 +7,10 @@ dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl This file defines some "once only" variants of standard autoconf macros.
-dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
-dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
-dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
-dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC
+dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
+dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
+dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
+dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL
dnl The advantage is that the check for each of the headers/functions/decls
dnl will be put only once into the 'configure' file. It keeps the size of
dnl the 'configure' file down, and avoids redundant output when 'configure'
diff --git a/m4/regex.m4 b/m4/regex.m4
index 8ea4fe9..cd71366 100644
--- a/m4/regex.m4
+++ b/m4/regex.m4
@@ -1,7 +1,7 @@
-#serial 31
+#serial 37
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
-# Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+# 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -14,31 +14,6 @@ AC_PREREQ([2.50])
AC_DEFUN([gl_REGEX],
[
- AC_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t
-
- AC_CACHE_CHECK([whether off_t can be used in a switch statement],
- [gl_cv_type_off_t_switch],
- [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [AC_INCLUDES_DEFAULT],
- [[off_t o = -1;
- switch (o)
- {
- case -2:
- return 1;
- case -1:
- return 2;
- default:
- return 0;
- }
- ]])],
- [gl_cv_type_off_t_switch=yes],
- [gl_cv_type_off_t_switch=no])])
- if test $gl_cv_type_off_t_switch = yes; then
- AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
- [Define if you want regoff_t to be at least as wide POSIX requires.])
- fi
-
AC_LIBSOURCES(
[regcomp.c, regex.c, regex.h,
regex_internal.c, regex_internal.h, regexec.c])
@@ -49,30 +24,34 @@ AC_DEFUN([gl_REGEX],
systems with recent-enough versions of the GNU C
Library (use with caution on other systems)])])
- case $with_included_regex in
+ case $with_included_regex in #(
yes|no) ac_use_included_regex=$with_included_regex
;;
'')
- # If the system regex support is good enough that it passes the the
+ # If the system regex support is good enough that it passes the
# following run test, then default to *not* using the included regex.c.
# If cross compiling, assume the test would fail and use the included
# regex.c. The first failing regular expression is from `Spencer ere
# test #75' in grep-2.3.
AC_CACHE_CHECK([for working re_compile_pattern],
- [gl_cv_func_re_compile_pattern_broken],
+ [gl_cv_func_re_compile_pattern_working],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT
- #include <regex.h>],
+ #include <limits.h>
+ #include <regex.h>
+ ],
[[static struct re_pattern_buffer regex;
+ unsigned char folded_chars[UCHAR_MAX + 1];
+ int i;
const char *s;
struct re_registers regs;
- /* Use the POSIX-compliant spelling with leading REG_,
- rather than the traditional GNU spelling with leading RE_,
- so that we reject older libc implementations. */
- re_set_syntax (REG_SYNTAX_POSIX_EGREP);
+ re_set_syntax (RE_SYNTAX_POSIX_EGREP);
memset (&regex, 0, sizeof (regex));
- s = re_compile_pattern ("a[:@:>@:]b\n", 9, &regex);
+ for (i = 0; i <= UCHAR_MAX; i++)
+ folded_chars[i] = i;
+ regex.translate = folded_chars;
+ s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
/* This should fail with _Invalid character class name_ error. */
if (!s)
exit (1);
@@ -106,10 +85,9 @@ AC_DEFUN([gl_REGEX],
exit (1);
/* The version of regex.c in older versions of gnulib
- ignored REG_IGNORE_CASE (which was then called RE_ICASE).
- Detect that problem too. */
+ ignored RE_ICASE. Detect that problem too. */
memset (&regex, 0, sizeof (regex));
- re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE);
+ re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
s = re_compile_pattern ("x", 1, &regex);
if (s)
exit (1);
@@ -123,24 +101,29 @@ AC_DEFUN([gl_REGEX],
exit (1);
/* Reject hosts whose regoff_t values are too narrow.
- These include glibc 2.3.5 on hosts with 64-bit off_t
- and 32-bit int, and Solaris 10 on hosts with 32-bit int
- and _FILE_OFFSET_BITS=64. */
- if (sizeof (regoff_t) < sizeof (off_t))
+ These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
+ and 32-bit int. */
+ if (sizeof (regoff_t) < sizeof (ptrdiff_t)
+ || sizeof (regoff_t) < sizeof (ssize_t))
exit (1);
exit (0);]])],
- [gl_cv_func_re_compile_pattern_broken=no],
- [gl_cv_func_re_compile_pattern_broken=yes],
- dnl When crosscompiling, assume it is broken.
- [gl_cv_func_re_compile_pattern_broken=yes])])
- ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken
+ [gl_cv_func_re_compile_pattern_working=yes],
+ [gl_cv_func_re_compile_pattern_working=no],
+ dnl When crosscompiling, assume it is not working.
+ [gl_cv_func_re_compile_pattern_working=no])])
+ case $gl_cv_func_re_compile_pattern_working in #(
+ yes) ac_use_included_regex=no;; #(
+ no) ac_use_included_regex=yes;;
+ esac
;;
*) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
;;
esac
if test $ac_use_included_regex = yes; then
+ AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
+ [Define if you want regoff_t to be at least as wide POSIX requires.])
AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
[Define to rpl_re_syntax_options if the replacement should be used.])
AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
@@ -183,5 +166,6 @@ AC_DEFUN([gl_PREREQ_REGEX],
AC_REQUIRE([gl_C_RESTRICT])
AC_REQUIRE([AM_LANGINFO_CODESET])
AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
- AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])
+ AC_CHECK_FUNCS_ONCE([mbrtowc mempcpy wcrtomb wcscoll])
+ AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
])
diff --git a/m4/size_max.m4 b/m4/size_max.m4
index 0336f3a..029e471 100644
--- a/m4/size_max.m4
+++ b/m4/size_max.m4
@@ -1,5 +1,5 @@
-# size_max.m4 serial 3
-dnl Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+# size_max.m4 serial 4
+dnl Copyright (C) 2003, 2005-2006 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.
@@ -23,28 +23,29 @@ Found it
], result=yes)
if test -z "$result"; then
dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
- dnl than the type 'unsigned long'.
- dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
- dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
- _AC_COMPUTE_INT([(size_t)~(size_t)0 / 10], res_hi,
- [#include <stddef.h>], result=?)
- _AC_COMPUTE_INT([(size_t)~(size_t)0 % 10], res_lo,
- [#include <stddef.h>], result=?)
+ dnl than the type 'unsigned long'. Try hard to find a definition that can
+ dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
+ _AC_COMPUTE_INT([sizeof (size_t) * CHAR_BIT - 1], size_t_bits_minus_1,
+ [#include <stddef.h>
+#include <limits.h>], size_t_bits_minus_1=)
_AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
- [#include <stddef.h>], result=?)
- if test "$fits_in_uint" = 1; then
- dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
- dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
- AC_TRY_COMPILE([#include <stddef.h>
- extern size_t foo;
- extern unsigned long foo;
- ], [], fits_in_uint=0)
- fi
- if test -z "$result"; then
- if test "$fits_in_uint" = 1; then
- result="$res_hi$res_lo"U
+ [#include <stddef.h>], fits_in_uint=)
+ if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
+ if test $fits_in_uint = 1; then
+ dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
+ dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
+ AC_TRY_COMPILE([#include <stddef.h>
+ extern size_t foo;
+ extern unsigned long foo;
+ ], [], fits_in_uint=0)
+ fi
+ dnl We cannot use 'expr' to simplify this expression, because 'expr'
+ dnl works only with 'long' integers in the host environment, while we
+ dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
+ if test $fits_in_uint = 1; then
+ result="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
else
- result="$res_hi$res_lo"UL
+ result="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
fi
else
dnl Shouldn't happen, but who knows...
diff --git a/m4/ssize_t.m4 b/m4/ssize_t.m4
new file mode 100644
index 0000000..4eaef93
--- /dev/null
+++ b/m4/ssize_t.m4
@@ -0,0 +1,21 @@
+# ssize_t.m4 serial 4 (gettext-0.15)
+dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+dnl Test whether ssize_t is defined.
+
+AC_DEFUN([gt_TYPE_SSIZE_T],
+[
+ AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
+ [AC_TRY_COMPILE([#include <sys/types.h>],
+ [int x = sizeof (ssize_t *) + sizeof (ssize_t);
+ return !x;],
+ [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
+ if test $gt_cv_ssize_t = no; then
+ AC_DEFINE([ssize_t], [int],
+ [Define as a signed type of the same size as size_t.])
+ fi
+])
diff --git a/m4/stdbool.m4 b/m4/stdbool.m4
index 43fbe28..2204ecd 100644
--- a/m4/stdbool.m4
+++ b/m4/stdbool.m4
@@ -64,9 +64,9 @@ AC_DEFUN([AC_HEADER_STDBOOL],
char a[true == 1 ? 1 : -1];
char b[false == 0 ? 1 : -1];
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
- char d[(bool) -0.5 == true ? 1 : -1];
+ char d[(bool) 0.5 == true ? 1 : -1];
bool e = &s;
- char f[(_Bool) -0.0 == false ? 1 : -1];
+ char f[(_Bool) 0.0 == false ? 1 : -1];
char g[true];
char h[sizeof (_Bool)];
char i[sizeof s.t];
diff --git a/m4/strerror_r.m4 b/m4/strerror_r.m4
index 28924b1..e3b5d0c 100644
--- a/m4/strerror_r.m4
+++ b/m4/strerror_r.m4
@@ -25,6 +25,7 @@ AC_CACHE_CHECK([whether strerror_r returns char *],
char buf[100];
char x = *strerror_r (0, buf, sizeof buf);
char *p = strerror_r (0, buf, sizeof buf);
+ return !p || x;
]])],
ac_cv_func_strerror_r_char_p=yes)
else
diff --git a/m4/strndup.m4 b/m4/strndup.m4
new file mode 100644
index 0000000..e333f5c
--- /dev/null
+++ b/m4/strndup.m4
@@ -0,0 +1,51 @@
+# strndup.m4 serial 7
+dnl Copyright (C) 2002-2003, 2005-2006 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_STRNDUP],
+[
+ AC_LIBSOURCES([strndup.c, strndup.h])
+
+ dnl Persuade glibc <string.h> to declare strndup().
+ AC_REQUIRE([AC_GNU_SOURCE])
+
+ AC_CHECK_DECLS_ONCE([strndup])
+
+ # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
+ AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup,
+ [AC_RUN_IFELSE([
+ AC_LANG_PROGRAM([#include <string.h>], [[
+#ifndef HAVE_DECL_STRNDUP
+ extern char *strndup (const char *, size_t);
+#endif
+ char *s;
+ s = strndup ("some longer string", 15);
+ free (s);
+ s = strndup ("shorter string", 13);
+ return s[13] != '\0';]])],
+ [gl_cv_func_strndup=yes],
+ [gl_cv_func_strndup=no],
+ [AC_CHECK_FUNC([strndup],
+ [AC_EGREP_CPP([too risky], [
+#ifdef _AIX
+ too risky
+#endif
+ ],
+ [gl_cv_func_strndup=no],
+ [gl_cv_func_strndup=yes])],
+ [gl_cv_func_strndup=no])])])
+ if test $gl_cv_func_strndup = yes; then
+ AC_DEFINE([HAVE_STRNDUP], 1,
+ [Define if you have the strndup() function and it works.])
+ else
+ AC_LIBOBJ([strndup])
+ AC_DEFINE(strndup, rpl_strndup,
+ [Define to rpl_strndup if the replacement function should be used,])
+ gl_PREREQ_STRNDUP
+ fi
+])
+
+# Prerequisites of lib/strndup.c.
+AC_DEFUN([gl_PREREQ_STRNDUP], [:])
diff --git a/m4/strnlen.m4 b/m4/strnlen.m4
new file mode 100644
index 0000000..67964c8
--- /dev/null
+++ b/m4/strnlen.m4
@@ -0,0 +1,29 @@
+# strnlen.m4 serial 5
+dnl Copyright (C) 2002-2003, 2005 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_STRNLEN],
+[
+ AC_LIBSOURCES([strnlen.c, strnlen.h])
+
+ dnl Persuade glibc <string.h> to declare strnlen().
+ AC_REQUIRE([AC_GNU_SOURCE])
+
+ AC_FUNC_STRNLEN
+ if test $ac_cv_func_strnlen_working = no; then
+ # This is necessary because automake-1.6.1 doens't understand
+ # that the above use of AC_FUNC_STRNLEN means we may have to use
+ # lib/strnlen.c.
+ #AC_LIBOBJ(strnlen)
+ AC_DEFINE(strnlen, rpl_strnlen,
+ [Define to rpl_strnlen if the replacement function should be used.])
+ gl_PREREQ_STRNLEN
+ fi
+])
+
+# Prerequisites of lib/strnlen.c.
+AC_DEFUN([gl_PREREQ_STRNLEN], [
+ AC_CHECK_DECLS_ONCE(strnlen)
+])
diff --git a/m4/ulonglong.m4 b/m4/ulonglong.m4
index dee10cc..15fab9f 100644
--- a/m4/ulonglong.m4
+++ b/m4/ulonglong.m4
@@ -1,21 +1,41 @@
-# ulonglong.m4 serial 4
-dnl Copyright (C) 1999-2004 Free Software Foundation, Inc.
+# ulonglong.m4 serial 5
+dnl Copyright (C) 1999-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Paul Eggert.
-# Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works.
+# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
+# This fixes a bug in Autoconf 2.60, but can be removed once we
+# assume 2.61 everywhere.
+AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
+[
+ AC_CACHE_CHECK([for unsigned long long int],
+ [ac_cv_type_unsigned_long_long_int],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[unsigned long long int ull = 18446744073709551615ULL;
+ typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1
+ ? 1 : -1)];
+ int i = 63;]],
+ [[unsigned long long int ullmax = 18446744073709551615ull;
+ return (ull << 63 | ull >> 63 | ull << i | ull >> i
+ | ullmax / ull | ullmax % ull);]])],
+ [ac_cv_type_unsigned_long_long_int=yes],
+ [ac_cv_type_unsigned_long_long_int=no])])
+ if test $ac_cv_type_unsigned_long_long_int = yes; then
+ AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
+ [Define to 1 if the system has the type `unsigned long long int'.])
+ fi
+])
+
+# This macro is obsolescent and should go away soon.
AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG],
[
- AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long,
- [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;],
- [unsigned long long ullmax = (unsigned long long) -1;
- return ull << i | ull >> i | ullmax / ull | ullmax % ull;],
- ac_cv_type_unsigned_long_long=yes,
- ac_cv_type_unsigned_long_long=no)])
+ AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
+ ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int
if test $ac_cv_type_unsigned_long_long = yes; then
AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1,
[Define if you have the 'unsigned long long' type.])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
new file mode 100644
index 0000000..9c77f9b
--- /dev/null
+++ b/m4/unistd_h.m4
@@ -0,0 +1,18 @@
+# unistd_h.m4 serial 2
+dnl Copyright (C) 2006 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 Simon Josefsson
+
+AC_DEFUN([gl_HEADER_UNISTD],
+[
+ dnl Prerequisites of lib/unistd.h.
+ AC_CHECK_HEADERS([unistd.h], [
+ UNISTD_H=''
+ ], [
+ UNISTD_H='unistd.h'
+ ])
+ AC_SUBST(UNISTD_H)
+])
diff --git a/m4/wcwidth.m4 b/m4/wcwidth.m4
new file mode 100644
index 0000000..09cf55a
--- /dev/null
+++ b/m4/wcwidth.m4
@@ -0,0 +1,26 @@
+# wcwidth.m4 serial 3
+dnl Copyright (C) 2006 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_WCWIDTH],
+[
+ dnl Persuade glibc <wchar.h> to declare wcwidth().
+ AC_REQUIRE([AC_GNU_SOURCE])
+
+ AC_REQUIRE([AC_C_INLINE])
+ AC_REQUIRE([gt_TYPE_WCHAR_T])
+
+ AC_CHECK_HEADERS_ONCE([wchar.h wctype.h])
+ AC_CHECK_FUNCS_ONCE([iswprint wcwidth])
+
+ AC_CHECK_DECLS([wcwidth], [], [], [
+/* AIX 3.2.5 declares wcwidth in <string.h>. */
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+])])
diff --git a/m4/xstrndup.m4 b/m4/xstrndup.m4
new file mode 100644
index 0000000..8a30ab1
--- /dev/null
+++ b/m4/xstrndup.m4
@@ -0,0 +1,15 @@
+# xstrndup.m4 serial 2
+dnl Copyright (C) 2003 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_XSTRNDUP],
+[
+ gl_PREREQ_XSTRNDUP
+])
+
+# Prerequisites of lib/xstrndup.c.
+AC_DEFUN([gl_PREREQ_XSTRNDUP], [
+ :
+])