diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rwxr-xr-x | config.rpath | 513 | ||||
-rw-r--r-- | configure.in | 195 | ||||
-rw-r--r-- | doc/developer-guidelines.sgml | 2 | ||||
-rw-r--r-- | gl/Makefile.am | 607 | ||||
-rw-r--r-- | gl/alloca.c (renamed from lib/alloca.c) | 4 | ||||
-rw-r--r-- | gl/alloca_.h (renamed from lib/alloca_.h) | 26 | ||||
-rw-r--r-- | gl/asnprintf.c | 35 | ||||
-rw-r--r-- | gl/asprintf.c | 35 | ||||
-rw-r--r-- | gl/basename.c | 129 | ||||
-rw-r--r-- | gl/c-strtod.c (renamed from lib/c-strtod.c) | 6 | ||||
-rw-r--r-- | gl/c-strtod.h (renamed from lib/c-strtod.h) | 0 | ||||
-rw-r--r-- | gl/cloexec.c (renamed from lib/cloexec.c) | 7 | ||||
-rw-r--r-- | gl/cloexec.h (renamed from lib/cloexec.h) | 0 | ||||
-rw-r--r-- | gl/creat-safer.c (renamed from lib/creat-safer.c) | 7 | ||||
-rw-r--r-- | gl/dirname.c | 85 | ||||
-rw-r--r-- | gl/dirname.h (renamed from lib/dirname.h) | 29 | ||||
-rw-r--r-- | gl/dup-safer.c (renamed from lib/dup-safer.c) | 9 | ||||
-rw-r--r-- | gl/error.c (renamed from lib/error.c) | 134 | ||||
-rw-r--r-- | gl/error.h (renamed from lib/error.h) | 4 | ||||
-rw-r--r-- | gl/exit.h (renamed from lib/exit.h) | 2 | ||||
-rw-r--r-- | gl/exitfail.c (renamed from lib/exitfail.c) | 6 | ||||
-rw-r--r-- | gl/exitfail.h (renamed from lib/exitfail.h) | 0 | ||||
-rw-r--r-- | gl/fcntl--.h (renamed from lib/fcntl--.h) | 0 | ||||
-rw-r--r-- | gl/fcntl-safer.h (renamed from lib/fcntl-safer.h) | 0 | ||||
-rw-r--r-- | gl/fd-safer.c (renamed from lib/fd-safer.c) | 6 | ||||
-rw-r--r-- | gl/fsusage.c (renamed from lib/fsusage.c) | 147 | ||||
-rw-r--r-- | gl/fsusage.h (renamed from lib/fsusage.h) | 3 | ||||
-rw-r--r-- | gl/full-read.c (renamed from lib/full-read.c) | 0 | ||||
-rw-r--r-- | gl/full-read.h (renamed from lib/full-read.h) | 0 | ||||
-rw-r--r-- | gl/full-write.c (renamed from lib/full-write.c) | 8 | ||||
-rw-r--r-- | gl/full-write.h (renamed from lib/full-write.h) | 0 | ||||
-rw-r--r-- | gl/gai_strerror.c | 77 | ||||
-rw-r--r-- | gl/getaddrinfo.c | 417 | ||||
-rw-r--r-- | gl/getaddrinfo.h | 155 | ||||
-rw-r--r-- | gl/gethostname.c | 52 | ||||
-rw-r--r-- | gl/getloadavg.c (renamed from lib/getloadavg.c) | 31 | ||||
-rw-r--r-- | gl/getopt.c (renamed from lib/getopt.c) | 86 | ||||
-rw-r--r-- | gl/getopt1.c (renamed from lib/getopt1.c) | 7 | ||||
-rw-r--r-- | gl/getopt_.h (renamed from lib/getopt_.h) | 9 | ||||
-rw-r--r-- | gl/getopt_int.h (renamed from lib/getopt_int.h) | 0 | ||||
-rw-r--r-- | gl/gettext.h | 270 | ||||
-rw-r--r-- | gl/inet_ntop.c | 238 | ||||
-rw-r--r-- | gl/inet_ntop.h | 42 | ||||
-rw-r--r-- | gl/intprops.h (renamed from lib/intprops.h) | 17 | ||||
-rw-r--r-- | gl/m4/absolute-header.m4 | 44 | ||||
-rw-r--r-- | gl/m4/alloca.m4 (renamed from m4/alloca.m4) | 28 | ||||
-rw-r--r-- | gl/m4/arpa_inet_h.m4 | 18 | ||||
-rw-r--r-- | gl/m4/c-strtod.m4 (renamed from m4/c-strtod.m4) | 10 | ||||
-rw-r--r-- | gl/m4/cloexec.m4 | 10 | ||||
-rw-r--r-- | gl/m4/codeset.m4 (renamed from m4/codeset.m4) | 6 | ||||
-rw-r--r-- | gl/m4/dirname.m4 | 18 | ||||
-rw-r--r-- | gl/m4/dos.m4 (renamed from m4/dos.m4) | 41 | ||||
-rw-r--r-- | gl/m4/double-slash-root.m4 | 38 | ||||
-rw-r--r-- | gl/m4/eoverflow.m4 | 70 | ||||
-rw-r--r-- | gl/m4/error.m4 (renamed from m4/error.m4) | 0 | ||||
-rw-r--r-- | gl/m4/exitfail.m4 (renamed from m4/exitfail.m4) | 5 | ||||
-rw-r--r-- | gl/m4/extensions.m4 | 58 | ||||
-rw-r--r-- | gl/m4/fcntl-safer.m4 (renamed from m4/fcntl-safer.m4) | 5 | ||||
-rw-r--r-- | gl/m4/fstypename.m4 | 22 | ||||
-rw-r--r-- | gl/m4/fsusage.m4 (renamed from m4/fsusage.m4) | 33 | ||||
-rw-r--r-- | gl/m4/getaddrinfo.m4 | 88 | ||||
-rw-r--r-- | gl/m4/gethostname.m4 | 18 | ||||
-rw-r--r-- | gl/m4/getloadavg.m4 | 155 | ||||
-rw-r--r-- | gl/m4/getopt.m4 (renamed from m4/getopt.m4) | 11 | ||||
-rw-r--r-- | gl/m4/gettext.m4 (renamed from m4/gettext.m4) | 280 | ||||
-rw-r--r-- | gl/m4/glibc2.m4 | 30 | ||||
-rw-r--r-- | gl/m4/glibc21.m4 (renamed from m4/glibc21.m4) | 0 | ||||
-rw-r--r-- | gl/m4/gnulib-cache.m4 | 30 | ||||
-rw-r--r-- | gl/m4/gnulib-common.m4 | 22 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 326 | ||||
-rw-r--r-- | gl/m4/gnulib-tool.m4 | 33 | ||||
-rw-r--r-- | gl/m4/iconv.m4 (renamed from m4/iconv.m4) | 0 | ||||
-rw-r--r-- | gl/m4/inet_ntop.m4 | 19 | ||||
-rw-r--r-- | gl/m4/inline.m4 | 40 | ||||
-rw-r--r-- | gl/m4/intdiv0.m4 | 70 | ||||
-rw-r--r-- | gl/m4/intl.m4 | 259 | ||||
-rw-r--r-- | gl/m4/intldir.m4 | 19 | ||||
-rw-r--r-- | gl/m4/intmax.m4 | 33 | ||||
-rw-r--r-- | gl/m4/intmax_t.m4 | 61 | ||||
-rw-r--r-- | gl/m4/inttypes-pri.m4 (renamed from m4/inttypes-pri.m4) | 14 | ||||
-rw-r--r-- | gl/m4/inttypes_h.m4 (renamed from m4/inttypes_h.m4) | 6 | ||||
-rw-r--r-- | gl/m4/lcmessage.m4 | 30 | ||||
-rw-r--r-- | gl/m4/lib-ld.m4 (renamed from m4/lib-ld.m4) | 0 | ||||
-rw-r--r-- | gl/m4/lib-link.m4 (renamed from m4/lib-link.m4) | 247 | ||||
-rw-r--r-- | gl/m4/lib-prefix.m4 (renamed from m4/lib-prefix.m4) | 0 | ||||
-rw-r--r-- | gl/m4/lock.m4 | 311 | ||||
-rw-r--r-- | gl/m4/longdouble.m4 (renamed from m4/longdouble.m4) | 7 | ||||
-rw-r--r-- | gl/m4/longlong.m4 | 72 | ||||
-rw-r--r-- | gl/m4/ls-mntd-fs.m4 (renamed from m4/ls-mntd-fs.m4) | 45 | ||||
-rw-r--r-- | gl/m4/mbchar.m4 | 14 | ||||
-rw-r--r-- | gl/m4/mbiter.m4 | 17 | ||||
-rw-r--r-- | gl/m4/mbrtowc.m4 | 31 | ||||
-rw-r--r-- | gl/m4/memchr.m4 | 18 | ||||
-rw-r--r-- | gl/m4/minmax.m4 | 41 | ||||
-rw-r--r-- | gl/m4/mountlist.m4 (renamed from m4/mountlist.m4) | 6 | ||||
-rw-r--r-- | gl/m4/netinet_in_h.m4 | 18 | ||||
-rw-r--r-- | gl/m4/nls.m4 (renamed from m4/nls.m4) | 24 | ||||
-rw-r--r-- | gl/m4/onceonly_2_57.m4 (renamed from m4/onceonly_2_57.m4) | 12 | ||||
-rw-r--r-- | gl/m4/po.m4 (renamed from m4/po.m4) | 83 | ||||
-rw-r--r-- | gl/m4/printf-posix.m4 | 44 | ||||
-rw-r--r-- | gl/m4/progtest.m4 (renamed from m4/progtest.m4) | 0 | ||||
-rw-r--r-- | gl/m4/regex.m4 (renamed from m4/regex.m4) | 121 | ||||
-rw-r--r-- | gl/m4/safe-read.m4 | 18 | ||||
-rw-r--r-- | gl/m4/safe-write.m4 | 18 | ||||
-rw-r--r-- | gl/m4/size_max.m4 | 68 | ||||
-rw-r--r-- | gl/m4/snprintf.m4 | 15 | ||||
-rw-r--r-- | gl/m4/socklen.m4 | 52 | ||||
-rw-r--r-- | gl/m4/sockpfaf.m4 | 58 | ||||
-rw-r--r-- | gl/m4/ssize_t.m4 | 21 | ||||
-rw-r--r-- | gl/m4/stdbool.m4 (renamed from m4/stdbool.m4) | 19 | ||||
-rw-r--r-- | gl/m4/stdint.m4 | 369 | ||||
-rw-r--r-- | gl/m4/stdint_h.m4 (renamed from m4/stdint_h.m4) | 6 | ||||
-rw-r--r-- | gl/m4/strcase.m4 | 39 | ||||
-rw-r--r-- | gl/m4/strdup.m4 | 15 | ||||
-rw-r--r-- | gl/m4/strndup.m4 | 48 | ||||
-rw-r--r-- | gl/m4/strnlen.m4 | 27 | ||||
-rw-r--r-- | gl/m4/sys_socket_h.m4 | 23 | ||||
-rw-r--r-- | gl/m4/uintmax_t.m4 (renamed from m4/uintmax_t.m4) | 0 | ||||
-rw-r--r-- | gl/m4/ulonglong.m4 | 48 | ||||
-rw-r--r-- | gl/m4/unistd-safer.m4 (renamed from m4/unistd-safer.m4) | 6 | ||||
-rw-r--r-- | gl/m4/unistd_h.m4 | 32 | ||||
-rw-r--r-- | gl/m4/vasnprintf.m4 | 57 | ||||
-rw-r--r-- | gl/m4/vasprintf.m4 | 33 | ||||
-rw-r--r-- | gl/m4/visibility.m4 | 52 | ||||
-rw-r--r-- | gl/m4/vsnprintf.m4 | 15 | ||||
-rw-r--r-- | gl/m4/wchar.m4 | 29 | ||||
-rw-r--r-- | gl/m4/wchar_t.m4 (renamed from m4/wchar_t.m4) | 0 | ||||
-rw-r--r-- | gl/m4/wctype.m4 | 41 | ||||
-rw-r--r-- | gl/m4/wcwidth.m4 | 30 | ||||
-rw-r--r-- | gl/m4/wint_t.m4 (renamed from m4/wint_t.m4) | 14 | ||||
-rw-r--r-- | gl/m4/xalloc.m4 (renamed from m4/xalloc.m4) | 7 | ||||
-rw-r--r-- | gl/m4/xsize.m4 | 13 | ||||
-rw-r--r-- | gl/m4/xstrndup.m4 | 15 | ||||
-rw-r--r-- | gl/malloc.c (renamed from lib/malloc.c) | 7 | ||||
-rw-r--r-- | gl/mbchar.c (renamed from lib/xstrdup.c) | 29 | ||||
-rw-r--r-- | gl/mbchar.h | 353 | ||||
-rw-r--r-- | gl/mbuiter.h | 203 | ||||
-rw-r--r-- | gl/memchr.c | 201 | ||||
-rw-r--r-- | gl/minmax.h | 60 | ||||
-rw-r--r-- | gl/mountlist.c (renamed from lib/mountlist.c) | 119 | ||||
-rw-r--r-- | gl/mountlist.h (renamed from lib/mountlist.h) | 0 | ||||
-rw-r--r-- | gl/open-safer.c (renamed from lib/open-safer.c) | 7 | ||||
-rw-r--r-- | gl/pipe-safer.c (renamed from lib/pipe-safer.c) | 49 | ||||
-rw-r--r-- | gl/printf-args.c | 141 | ||||
-rw-r--r-- | gl/printf-args.h | 136 | ||||
-rw-r--r-- | gl/printf-parse.c | 543 | ||||
-rw-r--r-- | gl/printf-parse.h | 74 | ||||
-rw-r--r-- | gl/regcomp.c (renamed from lib/regcomp.c) | 643 | ||||
-rw-r--r-- | gl/regex.c (renamed from lib/regex.c) | 9 | ||||
-rw-r--r-- | gl/regex.h (renamed from lib/regex.h) | 532 | ||||
-rw-r--r-- | gl/regex_internal.c (renamed from lib/regex_internal.c) | 412 | ||||
-rw-r--r-- | gl/regex_internal.h (renamed from lib/regex_internal.h) | 215 | ||||
-rw-r--r-- | gl/regexec.c (renamed from lib/regexec.c) | 671 | ||||
-rw-r--r-- | gl/safe-read.c (renamed from lib/safe-read.c) | 8 | ||||
-rw-r--r-- | gl/safe-read.h (renamed from lib/safe-read.h) | 12 | ||||
-rw-r--r-- | gl/safe-write.c (renamed from lib/safe-write.c) | 0 | ||||
-rw-r--r-- | gl/safe-write.h (renamed from lib/safe-write.h) | 0 | ||||
-rw-r--r-- | gl/size_max.h | 31 | ||||
-rw-r--r-- | gl/snprintf.c | 76 | ||||
-rw-r--r-- | gl/snprintf.h | 29 | ||||
-rw-r--r-- | gl/socket_.h | 70 | ||||
-rw-r--r-- | gl/stdbool_.h (renamed from lib/stdbool_.h) | 70 | ||||
-rw-r--r-- | gl/stdint_.h | 489 | ||||
-rw-r--r-- | gl/strcase.h (renamed from lib/strcase.h) | 12 | ||||
-rw-r--r-- | gl/strcasecmp.c | 103 | ||||
-rw-r--r-- | gl/strdup.c | 55 | ||||
-rw-r--r-- | gl/strdup.h | 39 | ||||
-rw-r--r-- | gl/stripslash.c | 45 | ||||
-rw-r--r-- | gl/strncasecmp.c | 63 | ||||
-rw-r--r-- | gl/strndup.c | 39 | ||||
-rw-r--r-- | gl/strndup.h | 32 | ||||
-rw-r--r-- | gl/strnlen.c | 31 | ||||
-rw-r--r-- | gl/strnlen.h | 32 | ||||
-rw-r--r-- | gl/strnlen1.c | 36 | ||||
-rw-r--r-- | gl/strnlen1.h | 40 | ||||
-rw-r--r-- | gl/unistd--.h (renamed from lib/unistd--.h) | 0 | ||||
-rw-r--r-- | gl/unistd-safer.h (renamed from lib/unistd-safer.h) | 0 | ||||
-rw-r--r-- | gl/unistd_.h | 52 | ||||
-rw-r--r-- | gl/vasnprintf.c | 889 | ||||
-rw-r--r-- | gl/vasnprintf.h | 77 | ||||
-rw-r--r-- | gl/vasprintf.c | 52 | ||||
-rw-r--r-- | gl/vasprintf.h | 63 | ||||
-rw-r--r-- | gl/vsnprintf.c | 77 | ||||
-rw-r--r-- | gl/vsnprintf.h | 31 | ||||
-rw-r--r-- | gl/wchar_.h | 42 | ||||
-rw-r--r-- | gl/wctype_.h | 154 | ||||
-rw-r--r-- | gl/wcwidth.h | 57 | ||||
-rw-r--r-- | gl/xalloc-die.c (renamed from lib/xalloc-die.c) | 7 | ||||
-rw-r--r-- | gl/xalloc.h | 267 | ||||
-rw-r--r-- | gl/xmalloc.c | 123 | ||||
-rw-r--r-- | gl/xsize.h | 108 | ||||
-rw-r--r-- | gl/xstrndup.c | 37 | ||||
-rw-r--r-- | gl/xstrndup.h | 24 | ||||
-rw-r--r-- | lib/Makefile.am | 79 | ||||
-rw-r--r-- | lib/basename.c | 79 | ||||
-rw-r--r-- | lib/c-strtold.c | 2 | ||||
-rw-r--r-- | lib/gettext.h | 78 | ||||
-rw-r--r-- | lib/realloc.c | 46 | ||||
-rw-r--r-- | lib/snprintf.c | 1023 | ||||
-rw-r--r-- | lib/strtod.c | 189 | ||||
-rw-r--r-- | lib/tests/Makefile.am | 2 | ||||
-rw-r--r-- | lib/unlocked-io.h | 137 | ||||
-rw-r--r-- | lib/xalloc.h | 79 | ||||
-rw-r--r-- | lib/xmalloc.c | 241 | ||||
-rw-r--r-- | m4/Makefile.am.in | 15 | ||||
-rw-r--r-- | m4/afs.m4 | 17 | ||||
-rw-r--r-- | m4/basename.m4 | 14 | ||||
-rw-r--r-- | m4/extensions.m4 | 30 | ||||
-rw-r--r-- | m4/fstypename.m4 | 37 | ||||
-rw-r--r-- | m4/inttypes.m4 | 25 | ||||
-rw-r--r-- | m4/longlong.m4 | 23 | ||||
-rw-r--r-- | m4/np_coreutils.m4 | 29 | ||||
-rw-r--r-- | m4/np_curl.m4 | 60 | ||||
-rw-r--r-- | m4/restrict.m4 | 38 | ||||
-rw-r--r-- | m4/signed.m4 | 17 | ||||
-rw-r--r-- | m4/ulonglong.m4 | 23 | ||||
-rw-r--r-- | m4/unlocked-io.m4 | 36 | ||||
-rw-r--r-- | plugins-root/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/check_smtp.c | 7 | ||||
-rw-r--r-- | plugins/common.h | 31 | ||||
-rw-r--r-- | plugins/getaddrinfo.c | 305 | ||||
-rw-r--r-- | plugins/getaddrinfo.h | 71 | ||||
-rw-r--r-- | plugins/gethostbyname.c | 241 | ||||
-rw-r--r-- | plugins/gethostbyname.h | 115 | ||||
-rw-r--r-- | plugins/netutils.h | 1 | ||||
-rwxr-xr-x | tools/setup | 6 | ||||
-rwxr-xr-x | tools/update_coreutils | 31 |
230 files changed, 12681 insertions, 5885 deletions
diff --git a/Makefile.am b/Makefile.am index 22b7fe0..1fb696f 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -1,6 +1,6 @@ | |||
1 | ## Process this file with automake to produce Makefile.in | 1 | ## Process this file with automake to produce Makefile.in |
2 | 2 | ||
3 | SUBDIRS = lib plugins plugins-scripts plugins-root m4 po | 3 | SUBDIRS = gl lib plugins plugins-scripts plugins-root po |
4 | 4 | ||
5 | EXTRA_DIST = config.rpath \ | 5 | EXTRA_DIST = config.rpath \ |
6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ | 6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ |
@@ -9,7 +9,7 @@ EXTRA_DIST = config.rpath \ | |||
9 | config_test/Makefile config_test/run_tests config_test/child_test.c \ | 9 | config_test/Makefile config_test/run_tests config_test/child_test.c \ |
10 | tools/tinderbox_build | 10 | tools/tinderbox_build |
11 | 11 | ||
12 | ACLOCAL_AMFLAGS = -I m4 | 12 | ACLOCAL_AMFLAGS = -I gl/m4 -I m4 |
13 | 13 | ||
14 | localedir = $(datadir)/locale | 14 | localedir = $(datadir)/locale |
15 | DEFS = -DLOCALEDIR=\"$(localedir)\" | 15 | DEFS = -DLOCALEDIR=\"$(localedir)\" |
@@ -1,2 +0,0 @@ | |||
1 | New in 1.2.9: | ||
2 | * Added support for multiplatform builds | ||
diff --git a/config.rpath b/config.rpath deleted file mode 100755 index 5ead758..0000000 --- a/config.rpath +++ /dev/null | |||
@@ -1,513 +0,0 @@ | |||
1 | #! /bin/sh | ||
2 | # Output a system dependent set of variables, describing how to set the | ||
3 | # run time search path of shared libraries in an executable. | ||
4 | # | ||
5 | # Copyright 1996-2002 Free Software Foundation, Inc. | ||
6 | # Taken from GNU libtool, 2001 | ||
7 | # Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 | ||
8 | # | ||
9 | # This program is free software; you can redistribute it and/or modify | ||
10 | # it under the terms of the GNU General Public License as published by | ||
11 | # the Free Software Foundation; either version 2 of the License, or | ||
12 | # (at your option) any later version. | ||
13 | # | ||
14 | # This program is distributed in the hope that it will be useful, but | ||
15 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | # General Public License for more details. | ||
18 | # | ||
19 | # You should have received a copy of the GNU General Public License | ||
20 | # along with this program; if not, write to the Free Software | ||
21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
22 | # | ||
23 | # As a special exception to the GNU General Public License, if you | ||
24 | # distribute this file as part of a program that contains a | ||
25 | # configuration script generated by Autoconf, you may include it under | ||
26 | # the same distribution terms that you use for the rest of that program. | ||
27 | # | ||
28 | # The first argument passed to this file is the canonical host specification, | ||
29 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM | ||
30 | # or | ||
31 | # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM | ||
32 | # The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld | ||
33 | # should be set by the caller. | ||
34 | # | ||
35 | # The set of defined variables is at the end of this script. | ||
36 | |||
37 | # All known linkers require a `.a' archive for static linking (except M$VC, | ||
38 | # which needs '.lib'). | ||
39 | libext=a | ||
40 | shlibext= | ||
41 | |||
42 | host="$1" | ||
43 | host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` | ||
44 | host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` | ||
45 | host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` | ||
46 | |||
47 | wl= | ||
48 | if test "$GCC" = yes; then | ||
49 | wl='-Wl,' | ||
50 | else | ||
51 | case "$host_os" in | ||
52 | aix3* | aix4* | aix5*) | ||
53 | wl='-Wl,' | ||
54 | ;; | ||
55 | hpux9* | hpux10* | hpux11*) | ||
56 | wl='-Wl,' | ||
57 | ;; | ||
58 | irix5* | irix6*) | ||
59 | wl='-Wl,' | ||
60 | ;; | ||
61 | linux*) | ||
62 | echo '__INTEL_COMPILER' > conftest.$ac_ext | ||
63 | if $CC -E conftest.$ac_ext >/dev/null | grep __INTEL_COMPILER >/dev/null | ||
64 | then | ||
65 | : | ||
66 | else | ||
67 | # Intel icc | ||
68 | wl='-Qoption,ld,' | ||
69 | fi | ||
70 | ;; | ||
71 | osf3* | osf4* | osf5*) | ||
72 | wl='-Wl,' | ||
73 | ;; | ||
74 | solaris*) | ||
75 | wl='-Wl,' | ||
76 | ;; | ||
77 | sunos4*) | ||
78 | wl='-Qoption ld ' | ||
79 | ;; | ||
80 | sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) | ||
81 | if test "x$host_vendor" = xsni; then | ||
82 | wl='-LD' | ||
83 | else | ||
84 | wl='-Wl,' | ||
85 | fi | ||
86 | ;; | ||
87 | esac | ||
88 | fi | ||
89 | |||
90 | hardcode_libdir_flag_spec= | ||
91 | hardcode_libdir_separator= | ||
92 | hardcode_direct=no | ||
93 | hardcode_minus_L=no | ||
94 | |||
95 | case "$host_os" in | ||
96 | cygwin* | mingw* | pw32*) | ||
97 | # FIXME: the MSVC++ port hasn't been tested in a loooong time | ||
98 | # When not using gcc, we currently assume that we are using | ||
99 | # Microsoft Visual C++. | ||
100 | if test "$GCC" != yes; then | ||
101 | with_gnu_ld=no | ||
102 | fi | ||
103 | ;; | ||
104 | openbsd*) | ||
105 | with_gnu_ld=no | ||
106 | ;; | ||
107 | esac | ||
108 | |||
109 | ld_shlibs=yes | ||
110 | if test "$with_gnu_ld" = yes; then | ||
111 | case "$host_os" in | ||
112 | aix3* | aix4* | aix5*) | ||
113 | # On AIX, the GNU linker is very broken | ||
114 | ld_shlibs=no | ||
115 | ;; | ||
116 | amigaos*) | ||
117 | hardcode_libdir_flag_spec='-L$libdir' | ||
118 | hardcode_minus_L=yes | ||
119 | # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports | ||
120 | # that the semantics of dynamic libraries on AmigaOS, at least up | ||
121 | # to version 4, is to share data among multiple programs linked | ||
122 | # with the same dynamic library. Since this doesn't match the | ||
123 | # behavior of shared libraries on other platforms, we can use | ||
124 | # them. | ||
125 | ld_shlibs=no | ||
126 | ;; | ||
127 | beos*) | ||
128 | if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then | ||
129 | : | ||
130 | else | ||
131 | ld_shlibs=no | ||
132 | fi | ||
133 | ;; | ||
134 | cygwin* | mingw* | pw32*) | ||
135 | # hardcode_libdir_flag_spec is actually meaningless, as there is | ||
136 | # no search path for DLLs. | ||
137 | hardcode_libdir_flag_spec='-L$libdir' | ||
138 | ;; | ||
139 | solaris* | sysv5*) | ||
140 | if $LD -v 2>&1 | egrep 'BFD 2\.8' > /dev/null; then | ||
141 | ld_shlibs=no | ||
142 | elif $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then | ||
143 | : | ||
144 | else | ||
145 | ld_shlibs=no | ||
146 | fi | ||
147 | ;; | ||
148 | sunos4*) | ||
149 | hardcode_direct=yes | ||
150 | ;; | ||
151 | *) | ||
152 | if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then | ||
153 | : | ||
154 | else | ||
155 | ld_shlibs=no | ||
156 | fi | ||
157 | ;; | ||
158 | esac | ||
159 | if test "$ld_shlibs" = yes; then | ||
160 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' | ||
161 | fi | ||
162 | else | ||
163 | case "$host_os" in | ||
164 | aix3*) | ||
165 | # Note: this linker hardcodes the directories in LIBPATH if there | ||
166 | # are no directories specified by -L. | ||
167 | hardcode_minus_L=yes | ||
168 | if test "$GCC" = yes; then | ||
169 | # Neither direct hardcoding nor static linking is supported with a | ||
170 | # broken collect2. | ||
171 | hardcode_direct=unsupported | ||
172 | fi | ||
173 | ;; | ||
174 | aix4* | aix5*) | ||
175 | if test "$host_cpu" = ia64; then | ||
176 | # On IA64, the linker does run time linking by default, so we don't | ||
177 | # have to do anything special. | ||
178 | aix_use_runtimelinking=no | ||
179 | else | ||
180 | aix_use_runtimelinking=no | ||
181 | # Test if we are trying to use run time linking or normal | ||
182 | # AIX style linking. If -brtl is somewhere in LDFLAGS, we | ||
183 | # need to do runtime linking. | ||
184 | case $host_os in aix4.[23]|aix4.[23].*|aix5*) | ||
185 | for ld_flag in $LDFLAGS; do | ||
186 | if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then | ||
187 | aix_use_runtimelinking=yes | ||
188 | break | ||
189 | fi | ||
190 | done | ||
191 | esac | ||
192 | fi | ||
193 | hardcode_direct=yes | ||
194 | hardcode_libdir_separator=':' | ||
195 | if test "$GCC" = yes; then | ||
196 | case $host_os in aix4.[012]|aix4.[012].*) | ||
197 | collect2name=`${CC} -print-prog-name=collect2` | ||
198 | if test -f "$collect2name" && \ | ||
199 | strings "$collect2name" | grep resolve_lib_name >/dev/null | ||
200 | then | ||
201 | # We have reworked collect2 | ||
202 | hardcode_direct=yes | ||
203 | else | ||
204 | # We have old collect2 | ||
205 | hardcode_direct=unsupported | ||
206 | hardcode_minus_L=yes | ||
207 | hardcode_libdir_flag_spec='-L$libdir' | ||
208 | hardcode_libdir_separator= | ||
209 | fi | ||
210 | esac | ||
211 | fi | ||
212 | if test "$aix_use_runtimelinking" = yes; then | ||
213 | hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib' | ||
214 | else | ||
215 | if test "$host_cpu" = ia64; then | ||
216 | hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' | ||
217 | else | ||
218 | hardcode_libdir_flag_spec='${wl}-bnolibpath ${wl}-blibpath:$libdir:/usr/lib:/lib' | ||
219 | fi | ||
220 | fi | ||
221 | ;; | ||
222 | amigaos*) | ||
223 | hardcode_libdir_flag_spec='-L$libdir' | ||
224 | hardcode_minus_L=yes | ||
225 | # see comment about different semantics on the GNU ld section | ||
226 | ld_shlibs=no | ||
227 | ;; | ||
228 | cygwin* | mingw* | pw32*) | ||
229 | # When not using gcc, we currently assume that we are using | ||
230 | # Microsoft Visual C++. | ||
231 | # hardcode_libdir_flag_spec is actually meaningless, as there is | ||
232 | # no search path for DLLs. | ||
233 | hardcode_libdir_flag_spec=' ' | ||
234 | libext=lib | ||
235 | ;; | ||
236 | darwin* | rhapsody*) | ||
237 | hardcode_direct=yes | ||
238 | ;; | ||
239 | freebsd1*) | ||
240 | ld_shlibs=no | ||
241 | ;; | ||
242 | freebsd2.2*) | ||
243 | hardcode_libdir_flag_spec='-R$libdir' | ||
244 | hardcode_direct=yes | ||
245 | ;; | ||
246 | freebsd2*) | ||
247 | hardcode_direct=yes | ||
248 | hardcode_minus_L=yes | ||
249 | ;; | ||
250 | freebsd*) | ||
251 | hardcode_libdir_flag_spec='-R$libdir' | ||
252 | hardcode_direct=yes | ||
253 | ;; | ||
254 | hpux9* | hpux10* | hpux11*) | ||
255 | hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' | ||
256 | hardcode_libdir_separator=: | ||
257 | hardcode_direct=yes | ||
258 | hardcode_minus_L=yes # Not in the search PATH, but as the default | ||
259 | # location of the library. | ||
260 | ;; | ||
261 | irix5* | irix6*) | ||
262 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' | ||
263 | hardcode_libdir_separator=: | ||
264 | ;; | ||
265 | netbsd*) | ||
266 | hardcode_libdir_flag_spec='-R$libdir' | ||
267 | hardcode_direct=yes | ||
268 | ;; | ||
269 | newsos6) | ||
270 | hardcode_direct=yes | ||
271 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' | ||
272 | hardcode_libdir_separator=: | ||
273 | ;; | ||
274 | openbsd*) | ||
275 | hardcode_direct=yes | ||
276 | if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then | ||
277 | hardcode_libdir_flag_spec='${wl}-rpath,$libdir' | ||
278 | else | ||
279 | case "$host_os" in | ||
280 | openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) | ||
281 | hardcode_libdir_flag_spec='-R$libdir' | ||
282 | ;; | ||
283 | *) | ||
284 | hardcode_libdir_flag_spec='${wl}-rpath,$libdir' | ||
285 | ;; | ||
286 | esac | ||
287 | fi | ||
288 | ;; | ||
289 | os2*) | ||
290 | hardcode_libdir_flag_spec='-L$libdir' | ||
291 | hardcode_minus_L=yes | ||
292 | ;; | ||
293 | osf3*) | ||
294 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' | ||
295 | hardcode_libdir_separator=: | ||
296 | ;; | ||
297 | osf4* | osf5*) | ||
298 | if test "$GCC" = yes; then | ||
299 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' | ||
300 | else | ||
301 | # Both cc and cxx compiler support -rpath directly | ||
302 | hardcode_libdir_flag_spec='-rpath $libdir' | ||
303 | fi | ||
304 | hardcode_libdir_separator=: | ||
305 | ;; | ||
306 | sco3.2v5*) | ||
307 | ;; | ||
308 | solaris*) | ||
309 | hardcode_libdir_flag_spec='-R$libdir' | ||
310 | ;; | ||
311 | sunos4*) | ||
312 | hardcode_libdir_flag_spec='-L$libdir' | ||
313 | hardcode_direct=yes | ||
314 | hardcode_minus_L=yes | ||
315 | ;; | ||
316 | sysv4) | ||
317 | if test "x$host_vendor" = xsno; then | ||
318 | hardcode_direct=yes # is this really true??? | ||
319 | else | ||
320 | hardcode_direct=no # Motorola manual says yes, but my tests say they lie | ||
321 | fi | ||
322 | ;; | ||
323 | sysv4.3*) | ||
324 | ;; | ||
325 | sysv5*) | ||
326 | hardcode_libdir_flag_spec= | ||
327 | ;; | ||
328 | uts4*) | ||
329 | hardcode_libdir_flag_spec='-L$libdir' | ||
330 | ;; | ||
331 | dgux*) | ||
332 | hardcode_libdir_flag_spec='-L$libdir' | ||
333 | ;; | ||
334 | sysv4*MP*) | ||
335 | if test -d /usr/nec; then | ||
336 | ld_shlibs=yes | ||
337 | fi | ||
338 | ;; | ||
339 | sysv4.2uw2*) | ||
340 | hardcode_direct=yes | ||
341 | hardcode_minus_L=no | ||
342 | ;; | ||
343 | sysv5uw7* | unixware7*) | ||
344 | ;; | ||
345 | *) | ||
346 | ld_shlibs=no | ||
347 | ;; | ||
348 | esac | ||
349 | fi | ||
350 | |||
351 | # Check dynamic linker characteristics | ||
352 | libname_spec='lib$name' | ||
353 | sys_lib_dlsearch_path_spec="/lib /usr/lib" | ||
354 | sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" | ||
355 | case "$host_os" in | ||
356 | aix3*) | ||
357 | shlibext=so | ||
358 | ;; | ||
359 | aix4* | aix5*) | ||
360 | shlibext=so | ||
361 | ;; | ||
362 | amigaos*) | ||
363 | shlibext=ixlibrary | ||
364 | ;; | ||
365 | beos*) | ||
366 | shlibext=so | ||
367 | ;; | ||
368 | bsdi4*) | ||
369 | shlibext=so | ||
370 | sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" | ||
371 | sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" | ||
372 | ;; | ||
373 | cygwin* | mingw* | pw32*) | ||
374 | case $GCC,$host_os in | ||
375 | yes,cygwin*) | ||
376 | shlibext=dll.a | ||
377 | ;; | ||
378 | yes,mingw*) | ||
379 | shlibext=dll | ||
380 | sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | sed -e "s/^libraries://" -e "s/;/ /g"` | ||
381 | ;; | ||
382 | yes,pw32*) | ||
383 | shlibext=dll | ||
384 | ;; | ||
385 | *) | ||
386 | shlibext=dll | ||
387 | ;; | ||
388 | esac | ||
389 | ;; | ||
390 | darwin* | rhapsody*) | ||
391 | shlibext=dylib | ||
392 | ;; | ||
393 | freebsd1*) | ||
394 | ;; | ||
395 | freebsd*) | ||
396 | shlibext=so | ||
397 | ;; | ||
398 | gnu*) | ||
399 | shlibext=so | ||
400 | ;; | ||
401 | hpux9* | hpux10* | hpux11*) | ||
402 | shlibext=sl | ||
403 | ;; | ||
404 | irix5* | irix6*) | ||
405 | shlibext=so | ||
406 | case "$host_os" in | ||
407 | irix5*) | ||
408 | libsuff= shlibsuff= | ||
409 | ;; | ||
410 | *) | ||
411 | case $LD in | ||
412 | *-32|*"-32 ") libsuff= shlibsuff= ;; | ||
413 | *-n32|*"-n32 ") libsuff=32 shlibsuff=N32 ;; | ||
414 | *-64|*"-64 ") libsuff=64 shlibsuff=64 ;; | ||
415 | *) libsuff= shlibsuff= ;; | ||
416 | esac | ||
417 | ;; | ||
418 | esac | ||
419 | sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" | ||
420 | sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" | ||
421 | ;; | ||
422 | linux-gnuoldld* | linux-gnuaout* | linux-gnucoff*) | ||
423 | ;; | ||
424 | linux-gnu*) | ||
425 | shlibext=so | ||
426 | ;; | ||
427 | netbsd*) | ||
428 | shlibext=so | ||
429 | ;; | ||
430 | newsos6) | ||
431 | shlibext=so | ||
432 | ;; | ||
433 | openbsd*) | ||
434 | shlibext=so | ||
435 | ;; | ||
436 | os2*) | ||
437 | libname_spec='$name' | ||
438 | shlibext=dll | ||
439 | ;; | ||
440 | osf3* | osf4* | osf5*) | ||
441 | shlibext=so | ||
442 | sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" | ||
443 | sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" | ||
444 | ;; | ||
445 | sco3.2v5*) | ||
446 | shlibext=so | ||
447 | ;; | ||
448 | solaris*) | ||
449 | shlibext=so | ||
450 | ;; | ||
451 | sunos4*) | ||
452 | shlibext=so | ||
453 | ;; | ||
454 | sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) | ||
455 | shlibext=so | ||
456 | case "$host_vendor" in | ||
457 | motorola) | ||
458 | sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' | ||
459 | ;; | ||
460 | esac | ||
461 | ;; | ||
462 | uts4*) | ||
463 | shlibext=so | ||
464 | ;; | ||
465 | dgux*) | ||
466 | shlibext=so | ||
467 | ;; | ||
468 | sysv4*MP*) | ||
469 | if test -d /usr/nec; then | ||
470 | shlibext=so | ||
471 | fi | ||
472 | ;; | ||
473 | esac | ||
474 | |||
475 | sed_quote_subst='s/\(["`$\\]\)/\\\1/g' | ||
476 | escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` | ||
477 | escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` | ||
478 | escaped_sys_lib_search_path_spec=`echo "X$sys_lib_search_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` | ||
479 | escaped_sys_lib_dlsearch_path_spec=`echo "X$sys_lib_dlsearch_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` | ||
480 | |||
481 | sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <<EOF | ||
482 | |||
483 | # How to pass a linker flag through the compiler. | ||
484 | wl="$escaped_wl" | ||
485 | |||
486 | # Static library suffix (normally "a"). | ||
487 | libext="$libext" | ||
488 | |||
489 | # Shared library suffix (normally "so"). | ||
490 | shlibext="$shlibext" | ||
491 | |||
492 | # Flag to hardcode \$libdir into a binary during linking. | ||
493 | # This must work even if \$libdir does not exist. | ||
494 | hardcode_libdir_flag_spec="$escaped_hardcode_libdir_flag_spec" | ||
495 | |||
496 | # Whether we need a single -rpath flag with a separated argument. | ||
497 | hardcode_libdir_separator="$hardcode_libdir_separator" | ||
498 | |||
499 | # Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the | ||
500 | # resulting binary. | ||
501 | hardcode_direct="$hardcode_direct" | ||
502 | |||
503 | # Set to yes if using the -LDIR flag during linking hardcodes DIR into the | ||
504 | # resulting binary. | ||
505 | hardcode_minus_L="$hardcode_minus_L" | ||
506 | |||
507 | # Compile-time system search path for libraries | ||
508 | sys_lib_search_path_spec="$escaped_sys_lib_search_path_spec" | ||
509 | |||
510 | # Run-time system search path for libraries | ||
511 | sys_lib_dlsearch_path_spec="$escaped_sys_lib_dlsearch_path_spec" | ||
512 | |||
513 | EOF | ||
diff --git a/configure.in b/configure.in index 356e4e3..228a841 100644 --- a/configure.in +++ b/configure.in | |||
@@ -1,10 +1,12 @@ | |||
1 | dnl Process this file with autoconf to produce a configure script. | 1 | dnl Process this file with autoconf to produce a configure script. |
2 | AC_REVISION ($Revision$) | 2 | AC_REVISION ($Revision$) |
3 | AC_PREREQ(2.58) | 3 | AC_PREREQ(2.59) |
4 | AC_INIT(nagios-plugins,1.4.5) | 4 | AC_INIT(nagios-plugins,1.4.5) |
5 | AC_CONFIG_SRCDIR(NPTest.pm) | 5 | AC_CONFIG_SRCDIR(NPTest.pm) |
6 | AC_CONFIG_FILES(gl/Makefile) | ||
6 | AM_INIT_AUTOMAKE([1.8.3]) | 7 | AM_INIT_AUTOMAKE([1.8.3]) |
7 | AM_CONFIG_HEADER(config.h) | 8 | AM_CONFIG_HEADER(config.h) |
9 | dnl Not yet - AC_CONFIG_AUX_DIR(build-aux) | ||
8 | AC_CANONICAL_HOST | 10 | AC_CANONICAL_HOST |
9 | 11 | ||
10 | RELEASE=1 | 12 | RELEASE=1 |
@@ -22,11 +24,8 @@ dnl Figure out how to invoke "install" and what install options to use. | |||
22 | AC_PROG_INSTALL | 24 | AC_PROG_INSTALL |
23 | AC_SUBST(INSTALL) | 25 | AC_SUBST(INSTALL) |
24 | 26 | ||
25 | dnl Must come very early on due to coreutils requirement | ||
26 | dnl Takes care of AC_GNU_SOURCE, AC_AIX and AC_MINIX | ||
27 | gl_USE_SYSTEM_EXTENSIONS | ||
28 | |||
29 | AC_PROG_CC | 27 | AC_PROG_CC |
28 | gl_EARLY | ||
30 | AC_PROG_CPP | 29 | AC_PROG_CPP |
31 | AC_PROG_GCC_TRADITIONAL | 30 | AC_PROG_GCC_TRADITIONAL |
32 | AC_PROG_LIBTOOL | 31 | AC_PROG_LIBTOOL |
@@ -38,9 +37,6 @@ AC_FUNC_MALLOC | |||
38 | AC_FUNC_REALLOC | 37 | AC_FUNC_REALLOC |
39 | AC_FUNC_ERROR_AT_LINE | 38 | AC_FUNC_ERROR_AT_LINE |
40 | 39 | ||
41 | AC_CONFIG_LIBOBJ_DIR(lib) | ||
42 | AC_FUNC_GETLOADAVG([lib]) | ||
43 | |||
44 | ifdef([AC_FUNC_STRTOD],[AC_FUNC_STRTOD],[AM_FUNC_STRTOD]) | 40 | ifdef([AC_FUNC_STRTOD],[AC_FUNC_STRTOD],[AM_FUNC_STRTOD]) |
45 | 41 | ||
46 | PLUGIN_TEST=`echo $srcdir/plugins/t/*.t|sed -e 's,\.*/plugins/,,g'` | 42 | PLUGIN_TEST=`echo $srcdir/plugins/t/*.t|sed -e 's,\.*/plugins/,,g'` |
@@ -128,15 +124,6 @@ dnl the order should allow locally installed versions to override distros' ones | |||
128 | OPENSSL_DIRS="/usr /usr/local /usr/slocal /usr/local/openssl /usr/local/ssl \ | 124 | OPENSSL_DIRS="/usr /usr/local /usr/slocal /usr/local/openssl /usr/local/ssl \ |
129 | /opt /opt/openssl" | 125 | /opt /opt/openssl" |
130 | 126 | ||
131 | dnl | ||
132 | dnl Check for miscellaneous stuff | ||
133 | dnl | ||
134 | |||
135 | case $host_vender-$host_os in | ||
136 | osf*) | ||
137 | AC_DEFINE(_OSF_SOURCE,1,[OSF needs this for getaddrinfo]) | ||
138 | ;; | ||
139 | esac | ||
140 | 127 | ||
141 | dnl | 128 | dnl |
142 | dnl Checks for libraries. | 129 | dnl Checks for libraries. |
@@ -297,108 +284,6 @@ if test x"$with_ipv6" != xno ; then | |||
297 | AC_DEFINE(USE_IPV6,1,[Enable IPv6 support]) | 284 | AC_DEFINE(USE_IPV6,1,[Enable IPv6 support]) |
298 | fi | 285 | fi |
299 | 286 | ||
300 | dnl ######################################################################### | ||
301 | dnl Check if Posix getaddrinfo() is available. It is also possible to use | ||
302 | dnl the version from the lwres library distributed with BIND. | ||
303 | dnl ######################################################################### | ||
304 | AC_ARG_ENABLE([emulate-getaddrinfo], | ||
305 | ACX_HELP_STRING([--enable-emulate-getaddrinfo], | ||
306 | [enable getaddrinfo emulation (default=no)]), | ||
307 | , | ||
308 | enable_emulate_getaddrinfo=no) | ||
309 | |||
310 | AC_ARG_WITH(lwres, | ||
311 | ACX_HELP_STRING([--with-lwres=DIR], | ||
312 | [use lwres library for getaddrinfo (default=no)]), | ||
313 | , | ||
314 | with_lwres=no) | ||
315 | |||
316 | dnl ## enable force to test getaddrinfo.c | ||
317 | if test x$enable_emulate_getaddrinfo = xforce ; then | ||
318 | enable_emulate_getaddrinfo=yes | ||
319 | have_getaddrinfo=no | ||
320 | else | ||
321 | |||
322 | have_getaddrinfo=no | ||
323 | if test x$with_lwres != xno ; then | ||
324 | if test "$with_lwres" != yes ; then | ||
325 | CPPFLAGS="-I${with_lwres}/include $CPPFLAGS" | ||
326 | LDFLAGS="-L${with_lwres}/lib $LDFLAGS" | ||
327 | fi | ||
328 | AC_CHECK_HEADERS(lwres/netdb.h, , | ||
329 | [AC_MSG_ERROR([cannot find <lwres/netdb.h>])]) | ||
330 | AC_CHECK_LIB(lwres, lwres_getaddrinfo, , | ||
331 | [AC_MSG_ERROR([cannot find the lwres library])], | ||
332 | -lnsl -lpthread) | ||
333 | have_getaddrinfo=yes | ||
334 | fi | ||
335 | |||
336 | if test x$have_getaddrinfo != xyes ; then | ||
337 | AC_SEARCH_LIBS(getaddrinfo, socket resolv bind nsl c_r cr, have_getaddrinfo=yes) | ||
338 | fi | ||
339 | |||
340 | dnl # Special nonsense for systems that actually have getaddrinfo but | ||
341 | dnl # redefine the name to something else, e.g. OSF | ||
342 | if test x$have_getaddrinfo != xyes ; then | ||
343 | AC_MSG_CHECKING(if getaddrinfo is redefined in netdb.h) | ||
344 | AC_TRY_LINK([ | ||
345 | # include <netdb.h> | ||
346 | ], [ | ||
347 | struct addrinfo hints, *res; | ||
348 | int err; | ||
349 | |||
350 | err = getaddrinfo ("host", "service", &hints, &res); | ||
351 | ], [ | ||
352 | have_getaddrinfo=yes | ||
353 | AC_MSG_RESULT(yes) | ||
354 | ], [AC_MSG_RESULT(no)]) | ||
355 | fi | ||
356 | |||
357 | fi | ||
358 | |||
359 | if test x$have_getaddrinfo != xno ; then | ||
360 | if test x$enable_emulate_getaddrinfo != xno ; then | ||
361 | AC_MSG_ERROR([getaddrinfo found but emulate-getaddrinfo was enabled]) | ||
362 | fi | ||
363 | AC_DEFINE(HAVE_GETADDRINFO, 1, | ||
364 | [Does system provide RFC 2553/Posix getaddrinfo?]) | ||
365 | else | ||
366 | if test x$enable_emulate_getaddrinfo != xyes ; then | ||
367 | dnl AC_MSG_ERROR([getaddrinfo not found: try --with-lwres or --enable-emulate-getaddrinfo]) | ||
368 | enable_emulate_getaddrinfo=yes | ||
369 | AC_MSG_WARN([enabling getaddrinfo emulation]) | ||
370 | fi | ||
371 | EXTRA_NETOBJS="$EXTRA_NETOBJS getaddrinfo.o" | ||
372 | fi | ||
373 | |||
374 | if test x"$enable_emulate_getaddrinfo" != xno ; then | ||
375 | have_resolver=no | ||
376 | |||
377 | dnl Try for getipnodebyname | ||
378 | AC_SEARCH_LIBS(getipnodebyname, resolv bind nsl c_r cr, have_resolver=yes) | ||
379 | if test x"$have_resolver" != xno ; then | ||
380 | AC_DEFINE(HAVE_GETIPNODEBYNAME, 1, | ||
381 | [Set when getipnodebyname is available]) | ||
382 | fi | ||
383 | |||
384 | dnl Try for gethostbyname_r | ||
385 | if test x"$have_resolver" = xno ; then | ||
386 | AC_SEARCH_LIBS(gethostbyname_r, resolv bind nsl c_r cr, | ||
387 | [have_resolver=yes | ||
388 | ACX_WHICH_GETHOSTBYNAME_R]) | ||
389 | fi | ||
390 | |||
391 | dnl Try for gethostbyname | ||
392 | if test x"$have_resolver" = xno ; then | ||
393 | if test x"$enable_pthreads" != xno ; then | ||
394 | AC_MSG_WARN([using threads but cannot find gethostbyname_r or getipnodebyname]) | ||
395 | fi | ||
396 | AC_SEARCH_LIBS(gethostbyname, resolv bind nsl, , | ||
397 | [AC_MSG_ERROR([cannot find gethostbyname])]) | ||
398 | fi | ||
399 | EXTRA_NETOBJS="$EXTRA_NETOBJS gethostbyname.o" | ||
400 | |||
401 | fi | ||
402 | 287 | ||
403 | dnl Checks for Kerberos. Must come before openssl checks for Redhat EL 3 | 288 | dnl Checks for Kerberos. Must come before openssl checks for Redhat EL 3 |
404 | AC_CHECK_HEADERS(krb5.h,FOUNDINCLUDE=yes,FOUNDINCLUDE=no) | 289 | AC_CHECK_HEADERS(krb5.h,FOUNDINCLUDE=yes,FOUNDINCLUDE=no) |
@@ -519,7 +404,7 @@ dnl | |||
519 | AC_HEADER_STDC | 404 | AC_HEADER_STDC |
520 | AC_HEADER_TIME | 405 | AC_HEADER_TIME |
521 | AC_HEADER_SYS_WAIT | 406 | AC_HEADER_SYS_WAIT |
522 | AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h uio.h errno.h sys/types.h sys/time.h sys/socket.h sys/loadavg.h sys/un.h sys/poll.h) | 407 | AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h uio.h errno.h sys/types.h sys/time.h sys/socket.h sys/un.h sys/poll.h) |
523 | AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h stdlib.h) | 408 | AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h stdlib.h) |
524 | 409 | ||
525 | dnl Checks for typedefs, structures, and compiler characteristics. | 410 | dnl Checks for typedefs, structures, and compiler characteristics. |
@@ -547,37 +432,6 @@ else | |||
547 | fi | 432 | fi |
548 | fi | 433 | fi |
549 | 434 | ||
550 | AC_CHECK_FUNCS(vsnprintf snprintf asprintf vasprintf) | ||
551 | AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[ | ||
552 | AC_TRY_RUN([ | ||
553 | #include <sys/types.h> | ||
554 | #include <stdarg.h> | ||
555 | void foo(const char *format, ...) { | ||
556 | va_list ap; | ||
557 | int len; | ||
558 | char buf[5]; | ||
559 | |||
560 | va_start(ap, format); | ||
561 | len = vsnprintf(buf, 0, format, ap); | ||
562 | va_end(ap); | ||
563 | if (len != 5) exit(1); | ||
564 | |||
565 | va_start(ap, format); | ||
566 | len = vsnprintf(0, 0, format, ap); | ||
567 | va_end(ap); | ||
568 | if (len != 5) exit(1); | ||
569 | |||
570 | if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1); | ||
571 | |||
572 | exit(0); | ||
573 | } | ||
574 | main() { foo("hello"); } | ||
575 | ], | ||
576 | ac_cv_HAVE_C99_VSNPRINTF=yes,ac_cv_HAVE_C99_VSNPRINTF=no,ac_cv_HAVE_C99_VSNPRINTF=cross)]) | ||
577 | if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then | ||
578 | AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf]) | ||
579 | fi | ||
580 | |||
581 | AC_TRY_COMPILE([#include <sys/time.h>], | 435 | AC_TRY_COMPILE([#include <sys/time.h>], |
582 | [struct timeval *tv; | 436 | [struct timeval *tv; |
583 | struct timezone *tz;], | 437 | struct timezone *tz;], |
@@ -606,24 +460,6 @@ AC_TRY_COMPILE([#include <stdlib.h> | |||
606 | AC_DEFINE_UNQUOTED(SOCKET_SIZE_TYPE, $ac_cv_socket_size_type , | 460 | AC_DEFINE_UNQUOTED(SOCKET_SIZE_TYPE, $ac_cv_socket_size_type , |
607 | [Define type of socket size]) | 461 | [Define type of socket size]) |
608 | 462 | ||
609 | AC_ARG_WITH(proc-loadavg, | ||
610 | ACX_HELP_STRING([--with-proc-loadavg=PATH], | ||
611 | [path to /proc/loadavg or equivalent]), | ||
612 | ac_cv_proc_loadavg=$withval) | ||
613 | AC_MSG_CHECKING([for /proc/loadavg]) | ||
614 | if test -n "$ac_cv_proc_loadavg"; then | ||
615 | AC_MSG_RESULT([(command line) $ac_cv_proc_loadavg]) | ||
616 | elif test -f "/proc/loadavg"; then | ||
617 | AC_MSG_RESULT([found /proc/loadavg]) | ||
618 | ac_cv_proc_loadavg="/proc/loadavg" | ||
619 | else | ||
620 | AC_MSG_RESULT([no]) | ||
621 | fi | ||
622 | |||
623 | if test -n "$ac_cv_proc_loadavg"; then | ||
624 | AC_DEFINE(HAVE_PROC_LOADAVG,1,[Define if /proc/loadavg or similar exists]) | ||
625 | AC_DEFINE_UNQUOTED(PROC_LOADAVG,"/proc/loadavg",[Location of /proc/loadavg]) | ||
626 | fi | ||
627 | 463 | ||
628 | dnl #### Process table test | 464 | dnl #### Process table test |
629 | 465 | ||
@@ -1615,21 +1451,6 @@ elif test -f ../plugins/check_nt.c ; then | |||
1615 | EXTRAS="$EXTRAS check_nt" | 1451 | EXTRAS="$EXTRAS check_nt" |
1616 | fi | 1452 | fi |
1617 | 1453 | ||
1618 | AC_MSG_CHECKING(for va_list) | ||
1619 | AC_TRY_COMPILE([#ifdef __STDC__ | ||
1620 | #include <stdio.h> | ||
1621 | #include <stdlib.h> | ||
1622 | #include <stdarg.h> | ||
1623 | #else | ||
1624 | #include <sys/types.h> | ||
1625 | #include <stdio.h> | ||
1626 | #include <varargs.h> | ||
1627 | #endif], | ||
1628 | [va_list args;], | ||
1629 | [AC_MSG_RESULT(yes)], | ||
1630 | [NEED_VA_LIST=-DNEED_VA_LIST | ||
1631 | AC_SUBST(NEED_VA_LIST) | ||
1632 | AC_MSG_RESULT(no)]) | ||
1633 | 1454 | ||
1634 | case $host in | 1455 | case $host in |
1635 | *bsd*) | 1456 | *bsd*) |
@@ -1682,8 +1503,7 @@ elif test "$ac_cv_enable_redhat_pthread_workaround" = "yes" ; then | |||
1682 | fi | 1503 | fi |
1683 | 1504 | ||
1684 | dnl External libraries - see ACKNOWLEDGEMENTS | 1505 | dnl External libraries - see ACKNOWLEDGEMENTS |
1685 | np_COREUTILS | 1506 | gl_INIT |
1686 | np_CURL | ||
1687 | 1507 | ||
1688 | dnl Some helpful common compile errors checked here | 1508 | dnl Some helpful common compile errors checked here |
1689 | if test "$ac_cv_uname_s" = 'SunOS' -a "$ac_cv_prog_ac_ct_AR" = 'false' ; then | 1509 | if test "$ac_cv_uname_s" = 'SunOS' -a "$ac_cv_prog_ac_ct_AR" = 'false' ; then |
@@ -1693,7 +1513,6 @@ fi | |||
1693 | AC_OUTPUT( | 1513 | AC_OUTPUT( |
1694 | Makefile | 1514 | Makefile |
1695 | lib/Makefile | 1515 | lib/Makefile |
1696 | m4/Makefile | ||
1697 | plugins/Makefile | 1516 | plugins/Makefile |
1698 | lib/tests/Makefile | 1517 | lib/tests/Makefile |
1699 | plugins-root/Makefile | 1518 | plugins-root/Makefile |
@@ -1727,7 +1546,6 @@ dnl ACX_FEATURE([with],[snmpgetnext-command]) | |||
1727 | dnl ACX_FEATURE([with],[ssh-command]) | 1546 | dnl ACX_FEATURE([with],[ssh-command]) |
1728 | dnl ACX_FEATURE([with],[uptime-command]) | 1547 | dnl ACX_FEATURE([with],[uptime-command]) |
1729 | 1548 | ||
1730 | dnl ACX_FEATURE([with],[proc-loadavg]) | ||
1731 | dnl ACX_FEATURE([with],[proc-meminfo]) | 1549 | dnl ACX_FEATURE([with],[proc-meminfo]) |
1732 | dnl ACX_FEATURE([with],[ps-command]) | 1550 | dnl ACX_FEATURE([with],[ps-command]) |
1733 | dnl ACX_FEATURE([with],[ps-format]) | 1551 | dnl ACX_FEATURE([with],[ps-format]) |
@@ -1739,7 +1557,6 @@ ACX_FEATURE([with],[ipv6]) | |||
1739 | ACX_FEATURE([with],[mysql]) | 1557 | ACX_FEATURE([with],[mysql]) |
1740 | ACX_FEATURE([with],[openssl]) | 1558 | ACX_FEATURE([with],[openssl]) |
1741 | ACX_FEATURE([with],[gnutls]) | 1559 | ACX_FEATURE([with],[gnutls]) |
1742 | ACX_FEATURE([enable],[emulate-getaddrinfo]) | ||
1743 | ACX_FEATURE([with],[perl]) | 1560 | ACX_FEATURE([with],[perl]) |
1744 | ACX_FEATURE([with],[cgiurl]) | 1561 | ACX_FEATURE([with],[cgiurl]) |
1745 | ACX_FEATURE([with],[trusted-path]) | 1562 | ACX_FEATURE([with],[trusted-path]) |
diff --git a/doc/developer-guidelines.sgml b/doc/developer-guidelines.sgml index 15920af..21b85c3 100644 --- a/doc/developer-guidelines.sgml +++ b/doc/developer-guidelines.sgml | |||
@@ -56,7 +56,7 @@ | |||
56 | <literallayout> | 56 | <literallayout> |
57 | gnu make 3.79 | 57 | gnu make 3.79 |
58 | automake 1.9.2 | 58 | automake 1.9.2 |
59 | autoconf 2.58 | 59 | autoconf 2.59 |
60 | gnu m4 1.4.2 | 60 | gnu m4 1.4.2 |
61 | gnu libtool 1.5 | 61 | gnu libtool 1.5 |
62 | </literallayout> | 62 | </literallayout> |
diff --git a/gl/Makefile.am b/gl/Makefile.am new file mode 100644 index 0000000..67c9872 --- /dev/null +++ b/gl/Makefile.am | |||
@@ -0,0 +1,607 @@ | |||
1 | ## DO NOT EDIT! GENERATED AUTOMATICALLY! | ||
2 | ## Process this file with automake to produce Makefile.in. | ||
3 | # Copyright (C) 2004-2007 Free Software Foundation, Inc. | ||
4 | # | ||
5 | # This file is free software, distributed under the terms of the GNU | ||
6 | # General Public License. As a special exception to the GNU General | ||
7 | # Public License, this file may be distributed as part of a program | ||
8 | # that contains a configuration script generated by Autoconf, under | ||
9 | # the same distribution terms as the rest of that program. | ||
10 | # | ||
11 | # Generated by gnulib-tool. | ||
12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=. --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf | ||
13 | |||
14 | AUTOMAKE_OPTIONS = 1.5 gnits | ||
15 | |||
16 | noinst_HEADERS = | ||
17 | noinst_LIBRARIES = | ||
18 | noinst_LTLIBRARIES = | ||
19 | EXTRA_DIST = | ||
20 | BUILT_SOURCES = | ||
21 | SUFFIXES = | ||
22 | MOSTLYCLEANFILES = core *.stackdump | ||
23 | MOSTLYCLEANDIRS = | ||
24 | CLEANFILES = | ||
25 | DISTCLEANFILES = | ||
26 | MAINTAINERCLEANFILES = | ||
27 | |||
28 | AM_CPPFLAGS = | ||
29 | |||
30 | noinst_LIBRARIES += libgnu.a | ||
31 | |||
32 | libgnu_a_SOURCES = | ||
33 | libgnu_a_LIBADD = $(gl_LIBOBJS) | ||
34 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) | ||
35 | EXTRA_libgnu_a_SOURCES = | ||
36 | |||
37 | ## begin gnulib module alloca | ||
38 | |||
39 | |||
40 | EXTRA_DIST += alloca.c | ||
41 | |||
42 | EXTRA_libgnu_a_SOURCES += alloca.c | ||
43 | |||
44 | libgnu_a_LIBADD += @ALLOCA@ | ||
45 | libgnu_a_DEPENDENCIES += @ALLOCA@ | ||
46 | ## end gnulib module alloca | ||
47 | |||
48 | ## begin gnulib module alloca-opt | ||
49 | |||
50 | BUILT_SOURCES += $(ALLOCA_H) | ||
51 | |||
52 | # We need the following in order to create <alloca.h> when the system | ||
53 | # doesn't have one that works with the given compiler. | ||
54 | alloca.h: alloca_.h | ||
55 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
56 | cat $(srcdir)/alloca_.h; \ | ||
57 | } > $@-t | ||
58 | mv -f $@-t $@ | ||
59 | MOSTLYCLEANFILES += alloca.h alloca.h-t | ||
60 | |||
61 | EXTRA_DIST += alloca_.h | ||
62 | |||
63 | ## end gnulib module alloca-opt | ||
64 | |||
65 | ## begin gnulib module arpa_inet | ||
66 | |||
67 | BUILT_SOURCES += $(ARPA_INET_H) | ||
68 | |||
69 | # We need the following in order to create <arpa/inet.h> when the system | ||
70 | # doesn't have one. | ||
71 | arpa/inet.h: | ||
72 | test -d arpa || mkdir arpa | ||
73 | rm -f $@-t $@ | ||
74 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
75 | echo '#include <sys/socket.h>'; \ | ||
76 | } > $@-t | ||
77 | mv $@-t $@ | ||
78 | MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t | ||
79 | MOSTLYCLEANDIRS += arpa | ||
80 | |||
81 | ## end gnulib module arpa_inet | ||
82 | |||
83 | ## begin gnulib module c-strtod | ||
84 | |||
85 | |||
86 | EXTRA_DIST += c-strtod.c c-strtod.h | ||
87 | |||
88 | EXTRA_libgnu_a_SOURCES += c-strtod.c | ||
89 | |||
90 | ## end gnulib module c-strtod | ||
91 | |||
92 | ## begin gnulib module cloexec | ||
93 | |||
94 | |||
95 | EXTRA_DIST += cloexec.c cloexec.h | ||
96 | |||
97 | EXTRA_libgnu_a_SOURCES += cloexec.c | ||
98 | |||
99 | ## end gnulib module cloexec | ||
100 | |||
101 | ## begin gnulib module dirname | ||
102 | |||
103 | |||
104 | EXTRA_DIST += basename.c dirname.c dirname.h stripslash.c | ||
105 | |||
106 | EXTRA_libgnu_a_SOURCES += basename.c dirname.c stripslash.c | ||
107 | |||
108 | ## end gnulib module dirname | ||
109 | |||
110 | ## begin gnulib module error | ||
111 | |||
112 | |||
113 | EXTRA_DIST += error.c error.h | ||
114 | |||
115 | EXTRA_libgnu_a_SOURCES += error.c | ||
116 | |||
117 | ## end gnulib module error | ||
118 | |||
119 | ## begin gnulib module exit | ||
120 | |||
121 | libgnu_a_SOURCES += exit.h | ||
122 | |||
123 | ## end gnulib module exit | ||
124 | |||
125 | ## begin gnulib module exitfail | ||
126 | |||
127 | |||
128 | EXTRA_DIST += exitfail.c exitfail.h | ||
129 | |||
130 | EXTRA_libgnu_a_SOURCES += exitfail.c | ||
131 | |||
132 | ## end gnulib module exitfail | ||
133 | |||
134 | ## begin gnulib module fcntl-safer | ||
135 | |||
136 | |||
137 | EXTRA_DIST += creat-safer.c fcntl--.h fcntl-safer.h open-safer.c | ||
138 | |||
139 | EXTRA_libgnu_a_SOURCES += creat-safer.c open-safer.c | ||
140 | |||
141 | ## end gnulib module fcntl-safer | ||
142 | |||
143 | ## begin gnulib module fsusage | ||
144 | |||
145 | |||
146 | EXTRA_DIST += fsusage.c fsusage.h | ||
147 | |||
148 | EXTRA_libgnu_a_SOURCES += fsusage.c | ||
149 | |||
150 | ## end gnulib module fsusage | ||
151 | |||
152 | ## begin gnulib module full-read | ||
153 | |||
154 | libgnu_a_SOURCES += full-read.h full-read.c | ||
155 | |||
156 | ## end gnulib module full-read | ||
157 | |||
158 | ## begin gnulib module full-write | ||
159 | |||
160 | libgnu_a_SOURCES += full-write.h full-write.c | ||
161 | |||
162 | ## end gnulib module full-write | ||
163 | |||
164 | ## begin gnulib module getaddrinfo | ||
165 | |||
166 | |||
167 | EXTRA_DIST += gai_strerror.c getaddrinfo.c getaddrinfo.h | ||
168 | |||
169 | EXTRA_libgnu_a_SOURCES += gai_strerror.c getaddrinfo.c | ||
170 | |||
171 | ## end gnulib module getaddrinfo | ||
172 | |||
173 | ## begin gnulib module gethostname | ||
174 | |||
175 | |||
176 | EXTRA_DIST += gethostname.c | ||
177 | |||
178 | EXTRA_libgnu_a_SOURCES += gethostname.c | ||
179 | |||
180 | ## end gnulib module gethostname | ||
181 | |||
182 | ## begin gnulib module getloadavg | ||
183 | |||
184 | |||
185 | EXTRA_DIST += getloadavg.c | ||
186 | |||
187 | EXTRA_libgnu_a_SOURCES += getloadavg.c | ||
188 | |||
189 | ## end gnulib module getloadavg | ||
190 | |||
191 | ## begin gnulib module getopt | ||
192 | |||
193 | BUILT_SOURCES += $(GETOPT_H) | ||
194 | |||
195 | # We need the following in order to create <getopt.h> when the system | ||
196 | # doesn't have one that works with the given compiler. | ||
197 | getopt.h: getopt_.h | ||
198 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
199 | cat $(srcdir)/getopt_.h; \ | ||
200 | } > $@-t | ||
201 | mv -f $@-t $@ | ||
202 | MOSTLYCLEANFILES += getopt.h getopt.h-t | ||
203 | |||
204 | EXTRA_DIST += getopt.c getopt1.c getopt_.h getopt_int.h | ||
205 | |||
206 | EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c | ||
207 | |||
208 | ## end gnulib module getopt | ||
209 | |||
210 | ## begin gnulib module gettext | ||
211 | |||
212 | # This is for those projects which use "gettextize --intl" to put a source-code | ||
213 | # copy of libintl into their package. In such projects, every Makefile.am needs | ||
214 | # -I$(top_builddir)/intl, so that <libintl.h> can be found in this directory. | ||
215 | # For the Makefile.ams in other directories it is the maintainer's | ||
216 | # responsibility; for the one from gnulib we do it here. | ||
217 | # This option has no effect when the user disables NLS (because then the intl | ||
218 | # directory contains no libintl.h file) or when the project does not use | ||
219 | # "gettextize --intl". | ||
220 | AM_CPPFLAGS += -I$(top_builddir)/intl | ||
221 | |||
222 | ## end gnulib module gettext | ||
223 | |||
224 | ## begin gnulib module gettext-h | ||
225 | |||
226 | libgnu_a_SOURCES += gettext.h | ||
227 | |||
228 | ## end gnulib module gettext-h | ||
229 | |||
230 | ## begin gnulib module inet_ntop | ||
231 | |||
232 | |||
233 | EXTRA_DIST += inet_ntop.c inet_ntop.h | ||
234 | |||
235 | EXTRA_libgnu_a_SOURCES += inet_ntop.c | ||
236 | |||
237 | ## end gnulib module inet_ntop | ||
238 | |||
239 | ## begin gnulib module intprops | ||
240 | |||
241 | |||
242 | EXTRA_DIST += intprops.h | ||
243 | |||
244 | ## end gnulib module intprops | ||
245 | |||
246 | ## begin gnulib module malloc | ||
247 | |||
248 | |||
249 | EXTRA_DIST += malloc.c | ||
250 | |||
251 | EXTRA_libgnu_a_SOURCES += malloc.c | ||
252 | |||
253 | ## end gnulib module malloc | ||
254 | |||
255 | ## begin gnulib module mbchar | ||
256 | |||
257 | |||
258 | EXTRA_DIST += mbchar.c mbchar.h | ||
259 | |||
260 | EXTRA_libgnu_a_SOURCES += mbchar.c | ||
261 | |||
262 | ## end gnulib module mbchar | ||
263 | |||
264 | ## begin gnulib module mbuiter | ||
265 | |||
266 | libgnu_a_SOURCES += mbuiter.h | ||
267 | |||
268 | ## end gnulib module mbuiter | ||
269 | |||
270 | ## begin gnulib module memchr | ||
271 | |||
272 | |||
273 | EXTRA_DIST += memchr.c | ||
274 | |||
275 | EXTRA_libgnu_a_SOURCES += memchr.c | ||
276 | |||
277 | ## end gnulib module memchr | ||
278 | |||
279 | ## begin gnulib module minmax | ||
280 | |||
281 | libgnu_a_SOURCES += minmax.h | ||
282 | |||
283 | ## end gnulib module minmax | ||
284 | |||
285 | ## begin gnulib module mountlist | ||
286 | |||
287 | |||
288 | EXTRA_DIST += mountlist.c mountlist.h | ||
289 | |||
290 | EXTRA_libgnu_a_SOURCES += mountlist.c | ||
291 | |||
292 | ## end gnulib module mountlist | ||
293 | |||
294 | ## begin gnulib module netinet_in | ||
295 | |||
296 | BUILT_SOURCES += $(NETINET_IN_H) | ||
297 | |||
298 | # We need the following in order to create <netinet/in.h> when the system | ||
299 | # doesn't have one. | ||
300 | netinet/in.h: | ||
301 | test -d netinet || mkdir netinet | ||
302 | rm -f $@-t $@ | ||
303 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
304 | echo '#include <sys/socket.h>'; \ | ||
305 | } > $@-t | ||
306 | mv $@-t $@ | ||
307 | MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t | ||
308 | MOSTLYCLEANDIRS += netinet | ||
309 | |||
310 | ## end gnulib module netinet_in | ||
311 | |||
312 | ## begin gnulib module regex | ||
313 | |||
314 | |||
315 | EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c | ||
316 | |||
317 | EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c | ||
318 | |||
319 | ## end gnulib module regex | ||
320 | |||
321 | ## begin gnulib module safe-read | ||
322 | |||
323 | |||
324 | EXTRA_DIST += safe-read.c safe-read.h | ||
325 | |||
326 | EXTRA_libgnu_a_SOURCES += safe-read.c | ||
327 | |||
328 | ## end gnulib module safe-read | ||
329 | |||
330 | ## begin gnulib module safe-write | ||
331 | |||
332 | |||
333 | EXTRA_DIST += safe-write.c safe-write.h | ||
334 | |||
335 | EXTRA_libgnu_a_SOURCES += safe-write.c | ||
336 | |||
337 | ## end gnulib module safe-write | ||
338 | |||
339 | ## begin gnulib module size_max | ||
340 | |||
341 | libgnu_a_SOURCES += size_max.h | ||
342 | |||
343 | ## end gnulib module size_max | ||
344 | |||
345 | ## begin gnulib module snprintf | ||
346 | |||
347 | |||
348 | EXTRA_DIST += snprintf.c snprintf.h | ||
349 | |||
350 | EXTRA_libgnu_a_SOURCES += snprintf.c | ||
351 | |||
352 | ## end gnulib module snprintf | ||
353 | |||
354 | ## begin gnulib module stdbool | ||
355 | |||
356 | BUILT_SOURCES += $(STDBOOL_H) | ||
357 | |||
358 | # We need the following in order to create <stdbool.h> when the system | ||
359 | # doesn't have one that works. | ||
360 | stdbool.h: stdbool_.h | ||
361 | rm -f $@-t $@ | ||
362 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
363 | sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool_.h; \ | ||
364 | } > $@-t | ||
365 | mv $@-t $@ | ||
366 | MOSTLYCLEANFILES += stdbool.h stdbool.h-t | ||
367 | |||
368 | EXTRA_DIST += stdbool_.h | ||
369 | |||
370 | ## end gnulib module stdbool | ||
371 | |||
372 | ## begin gnulib module stdint | ||
373 | |||
374 | BUILT_SOURCES += $(STDINT_H) | ||
375 | |||
376 | # We need the following in order to create <stdint.h> when the system | ||
377 | # doesn't have one that works with the given compiler. | ||
378 | stdint.h: stdint_.h | ||
379 | rm -f $@-t $@ | ||
380 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
381 | sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ | ||
382 | -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \ | ||
383 | -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ | ||
384 | -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ | ||
385 | -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ | ||
386 | -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ | ||
387 | -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \ | ||
388 | -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \ | ||
389 | -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ | ||
390 | -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ | ||
391 | -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \ | ||
392 | -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \ | ||
393 | -e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \ | ||
394 | -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \ | ||
395 | -e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \ | ||
396 | -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \ | ||
397 | -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \ | ||
398 | -e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \ | ||
399 | -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ | ||
400 | -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ | ||
401 | -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ | ||
402 | < $(srcdir)/stdint_.h; \ | ||
403 | } > $@-t | ||
404 | mv $@-t $@ | ||
405 | MOSTLYCLEANFILES += stdint.h stdint.h-t | ||
406 | |||
407 | EXTRA_DIST += stdint_.h | ||
408 | |||
409 | ## end gnulib module stdint | ||
410 | |||
411 | ## begin gnulib module strcase | ||
412 | |||
413 | |||
414 | EXTRA_DIST += strcase.h strcasecmp.c strncasecmp.c | ||
415 | |||
416 | EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c | ||
417 | |||
418 | ## end gnulib module strcase | ||
419 | |||
420 | ## begin gnulib module strdup | ||
421 | |||
422 | |||
423 | EXTRA_DIST += strdup.c strdup.h | ||
424 | |||
425 | EXTRA_libgnu_a_SOURCES += strdup.c | ||
426 | |||
427 | ## end gnulib module strdup | ||
428 | |||
429 | ## begin gnulib module strndup | ||
430 | |||
431 | |||
432 | EXTRA_DIST += strndup.c strndup.h | ||
433 | |||
434 | EXTRA_libgnu_a_SOURCES += strndup.c | ||
435 | |||
436 | ## end gnulib module strndup | ||
437 | |||
438 | ## begin gnulib module strnlen | ||
439 | |||
440 | |||
441 | EXTRA_DIST += strnlen.c strnlen.h | ||
442 | |||
443 | EXTRA_libgnu_a_SOURCES += strnlen.c | ||
444 | |||
445 | ## end gnulib module strnlen | ||
446 | |||
447 | ## begin gnulib module strnlen1 | ||
448 | |||
449 | libgnu_a_SOURCES += strnlen1.h strnlen1.c | ||
450 | |||
451 | ## end gnulib module strnlen1 | ||
452 | |||
453 | ## begin gnulib module sys_socket | ||
454 | |||
455 | BUILT_SOURCES += $(SYS_SOCKET_H) | ||
456 | |||
457 | # We need the following in order to create <sys/socket.h> when the system | ||
458 | # doesn't have one that works with the given compiler. | ||
459 | sys/socket.h: socket_.h | ||
460 | @MKDIR_P@ sys | ||
461 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
462 | cat $(srcdir)/socket_.h; \ | ||
463 | } > $@-t | ||
464 | mv -f $@-t $@ | ||
465 | MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t | ||
466 | MOSTLYCLEANDIRS += sys | ||
467 | |||
468 | EXTRA_DIST += socket_.h | ||
469 | |||
470 | ## end gnulib module sys_socket | ||
471 | |||
472 | ## begin gnulib module unistd | ||
473 | |||
474 | BUILT_SOURCES += $(UNISTD_H) | ||
475 | |||
476 | # We need the following in order to create an empty placeholder for | ||
477 | # <unistd.h> when the system doesn't have one. | ||
478 | unistd.h: unistd_.h | ||
479 | rm -f $@-t $@ | ||
480 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
481 | sed -e 's|@''ABSOLUTE_UNISTD_H''@|$(ABSOLUTE_UNISTD_H)|g' \ | ||
482 | < $(srcdir)/unistd_.h; \ | ||
483 | } > $@-t | ||
484 | mv $@-t $@ | ||
485 | MOSTLYCLEANFILES += unistd.h unistd.h-t | ||
486 | |||
487 | EXTRA_DIST += unistd_.h | ||
488 | |||
489 | ## end gnulib module unistd | ||
490 | |||
491 | ## begin gnulib module unistd-safer | ||
492 | |||
493 | |||
494 | EXTRA_DIST += dup-safer.c fd-safer.c pipe-safer.c unistd--.h unistd-safer.h | ||
495 | |||
496 | EXTRA_libgnu_a_SOURCES += dup-safer.c fd-safer.c pipe-safer.c | ||
497 | |||
498 | ## end gnulib module unistd-safer | ||
499 | |||
500 | ## begin gnulib module vasnprintf | ||
501 | |||
502 | |||
503 | EXTRA_DIST += asnprintf.c printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h | ||
504 | |||
505 | EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c | ||
506 | |||
507 | ## end gnulib module vasnprintf | ||
508 | |||
509 | ## begin gnulib module vasprintf | ||
510 | |||
511 | |||
512 | EXTRA_DIST += asprintf.c vasprintf.c vasprintf.h | ||
513 | |||
514 | EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c | ||
515 | |||
516 | ## end gnulib module vasprintf | ||
517 | |||
518 | ## begin gnulib module vsnprintf | ||
519 | |||
520 | |||
521 | EXTRA_DIST += vsnprintf.c vsnprintf.h | ||
522 | |||
523 | EXTRA_libgnu_a_SOURCES += vsnprintf.c | ||
524 | |||
525 | ## end gnulib module vsnprintf | ||
526 | |||
527 | ## begin gnulib module wchar | ||
528 | |||
529 | BUILT_SOURCES += $(WCHAR_H) | ||
530 | |||
531 | # We need the following in order to create <wchar.h> when the system | ||
532 | # version does not work standalone. | ||
533 | wchar.h: wchar_.h | ||
534 | rm -f $@-t $@ | ||
535 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
536 | sed -e 's|@''ABSOLUTE_WCHAR_H''@|$(ABSOLUTE_WCHAR_H)|g' \ | ||
537 | < $(srcdir)/wchar_.h; \ | ||
538 | } > $@-t | ||
539 | mv $@-t $@ | ||
540 | MOSTLYCLEANFILES += wchar.h wchar.h-t | ||
541 | |||
542 | EXTRA_DIST += wchar_.h | ||
543 | |||
544 | ## end gnulib module wchar | ||
545 | |||
546 | ## begin gnulib module wctype | ||
547 | |||
548 | BUILT_SOURCES += $(WCTYPE_H) | ||
549 | |||
550 | # We need the following in order to create <wctype.h> when the system | ||
551 | # doesn't have one that works with the given compiler. | ||
552 | wctype.h: wctype_.h | ||
553 | rm -f $@-t $@ | ||
554 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
555 | sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ | ||
556 | -e 's|@''ABSOLUTE_WCTYPE_H''@|$(ABSOLUTE_WCTYPE_H)|g' \ | ||
557 | -e 's/@''HAVE_WCTYPE_CTMP_BUG''@/$(HAVE_WCTYPE_CTMP_BUG)/g' \ | ||
558 | -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ | ||
559 | < $(srcdir)/wctype_.h; \ | ||
560 | } > $@-t | ||
561 | mv $@-t $@ | ||
562 | MOSTLYCLEANFILES += wctype.h wctype.h-t | ||
563 | |||
564 | EXTRA_DIST += wctype_.h | ||
565 | |||
566 | ## end gnulib module wctype | ||
567 | |||
568 | ## begin gnulib module wcwidth | ||
569 | |||
570 | libgnu_a_SOURCES += wcwidth.h | ||
571 | |||
572 | ## end gnulib module wcwidth | ||
573 | |||
574 | ## begin gnulib module xalloc | ||
575 | |||
576 | |||
577 | EXTRA_DIST += xalloc.h xmalloc.c | ||
578 | |||
579 | EXTRA_libgnu_a_SOURCES += xmalloc.c | ||
580 | |||
581 | ## end gnulib module xalloc | ||
582 | |||
583 | ## begin gnulib module xalloc-die | ||
584 | |||
585 | libgnu_a_SOURCES += xalloc-die.c | ||
586 | |||
587 | ## end gnulib module xalloc-die | ||
588 | |||
589 | ## begin gnulib module xsize | ||
590 | |||
591 | libgnu_a_SOURCES += xsize.h | ||
592 | |||
593 | ## end gnulib module xsize | ||
594 | |||
595 | ## begin gnulib module xstrndup | ||
596 | |||
597 | libgnu_a_SOURCES += xstrndup.h xstrndup.c | ||
598 | |||
599 | ## end gnulib module xstrndup | ||
600 | |||
601 | |||
602 | mostlyclean-local: mostlyclean-generic | ||
603 | @for dir in '' $(MOSTLYCLEANDIRS); do \ | ||
604 | if test -n "$$dir" && test -d $$dir; then \ | ||
605 | echo "rmdir $$dir"; rmdir $$dir; \ | ||
606 | fi; \ | ||
607 | done | ||
diff --git a/lib/alloca.c b/gl/alloca.c index d1d5447..3a1f4e2 100644 --- a/lib/alloca.c +++ b/gl/alloca.c | |||
@@ -21,9 +21,7 @@ | |||
21 | allocating any. It is a good idea to use alloca(0) in | 21 | allocating any. It is a good idea to use alloca(0) in |
22 | your main control loop, etc. to force garbage collection. */ | 22 | your main control loop, etc. to force garbage collection. */ |
23 | 23 | ||
24 | #ifdef HAVE_CONFIG_H | 24 | #include <config.h> |
25 | # include <config.h> | ||
26 | #endif | ||
27 | 25 | ||
28 | #include <alloca.h> | 26 | #include <alloca.h> |
29 | 27 | ||
diff --git a/lib/alloca_.h b/gl/alloca_.h index 3e3fdf4..dd0b3e9 100644 --- a/lib/alloca_.h +++ b/gl/alloca_.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Memory allocation on the stack. | 1 | /* Memory allocation on the stack. |
2 | 2 | ||
3 | Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software | 3 | Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software |
4 | Foundation, Inc. | 4 | Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify it | 6 | This program is free software; you can redistribute it and/or modify it |
@@ -34,19 +34,21 @@ | |||
34 | request, the program just crashes. | 34 | request, the program just crashes. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #ifdef __GNUC__ | 37 | #ifndef alloca |
38 | # define alloca __builtin_alloca | 38 | # ifdef __GNUC__ |
39 | #elif defined _AIX | 39 | # define alloca __builtin_alloca |
40 | # define alloca __alloca | 40 | # elif defined _AIX |
41 | #elif defined _MSC_VER | 41 | # define alloca __alloca |
42 | # include <malloc.h> | 42 | # elif defined _MSC_VER |
43 | # define alloca _alloca | 43 | # include <malloc.h> |
44 | #else | 44 | # define alloca _alloca |
45 | # include <stddef.h> | 45 | # else |
46 | # ifdef __cplusplus | 46 | # include <stddef.h> |
47 | # ifdef __cplusplus | ||
47 | extern "C" | 48 | extern "C" |
48 | # endif | 49 | # endif |
49 | void *alloca (size_t); | 50 | void *alloca (size_t); |
51 | # endif | ||
50 | #endif | 52 | #endif |
51 | 53 | ||
52 | #endif /* _GNULIB_ALLOCA_H */ | 54 | #endif /* _GNULIB_ALLOCA_H */ |
diff --git a/gl/asnprintf.c b/gl/asnprintf.c new file mode 100644 index 0000000..26c3988 --- /dev/null +++ b/gl/asnprintf.c | |||
@@ -0,0 +1,35 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "vasnprintf.h" | ||
22 | |||
23 | #include <stdarg.h> | ||
24 | |||
25 | char * | ||
26 | asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) | ||
27 | { | ||
28 | va_list args; | ||
29 | char *result; | ||
30 | |||
31 | va_start (args, format); | ||
32 | result = vasnprintf (resultbuf, lengthp, format, args); | ||
33 | va_end (args); | ||
34 | return result; | ||
35 | } | ||
diff --git a/gl/asprintf.c b/gl/asprintf.c new file mode 100644 index 0000000..29ac6cf --- /dev/null +++ b/gl/asprintf.c | |||
@@ -0,0 +1,35 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "vasprintf.h" | ||
22 | |||
23 | #include <stdarg.h> | ||
24 | |||
25 | int | ||
26 | asprintf (char **resultp, const char *format, ...) | ||
27 | { | ||
28 | va_list args; | ||
29 | int result; | ||
30 | |||
31 | va_start (args, format); | ||
32 | result = vasprintf (resultp, format, args); | ||
33 | va_end (args); | ||
34 | return result; | ||
35 | } | ||
diff --git a/gl/basename.c b/gl/basename.c new file mode 100644 index 0000000..fbe17ff --- /dev/null +++ b/gl/basename.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* basename.c -- return the last element in a file name | ||
2 | |||
3 | Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free | ||
4 | Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #include <config.h> | ||
21 | |||
22 | #include "dirname.h" | ||
23 | |||
24 | #include <string.h> | ||
25 | #include "xalloc.h" | ||
26 | #include "xstrndup.h" | ||
27 | |||
28 | /* Return the address of the last file name component of NAME. If | ||
29 | NAME has no relative file name components because it is a file | ||
30 | system root, return the empty string. */ | ||
31 | |||
32 | char * | ||
33 | last_component (char const *name) | ||
34 | { | ||
35 | char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); | ||
36 | char const *p; | ||
37 | bool saw_slash = false; | ||
38 | |||
39 | while (ISSLASH (*base)) | ||
40 | base++; | ||
41 | |||
42 | for (p = base; *p; p++) | ||
43 | { | ||
44 | if (ISSLASH (*p)) | ||
45 | saw_slash = true; | ||
46 | else if (saw_slash) | ||
47 | { | ||
48 | base = p; | ||
49 | saw_slash = false; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | return (char *) base; | ||
54 | } | ||
55 | |||
56 | |||
57 | /* In general, we can't use the builtin `basename' function if available, | ||
58 | since it has different meanings in different environments. | ||
59 | In some environments the builtin `basename' modifies its argument. | ||
60 | |||
61 | Return the last file name component of NAME, allocated with | ||
62 | xmalloc. On systems with drive letters, a leading "./" | ||
63 | distinguishes relative names that would otherwise look like a drive | ||
64 | letter. Unlike POSIX basename(), NAME cannot be NULL, | ||
65 | base_name("") returns "", and the first trailing slash is not | ||
66 | stripped. | ||
67 | |||
68 | If lstat (NAME) would succeed, then { chdir (dir_name (NAME)); | ||
69 | lstat (base_name (NAME)); } will access the same file. Likewise, | ||
70 | if the sequence { chdir (dir_name (NAME)); | ||
71 | rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME | ||
72 | to "foo" in the same directory NAME was in. */ | ||
73 | |||
74 | char * | ||
75 | base_name (char const *name) | ||
76 | { | ||
77 | char const *base = last_component (name); | ||
78 | size_t length; | ||
79 | |||
80 | /* If there is no last component, then name is a file system root or the | ||
81 | empty string. */ | ||
82 | if (! *base) | ||
83 | return xstrndup (name, base_len (name)); | ||
84 | |||
85 | /* Collapse a sequence of trailing slashes into one. */ | ||
86 | length = base_len (base); | ||
87 | if (ISSLASH (base[length])) | ||
88 | length++; | ||
89 | |||
90 | /* On systems with drive letters, `a/b:c' must return `./b:c' rather | ||
91 | than `b:c' to avoid confusion with a drive letter. On systems | ||
92 | with pure POSIX semantics, this is not an issue. */ | ||
93 | if (FILE_SYSTEM_PREFIX_LEN (base)) | ||
94 | { | ||
95 | char *p = xmalloc (length + 3); | ||
96 | p[0] = '.'; | ||
97 | p[1] = '/'; | ||
98 | memcpy (p + 2, base, length); | ||
99 | p[length + 2] = '\0'; | ||
100 | return p; | ||
101 | } | ||
102 | |||
103 | /* Finally, copy the basename. */ | ||
104 | return xstrndup (base, length); | ||
105 | } | ||
106 | |||
107 | /* Return the length of the basename NAME. Typically NAME is the | ||
108 | value returned by base_name or last_component. Act like strlen | ||
109 | (NAME), except omit all trailing slashes. */ | ||
110 | |||
111 | size_t | ||
112 | base_len (char const *name) | ||
113 | { | ||
114 | size_t len; | ||
115 | size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); | ||
116 | |||
117 | for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) | ||
118 | continue; | ||
119 | |||
120 | if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1 | ||
121 | && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2]) | ||
122 | return 2; | ||
123 | |||
124 | if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len | ||
125 | && len == prefix_len && ISSLASH (name[prefix_len])) | ||
126 | return prefix_len + 1; | ||
127 | |||
128 | return len; | ||
129 | } | ||
diff --git a/lib/c-strtod.c b/gl/c-strtod.c index 031f5f8..2234ed0 100644 --- a/lib/c-strtod.c +++ b/gl/c-strtod.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Convert string to double, using the C locale. | 1 | /* Convert string to double, using the C locale. |
2 | 2 | ||
3 | Copyright (C) 2003, 2004 Free Software Foundation, Inc. | 3 | Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -18,9 +18,7 @@ | |||
18 | 18 | ||
19 | /* Written by Paul Eggert. */ | 19 | /* Written by Paul Eggert. */ |
20 | 20 | ||
21 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
22 | # include <config.h> | ||
23 | #endif | ||
24 | 22 | ||
25 | #include "c-strtod.h" | 23 | #include "c-strtod.h" |
26 | 24 | ||
diff --git a/lib/c-strtod.h b/gl/c-strtod.h index ca9a9e7..ca9a9e7 100644 --- a/lib/c-strtod.h +++ b/gl/c-strtod.h | |||
diff --git a/lib/cloexec.c b/gl/cloexec.c index cf2308c..6480006 100644 --- a/lib/cloexec.c +++ b/gl/cloexec.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* closexec.c - set or clear the close-on-exec descriptor flag | 1 | /* closexec.c - set or clear the close-on-exec descriptor flag |
2 | Copyright (C) 1991, 2004, 2005 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1991, 2004, 2005, 2006 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +18,7 @@ | |||
17 | 18 | ||
18 | The code is taken from glibc/manual/llio.texi */ | 19 | The code is taken from glibc/manual/llio.texi */ |
19 | 20 | ||
20 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 22 | ||
24 | #include "cloexec.h" | 23 | #include "cloexec.h" |
25 | 24 | ||
diff --git a/lib/cloexec.h b/gl/cloexec.h index c25921d..c25921d 100644 --- a/lib/cloexec.h +++ b/gl/cloexec.h | |||
diff --git a/lib/creat-safer.c b/gl/creat-safer.c index 4588de3..f4a2e59 100644 --- a/lib/creat-safer.c +++ b/gl/creat-safer.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* Invoke creat, but avoid some glitches. | 1 | /* Invoke creat, but avoid some glitches. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +18,7 @@ | |||
17 | 18 | ||
18 | /* Written by Jim Meyering. */ | 19 | /* Written by Jim Meyering. */ |
19 | 20 | ||
20 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 22 | ||
24 | #include "fcntl-safer.h" | 23 | #include "fcntl-safer.h" |
25 | 24 | ||
diff --git a/gl/dirname.c b/gl/dirname.c new file mode 100644 index 0000000..16552c6 --- /dev/null +++ b/gl/dirname.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* dirname.c -- return all but the last element in a file name | ||
2 | |||
3 | Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software | ||
4 | Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #include <config.h> | ||
21 | |||
22 | #include "dirname.h" | ||
23 | |||
24 | #include <string.h> | ||
25 | #include "xalloc.h" | ||
26 | |||
27 | /* Return the length of the prefix of FILE that will be used by | ||
28 | dir_name. If FILE is in the working directory, this returns zero | ||
29 | even though `dir_name (FILE)' will return ".". Works properly even | ||
30 | if there are trailing slashes (by effectively ignoring them). */ | ||
31 | |||
32 | size_t | ||
33 | dir_len (char const *file) | ||
34 | { | ||
35 | size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file); | ||
36 | size_t length; | ||
37 | |||
38 | /* Advance prefix_length beyond important leading slashes. */ | ||
39 | prefix_length += (prefix_length != 0 | ||
40 | ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
41 | && ISSLASH (file[prefix_length])) | ||
42 | : (ISSLASH (file[0]) | ||
43 | ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT | ||
44 | && ISSLASH (file[1]) && ! ISSLASH (file[2]) | ||
45 | ? 2 : 1)) | ||
46 | : 0)); | ||
47 | |||
48 | /* Strip the basename and any redundant slashes before it. */ | ||
49 | for (length = last_component (file) - file; | ||
50 | prefix_length < length; length--) | ||
51 | if (! ISSLASH (file[length - 1])) | ||
52 | break; | ||
53 | return length; | ||
54 | } | ||
55 | |||
56 | |||
57 | /* In general, we can't use the builtin `dirname' function if available, | ||
58 | since it has different meanings in different environments. | ||
59 | In some environments the builtin `dirname' modifies its argument. | ||
60 | |||
61 | Return the leading directories part of FILE, allocated with xmalloc. | ||
62 | Works properly even if there are trailing slashes (by effectively | ||
63 | ignoring them). Unlike POSIX dirname(), FILE cannot be NULL. | ||
64 | |||
65 | If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); | ||
66 | lstat (base_name (FILE)); } will access the same file. Likewise, | ||
67 | if the sequence { chdir (dir_name (FILE)); | ||
68 | rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE | ||
69 | to "foo" in the same directory FILE was in. */ | ||
70 | |||
71 | char * | ||
72 | dir_name (char const *file) | ||
73 | { | ||
74 | size_t length = dir_len (file); | ||
75 | bool append_dot = (length == 0 | ||
76 | || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
77 | && length == FILE_SYSTEM_PREFIX_LEN (file) | ||
78 | && file[2] != '\0' && ! ISSLASH (file[2]))); | ||
79 | char *dir = xmalloc (length + append_dot + 1); | ||
80 | memcpy (dir, file, length); | ||
81 | if (append_dot) | ||
82 | dir[length++] = '.'; | ||
83 | dir[length] = '\0'; | ||
84 | return dir; | ||
85 | } | ||
diff --git a/lib/dirname.h b/gl/dirname.h index 1688ae8..91e7ed3 100644 --- a/lib/dirname.h +++ b/gl/dirname.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Take file names apart into directory and base names. | 1 | /* Take file names apart into directory and base names. |
2 | 2 | ||
3 | Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. | 3 | Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -31,16 +31,39 @@ | |||
31 | # endif | 31 | # endif |
32 | 32 | ||
33 | # ifndef FILE_SYSTEM_PREFIX_LEN | 33 | # ifndef FILE_SYSTEM_PREFIX_LEN |
34 | # define FILE_SYSTEM_PREFIX_LEN(File_name) 0 | 34 | # if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX |
35 | /* This internal macro assumes ASCII, but all hosts that support drive | ||
36 | letters use ASCII. */ | ||
37 | # define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \ | ||
38 | <= 'z' - 'a') | ||
39 | # define FILE_SYSTEM_PREFIX_LEN(Filename) \ | ||
40 | (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) | ||
41 | # else | ||
42 | # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 | ||
43 | # endif | ||
35 | # endif | 44 | # endif |
36 | 45 | ||
37 | # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) | 46 | # ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE |
47 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 | ||
48 | # endif | ||
49 | |||
50 | # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT | ||
51 | # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 | ||
52 | # endif | ||
53 | |||
54 | # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
55 | # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) | ||
56 | # else | ||
57 | # define IS_ABSOLUTE_FILE_NAME(F) \ | ||
58 | (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) | ||
59 | # endif | ||
38 | # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) | 60 | # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) |
39 | 61 | ||
40 | char *base_name (char const *file); | 62 | char *base_name (char const *file); |
41 | char *dir_name (char const *file); | 63 | char *dir_name (char const *file); |
42 | size_t base_len (char const *file); | 64 | size_t base_len (char const *file); |
43 | size_t dir_len (char const *file); | 65 | size_t dir_len (char const *file); |
66 | char *last_component (char const *file); | ||
44 | 67 | ||
45 | bool strip_trailing_slashes (char *file); | 68 | bool strip_trailing_slashes (char *file); |
46 | 69 | ||
diff --git a/lib/dup-safer.c b/gl/dup-safer.c index 8cbee70..7b12b61 100644 --- a/lib/dup-safer.c +++ b/gl/dup-safer.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* Invoke dup, but avoid some glitches. | 1 | /* Invoke dup, but avoid some glitches. |
2 | Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +18,7 @@ | |||
17 | 18 | ||
18 | /* Written by Paul Eggert. */ | 19 | /* Written by Paul Eggert. */ |
19 | 20 | ||
20 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 22 | ||
24 | #include "unistd-safer.h" | 23 | #include "unistd-safer.h" |
25 | 24 | ||
@@ -36,7 +35,7 @@ | |||
36 | int | 35 | int |
37 | dup_safer (int fd) | 36 | dup_safer (int fd) |
38 | { | 37 | { |
39 | #ifdef F_DUPFD | 38 | #if defined F_DUPFD && !defined FCHDIR_REPLACEMENT |
40 | return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); | 39 | return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); |
41 | #else | 40 | #else |
42 | /* fd_safer calls us back, but eventually the recursion unwinds and | 41 | /* fd_safer calls us back, but eventually the recursion unwinds and |
@@ -1,5 +1,5 @@ | |||
1 | /* Error handler for noninteractive utilities | 1 | /* Error handler for noninteractive utilities |
2 | Copyright (C) 1990-1998, 2000-2003, 2004 Free Software Foundation, Inc. | 2 | Copyright (C) 1990-1998, 2000-2005, 2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ | 19 | /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ |
20 | 20 | ||
21 | #ifdef HAVE_CONFIG_H | 21 | #if !_LIBC |
22 | # include <config.h> | 22 | # include <config.h> |
23 | #endif | 23 | #endif |
24 | 24 | ||
@@ -34,6 +34,9 @@ | |||
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #ifdef _LIBC | 36 | #ifdef _LIBC |
37 | # include <libintl.h> | ||
38 | # include <stdbool.h> | ||
39 | # include <stdint.h> | ||
37 | # include <wchar.h> | 40 | # include <wchar.h> |
38 | # define mbsrtowcs __mbsrtowcs | 41 | # define mbsrtowcs __mbsrtowcs |
39 | #endif | 42 | #endif |
@@ -59,6 +62,7 @@ unsigned int error_message_count; | |||
59 | 62 | ||
60 | # define program_name program_invocation_name | 63 | # define program_name program_invocation_name |
61 | # include <errno.h> | 64 | # include <errno.h> |
65 | # include <limits.h> | ||
62 | # include <libio/libioP.h> | 66 | # include <libio/libioP.h> |
63 | 67 | ||
64 | /* In GNU libc we want do not want to use the common name `error' directly. | 68 | /* In GNU libc we want do not want to use the common name `error' directly. |
@@ -88,23 +92,19 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
88 | char *strerror_r (); | 92 | char *strerror_r (); |
89 | # endif | 93 | # endif |
90 | 94 | ||
91 | # ifndef SIZE_MAX | ||
92 | # define SIZE_MAX ((size_t) -1) | ||
93 | # endif | ||
94 | |||
95 | /* The calling program should define program_name and set it to the | 95 | /* The calling program should define program_name and set it to the |
96 | name of the executing program. */ | 96 | name of the executing program. */ |
97 | extern char *program_name; | 97 | extern char *program_name; |
98 | 98 | ||
99 | # if HAVE_STRERROR_R || defined strerror_r | 99 | # if HAVE_STRERROR_R || defined strerror_r |
100 | # define __strerror_r strerror_r | 100 | # define __strerror_r strerror_r |
101 | # endif | 101 | # endif /* HAVE_STRERROR_R || defined strerror_r */ |
102 | #endif /* not _LIBC */ | 102 | #endif /* not _LIBC */ |
103 | 103 | ||
104 | static void | 104 | static void |
105 | print_errno_message (int errnum) | 105 | print_errno_message (int errnum) |
106 | { | 106 | { |
107 | char const *s = NULL; | 107 | char const *s; |
108 | 108 | ||
109 | #if defined HAVE_STRERROR_R || _LIBC | 109 | #if defined HAVE_STRERROR_R || _LIBC |
110 | char errbuf[1024]; | 110 | char errbuf[1024]; |
@@ -113,23 +113,23 @@ print_errno_message (int errnum) | |||
113 | # else | 113 | # else |
114 | if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) | 114 | if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) |
115 | s = errbuf; | 115 | s = errbuf; |
116 | else | ||
117 | s = 0; | ||
116 | # endif | 118 | # endif |
119 | #else | ||
120 | s = strerror (errnum); | ||
117 | #endif | 121 | #endif |
118 | 122 | ||
119 | #if !_LIBC | 123 | #if !_LIBC |
120 | if (! s && ! (s = strerror (errnum))) | 124 | if (! s) |
121 | s = _("Unknown system error"); | 125 | s = _("Unknown system error"); |
122 | #endif | 126 | #endif |
123 | 127 | ||
124 | #if _LIBC | 128 | #if _LIBC |
125 | if (_IO_fwide (stderr, 0) > 0) | 129 | __fxprintf (NULL, ": %s", s); |
126 | { | 130 | #else |
127 | __fwprintf (stderr, L": %s", s); | ||
128 | return; | ||
129 | } | ||
130 | #endif | ||
131 | |||
132 | fprintf (stderr, ": %s", s); | 131 | fprintf (stderr, ": %s", s); |
132 | #endif | ||
133 | } | 133 | } |
134 | 134 | ||
135 | static void | 135 | static void |
@@ -140,26 +140,65 @@ error_tail (int status, int errnum, const char *message, va_list args) | |||
140 | { | 140 | { |
141 | # define ALLOCA_LIMIT 2000 | 141 | # define ALLOCA_LIMIT 2000 |
142 | size_t len = strlen (message) + 1; | 142 | size_t len = strlen (message) + 1; |
143 | const wchar_t *wmessage = L"out of memory"; | 143 | wchar_t *wmessage = NULL; |
144 | wchar_t *wbuf = (len < ALLOCA_LIMIT | 144 | mbstate_t st; |
145 | ? alloca (len * sizeof *wbuf) | 145 | size_t res; |
146 | : len <= SIZE_MAX / sizeof *wbuf | 146 | const char *tmp; |
147 | ? malloc (len * sizeof *wbuf) | 147 | bool use_malloc = false; |
148 | : NULL); | 148 | |
149 | 149 | while (1) | |
150 | if (wbuf) | ||
151 | { | 150 | { |
152 | size_t res; | 151 | if (__libc_use_alloca (len * sizeof (wchar_t))) |
153 | mbstate_t st; | 152 | wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); |
154 | const char *tmp = message; | 153 | else |
154 | { | ||
155 | if (!use_malloc) | ||
156 | wmessage = NULL; | ||
157 | |||
158 | wchar_t *p = (wchar_t *) realloc (wmessage, | ||
159 | len * sizeof (wchar_t)); | ||
160 | if (p == NULL) | ||
161 | { | ||
162 | free (wmessage); | ||
163 | fputws_unlocked (L"out of memory\n", stderr); | ||
164 | return; | ||
165 | } | ||
166 | wmessage = p; | ||
167 | use_malloc = true; | ||
168 | } | ||
169 | |||
155 | memset (&st, '\0', sizeof (st)); | 170 | memset (&st, '\0', sizeof (st)); |
156 | res = mbsrtowcs (wbuf, &tmp, len, &st); | 171 | tmp = message; |
157 | wmessage = res == (size_t) -1 ? L"???" : wbuf; | 172 | |
173 | res = mbsrtowcs (wmessage, &tmp, len, &st); | ||
174 | if (res != len) | ||
175 | break; | ||
176 | |||
177 | if (__builtin_expect (len >= SIZE_MAX / 2, 0)) | ||
178 | { | ||
179 | /* This really should not happen if everything is fine. */ | ||
180 | res = (size_t) -1; | ||
181 | break; | ||
182 | } | ||
183 | |||
184 | len *= 2; | ||
185 | } | ||
186 | |||
187 | if (res == (size_t) -1) | ||
188 | { | ||
189 | /* The string cannot be converted. */ | ||
190 | if (use_malloc) | ||
191 | { | ||
192 | free (wmessage); | ||
193 | use_malloc = false; | ||
194 | } | ||
195 | wmessage = (wchar_t *) L"???"; | ||
158 | } | 196 | } |
159 | 197 | ||
160 | __vfwprintf (stderr, wmessage, args); | 198 | __vfwprintf (stderr, wmessage, args); |
161 | if (! (len < ALLOCA_LIMIT)) | 199 | |
162 | free (wbuf); | 200 | if (use_malloc) |
201 | free (wmessage); | ||
163 | } | 202 | } |
164 | else | 203 | else |
165 | #endif | 204 | #endif |
@@ -170,11 +209,10 @@ error_tail (int status, int errnum, const char *message, va_list args) | |||
170 | if (errnum) | 209 | if (errnum) |
171 | print_errno_message (errnum); | 210 | print_errno_message (errnum); |
172 | #if _LIBC | 211 | #if _LIBC |
173 | if (_IO_fwide (stderr, 0) > 0) | 212 | __fxprintf (NULL, "\n"); |
174 | putwc (L'\n', stderr); | 213 | #else |
175 | else | 214 | putc ('\n', stderr); |
176 | #endif | 215 | #endif |
177 | putc ('\n', stderr); | ||
178 | fflush (stderr); | 216 | fflush (stderr); |
179 | if (status) | 217 | if (status) |
180 | exit (status); | 218 | exit (status); |
@@ -207,11 +245,10 @@ error (int status, int errnum, const char *message, ...) | |||
207 | else | 245 | else |
208 | { | 246 | { |
209 | #if _LIBC | 247 | #if _LIBC |
210 | if (_IO_fwide (stderr, 0) > 0) | 248 | __fxprintf (NULL, "%s: ", program_name); |
211 | __fwprintf (stderr, L"%s: ", program_name); | 249 | #else |
212 | else | 250 | fprintf (stderr, "%s: ", program_name); |
213 | #endif | 251 | #endif |
214 | fprintf (stderr, "%s: ", program_name); | ||
215 | } | 252 | } |
216 | 253 | ||
217 | va_start (args, message); | 254 | va_start (args, message); |
@@ -267,22 +304,19 @@ error_at_line (int status, int errnum, const char *file_name, | |||
267 | else | 304 | else |
268 | { | 305 | { |
269 | #if _LIBC | 306 | #if _LIBC |
270 | if (_IO_fwide (stderr, 0) > 0) | 307 | __fxprintf (NULL, "%s:", program_name); |
271 | __fwprintf (stderr, L"%s: ", program_name); | 308 | #else |
272 | else | 309 | fprintf (stderr, "%s:", program_name); |
273 | #endif | 310 | #endif |
274 | fprintf (stderr, "%s:", program_name); | ||
275 | } | 311 | } |
276 | 312 | ||
277 | if (file_name != NULL) | ||
278 | { | ||
279 | #if _LIBC | 313 | #if _LIBC |
280 | if (_IO_fwide (stderr, 0) > 0) | 314 | __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", |
281 | __fwprintf (stderr, L"%s:%d: ", file_name, line_number); | 315 | file_name, line_number); |
282 | else | 316 | #else |
317 | fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", | ||
318 | file_name, line_number); | ||
283 | #endif | 319 | #endif |
284 | fprintf (stderr, "%s:%d: ", file_name, line_number); | ||
285 | } | ||
286 | 320 | ||
287 | va_start (args, message); | 321 | va_start (args, message); |
288 | error_tail (status, errnum, message, args); | 322 | error_tail (status, errnum, message, args); |
@@ -1,5 +1,5 @@ | |||
1 | /* Declaration for error-reporting function | 1 | /* Declaration for error-reporting function |
2 | Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc. | 2 | Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | #ifndef __attribute__ | 22 | #ifndef __attribute__ |
23 | /* This feature is available in gcc versions 2.5 and later. */ | 23 | /* This feature is available in gcc versions 2.5 and later. */ |
24 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) | 24 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ |
25 | # define __attribute__(Spec) /* empty */ | 25 | # define __attribute__(Spec) /* empty */ |
26 | # endif | 26 | # endif |
27 | /* The __-protected variants of `format' and `printf' attributes | 27 | /* The __-protected variants of `format' and `printf' attributes |
@@ -21,7 +21,7 @@ | |||
21 | /* Get exit() declaration. */ | 21 | /* Get exit() declaration. */ |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | /* Some systems do not define EXIT_*, even with STDC_HEADERS. */ | 24 | /* Some systems do not define EXIT_*, despite otherwise supporting C89. */ |
25 | #ifndef EXIT_SUCCESS | 25 | #ifndef EXIT_SUCCESS |
26 | # define EXIT_SUCCESS 0 | 26 | # define EXIT_SUCCESS 0 |
27 | #endif | 27 | #endif |
diff --git a/lib/exitfail.c b/gl/exitfail.c index 27d38c3..97abc67 100644 --- a/lib/exitfail.c +++ b/gl/exitfail.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Failure exit status | 1 | /* Failure exit status |
2 | 2 | ||
3 | Copyright (C) 2002, 2003 Free Software Foundation, Inc. | 3 | Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +17,7 @@ | |||
17 | If not, write to the Free Software Foundation, | 17 | If not, write to the Free Software Foundation, |
18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | #include "exitfail.h" | 22 | #include "exitfail.h" |
25 | #include "exit.h" | 23 | #include "exit.h" |
diff --git a/lib/exitfail.h b/gl/exitfail.h index e46cf9c..e46cf9c 100644 --- a/lib/exitfail.h +++ b/gl/exitfail.h | |||
diff --git a/lib/fcntl--.h b/gl/fcntl--.h index 51b869e..51b869e 100644 --- a/lib/fcntl--.h +++ b/gl/fcntl--.h | |||
diff --git a/lib/fcntl-safer.h b/gl/fcntl-safer.h index cab6aab..cab6aab 100644 --- a/lib/fcntl-safer.h +++ b/gl/fcntl-safer.h | |||
diff --git a/lib/fd-safer.c b/gl/fd-safer.c index 5933bcb..256bfa4 100644 --- a/lib/fd-safer.c +++ b/gl/fd-safer.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Return a safer copy of a file descriptor. | 1 | /* Return a safer copy of a file descriptor. |
2 | 2 | ||
3 | Copyright (C) 2005 Free Software Foundation, Inc. | 3 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -18,9 +18,7 @@ | |||
18 | 18 | ||
19 | /* Written by Paul Eggert. */ | 19 | /* Written by Paul Eggert. */ |
20 | 20 | ||
21 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
22 | # include <config.h> | ||
23 | #endif | ||
24 | 22 | ||
25 | #include "unistd-safer.h" | 23 | #include "unistd-safer.h" |
26 | 24 | ||
diff --git a/lib/fsusage.c b/gl/fsusage.c index b137790..337bf53 100644 --- a/lib/fsusage.c +++ b/gl/fsusage.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* fsusage.c -- return space usage of mounted file systems | 1 | /* fsusage.c -- return space usage of mounted file systems |
2 | 2 | ||
3 | Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005 | 3 | Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005, 2006 |
4 | Free Software Foundation, Inc. | 4 | Free Software Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
@@ -17,62 +17,49 @@ | |||
17 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #if HAVE_INTTYPES_H | ||
25 | # include <inttypes.h> | ||
26 | #endif | ||
27 | #if HAVE_STDINT_H | ||
28 | # include <stdint.h> | ||
29 | #endif | ||
30 | #include <unistd.h> | ||
31 | #ifndef UINTMAX_MAX | ||
32 | # define UINTMAX_MAX ((uintmax_t) -1) | ||
33 | #endif | ||
34 | 21 | ||
35 | #include <sys/types.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include "fsusage.h" | 22 | #include "fsusage.h" |
38 | 23 | ||
39 | #include <limits.h> | 24 | #include <limits.h> |
25 | #include <sys/types.h> | ||
40 | 26 | ||
41 | #if HAVE_SYS_PARAM_H | 27 | #if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */ |
42 | # include <sys/param.h> | ||
43 | #endif | ||
44 | |||
45 | #if HAVE_SYS_MOUNT_H | ||
46 | # include <sys/mount.h> | ||
47 | #endif | ||
48 | |||
49 | #if HAVE_SYS_VFS_H | ||
50 | # include <sys/vfs.h> | ||
51 | #endif | ||
52 | |||
53 | #if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ | ||
54 | # include <sys/fs/s5param.h> | ||
55 | #endif | ||
56 | |||
57 | #if defined HAVE_SYS_FILSYS_H && !defined _CRAY | ||
58 | # include <sys/filsys.h> /* SVR2 */ | ||
59 | #endif | ||
60 | |||
61 | #include <fcntl.h> | ||
62 | |||
63 | #if HAVE_SYS_STATFS_H | ||
64 | # include <sys/statfs.h> | ||
65 | #endif | ||
66 | |||
67 | #if HAVE_DUSTAT_H /* AIX PS/2 */ | ||
68 | # include <sys/dustat.h> | ||
69 | #endif | ||
70 | |||
71 | #if HAVE_SYS_STATVFS_H /* SVR4 */ | ||
72 | # include <sys/statvfs.h> | 28 | # include <sys/statvfs.h> |
29 | #else | ||
30 | /* Don't include backward-compatibility files unless they're needed. | ||
31 | Eventually we'd like to remove all this cruft. */ | ||
32 | # include <fcntl.h> | ||
33 | # include <unistd.h> | ||
34 | # include <sys/stat.h> | ||
35 | # if HAVE_SYS_PARAM_H | ||
36 | # include <sys/param.h> | ||
37 | # endif | ||
38 | # if HAVE_SYS_MOUNT_H | ||
39 | # include <sys/mount.h> | ||
40 | # endif | ||
41 | # if HAVE_SYS_VFS_H | ||
42 | # include <sys/vfs.h> | ||
43 | # endif | ||
44 | # if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ | ||
45 | # include <sys/fs/s5param.h> | ||
46 | # endif | ||
47 | # if defined HAVE_SYS_FILSYS_H && !defined _CRAY | ||
48 | # include <sys/filsys.h> /* SVR2 */ | ||
49 | # endif | ||
50 | # if HAVE_SYS_STATFS_H | ||
51 | # include <sys/statfs.h> | ||
52 | # endif | ||
53 | # if HAVE_DUSTAT_H /* AIX PS/2 */ | ||
54 | # include <sys/dustat.h> | ||
55 | # endif | ||
56 | # include "full-read.h" | ||
73 | #endif | 57 | #endif |
74 | 58 | ||
75 | #include "full-read.h" | 59 | /* The results of open() in this file are not used with fchdir, |
60 | therefore save some unnecessary work in fchdir.c. */ | ||
61 | #undef open | ||
62 | #undef close | ||
76 | 63 | ||
77 | /* Many space usage primitives use all 1 bits to denote a value that is | 64 | /* Many space usage primitives use all 1 bits to denote a value that is |
78 | not applicable or unknown. Propagate this information by returning | 65 | not applicable or unknown. Propagate this information by returning |
@@ -83,7 +70,7 @@ | |||
83 | && (~ (x) == (sizeof (x) < sizeof (int) \ | 70 | && (~ (x) == (sizeof (x) < sizeof (int) \ |
84 | ? - (1 << (sizeof (x) * CHAR_BIT)) \ | 71 | ? - (1 << (sizeof (x) * CHAR_BIT)) \ |
85 | : 0))) \ | 72 | : 0))) \ |
86 | ? UINTMAX_MAX : (x)) | 73 | ? UINTMAX_MAX : (uintmax_t) (x)) |
87 | 74 | ||
88 | /* Extract the top bit of X as an uintmax_t value. */ | 75 | /* Extract the top bit of X as an uintmax_t value. */ |
89 | #define EXTRACT_TOP_BIT(x) ((x) \ | 76 | #define EXTRACT_TOP_BIT(x) ((x) \ |
@@ -108,18 +95,19 @@ | |||
108 | int | 95 | int |
109 | get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | 96 | get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) |
110 | { | 97 | { |
111 | #ifdef STAT_STATFS3_OSF1 | 98 | #if defined STAT_STATVFS /* POSIX */ |
112 | 99 | ||
113 | struct statfs fsd; | 100 | struct statvfs fsd; |
114 | 101 | ||
115 | if (statfs (file, &fsd, sizeof (struct statfs)) != 0) | 102 | if (statvfs (file, &fsd) < 0) |
116 | return -1; | 103 | return -1; |
117 | 104 | ||
118 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | 105 | /* f_frsize isn't guaranteed to be supported. */ |
119 | 106 | fsp->fsu_blocksize = (fsd.f_frsize | |
120 | #endif /* STAT_STATFS3_OSF1 */ | 107 | ? PROPAGATE_ALL_ONES (fsd.f_frsize) |
108 | : PROPAGATE_ALL_ONES (fsd.f_bsize)); | ||
121 | 109 | ||
122 | #ifdef STAT_STATFS2_FS_DATA /* Ultrix */ | 110 | #elif defined STAT_STATFS2_FS_DATA /* Ultrix */ |
123 | 111 | ||
124 | struct fs_data fsd; | 112 | struct fs_data fsd; |
125 | 113 | ||
@@ -134,9 +122,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
134 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); | 122 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); |
135 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | 123 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); |
136 | 124 | ||
137 | #endif /* STAT_STATFS2_FS_DATA */ | 125 | #elif defined STAT_READ_FILSYS /* SVR2 */ |
138 | |||
139 | #ifdef STAT_READ_FILSYS /* SVR2 */ | ||
140 | # ifndef SUPERBOFF | 126 | # ifndef SUPERBOFF |
141 | # define SUPERBOFF (SUPERB * 512) | 127 | # define SUPERBOFF (SUPERB * 512) |
142 | # endif | 128 | # endif |
@@ -171,9 +157,16 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
171 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); | 157 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); |
172 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); | 158 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); |
173 | 159 | ||
174 | #endif /* STAT_READ_FILSYS */ | 160 | #elif defined STAT_STATFS3_OSF1 |
175 | 161 | ||
176 | #ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ | 162 | struct statfs fsd; |
163 | |||
164 | if (statfs (file, &fsd, sizeof (struct statfs)) != 0) | ||
165 | return -1; | ||
166 | |||
167 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | ||
168 | |||
169 | #elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ | ||
177 | 170 | ||
178 | struct statfs fsd; | 171 | struct statfs fsd; |
179 | 172 | ||
@@ -197,9 +190,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
197 | } | 190 | } |
198 | # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ | 191 | # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ |
199 | 192 | ||
200 | #endif /* STAT_STATFS2_BSIZE */ | 193 | #elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ |
201 | |||
202 | #ifdef STAT_STATFS2_FSIZE /* 4.4BSD */ | ||
203 | 194 | ||
204 | struct statfs fsd; | 195 | struct statfs fsd; |
205 | 196 | ||
@@ -208,9 +199,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
208 | 199 | ||
209 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | 200 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); |
210 | 201 | ||
211 | #endif /* STAT_STATFS2_FSIZE */ | 202 | #elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ |
212 | |||
213 | #ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ | ||
214 | 203 | ||
215 | # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN | 204 | # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN |
216 | # define f_bavail f_bfree | 205 | # define f_bavail f_bfree |
@@ -230,24 +219,10 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
230 | fsp->fsu_blocksize = 512; | 219 | fsp->fsu_blocksize = 512; |
231 | # endif | 220 | # endif |
232 | 221 | ||
233 | #endif /* STAT_STATFS4 */ | 222 | #endif |
234 | |||
235 | #ifdef STAT_STATVFS /* SVR4 */ | ||
236 | |||
237 | struct statvfs fsd; | ||
238 | |||
239 | if (statvfs (file, &fsd) < 0) | ||
240 | return -1; | ||
241 | |||
242 | /* f_frsize isn't guaranteed to be supported. */ | ||
243 | fsp->fsu_blocksize = (fsd.f_frsize | ||
244 | ? PROPAGATE_ALL_ONES (fsd.f_frsize) | ||
245 | : PROPAGATE_ALL_ONES (fsd.f_bsize)); | ||
246 | |||
247 | #endif /* STAT_STATVFS */ | ||
248 | 223 | ||
249 | #if !defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS | 224 | #if (defined STAT_STATVFS \ |
250 | /* !Ultrix && !SVR2 */ | 225 | || (!defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS)) |
251 | 226 | ||
252 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); | 227 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); |
253 | fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.f_bfree); | 228 | fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.f_bfree); |
@@ -256,7 +231,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
256 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); | 231 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); |
257 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); | 232 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); |
258 | 233 | ||
259 | #endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */ | 234 | #endif |
260 | 235 | ||
261 | return 0; | 236 | return 0; |
262 | } | 237 | } |
diff --git a/lib/fsusage.h b/gl/fsusage.h index f3eda2d..7fa9f8d 100644 --- a/lib/fsusage.h +++ b/gl/fsusage.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* fsusage.h -- declarations for file system space usage info | 1 | /* fsusage.h -- declarations for file system space usage info |
2 | 2 | ||
3 | Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005 Free Software | 3 | Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005, 2006 Free Software |
4 | Foundation, Inc. | 4 | Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
@@ -22,6 +22,7 @@ | |||
22 | #if !defined FSUSAGE_H_ | 22 | #if !defined FSUSAGE_H_ |
23 | # define FSUSAGE_H_ | 23 | # define FSUSAGE_H_ |
24 | 24 | ||
25 | # include <stdint.h> | ||
25 | # include <stdbool.h> | 26 | # include <stdbool.h> |
26 | 27 | ||
27 | struct fs_usage | 28 | struct fs_usage |
diff --git a/lib/full-read.c b/gl/full-read.c index 8c3472a..8c3472a 100644 --- a/lib/full-read.c +++ b/gl/full-read.c | |||
diff --git a/lib/full-read.h b/gl/full-read.h index 05d83a7..05d83a7 100644 --- a/lib/full-read.h +++ b/gl/full-read.h | |||
diff --git a/lib/full-write.c b/gl/full-write.c index 106f3c7..cc16872 100644 --- a/lib/full-write.c +++ b/gl/full-write.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* An interface to read and write that retries (if necessary) until complete. | 1 | /* An interface to read and write that retries (if necessary) until complete. |
2 | 2 | ||
3 | Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, | 3 | Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4 | 2004 Free Software Foundation, Inc. | 4 | 2004, 2005, 2006 Free Software Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +17,7 @@ | |||
17 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | /* Specification. */ | 22 | /* Specification. */ |
25 | #ifdef FULL_READ | 23 | #ifdef FULL_READ |
@@ -62,7 +60,7 @@ size_t | |||
62 | full_rw (int fd, const void *buf, size_t count) | 60 | full_rw (int fd, const void *buf, size_t count) |
63 | { | 61 | { |
64 | size_t total = 0; | 62 | size_t total = 0; |
65 | const char *ptr = buf; | 63 | const char *ptr = (const char *) buf; |
66 | 64 | ||
67 | while (count > 0) | 65 | while (count > 0) |
68 | { | 66 | { |
diff --git a/lib/full-write.h b/gl/full-write.h index d20d2fe..d20d2fe 100644 --- a/lib/full-write.h +++ b/gl/full-write.h | |||
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c new file mode 100644 index 0000000..7f0e034 --- /dev/null +++ b/gl/gai_strerror.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. | ||
2 | This file is part of the GNU C Library. | ||
3 | Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef _LIBC | ||
20 | # include <config.h> | ||
21 | # include "getaddrinfo.h" | ||
22 | #endif | ||
23 | |||
24 | #include <stdio.h> | ||
25 | #ifdef HAVE_NETDB_H | ||
26 | # include <netdb.h> | ||
27 | #endif | ||
28 | |||
29 | #ifdef _LIBC | ||
30 | # include <libintl.h> | ||
31 | #else | ||
32 | # include "gettext.h" | ||
33 | # define _(String) gettext (String) | ||
34 | # define N_(String) String | ||
35 | #endif | ||
36 | |||
37 | static struct | ||
38 | { | ||
39 | int code; | ||
40 | const char *msg; | ||
41 | } | ||
42 | values[] = | ||
43 | { | ||
44 | { EAI_ADDRFAMILY, N_("Address family for hostname not supported") }, | ||
45 | { EAI_AGAIN, N_("Temporary failure in name resolution") }, | ||
46 | { EAI_BADFLAGS, N_("Bad value for ai_flags") }, | ||
47 | { EAI_FAIL, N_("Non-recoverable failure in name resolution") }, | ||
48 | { EAI_FAMILY, N_("ai_family not supported") }, | ||
49 | { EAI_MEMORY, N_("Memory allocation failure") }, | ||
50 | { EAI_NODATA, N_("No address associated with hostname") }, | ||
51 | { EAI_NONAME, N_("Name or service not known") }, | ||
52 | { EAI_SERVICE, N_("Servname not supported for ai_socktype") }, | ||
53 | { EAI_SOCKTYPE, N_("ai_socktype not supported") }, | ||
54 | { EAI_SYSTEM, N_("System error") }, | ||
55 | #ifdef __USE_GNU | ||
56 | { EAI_INPROGRESS, N_("Processing request in progress") }, | ||
57 | { EAI_CANCELED, N_("Request canceled") }, | ||
58 | { EAI_NOTCANCELED, N_("Request not canceled") }, | ||
59 | { EAI_ALLDONE, N_("All requests done") }, | ||
60 | { EAI_INTR, N_("Interrupted by a signal") }, | ||
61 | { EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") } | ||
62 | #endif | ||
63 | }; | ||
64 | |||
65 | const char * | ||
66 | gai_strerror (int code) | ||
67 | { | ||
68 | size_t i; | ||
69 | for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i) | ||
70 | if (values[i].code == code) | ||
71 | return _(values[i].msg); | ||
72 | |||
73 | return _("Unknown error"); | ||
74 | } | ||
75 | #ifdef _LIBC | ||
76 | libc_hidden_def (gai_strerror) | ||
77 | #endif | ||
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c new file mode 100644 index 0000000..f523f76 --- /dev/null +++ b/gl/getaddrinfo.c | |||
@@ -0,0 +1,417 @@ | |||
1 | /* Get address information (partial implementation). | ||
2 | Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software | ||
3 | Foundation, Inc. | ||
4 | Contributed by Simon Josefsson <simon@josefsson.org>. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #include <config.h> | ||
21 | |||
22 | #include "getaddrinfo.h" | ||
23 | |||
24 | #if HAVE_NETINET_IN_H | ||
25 | # include <netinet/in.h> | ||
26 | #endif | ||
27 | |||
28 | /* Get calloc. */ | ||
29 | #include <stdlib.h> | ||
30 | |||
31 | /* Get memcpy. */ | ||
32 | #include <string.h> | ||
33 | |||
34 | #include <stdbool.h> | ||
35 | |||
36 | #include "gettext.h" | ||
37 | #define _(String) gettext (String) | ||
38 | #define N_(String) String | ||
39 | |||
40 | #include "inet_ntop.h" | ||
41 | #include "snprintf.h" | ||
42 | #include "strdup.h" | ||
43 | |||
44 | /* BeOS has AF_INET, but not PF_INET. */ | ||
45 | #ifndef PF_INET | ||
46 | # define PF_INET AF_INET | ||
47 | #endif | ||
48 | /* BeOS also lacks PF_UNSPEC. */ | ||
49 | #ifndef PF_UNSPEC | ||
50 | # define PF_UNSPEC 0 | ||
51 | #endif | ||
52 | |||
53 | #if defined _WIN32 || defined __WIN32__ | ||
54 | # define WIN32_NATIVE | ||
55 | #endif | ||
56 | |||
57 | #ifdef WIN32_NATIVE | ||
58 | typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, | ||
59 | const struct addrinfo*, | ||
60 | struct addrinfo**); | ||
61 | typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*); | ||
62 | typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*, | ||
63 | socklen_t, char*, DWORD, | ||
64 | char*, DWORD, int); | ||
65 | |||
66 | static getaddrinfo_func getaddrinfo_ptr = NULL; | ||
67 | static freeaddrinfo_func freeaddrinfo_ptr = NULL; | ||
68 | static getnameinfo_func getnameinfo_ptr = NULL; | ||
69 | |||
70 | static int | ||
71 | use_win32_p (void) | ||
72 | { | ||
73 | static int done = 0; | ||
74 | HMODULE h; | ||
75 | |||
76 | if (done) | ||
77 | return getaddrinfo_ptr ? 1 : 0; | ||
78 | |||
79 | done = 1; | ||
80 | |||
81 | h = GetModuleHandle ("ws2_32.dll"); | ||
82 | |||
83 | if (h) | ||
84 | { | ||
85 | getaddrinfo_ptr = (getaddrinfo_func) GetProcAddress (h, "getaddrinfo"); | ||
86 | freeaddrinfo_ptr = (freeaddrinfo_func) GetProcAddress (h, "freeaddrinfo"); | ||
87 | getnameinfo_ptr = (getnameinfo_func) GetProcAddress (h, "getnameinfo"); | ||
88 | } | ||
89 | |||
90 | /* If either is missing, something is odd. */ | ||
91 | if (!getaddrinfo_ptr || !freeaddrinfo_ptr || !getnameinfo_ptr) | ||
92 | { | ||
93 | getaddrinfo_ptr = NULL; | ||
94 | freeaddrinfo_ptr = NULL; | ||
95 | getnameinfo_ptr = NULL; | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | return 1; | ||
100 | } | ||
101 | #endif | ||
102 | |||
103 | static inline bool | ||
104 | validate_family (int family) | ||
105 | { | ||
106 | /* FIXME: Support more families. */ | ||
107 | #if HAVE_IPV4 | ||
108 | if (family == PF_INET) | ||
109 | return true; | ||
110 | #endif | ||
111 | #if HAVE_IPV6 | ||
112 | if (family == PF_INET6) | ||
113 | return true; | ||
114 | #endif | ||
115 | if (family == PF_UNSPEC) | ||
116 | return true; | ||
117 | return false; | ||
118 | } | ||
119 | |||
120 | /* Translate name of a service location and/or a service name to set of | ||
121 | socket addresses. */ | ||
122 | int | ||
123 | getaddrinfo (const char *restrict nodename, | ||
124 | const char *restrict servname, | ||
125 | const struct addrinfo *restrict hints, | ||
126 | struct addrinfo **restrict res) | ||
127 | { | ||
128 | struct addrinfo *tmp; | ||
129 | int port = 0; | ||
130 | struct hostent *he; | ||
131 | void *storage; | ||
132 | size_t size; | ||
133 | #if HAVE_IPV6 | ||
134 | struct v6_pair { | ||
135 | struct addrinfo addrinfo; | ||
136 | struct sockaddr_in6 sockaddr_in6; | ||
137 | }; | ||
138 | #endif | ||
139 | #if HAVE_IPV4 | ||
140 | struct v4_pair { | ||
141 | struct addrinfo addrinfo; | ||
142 | struct sockaddr_in sockaddr_in; | ||
143 | }; | ||
144 | #endif | ||
145 | |||
146 | #ifdef WIN32_NATIVE | ||
147 | if (use_win32_p ()) | ||
148 | return getaddrinfo_ptr (nodename, servname, hints, res); | ||
149 | #endif | ||
150 | |||
151 | if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE))) | ||
152 | /* FIXME: Support more flags. */ | ||
153 | return EAI_BADFLAGS; | ||
154 | |||
155 | if (hints && !validate_family (hints->ai_family)) | ||
156 | return EAI_FAMILY; | ||
157 | |||
158 | if (hints && | ||
159 | hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM) | ||
160 | /* FIXME: Support other socktype. */ | ||
161 | return EAI_SOCKTYPE; /* FIXME: Better return code? */ | ||
162 | |||
163 | if (!nodename) | ||
164 | { | ||
165 | if (!(hints->ai_flags & AI_PASSIVE)) | ||
166 | return EAI_NONAME; | ||
167 | |||
168 | #ifdef HAVE_IPV6 | ||
169 | nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; | ||
170 | #else | ||
171 | nodename = "0.0.0.0"; | ||
172 | #endif | ||
173 | } | ||
174 | |||
175 | if (servname) | ||
176 | { | ||
177 | struct servent *se = NULL; | ||
178 | const char *proto = | ||
179 | (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; | ||
180 | |||
181 | if (!(hints->ai_flags & AI_NUMERICSERV)) | ||
182 | /* FIXME: Use getservbyname_r if available. */ | ||
183 | se = getservbyname (servname, proto); | ||
184 | |||
185 | if (!se) | ||
186 | { | ||
187 | char *c; | ||
188 | if (!(*servname >= '0' && *servname <= '9')) | ||
189 | return EAI_NONAME; | ||
190 | port = strtoul (servname, &c, 10); | ||
191 | if (*c || port > 0xffff) | ||
192 | return EAI_NONAME; | ||
193 | port = htons (port); | ||
194 | } | ||
195 | else | ||
196 | port = se->s_port; | ||
197 | } | ||
198 | |||
199 | /* FIXME: Use gethostbyname_r if available. */ | ||
200 | he = gethostbyname (nodename); | ||
201 | if (!he || he->h_addr_list[0] == NULL) | ||
202 | return EAI_NONAME; | ||
203 | |||
204 | switch (he->h_addrtype) | ||
205 | { | ||
206 | #if HAVE_IPV6 | ||
207 | case PF_INET6: | ||
208 | size = sizeof (struct v6_pair); | ||
209 | break; | ||
210 | #endif | ||
211 | |||
212 | #if HAVE_IPV4 | ||
213 | case PF_INET: | ||
214 | size = sizeof (struct v4_pair); | ||
215 | break; | ||
216 | #endif | ||
217 | |||
218 | default: | ||
219 | return EAI_NODATA; | ||
220 | } | ||
221 | |||
222 | storage = calloc (1, size); | ||
223 | if (!storage) | ||
224 | return EAI_MEMORY; | ||
225 | |||
226 | switch (he->h_addrtype) | ||
227 | { | ||
228 | #if HAVE_IPV6 | ||
229 | case PF_INET6: | ||
230 | { | ||
231 | struct v6_pair *p = storage; | ||
232 | struct sockaddr_in6 *sinp = &p->sockaddr_in6; | ||
233 | tmp = &p->addrinfo; | ||
234 | |||
235 | if (port) | ||
236 | sinp->sin6_port = port; | ||
237 | |||
238 | if (he->h_length != sizeof (sinp->sin6_addr)) | ||
239 | { | ||
240 | free (storage); | ||
241 | return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ | ||
242 | } | ||
243 | |||
244 | memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); | ||
245 | |||
246 | tmp->ai_addr = (struct sockaddr *) sinp; | ||
247 | tmp->ai_addrlen = sizeof *sinp; | ||
248 | } | ||
249 | break; | ||
250 | #endif | ||
251 | |||
252 | #if HAVE_IPV4 | ||
253 | case PF_INET: | ||
254 | { | ||
255 | struct v4_pair *p = storage; | ||
256 | struct sockaddr_in *sinp = &p->sockaddr_in; | ||
257 | tmp = &p->addrinfo; | ||
258 | |||
259 | if (port) | ||
260 | sinp->sin_port = port; | ||
261 | |||
262 | if (he->h_length != sizeof (sinp->sin_addr)) | ||
263 | { | ||
264 | free (storage); | ||
265 | return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ | ||
266 | } | ||
267 | |||
268 | memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); | ||
269 | |||
270 | tmp->ai_addr = (struct sockaddr *) sinp; | ||
271 | tmp->ai_addrlen = sizeof *sinp; | ||
272 | } | ||
273 | break; | ||
274 | #endif | ||
275 | |||
276 | default: | ||
277 | free (storage); | ||
278 | return EAI_NODATA; | ||
279 | } | ||
280 | |||
281 | if (hints && hints->ai_flags & AI_CANONNAME) | ||
282 | { | ||
283 | const char *cn; | ||
284 | if (he->h_name) | ||
285 | cn = he->h_name; | ||
286 | else | ||
287 | cn = nodename; | ||
288 | |||
289 | tmp->ai_canonname = strdup (cn); | ||
290 | if (!tmp->ai_canonname) | ||
291 | { | ||
292 | free (storage); | ||
293 | return EAI_MEMORY; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | tmp->ai_protocol = (hints) ? hints->ai_protocol : 0; | ||
298 | tmp->ai_socktype = (hints) ? hints->ai_socktype : 0; | ||
299 | tmp->ai_addr->sa_family = he->h_addrtype; | ||
300 | tmp->ai_family = he->h_addrtype; | ||
301 | |||
302 | /* FIXME: If more than one address, create linked list of addrinfo's. */ | ||
303 | |||
304 | *res = tmp; | ||
305 | |||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | /* Free `addrinfo' structure AI including associated storage. */ | ||
310 | void | ||
311 | freeaddrinfo (struct addrinfo *ai) | ||
312 | { | ||
313 | #ifdef WIN32_NATIVE | ||
314 | if (use_win32_p ()) | ||
315 | { | ||
316 | freeaddrinfo_ptr (ai); | ||
317 | return; | ||
318 | } | ||
319 | #endif | ||
320 | |||
321 | while (ai) | ||
322 | { | ||
323 | struct addrinfo *cur; | ||
324 | |||
325 | cur = ai; | ||
326 | ai = ai->ai_next; | ||
327 | |||
328 | if (cur->ai_canonname) free (cur->ai_canonname); | ||
329 | free (cur); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, | ||
334 | char *restrict node, socklen_t nodelen, | ||
335 | char *restrict service, socklen_t servicelen, | ||
336 | int flags) | ||
337 | { | ||
338 | #ifdef WIN32_NATIVE | ||
339 | if (use_win32_p ()) | ||
340 | return getnameinfo_ptr (sa, salen, node, nodelen, | ||
341 | service, servicelen, flags); | ||
342 | #endif | ||
343 | |||
344 | /* FIXME: Support other flags. */ | ||
345 | if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) || | ||
346 | (service && servicelen > 0 && !(flags & NI_NUMERICHOST)) || | ||
347 | (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV))) | ||
348 | return EAI_BADFLAGS; | ||
349 | |||
350 | if (sa == NULL || salen < sizeof (sa->sa_family)) | ||
351 | return EAI_FAMILY; | ||
352 | |||
353 | switch (sa->sa_family) | ||
354 | { | ||
355 | #if HAVE_IPV4 | ||
356 | case AF_INET: | ||
357 | if (salen < sizeof (struct sockaddr_in)) | ||
358 | return EAI_FAMILY; | ||
359 | break; | ||
360 | #endif | ||
361 | #if HAVE_IPV6 | ||
362 | case AF_INET6: | ||
363 | if (salen < sizeof (struct sockaddr_in6)) | ||
364 | return EAI_FAMILY; | ||
365 | break; | ||
366 | #endif | ||
367 | default: | ||
368 | return EAI_FAMILY; | ||
369 | } | ||
370 | |||
371 | if (node && nodelen > 0 && flags & NI_NUMERICHOST) | ||
372 | { | ||
373 | switch (sa->sa_family) | ||
374 | { | ||
375 | #if HAVE_IPV4 | ||
376 | case AF_INET: | ||
377 | if (!inet_ntop (AF_INET, | ||
378 | &(((const struct sockaddr_in *) sa)->sin_addr), | ||
379 | node, nodelen)) | ||
380 | return EAI_SYSTEM; | ||
381 | break; | ||
382 | #endif | ||
383 | |||
384 | #if HAVE_IPV6 | ||
385 | case AF_INET6: | ||
386 | if (!inet_ntop (AF_INET6, | ||
387 | &(((const struct sockaddr_in6 *) sa)->sin6_addr), | ||
388 | node, nodelen)) | ||
389 | return EAI_SYSTEM; | ||
390 | break; | ||
391 | #endif | ||
392 | |||
393 | default: | ||
394 | return EAI_FAMILY; | ||
395 | } | ||
396 | } | ||
397 | |||
398 | if (service && servicelen > 0 && flags & NI_NUMERICSERV) | ||
399 | switch (sa->sa_family) | ||
400 | { | ||
401 | #if HAVE_IPV4 | ||
402 | case AF_INET: | ||
403 | #endif | ||
404 | #if HAVE_IPV6 | ||
405 | case AF_INET6: | ||
406 | #endif | ||
407 | { | ||
408 | unsigned short int port | ||
409 | = ntohs (((const struct sockaddr_in *) sa)->sin_port); | ||
410 | if (servicelen <= snprintf (service, servicelen, "%u", port)) | ||
411 | return EAI_OVERFLOW; | ||
412 | } | ||
413 | break; | ||
414 | } | ||
415 | |||
416 | return 0; | ||
417 | } | ||
diff --git a/gl/getaddrinfo.h b/gl/getaddrinfo.h new file mode 100644 index 0000000..b4ef242 --- /dev/null +++ b/gl/getaddrinfo.h | |||
@@ -0,0 +1,155 @@ | |||
1 | /* Get address information. | ||
2 | Copyright (C) 1996-2002, 2003, 2004, 2005, 2006 | ||
3 | Free Software Foundation, Inc. | ||
4 | Contributed by Simon Josefsson <simon@josefsson.org>. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifndef GETADDRINFO_H | ||
21 | #define GETADDRINFO_H | ||
22 | |||
23 | /* sys/socket.h in i386-unknown-freebsd4.10 and | ||
24 | powerpc-apple-darwin5.5 require sys/types.h, so include it first. | ||
25 | Then we'll also get 'socklen_t' and 'struct sockaddr' which are | ||
26 | used below. */ | ||
27 | #include <sys/types.h> | ||
28 | /* Get all getaddrinfo related declarations, if available. */ | ||
29 | #include <sys/socket.h> | ||
30 | #ifdef HAVE_NETDB_H | ||
31 | # include <netdb.h> | ||
32 | #endif | ||
33 | |||
34 | #ifndef HAVE_STRUCT_ADDRINFO | ||
35 | |||
36 | /* Structure to contain information about address of a service provider. */ | ||
37 | struct addrinfo | ||
38 | { | ||
39 | int ai_flags; /* Input flags. */ | ||
40 | int ai_family; /* Protocol family for socket. */ | ||
41 | int ai_socktype; /* Socket type. */ | ||
42 | int ai_protocol; /* Protocol for socket. */ | ||
43 | socklen_t ai_addrlen; /* Length of socket address. */ | ||
44 | struct sockaddr *ai_addr; /* Socket address for socket. */ | ||
45 | char *ai_canonname; /* Canonical name for service location. */ | ||
46 | struct addrinfo *ai_next; /* Pointer to next in list. */ | ||
47 | }; | ||
48 | #endif | ||
49 | |||
50 | /* Possible values for `ai_flags' field in `addrinfo' structure. */ | ||
51 | #ifndef AI_PASSIVE | ||
52 | # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ | ||
53 | #endif | ||
54 | #ifndef AI_CANONNAME | ||
55 | # define AI_CANONNAME 0x0002 /* Request for canonical name. */ | ||
56 | #endif | ||
57 | #ifndef AI_NUMERICSERV | ||
58 | # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ | ||
59 | #endif | ||
60 | |||
61 | #if 0 | ||
62 | /* The commented out definitions below are not yet implemented in the | ||
63 | GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact, | ||
64 | cause conflicts on systems with a getaddrinfo() function which does not | ||
65 | define them. | ||
66 | |||
67 | If they are restored, be sure to protect the definitions with #ifndef. */ | ||
68 | #define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ | ||
69 | #define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ | ||
70 | #define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ | ||
71 | #define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose | ||
72 | returned address type.. */ | ||
73 | #endif /* 0 */ | ||
74 | |||
75 | /* Error values for `getaddrinfo' function. */ | ||
76 | #ifndef EAI_BADFLAGS | ||
77 | # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ | ||
78 | # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ | ||
79 | # define EAI_AGAIN -3 /* Temporary failure in name resolution. */ | ||
80 | # define EAI_FAIL -4 /* Non-recoverable failure in name res. */ | ||
81 | # define EAI_NODATA -5 /* No address associated with NAME. */ | ||
82 | # define EAI_FAMILY -6 /* `ai_family' not supported. */ | ||
83 | # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ | ||
84 | # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ | ||
85 | # define EAI_MEMORY -10 /* Memory allocation failure. */ | ||
86 | #endif | ||
87 | #ifndef EAI_OVERFLOW | ||
88 | /* Not defined on mingw32. */ | ||
89 | # define EAI_OVERFLOW -12 /* Argument buffer overflow. */ | ||
90 | #endif | ||
91 | #ifndef EAI_ADDRFAMILY | ||
92 | /* Not defined on mingw32. */ | ||
93 | # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ | ||
94 | #endif | ||
95 | #ifndef EAI_SYSTEM | ||
96 | /* Not defined on mingw32. */ | ||
97 | # define EAI_SYSTEM -11 /* System error returned in `errno'. */ | ||
98 | #endif | ||
99 | |||
100 | #ifdef __USE_GNU | ||
101 | # ifndef EAI_INPROGRESS | ||
102 | # define EAI_INPROGRESS -100 /* Processing request in progress. */ | ||
103 | # define EAI_CANCELED -101 /* Request canceled. */ | ||
104 | # define EAI_NOTCANCELED -102 /* Request not canceled. */ | ||
105 | # define EAI_ALLDONE -103 /* All requests done. */ | ||
106 | # define EAI_INTR -104 /* Interrupted by a signal. */ | ||
107 | # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ | ||
108 | # endif | ||
109 | #endif | ||
110 | |||
111 | #if !HAVE_DECL_GETADDRINFO | ||
112 | /* Translate name of a service location and/or a service name to set of | ||
113 | socket addresses. | ||
114 | For more details, see the POSIX:2001 specification | ||
115 | <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ | ||
116 | extern int getaddrinfo (const char *restrict nodename, | ||
117 | const char *restrict servname, | ||
118 | const struct addrinfo *restrict hints, | ||
119 | struct addrinfo **restrict res); | ||
120 | #endif | ||
121 | |||
122 | #if !HAVE_DECL_FREEADDRINFO | ||
123 | /* Free `addrinfo' structure AI including associated storage. | ||
124 | For more details, see the POSIX:2001 specification | ||
125 | <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ | ||
126 | extern void freeaddrinfo (struct addrinfo *ai); | ||
127 | #endif | ||
128 | |||
129 | #if !HAVE_DECL_GAI_STRERROR | ||
130 | /* Convert error return from getaddrinfo() to a string. | ||
131 | For more details, see the POSIX:2001 specification | ||
132 | <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ | ||
133 | extern const char *gai_strerror (int ecode); | ||
134 | #endif | ||
135 | |||
136 | #if !HAVE_DECL_GETNAMEINFO | ||
137 | /* Convert socket address to printable node and service names. | ||
138 | For more details, see the POSIX:2001 specification | ||
139 | <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ | ||
140 | extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, | ||
141 | char *restrict node, socklen_t nodelen, | ||
142 | char *restrict service, socklen_t servicelen, | ||
143 | int flags); | ||
144 | |||
145 | #endif | ||
146 | |||
147 | /* Possible flags for getnameinfo. */ | ||
148 | #ifndef NI_NUMERICHOST | ||
149 | # define NI_NUMERICHOST 1 | ||
150 | #endif | ||
151 | #ifndef NI_NUMERICSERV | ||
152 | # define NI_NUMERICSERV 2 | ||
153 | #endif | ||
154 | |||
155 | #endif /* GETADDRINFO_H */ | ||
diff --git a/gl/gethostname.c b/gl/gethostname.c new file mode 100644 index 0000000..eedc40e --- /dev/null +++ b/gl/gethostname.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* gethostname emulation for SysV and POSIX.1. | ||
2 | |||
3 | Copyright (C) 1992, 2003, 2006 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* David MacKenzie <djm@gnu.ai.mit.edu> */ | ||
20 | |||
21 | #include <config.h> | ||
22 | |||
23 | #ifdef HAVE_UNAME | ||
24 | # include <sys/utsname.h> | ||
25 | #endif | ||
26 | |||
27 | /* Put up to LEN chars of the host name into NAME. | ||
28 | Null terminate it if the name is shorter than LEN. | ||
29 | Return 0 if ok, -1 if error. */ | ||
30 | |||
31 | #include <stddef.h> | ||
32 | |||
33 | int | ||
34 | gethostname (char *name, size_t len) | ||
35 | { | ||
36 | #ifdef HAVE_UNAME | ||
37 | struct utsname uts; | ||
38 | |||
39 | if (uname (&uts) == -1) | ||
40 | return -1; | ||
41 | if (len > sizeof (uts.nodename)) | ||
42 | { | ||
43 | /* More space than we need is available. */ | ||
44 | name[sizeof (uts.nodename)] = '\0'; | ||
45 | len = sizeof (uts.nodename); | ||
46 | } | ||
47 | strncpy (name, uts.nodename, len); | ||
48 | #else | ||
49 | strcpy (name, ""); /* Hardcode your system name if you want. */ | ||
50 | #endif | ||
51 | return 0; | ||
52 | } | ||
diff --git a/lib/getloadavg.c b/gl/getloadavg.c index 2a50131..cfa6273 100644 --- a/lib/getloadavg.c +++ b/gl/getloadavg.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* Get the system load averages. | 1 | /* Get the system load averages. |
2 | 2 | ||
3 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, | 3 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, |
4 | 1995, 1997, 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. | 4 | 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006 Free Software |
5 | Foundation, Inc. | ||
5 | 6 | ||
6 | NOTE: The canonical source of this file is maintained with gnulib. | 7 | NOTE: The canonical source of this file is maintained with gnulib. |
7 | Bugs can be reported to bug-gnulib@gnu.org. | 8 | Bugs can be reported to bug-gnulib@gnu.org. |
@@ -80,13 +81,15 @@ | |||
80 | We also #define LDAV_PRIVILEGED if a program will require | 81 | We also #define LDAV_PRIVILEGED if a program will require |
81 | special installation to be able to call getloadavg. */ | 82 | special installation to be able to call getloadavg. */ |
82 | 83 | ||
83 | /* This should always be first. */ | 84 | /* "configure" defines CONFIGURING_GETLOADAVG to sidestep problems |
84 | #ifdef HAVE_CONFIG_H | 85 | with partially-configured source directories. */ |
86 | |||
87 | #ifndef CONFIGURING_GETLOADAVG | ||
85 | # include <config.h> | 88 | # include <config.h> |
89 | # include <stdbool.h> | ||
86 | #endif | 90 | #endif |
87 | 91 | ||
88 | #include <errno.h> | 92 | #include <errno.h> |
89 | #include <stdbool.h> | ||
90 | #include <stdio.h> | 93 | #include <stdio.h> |
91 | #include <stdlib.h> | 94 | #include <stdlib.h> |
92 | 95 | ||
@@ -279,7 +282,7 @@ | |||
279 | # endif | 282 | # endif |
280 | 283 | ||
281 | 284 | ||
282 | # ifndef FSCALE | 285 | # ifndef FSCALE |
283 | 286 | ||
284 | /* SunOS and some others define FSCALE in sys/param.h. */ | 287 | /* SunOS and some others define FSCALE in sys/param.h. */ |
285 | 288 | ||
@@ -358,7 +361,7 @@ | |||
358 | 361 | ||
359 | # ifdef LOAD_AVE_TYPE | 362 | # ifdef LOAD_AVE_TYPE |
360 | 363 | ||
361 | # ifndef VMS | 364 | # ifndef __VMS |
362 | # ifndef __linux__ | 365 | # ifndef __linux__ |
363 | # ifndef NLIST_STRUCT | 366 | # ifndef NLIST_STRUCT |
364 | # include <a.out.h> | 367 | # include <a.out.h> |
@@ -385,7 +388,7 @@ | |||
385 | # endif /* LDAV_SYMBOL */ | 388 | # endif /* LDAV_SYMBOL */ |
386 | # endif /* __linux__ */ | 389 | # endif /* __linux__ */ |
387 | 390 | ||
388 | # else /* VMS */ | 391 | # else /* __VMS */ |
389 | 392 | ||
390 | # ifndef eunice | 393 | # ifndef eunice |
391 | # include <iodef.h> | 394 | # include <iodef.h> |
@@ -393,7 +396,7 @@ | |||
393 | # else /* eunice */ | 396 | # else /* eunice */ |
394 | # include <vms/iodef.h> | 397 | # include <vms/iodef.h> |
395 | # endif /* eunice */ | 398 | # endif /* eunice */ |
396 | # endif /* VMS */ | 399 | # endif /* __VMS */ |
397 | 400 | ||
398 | # ifndef LDAV_CVT | 401 | # ifndef LDAV_CVT |
399 | # define LDAV_CVT(n) ((double) (n)) | 402 | # define LDAV_CVT(n) ((double) (n)) |
@@ -473,9 +476,9 @@ static bool getloadavg_initialized; | |||
473 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ | 476 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ |
474 | static long offset; | 477 | static long offset; |
475 | 478 | ||
476 | # if !defined (VMS) && !defined (sgi) && !defined (__linux__) | 479 | # if ! defined __VMS && ! defined sgi && ! defined __linux__ |
477 | static struct nlist nl[2]; | 480 | static struct nlist nl[2]; |
478 | # endif /* Not VMS or sgi */ | 481 | # endif |
479 | 482 | ||
480 | # ifdef SUNOS_5 | 483 | # ifdef SUNOS_5 |
481 | static kvm_t *kd; | 484 | static kvm_t *kd; |
@@ -813,7 +816,7 @@ getloadavg (double loadavg[], int nelem) | |||
813 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); | 816 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); |
814 | # endif /* OSF_ALPHA */ | 817 | # endif /* OSF_ALPHA */ |
815 | 818 | ||
816 | # if !defined (LDAV_DONE) && defined (VMS) | 819 | # if ! defined LDAV_DONE && defined __VMS |
817 | /* VMS specific code -- read from the Load Ave driver. */ | 820 | /* VMS specific code -- read from the Load Ave driver. */ |
818 | 821 | ||
819 | LOAD_AVE_TYPE load_ave[3]; | 822 | LOAD_AVE_TYPE load_ave[3]; |
@@ -851,9 +854,9 @@ getloadavg (double loadavg[], int nelem) | |||
851 | 854 | ||
852 | if (!getloadavg_initialized) | 855 | if (!getloadavg_initialized) |
853 | return -1; | 856 | return -1; |
854 | # endif /* VMS */ | 857 | # endif /* ! defined LDAV_DONE && defined __VMS */ |
855 | 858 | ||
856 | # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) && !defined (VMS) | 859 | # if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS |
857 | 860 | ||
858 | /* UNIX-specific code -- read the average from /dev/kmem. */ | 861 | /* UNIX-specific code -- read the average from /dev/kmem. */ |
859 | 862 | ||
@@ -953,7 +956,7 @@ getloadavg (double loadavg[], int nelem) | |||
953 | 956 | ||
954 | if (offset == 0 || !getloadavg_initialized) | 957 | if (offset == 0 || !getloadavg_initialized) |
955 | return -1; | 958 | return -1; |
956 | # endif /* LOAD_AVE_TYPE and not VMS */ | 959 | # endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */ |
957 | 960 | ||
958 | # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ | 961 | # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ |
959 | if (nelem > 0) | 962 | if (nelem > 0) |
diff --git a/lib/getopt.c b/gl/getopt.c index bcb81c8..3580ad8 100644 --- a/lib/getopt.c +++ b/gl/getopt.c | |||
@@ -2,7 +2,7 @@ | |||
2 | NOTE: getopt is now part of the C library, so if you don't know what | 2 | NOTE: getopt is now part of the C library, so if you don't know what |
3 | "Keep this file name-space clean" means, talk to drepper@gnu.org | 3 | "Keep this file name-space clean" means, talk to drepper@gnu.org |
4 | before changing it! | 4 | before changing it! |
5 | Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004 | 5 | Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006 |
6 | Free Software Foundation, Inc. | 6 | Free Software Foundation, Inc. |
7 | This file is part of the GNU C Library. | 7 | This file is part of the GNU C Library. |
8 | 8 | ||
@@ -20,30 +20,18 @@ | |||
20 | with this program; if not, write to the Free Software Foundation, | 20 | with this program; if not, write to the Free Software Foundation, |
21 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 21 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
22 | 22 | ||
23 | /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. | 23 | #ifndef _LIBC |
24 | Ditto for AIX 3.2 and <stdlib.h>. */ | ||
25 | #ifndef _NO_PROTO | ||
26 | # define _NO_PROTO | ||
27 | #endif | ||
28 | |||
29 | #ifdef HAVE_CONFIG_H | ||
30 | # include <config.h> | 24 | # include <config.h> |
31 | #endif | 25 | #endif |
32 | 26 | ||
33 | #include <stdio.h> | 27 | #include "getopt.h" |
34 | |||
35 | /* This needs to come after some library #include | ||
36 | to get __GNU_LIBRARY__ defined. */ | ||
37 | #ifdef __GNU_LIBRARY__ | ||
38 | /* Don't include stdlib.h for non-GNU C libraries because some of them | ||
39 | contain conflicting prototypes for getopt. */ | ||
40 | # include <stdlib.h> | ||
41 | # include <unistd.h> | ||
42 | #endif /* GNU C library. */ | ||
43 | 28 | ||
29 | #include <stdio.h> | ||
30 | #include <stdlib.h> | ||
44 | #include <string.h> | 31 | #include <string.h> |
32 | #include <unistd.h> | ||
45 | 33 | ||
46 | #ifdef VMS | 34 | #ifdef __VMS |
47 | # include <unixlib.h> | 35 | # include <unixlib.h> |
48 | #endif | 36 | #endif |
49 | 37 | ||
@@ -76,7 +64,6 @@ | |||
76 | GNU application programs can use a third alternative mode in which | 64 | GNU application programs can use a third alternative mode in which |
77 | they can distinguish the relative order of options and other arguments. */ | 65 | they can distinguish the relative order of options and other arguments. */ |
78 | 66 | ||
79 | #include "getopt.h" | ||
80 | #include "getopt_int.h" | 67 | #include "getopt_int.h" |
81 | 68 | ||
82 | /* For communication from `getopt' to the caller. | 69 | /* For communication from `getopt' to the caller. |
@@ -118,16 +105,9 @@ int optopt = '?'; | |||
118 | static struct _getopt_data getopt_data; | 105 | static struct _getopt_data getopt_data; |
119 | 106 | ||
120 | 107 | ||
121 | #ifndef __GNU_LIBRARY__ | 108 | #if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV |
122 | |||
123 | /* Avoid depending on library functions or files | ||
124 | whose names are inconsistent. */ | ||
125 | |||
126 | #ifndef getenv | ||
127 | extern char *getenv (); | 109 | extern char *getenv (); |
128 | #endif | 110 | #endif |
129 | |||
130 | #endif /* not __GNU_LIBRARY__ */ | ||
131 | 111 | ||
132 | #ifdef _LIBC | 112 | #ifdef _LIBC |
133 | /* Stored original parameters. | 113 | /* Stored original parameters. |
@@ -556,10 +536,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
556 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 536 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
557 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 537 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
558 | 538 | ||
559 | if (_IO_fwide (stderr, 0) > 0) | 539 | __fxprintf (NULL, "%s", buf); |
560 | __fwprintf (stderr, L"%s", buf); | ||
561 | else | ||
562 | fputs (buf, stderr); | ||
563 | 540 | ||
564 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 541 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
565 | _IO_funlockfile (stderr); | 542 | _IO_funlockfile (stderr); |
@@ -634,10 +611,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
634 | ((_IO_FILE *) stderr)->_flags2 | 611 | ((_IO_FILE *) stderr)->_flags2 |
635 | |= _IO_FLAGS2_NOTCANCEL; | 612 | |= _IO_FLAGS2_NOTCANCEL; |
636 | 613 | ||
637 | if (_IO_fwide (stderr, 0) > 0) | 614 | __fxprintf (NULL, "%s", buf); |
638 | __fwprintf (stderr, L"%s", buf); | ||
639 | else | ||
640 | fputs (buf, stderr); | ||
641 | 615 | ||
642 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 616 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
643 | _IO_funlockfile (stderr); | 617 | _IO_funlockfile (stderr); |
@@ -674,10 +648,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
674 | ((_IO_FILE *) stderr)->_flags2 | 648 | ((_IO_FILE *) stderr)->_flags2 |
675 | |= _IO_FLAGS2_NOTCANCEL; | 649 | |= _IO_FLAGS2_NOTCANCEL; |
676 | 650 | ||
677 | if (_IO_fwide (stderr, 0) > 0) | 651 | __fxprintf (NULL, "%s", buf); |
678 | __fwprintf (stderr, L"%s", buf); | ||
679 | else | ||
680 | fputs (buf, stderr); | ||
681 | 652 | ||
682 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 653 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
683 | _IO_funlockfile (stderr); | 654 | _IO_funlockfile (stderr); |
@@ -751,10 +722,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
751 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 722 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
752 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 723 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
753 | 724 | ||
754 | if (_IO_fwide (stderr, 0) > 0) | 725 | __fxprintf (NULL, "%s", buf); |
755 | __fwprintf (stderr, L"%s", buf); | ||
756 | else | ||
757 | fputs (buf, stderr); | ||
758 | 726 | ||
759 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 727 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
760 | _IO_funlockfile (stderr); | 728 | _IO_funlockfile (stderr); |
@@ -817,10 +785,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
817 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 785 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
818 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 786 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
819 | 787 | ||
820 | if (_IO_fwide (stderr, 0) > 0) | 788 | __fxprintf (NULL, "%s", buf); |
821 | __fwprintf (stderr, L"%s", buf); | ||
822 | else | ||
823 | fputs (buf, stderr); | ||
824 | 789 | ||
825 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 790 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
826 | _IO_funlockfile (stderr); | 791 | _IO_funlockfile (stderr); |
@@ -868,10 +833,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
868 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 833 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
869 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 834 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
870 | 835 | ||
871 | if (_IO_fwide (stderr, 0) > 0) | 836 | __fxprintf (NULL, "%s", buf); |
872 | __fwprintf (stderr, L"%s", buf); | ||
873 | else | ||
874 | fputs (buf, stderr); | ||
875 | 837 | ||
876 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 838 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
877 | _IO_funlockfile (stderr); | 839 | _IO_funlockfile (stderr); |
@@ -940,10 +902,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
940 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 902 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
941 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 903 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
942 | 904 | ||
943 | if (_IO_fwide (stderr, 0) > 0) | 905 | __fxprintf (NULL, "%s", buf); |
944 | __fwprintf (stderr, L"%s", buf); | ||
945 | else | ||
946 | fputs (buf, stderr); | ||
947 | 906 | ||
948 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 907 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
949 | _IO_funlockfile (stderr); | 908 | _IO_funlockfile (stderr); |
@@ -985,10 +944,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
985 | ((_IO_FILE *) stderr)->_flags2 | 944 | ((_IO_FILE *) stderr)->_flags2 |
986 | |= _IO_FLAGS2_NOTCANCEL; | 945 | |= _IO_FLAGS2_NOTCANCEL; |
987 | 946 | ||
988 | if (_IO_fwide (stderr, 0) > 0) | 947 | __fxprintf (NULL, "%s", buf); |
989 | __fwprintf (stderr, L"%s", buf); | ||
990 | else | ||
991 | fputs (buf, stderr); | ||
992 | 948 | ||
993 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 949 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
994 | _IO_funlockfile (stderr); | 950 | _IO_funlockfile (stderr); |
@@ -1027,10 +983,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
1027 | ((_IO_FILE *) stderr)->_flags2 | 983 | ((_IO_FILE *) stderr)->_flags2 |
1028 | |= _IO_FLAGS2_NOTCANCEL; | 984 | |= _IO_FLAGS2_NOTCANCEL; |
1029 | 985 | ||
1030 | if (_IO_fwide (stderr, 0) > 0) | 986 | __fxprintf (NULL, "%s", buf); |
1031 | __fwprintf (stderr, L"%s", buf); | ||
1032 | else | ||
1033 | fputs (buf, stderr); | ||
1034 | 987 | ||
1035 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 988 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
1036 | _IO_funlockfile (stderr); | 989 | _IO_funlockfile (stderr); |
@@ -1101,10 +1054,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
1101 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 1054 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
1102 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 1055 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; |
1103 | 1056 | ||
1104 | if (_IO_fwide (stderr, 0) > 0) | 1057 | __fxprintf (NULL, "%s", buf); |
1105 | __fwprintf (stderr, L"%s", buf); | ||
1106 | else | ||
1107 | fputs (buf, stderr); | ||
1108 | 1058 | ||
1109 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 1059 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; |
1110 | _IO_funlockfile (stderr); | 1060 | _IO_funlockfile (stderr); |
diff --git a/lib/getopt1.c b/gl/getopt1.c index 25d7926..cc0746e 100644 --- a/lib/getopt1.c +++ b/gl/getopt1.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* getopt_long and getopt_long_only entry points for GNU getopt. | 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. |
2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004 | 2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006 |
3 | Free Software Foundation, Inc. | 3 | Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
5 | 5 | ||
@@ -17,13 +17,10 @@ | |||
17 | with this program; if not, write to the Free Software Foundation, | 17 | with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #ifdef _LIBC | 20 | #ifdef _LIBC |
25 | # include <getopt.h> | 21 | # include <getopt.h> |
26 | #else | 22 | #else |
23 | # include <config.h> | ||
27 | # include "getopt.h" | 24 | # include "getopt.h" |
28 | #endif | 25 | #endif |
29 | #include "getopt_int.h" | 26 | #include "getopt_int.h" |
diff --git a/lib/getopt_.h b/gl/getopt_.h index 3c406e5..27fce3d 100644 --- a/lib/getopt_.h +++ b/gl/getopt_.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Declarations for getopt. | 1 | /* Declarations for getopt. |
2 | Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005 | 2 | Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006 |
3 | Free Software Foundation, Inc. | 3 | Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
5 | 5 | ||
@@ -196,9 +196,10 @@ struct option | |||
196 | scanning, explicitly telling `getopt' that there are no more | 196 | scanning, explicitly telling `getopt' that there are no more |
197 | options. | 197 | options. |
198 | 198 | ||
199 | If OPTS begins with `--', then non-option arguments are treated as | 199 | If OPTS begins with `-', then non-option arguments are treated as |
200 | arguments to the option '\0'. This behavior is specific to the GNU | 200 | arguments to the option '\1'. This behavior is specific to the GNU |
201 | `getopt'. */ | 201 | `getopt'. If OPTS begins with `+', or POSIXLY_CORRECT is set in |
202 | the environment, then do not permute arguments. */ | ||
202 | 203 | ||
203 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) | 204 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) |
204 | __THROW; | 205 | __THROW; |
diff --git a/lib/getopt_int.h b/gl/getopt_int.h index 401579f..401579f 100644 --- a/lib/getopt_int.h +++ b/gl/getopt_int.h | |||
diff --git a/gl/gettext.h b/gl/gettext.h new file mode 100644 index 0000000..9d76ec9 --- /dev/null +++ b/gl/gettext.h | |||
@@ -0,0 +1,270 @@ | |||
1 | /* Convenience header for conditional use of GNU <libintl.h>. | ||
2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _LIBGETTEXT_H | ||
19 | #define _LIBGETTEXT_H 1 | ||
20 | |||
21 | /* NLS can be disabled through the configure --disable-nls option. */ | ||
22 | #if ENABLE_NLS | ||
23 | |||
24 | /* Get declarations of GNU message catalog functions. */ | ||
25 | # include <libintl.h> | ||
26 | |||
27 | /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by | ||
28 | the gettext() and ngettext() macros. This is an alternative to calling | ||
29 | textdomain(), and is useful for libraries. */ | ||
30 | # ifdef DEFAULT_TEXT_DOMAIN | ||
31 | # undef gettext | ||
32 | # define gettext(Msgid) \ | ||
33 | dgettext (DEFAULT_TEXT_DOMAIN, Msgid) | ||
34 | # undef ngettext | ||
35 | # define ngettext(Msgid1, Msgid2, N) \ | ||
36 | dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) | ||
37 | # endif | ||
38 | |||
39 | #else | ||
40 | |||
41 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which | ||
42 | chokes if dcgettext is defined as a macro. So include it now, to make | ||
43 | later inclusions of <locale.h> a NOP. We don't include <libintl.h> | ||
44 | as well because people using "gettext.h" will not include <libintl.h>, | ||
45 | and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> | ||
46 | is OK. */ | ||
47 | #if defined(__sun) | ||
48 | # include <locale.h> | ||
49 | #endif | ||
50 | |||
51 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include | ||
52 | <libintl.h>, which chokes if dcgettext is defined as a macro. So include | ||
53 | it now, to make later inclusions of <libintl.h> a NOP. */ | ||
54 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) | ||
55 | # include <cstdlib> | ||
56 | # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H | ||
57 | # include <libintl.h> | ||
58 | # endif | ||
59 | #endif | ||
60 | |||
61 | /* Disabled NLS. | ||
62 | The casts to 'const char *' serve the purpose of producing warnings | ||
63 | for invalid uses of the value returned from these functions. | ||
64 | On pre-ANSI systems without 'const', the config.h file is supposed to | ||
65 | contain "#define const". */ | ||
66 | # define gettext(Msgid) ((const char *) (Msgid)) | ||
67 | # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) | ||
68 | # define dcgettext(Domainname, Msgid, Category) \ | ||
69 | ((void) (Category), dgettext (Domainname, Msgid)) | ||
70 | # define ngettext(Msgid1, Msgid2, N) \ | ||
71 | ((N) == 1 \ | ||
72 | ? ((void) (Msgid2), (const char *) (Msgid1)) \ | ||
73 | : ((void) (Msgid1), (const char *) (Msgid2))) | ||
74 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ | ||
75 | ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) | ||
76 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ | ||
77 | ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) | ||
78 | # define textdomain(Domainname) ((const char *) (Domainname)) | ||
79 | # define bindtextdomain(Domainname, Dirname) \ | ||
80 | ((void) (Domainname), (const char *) (Dirname)) | ||
81 | # define bind_textdomain_codeset(Domainname, Codeset) \ | ||
82 | ((void) (Domainname), (const char *) (Codeset)) | ||
83 | |||
84 | #endif | ||
85 | |||
86 | /* A pseudo function call that serves as a marker for the automated | ||
87 | extraction of messages, but does not call gettext(). The run-time | ||
88 | translation is done at a different place in the code. | ||
89 | The argument, String, should be a literal string. Concatenated strings | ||
90 | and other string expressions won't work. | ||
91 | The macro's expansion is not parenthesized, so that it is suitable as | ||
92 | initializer for static 'char[]' or 'const char[]' variables. */ | ||
93 | #define gettext_noop(String) String | ||
94 | |||
95 | /* The separator between msgctxt and msgid in a .mo file. */ | ||
96 | #define GETTEXT_CONTEXT_GLUE "\004" | ||
97 | |||
98 | /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a | ||
99 | MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be | ||
100 | short and rarely need to change. | ||
101 | The letter 'p' stands for 'particular' or 'special'. */ | ||
102 | #ifdef DEFAULT_TEXT_DOMAIN | ||
103 | # define pgettext(Msgctxt, Msgid) \ | ||
104 | pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) | ||
105 | #else | ||
106 | # define pgettext(Msgctxt, Msgid) \ | ||
107 | pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) | ||
108 | #endif | ||
109 | #define dpgettext(Domainname, Msgctxt, Msgid) \ | ||
110 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) | ||
111 | #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ | ||
112 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) | ||
113 | #ifdef DEFAULT_TEXT_DOMAIN | ||
114 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ | ||
115 | npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) | ||
116 | #else | ||
117 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ | ||
118 | npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) | ||
119 | #endif | ||
120 | #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ | ||
121 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) | ||
122 | #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ | ||
123 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) | ||
124 | |||
125 | #ifdef __GNUC__ | ||
126 | __inline | ||
127 | #else | ||
128 | #ifdef __cplusplus | ||
129 | inline | ||
130 | #endif | ||
131 | #endif | ||
132 | static const char * | ||
133 | pgettext_aux (const char *domain, | ||
134 | const char *msg_ctxt_id, const char *msgid, | ||
135 | int category) | ||
136 | { | ||
137 | const char *translation = dcgettext (domain, msg_ctxt_id, category); | ||
138 | if (translation == msg_ctxt_id) | ||
139 | return msgid; | ||
140 | else | ||
141 | return translation; | ||
142 | } | ||
143 | |||
144 | #ifdef __GNUC__ | ||
145 | __inline | ||
146 | #else | ||
147 | #ifdef __cplusplus | ||
148 | inline | ||
149 | #endif | ||
150 | #endif | ||
151 | static const char * | ||
152 | npgettext_aux (const char *domain, | ||
153 | const char *msg_ctxt_id, const char *msgid, | ||
154 | const char *msgid_plural, unsigned long int n, | ||
155 | int category) | ||
156 | { | ||
157 | const char *translation = | ||
158 | dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); | ||
159 | if (translation == msg_ctxt_id || translation == msgid_plural) | ||
160 | return (n == 1 ? msgid : msgid_plural); | ||
161 | else | ||
162 | return translation; | ||
163 | } | ||
164 | |||
165 | /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID | ||
166 | can be arbitrary expressions. But for string literals these macros are | ||
167 | less efficient than those above. */ | ||
168 | |||
169 | #include <string.h> | ||
170 | |||
171 | #define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ | ||
172 | (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ | ||
173 | /* || __STDC_VERSION__ >= 199901L */ ) | ||
174 | |||
175 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | ||
176 | #include <stdlib.h> | ||
177 | #endif | ||
178 | |||
179 | #define pgettext_expr(Msgctxt, Msgid) \ | ||
180 | dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) | ||
181 | #define dpgettext_expr(Domainname, Msgctxt, Msgid) \ | ||
182 | dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) | ||
183 | |||
184 | #ifdef __GNUC__ | ||
185 | __inline | ||
186 | #else | ||
187 | #ifdef __cplusplus | ||
188 | inline | ||
189 | #endif | ||
190 | #endif | ||
191 | static const char * | ||
192 | dcpgettext_expr (const char *domain, | ||
193 | const char *msgctxt, const char *msgid, | ||
194 | int category) | ||
195 | { | ||
196 | size_t msgctxt_len = strlen (msgctxt) + 1; | ||
197 | size_t msgid_len = strlen (msgid) + 1; | ||
198 | const char *translation; | ||
199 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | ||
200 | char msg_ctxt_id[msgctxt_len + msgid_len]; | ||
201 | #else | ||
202 | char buf[1024]; | ||
203 | char *msg_ctxt_id = | ||
204 | (msgctxt_len + msgid_len <= sizeof (buf) | ||
205 | ? buf | ||
206 | : (char *) malloc (msgctxt_len + msgid_len)); | ||
207 | if (msg_ctxt_id != NULL) | ||
208 | #endif | ||
209 | { | ||
210 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); | ||
211 | msg_ctxt_id[msgctxt_len - 1] = '\004'; | ||
212 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); | ||
213 | translation = dcgettext (domain, msg_ctxt_id, category); | ||
214 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | ||
215 | if (msg_ctxt_id != buf) | ||
216 | free (msg_ctxt_id); | ||
217 | #endif | ||
218 | if (translation != msg_ctxt_id) | ||
219 | return translation; | ||
220 | } | ||
221 | return msgid; | ||
222 | } | ||
223 | |||
224 | #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ | ||
225 | dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) | ||
226 | #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ | ||
227 | dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) | ||
228 | |||
229 | #ifdef __GNUC__ | ||
230 | __inline | ||
231 | #else | ||
232 | #ifdef __cplusplus | ||
233 | inline | ||
234 | #endif | ||
235 | #endif | ||
236 | static const char * | ||
237 | dcnpgettext_expr (const char *domain, | ||
238 | const char *msgctxt, const char *msgid, | ||
239 | const char *msgid_plural, unsigned long int n, | ||
240 | int category) | ||
241 | { | ||
242 | size_t msgctxt_len = strlen (msgctxt) + 1; | ||
243 | size_t msgid_len = strlen (msgid) + 1; | ||
244 | const char *translation; | ||
245 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | ||
246 | char msg_ctxt_id[msgctxt_len + msgid_len]; | ||
247 | #else | ||
248 | char buf[1024]; | ||
249 | char *msg_ctxt_id = | ||
250 | (msgctxt_len + msgid_len <= sizeof (buf) | ||
251 | ? buf | ||
252 | : (char *) malloc (msgctxt_len + msgid_len)); | ||
253 | if (msg_ctxt_id != NULL) | ||
254 | #endif | ||
255 | { | ||
256 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); | ||
257 | msg_ctxt_id[msgctxt_len - 1] = '\004'; | ||
258 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); | ||
259 | translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); | ||
260 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | ||
261 | if (msg_ctxt_id != buf) | ||
262 | free (msg_ctxt_id); | ||
263 | #endif | ||
264 | if (!(translation == msg_ctxt_id || translation == msgid_plural)) | ||
265 | return translation; | ||
266 | } | ||
267 | return (n == 1 ? msgid : msgid_plural); | ||
268 | } | ||
269 | |||
270 | #endif /* _LIBGETTEXT_H */ | ||
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c new file mode 100644 index 0000000..537b59f --- /dev/null +++ b/gl/inet_ntop.c | |||
@@ -0,0 +1,238 @@ | |||
1 | /* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form | ||
2 | |||
3 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* | ||
20 | * Copyright (c) 1996-1999 by Internet Software Consortium. | ||
21 | * | ||
22 | * Permission to use, copy, modify, and distribute this software for any | ||
23 | * purpose with or without fee is hereby granted, provided that the above | ||
24 | * copyright notice and this permission notice appear in all copies. | ||
25 | * | ||
26 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
27 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
28 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
29 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
30 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
31 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
32 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
33 | * SOFTWARE. | ||
34 | */ | ||
35 | |||
36 | #include <config.h> | ||
37 | |||
38 | /* Specification. */ | ||
39 | #include "inet_ntop.h" | ||
40 | |||
41 | #include <stdio.h> | ||
42 | #include <string.h> | ||
43 | #include <errno.h> | ||
44 | |||
45 | #ifndef EAFNOSUPPORT | ||
46 | # define EAFNOSUPPORT EINVAL | ||
47 | #endif | ||
48 | |||
49 | #define NS_IN6ADDRSZ 16 | ||
50 | #define NS_INT16SZ 2 | ||
51 | |||
52 | /* | ||
53 | * WARNING: Don't even consider trying to compile this on a system where | ||
54 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
55 | */ | ||
56 | typedef int verify_int_size[2 * sizeof (int) - 7]; | ||
57 | |||
58 | static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); | ||
59 | #if HAVE_IPV6 | ||
60 | static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); | ||
61 | #endif | ||
62 | |||
63 | |||
64 | /* char * | ||
65 | * inet_ntop(af, src, dst, size) | ||
66 | * convert a network format address to presentation format. | ||
67 | * return: | ||
68 | * pointer to presentation format address (`dst'), or NULL (see errno). | ||
69 | * author: | ||
70 | * Paul Vixie, 1996. | ||
71 | */ | ||
72 | const char * | ||
73 | inet_ntop (int af, const void *restrict src, | ||
74 | char *restrict dst, socklen_t cnt) | ||
75 | { | ||
76 | switch (af) | ||
77 | { | ||
78 | #if HAVE_IPV4 | ||
79 | case AF_INET: | ||
80 | return (inet_ntop4 (src, dst, cnt)); | ||
81 | #endif | ||
82 | |||
83 | #if HAVE_IPV6 | ||
84 | case AF_INET6: | ||
85 | return (inet_ntop6 (src, dst, cnt)); | ||
86 | #endif | ||
87 | |||
88 | default: | ||
89 | errno = EAFNOSUPPORT; | ||
90 | return (NULL); | ||
91 | } | ||
92 | /* NOTREACHED */ | ||
93 | } | ||
94 | |||
95 | /* const char * | ||
96 | * inet_ntop4(src, dst, size) | ||
97 | * format an IPv4 address | ||
98 | * return: | ||
99 | * `dst' (as a const) | ||
100 | * notes: | ||
101 | * (1) uses no statics | ||
102 | * (2) takes a u_char* not an in_addr as input | ||
103 | * author: | ||
104 | * Paul Vixie, 1996. | ||
105 | */ | ||
106 | static const char * | ||
107 | inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) | ||
108 | { | ||
109 | char tmp[sizeof "255.255.255.255"]; | ||
110 | int len; | ||
111 | |||
112 | len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); | ||
113 | if (len < 0) | ||
114 | return NULL; | ||
115 | |||
116 | if (len > size) | ||
117 | { | ||
118 | errno = ENOSPC; | ||
119 | return NULL; | ||
120 | } | ||
121 | |||
122 | return strcpy (dst, tmp); | ||
123 | } | ||
124 | |||
125 | #if HAVE_IPV6 | ||
126 | |||
127 | /* const char * | ||
128 | * inet_ntop6(src, dst, size) | ||
129 | * convert IPv6 binary address into presentation (printable) format | ||
130 | * author: | ||
131 | * Paul Vixie, 1996. | ||
132 | */ | ||
133 | static const char * | ||
134 | inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) | ||
135 | { | ||
136 | /* | ||
137 | * Note that int32_t and int16_t need only be "at least" large enough | ||
138 | * to contain a value of the specified size. On some systems, like | ||
139 | * Crays, there is no such thing as an integer variable with 16 bits. | ||
140 | * Keep this in mind if you think this function should have been coded | ||
141 | * to use pointer overlays. All the world's not a VAX. | ||
142 | */ | ||
143 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
144 | struct | ||
145 | { | ||
146 | int base, len; | ||
147 | } best, cur; | ||
148 | unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; | ||
149 | int i; | ||
150 | |||
151 | /* | ||
152 | * Preprocess: | ||
153 | * Copy the input (bytewise) array into a wordwise array. | ||
154 | * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
155 | */ | ||
156 | memset (words, '\0', sizeof words); | ||
157 | for (i = 0; i < NS_IN6ADDRSZ; i += 2) | ||
158 | words[i / 2] = (src[i] << 8) | src[i + 1]; | ||
159 | best.base = -1; | ||
160 | cur.base = -1; | ||
161 | for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) | ||
162 | { | ||
163 | if (words[i] == 0) | ||
164 | { | ||
165 | if (cur.base == -1) | ||
166 | cur.base = i, cur.len = 1; | ||
167 | else | ||
168 | cur.len++; | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | if (cur.base != -1) | ||
173 | { | ||
174 | if (best.base == -1 || cur.len > best.len) | ||
175 | best = cur; | ||
176 | cur.base = -1; | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | if (cur.base != -1) | ||
181 | { | ||
182 | if (best.base == -1 || cur.len > best.len) | ||
183 | best = cur; | ||
184 | } | ||
185 | if (best.base != -1 && best.len < 2) | ||
186 | best.base = -1; | ||
187 | |||
188 | /* | ||
189 | * Format the result. | ||
190 | */ | ||
191 | tp = tmp; | ||
192 | for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) | ||
193 | { | ||
194 | /* Are we inside the best run of 0x00's? */ | ||
195 | if (best.base != -1 && i >= best.base && i < (best.base + best.len)) | ||
196 | { | ||
197 | if (i == best.base) | ||
198 | *tp++ = ':'; | ||
199 | continue; | ||
200 | } | ||
201 | /* Are we following an initial run of 0x00s or any real hex? */ | ||
202 | if (i != 0) | ||
203 | *tp++ = ':'; | ||
204 | /* Is this address an encapsulated IPv4? */ | ||
205 | if (i == 6 && best.base == 0 && | ||
206 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) | ||
207 | { | ||
208 | if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) | ||
209 | return (NULL); | ||
210 | tp += strlen (tp); | ||
211 | break; | ||
212 | } | ||
213 | { | ||
214 | int len = sprintf (tp, "%x", words[i]); | ||
215 | if (len < 0) | ||
216 | return NULL; | ||
217 | tp += len; | ||
218 | } | ||
219 | } | ||
220 | /* Was it a trailing run of 0x00's? */ | ||
221 | if (best.base != -1 && (best.base + best.len) == | ||
222 | (NS_IN6ADDRSZ / NS_INT16SZ)) | ||
223 | *tp++ = ':'; | ||
224 | *tp++ = '\0'; | ||
225 | |||
226 | /* | ||
227 | * Check for overflow, copy, and we're done. | ||
228 | */ | ||
229 | if ((socklen_t) (tp - tmp) > size) | ||
230 | { | ||
231 | errno = ENOSPC; | ||
232 | return NULL; | ||
233 | } | ||
234 | |||
235 | return strcpy (dst, tmp); | ||
236 | } | ||
237 | |||
238 | #endif | ||
diff --git a/gl/inet_ntop.h b/gl/inet_ntop.h new file mode 100644 index 0000000..bd1e085 --- /dev/null +++ b/gl/inet_ntop.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* Convert internet address from internal to printable, presentable format. | ||
2 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | #include <sys/socket.h> | ||
20 | #include <netinet/in.h> | ||
21 | #include <arpa/inet.h> | ||
22 | |||
23 | /* Converts an internet address from internal format to a printable, | ||
24 | presentable format. | ||
25 | AF is an internet address family, such as AF_INET or AF_INET6. | ||
26 | SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr' | ||
27 | (for AF_INET6). | ||
28 | DST points to a buffer having room for CNT bytes. | ||
29 | The printable representation of the address (in numeric form, not | ||
30 | surrounded by [...], no reverse DNS is done) is placed in DST, and | ||
31 | DST is returned. If an error occurs, the return value is NULL and | ||
32 | errno is set. If CNT bytes are not sufficient to hold the result, | ||
33 | the return value is NULL and errno is set to ENOSPC. A good value | ||
34 | for CNT is 46. | ||
35 | |||
36 | For more details, see the POSIX:2001 specification | ||
37 | <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */ | ||
38 | |||
39 | #if !HAVE_DECL_INET_NTOP | ||
40 | extern const char *inet_ntop (int af, const void *restrict src, | ||
41 | char *restrict dst, socklen_t cnt); | ||
42 | #endif | ||
diff --git a/lib/intprops.h b/gl/intprops.h index 65280b1..34f971c 100644 --- a/lib/intprops.h +++ b/gl/intprops.h | |||
@@ -53,12 +53,25 @@ | |||
53 | ? (t) -1 \ | 53 | ? (t) -1 \ |
54 | : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) | 54 | : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) |
55 | 55 | ||
56 | /* Return zero if T can be determined to be an unsigned type. | ||
57 | Otherwise, return 1. | ||
58 | When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a | ||
59 | tighter bound. Otherwise, it overestimates the true bound by one byte | ||
60 | when applied to unsigned types of size 2, 4, 16, ... bytes. | ||
61 | The symbol signed_type_or_expr__ is private to this header file. */ | ||
62 | #if __GNUC__ >= 2 | ||
63 | # define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t)) | ||
64 | #else | ||
65 | # define signed_type_or_expr__(t) 1 | ||
66 | #endif | ||
67 | |||
56 | /* Bound on length of the string representing an integer type or expression T. | 68 | /* Bound on length of the string representing an integer type or expression T. |
57 | Subtract 1 for the sign bit if t is signed; log10 (2.0) < 146/485; | 69 | Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485; |
58 | add 1 for integer division truncation; add 1 more for a minus sign | 70 | add 1 for integer division truncation; add 1 more for a minus sign |
59 | if needed. */ | 71 | if needed. */ |
60 | #define INT_STRLEN_BOUND(t) \ | 72 | #define INT_STRLEN_BOUND(t) \ |
61 | ((sizeof (t) * CHAR_BIT - 1) * 146 / 485 + 2) | 73 | ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \ |
74 | + signed_type_or_expr__ (t) + 1) | ||
62 | 75 | ||
63 | /* Bound on buffer size needed to represent an integer type or expression T, | 76 | /* Bound on buffer size needed to represent an integer type or expression T, |
64 | including the terminating null. */ | 77 | including the terminating null. */ |
diff --git a/gl/m4/absolute-header.m4 b/gl/m4/absolute-header.m4 new file mode 100644 index 0000000..c649df0 --- /dev/null +++ b/gl/m4/absolute-header.m4 | |||
@@ -0,0 +1,44 @@ | |||
1 | # absolute-header.m4 serial 6 | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Derek Price. | ||
8 | |||
9 | # gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...) | ||
10 | # --------------------------------------- | ||
11 | # Find the absolute name of a header file, assuming the header exists. | ||
12 | # If the header were sys/inttypes.h, this macro would define | ||
13 | # ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h | ||
14 | # in config.h | ||
15 | # (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"'). | ||
16 | # The three "///" are to pacify Sun C 5.8, which otherwise would say | ||
17 | # "warning: #include of /usr/include/... may be non-portable". | ||
18 | # Use `""', not `<>', so that the /// cannot be confused with a C99 comment. | ||
19 | AC_DEFUN([gl_ABSOLUTE_HEADER], | ||
20 | [AC_LANG_PREPROC_REQUIRE()dnl | ||
21 | AC_FOREACH([gl_HEADER_NAME], [$1], | ||
22 | [AS_VAR_PUSHDEF([gl_absolute_header], | ||
23 | [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl | ||
24 | AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], | ||
25 | m4_quote(m4_defn([gl_absolute_header])), | ||
26 | [AS_VAR_PUSHDEF([ac_header_exists], | ||
27 | [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl | ||
28 | AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl | ||
29 | if test AS_VAR_GET(ac_header_exists) = yes; then | ||
30 | AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])]) | ||
31 | dnl eval is necessary to expand ac_cpp. | ||
32 | dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. | ||
33 | AS_VAR_SET(gl_absolute_header, | ||
34 | [`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | | ||
35 | sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#;s#^/[^/]#//&#;p;q;}'`]) | ||
36 | fi | ||
37 | AS_VAR_POPDEF([ac_header_exists])dnl | ||
38 | ])dnl | ||
39 | AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))), | ||
40 | ["AS_VAR_GET(gl_absolute_header)"], | ||
41 | [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.]) | ||
42 | AS_VAR_POPDEF([gl_absolute_header])dnl | ||
43 | ])dnl | ||
44 | ])# gl_ABSOLUTE_HEADER | ||
diff --git a/m4/alloca.m4 b/gl/m4/alloca.m4 index a9e3f45..eb62e0e 100644 --- a/m4/alloca.m4 +++ b/gl/m4/alloca.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # alloca.m4 serial 5 | 1 | # alloca.m4 serial 7 |
2 | dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -17,16 +17,24 @@ AC_DEFUN([gl_FUNC_ALLOCA], | |||
17 | 17 | ||
18 | # Define an additional variable used in the Makefile substitution. | 18 | # Define an additional variable used in the Makefile substitution. |
19 | if test $ac_cv_working_alloca_h = yes; then | 19 | if test $ac_cv_working_alloca_h = yes; then |
20 | AC_EGREP_CPP([Need own alloca], [ | 20 | AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ |
21 | AC_EGREP_CPP([Need own alloca], [ | ||
21 | #if defined __GNUC__ || defined _AIX || defined _MSC_VER | 22 | #if defined __GNUC__ || defined _AIX || defined _MSC_VER |
22 | Need own alloca | 23 | Need own alloca |
23 | #endif | 24 | #endif |
24 | ], | 25 | ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) |
25 | [AC_DEFINE(HAVE_ALLOCA, 1, | 26 | ]) |
26 | [Define to 1 if you have `alloca' after including <alloca.h>, | 27 | if test $gl_cv_rpl_alloca = yes; then |
27 | a header that may be supplied by this distribution.]) | 28 | dnl OK, alloca can be implemented through a compiler built-in. |
28 | ALLOCA_H=alloca.h], | 29 | AC_DEFINE([HAVE_ALLOCA], 1, |
29 | [ALLOCA_H=]) | 30 | [Define to 1 if you have 'alloca' after including <alloca.h>, |
31 | a header that may be supplied by this distribution.]) | ||
32 | ALLOCA_H=alloca.h | ||
33 | else | ||
34 | dnl alloca exists as a library function, i.e. it is slow and probably | ||
35 | dnl a memory leak. Don't define HAVE_ALLOCA in this case. | ||
36 | ALLOCA_H= | ||
37 | fi | ||
30 | else | 38 | else |
31 | ALLOCA_H=alloca.h | 39 | ALLOCA_H=alloca.h |
32 | fi | 40 | fi |
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4 new file mode 100644 index 0000000..d01d098 --- /dev/null +++ b/gl/m4/arpa_inet_h.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # arpa_inet_h.m4 serial 1 | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl Written by Simon Josefsson | ||
8 | |||
9 | AC_DEFUN([gl_HEADER_ARPA_INET], | ||
10 | [ | ||
11 | AC_CHECK_HEADERS_ONCE([arpa/inet.h]) | ||
12 | if test $ac_cv_header_arpa_inet_h = yes; then | ||
13 | ARPA_INET_H='' | ||
14 | else | ||
15 | ARPA_INET_H='arpa/inet.h' | ||
16 | fi | ||
17 | AC_SUBST(ARPA_INET_H) | ||
18 | ]) | ||
diff --git a/m4/c-strtod.m4 b/gl/m4/c-strtod.m4 index ffeb458..7f206c7 100644 --- a/m4/c-strtod.m4 +++ b/gl/m4/c-strtod.m4 | |||
@@ -1,6 +1,6 @@ | |||
1 | # c-strtod.m4 serial 6 | 1 | # c-strtod.m4 serial 9 |
2 | 2 | ||
3 | # Copyright (C) 2004, 2005 Free Software Foundation, Inc. | 3 | # Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. |
4 | # This file is free software; the Free Software Foundation | 4 | # This file is free software; the Free Software Foundation |
5 | # gives unlimited permission to copy and/or distribute it, | 5 | # gives unlimited permission to copy and/or distribute it, |
6 | # with or without modifications, as long as this notice is preserved. | 6 | # with or without modifications, as long as this notice is preserved. |
@@ -11,7 +11,7 @@ AC_DEFUN([gl_C99_STRTOLD], | |||
11 | [ | 11 | [ |
12 | AC_CACHE_CHECK([whether strtold conforms to C99], | 12 | AC_CACHE_CHECK([whether strtold conforms to C99], |
13 | [gl_cv_func_c99_strtold], | 13 | [gl_cv_func_c99_strtold], |
14 | [AC_COMPILE_IFELSE( | 14 | [AC_LINK_IFELSE( |
15 | [AC_LANG_PROGRAM( | 15 | [AC_LANG_PROGRAM( |
16 | [[/* On HP-UX before 11.23, strtold returns a struct instead of | 16 | [[/* On HP-UX before 11.23, strtold returns a struct instead of |
17 | long double. Reject implementations like that, by requiring | 17 | long double. Reject implementations like that, by requiring |
@@ -35,7 +35,6 @@ AC_DEFUN([gl_C99_STRTOLD], | |||
35 | 35 | ||
36 | AC_DEFUN([gl_C_STRTOD], | 36 | AC_DEFUN([gl_C_STRTOD], |
37 | [ | 37 | [ |
38 | AC_LIBSOURCES([c-strtod.c, c-strtod.h]) | ||
39 | AC_LIBOBJ([c-strtod]) | 38 | AC_LIBOBJ([c-strtod]) |
40 | 39 | ||
41 | dnl Prerequisites of lib/c-strtod.c. | 40 | dnl Prerequisites of lib/c-strtod.c. |
@@ -45,11 +44,10 @@ AC_DEFUN([gl_C_STRTOD], | |||
45 | 44 | ||
46 | AC_DEFUN([gl_C_STRTOLD], | 45 | AC_DEFUN([gl_C_STRTOLD], |
47 | [ | 46 | [ |
48 | AC_LIBSOURCES([c-strtold.c, c-strtod.h]) | ||
49 | AC_LIBOBJ([c-strtold]) | 47 | AC_LIBOBJ([c-strtold]) |
50 | 48 | ||
51 | dnl Prerequisites of lib/c-strtold.c. | 49 | dnl Prerequisites of lib/c-strtold.c. |
52 | AC_REQUIRE([gl_C_STRTOD]) | 50 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
53 | AC_REQUIRE([gl_C99_STRTOLD]) | 51 | AC_REQUIRE([gl_C99_STRTOLD]) |
54 | : | 52 | : |
55 | ]) | 53 | ]) |
diff --git a/gl/m4/cloexec.m4 b/gl/m4/cloexec.m4 new file mode 100644 index 0000000..4c4e26a --- /dev/null +++ b/gl/m4/cloexec.m4 | |||
@@ -0,0 +1,10 @@ | |||
1 | #serial 6 | ||
2 | dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_CLOEXEC], | ||
8 | [ | ||
9 | AC_LIBOBJ([cloexec]) | ||
10 | ]) | ||
diff --git a/m4/codeset.m4 b/gl/m4/codeset.m4 index a6e67ec..223955b 100644 --- a/m4/codeset.m4 +++ b/gl/m4/codeset.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # codeset.m4 serial AM1 (gettext-0.10.40) | 1 | # codeset.m4 serial 2 (gettext-0.16) |
2 | dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -10,7 +10,7 @@ AC_DEFUN([AM_LANGINFO_CODESET], | |||
10 | [ | 10 | [ |
11 | AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, | 11 | AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, |
12 | [AC_TRY_LINK([#include <langinfo.h>], | 12 | [AC_TRY_LINK([#include <langinfo.h>], |
13 | [char* cs = nl_langinfo(CODESET);], | 13 | [char* cs = nl_langinfo(CODESET); return !cs;], |
14 | am_cv_langinfo_codeset=yes, | 14 | am_cv_langinfo_codeset=yes, |
15 | am_cv_langinfo_codeset=no) | 15 | am_cv_langinfo_codeset=no) |
16 | ]) | 16 | ]) |
diff --git a/gl/m4/dirname.m4 b/gl/m4/dirname.m4 new file mode 100644 index 0000000..e35da96 --- /dev/null +++ b/gl/m4/dirname.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | #serial 7 -*- autoconf -*- | ||
2 | dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_DIRNAME], | ||
8 | [ | ||
9 | AC_LIBOBJ([basename]) | ||
10 | AC_LIBOBJ([dirname]) | ||
11 | AC_LIBOBJ([stripslash]) | ||
12 | |||
13 | dnl Prerequisites of lib/dirname.h. | ||
14 | AC_REQUIRE([gl_AC_DOS]) | ||
15 | AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) | ||
16 | |||
17 | dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c. | ||
18 | ]) | ||
@@ -1,9 +1,9 @@ | |||
1 | #serial 9 | 1 | #serial 10 -*- autoconf -*- |
2 | 2 | ||
3 | # Define some macros required for proper operation of code in lib/*.c | 3 | # Define some macros required for proper operation of code in lib/*.c |
4 | # on MSDOS/Windows systems. | 4 | # on MSDOS/Windows systems. |
5 | 5 | ||
6 | # Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. | 6 | # Copyright (C) 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. |
7 | # This file is free software; the Free Software Foundation | 7 | # This file is free software; the Free Software Foundation |
8 | # gives unlimited permission to copy and/or distribute it, | 8 | # gives unlimited permission to copy and/or distribute it, |
9 | # with or without modifications, as long as this notice is preserved. | 9 | # with or without modifications, as long as this notice is preserved. |
@@ -14,30 +14,38 @@ AC_DEFUN([gl_AC_DOS], | |||
14 | [ | 14 | [ |
15 | AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], | 15 | AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], |
16 | [ | 16 | [ |
17 | AC_TRY_COMPILE([], | 17 | AC_TRY_COMPILE([], |
18 | [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ | 18 | [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ |
19 | neither MSDOS nor Windows | 19 | neither MSDOS nor Windows |
20 | #endif], | 20 | #endif], |
21 | [ac_cv_win_or_dos=yes], | 21 | [ac_cv_win_or_dos=yes], |
22 | [ac_cv_win_or_dos=no]) | 22 | [ac_cv_win_or_dos=no]) |
23 | ]) | 23 | ]) |
24 | 24 | ||
25 | if test x"$ac_cv_win_or_dos" = xyes; then | 25 | if test x"$ac_cv_win_or_dos" = xyes; then |
26 | ac_fs_accepts_drive_letter_prefix=1 | 26 | ac_fs_accepts_drive_letter_prefix=1 |
27 | ac_fs_backslash_is_file_name_separator=1 | 27 | ac_fs_backslash_is_file_name_separator=1 |
28 | AC_CACHE_CHECK([whether drive letter can start relative path], | ||
29 | [ac_cv_drive_letter_can_be_relative], | ||
30 | [ | ||
31 | AC_TRY_COMPILE([], | ||
32 | [#if defined __CYGWIN__ | ||
33 | drive letters are always absolute | ||
34 | #endif], | ||
35 | [ac_cv_drive_letter_can_be_relative=yes], | ||
36 | [ac_cv_drive_letter_can_be_relative=no]) | ||
37 | ]) | ||
38 | if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then | ||
39 | ac_fs_drive_letter_can_be_relative=1 | ||
40 | else | ||
41 | ac_fs_drive_letter_can_be_relative=0 | ||
42 | fi | ||
28 | else | 43 | else |
29 | ac_fs_accepts_drive_letter_prefix=0 | 44 | ac_fs_accepts_drive_letter_prefix=0 |
30 | ac_fs_backslash_is_file_name_separator=0 | 45 | ac_fs_backslash_is_file_name_separator=0 |
46 | ac_fs_drive_letter_can_be_relative=0 | ||
31 | fi | 47 | fi |
32 | 48 | ||
33 | AH_VERBATIM(FILE_SYSTEM_PREFIX_LEN, | ||
34 | [#if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX | ||
35 | # define FILE_SYSTEM_PREFIX_LEN(Filename) \ | ||
36 | ((Filename)[0] && (Filename)[1] == ':' ? 2 : 0) | ||
37 | #else | ||
38 | # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 | ||
39 | #endif]) | ||
40 | |||
41 | AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], | 49 | AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], |
42 | $ac_fs_accepts_drive_letter_prefix, | 50 | $ac_fs_accepts_drive_letter_prefix, |
43 | [Define on systems for which file names may have a so-called | 51 | [Define on systems for which file names may have a so-called |
@@ -55,4 +63,9 @@ neither MSDOS nor Windows | |||
55 | $ac_fs_backslash_is_file_name_separator, | 63 | $ac_fs_backslash_is_file_name_separator, |
56 | [Define if the backslash character may also serve as a file name | 64 | [Define if the backslash character may also serve as a file name |
57 | component separator.]) | 65 | component separator.]) |
66 | |||
67 | AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE], | ||
68 | $ac_fs_drive_letter_can_be_relative, | ||
69 | [Define if a drive letter prefix denotes a relative path if it is | ||
70 | not followed by a file name component separator.]) | ||
58 | ]) | 71 | ]) |
diff --git a/gl/m4/double-slash-root.m4 b/gl/m4/double-slash-root.m4 new file mode 100644 index 0000000..69d60d0 --- /dev/null +++ b/gl/m4/double-slash-root.m4 | |||
@@ -0,0 +1,38 @@ | |||
1 | # double-slash-root.m4 serial 2 -*- Autoconf -*- | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_DOUBLE_SLASH_ROOT], | ||
8 | [ | ||
9 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
10 | AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], | ||
11 | [ if test x"$cross_compiling" = xyes ; then | ||
12 | # When cross-compiling, there is no way to tell whether // is special | ||
13 | # short of a list of hosts. However, the only known hosts to date | ||
14 | # that have a distinct // are Apollo DomainOS (too old to port to), | ||
15 | # Cygwin, and z/OS. If anyone knows of another system for which // has | ||
16 | # special semantics and is distinct from /, please report it to | ||
17 | # <bug-gnulib@gnu.org>. | ||
18 | case $host in | ||
19 | *-cygwin | i370-ibm-openedition) | ||
20 | gl_cv_double_slash_root=yes ;; | ||
21 | *) | ||
22 | # Be optimistic and assume that / and // are the same when we | ||
23 | # don't know. | ||
24 | gl_cv_double_slash_root='unknown, assuming no' ;; | ||
25 | esac | ||
26 | else | ||
27 | set x `ls -di / //` | ||
28 | if test $[2] = $[4] && wc //dev/null >/dev/null 2>&1; then | ||
29 | gl_cv_double_slash_root=no | ||
30 | else | ||
31 | gl_cv_double_slash_root=yes | ||
32 | fi | ||
33 | fi]) | ||
34 | if test "$gl_cv_double_slash_root" = yes; then | ||
35 | AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], 1, | ||
36 | [Define to 1 if // is a file system root distinct from /.]) | ||
37 | fi | ||
38 | ]) | ||
diff --git a/gl/m4/eoverflow.m4 b/gl/m4/eoverflow.m4 new file mode 100644 index 0000000..3bffd10 --- /dev/null +++ b/gl/m4/eoverflow.m4 | |||
@@ -0,0 +1,70 @@ | |||
1 | # eoverflow.m4 serial 2 | ||
2 | dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | # The EOVERFLOW errno value ought to be defined in <errno.h>, according to | ||
10 | # POSIX. But some systems (like AIX 3) don't define it, and some systems | ||
11 | # (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined. | ||
12 | |||
13 | # Define EOVERFLOW as a C macro and as a substituted macro in such a way that | ||
14 | # 1. on all systems, after inclusion of <errno.h>, EOVERFLOW is usable, | ||
15 | # 2. on systems where EOVERFLOW is defined elsewhere, we use the same numeric | ||
16 | # value. | ||
17 | |||
18 | AC_DEFUN([gl_EOVERFLOW], | ||
19 | [ | ||
20 | AC_REQUIRE([AC_PROG_CC])dnl | ||
21 | |||
22 | AC_CACHE_CHECK([for EOVERFLOW], ac_cv_decl_EOVERFLOW, [ | ||
23 | AC_EGREP_CPP(yes,[ | ||
24 | #include <errno.h> | ||
25 | #ifdef EOVERFLOW | ||
26 | yes | ||
27 | #endif | ||
28 | ], have_eoverflow=1) | ||
29 | if test -n "$have_eoverflow"; then | ||
30 | dnl EOVERFLOW exists in <errno.h>. Don't need to define EOVERFLOW ourselves. | ||
31 | ac_cv_decl_EOVERFLOW=yes | ||
32 | else | ||
33 | AC_EGREP_CPP(yes,[ | ||
34 | #define _XOPEN_SOURCE_EXTENDED 1 | ||
35 | #include <errno.h> | ||
36 | #ifdef EOVERFLOW | ||
37 | yes | ||
38 | #endif | ||
39 | ], have_eoverflow=1) | ||
40 | if test -n "$have_eoverflow"; then | ||
41 | dnl EOVERFLOW exists but is hidden. | ||
42 | dnl Define it to the same value. | ||
43 | AC_COMPUTE_INT([ac_cv_decl_EOVERFLOW], [EOVERFLOW], [ | ||
44 | #define _XOPEN_SOURCE_EXTENDED 1 | ||
45 | #include <errno.h> | ||
46 | /* The following two lines are a workaround against an autoconf-2.52 bug. */ | ||
47 | #include <stdio.h> | ||
48 | #include <stdlib.h> | ||
49 | ]) | ||
50 | else | ||
51 | dnl EOVERFLOW isn't defined by the system. Define EOVERFLOW ourselves, but | ||
52 | dnl don't define it as EINVAL, because snprintf() callers want to | ||
53 | dnl distinguish EINVAL and EOVERFLOW. | ||
54 | ac_cv_decl_EOVERFLOW=E2BIG | ||
55 | fi | ||
56 | fi | ||
57 | ]) | ||
58 | if test "$ac_cv_decl_EOVERFLOW" != yes; then | ||
59 | AC_DEFINE_UNQUOTED([EOVERFLOW], [$ac_cv_decl_EOVERFLOW], | ||
60 | [Define as good substitute value for EOVERFLOW.]) | ||
61 | EOVERFLOW="$ac_cv_decl_EOVERFLOW" | ||
62 | AC_SUBST(EOVERFLOW) | ||
63 | fi | ||
64 | ]) | ||
65 | |||
66 | dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. | ||
67 | dnl Remove this when we can assume autoconf >= 2.61. | ||
68 | m4_ifdef([AC_COMPUTE_INT], [], [ | ||
69 | AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) | ||
70 | ]) | ||
diff --git a/m4/error.m4 b/gl/m4/error.m4 index 7c7746e..7c7746e 100644 --- a/m4/error.m4 +++ b/gl/m4/error.m4 | |||
diff --git a/m4/exitfail.m4 b/gl/m4/exitfail.m4 index 5523676..b7a691e 100644 --- a/m4/exitfail.m4 +++ b/gl/m4/exitfail.m4 | |||
@@ -1,12 +1,11 @@ | |||
1 | # exitfail.m4 serial 5 | 1 | # exitfail.m4 serial 6 |
2 | dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | AC_DEFUN([gl_EXITFAIL], | 7 | AC_DEFUN([gl_EXITFAIL], |
8 | [ | 8 | [ |
9 | AC_LIBSOURCES([exitfail.c, exitfail.h]) | ||
10 | AC_LIBOBJ([exitfail]) | 9 | AC_LIBOBJ([exitfail]) |
11 | 10 | ||
12 | dnl No prerequisites of lib/exitfail.c. | 11 | dnl No prerequisites of lib/exitfail.c. |
diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4 new file mode 100644 index 0000000..143a9e5 --- /dev/null +++ b/gl/m4/extensions.m4 | |||
@@ -0,0 +1,58 @@ | |||
1 | # serial 4 -*- Autoconf -*- | ||
2 | # Enable extensions on systems that normally disable them. | ||
3 | |||
4 | # Copyright (C) 2003, 2006 Free Software Foundation, Inc. | ||
5 | # This file is free software; the Free Software Foundation | ||
6 | # gives unlimited permission to copy and/or distribute it, | ||
7 | # with or without modifications, as long as this notice is preserved. | ||
8 | |||
9 | # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS | ||
10 | # Autoconf. Perhaps we can remove this once we can assume Autoconf | ||
11 | # 2.61 or later everywhere, but since CVS Autoconf mutates rapidly | ||
12 | # enough in this area it's likely we'll need to redefine | ||
13 | # AC_USE_SYSTEM_EXTENSIONS for quite some time. | ||
14 | |||
15 | # AC_USE_SYSTEM_EXTENSIONS | ||
16 | # ------------------------ | ||
17 | # Enable extensions on systems that normally disable them, | ||
18 | # typically due to standards-conformance issues. | ||
19 | AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], | ||
20 | [ | ||
21 | AC_BEFORE([$0], [AC_COMPILE_IFELSE]) | ||
22 | AC_BEFORE([$0], [AC_RUN_IFELSE]) | ||
23 | |||
24 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
25 | AC_REQUIRE([AC_AIX]) | ||
26 | AC_REQUIRE([AC_MINIX]) | ||
27 | |||
28 | AH_VERBATIM([__EXTENSIONS__], | ||
29 | [/* Enable extensions on Solaris. */ | ||
30 | #ifndef __EXTENSIONS__ | ||
31 | # undef __EXTENSIONS__ | ||
32 | #endif | ||
33 | #ifndef _POSIX_PTHREAD_SEMANTICS | ||
34 | # undef _POSIX_PTHREAD_SEMANTICS | ||
35 | #endif | ||
36 | #ifndef _TANDEM_SOURCE | ||
37 | # undef _TANDEM_SOURCE | ||
38 | #endif]) | ||
39 | AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], | ||
40 | [ac_cv_safe_to_define___extensions__], | ||
41 | [AC_COMPILE_IFELSE( | ||
42 | [AC_LANG_PROGRAM([ | ||
43 | # define __EXTENSIONS__ 1 | ||
44 | AC_INCLUDES_DEFAULT])], | ||
45 | [ac_cv_safe_to_define___extensions__=yes], | ||
46 | [ac_cv_safe_to_define___extensions__=no])]) | ||
47 | test $ac_cv_safe_to_define___extensions__ = yes && | ||
48 | AC_DEFINE([__EXTENSIONS__]) | ||
49 | AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) | ||
50 | AC_DEFINE([_TANDEM_SOURCE]) | ||
51 | ]) | ||
52 | |||
53 | # gl_USE_SYSTEM_EXTENSIONS | ||
54 | # ------------------------ | ||
55 | # Enable extensions on systems that normally disable them, | ||
56 | # typically due to standards-conformance issues. | ||
57 | AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], | ||
58 | [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])]) | ||
diff --git a/m4/fcntl-safer.m4 b/gl/m4/fcntl-safer.m4 index be210f9..3475b0a 100644 --- a/m4/fcntl-safer.m4 +++ b/gl/m4/fcntl-safer.m4 | |||
@@ -1,12 +1,11 @@ | |||
1 | #serial 2 | 1 | #serial 5 |
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | AC_DEFUN([gl_FCNTL_SAFER], | 7 | AC_DEFUN([gl_FCNTL_SAFER], |
8 | [ | 8 | [ |
9 | AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h]) | ||
10 | AC_LIBOBJ([open-safer]) | 9 | AC_LIBOBJ([open-safer]) |
11 | AC_LIBOBJ([creat-safer]) | 10 | AC_LIBOBJ([creat-safer]) |
12 | ]) | 11 | ]) |
diff --git a/gl/m4/fstypename.m4 b/gl/m4/fstypename.m4 new file mode 100644 index 0000000..aa676f3 --- /dev/null +++ b/gl/m4/fstypename.m4 | |||
@@ -0,0 +1,22 @@ | |||
1 | #serial 6 | ||
2 | |||
3 | dnl From Jim Meyering. | ||
4 | dnl | ||
5 | dnl See if struct statfs has the f_fstypename member. | ||
6 | dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME. | ||
7 | dnl | ||
8 | |||
9 | # Copyright (C) 1998, 1999, 2001, 2004, 2006 Free Software Foundation, Inc. | ||
10 | # This file is free software; the Free Software Foundation | ||
11 | # gives unlimited permission to copy and/or distribute it, | ||
12 | # with or without modifications, as long as this notice is preserved. | ||
13 | |||
14 | AC_DEFUN([gl_FSTYPENAME], | ||
15 | [ | ||
16 | AC_CHECK_MEMBERS([struct statfs.f_fstypename],,, | ||
17 | [ | ||
18 | #include <sys/types.h> | ||
19 | #include <sys/param.h> | ||
20 | #include <sys/mount.h> | ||
21 | ]) | ||
22 | ]) | ||
diff --git a/m4/fsusage.m4 b/gl/m4/fsusage.m4 index dd10f79..08bf06c 100644 --- a/m4/fsusage.m4 +++ b/gl/m4/fsusage.m4 | |||
@@ -1,7 +1,7 @@ | |||
1 | #serial 16 | 1 | #serial 22 |
2 | # Obtaining file system usage information. | 2 | # Obtaining file system usage information. |
3 | 3 | ||
4 | # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005 Free Software | 4 | # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software |
5 | # Foundation, Inc. | 5 | # Foundation, Inc. |
6 | # | 6 | # |
7 | # This file is free software; the Free Software Foundation | 7 | # This file is free software; the Free Software Foundation |
@@ -12,8 +12,6 @@ | |||
12 | 12 | ||
13 | AC_DEFUN([gl_FSUSAGE], | 13 | AC_DEFUN([gl_FSUSAGE], |
14 | [ | 14 | [ |
15 | AC_LIBSOURCES([fsusage.c, fsusage.h]) | ||
16 | |||
17 | AC_CHECK_HEADERS_ONCE(sys/param.h) | 15 | AC_CHECK_HEADERS_ONCE(sys/param.h) |
18 | AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h) | 16 | AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h) |
19 | AC_CHECK_HEADERS(sys/mount.h, [], [], | 17 | AC_CHECK_HEADERS(sys/mount.h, [], [], |
@@ -37,7 +35,7 @@ AC_DEFUN([gl_FSUSAGE], | |||
37 | AC_DEFUN([gl_FILE_SYSTEM_USAGE], | 35 | AC_DEFUN([gl_FILE_SYSTEM_USAGE], |
38 | [ | 36 | [ |
39 | 37 | ||
40 | echo "checking how to get file system space usage..." | 38 | AC_MSG_NOTICE([checking how to get file system space usage]) |
41 | ac_fsusage_space=no | 39 | ac_fsusage_space=no |
42 | 40 | ||
43 | # Perform only the link test since it seems there are no variants of the | 41 | # Perform only the link test since it seems there are no variants of the |
@@ -50,10 +48,12 @@ if test $ac_fsusage_space = no; then | |||
50 | # SVR4 | 48 | # SVR4 |
51 | AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs, | 49 | AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs, |
52 | [AC_TRY_LINK([#include <sys/types.h> | 50 | [AC_TRY_LINK([#include <sys/types.h> |
53 | #ifdef __GLIBC__ | 51 | #if defined __GLIBC__ && !defined __BEOS__ |
54 | Do not use statvfs on systems with GNU libc, because that function stats | 52 | Do not use statvfs on systems with GNU libc, because that function stats |
55 | all preceding entries in /proc/mounts, and that makes df hang if even | 53 | all preceding entries in /proc/mounts, and that makes df hang if even |
56 | one of the corresponding file systems is hard-mounted, but not available. | 54 | one of the corresponding file systems is hard-mounted, but not available. |
55 | statvfs in GNU libc on BeOS operates differently: it only makes a system | ||
56 | call. | ||
57 | #endif | 57 | #endif |
58 | #include <sys/statvfs.h>], | 58 | #include <sys/statvfs.h>], |
59 | [struct statvfs fsd; statvfs (0, &fsd);], | 59 | [struct statvfs fsd; statvfs (0, &fsd);], |
@@ -74,11 +74,12 @@ if test $ac_fsusage_space = no; then | |||
74 | #include <sys/param.h> | 74 | #include <sys/param.h> |
75 | #include <sys/types.h> | 75 | #include <sys/types.h> |
76 | #include <sys/mount.h> | 76 | #include <sys/mount.h> |
77 | int | ||
77 | main () | 78 | main () |
78 | { | 79 | { |
79 | struct statfs fsd; | 80 | struct statfs fsd; |
80 | fsd.f_fsize = 0; | 81 | fsd.f_fsize = 0; |
81 | exit (statfs (".", &fsd, sizeof (struct statfs))); | 82 | return statfs (".", &fsd, sizeof (struct statfs)) != 0; |
82 | }], | 83 | }], |
83 | fu_cv_sys_stat_statfs3_osf1=yes, | 84 | fu_cv_sys_stat_statfs3_osf1=yes, |
84 | fu_cv_sys_stat_statfs3_osf1=no, | 85 | fu_cv_sys_stat_statfs3_osf1=no, |
@@ -106,11 +107,12 @@ member (AIX, 4.3BSD)]) | |||
106 | #ifdef HAVE_SYS_VFS_H | 107 | #ifdef HAVE_SYS_VFS_H |
107 | #include <sys/vfs.h> | 108 | #include <sys/vfs.h> |
108 | #endif | 109 | #endif |
110 | int | ||
109 | main () | 111 | main () |
110 | { | 112 | { |
111 | struct statfs fsd; | 113 | struct statfs fsd; |
112 | fsd.f_bsize = 0; | 114 | fsd.f_bsize = 0; |
113 | exit (statfs (".", &fsd)); | 115 | return statfs (".", &fsd) != 0; |
114 | }], | 116 | }], |
115 | fu_cv_sys_stat_statfs2_bsize=yes, | 117 | fu_cv_sys_stat_statfs2_bsize=yes, |
116 | fu_cv_sys_stat_statfs2_bsize=no, | 118 | fu_cv_sys_stat_statfs2_bsize=no, |
@@ -130,10 +132,11 @@ if test $ac_fsusage_space = no; then | |||
130 | AC_CACHE_VAL(fu_cv_sys_stat_statfs4, | 132 | AC_CACHE_VAL(fu_cv_sys_stat_statfs4, |
131 | [AC_TRY_RUN([#include <sys/types.h> | 133 | [AC_TRY_RUN([#include <sys/types.h> |
132 | #include <sys/statfs.h> | 134 | #include <sys/statfs.h> |
135 | int | ||
133 | main () | 136 | main () |
134 | { | 137 | { |
135 | struct statfs fsd; | 138 | struct statfs fsd; |
136 | exit (statfs (".", &fsd, sizeof fsd, 0)); | 139 | return statfs (".", &fsd, sizeof fsd, 0) != 0; |
137 | }], | 140 | }], |
138 | fu_cv_sys_stat_statfs4=yes, | 141 | fu_cv_sys_stat_statfs4=yes, |
139 | fu_cv_sys_stat_statfs4=no, | 142 | fu_cv_sys_stat_statfs4=no, |
@@ -158,11 +161,12 @@ member (4.4BSD and NetBSD)]) | |||
158 | #ifdef HAVE_SYS_MOUNT_H | 161 | #ifdef HAVE_SYS_MOUNT_H |
159 | #include <sys/mount.h> | 162 | #include <sys/mount.h> |
160 | #endif | 163 | #endif |
164 | int | ||
161 | main () | 165 | main () |
162 | { | 166 | { |
163 | struct statfs fsd; | 167 | struct statfs fsd; |
164 | fsd.f_fsize = 0; | 168 | fsd.f_fsize = 0; |
165 | exit (statfs (".", &fsd)); | 169 | return statfs (".", &fsd) != 0; |
166 | }], | 170 | }], |
167 | fu_cv_sys_stat_statfs2_fsize=yes, | 171 | fu_cv_sys_stat_statfs2_fsize=yes, |
168 | fu_cv_sys_stat_statfs2_fsize=no, | 172 | fu_cv_sys_stat_statfs2_fsize=no, |
@@ -190,12 +194,13 @@ if test $ac_fsusage_space = no; then | |||
190 | #ifdef HAVE_SYS_FS_TYPES_H | 194 | #ifdef HAVE_SYS_FS_TYPES_H |
191 | #include <sys/fs_types.h> | 195 | #include <sys/fs_types.h> |
192 | #endif | 196 | #endif |
197 | int | ||
193 | main () | 198 | main () |
194 | { | 199 | { |
195 | struct fs_data fsd; | 200 | struct fs_data fsd; |
196 | /* Ultrix's statfs returns 1 for success, | 201 | /* Ultrix's statfs returns 1 for success, |
197 | 0 for not mounted, -1 for failure. */ | 202 | 0 for not mounted, -1 for failure. */ |
198 | exit (statfs (".", &fsd) != 1); | 203 | return statfs (".", &fsd) != 1; |
199 | }], | 204 | }], |
200 | fu_cv_sys_stat_fs_data=yes, | 205 | fu_cv_sys_stat_fs_data=yes, |
201 | fu_cv_sys_stat_fs_data=no, | 206 | fu_cv_sys_stat_fs_data=no, |
@@ -237,7 +242,8 @@ choke -- this is a workaround for a Sun-specific problem | |||
237 | #endif | 242 | #endif |
238 | #include <sys/types.h> | 243 | #include <sys/types.h> |
239 | #include <sys/vfs.h>]], | 244 | #include <sys/vfs.h>]], |
240 | [[struct statfs t; long c = *(t.f_spare);]])], | 245 | [[struct statfs t; long c = *(t.f_spare); |
246 | if (c) return 0;]])], | ||
241 | [fu_cv_sys_truncating_statfs=yes], | 247 | [fu_cv_sys_truncating_statfs=yes], |
242 | [fu_cv_sys_truncating_statfs=no])]) | 248 | [fu_cv_sys_truncating_statfs=no])]) |
243 | if test $fu_cv_sys_truncating_statfs = yes; then | 249 | if test $fu_cv_sys_truncating_statfs = yes; then |
@@ -254,7 +260,6 @@ choke -- this is a workaround for a Sun-specific problem | |||
254 | # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE. | 260 | # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE. |
255 | AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], | 261 | AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], |
256 | [ | 262 | [ |
257 | AC_REQUIRE([gl_AC_TYPE_UINTMAX_T]) | 263 | AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h) |
258 | AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h) | ||
259 | gl_STATFS_TRUNCATES | 264 | gl_STATFS_TRUNCATES |
260 | ]) | 265 | ]) |
diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4 new file mode 100644 index 0000000..db285d9 --- /dev/null +++ b/gl/m4/getaddrinfo.m4 | |||
@@ -0,0 +1,88 @@ | |||
1 | # getaddrinfo.m4 serial 11 | ||
2 | dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_GETADDRINFO], | ||
8 | [ | ||
9 | AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo]) | ||
10 | |||
11 | AC_SEARCH_LIBS(getaddrinfo, [nsl socket]) | ||
12 | AC_CHECK_FUNCS(getaddrinfo,, [ | ||
13 | AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32, | ||
14 | gl_cv_w32_getaddrinfo, [ | ||
15 | gl_cv_w32_getaddrinfo=no | ||
16 | am_save_LIBS="$LIBS" | ||
17 | LIBS="$LIBS -lws2_32" | ||
18 | AC_TRY_LINK([ | ||
19 | #ifdef HAVE_WS2TCPIP_H | ||
20 | #include <ws2tcpip.h> | ||
21 | #endif | ||
22 | ], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes) | ||
23 | LIBS="$am_save_LIBS"]) | ||
24 | if test "$gl_cv_w32_getaddrinfo" = "yes"; then | ||
25 | LIBS="$LIBS -lws2_32" | ||
26 | else | ||
27 | AC_LIBOBJ(getaddrinfo) | ||
28 | fi | ||
29 | ]) | ||
30 | |||
31 | AC_REPLACE_FUNCS(gai_strerror) | ||
32 | gl_PREREQ_GETADDRINFO | ||
33 | ]) | ||
34 | |||
35 | # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c. | ||
36 | AC_DEFUN([gl_PREREQ_GETADDRINFO], [ | ||
37 | AC_SEARCH_LIBS(gethostbyname, [inet nsl]) | ||
38 | AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet]) | ||
39 | AC_CHECK_FUNCS(gethostbyname,, [ | ||
40 | AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32, | ||
41 | gl_cv_w32_gethostbyname, [ | ||
42 | gl_cv_w32_gethostbyname=no | ||
43 | am_save_LIBS="$LIBS" | ||
44 | LIBS="$LIBS -lws2_32" | ||
45 | AC_TRY_LINK([ | ||
46 | #ifdef HAVE_WINSOCK2_H | ||
47 | #include <winsock2.h> | ||
48 | #endif | ||
49 | ], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes) | ||
50 | LIBS="$am_save_LIBS"]) | ||
51 | if test "$gl_cv_w32_gethostbyname" = "yes"; then | ||
52 | LIBS="$LIBS -lws2_32" | ||
53 | fi | ||
54 | ]) | ||
55 | AC_REQUIRE([AC_C_RESTRICT]) | ||
56 | AC_REQUIRE([gl_SOCKET_FAMILIES]) | ||
57 | AC_REQUIRE([gl_HEADER_SYS_SOCKET]) | ||
58 | AC_REQUIRE([AC_C_INLINE]) | ||
59 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
60 | AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h) | ||
61 | AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ | ||
62 | /* sys/types.h is not needed according to POSIX, but the | ||
63 | sys/socket.h in i386-unknown-freebsd4.10 and | ||
64 | powerpc-apple-darwin5.5 required it. */ | ||
65 | #include <sys/types.h> | ||
66 | #ifdef HAVE_SYS_SOCKET_H | ||
67 | #include <sys/socket.h> | ||
68 | #endif | ||
69 | #ifdef HAVE_NETDB_H | ||
70 | #include <netdb.h> | ||
71 | #endif | ||
72 | #ifdef HAVE_WS2TCPIP_H | ||
73 | #include <ws2tcpip.h> | ||
74 | #endif | ||
75 | ]) | ||
76 | AC_CHECK_TYPES([struct addrinfo],,,[ | ||
77 | #include <sys/types.h> | ||
78 | #ifdef HAVE_SYS_SOCKET_H | ||
79 | #include <sys/socket.h> | ||
80 | #endif | ||
81 | #ifdef HAVE_NETDB_H | ||
82 | #include <netdb.h> | ||
83 | #endif | ||
84 | #ifdef HAVE_WS2TCPIP_H | ||
85 | #include <ws2tcpip.h> | ||
86 | #endif | ||
87 | ]) | ||
88 | ]) | ||
diff --git a/gl/m4/gethostname.m4 b/gl/m4/gethostname.m4 new file mode 100644 index 0000000..1e9749d --- /dev/null +++ b/gl/m4/gethostname.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # gethostname.m4 serial 2 | ||
2 | dnl Copyright (C) 2002 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_GETHOSTNAME], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(gethostname) | ||
10 | if test $ac_cv_func_gethostname = no; then | ||
11 | gl_PREREQ_GETHOSTNAME | ||
12 | fi | ||
13 | ]) | ||
14 | |||
15 | # Prerequisites of lib/gethostname.c. | ||
16 | AC_DEFUN([gl_PREREQ_GETHOSTNAME], [ | ||
17 | AC_CHECK_FUNCS(uname) | ||
18 | ]) | ||
diff --git a/gl/m4/getloadavg.m4 b/gl/m4/getloadavg.m4 new file mode 100644 index 0000000..8243729 --- /dev/null +++ b/gl/m4/getloadavg.m4 | |||
@@ -0,0 +1,155 @@ | |||
1 | # Check for getloadavg. | ||
2 | |||
3 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003, | ||
4 | # 2006 Free Software Foundation, Inc. | ||
5 | |||
6 | # This file is free software; the Free Software Foundation | ||
7 | # gives unlimited permission to copy and/or distribute it, | ||
8 | # with or without modifications, as long as this notice is preserved. | ||
9 | |||
10 | # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. | ||
11 | # New applications should use gl_GETLOADAVG instead. | ||
12 | |||
13 | # gl_GETLOADAVG(LIBOBJDIR) | ||
14 | # ------------------------ | ||
15 | AC_DEFUN([gl_GETLOADAVG], | ||
16 | [gl_have_func=no # yes means we've found a way to get the load average. | ||
17 | |||
18 | # Make sure getloadavg.c is where it belongs, at configure-time. | ||
19 | test -f "$srcdir/$1/getloadavg.c" || | ||
20 | AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing]) | ||
21 | |||
22 | gl_save_LIBS=$LIBS | ||
23 | |||
24 | # Check for getloadavg, but be sure not to touch the cache variable. | ||
25 | (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes | ||
26 | |||
27 | # On HPUX9, an unprivileged user can get load averages through this function. | ||
28 | AC_CHECK_FUNCS(pstat_getdynamic) | ||
29 | |||
30 | # Solaris has libkstat which does not require root. | ||
31 | AC_CHECK_LIB(kstat, kstat_open) | ||
32 | test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes | ||
33 | |||
34 | # Some systems with -lutil have (and need) -lkvm as well, some do not. | ||
35 | # On Solaris, -lkvm requires nlist from -lelf, so check that first | ||
36 | # to get the right answer into the cache. | ||
37 | # For kstat on solaris, we need libelf to force the definition of SVR4 below. | ||
38 | if test $gl_have_func = no; then | ||
39 | AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS") | ||
40 | fi | ||
41 | if test $gl_have_func = no; then | ||
42 | AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS") | ||
43 | # Check for the 4.4BSD definition of getloadavg. | ||
44 | AC_CHECK_LIB(util, getloadavg, | ||
45 | [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes]) | ||
46 | fi | ||
47 | |||
48 | if test $gl_have_func = no; then | ||
49 | # There is a commonly available library for RS/6000 AIX. | ||
50 | # Since it is not a standard part of AIX, it might be installed locally. | ||
51 | gl_getloadavg_LIBS=$LIBS | ||
52 | LIBS="-L/usr/local/lib $LIBS" | ||
53 | AC_CHECK_LIB(getloadavg, getloadavg, | ||
54 | [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS]) | ||
55 | fi | ||
56 | |||
57 | # Make sure it is really in the library, if we think we found it, | ||
58 | # otherwise set up the replacement function. | ||
59 | AC_CHECK_FUNCS(getloadavg, [], | ||
60 | [gl_PREREQ_GETLOADAVG]) | ||
61 | |||
62 | # Some definitions of getloadavg require that the program be installed setgid. | ||
63 | AC_CACHE_CHECK(whether getloadavg requires setgid, | ||
64 | gl_cv_func_getloadavg_setgid, | ||
65 | [AC_EGREP_CPP([Yowza Am I SETGID yet], | ||
66 | [#define CONFIGURING_GETLOADAVG | ||
67 | #include "$srcdir/$1/getloadavg.c" | ||
68 | #ifdef LDAV_PRIVILEGED | ||
69 | Yowza Am I SETGID yet | ||
70 | #endif | ||
71 | ], | ||
72 | gl_cv_func_getloadavg_setgid=yes, | ||
73 | gl_cv_func_getloadavg_setgid=no)]) | ||
74 | if test $gl_cv_func_getloadavg_setgid = yes; then | ||
75 | NEED_SETGID=true | ||
76 | AC_DEFINE(GETLOADAVG_PRIVILEGED, 1, | ||
77 | [Define to 1 if the `getloadavg' function needs to be run setuid | ||
78 | or setgid.]) | ||
79 | else | ||
80 | NEED_SETGID=false | ||
81 | fi | ||
82 | AC_SUBST(NEED_SETGID)dnl | ||
83 | |||
84 | if test $gl_cv_func_getloadavg_setgid = yes; then | ||
85 | AC_CACHE_CHECK(group of /dev/kmem, gl_cv_group_kmem, | ||
86 | [ # On Solaris, /dev/kmem is a symlink. Get info on the real file. | ||
87 | ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null` | ||
88 | # If we got an error (system does not support symlinks), try without -L. | ||
89 | test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem` | ||
90 | gl_cv_group_kmem=`echo $ac_ls_output \ | ||
91 | | sed -ne ['s/[ ][ ]*/ /g | ||
92 | s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/ | ||
93 | / /s/.* //;p']` | ||
94 | ]) | ||
95 | AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl | ||
96 | fi | ||
97 | if test "x$gl_save_LIBS" = x; then | ||
98 | GETLOADAVG_LIBS=$LIBS | ||
99 | else | ||
100 | GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"` | ||
101 | fi | ||
102 | LIBS=$gl_save_LIBS | ||
103 | |||
104 | AC_SUBST(GETLOADAVG_LIBS)dnl | ||
105 | ])# gl_GETLOADAVG | ||
106 | |||
107 | |||
108 | # gl_PREREQ_GETLOADAVG | ||
109 | # -------------------- | ||
110 | # Set up the AC_LIBOBJ replacement of `getloadavg'. | ||
111 | AC_DEFUN([gl_PREREQ_GETLOADAVG], | ||
112 | [AC_LIBOBJ(getloadavg) | ||
113 | AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.]) | ||
114 | # Figure out what our getloadavg.c needs. | ||
115 | gl_have_func=no | ||
116 | AC_CHECK_HEADER(sys/dg_sys_info.h, | ||
117 | [gl_have_func=yes | ||
118 | AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.]) | ||
119 | AC_CHECK_LIB(dgc, dg_sys_info)]) | ||
120 | |||
121 | # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it | ||
122 | # uses stabs), but it is still SVR4. We cannot check for <elf.h> because | ||
123 | # Irix 4.0.5F has the header but not the library. | ||
124 | if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then | ||
125 | gl_have_func=yes | ||
126 | AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.]) | ||
127 | fi | ||
128 | |||
129 | if test $gl_have_func = no; then | ||
130 | AC_CHECK_HEADER(inq_stats/cpustats.h, | ||
131 | [gl_have_func=yes | ||
132 | AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.]) | ||
133 | AC_DEFINE(UMAX4_3, 1, | ||
134 | [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h> | ||
135 | instead of <sys/cpustats.h>.])]) | ||
136 | fi | ||
137 | |||
138 | if test $gl_have_func = no; then | ||
139 | AC_CHECK_HEADER(sys/cpustats.h, | ||
140 | [gl_have_func=yes; AC_DEFINE(UMAX)]) | ||
141 | fi | ||
142 | |||
143 | if test $gl_have_func = no; then | ||
144 | AC_CHECK_HEADERS(mach/mach.h) | ||
145 | fi | ||
146 | |||
147 | AC_CHECK_HEADERS(nlist.h, | ||
148 | [AC_CHECK_MEMBERS([struct nlist.n_un.n_name], | ||
149 | [AC_DEFINE(NLIST_NAME_UNION, 1, | ||
150 | [Define to 1 if your `struct nlist' has an | ||
151 | `n_un' member. Obsolete, depend on | ||
152 | `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [], | ||
153 | [@%:@include <nlist.h>]) | ||
154 | ])dnl | ||
155 | ])# gl_PREREQ_GETLOADAVG | ||
diff --git a/m4/getopt.m4 b/gl/m4/getopt.m4 index 6b98782..c0a73b2 100644 --- a/m4/getopt.m4 +++ b/gl/m4/getopt.m4 | |||
@@ -1,11 +1,11 @@ | |||
1 | # getopt.m4 serial 11 | 1 | # getopt.m4 serial 13 |
2 | dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | # The getopt module assume you want GNU getopt, with getopt_long etc, | 7 | # The getopt module assume you want GNU getopt, with getopt_long etc, |
8 | # rather than vanilla POSIX getopt. This means your your code should | 8 | # rather than vanilla POSIX getopt. This means your code should |
9 | # always include <getopt.h> for the getopt prototypes. | 9 | # always include <getopt.h> for the getopt prototypes. |
10 | 10 | ||
11 | AC_DEFUN([gl_GETOPT_SUBSTITUTE], | 11 | AC_DEFUN([gl_GETOPT_SUBSTITUTE], |
@@ -77,4 +77,7 @@ AC_DEFUN([gl_GETOPT_IFELSE], | |||
77 | AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])]) | 77 | AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])]) |
78 | 78 | ||
79 | # Prerequisites of lib/getopt*. | 79 | # Prerequisites of lib/getopt*. |
80 | AC_DEFUN([gl_PREREQ_GETOPT], [:]) | 80 | AC_DEFUN([gl_PREREQ_GETOPT], |
81 | [ | ||
82 | AC_CHECK_DECLS_ONCE([getenv]) | ||
83 | ]) | ||
diff --git a/m4/gettext.m4 b/gl/m4/gettext.m4 index 624a807..91c345e 100644 --- a/m4/gettext.m4 +++ b/gl/m4/gettext.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # gettext.m4 serial 37 (gettext-0.14.4) | 1 | # gettext.m4 serial 59 (gettext-0.16.1) |
2 | dnl Copyright (C) 1995-2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -15,7 +15,7 @@ dnl They are *not* in the public domain. | |||
15 | 15 | ||
16 | dnl Authors: | 16 | dnl Authors: |
17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. | 17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. |
18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. | 18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006. |
19 | 19 | ||
20 | dnl Macro to add for using GNU gettext. | 20 | dnl Macro to add for using GNU gettext. |
21 | 21 | ||
@@ -63,8 +63,13 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
63 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , | 63 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , |
64 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT | 64 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT |
65 | ])])])]) | 65 | ])])])]) |
66 | define([gt_included_intl], ifelse([$1], [external], [no], [yes])) | 66 | define([gt_included_intl], |
67 | ifelse([$1], [external], | ||
68 | ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]), | ||
69 | [yes])) | ||
67 | define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) | 70 | define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) |
71 | gt_NEEDS_INIT | ||
72 | AM_GNU_GETTEXT_NEED([$2]) | ||
68 | 73 | ||
69 | AC_REQUIRE([AM_PO_SUBDIRS])dnl | 74 | AC_REQUIRE([AM_PO_SUBDIRS])dnl |
70 | ifelse(gt_included_intl, yes, [ | 75 | ifelse(gt_included_intl, yes, [ |
@@ -78,7 +83,7 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
78 | dnl Sometimes libintl requires libiconv, so first search for libiconv. | 83 | dnl Sometimes libintl requires libiconv, so first search for libiconv. |
79 | dnl Ideally we would do this search only after the | 84 | dnl Ideally we would do this search only after the |
80 | dnl if test "$USE_NLS" = "yes"; then | 85 | dnl if test "$USE_NLS" = "yes"; then |
81 | dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then | 86 | dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then |
82 | dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT | 87 | dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT |
83 | dnl the configure script would need to contain the same shell code | 88 | dnl the configure script would need to contain the same shell code |
84 | dnl again, outside any 'if'. There are two solutions: | 89 | dnl again, outside any 'if'. There are two solutions: |
@@ -94,7 +99,7 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
94 | gt_INTL_MACOSX | 99 | gt_INTL_MACOSX |
95 | 100 | ||
96 | dnl Set USE_NLS. | 101 | dnl Set USE_NLS. |
97 | AM_NLS | 102 | AC_REQUIRE([AM_NLS]) |
98 | 103 | ||
99 | ifelse(gt_included_intl, yes, [ | 104 | ifelse(gt_included_intl, yes, [ |
100 | BUILD_INCLUDED_LIBINTL=no | 105 | BUILD_INCLUDED_LIBINTL=no |
@@ -104,6 +109,15 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
104 | LTLIBINTL= | 109 | LTLIBINTL= |
105 | POSUB= | 110 | POSUB= |
106 | 111 | ||
112 | dnl Add a version number to the cache macros. | ||
113 | case " $gt_needs " in | ||
114 | *" need-formatstring-macros "*) gt_api_version=3 ;; | ||
115 | *" need-ngettext "*) gt_api_version=2 ;; | ||
116 | *) gt_api_version=1 ;; | ||
117 | esac | ||
118 | gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" | ||
119 | gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" | ||
120 | |||
107 | dnl If we use NLS figure out what method | 121 | dnl If we use NLS figure out what method |
108 | if test "$USE_NLS" = "yes"; then | 122 | if test "$USE_NLS" = "yes"; then |
109 | gt_use_preinstalled_gnugettext=no | 123 | gt_use_preinstalled_gnugettext=no |
@@ -122,28 +136,35 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
122 | dnl to use. If GNU gettext is available we use this. Else we have | 136 | dnl to use. If GNU gettext is available we use this. Else we have |
123 | dnl to fall back to GNU NLS library. | 137 | dnl to fall back to GNU NLS library. |
124 | 138 | ||
125 | dnl Add a version number to the cache macros. | 139 | if test $gt_api_version -ge 3; then |
126 | define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1))) | 140 | gt_revision_test_code=' |
127 | define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc]) | 141 | #ifndef __GNU_GETTEXT_SUPPORTED_REVISION |
128 | define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl]) | ||
129 | |||
130 | AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc, | ||
131 | [AC_TRY_LINK([#include <libintl.h> | ||
132 | ]ifelse([$2], [need-formatstring-macros], | ||
133 | [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION | ||
134 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) | 142 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) |
135 | #endif | 143 | #endif |
136 | changequote(,)dnl | 144 | changequote(,)dnl |
137 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; | 145 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; |
138 | changequote([,])dnl | 146 | changequote([,])dnl |
139 | ], [])[extern int _nl_msg_cat_cntr; | 147 | ' |
148 | else | ||
149 | gt_revision_test_code= | ||
150 | fi | ||
151 | if test $gt_api_version -ge 2; then | ||
152 | gt_expression_test_code=' + * ngettext ("", "", 0)' | ||
153 | else | ||
154 | gt_expression_test_code= | ||
155 | fi | ||
156 | |||
157 | AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], | ||
158 | [AC_TRY_LINK([#include <libintl.h> | ||
159 | $gt_revision_test_code | ||
160 | extern int _nl_msg_cat_cntr; | ||
140 | extern int *_nl_domain_bindings;], | 161 | extern int *_nl_domain_bindings;], |
141 | [bindtextdomain ("", ""); | 162 | [bindtextdomain ("", ""); |
142 | return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings], | 163 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings], |
143 | gt_cv_func_gnugettext_libc=yes, | 164 | [eval "$gt_func_gnugettext_libc=yes"], |
144 | gt_cv_func_gnugettext_libc=no)]) | 165 | [eval "$gt_func_gnugettext_libc=no"])]) |
145 | 166 | ||
146 | if test "$gt_cv_func_gnugettext_libc" != "yes"; then | 167 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then |
147 | dnl Sometimes libintl requires libiconv, so first search for libiconv. | 168 | dnl Sometimes libintl requires libiconv, so first search for libiconv. |
148 | ifelse(gt_included_intl, yes, , [ | 169 | ifelse(gt_included_intl, yes, , [ |
149 | AM_ICONV_LINK | 170 | AM_ICONV_LINK |
@@ -154,52 +175,40 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
154 | dnl even if libiconv doesn't exist. | 175 | dnl even if libiconv doesn't exist. |
155 | AC_LIB_LINKFLAGS_BODY([intl]) | 176 | AC_LIB_LINKFLAGS_BODY([intl]) |
156 | AC_CACHE_CHECK([for GNU gettext in libintl], | 177 | AC_CACHE_CHECK([for GNU gettext in libintl], |
157 | gt_cv_func_gnugettext_libintl, | 178 | [$gt_func_gnugettext_libintl], |
158 | [gt_save_CPPFLAGS="$CPPFLAGS" | 179 | [gt_save_CPPFLAGS="$CPPFLAGS" |
159 | CPPFLAGS="$CPPFLAGS $INCINTL" | 180 | CPPFLAGS="$CPPFLAGS $INCINTL" |
160 | gt_save_LIBS="$LIBS" | 181 | gt_save_LIBS="$LIBS" |
161 | LIBS="$LIBS $LIBINTL" | 182 | LIBS="$LIBS $LIBINTL" |
162 | dnl Now see whether libintl exists and does not depend on libiconv. | 183 | dnl Now see whether libintl exists and does not depend on libiconv. |
163 | AC_TRY_LINK([#include <libintl.h> | 184 | AC_TRY_LINK([#include <libintl.h> |
164 | ]ifelse([$2], [need-formatstring-macros], | 185 | $gt_revision_test_code |
165 | [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION | 186 | extern int _nl_msg_cat_cntr; |
166 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) | ||
167 | #endif | ||
168 | changequote(,)dnl | ||
169 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; | ||
170 | changequote([,])dnl | ||
171 | ], [])[extern int _nl_msg_cat_cntr; | ||
172 | extern | 187 | extern |
173 | #ifdef __cplusplus | 188 | #ifdef __cplusplus |
174 | "C" | 189 | "C" |
175 | #endif | 190 | #endif |
176 | const char *_nl_expand_alias (const char *);], | 191 | const char *_nl_expand_alias (const char *);], |
177 | [bindtextdomain ("", ""); | 192 | [bindtextdomain ("", ""); |
178 | return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")], | 193 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], |
179 | gt_cv_func_gnugettext_libintl=yes, | 194 | [eval "$gt_func_gnugettext_libintl=yes"], |
180 | gt_cv_func_gnugettext_libintl=no) | 195 | [eval "$gt_func_gnugettext_libintl=no"]) |
181 | dnl Now see whether libintl exists and depends on libiconv. | 196 | dnl Now see whether libintl exists and depends on libiconv. |
182 | if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then | 197 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then |
183 | LIBS="$LIBS $LIBICONV" | 198 | LIBS="$LIBS $LIBICONV" |
184 | AC_TRY_LINK([#include <libintl.h> | 199 | AC_TRY_LINK([#include <libintl.h> |
185 | ]ifelse([$2], [need-formatstring-macros], | 200 | $gt_revision_test_code |
186 | [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION | 201 | extern int _nl_msg_cat_cntr; |
187 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) | ||
188 | #endif | ||
189 | changequote(,)dnl | ||
190 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; | ||
191 | changequote([,])dnl | ||
192 | ], [])[extern int _nl_msg_cat_cntr; | ||
193 | extern | 202 | extern |
194 | #ifdef __cplusplus | 203 | #ifdef __cplusplus |
195 | "C" | 204 | "C" |
196 | #endif | 205 | #endif |
197 | const char *_nl_expand_alias (const char *);], | 206 | const char *_nl_expand_alias (const char *);], |
198 | [bindtextdomain ("", ""); | 207 | [bindtextdomain ("", ""); |
199 | return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")], | 208 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], |
200 | [LIBINTL="$LIBINTL $LIBICONV" | 209 | [LIBINTL="$LIBINTL $LIBICONV" |
201 | LTLIBINTL="$LTLIBINTL $LTLIBICONV" | 210 | LTLIBINTL="$LTLIBINTL $LTLIBICONV" |
202 | gt_cv_func_gnugettext_libintl=yes | 211 | eval "$gt_func_gnugettext_libintl=yes" |
203 | ]) | 212 | ]) |
204 | fi | 213 | fi |
205 | CPPFLAGS="$gt_save_CPPFLAGS" | 214 | CPPFLAGS="$gt_save_CPPFLAGS" |
@@ -210,8 +219,8 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
210 | dnl use it. But if this macro is used in GNU gettext, and GNU | 219 | dnl use it. But if this macro is used in GNU gettext, and GNU |
211 | dnl gettext is already preinstalled in libintl, we update this | 220 | dnl gettext is already preinstalled in libintl, we update this |
212 | dnl libintl. (Cf. the install rule in intl/Makefile.in.) | 221 | dnl libintl. (Cf. the install rule in intl/Makefile.in.) |
213 | if test "$gt_cv_func_gnugettext_libc" = "yes" \ | 222 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ |
214 | || { test "$gt_cv_func_gnugettext_libintl" = "yes" \ | 223 | || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ |
215 | && test "$PACKAGE" != gettext-runtime \ | 224 | && test "$PACKAGE" != gettext-runtime \ |
216 | && test "$PACKAGE" != gettext-tools; }; then | 225 | && test "$PACKAGE" != gettext-tools; }; then |
217 | gt_use_preinstalled_gnugettext=yes | 226 | gt_use_preinstalled_gnugettext=yes |
@@ -234,8 +243,8 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
234 | dnl Mark actions used to generate GNU NLS library. | 243 | dnl Mark actions used to generate GNU NLS library. |
235 | BUILD_INCLUDED_LIBINTL=yes | 244 | BUILD_INCLUDED_LIBINTL=yes |
236 | USE_INCLUDED_LIBINTL=yes | 245 | USE_INCLUDED_LIBINTL=yes |
237 | LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV" | 246 | LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" |
238 | LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV" | 247 | LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" |
239 | LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` | 248 | LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` |
240 | fi | 249 | fi |
241 | 250 | ||
@@ -271,7 +280,7 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
271 | if test "$USE_NLS" = "yes"; then | 280 | if test "$USE_NLS" = "yes"; then |
272 | AC_MSG_CHECKING([where the gettext function comes from]) | 281 | AC_MSG_CHECKING([where the gettext function comes from]) |
273 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then | 282 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then |
274 | if test "$gt_cv_func_gnugettext_libintl" = "yes"; then | 283 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then |
275 | gt_source="external libintl" | 284 | gt_source="external libintl" |
276 | else | 285 | else |
277 | gt_source="libc" | 286 | gt_source="libc" |
@@ -285,7 +294,7 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
285 | if test "$USE_NLS" = "yes"; then | 294 | if test "$USE_NLS" = "yes"; then |
286 | 295 | ||
287 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then | 296 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then |
288 | if test "$gt_cv_func_gnugettext_libintl" = "yes"; then | 297 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then |
289 | AC_MSG_CHECKING([how to link with libintl]) | 298 | AC_MSG_CHECKING([how to link with libintl]) |
290 | AC_MSG_RESULT([$LIBINTL]) | 299 | AC_MSG_RESULT([$LIBINTL]) |
291 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) | 300 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) |
@@ -353,134 +362,6 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], | |||
353 | ]) | 362 | ]) |
354 | 363 | ||
355 | 364 | ||
356 | dnl Checks for all prerequisites of the intl subdirectory, | ||
357 | dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, | ||
358 | dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. | ||
359 | AC_DEFUN([AM_INTL_SUBDIR], | ||
360 | [ | ||
361 | AC_REQUIRE([AC_PROG_INSTALL])dnl | ||
362 | AC_REQUIRE([AM_MKINSTALLDIRS])dnl | ||
363 | AC_REQUIRE([AC_PROG_CC])dnl | ||
364 | AC_REQUIRE([AC_CANONICAL_HOST])dnl | ||
365 | AC_REQUIRE([gt_GLIBC2])dnl | ||
366 | AC_REQUIRE([AC_PROG_RANLIB])dnl | ||
367 | AC_REQUIRE([AC_ISC_POSIX])dnl | ||
368 | AC_REQUIRE([AC_HEADER_STDC])dnl | ||
369 | AC_REQUIRE([AC_C_CONST])dnl | ||
370 | AC_REQUIRE([bh_C_SIGNED])dnl | ||
371 | AC_REQUIRE([AC_C_INLINE])dnl | ||
372 | AC_REQUIRE([AC_TYPE_OFF_T])dnl | ||
373 | AC_REQUIRE([AC_TYPE_SIZE_T])dnl | ||
374 | AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl | ||
375 | AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl | ||
376 | AC_REQUIRE([gt_TYPE_WCHAR_T])dnl | ||
377 | AC_REQUIRE([gt_TYPE_WINT_T])dnl | ||
378 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) | ||
379 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) | ||
380 | AC_REQUIRE([gt_TYPE_INTMAX_T]) | ||
381 | AC_REQUIRE([gt_PRINTF_POSIX]) | ||
382 | AC_REQUIRE([AC_FUNC_ALLOCA])dnl | ||
383 | AC_REQUIRE([AC_FUNC_MMAP])dnl | ||
384 | AC_REQUIRE([gl_GLIBC21])dnl | ||
385 | AC_REQUIRE([gt_INTDIV0])dnl | ||
386 | AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl | ||
387 | AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl | ||
388 | AC_REQUIRE([gt_INTTYPES_PRI])dnl | ||
389 | AC_REQUIRE([gl_XSIZE])dnl | ||
390 | AC_REQUIRE([gt_INTL_MACOSX])dnl | ||
391 | |||
392 | AC_CHECK_TYPE([ptrdiff_t], , | ||
393 | [AC_DEFINE([ptrdiff_t], [long], | ||
394 | [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) | ||
395 | ]) | ||
396 | AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \ | ||
397 | stdlib.h string.h unistd.h sys/param.h]) | ||
398 | AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \ | ||
399 | mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \ | ||
400 | strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \ | ||
401 | __fsetlocking]) | ||
402 | |||
403 | dnl Use the _snprintf function only if it is declared (because on NetBSD it | ||
404 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). | ||
405 | gt_CHECK_DECL(_snprintf, [#include <stdio.h>]) | ||
406 | gt_CHECK_DECL(_snwprintf, [#include <stdio.h>]) | ||
407 | |||
408 | dnl Use the *_unlocked functions only if they are declared. | ||
409 | dnl (because some of them were defined without being declared in Solaris | ||
410 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built | ||
411 | dnl on Solaris 2.5.1 to run on Solaris 2.6). | ||
412 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. | ||
413 | gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>]) | ||
414 | gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>]) | ||
415 | gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>]) | ||
416 | |||
417 | case $gt_cv_func_printf_posix in | ||
418 | *yes) HAVE_POSIX_PRINTF=1 ;; | ||
419 | *) HAVE_POSIX_PRINTF=0 ;; | ||
420 | esac | ||
421 | AC_SUBST([HAVE_POSIX_PRINTF]) | ||
422 | if test "$ac_cv_func_asprintf" = yes; then | ||
423 | HAVE_ASPRINTF=1 | ||
424 | else | ||
425 | HAVE_ASPRINTF=0 | ||
426 | fi | ||
427 | AC_SUBST([HAVE_ASPRINTF]) | ||
428 | if test "$ac_cv_func_snprintf" = yes; then | ||
429 | HAVE_SNPRINTF=1 | ||
430 | else | ||
431 | HAVE_SNPRINTF=0 | ||
432 | fi | ||
433 | AC_SUBST([HAVE_SNPRINTF]) | ||
434 | if test "$ac_cv_func_wprintf" = yes; then | ||
435 | HAVE_WPRINTF=1 | ||
436 | else | ||
437 | HAVE_WPRINTF=0 | ||
438 | fi | ||
439 | AC_SUBST([HAVE_WPRINTF]) | ||
440 | |||
441 | AM_ICONV | ||
442 | AM_LANGINFO_CODESET | ||
443 | if test $ac_cv_header_locale_h = yes; then | ||
444 | gt_LC_MESSAGES | ||
445 | fi | ||
446 | |||
447 | if test -n "$INTL_MACOSX_LIBS"; then | ||
448 | CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" | ||
449 | fi | ||
450 | |||
451 | dnl intl/plural.c is generated from intl/plural.y. It requires bison, | ||
452 | dnl because plural.y uses bison specific features. It requires at least | ||
453 | dnl bison-1.26 because earlier versions generate a plural.c that doesn't | ||
454 | dnl compile. | ||
455 | dnl bison is only needed for the maintainer (who touches plural.y). But in | ||
456 | dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put | ||
457 | dnl the rule in general Makefile. Now, some people carelessly touch the | ||
458 | dnl files or have a broken "make" program, hence the plural.c rule will | ||
459 | dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not | ||
460 | dnl present or too old. | ||
461 | AC_CHECK_PROGS([INTLBISON], [bison]) | ||
462 | if test -z "$INTLBISON"; then | ||
463 | ac_verc_fail=yes | ||
464 | else | ||
465 | dnl Found it, now check the version. | ||
466 | AC_MSG_CHECKING([version of bison]) | ||
467 | changequote(<<,>>)dnl | ||
468 | ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` | ||
469 | case $ac_prog_version in | ||
470 | '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; | ||
471 | 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) | ||
472 | changequote([,])dnl | ||
473 | ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; | ||
474 | *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; | ||
475 | esac | ||
476 | AC_MSG_RESULT([$ac_prog_version]) | ||
477 | fi | ||
478 | if test $ac_verc_fail = yes; then | ||
479 | INTLBISON=: | ||
480 | fi | ||
481 | ]) | ||
482 | |||
483 | |||
484 | dnl Checks for special options needed on MacOS X. | 365 | dnl Checks for special options needed on MacOS X. |
485 | dnl Defines INTL_MACOSX_LIBS. | 366 | dnl Defines INTL_MACOSX_LIBS. |
486 | AC_DEFUN([gt_INTL_MACOSX], | 367 | AC_DEFUN([gt_INTL_MACOSX], |
@@ -488,15 +369,12 @@ AC_DEFUN([gt_INTL_MACOSX], | |||
488 | dnl Check for API introduced in MacOS X 10.2. | 369 | dnl Check for API introduced in MacOS X 10.2. |
489 | AC_CACHE_CHECK([for CFPreferencesCopyAppValue], | 370 | AC_CACHE_CHECK([for CFPreferencesCopyAppValue], |
490 | gt_cv_func_CFPreferencesCopyAppValue, | 371 | gt_cv_func_CFPreferencesCopyAppValue, |
491 | [gt_save_CPPFLAGS="$CPPFLAGS" | 372 | [gt_save_LIBS="$LIBS" |
492 | CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" | 373 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" |
493 | gt_save_LIBS="$LIBS" | 374 | AC_TRY_LINK([#include <CoreFoundation/CFPreferences.h>], |
494 | LIBS="$LIBS -framework CoreFoundation" | ||
495 | AC_TRY_LINK([#include <CFPreferences.h>], | ||
496 | [CFPreferencesCopyAppValue(NULL, NULL)], | 375 | [CFPreferencesCopyAppValue(NULL, NULL)], |
497 | [gt_cv_func_CFPreferencesCopyAppValue=yes], | 376 | [gt_cv_func_CFPreferencesCopyAppValue=yes], |
498 | [gt_cv_func_CFPreferencesCopyAppValue=no]) | 377 | [gt_cv_func_CFPreferencesCopyAppValue=no]) |
499 | CPPFLAGS="$gt_save_CPPFLAGS" | ||
500 | LIBS="$gt_save_LIBS"]) | 378 | LIBS="$gt_save_LIBS"]) |
501 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then | 379 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then |
502 | AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1, | 380 | AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1, |
@@ -504,14 +382,11 @@ AC_DEFUN([gt_INTL_MACOSX], | |||
504 | fi | 382 | fi |
505 | dnl Check for API introduced in MacOS X 10.3. | 383 | dnl Check for API introduced in MacOS X 10.3. |
506 | AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent, | 384 | AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent, |
507 | [gt_save_CPPFLAGS="$CPPFLAGS" | 385 | [gt_save_LIBS="$LIBS" |
508 | CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" | 386 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" |
509 | gt_save_LIBS="$LIBS" | 387 | AC_TRY_LINK([#include <CoreFoundation/CFLocale.h>], [CFLocaleCopyCurrent();], |
510 | LIBS="$LIBS -framework CoreFoundation" | ||
511 | AC_TRY_LINK([#include <CFLocale.h>], [CFLocaleCopyCurrent();], | ||
512 | [gt_cv_func_CFLocaleCopyCurrent=yes], | 388 | [gt_cv_func_CFLocaleCopyCurrent=yes], |
513 | [gt_cv_func_CFLocaleCopyCurrent=no]) | 389 | [gt_cv_func_CFLocaleCopyCurrent=no]) |
514 | CPPFLAGS="$gt_save_CPPFLAGS" | ||
515 | LIBS="$gt_save_LIBS"]) | 390 | LIBS="$gt_save_LIBS"]) |
516 | if test $gt_cv_func_CFLocaleCopyCurrent = yes; then | 391 | if test $gt_cv_func_CFLocaleCopyCurrent = yes; then |
517 | AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1, | 392 | AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1, |
@@ -525,23 +400,18 @@ AC_DEFUN([gt_INTL_MACOSX], | |||
525 | ]) | 400 | ]) |
526 | 401 | ||
527 | 402 | ||
528 | dnl gt_CHECK_DECL(FUNC, INCLUDES) | 403 | dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. |
529 | dnl Check whether a function is declared. | 404 | m4_define([gt_NEEDS_INIT], |
530 | AC_DEFUN([gt_CHECK_DECL], | ||
531 | [ | 405 | [ |
532 | AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, | 406 | m4_divert_text([DEFAULTS], [gt_needs=]) |
533 | [AC_TRY_COMPILE([$2], [ | 407 | m4_define([gt_NEEDS_INIT], []) |
534 | #ifndef $1 | 408 | ]) |
535 | char *p = (char *) $1; | 409 | |
536 | #endif | 410 | |
537 | ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) | 411 | dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) |
538 | if test $ac_cv_have_decl_$1 = yes; then | 412 | AC_DEFUN([AM_GNU_GETTEXT_NEED], |
539 | gt_value=1 | 413 | [ |
540 | else | 414 | m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) |
541 | gt_value=0 | ||
542 | fi | ||
543 | AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], | ||
544 | [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) | ||
545 | ]) | 415 | ]) |
546 | 416 | ||
547 | 417 | ||
diff --git a/gl/m4/glibc2.m4 b/gl/m4/glibc2.m4 new file mode 100644 index 0000000..e8f5bfe --- /dev/null +++ b/gl/m4/glibc2.m4 | |||
@@ -0,0 +1,30 @@ | |||
1 | # glibc2.m4 serial 1 | ||
2 | dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | # Test for the GNU C Library, version 2.0 or newer. | ||
8 | # From Bruno Haible. | ||
9 | |||
10 | AC_DEFUN([gt_GLIBC2], | ||
11 | [ | ||
12 | AC_CACHE_CHECK(whether we are using the GNU C Library 2 or newer, | ||
13 | ac_cv_gnu_library_2, | ||
14 | [AC_EGREP_CPP([Lucky GNU user], | ||
15 | [ | ||
16 | #include <features.h> | ||
17 | #ifdef __GNU_LIBRARY__ | ||
18 | #if (__GLIBC__ >= 2) | ||
19 | Lucky GNU user | ||
20 | #endif | ||
21 | #endif | ||
22 | ], | ||
23 | ac_cv_gnu_library_2=yes, | ||
24 | ac_cv_gnu_library_2=no) | ||
25 | ] | ||
26 | ) | ||
27 | AC_SUBST(GLIBC2) | ||
28 | GLIBC2="$ac_cv_gnu_library_2" | ||
29 | ] | ||
30 | ) | ||
diff --git a/m4/glibc21.m4 b/gl/m4/glibc21.m4 index d95fd98..d95fd98 100644 --- a/m4/glibc21.m4 +++ b/gl/m4/glibc21.m4 | |||
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 new file mode 100644 index 0000000..e78c860 --- /dev/null +++ b/gl/m4/gnulib-cache.m4 | |||
@@ -0,0 +1,30 @@ | |||
1 | # Copyright (C) 2004-2007 Free Software Foundation, Inc. | ||
2 | # | ||
3 | # This file is free software, distributed under the terms of the GNU | ||
4 | # General Public License. As a special exception to the GNU General | ||
5 | # Public License, this file may be distributed as part of a program | ||
6 | # that contains a configuration script generated by Autoconf, under | ||
7 | # the same distribution terms as the rest of that program. | ||
8 | # | ||
9 | # Generated by gnulib-tool. | ||
10 | # | ||
11 | # This file represents the specification of how gnulib-tool is used. | ||
12 | # It acts as a cache: It is written and read by gnulib-tool. | ||
13 | # In projects using CVS, this file is meant to be stored in CVS, | ||
14 | # like the configure.ac and various Makefile.am files. | ||
15 | |||
16 | |||
17 | # Specification in the form of a command-line invocation: | ||
18 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=. --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf | ||
19 | |||
20 | # Specification in the form of a few gnulib-tool.m4 macro invocations: | ||
21 | gl_LOCAL_DIR([]) | ||
22 | gl_MODULES([dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf]) | ||
23 | gl_AVOID([]) | ||
24 | gl_SOURCE_BASE([gl]) | ||
25 | gl_M4_BASE([gl/m4]) | ||
26 | gl_DOC_BASE([doc]) | ||
27 | gl_TESTS_BASE([tests]) | ||
28 | gl_LIB([libgnu]) | ||
29 | gl_MAKEFILE_NAME([]) | ||
30 | gl_MACRO_PREFIX([gl]) | ||
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4 new file mode 100644 index 0000000..5398010 --- /dev/null +++ b/gl/m4/gnulib-common.m4 | |||
@@ -0,0 +1,22 @@ | |||
1 | # gnulib-common.m4 serial 2 | ||
2 | dnl Copyright (C) 2007 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | # gl_MODULE_INDICATOR([modulename]) | ||
8 | # defines a C macro indicating the presence of the given module. | ||
9 | AC_DEFUN([gl_MODULE_INDICATOR], | ||
10 | [ | ||
11 | AC_DEFINE([GNULIB_]translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1], | ||
12 | [Define to 1 when using the gnulib module ]$1[.]) | ||
13 | ]) | ||
14 | |||
15 | # AC_PROG_MKDIR_P | ||
16 | # is a backport of autoconf-2.60's AC_PROG_MKDIR_P. | ||
17 | # Remove this macro when we can assume autoconf >= 2.60. | ||
18 | m4_ifdef([AC_PROG_MKDIR_P], [], [ | ||
19 | AC_DEFUN([AC_PROG_MKDIR_P], | ||
20 | [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake | ||
21 | MKDIR_P='$(mkdir_p)' | ||
22 | AC_SUBST([MKDIR_P])])]) | ||
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 new file mode 100644 index 0000000..ed4da7d --- /dev/null +++ b/gl/m4/gnulib-comp.m4 | |||
@@ -0,0 +1,326 @@ | |||
1 | # DO NOT EDIT! GENERATED AUTOMATICALLY! | ||
2 | # Copyright (C) 2004-2007 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # This file is free software, distributed under the terms of the GNU | ||
5 | # General Public License. As a special exception to the GNU General | ||
6 | # Public License, this file may be distributed as part of a program | ||
7 | # that contains a configuration script generated by Autoconf, under | ||
8 | # the same distribution terms as the rest of that program. | ||
9 | # | ||
10 | # Generated by gnulib-tool. | ||
11 | # | ||
12 | # This file represents the compiled summary of the specification in | ||
13 | # gnulib-cache.m4. It lists the computed macro invocations that need | ||
14 | # to be invoked from configure.ac. | ||
15 | # In projects using CVS, this file can be treated like other built files. | ||
16 | |||
17 | |||
18 | # This macro should be invoked from ./configure.in, in the section | ||
19 | # "Checks for programs", right after AC_PROG_CC, and certainly before | ||
20 | # any checks for libraries, header files, types and library functions. | ||
21 | AC_DEFUN([gl_EARLY], | ||
22 | [ | ||
23 | m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace | ||
24 | m4_pattern_allow([^gl_ES$])dnl a valid locale name | ||
25 | m4_pattern_allow([^gl_LIBOBJS$])dnl a variable | ||
26 | m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable | ||
27 | AC_REQUIRE([AC_PROG_RANLIB]) | ||
28 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
29 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
30 | AC_REQUIRE([gl_LOCK_EARLY]) | ||
31 | ]) | ||
32 | |||
33 | # This macro should be invoked from ./configure.in, in the section | ||
34 | # "Check for header files, types and library functions". | ||
35 | AC_DEFUN([gl_INIT], | ||
36 | [ | ||
37 | m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) | ||
38 | m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) | ||
39 | m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) | ||
40 | AM_CONDITIONAL([GL_COND_LIBTOOL], [false]) | ||
41 | gl_cond_libtool=false | ||
42 | gl_libdeps= | ||
43 | gl_ltlibdeps= | ||
44 | gl_source_base='gl' | ||
45 | gl_FUNC_ALLOCA | ||
46 | gl_HEADER_ARPA_INET | ||
47 | gl_C_STRTOD | ||
48 | gl_CLOEXEC | ||
49 | gl_DIRNAME | ||
50 | gl_DOUBLE_SLASH_ROOT | ||
51 | gl_ERROR | ||
52 | gl_EXITFAIL | ||
53 | dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac. | ||
54 | gl_FCNTL_SAFER | ||
55 | gl_MODULE_INDICATOR([fcntl-safer]) | ||
56 | gl_FSUSAGE | ||
57 | gl_GETADDRINFO | ||
58 | gl_FUNC_GETHOSTNAME | ||
59 | gl_GETLOADAVG([$gl_source_base]) | ||
60 | gl_GETOPT | ||
61 | dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. | ||
62 | AM_GNU_GETTEXT_VERSION([0.15]) | ||
63 | gl_INET_NTOP | ||
64 | gl_INLINE | ||
65 | AC_FUNC_MALLOC | ||
66 | gl_MBCHAR | ||
67 | gl_MBITER | ||
68 | gl_FUNC_MEMCHR | ||
69 | gl_MINMAX | ||
70 | gl_MOUNTLIST | ||
71 | gl_HEADER_NETINET_IN | ||
72 | gl_REGEX | ||
73 | gl_SAFE_READ | ||
74 | gl_SAFE_WRITE | ||
75 | gl_SIZE_MAX | ||
76 | gl_FUNC_SNPRINTF | ||
77 | gl_TYPE_SOCKLEN_T | ||
78 | gt_TYPE_SSIZE_T | ||
79 | AM_STDBOOL_H | ||
80 | gl_STDINT_H | ||
81 | gl_STRCASE | ||
82 | gl_FUNC_STRDUP | ||
83 | gl_FUNC_STRNDUP | ||
84 | gl_FUNC_STRNLEN | ||
85 | gl_HEADER_SYS_SOCKET | ||
86 | AC_PROG_MKDIR_P | ||
87 | gl_HEADER_UNISTD | ||
88 | gl_UNISTD_SAFER | ||
89 | gl_FUNC_VASNPRINTF | ||
90 | gl_FUNC_VASPRINTF | ||
91 | gl_FUNC_VSNPRINTF | ||
92 | gl_WCHAR_H | ||
93 | gl_WCTYPE_H | ||
94 | gl_FUNC_WCWIDTH | ||
95 | gl_XALLOC | ||
96 | gl_XSIZE | ||
97 | gl_XSTRNDUP | ||
98 | LIBGNU_LIBDEPS="$gl_libdeps" | ||
99 | AC_SUBST([LIBGNU_LIBDEPS]) | ||
100 | LIBGNU_LTLIBDEPS="$gl_ltlibdeps" | ||
101 | AC_SUBST([LIBGNU_LTLIBDEPS]) | ||
102 | m4_popdef([AC_LIBSOURCES]) | ||
103 | m4_popdef([AC_REPLACE_FUNCS]) | ||
104 | m4_popdef([AC_LIBOBJ]) | ||
105 | AC_CONFIG_COMMANDS_PRE([ | ||
106 | gl_libobjs= | ||
107 | gl_ltlibobjs= | ||
108 | if test -n "$gl_LIBOBJS"; then | ||
109 | # Remove the extension. | ||
110 | sed_drop_objext='s/\.o$//;s/\.obj$//' | ||
111 | for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do | ||
112 | gl_libobjs="$gl_libobjs $i.$ac_objext" | ||
113 | gl_ltlibobjs="$gl_ltlibobjs $i.lo" | ||
114 | done | ||
115 | fi | ||
116 | AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) | ||
117 | AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) | ||
118 | ]) | ||
119 | ]) | ||
120 | |||
121 | # Like AC_LIBOBJ, except that the module name goes | ||
122 | # into gl_LIBOBJS instead of into LIBOBJS. | ||
123 | AC_DEFUN([gl_LIBOBJ], | ||
124 | [gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext"]) | ||
125 | |||
126 | # Like AC_REPLACE_FUNCS, except that the module name goes | ||
127 | # into gl_LIBOBJS instead of into LIBOBJS. | ||
128 | AC_DEFUN([gl_REPLACE_FUNCS], | ||
129 | [AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)])]) | ||
130 | |||
131 | # Like AC_LIBSOURCES, except that it does nothing. | ||
132 | # We rely on EXTRA_lib..._SOURCES instead. | ||
133 | AC_DEFUN([gl_LIBSOURCES], | ||
134 | []) | ||
135 | |||
136 | # This macro records the list of files which have been installed by | ||
137 | # gnulib-tool and may be removed by future gnulib-tool invocations. | ||
138 | AC_DEFUN([gl_FILE_LIST], [ | ||
139 | build-aux/config.rpath | ||
140 | lib/alloca.c | ||
141 | lib/alloca_.h | ||
142 | lib/asnprintf.c | ||
143 | lib/asprintf.c | ||
144 | lib/basename.c | ||
145 | lib/c-strtod.c | ||
146 | lib/c-strtod.h | ||
147 | lib/cloexec.c | ||
148 | lib/cloexec.h | ||
149 | lib/creat-safer.c | ||
150 | lib/dirname.c | ||
151 | lib/dirname.h | ||
152 | lib/dup-safer.c | ||
153 | lib/error.c | ||
154 | lib/error.h | ||
155 | lib/exit.h | ||
156 | lib/exitfail.c | ||
157 | lib/exitfail.h | ||
158 | lib/fcntl--.h | ||
159 | lib/fcntl-safer.h | ||
160 | lib/fd-safer.c | ||
161 | lib/fsusage.c | ||
162 | lib/fsusage.h | ||
163 | lib/full-read.c | ||
164 | lib/full-read.h | ||
165 | lib/full-write.c | ||
166 | lib/full-write.h | ||
167 | lib/gai_strerror.c | ||
168 | lib/getaddrinfo.c | ||
169 | lib/getaddrinfo.h | ||
170 | lib/gethostname.c | ||
171 | lib/getloadavg.c | ||
172 | lib/getopt.c | ||
173 | lib/getopt1.c | ||
174 | lib/getopt_.h | ||
175 | lib/getopt_int.h | ||
176 | lib/gettext.h | ||
177 | lib/inet_ntop.c | ||
178 | lib/inet_ntop.h | ||
179 | lib/intprops.h | ||
180 | lib/malloc.c | ||
181 | lib/mbchar.c | ||
182 | lib/mbchar.h | ||
183 | lib/mbuiter.h | ||
184 | lib/memchr.c | ||
185 | lib/minmax.h | ||
186 | lib/mountlist.c | ||
187 | lib/mountlist.h | ||
188 | lib/open-safer.c | ||
189 | lib/pipe-safer.c | ||
190 | lib/printf-args.c | ||
191 | lib/printf-args.h | ||
192 | lib/printf-parse.c | ||
193 | lib/printf-parse.h | ||
194 | lib/regcomp.c | ||
195 | lib/regex.c | ||
196 | lib/regex.h | ||
197 | lib/regex_internal.c | ||
198 | lib/regex_internal.h | ||
199 | lib/regexec.c | ||
200 | lib/safe-read.c | ||
201 | lib/safe-read.h | ||
202 | lib/safe-write.c | ||
203 | lib/safe-write.h | ||
204 | lib/size_max.h | ||
205 | lib/snprintf.c | ||
206 | lib/snprintf.h | ||
207 | lib/socket_.h | ||
208 | lib/stdbool_.h | ||
209 | lib/stdint_.h | ||
210 | lib/strcase.h | ||
211 | lib/strcasecmp.c | ||
212 | lib/strdup.c | ||
213 | lib/strdup.h | ||
214 | lib/stripslash.c | ||
215 | lib/strncasecmp.c | ||
216 | lib/strndup.c | ||
217 | lib/strndup.h | ||
218 | lib/strnlen.c | ||
219 | lib/strnlen.h | ||
220 | lib/strnlen1.c | ||
221 | lib/strnlen1.h | ||
222 | lib/unistd--.h | ||
223 | lib/unistd-safer.h | ||
224 | lib/unistd_.h | ||
225 | lib/vasnprintf.c | ||
226 | lib/vasnprintf.h | ||
227 | lib/vasprintf.c | ||
228 | lib/vasprintf.h | ||
229 | lib/vsnprintf.c | ||
230 | lib/vsnprintf.h | ||
231 | lib/wchar_.h | ||
232 | lib/wctype_.h | ||
233 | lib/wcwidth.h | ||
234 | lib/xalloc-die.c | ||
235 | lib/xalloc.h | ||
236 | lib/xmalloc.c | ||
237 | lib/xsize.h | ||
238 | lib/xstrndup.c | ||
239 | lib/xstrndup.h | ||
240 | m4/absolute-header.m4 | ||
241 | m4/alloca.m4 | ||
242 | m4/arpa_inet_h.m4 | ||
243 | m4/c-strtod.m4 | ||
244 | m4/cloexec.m4 | ||
245 | m4/codeset.m4 | ||
246 | m4/dirname.m4 | ||
247 | m4/dos.m4 | ||
248 | m4/double-slash-root.m4 | ||
249 | m4/eoverflow.m4 | ||
250 | m4/error.m4 | ||
251 | m4/exitfail.m4 | ||
252 | m4/extensions.m4 | ||
253 | m4/fcntl-safer.m4 | ||
254 | m4/fstypename.m4 | ||
255 | m4/fsusage.m4 | ||
256 | m4/getaddrinfo.m4 | ||
257 | m4/gethostname.m4 | ||
258 | m4/getloadavg.m4 | ||
259 | m4/getopt.m4 | ||
260 | m4/gettext.m4 | ||
261 | m4/glibc2.m4 | ||
262 | m4/glibc21.m4 | ||
263 | m4/gnulib-common.m4 | ||
264 | m4/iconv.m4 | ||
265 | m4/inet_ntop.m4 | ||
266 | m4/inline.m4 | ||
267 | m4/intdiv0.m4 | ||
268 | m4/intl.m4 | ||
269 | m4/intldir.m4 | ||
270 | m4/intmax.m4 | ||
271 | m4/intmax_t.m4 | ||
272 | m4/inttypes-pri.m4 | ||
273 | m4/inttypes_h.m4 | ||
274 | m4/lcmessage.m4 | ||
275 | m4/lib-ld.m4 | ||
276 | m4/lib-link.m4 | ||
277 | m4/lib-prefix.m4 | ||
278 | m4/lock.m4 | ||
279 | m4/longdouble.m4 | ||
280 | m4/longlong.m4 | ||
281 | m4/ls-mntd-fs.m4 | ||
282 | m4/mbchar.m4 | ||
283 | m4/mbiter.m4 | ||
284 | m4/mbrtowc.m4 | ||
285 | m4/memchr.m4 | ||
286 | m4/minmax.m4 | ||
287 | m4/mountlist.m4 | ||
288 | m4/netinet_in_h.m4 | ||
289 | m4/nls.m4 | ||
290 | m4/onceonly_2_57.m4 | ||
291 | m4/po.m4 | ||
292 | m4/printf-posix.m4 | ||
293 | m4/progtest.m4 | ||
294 | m4/regex.m4 | ||
295 | m4/safe-read.m4 | ||
296 | m4/safe-write.m4 | ||
297 | m4/size_max.m4 | ||
298 | m4/snprintf.m4 | ||
299 | m4/socklen.m4 | ||
300 | m4/sockpfaf.m4 | ||
301 | m4/ssize_t.m4 | ||
302 | m4/stdbool.m4 | ||
303 | m4/stdint.m4 | ||
304 | m4/stdint_h.m4 | ||
305 | m4/strcase.m4 | ||
306 | m4/strdup.m4 | ||
307 | m4/strndup.m4 | ||
308 | m4/strnlen.m4 | ||
309 | m4/sys_socket_h.m4 | ||
310 | m4/uintmax_t.m4 | ||
311 | m4/ulonglong.m4 | ||
312 | m4/unistd-safer.m4 | ||
313 | m4/unistd_h.m4 | ||
314 | m4/vasnprintf.m4 | ||
315 | m4/vasprintf.m4 | ||
316 | m4/visibility.m4 | ||
317 | m4/vsnprintf.m4 | ||
318 | m4/wchar.m4 | ||
319 | m4/wchar_t.m4 | ||
320 | m4/wctype.m4 | ||
321 | m4/wcwidth.m4 | ||
322 | m4/wint_t.m4 | ||
323 | m4/xalloc.m4 | ||
324 | m4/xsize.m4 | ||
325 | m4/xstrndup.m4 | ||
326 | ]) | ||
diff --git a/gl/m4/gnulib-tool.m4 b/gl/m4/gnulib-tool.m4 new file mode 100644 index 0000000..ef59320 --- /dev/null +++ b/gl/m4/gnulib-tool.m4 | |||
@@ -0,0 +1,33 @@ | |||
1 | # gnulib-tool.m4 serial 1 | ||
2 | dnl Copyright (C) 2004-2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl The following macros need not be invoked explicitly. | ||
8 | dnl Invoking them does nothing except to declare default arguments | ||
9 | dnl for "gnulib-tool --import". | ||
10 | |||
11 | dnl Usage: gl_MODULES([module1 module2 ...]) | ||
12 | AC_DEFUN([gl_MODULES], []) | ||
13 | |||
14 | dnl Usage: gl_AVOID([module1 module2 ...]) | ||
15 | AC_DEFUN([gl_AVOID], []) | ||
16 | |||
17 | dnl Usage: gl_SOURCE_BASE([DIR]) | ||
18 | AC_DEFUN([gl_SOURCE_BASE], []) | ||
19 | |||
20 | dnl Usage: gl_M4_BASE([DIR]) | ||
21 | AC_DEFUN([gl_M4_BASE], []) | ||
22 | |||
23 | dnl Usage: gl_LIB([LIBNAME]) | ||
24 | AC_DEFUN([gl_LIB], []) | ||
25 | |||
26 | dnl Usage: gl_LGPL | ||
27 | AC_DEFUN([gl_LGPL], []) | ||
28 | |||
29 | dnl Usage: gl_LIBTOOL | ||
30 | AC_DEFUN([gl_LIBTOOL], []) | ||
31 | |||
32 | dnl Usage: gl_MACRO_PREFIX([PREFIX]) | ||
33 | AC_DEFUN([gl_MACRO_PREFIX], []) | ||
diff --git a/m4/iconv.m4 b/gl/m4/iconv.m4 index 654c415..654c415 100644 --- a/m4/iconv.m4 +++ b/gl/m4/iconv.m4 | |||
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4 new file mode 100644 index 0000000..bb02d22 --- /dev/null +++ b/gl/m4/inet_ntop.m4 | |||
@@ -0,0 +1,19 @@ | |||
1 | # inet_ntop.m4 serial 3 | ||
2 | dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_INET_NTOP], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(inet_ntop) | ||
10 | gl_PREREQ_INET_NTOP | ||
11 | ]) | ||
12 | |||
13 | # Prerequisites of lib/inet_ntop.h and lib/inet_ntop.c. | ||
14 | AC_DEFUN([gl_PREREQ_INET_NTOP], [ | ||
15 | AC_CHECK_HEADERS_ONCE([netinet/in.h arpa/inet.h]) | ||
16 | AC_CHECK_DECLS([inet_ntop],,,[#include <arpa/inet.h>]) | ||
17 | AC_REQUIRE([gl_SOCKET_FAMILIES]) | ||
18 | AC_REQUIRE([AC_C_RESTRICT]) | ||
19 | ]) | ||
diff --git a/gl/m4/inline.m4 b/gl/m4/inline.m4 new file mode 100644 index 0000000..a07076c --- /dev/null +++ b/gl/m4/inline.m4 | |||
@@ -0,0 +1,40 @@ | |||
1 | # inline.m4 serial 3 | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl Test for the 'inline' keyword or equivalent. | ||
8 | dnl Define 'inline' to a supported equivalent, or to nothing if not supported, | ||
9 | dnl like AC_C_INLINE does. Also, define HAVE_INLINE if 'inline' or an | ||
10 | dnl equivalent is effectively supported, i.e. if the compiler is likely to | ||
11 | dnl drop unused 'static inline' functions. | ||
12 | AC_DEFUN([gl_INLINE], | ||
13 | [ | ||
14 | AC_REQUIRE([AC_C_INLINE]) | ||
15 | AC_CACHE_CHECK([whether the compiler generally respects inline], | ||
16 | [gl_cv_c_inline_effective], | ||
17 | [if test $ac_cv_c_inline = no; then | ||
18 | gl_cv_c_inline_effective=no | ||
19 | else | ||
20 | dnl GCC defines __NO_INLINE__ if not optimizing or if -fno-inline is | ||
21 | dnl specified. | ||
22 | dnl Use AC_COMPILE_IFELSE here, not AC_EGREP_CPP, because the result | ||
23 | dnl depends on optimization flags, which can be in CFLAGS. | ||
24 | dnl (AC_EGREP_CPP looks only at the CPPFLAGS.) | ||
25 | AC_COMPILE_IFELSE( | ||
26 | [AC_LANG_PROGRAM([[]], | ||
27 | [[#ifdef __NO_INLINE__ | ||
28 | #error "inline is not effective" | ||
29 | #endif]])], | ||
30 | [gl_cv_c_inline_effective=yes], | ||
31 | [gl_cv_c_inline_effective=no]) | ||
32 | fi | ||
33 | ]) | ||
34 | if test $gl_cv_c_inline_effective = yes; then | ||
35 | AC_DEFINE([HAVE_INLINE], 1, | ||
36 | [Define to 1 if the compiler supports one of the keywords | ||
37 | 'inline', '__inline__', '__inline' and effectively inlines | ||
38 | functions marked as such.]) | ||
39 | fi | ||
40 | ]) | ||
diff --git a/gl/m4/intdiv0.m4 b/gl/m4/intdiv0.m4 new file mode 100644 index 0000000..b8d7817 --- /dev/null +++ b/gl/m4/intdiv0.m4 | |||
@@ -0,0 +1,70 @@ | |||
1 | # intdiv0.m4 serial 1 (gettext-0.11.3) | ||
2 | dnl Copyright (C) 2002 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | AC_DEFUN([gt_INTDIV0], | ||
10 | [ | ||
11 | AC_REQUIRE([AC_PROG_CC])dnl | ||
12 | AC_REQUIRE([AC_CANONICAL_HOST])dnl | ||
13 | |||
14 | AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], | ||
15 | gt_cv_int_divbyzero_sigfpe, | ||
16 | [ | ||
17 | AC_TRY_RUN([ | ||
18 | #include <stdlib.h> | ||
19 | #include <signal.h> | ||
20 | |||
21 | static void | ||
22 | #ifdef __cplusplus | ||
23 | sigfpe_handler (int sig) | ||
24 | #else | ||
25 | sigfpe_handler (sig) int sig; | ||
26 | #endif | ||
27 | { | ||
28 | /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ | ||
29 | exit (sig != SIGFPE); | ||
30 | } | ||
31 | |||
32 | int x = 1; | ||
33 | int y = 0; | ||
34 | int z; | ||
35 | int nan; | ||
36 | |||
37 | int main () | ||
38 | { | ||
39 | signal (SIGFPE, sigfpe_handler); | ||
40 | /* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ | ||
41 | #if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) | ||
42 | signal (SIGTRAP, sigfpe_handler); | ||
43 | #endif | ||
44 | /* Linux/SPARC yields signal SIGILL. */ | ||
45 | #if defined (__sparc__) && defined (__linux__) | ||
46 | signal (SIGILL, sigfpe_handler); | ||
47 | #endif | ||
48 | |||
49 | z = x / y; | ||
50 | nan = y / y; | ||
51 | exit (1); | ||
52 | } | ||
53 | ], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, | ||
54 | [ | ||
55 | # Guess based on the CPU. | ||
56 | case "$host_cpu" in | ||
57 | alpha* | i[34567]86 | m68k | s390*) | ||
58 | gt_cv_int_divbyzero_sigfpe="guessing yes";; | ||
59 | *) | ||
60 | gt_cv_int_divbyzero_sigfpe="guessing no";; | ||
61 | esac | ||
62 | ]) | ||
63 | ]) | ||
64 | case "$gt_cv_int_divbyzero_sigfpe" in | ||
65 | *yes) value=1;; | ||
66 | *) value=0;; | ||
67 | esac | ||
68 | AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, | ||
69 | [Define if integer division by zero raises signal SIGFPE.]) | ||
70 | ]) | ||
diff --git a/gl/m4/intl.m4 b/gl/m4/intl.m4 new file mode 100644 index 0000000..dcefb11 --- /dev/null +++ b/gl/m4/intl.m4 | |||
@@ -0,0 +1,259 @@ | |||
1 | # intl.m4 serial 3 (gettext-0.16) | ||
2 | dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | dnl | ||
7 | dnl This file can can be used in projects which are not available under | ||
8 | dnl the GNU General Public License or the GNU Library General Public | ||
9 | dnl License but which still want to provide support for the GNU gettext | ||
10 | dnl functionality. | ||
11 | dnl Please note that the actual code of the GNU gettext library is covered | ||
12 | dnl by the GNU Library General Public License, and the rest of the GNU | ||
13 | dnl gettext package package is covered by the GNU General Public License. | ||
14 | dnl They are *not* in the public domain. | ||
15 | |||
16 | dnl Authors: | ||
17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. | ||
18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006. | ||
19 | |||
20 | AC_PREREQ(2.52) | ||
21 | |||
22 | dnl Checks for all prerequisites of the intl subdirectory, | ||
23 | dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, | ||
24 | dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. | ||
25 | AC_DEFUN([AM_INTL_SUBDIR], | ||
26 | [ | ||
27 | AC_REQUIRE([AC_PROG_INSTALL])dnl | ||
28 | AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake | ||
29 | AC_REQUIRE([AC_PROG_CC])dnl | ||
30 | AC_REQUIRE([AC_CANONICAL_HOST])dnl | ||
31 | AC_REQUIRE([gt_GLIBC2])dnl | ||
32 | AC_REQUIRE([AC_PROG_RANLIB])dnl | ||
33 | AC_REQUIRE([gl_VISIBILITY])dnl | ||
34 | AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl | ||
35 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl | ||
36 | AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl | ||
37 | AC_REQUIRE([gt_TYPE_WCHAR_T])dnl | ||
38 | AC_REQUIRE([gt_TYPE_WINT_T])dnl | ||
39 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) | ||
40 | AC_REQUIRE([gt_TYPE_INTMAX_T]) | ||
41 | AC_REQUIRE([gt_PRINTF_POSIX]) | ||
42 | AC_REQUIRE([gl_GLIBC21])dnl | ||
43 | AC_REQUIRE([gl_XSIZE])dnl | ||
44 | AC_REQUIRE([gt_INTL_MACOSX])dnl | ||
45 | |||
46 | AC_CHECK_TYPE([ptrdiff_t], , | ||
47 | [AC_DEFINE([ptrdiff_t], [long], | ||
48 | [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) | ||
49 | ]) | ||
50 | AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) | ||
51 | AC_CHECK_FUNCS([asprintf fwprintf putenv setenv setlocale snprintf wcslen]) | ||
52 | |||
53 | dnl Use the _snprintf function only if it is declared (because on NetBSD it | ||
54 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). | ||
55 | gt_CHECK_DECL(_snprintf, [#include <stdio.h>]) | ||
56 | gt_CHECK_DECL(_snwprintf, [#include <stdio.h>]) | ||
57 | |||
58 | dnl Use the *_unlocked functions only if they are declared. | ||
59 | dnl (because some of them were defined without being declared in Solaris | ||
60 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built | ||
61 | dnl on Solaris 2.5.1 to run on Solaris 2.6). | ||
62 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. | ||
63 | gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>]) | ||
64 | |||
65 | case $gt_cv_func_printf_posix in | ||
66 | *yes) HAVE_POSIX_PRINTF=1 ;; | ||
67 | *) HAVE_POSIX_PRINTF=0 ;; | ||
68 | esac | ||
69 | AC_SUBST([HAVE_POSIX_PRINTF]) | ||
70 | if test "$ac_cv_func_asprintf" = yes; then | ||
71 | HAVE_ASPRINTF=1 | ||
72 | else | ||
73 | HAVE_ASPRINTF=0 | ||
74 | fi | ||
75 | AC_SUBST([HAVE_ASPRINTF]) | ||
76 | if test "$ac_cv_func_snprintf" = yes; then | ||
77 | HAVE_SNPRINTF=1 | ||
78 | else | ||
79 | HAVE_SNPRINTF=0 | ||
80 | fi | ||
81 | AC_SUBST([HAVE_SNPRINTF]) | ||
82 | if test "$ac_cv_func_wprintf" = yes; then | ||
83 | HAVE_WPRINTF=1 | ||
84 | else | ||
85 | HAVE_WPRINTF=0 | ||
86 | fi | ||
87 | AC_SUBST([HAVE_WPRINTF]) | ||
88 | |||
89 | AM_LANGINFO_CODESET | ||
90 | gt_LC_MESSAGES | ||
91 | |||
92 | dnl Compilation on mingw and Cygwin needs special Makefile rules, because | ||
93 | dnl 1. when we install a shared library, we must arrange to export | ||
94 | dnl auxiliary pointer variables for every exported variable, | ||
95 | dnl 2. when we install a shared library and a static library simultaneously, | ||
96 | dnl the include file specifies __declspec(dllimport) and therefore we | ||
97 | dnl must arrange to define the auxiliary pointer variables for the | ||
98 | dnl exported variables _also_ in the static library. | ||
99 | if test "$enable_shared" = yes; then | ||
100 | case "$host_os" in | ||
101 | cygwin*) is_woe32dll=yes ;; | ||
102 | *) is_woe32dll=no ;; | ||
103 | esac | ||
104 | else | ||
105 | is_woe32dll=no | ||
106 | fi | ||
107 | WOE32DLL=$is_woe32dll | ||
108 | AC_SUBST([WOE32DLL]) | ||
109 | |||
110 | dnl Rename some macros and functions used for locking. | ||
111 | AH_BOTTOM([ | ||
112 | #define __libc_lock_t gl_lock_t | ||
113 | #define __libc_lock_define gl_lock_define | ||
114 | #define __libc_lock_define_initialized gl_lock_define_initialized | ||
115 | #define __libc_lock_init gl_lock_init | ||
116 | #define __libc_lock_lock gl_lock_lock | ||
117 | #define __libc_lock_unlock gl_lock_unlock | ||
118 | #define __libc_lock_recursive_t gl_recursive_lock_t | ||
119 | #define __libc_lock_define_recursive gl_recursive_lock_define | ||
120 | #define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized | ||
121 | #define __libc_lock_init_recursive gl_recursive_lock_init | ||
122 | #define __libc_lock_lock_recursive gl_recursive_lock_lock | ||
123 | #define __libc_lock_unlock_recursive gl_recursive_lock_unlock | ||
124 | #define glthread_in_use libintl_thread_in_use | ||
125 | #define glthread_lock_init libintl_lock_init | ||
126 | #define glthread_lock_lock libintl_lock_lock | ||
127 | #define glthread_lock_unlock libintl_lock_unlock | ||
128 | #define glthread_lock_destroy libintl_lock_destroy | ||
129 | #define glthread_rwlock_init libintl_rwlock_init | ||
130 | #define glthread_rwlock_rdlock libintl_rwlock_rdlock | ||
131 | #define glthread_rwlock_wrlock libintl_rwlock_wrlock | ||
132 | #define glthread_rwlock_unlock libintl_rwlock_unlock | ||
133 | #define glthread_rwlock_destroy libintl_rwlock_destroy | ||
134 | #define glthread_recursive_lock_init libintl_recursive_lock_init | ||
135 | #define glthread_recursive_lock_lock libintl_recursive_lock_lock | ||
136 | #define glthread_recursive_lock_unlock libintl_recursive_lock_unlock | ||
137 | #define glthread_recursive_lock_destroy libintl_recursive_lock_destroy | ||
138 | #define glthread_once libintl_once | ||
139 | #define glthread_once_call libintl_once_call | ||
140 | #define glthread_once_singlethreaded libintl_once_singlethreaded | ||
141 | ]) | ||
142 | ]) | ||
143 | |||
144 | |||
145 | dnl Checks for the core files of the intl subdirectory: | ||
146 | dnl dcigettext.c | ||
147 | dnl eval-plural.h | ||
148 | dnl explodename.c | ||
149 | dnl finddomain.c | ||
150 | dnl gettextP.h | ||
151 | dnl gmo.h | ||
152 | dnl hash-string.h hash-string.c | ||
153 | dnl l10nflist.c | ||
154 | dnl libgnuintl.h.in (except the *printf stuff) | ||
155 | dnl loadinfo.h | ||
156 | dnl loadmsgcat.c | ||
157 | dnl localealias.c | ||
158 | dnl log.c | ||
159 | dnl plural-exp.h plural-exp.c | ||
160 | dnl plural.y | ||
161 | dnl Used by libglocale. | ||
162 | AC_DEFUN([gt_INTL_SUBDIR_CORE], | ||
163 | [ | ||
164 | AC_REQUIRE([AC_C_INLINE])dnl | ||
165 | AC_REQUIRE([AC_TYPE_SIZE_T])dnl | ||
166 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) | ||
167 | AC_REQUIRE([AC_FUNC_ALLOCA])dnl | ||
168 | AC_REQUIRE([AC_FUNC_MMAP])dnl | ||
169 | AC_REQUIRE([gt_INTDIV0])dnl | ||
170 | AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl | ||
171 | AC_REQUIRE([gt_INTTYPES_PRI])dnl | ||
172 | AC_REQUIRE([gl_LOCK])dnl | ||
173 | |||
174 | AC_TRY_LINK( | ||
175 | [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], | ||
176 | [], | ||
177 | [AC_DEFINE([HAVE_BUILTIN_EXPECT], 1, | ||
178 | [Define to 1 if the compiler understands __builtin_expect.])]) | ||
179 | |||
180 | AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) | ||
181 | AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ | ||
182 | stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ | ||
183 | argz_next __fsetlocking]) | ||
184 | |||
185 | dnl Use the *_unlocked functions only if they are declared. | ||
186 | dnl (because some of them were defined without being declared in Solaris | ||
187 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built | ||
188 | dnl on Solaris 2.5.1 to run on Solaris 2.6). | ||
189 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. | ||
190 | gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>]) | ||
191 | gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>]) | ||
192 | |||
193 | AM_ICONV | ||
194 | |||
195 | dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined, | ||
196 | dnl and a _NL_LOCALE_NAME macro always. | ||
197 | AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, | ||
198 | [AC_TRY_LINK([#include <langinfo.h> | ||
199 | #include <locale.h>], | ||
200 | [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES));], | ||
201 | gt_cv_nl_locale_name=yes, | ||
202 | gt_cv_nl_locale_name=no) | ||
203 | ]) | ||
204 | if test $gt_cv_nl_locale_name = yes; then | ||
205 | AC_DEFINE(HAVE_NL_LOCALE_NAME, 1, | ||
206 | [Define if you have <langinfo.h> and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.]) | ||
207 | fi | ||
208 | |||
209 | dnl intl/plural.c is generated from intl/plural.y. It requires bison, | ||
210 | dnl because plural.y uses bison specific features. It requires at least | ||
211 | dnl bison-1.26 because earlier versions generate a plural.c that doesn't | ||
212 | dnl compile. | ||
213 | dnl bison is only needed for the maintainer (who touches plural.y). But in | ||
214 | dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put | ||
215 | dnl the rule in general Makefile. Now, some people carelessly touch the | ||
216 | dnl files or have a broken "make" program, hence the plural.c rule will | ||
217 | dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not | ||
218 | dnl present or too old. | ||
219 | AC_CHECK_PROGS([INTLBISON], [bison]) | ||
220 | if test -z "$INTLBISON"; then | ||
221 | ac_verc_fail=yes | ||
222 | else | ||
223 | dnl Found it, now check the version. | ||
224 | AC_MSG_CHECKING([version of bison]) | ||
225 | changequote(<<,>>)dnl | ||
226 | ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` | ||
227 | case $ac_prog_version in | ||
228 | '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; | ||
229 | 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) | ||
230 | changequote([,])dnl | ||
231 | ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; | ||
232 | *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; | ||
233 | esac | ||
234 | AC_MSG_RESULT([$ac_prog_version]) | ||
235 | fi | ||
236 | if test $ac_verc_fail = yes; then | ||
237 | INTLBISON=: | ||
238 | fi | ||
239 | ]) | ||
240 | |||
241 | |||
242 | dnl gt_CHECK_DECL(FUNC, INCLUDES) | ||
243 | dnl Check whether a function is declared. | ||
244 | AC_DEFUN([gt_CHECK_DECL], | ||
245 | [ | ||
246 | AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, | ||
247 | [AC_TRY_COMPILE([$2], [ | ||
248 | #ifndef $1 | ||
249 | char *p = (char *) $1; | ||
250 | #endif | ||
251 | ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) | ||
252 | if test $ac_cv_have_decl_$1 = yes; then | ||
253 | gt_value=1 | ||
254 | else | ||
255 | gt_value=0 | ||
256 | fi | ||
257 | AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], | ||
258 | [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) | ||
259 | ]) | ||
diff --git a/gl/m4/intldir.m4 b/gl/m4/intldir.m4 new file mode 100644 index 0000000..7a28843 --- /dev/null +++ b/gl/m4/intldir.m4 | |||
@@ -0,0 +1,19 @@ | |||
1 | # intldir.m4 serial 1 (gettext-0.16) | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | dnl | ||
7 | dnl This file can can be used in projects which are not available under | ||
8 | dnl the GNU General Public License or the GNU Library General Public | ||
9 | dnl License but which still want to provide support for the GNU gettext | ||
10 | dnl functionality. | ||
11 | dnl Please note that the actual code of the GNU gettext library is covered | ||
12 | dnl by the GNU Library General Public License, and the rest of the GNU | ||
13 | dnl gettext package package is covered by the GNU General Public License. | ||
14 | dnl They are *not* in the public domain. | ||
15 | |||
16 | AC_PREREQ(2.52) | ||
17 | |||
18 | dnl Tells the AM_GNU_GETTEXT macro to consider an intl/ directory. | ||
19 | AC_DEFUN([AM_GNU_GETTEXT_INTL_SUBDIR], []) | ||
diff --git a/gl/m4/intmax.m4 b/gl/m4/intmax.m4 new file mode 100644 index 0000000..ce7a8a4 --- /dev/null +++ b/gl/m4/intmax.m4 | |||
@@ -0,0 +1,33 @@ | |||
1 | # intmax.m4 serial 3 (gettext-0.16) | ||
2 | dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | dnl Test whether the system has the 'intmax_t' type, but don't attempt to | ||
9 | dnl find a replacement if it is lacking. | ||
10 | |||
11 | AC_DEFUN([gt_TYPE_INTMAX_T], | ||
12 | [ | ||
13 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) | ||
14 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) | ||
15 | AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, | ||
16 | [AC_TRY_COMPILE([ | ||
17 | #include <stddef.h> | ||
18 | #include <stdlib.h> | ||
19 | #if HAVE_STDINT_H_WITH_UINTMAX | ||
20 | #include <stdint.h> | ||
21 | #endif | ||
22 | #if HAVE_INTTYPES_H_WITH_UINTMAX | ||
23 | #include <inttypes.h> | ||
24 | #endif | ||
25 | ], [intmax_t x = -1; | ||
26 | return !x;], | ||
27 | gt_cv_c_intmax_t=yes, | ||
28 | gt_cv_c_intmax_t=no)]) | ||
29 | if test $gt_cv_c_intmax_t = yes; then | ||
30 | AC_DEFINE(HAVE_INTMAX_T, 1, | ||
31 | [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) | ||
32 | fi | ||
33 | ]) | ||
diff --git a/gl/m4/intmax_t.m4 b/gl/m4/intmax_t.m4 new file mode 100644 index 0000000..17c7b0a --- /dev/null +++ b/gl/m4/intmax_t.m4 | |||
@@ -0,0 +1,61 @@ | |||
1 | # intmax_t.m4 serial 5 | ||
2 | dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | AC_PREREQ(2.13) | ||
10 | |||
11 | # Define intmax_t to 'long' or 'long long' | ||
12 | # if it is not already defined in <stdint.h> or <inttypes.h>. | ||
13 | |||
14 | AC_DEFUN([gl_AC_TYPE_INTMAX_T], | ||
15 | [ | ||
16 | dnl For simplicity, we assume that a header file defines 'intmax_t' if and | ||
17 | dnl only if it defines 'uintmax_t'. | ||
18 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) | ||
19 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) | ||
20 | if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then | ||
21 | AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) | ||
22 | test $ac_cv_type_long_long = yes \ | ||
23 | && ac_type='long long' \ | ||
24 | || ac_type='long' | ||
25 | AC_DEFINE_UNQUOTED(intmax_t, $ac_type, | ||
26 | [Define to long or long long if <inttypes.h> and <stdint.h> don't define.]) | ||
27 | else | ||
28 | AC_DEFINE(HAVE_INTMAX_T, 1, | ||
29 | [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) | ||
30 | fi | ||
31 | ]) | ||
32 | |||
33 | dnl An alternative would be to explicitly test for 'intmax_t'. | ||
34 | |||
35 | AC_DEFUN([gt_AC_TYPE_INTMAX_T], | ||
36 | [ | ||
37 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) | ||
38 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) | ||
39 | AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, | ||
40 | [AC_TRY_COMPILE([ | ||
41 | #include <stddef.h> | ||
42 | #include <stdlib.h> | ||
43 | #if HAVE_STDINT_H_WITH_UINTMAX | ||
44 | #include <stdint.h> | ||
45 | #endif | ||
46 | #if HAVE_INTTYPES_H_WITH_UINTMAX | ||
47 | #include <inttypes.h> | ||
48 | #endif | ||
49 | ], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)]) | ||
50 | if test $gt_cv_c_intmax_t = yes; then | ||
51 | AC_DEFINE(HAVE_INTMAX_T, 1, | ||
52 | [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) | ||
53 | else | ||
54 | AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) | ||
55 | test $ac_cv_type_long_long = yes \ | ||
56 | && ac_type='long long' \ | ||
57 | || ac_type='long' | ||
58 | AC_DEFINE_UNQUOTED(intmax_t, $ac_type, | ||
59 | [Define to long or long long if <stdint.h> and <inttypes.h> don't define.]) | ||
60 | fi | ||
61 | ]) | ||
diff --git a/m4/inttypes-pri.m4 b/gl/m4/inttypes-pri.m4 index 4d56a9a..7c7f894 100644 --- a/m4/inttypes-pri.m4 +++ b/gl/m4/inttypes-pri.m4 | |||
@@ -1,18 +1,20 @@ | |||
1 | # inttypes-pri.m4 serial 1 (gettext-0.11.4) | 1 | # inttypes-pri.m4 serial 4 (gettext-0.16) |
2 | dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1997-2002, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | dnl From Bruno Haible. | 7 | dnl From Bruno Haible. |
8 | 8 | ||
9 | AC_PREREQ(2.52) | ||
10 | |||
9 | # Define PRI_MACROS_BROKEN if <inttypes.h> exists and defines the PRI* | 11 | # Define PRI_MACROS_BROKEN if <inttypes.h> exists and defines the PRI* |
10 | # macros to non-string values. This is the case on AIX 4.3.3. | 12 | # macros to non-string values. This is the case on AIX 4.3.3. |
11 | 13 | ||
12 | AC_DEFUN([gt_INTTYPES_PRI], | 14 | AC_DEFUN([gt_INTTYPES_PRI], |
13 | [ | 15 | [ |
14 | AC_REQUIRE([gt_HEADER_INTTYPES_H]) | 16 | AC_CHECK_HEADERS([inttypes.h]) |
15 | if test $gt_cv_header_inttypes_h = yes; then | 17 | if test $ac_cv_header_inttypes_h = yes; then |
16 | AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], | 18 | AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], |
17 | gt_cv_inttypes_pri_broken, | 19 | gt_cv_inttypes_pri_broken, |
18 | [ | 20 | [ |
@@ -26,5 +28,9 @@ char *p = PRId32; | |||
26 | if test "$gt_cv_inttypes_pri_broken" = yes; then | 28 | if test "$gt_cv_inttypes_pri_broken" = yes; then |
27 | AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, | 29 | AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, |
28 | [Define if <inttypes.h> exists and defines unusable PRI* macros.]) | 30 | [Define if <inttypes.h> exists and defines unusable PRI* macros.]) |
31 | PRI_MACROS_BROKEN=1 | ||
32 | else | ||
33 | PRI_MACROS_BROKEN=0 | ||
29 | fi | 34 | fi |
35 | AC_SUBST([PRI_MACROS_BROKEN]) | ||
30 | ]) | 36 | ]) |
diff --git a/m4/inttypes_h.m4 b/gl/m4/inttypes_h.m4 index a5d075d..edc8ecb 100644 --- a/m4/inttypes_h.m4 +++ b/gl/m4/inttypes_h.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # inttypes_h.m4 serial 6 | 1 | # inttypes_h.m4 serial 7 |
2 | dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -15,7 +15,7 @@ AC_DEFUN([gl_AC_HEADER_INTTYPES_H], | |||
15 | [AC_TRY_COMPILE( | 15 | [AC_TRY_COMPILE( |
16 | [#include <sys/types.h> | 16 | [#include <sys/types.h> |
17 | #include <inttypes.h>], | 17 | #include <inttypes.h>], |
18 | [uintmax_t i = (uintmax_t) -1;], | 18 | [uintmax_t i = (uintmax_t) -1; return !i;], |
19 | gl_cv_header_inttypes_h=yes, | 19 | gl_cv_header_inttypes_h=yes, |
20 | gl_cv_header_inttypes_h=no)]) | 20 | gl_cv_header_inttypes_h=no)]) |
21 | if test $gl_cv_header_inttypes_h = yes; then | 21 | if test $gl_cv_header_inttypes_h = yes; then |
diff --git a/gl/m4/lcmessage.m4 b/gl/m4/lcmessage.m4 new file mode 100644 index 0000000..19aa77e --- /dev/null +++ b/gl/m4/lcmessage.m4 | |||
@@ -0,0 +1,30 @@ | |||
1 | # lcmessage.m4 serial 4 (gettext-0.14.2) | ||
2 | dnl Copyright (C) 1995-2002, 2004-2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | dnl | ||
7 | dnl This file can can be used in projects which are not available under | ||
8 | dnl the GNU General Public License or the GNU Library General Public | ||
9 | dnl License but which still want to provide support for the GNU gettext | ||
10 | dnl functionality. | ||
11 | dnl Please note that the actual code of the GNU gettext library is covered | ||
12 | dnl by the GNU Library General Public License, and the rest of the GNU | ||
13 | dnl gettext package package is covered by the GNU General Public License. | ||
14 | dnl They are *not* in the public domain. | ||
15 | |||
16 | dnl Authors: | ||
17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995. | ||
18 | |||
19 | # Check whether LC_MESSAGES is available in <locale.h>. | ||
20 | |||
21 | AC_DEFUN([gt_LC_MESSAGES], | ||
22 | [ | ||
23 | AC_CACHE_CHECK([for LC_MESSAGES], gt_cv_val_LC_MESSAGES, | ||
24 | [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES], | ||
25 | gt_cv_val_LC_MESSAGES=yes, gt_cv_val_LC_MESSAGES=no)]) | ||
26 | if test $gt_cv_val_LC_MESSAGES = yes; then | ||
27 | AC_DEFINE(HAVE_LC_MESSAGES, 1, | ||
28 | [Define if your <locale.h> file defines LC_MESSAGES.]) | ||
29 | fi | ||
30 | ]) | ||
diff --git a/m4/lib-ld.m4 b/gl/m4/lib-ld.m4 index 96c4e2c..96c4e2c 100644 --- a/m4/lib-ld.m4 +++ b/gl/m4/lib-ld.m4 | |||
diff --git a/m4/lib-link.m4 b/gl/m4/lib-link.m4 index 244a779..f157d98 100644 --- a/m4/lib-link.m4 +++ b/gl/m4/lib-link.m4 | |||
@@ -1,17 +1,19 @@ | |||
1 | # lib-link.m4 serial 7 (gettext-0.15) | 1 | # lib-link.m4 serial 13 (gettext-0.16.2) |
2 | dnl Copyright (C) 2001-2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | dnl From Bruno Haible. | 7 | dnl From Bruno Haible. |
8 | 8 | ||
9 | AC_PREREQ(2.50) | 9 | AC_PREREQ(2.54) |
10 | 10 | ||
11 | dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and | 11 | dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and |
12 | dnl the libraries corresponding to explicit and implicit dependencies. | 12 | dnl the libraries corresponding to explicit and implicit dependencies. |
13 | dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and | 13 | dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and |
14 | dnl augments the CPPFLAGS variable. | 14 | dnl augments the CPPFLAGS variable. |
15 | dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname | ||
16 | dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. | ||
15 | AC_DEFUN([AC_LIB_LINKFLAGS], | 17 | AC_DEFUN([AC_LIB_LINKFLAGS], |
16 | [ | 18 | [ |
17 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) | 19 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) |
@@ -24,13 +26,16 @@ AC_DEFUN([AC_LIB_LINKFLAGS], | |||
24 | ac_cv_lib[]Name[]_libs="$LIB[]NAME" | 26 | ac_cv_lib[]Name[]_libs="$LIB[]NAME" |
25 | ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" | 27 | ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" |
26 | ac_cv_lib[]Name[]_cppflags="$INC[]NAME" | 28 | ac_cv_lib[]Name[]_cppflags="$INC[]NAME" |
29 | ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX" | ||
27 | ]) | 30 | ]) |
28 | LIB[]NAME="$ac_cv_lib[]Name[]_libs" | 31 | LIB[]NAME="$ac_cv_lib[]Name[]_libs" |
29 | LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" | 32 | LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" |
30 | INC[]NAME="$ac_cv_lib[]Name[]_cppflags" | 33 | INC[]NAME="$ac_cv_lib[]Name[]_cppflags" |
34 | LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix" | ||
31 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) | 35 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) |
32 | AC_SUBST([LIB]NAME) | 36 | AC_SUBST([LIB]NAME) |
33 | AC_SUBST([LTLIB]NAME) | 37 | AC_SUBST([LTLIB]NAME) |
38 | AC_SUBST([LIB]NAME[_PREFIX]) | ||
34 | dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the | 39 | dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the |
35 | dnl results of this search when this library appears as a dependency. | 40 | dnl results of this search when this library appears as a dependency. |
36 | HAVE_LIB[]NAME=yes | 41 | HAVE_LIB[]NAME=yes |
@@ -46,6 +51,8 @@ dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and | |||
46 | dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and | 51 | dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and |
47 | dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs | 52 | dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs |
48 | dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. | 53 | dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. |
54 | dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname | ||
55 | dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. | ||
49 | AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], | 56 | AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], |
50 | [ | 57 | [ |
51 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) | 58 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) |
@@ -82,17 +89,23 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], | |||
82 | CPPFLAGS="$ac_save_CPPFLAGS" | 89 | CPPFLAGS="$ac_save_CPPFLAGS" |
83 | LIB[]NAME= | 90 | LIB[]NAME= |
84 | LTLIB[]NAME= | 91 | LTLIB[]NAME= |
92 | LIB[]NAME[]_PREFIX= | ||
85 | fi | 93 | fi |
86 | AC_SUBST([HAVE_LIB]NAME) | 94 | AC_SUBST([HAVE_LIB]NAME) |
87 | AC_SUBST([LIB]NAME) | 95 | AC_SUBST([LIB]NAME) |
88 | AC_SUBST([LTLIB]NAME) | 96 | AC_SUBST([LTLIB]NAME) |
97 | AC_SUBST([LIB]NAME[_PREFIX]) | ||
89 | undefine([Name]) | 98 | undefine([Name]) |
90 | undefine([NAME]) | 99 | undefine([NAME]) |
91 | ]) | 100 | ]) |
92 | 101 | ||
93 | dnl Determine the platform dependent parameters needed to use rpath: | 102 | dnl Determine the platform dependent parameters needed to use rpath: |
94 | dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator, | 103 | dnl acl_libext, |
95 | dnl hardcode_direct, hardcode_minus_L. | 104 | dnl acl_shlibext, |
105 | dnl acl_hardcode_libdir_flag_spec, | ||
106 | dnl acl_hardcode_libdir_separator, | ||
107 | dnl acl_hardcode_direct, | ||
108 | dnl acl_hardcode_minus_L. | ||
96 | AC_DEFUN([AC_LIB_RPATH], | 109 | AC_DEFUN([AC_LIB_RPATH], |
97 | [ | 110 | [ |
98 | dnl Tell automake >= 1.10 to complain if config.rpath is missing. | 111 | dnl Tell automake >= 1.10 to complain if config.rpath is missing. |
@@ -109,12 +122,14 @@ AC_DEFUN([AC_LIB_RPATH], | |||
109 | acl_cv_rpath=done | 122 | acl_cv_rpath=done |
110 | ]) | 123 | ]) |
111 | wl="$acl_cv_wl" | 124 | wl="$acl_cv_wl" |
112 | libext="$acl_cv_libext" | 125 | acl_libext="$acl_cv_libext" |
113 | shlibext="$acl_cv_shlibext" | 126 | acl_shlibext="$acl_cv_shlibext" |
114 | hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" | 127 | acl_libname_spec="$acl_cv_libname_spec" |
115 | hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" | 128 | acl_library_names_spec="$acl_cv_library_names_spec" |
116 | hardcode_direct="$acl_cv_hardcode_direct" | 129 | acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" |
117 | hardcode_minus_L="$acl_cv_hardcode_minus_L" | 130 | acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" |
131 | acl_hardcode_direct="$acl_cv_hardcode_direct" | ||
132 | acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" | ||
118 | dnl Determine whether the user wants rpath handling at all. | 133 | dnl Determine whether the user wants rpath handling at all. |
119 | AC_ARG_ENABLE(rpath, | 134 | AC_ARG_ENABLE(rpath, |
120 | [ --disable-rpath do not hardcode runtime library paths], | 135 | [ --disable-rpath do not hardcode runtime library paths], |
@@ -124,20 +139,24 @@ AC_DEFUN([AC_LIB_RPATH], | |||
124 | dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and | 139 | dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and |
125 | dnl the libraries corresponding to explicit and implicit dependencies. | 140 | dnl the libraries corresponding to explicit and implicit dependencies. |
126 | dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. | 141 | dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. |
142 | dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found | ||
143 | dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. | ||
127 | AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | 144 | AC_DEFUN([AC_LIB_LINKFLAGS_BODY], |
128 | [ | 145 | [ |
129 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) | 146 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) |
130 | define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], | 147 | define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], |
131 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 148 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) |
149 | dnl Autoconf >= 2.61 supports dots in --with options. | ||
150 | define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])]) | ||
132 | dnl By default, look in $includedir and $libdir. | 151 | dnl By default, look in $includedir and $libdir. |
133 | use_additional=yes | 152 | use_additional=yes |
134 | AC_LIB_WITH_FINAL_PREFIX([ | 153 | AC_LIB_WITH_FINAL_PREFIX([ |
135 | eval additional_includedir=\"$includedir\" | 154 | eval additional_includedir=\"$includedir\" |
136 | eval additional_libdir=\"$libdir\" | 155 | eval additional_libdir=\"$libdir\" |
137 | ]) | 156 | ]) |
138 | AC_LIB_ARG_WITH([lib$1-prefix], | 157 | AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix], |
139 | [ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib | 158 | [ --with-lib]N_A_M_E[-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib |
140 | --without-lib$1-prefix don't search for lib$1 in includedir and libdir], | 159 | --without-lib]N_A_M_E[-prefix don't search for lib$1 in includedir and libdir], |
141 | [ | 160 | [ |
142 | if test "X$withval" = "Xno"; then | 161 | if test "X$withval" = "Xno"; then |
143 | use_additional=no | 162 | use_additional=no |
@@ -158,6 +177,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
158 | LIB[]NAME= | 177 | LIB[]NAME= |
159 | LTLIB[]NAME= | 178 | LTLIB[]NAME= |
160 | INC[]NAME= | 179 | INC[]NAME= |
180 | LIB[]NAME[]_PREFIX= | ||
161 | rpathdirs= | 181 | rpathdirs= |
162 | ltrpathdirs= | 182 | ltrpathdirs= |
163 | names_already_handled= | 183 | names_already_handled= |
@@ -197,22 +217,55 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
197 | found_la= | 217 | found_la= |
198 | found_so= | 218 | found_so= |
199 | found_a= | 219 | found_a= |
220 | eval libname=\"$acl_libname_spec\" # typically: libname=lib$name | ||
221 | if test -n "$acl_shlibext"; then | ||
222 | shrext=".$acl_shlibext" # typically: shrext=.so | ||
223 | else | ||
224 | shrext= | ||
225 | fi | ||
200 | if test $use_additional = yes; then | 226 | if test $use_additional = yes; then |
201 | if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then | 227 | dir="$additional_libdir" |
202 | found_dir="$additional_libdir" | 228 | dnl The same code as in the loop below: |
203 | found_so="$additional_libdir/lib$name.$shlibext" | 229 | dnl First look for a shared library. |
204 | if test -f "$additional_libdir/lib$name.la"; then | 230 | if test -n "$acl_shlibext"; then |
205 | found_la="$additional_libdir/lib$name.la" | 231 | if test -f "$dir/$libname$shrext"; then |
206 | fi | 232 | found_dir="$dir" |
207 | else | 233 | found_so="$dir/$libname$shrext" |
208 | if test -f "$additional_libdir/lib$name.$libext"; then | 234 | else |
209 | found_dir="$additional_libdir" | 235 | if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then |
210 | found_a="$additional_libdir/lib$name.$libext" | 236 | ver=`(cd "$dir" && \ |
211 | if test -f "$additional_libdir/lib$name.la"; then | 237 | for f in "$libname$shrext".*; do echo "$f"; done \ |
212 | found_la="$additional_libdir/lib$name.la" | 238 | | sed -e "s,^$libname$shrext\\\\.,," \ |
239 | | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | ||
240 | | sed 1q ) 2>/dev/null` | ||
241 | if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then | ||
242 | found_dir="$dir" | ||
243 | found_so="$dir/$libname$shrext.$ver" | ||
244 | fi | ||
245 | else | ||
246 | eval library_names=\"$acl_library_names_spec\" | ||
247 | for f in $library_names; do | ||
248 | if test -f "$dir/$f"; then | ||
249 | found_dir="$dir" | ||
250 | found_so="$dir/$f" | ||
251 | break | ||
252 | fi | ||
253 | done | ||
213 | fi | 254 | fi |
214 | fi | 255 | fi |
215 | fi | 256 | fi |
257 | dnl Then look for a static library. | ||
258 | if test "X$found_dir" = "X"; then | ||
259 | if test -f "$dir/$libname.$acl_libext"; then | ||
260 | found_dir="$dir" | ||
261 | found_a="$dir/$libname.$acl_libext" | ||
262 | fi | ||
263 | fi | ||
264 | if test "X$found_dir" != "X"; then | ||
265 | if test -f "$dir/$libname.la"; then | ||
266 | found_la="$dir/$libname.la" | ||
267 | fi | ||
268 | fi | ||
216 | fi | 269 | fi |
217 | if test "X$found_dir" = "X"; then | 270 | if test "X$found_dir" = "X"; then |
218 | for x in $LDFLAGS $LTLIB[]NAME; do | 271 | for x in $LDFLAGS $LTLIB[]NAME; do |
@@ -220,21 +273,46 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
220 | case "$x" in | 273 | case "$x" in |
221 | -L*) | 274 | -L*) |
222 | dir=`echo "X$x" | sed -e 's/^X-L//'` | 275 | dir=`echo "X$x" | sed -e 's/^X-L//'` |
223 | if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then | 276 | dnl First look for a shared library. |
224 | found_dir="$dir" | 277 | if test -n "$acl_shlibext"; then |
225 | found_so="$dir/lib$name.$shlibext" | 278 | if test -f "$dir/$libname$shrext"; then |
226 | if test -f "$dir/lib$name.la"; then | ||
227 | found_la="$dir/lib$name.la" | ||
228 | fi | ||
229 | else | ||
230 | if test -f "$dir/lib$name.$libext"; then | ||
231 | found_dir="$dir" | 279 | found_dir="$dir" |
232 | found_a="$dir/lib$name.$libext" | 280 | found_so="$dir/$libname$shrext" |
233 | if test -f "$dir/lib$name.la"; then | 281 | else |
234 | found_la="$dir/lib$name.la" | 282 | if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then |
283 | ver=`(cd "$dir" && \ | ||
284 | for f in "$libname$shrext".*; do echo "$f"; done \ | ||
285 | | sed -e "s,^$libname$shrext\\\\.,," \ | ||
286 | | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | ||
287 | | sed 1q ) 2>/dev/null` | ||
288 | if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then | ||
289 | found_dir="$dir" | ||
290 | found_so="$dir/$libname$shrext.$ver" | ||
291 | fi | ||
292 | else | ||
293 | eval library_names=\"$acl_library_names_spec\" | ||
294 | for f in $library_names; do | ||
295 | if test -f "$dir/$f"; then | ||
296 | found_dir="$dir" | ||
297 | found_so="$dir/$f" | ||
298 | break | ||
299 | fi | ||
300 | done | ||
235 | fi | 301 | fi |
236 | fi | 302 | fi |
237 | fi | 303 | fi |
304 | dnl Then look for a static library. | ||
305 | if test "X$found_dir" = "X"; then | ||
306 | if test -f "$dir/$libname.$acl_libext"; then | ||
307 | found_dir="$dir" | ||
308 | found_a="$dir/$libname.$acl_libext" | ||
309 | fi | ||
310 | fi | ||
311 | if test "X$found_dir" != "X"; then | ||
312 | if test -f "$dir/$libname.la"; then | ||
313 | found_la="$dir/$libname.la" | ||
314 | fi | ||
315 | fi | ||
238 | ;; | 316 | ;; |
239 | esac | 317 | esac |
240 | if test "X$found_dir" != "X"; then | 318 | if test "X$found_dir" != "X"; then |
@@ -268,12 +346,12 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
268 | ltrpathdirs="$ltrpathdirs $found_dir" | 346 | ltrpathdirs="$ltrpathdirs $found_dir" |
269 | fi | 347 | fi |
270 | dnl The hardcoding into $LIBNAME is system dependent. | 348 | dnl The hardcoding into $LIBNAME is system dependent. |
271 | if test "$hardcode_direct" = yes; then | 349 | if test "$acl_hardcode_direct" = yes; then |
272 | dnl Using DIR/libNAME.so during linking hardcodes DIR into the | 350 | dnl Using DIR/libNAME.so during linking hardcodes DIR into the |
273 | dnl resulting binary. | 351 | dnl resulting binary. |
274 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" | 352 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" |
275 | else | 353 | else |
276 | if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then | 354 | if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then |
277 | dnl Use an explicit option to hardcode DIR into the resulting | 355 | dnl Use an explicit option to hardcode DIR into the resulting |
278 | dnl binary. | 356 | dnl binary. |
279 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" | 357 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" |
@@ -304,13 +382,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
304 | if test -z "$haveit"; then | 382 | if test -z "$haveit"; then |
305 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" | 383 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" |
306 | fi | 384 | fi |
307 | if test "$hardcode_minus_L" != no; then | 385 | if test "$acl_hardcode_minus_L" != no; then |
308 | dnl FIXME: Not sure whether we should use | 386 | dnl FIXME: Not sure whether we should use |
309 | dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" | 387 | dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" |
310 | dnl here. | 388 | dnl here. |
311 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" | 389 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" |
312 | else | 390 | else |
313 | dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH | 391 | dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH |
314 | dnl here, because this doesn't fit in flags passed to the | 392 | dnl here, because this doesn't fit in flags passed to the |
315 | dnl compiler. So give up. No hardcoding. This affects only | 393 | dnl compiler. So give up. No hardcoding. This affects only |
316 | dnl very old systems. | 394 | dnl very old systems. |
@@ -337,6 +415,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
337 | case "$found_dir" in | 415 | case "$found_dir" in |
338 | */$acl_libdirstem | */$acl_libdirstem/) | 416 | */$acl_libdirstem | */$acl_libdirstem/) |
339 | basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` | 417 | basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` |
418 | LIB[]NAME[]_PREFIX="$basedir" | ||
340 | additional_includedir="$basedir/include" | 419 | additional_includedir="$basedir/include" |
341 | ;; | 420 | ;; |
342 | esac | 421 | esac |
@@ -498,18 +577,18 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
498 | done | 577 | done |
499 | done | 578 | done |
500 | if test "X$rpathdirs" != "X"; then | 579 | if test "X$rpathdirs" != "X"; then |
501 | if test -n "$hardcode_libdir_separator"; then | 580 | if test -n "$acl_hardcode_libdir_separator"; then |
502 | dnl Weird platform: only the last -rpath option counts, the user must | 581 | dnl Weird platform: only the last -rpath option counts, the user must |
503 | dnl pass all path elements in one option. We can arrange that for a | 582 | dnl pass all path elements in one option. We can arrange that for a |
504 | dnl single library, but not when more than one $LIBNAMEs are used. | 583 | dnl single library, but not when more than one $LIBNAMEs are used. |
505 | alldirs= | 584 | alldirs= |
506 | for found_dir in $rpathdirs; do | 585 | for found_dir in $rpathdirs; do |
507 | alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir" | 586 | alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" |
508 | done | 587 | done |
509 | dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl. | 588 | dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. |
510 | acl_save_libdir="$libdir" | 589 | acl_save_libdir="$libdir" |
511 | libdir="$alldirs" | 590 | libdir="$alldirs" |
512 | eval flag=\"$hardcode_libdir_flag_spec\" | 591 | eval flag=\"$acl_hardcode_libdir_flag_spec\" |
513 | libdir="$acl_save_libdir" | 592 | libdir="$acl_save_libdir" |
514 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" | 593 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" |
515 | else | 594 | else |
@@ -517,7 +596,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
517 | for found_dir in $rpathdirs; do | 596 | for found_dir in $rpathdirs; do |
518 | acl_save_libdir="$libdir" | 597 | acl_save_libdir="$libdir" |
519 | libdir="$found_dir" | 598 | libdir="$found_dir" |
520 | eval flag=\"$hardcode_libdir_flag_spec\" | 599 | eval flag=\"$acl_hardcode_libdir_flag_spec\" |
521 | libdir="$acl_save_libdir" | 600 | libdir="$acl_save_libdir" |
522 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" | 601 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" |
523 | done | 602 | done |
@@ -552,3 +631,79 @@ AC_DEFUN([AC_LIB_APPENDTOVAR], | |||
552 | fi | 631 | fi |
553 | done | 632 | done |
554 | ]) | 633 | ]) |
634 | |||
635 | dnl For those cases where a variable contains several -L and -l options | ||
636 | dnl referring to unknown libraries and directories, this macro determines the | ||
637 | dnl necessary additional linker options for the runtime path. | ||
638 | dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) | ||
639 | dnl sets LDADDVAR to linker options needed together with LIBSVALUE. | ||
640 | dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, | ||
641 | dnl otherwise linking without libtool is assumed. | ||
642 | AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], | ||
643 | [ | ||
644 | AC_REQUIRE([AC_LIB_RPATH]) | ||
645 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) | ||
646 | $1= | ||
647 | if test "$enable_rpath" != no; then | ||
648 | if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then | ||
649 | dnl Use an explicit option to hardcode directories into the resulting | ||
650 | dnl binary. | ||
651 | rpathdirs= | ||
652 | next= | ||
653 | for opt in $2; do | ||
654 | if test -n "$next"; then | ||
655 | dir="$next" | ||
656 | dnl No need to hardcode the standard /usr/lib. | ||
657 | if test "X$dir" != "X/usr/$acl_libdirstem"; then | ||
658 | rpathdirs="$rpathdirs $dir" | ||
659 | fi | ||
660 | next= | ||
661 | else | ||
662 | case $opt in | ||
663 | -L) next=yes ;; | ||
664 | -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` | ||
665 | dnl No need to hardcode the standard /usr/lib. | ||
666 | if test "X$dir" != "X/usr/$acl_libdirstem"; then | ||
667 | rpathdirs="$rpathdirs $dir" | ||
668 | fi | ||
669 | next= ;; | ||
670 | *) next= ;; | ||
671 | esac | ||
672 | fi | ||
673 | done | ||
674 | if test "X$rpathdirs" != "X"; then | ||
675 | if test -n ""$3""; then | ||
676 | dnl libtool is used for linking. Use -R options. | ||
677 | for dir in $rpathdirs; do | ||
678 | $1="${$1}${$1:+ }-R$dir" | ||
679 | done | ||
680 | else | ||
681 | dnl The linker is used for linking directly. | ||
682 | if test -n "$acl_hardcode_libdir_separator"; then | ||
683 | dnl Weird platform: only the last -rpath option counts, the user | ||
684 | dnl must pass all path elements in one option. | ||
685 | alldirs= | ||
686 | for dir in $rpathdirs; do | ||
687 | alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" | ||
688 | done | ||
689 | acl_save_libdir="$libdir" | ||
690 | libdir="$alldirs" | ||
691 | eval flag=\"$acl_hardcode_libdir_flag_spec\" | ||
692 | libdir="$acl_save_libdir" | ||
693 | $1="$flag" | ||
694 | else | ||
695 | dnl The -rpath options are cumulative. | ||
696 | for dir in $rpathdirs; do | ||
697 | acl_save_libdir="$libdir" | ||
698 | libdir="$dir" | ||
699 | eval flag=\"$acl_hardcode_libdir_flag_spec\" | ||
700 | libdir="$acl_save_libdir" | ||
701 | $1="${$1}${$1:+ }$flag" | ||
702 | done | ||
703 | fi | ||
704 | fi | ||
705 | fi | ||
706 | fi | ||
707 | fi | ||
708 | AC_SUBST([$1]) | ||
709 | ]) | ||
diff --git a/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4 index a8684e1..a8684e1 100644 --- a/m4/lib-prefix.m4 +++ b/gl/m4/lib-prefix.m4 | |||
diff --git a/gl/m4/lock.m4 b/gl/m4/lock.m4 new file mode 100644 index 0000000..0224f2f --- /dev/null +++ b/gl/m4/lock.m4 | |||
@@ -0,0 +1,311 @@ | |||
1 | # lock.m4 serial 6 (gettext-0.16) | ||
2 | dnl Copyright (C) 2005-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | dnl Tests for a multithreading library to be used. | ||
10 | dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, | ||
11 | dnl USE_PTH_THREADS, USE_WIN32_THREADS | ||
12 | dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use | ||
13 | dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with | ||
14 | dnl libtool). | ||
15 | dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for | ||
16 | dnl programs that really need multithread functionality. The difference | ||
17 | dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak | ||
18 | dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". | ||
19 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for | ||
20 | dnl multithread-safe programs. | ||
21 | |||
22 | AC_DEFUN([gl_LOCK_EARLY], | ||
23 | [ | ||
24 | AC_REQUIRE([gl_LOCK_EARLY_BODY]) | ||
25 | ]) | ||
26 | |||
27 | dnl The guts of gl_LOCK_EARLY. Needs to be expanded only once. | ||
28 | |||
29 | AC_DEFUN([gl_LOCK_EARLY_BODY], | ||
30 | [ | ||
31 | dnl Ordering constraints: This macro modifies CPPFLAGS in a way that | ||
32 | dnl influences the result of the autoconf tests that test for *_unlocked | ||
33 | dnl declarations, on AIX 5 at least. Therefore it must come early. | ||
34 | AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl | ||
35 | AC_BEFORE([$0], [gl_ARGP])dnl | ||
36 | |||
37 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
38 | AC_REQUIRE([AC_GNU_SOURCE]) dnl needed for pthread_rwlock_t on glibc systems | ||
39 | dnl Check for multithreading. | ||
40 | AC_ARG_ENABLE(threads, | ||
41 | AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) | ||
42 | AC_HELP_STRING([--disable-threads], [build without multithread safety]), | ||
43 | [gl_use_threads=$enableval], | ||
44 | [case "$host_os" in | ||
45 | dnl Disable multithreading by default on OSF/1, because it interferes | ||
46 | dnl with fork()/exec(): When msgexec is linked with -lpthread, its child | ||
47 | dnl process gets an endless segmentation fault inside execvp(). | ||
48 | osf*) gl_use_threads=no ;; | ||
49 | *) gl_use_threads=yes ;; | ||
50 | esac | ||
51 | ]) | ||
52 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then | ||
53 | # For using <pthread.h>: | ||
54 | case "$host_os" in | ||
55 | osf*) | ||
56 | # On OSF/1, the compiler needs the flag -D_REENTRANT so that it | ||
57 | # groks <pthread.h>. cc also understands the flag -pthread, but | ||
58 | # we don't use it because 1. gcc-2.95 doesn't understand -pthread, | ||
59 | # 2. putting a flag into CPPFLAGS that has an effect on the linker | ||
60 | # causes the AC_TRY_LINK test below to succeed unexpectedly, | ||
61 | # leading to wrong values of LIBTHREAD and LTLIBTHREAD. | ||
62 | CPPFLAGS="$CPPFLAGS -D_REENTRANT" | ||
63 | ;; | ||
64 | esac | ||
65 | # Some systems optimize for single-threaded programs by default, and | ||
66 | # need special flags to disable these optimizations. For example, the | ||
67 | # definition of 'errno' in <errno.h>. | ||
68 | case "$host_os" in | ||
69 | aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; | ||
70 | solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; | ||
71 | esac | ||
72 | fi | ||
73 | ]) | ||
74 | |||
75 | dnl The guts of gl_LOCK. Needs to be expanded only once. | ||
76 | |||
77 | AC_DEFUN([gl_LOCK_BODY], | ||
78 | [ | ||
79 | AC_REQUIRE([gl_LOCK_EARLY_BODY]) | ||
80 | gl_threads_api=none | ||
81 | LIBTHREAD= | ||
82 | LTLIBTHREAD= | ||
83 | LIBMULTITHREAD= | ||
84 | LTLIBMULTITHREAD= | ||
85 | if test "$gl_use_threads" != no; then | ||
86 | dnl Check whether the compiler and linker support weak declarations. | ||
87 | AC_MSG_CHECKING([whether imported symbols can be declared weak]) | ||
88 | gl_have_weak=no | ||
89 | AC_TRY_LINK([extern void xyzzy (); | ||
90 | #pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes]) | ||
91 | AC_MSG_RESULT([$gl_have_weak]) | ||
92 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then | ||
93 | # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that | ||
94 | # it groks <pthread.h>. It's added above, in gl_LOCK_EARLY_BODY. | ||
95 | AC_CHECK_HEADER(pthread.h, gl_have_pthread_h=yes, gl_have_pthread_h=no) | ||
96 | if test "$gl_have_pthread_h" = yes; then | ||
97 | # Other possible tests: | ||
98 | # -lpthreads (FSU threads, PCthreads) | ||
99 | # -lgthreads | ||
100 | gl_have_pthread= | ||
101 | # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist | ||
102 | # in libc. IRIX 6.5 has the first one in both libc and libpthread, but | ||
103 | # the second one only in libpthread, and lock.c needs it. | ||
104 | AC_TRY_LINK([#include <pthread.h>], | ||
105 | [pthread_mutex_lock((pthread_mutex_t*)0); | ||
106 | pthread_mutexattr_init((pthread_mutexattr_t*)0);], | ||
107 | [gl_have_pthread=yes]) | ||
108 | # Test for libpthread by looking for pthread_kill. (Not pthread_self, | ||
109 | # since it is defined as a macro on OSF/1.) | ||
110 | if test -n "$gl_have_pthread"; then | ||
111 | # The program links fine without libpthread. But it may actually | ||
112 | # need to link with libpthread in order to create multiple threads. | ||
113 | AC_CHECK_LIB(pthread, pthread_kill, | ||
114 | [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread | ||
115 | # On Solaris and HP-UX, most pthread functions exist also in libc. | ||
116 | # Therefore pthread_in_use() needs to actually try to create a | ||
117 | # thread: pthread_create from libc will fail, whereas | ||
118 | # pthread_create will actually create a thread. | ||
119 | case "$host_os" in | ||
120 | solaris* | hpux*) | ||
121 | AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1, | ||
122 | [Define if the pthread_in_use() detection is hard.]) | ||
123 | esac | ||
124 | ]) | ||
125 | else | ||
126 | # Some library is needed. Try libpthread and libc_r. | ||
127 | AC_CHECK_LIB(pthread, pthread_kill, | ||
128 | [gl_have_pthread=yes | ||
129 | LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread | ||
130 | LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) | ||
131 | if test -z "$gl_have_pthread"; then | ||
132 | # For FreeBSD 4. | ||
133 | AC_CHECK_LIB(c_r, pthread_kill, | ||
134 | [gl_have_pthread=yes | ||
135 | LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r | ||
136 | LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r]) | ||
137 | fi | ||
138 | fi | ||
139 | if test -n "$gl_have_pthread"; then | ||
140 | gl_threads_api=posix | ||
141 | AC_DEFINE([USE_POSIX_THREADS], 1, | ||
142 | [Define if the POSIX multithreading library can be used.]) | ||
143 | if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then | ||
144 | if test $gl_have_weak = yes; then | ||
145 | AC_DEFINE([USE_POSIX_THREADS_WEAK], 1, | ||
146 | [Define if references to the POSIX multithreading library should be made weak.]) | ||
147 | LIBTHREAD= | ||
148 | LTLIBTHREAD= | ||
149 | fi | ||
150 | fi | ||
151 | # OSF/1 4.0 and MacOS X 10.1 lack the pthread_rwlock_t type and the | ||
152 | # pthread_rwlock_* functions. | ||
153 | AC_CHECK_TYPE([pthread_rwlock_t], | ||
154 | [AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1, | ||
155 | [Define if the POSIX multithreading library has read/write locks.])], | ||
156 | [], | ||
157 | [#include <pthread.h>]) | ||
158 | # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. | ||
159 | AC_TRY_COMPILE([#include <pthread.h>], | ||
160 | [#if __FreeBSD__ == 4 | ||
161 | error "No, in FreeBSD 4.0 recursive mutexes actually don't work." | ||
162 | #else | ||
163 | int x = (int)PTHREAD_MUTEX_RECURSIVE; | ||
164 | return !x; | ||
165 | #endif], | ||
166 | [AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1, | ||
167 | [Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE.])]) | ||
168 | fi | ||
169 | fi | ||
170 | fi | ||
171 | if test -z "$gl_have_pthread"; then | ||
172 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then | ||
173 | gl_have_solaristhread= | ||
174 | gl_save_LIBS="$LIBS" | ||
175 | LIBS="$LIBS -lthread" | ||
176 | AC_TRY_LINK([#include <thread.h> | ||
177 | #include <synch.h>], | ||
178 | [thr_self();], | ||
179 | [gl_have_solaristhread=yes]) | ||
180 | LIBS="$gl_save_LIBS" | ||
181 | if test -n "$gl_have_solaristhread"; then | ||
182 | gl_threads_api=solaris | ||
183 | LIBTHREAD=-lthread | ||
184 | LTLIBTHREAD=-lthread | ||
185 | LIBMULTITHREAD="$LIBTHREAD" | ||
186 | LTLIBMULTITHREAD="$LTLIBTHREAD" | ||
187 | AC_DEFINE([USE_SOLARIS_THREADS], 1, | ||
188 | [Define if the old Solaris multithreading library can be used.]) | ||
189 | if test $gl_have_weak = yes; then | ||
190 | AC_DEFINE([USE_SOLARIS_THREADS_WEAK], 1, | ||
191 | [Define if references to the old Solaris multithreading library should be made weak.]) | ||
192 | LIBTHREAD= | ||
193 | LTLIBTHREAD= | ||
194 | fi | ||
195 | fi | ||
196 | fi | ||
197 | fi | ||
198 | if test "$gl_use_threads" = pth; then | ||
199 | gl_save_CPPFLAGS="$CPPFLAGS" | ||
200 | AC_LIB_LINKFLAGS(pth) | ||
201 | gl_have_pth= | ||
202 | gl_save_LIBS="$LIBS" | ||
203 | LIBS="$LIBS -lpth" | ||
204 | AC_TRY_LINK([#include <pth.h>], [pth_self();], gl_have_pth=yes) | ||
205 | LIBS="$gl_save_LIBS" | ||
206 | if test -n "$gl_have_pth"; then | ||
207 | gl_threads_api=pth | ||
208 | LIBTHREAD="$LIBPTH" | ||
209 | LTLIBTHREAD="$LTLIBPTH" | ||
210 | LIBMULTITHREAD="$LIBTHREAD" | ||
211 | LTLIBMULTITHREAD="$LTLIBTHREAD" | ||
212 | AC_DEFINE([USE_PTH_THREADS], 1, | ||
213 | [Define if the GNU Pth multithreading library can be used.]) | ||
214 | if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then | ||
215 | if test $gl_have_weak = yes; then | ||
216 | AC_DEFINE([USE_PTH_THREADS_WEAK], 1, | ||
217 | [Define if references to the GNU Pth multithreading library should be made weak.]) | ||
218 | LIBTHREAD= | ||
219 | LTLIBTHREAD= | ||
220 | fi | ||
221 | fi | ||
222 | else | ||
223 | CPPFLAGS="$gl_save_CPPFLAGS" | ||
224 | fi | ||
225 | fi | ||
226 | if test -z "$gl_have_pthread"; then | ||
227 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then | ||
228 | if { case "$host_os" in | ||
229 | mingw*) true;; | ||
230 | *) false;; | ||
231 | esac | ||
232 | }; then | ||
233 | gl_threads_api=win32 | ||
234 | AC_DEFINE([USE_WIN32_THREADS], 1, | ||
235 | [Define if the Win32 multithreading API can be used.]) | ||
236 | fi | ||
237 | fi | ||
238 | fi | ||
239 | fi | ||
240 | AC_MSG_CHECKING([for multithread API to use]) | ||
241 | AC_MSG_RESULT([$gl_threads_api]) | ||
242 | AC_SUBST(LIBTHREAD) | ||
243 | AC_SUBST(LTLIBTHREAD) | ||
244 | AC_SUBST(LIBMULTITHREAD) | ||
245 | AC_SUBST(LTLIBMULTITHREAD) | ||
246 | ]) | ||
247 | |||
248 | AC_DEFUN([gl_LOCK], | ||
249 | [ | ||
250 | AC_REQUIRE([gl_LOCK_EARLY]) | ||
251 | AC_REQUIRE([gl_LOCK_BODY]) | ||
252 | gl_PREREQ_LOCK | ||
253 | ]) | ||
254 | |||
255 | # Prerequisites of lib/lock.c. | ||
256 | AC_DEFUN([gl_PREREQ_LOCK], [ | ||
257 | AC_REQUIRE([AC_C_INLINE]) | ||
258 | ]) | ||
259 | |||
260 | dnl Survey of platforms: | ||
261 | dnl | ||
262 | dnl Platform Available Compiler Supports test-lock | ||
263 | dnl flavours option weak result | ||
264 | dnl --------------- --------- --------- -------- --------- | ||
265 | dnl Linux 2.4/glibc posix -lpthread Y OK | ||
266 | dnl | ||
267 | dnl GNU Hurd/glibc posix | ||
268 | dnl | ||
269 | dnl FreeBSD 5.3 posix -lc_r Y | ||
270 | dnl posix -lkse ? Y | ||
271 | dnl posix -lpthread ? Y | ||
272 | dnl posix -lthr Y | ||
273 | dnl | ||
274 | dnl FreeBSD 5.2 posix -lc_r Y | ||
275 | dnl posix -lkse Y | ||
276 | dnl posix -lthr Y | ||
277 | dnl | ||
278 | dnl FreeBSD 4.0,4.10 posix -lc_r Y OK | ||
279 | dnl | ||
280 | dnl NetBSD 1.6 -- | ||
281 | dnl | ||
282 | dnl OpenBSD 3.4 posix -lpthread Y OK | ||
283 | dnl | ||
284 | dnl MacOS X 10.[123] posix -lpthread Y OK | ||
285 | dnl | ||
286 | dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK | ||
287 | dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK | ||
288 | dnl | ||
289 | dnl HP-UX 11 posix -lpthread N (cc) OK | ||
290 | dnl Y (gcc) | ||
291 | dnl | ||
292 | dnl IRIX 6.5 posix -lpthread Y 0.5 | ||
293 | dnl | ||
294 | dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK | ||
295 | dnl | ||
296 | dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK | ||
297 | dnl -lpthread (gcc) Y | ||
298 | dnl | ||
299 | dnl Cygwin posix -lpthread Y OK | ||
300 | dnl | ||
301 | dnl Any of the above pth -lpth 0.0 | ||
302 | dnl | ||
303 | dnl Mingw win32 N OK | ||
304 | dnl | ||
305 | dnl BeOS 5 -- | ||
306 | dnl | ||
307 | dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is | ||
308 | dnl turned off: | ||
309 | dnl OK if all three tests terminate OK, | ||
310 | dnl 0.5 if the first test terminates OK but the second one loops endlessly, | ||
311 | dnl 0.0 if the first test already loops endlessly. | ||
diff --git a/m4/longdouble.m4 b/gl/m4/longdouble.m4 index 40cd7ce..25590f4 100644 --- a/m4/longdouble.m4 +++ b/gl/m4/longdouble.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # longdouble.m4 serial 1 (gettext-0.12) | 1 | # longdouble.m4 serial 2 (gettext-0.15) |
2 | dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -8,6 +8,9 @@ dnl From Bruno Haible. | |||
8 | dnl Test whether the compiler supports the 'long double' type. | 8 | dnl Test whether the compiler supports the 'long double' type. |
9 | dnl Prerequisite: AC_PROG_CC | 9 | dnl Prerequisite: AC_PROG_CC |
10 | 10 | ||
11 | dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf | ||
12 | dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics. | ||
13 | |||
11 | AC_DEFUN([gt_TYPE_LONGDOUBLE], | 14 | AC_DEFUN([gt_TYPE_LONGDOUBLE], |
12 | [ | 15 | [ |
13 | AC_CACHE_CHECK([for long double], gt_cv_c_long_double, | 16 | AC_CACHE_CHECK([for long double], gt_cv_c_long_double, |
diff --git a/gl/m4/longlong.m4 b/gl/m4/longlong.m4 new file mode 100644 index 0000000..1f9e862 --- /dev/null +++ b/gl/m4/longlong.m4 | |||
@@ -0,0 +1,72 @@ | |||
1 | # longlong.m4 serial 10 | ||
2 | dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | # Define HAVE_LONG_LONG_INT if 'long long int' works. | ||
10 | # This fixes a bug in Autoconf 2.60, but can be removed once we | ||
11 | # assume 2.61 everywhere. | ||
12 | |||
13 | # Note: If the type 'long long int' exists but is only 32 bits large | ||
14 | # (as on some very old compilers), HAVE_LONG_LONG_INT will not be | ||
15 | # defined. In this case you can treat 'long long int' like 'long int'. | ||
16 | |||
17 | AC_DEFUN([AC_TYPE_LONG_LONG_INT], | ||
18 | [ | ||
19 | AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], | ||
20 | [AC_LINK_IFELSE( | ||
21 | [AC_LANG_PROGRAM( | ||
22 | [[long long int ll = 9223372036854775807ll; | ||
23 | long long int nll = -9223372036854775807LL; | ||
24 | typedef int a[((-9223372036854775807LL < 0 | ||
25 | && 0 < 9223372036854775807ll) | ||
26 | ? 1 : -1)]; | ||
27 | int i = 63;]], | ||
28 | [[long long int llmax = 9223372036854775807ll; | ||
29 | return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) | ||
30 | | (llmax / ll) | (llmax % ll));]])], | ||
31 | [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. | ||
32 | dnl If cross compiling, assume the bug isn't important, since | ||
33 | dnl nobody cross compiles for this platform as far as we know. | ||
34 | AC_RUN_IFELSE( | ||
35 | [AC_LANG_PROGRAM( | ||
36 | [[@%:@include <limits.h> | ||
37 | @%:@ifndef LLONG_MAX | ||
38 | @%:@ define HALF \ | ||
39 | (1LL << (sizeof (long long int) * CHAR_BIT - 2)) | ||
40 | @%:@ define LLONG_MAX (HALF - 1 + HALF) | ||
41 | @%:@endif]], | ||
42 | [[long long int n = 1; | ||
43 | int i; | ||
44 | for (i = 0; ; i++) | ||
45 | { | ||
46 | long long int m = n << i; | ||
47 | if (m >> i != n) | ||
48 | return 1; | ||
49 | if (LLONG_MAX / 2 < m) | ||
50 | break; | ||
51 | } | ||
52 | return 0;]])], | ||
53 | [ac_cv_type_long_long_int=yes], | ||
54 | [ac_cv_type_long_long_int=no], | ||
55 | [ac_cv_type_long_long_int=yes])], | ||
56 | [ac_cv_type_long_long_int=no])]) | ||
57 | if test $ac_cv_type_long_long_int = yes; then | ||
58 | AC_DEFINE([HAVE_LONG_LONG_INT], 1, | ||
59 | [Define to 1 if the system has the type `long long int'.]) | ||
60 | fi | ||
61 | ]) | ||
62 | |||
63 | # This macro is obsolescent and should go away soon. | ||
64 | AC_DEFUN([gl_AC_TYPE_LONG_LONG], | ||
65 | [ | ||
66 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | ||
67 | ac_cv_type_long_long=$ac_cv_type_long_long_int | ||
68 | if test $ac_cv_type_long_long = yes; then | ||
69 | AC_DEFINE(HAVE_LONG_LONG, 1, | ||
70 | [Define if you have the 'long long' type.]) | ||
71 | fi | ||
72 | ]) | ||
diff --git a/m4/ls-mntd-fs.m4 b/gl/m4/ls-mntd-fs.m4 index a4c8089..21ac4e7 100644 --- a/m4/ls-mntd-fs.m4 +++ b/gl/m4/ls-mntd-fs.m4 | |||
@@ -1,4 +1,4 @@ | |||
1 | #serial 21 | 1 | #serial 26 |
2 | # How to list mounted file systems. | 2 | # How to list mounted file systems. |
3 | 3 | ||
4 | # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software | 4 | # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software |
@@ -28,7 +28,7 @@ AC_CHECK_FUNCS(getmntent) | |||
28 | AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS], | 28 | AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS], |
29 | [ | 29 | [ |
30 | AC_CHECK_FUNCS(listmntent getmntinfo) | 30 | AC_CHECK_FUNCS(listmntent getmntinfo) |
31 | AC_CHECK_HEADERS_ONCE(sys/param.h) | 31 | AC_CHECK_HEADERS_ONCE(sys/param.h sys/statvfs.h) |
32 | 32 | ||
33 | # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses | 33 | # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses |
34 | # NGROUPS (as the array dimension for a struct member) without a definition. | 34 | # NGROUPS (as the array dimension for a struct member) without a definition. |
@@ -141,7 +141,8 @@ if test $ac_cv_func_getmntent = yes; then | |||
141 | # endif | 141 | # endif |
142 | #endif | 142 | #endif |
143 | ], | 143 | ], |
144 | [ struct mntent *mnt = 0; char *table = MOUNTED; ], | 144 | [ struct mntent *mnt = 0; char *table = MOUNTED; |
145 | if (sizeof mnt && sizeof table) return 0;], | ||
145 | fu_cv_sys_mounted_getmntent1=yes, | 146 | fu_cv_sys_mounted_getmntent1=yes, |
146 | fu_cv_sys_mounted_getmntent1=no)]) | 147 | fu_cv_sys_mounted_getmntent1=no)]) |
147 | AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1) | 148 | AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1) |
@@ -167,6 +168,7 @@ if test $ac_cv_func_getmntent = yes; then | |||
167 | AC_DEFINE(MOUNTED_GETMNTENT2, 1, | 168 | AC_DEFINE(MOUNTED_GETMNTENT2, 1, |
168 | [Define if there is a function named getmntent for reading the list of | 169 | [Define if there is a function named getmntent for reading the list of |
169 | mounted file systems, and that function takes two arguments. (SVR4)]) | 170 | mounted file systems, and that function takes two arguments. (SVR4)]) |
171 | AC_CHECK_FUNCS(hasmntopt) | ||
170 | fi | 172 | fi |
171 | fi | 173 | fi |
172 | 174 | ||
@@ -232,10 +234,39 @@ if test -z "$ac_list_mounted_fs"; then | |||
232 | ]) | 234 | ]) |
233 | AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo) | 235 | AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo) |
234 | if test $fu_cv_sys_mounted_getmntinfo = yes; then | 236 | if test $fu_cv_sys_mounted_getmntinfo = yes; then |
235 | ac_list_mounted_fs=found | 237 | AC_MSG_CHECKING([whether getmntinfo returns statvfs structures]) |
236 | AC_DEFINE(MOUNTED_GETMNTINFO, 1, | 238 | AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo2, |
237 | [Define if there is a function named getmntinfo for reading the | 239 | [ |
238 | list of mounted file systems. (4.4BSD, Darwin)]) | 240 | AC_TRY_COMPILE([ |
241 | #if HAVE_SYS_PARAM_H | ||
242 | # include <sys/param.h> | ||
243 | #endif | ||
244 | #include <sys/types.h> | ||
245 | #if HAVE_SYS_MOUNT_H | ||
246 | # include <sys/mount.h> | ||
247 | #endif | ||
248 | #if HAVE_SYS_STATVFS_H | ||
249 | # include <sys/statvfs.h> | ||
250 | #endif | ||
251 | extern int getmntinfo (struct statfs **, int); | ||
252 | ], [], | ||
253 | [fu_cv_sys_mounted_getmntinfo2=no], | ||
254 | [fu_cv_sys_mounted_getmntinfo2=yes]) | ||
255 | ]) | ||
256 | AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2]) | ||
257 | if test $fu_cv_sys_mounted_getmntinfo2 = no; then | ||
258 | ac_list_mounted_fs=found | ||
259 | AC_DEFINE(MOUNTED_GETMNTINFO, 1, | ||
260 | [Define if there is a function named getmntinfo for reading the | ||
261 | list of mounted file systems and it returns an array of | ||
262 | 'struct statfs'. (4.4BSD, Darwin)]) | ||
263 | else | ||
264 | ac_list_mounted_fs=found | ||
265 | AC_DEFINE(MOUNTED_GETMNTINFO2, 1, | ||
266 | [Define if there is a function named getmntinfo for reading the | ||
267 | list of mounted file systems and it returns an array of | ||
268 | 'struct statvfs'. (NetBSD 3.0)]) | ||
269 | fi | ||
239 | fi | 270 | fi |
240 | fi | 271 | fi |
241 | 272 | ||
diff --git a/gl/m4/mbchar.m4 b/gl/m4/mbchar.m4 new file mode 100644 index 0000000..5380941 --- /dev/null +++ b/gl/m4/mbchar.m4 | |||
@@ -0,0 +1,14 @@ | |||
1 | # mbchar.m4 serial 5 | ||
2 | dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl autoconf tests required for use of mbchar.m4 | ||
8 | dnl From Bruno Haible. | ||
9 | |||
10 | AC_DEFUN([gl_MBCHAR], | ||
11 | [ | ||
12 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
13 | AC_LIBOBJ([mbchar]) | ||
14 | ]) | ||
diff --git a/gl/m4/mbiter.m4 b/gl/m4/mbiter.m4 new file mode 100644 index 0000000..7d51af1 --- /dev/null +++ b/gl/m4/mbiter.m4 | |||
@@ -0,0 +1,17 @@ | |||
1 | # mbiter.m4 serial 2 | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl autoconf tests required for use of mbiter.h | ||
8 | dnl From Bruno Haible. | ||
9 | |||
10 | AC_DEFUN([gl_MBITER], | ||
11 | [ | ||
12 | AC_REQUIRE([AC_TYPE_MBSTATE_T]) | ||
13 | dnl The following line is that so the user can test HAVE_MBRTOWC before | ||
14 | dnl #include "mbiter.h" or "mbuiter.h". | ||
15 | AC_REQUIRE([gl_FUNC_MBRTOWC]) | ||
16 | : | ||
17 | ]) | ||
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4 new file mode 100644 index 0000000..a3bd911 --- /dev/null +++ b/gl/m4/mbrtowc.m4 | |||
@@ -0,0 +1,31 @@ | |||
1 | # mbrtowc.m4 serial 8 | ||
2 | dnl Copyright (C) 2001-2002, 2004-2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert | ||
8 | |||
9 | dnl This file can be removed, and gl_FUNC_MBRTOWC replaced with | ||
10 | dnl AC_FUNC_MBRTOWC, when autoconf 2.60 can be assumed everywhere. | ||
11 | |||
12 | AC_DEFUN([gl_FUNC_MBRTOWC], | ||
13 | [ | ||
14 | dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. | ||
15 | AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], | ||
16 | gl_cv_func_mbrtowc, | ||
17 | [AC_LINK_IFELSE( | ||
18 | [AC_LANG_PROGRAM( | ||
19 | [[#include <wchar.h>]], | ||
20 | [[wchar_t wc; | ||
21 | char const s[] = ""; | ||
22 | size_t n = 1; | ||
23 | mbstate_t state; | ||
24 | return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], | ||
25 | gl_cv_func_mbrtowc=yes, | ||
26 | gl_cv_func_mbrtowc=no)]) | ||
27 | if test $gl_cv_func_mbrtowc = yes; then | ||
28 | AC_DEFINE([HAVE_MBRTOWC], 1, | ||
29 | [Define to 1 if mbrtowc and mbstate_t are properly declared.]) | ||
30 | fi | ||
31 | ]) | ||
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4 new file mode 100644 index 0000000..91b8636 --- /dev/null +++ b/gl/m4/memchr.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # memchr.m4 serial 4 | ||
2 | dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_MEMCHR], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(memchr) | ||
10 | if test $ac_cv_func_memchr = no; then | ||
11 | gl_PREREQ_MEMCHR | ||
12 | fi | ||
13 | ]) | ||
14 | |||
15 | # Prerequisites of lib/memchr.c. | ||
16 | AC_DEFUN([gl_PREREQ_MEMCHR], [ | ||
17 | AC_CHECK_HEADERS(bp-sym.h) | ||
18 | ]) | ||
diff --git a/gl/m4/minmax.m4 b/gl/m4/minmax.m4 new file mode 100644 index 0000000..bbd1ba0 --- /dev/null +++ b/gl/m4/minmax.m4 | |||
@@ -0,0 +1,41 @@ | |||
1 | # minmax.m4 serial 2 | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_PREREQ(2.52) | ||
8 | |||
9 | AC_DEFUN([gl_MINMAX], | ||
10 | [ | ||
11 | AC_REQUIRE([gl_PREREQ_MINMAX]) | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/minmax.h. | ||
15 | AC_DEFUN([gl_PREREQ_MINMAX], | ||
16 | [ | ||
17 | gl_MINMAX_IN_HEADER([limits.h]) | ||
18 | gl_MINMAX_IN_HEADER([sys/param.h]) | ||
19 | ]) | ||
20 | |||
21 | dnl gl_MINMAX_IN_HEADER(HEADER) | ||
22 | dnl The parameter has to be a literal header name; it cannot be macro, | ||
23 | dnl nor a shell variable. (Because autoheader collects only AC_DEFINE | ||
24 | dnl invocations with a literal macro name.) | ||
25 | AC_DEFUN([gl_MINMAX_IN_HEADER], | ||
26 | [ | ||
27 | m4_pushdef([header], AS_TR_SH([$1])) | ||
28 | m4_pushdef([HEADER], AS_TR_CPP([$1])) | ||
29 | AC_CACHE_CHECK([whether <$1> defines MIN and MAX], | ||
30 | [gl_cv_minmax_in_]header, | ||
31 | [AC_TRY_COMPILE([#include <$1> | ||
32 | int x = MIN (42, 17);], [], | ||
33 | [gl_cv_minmax_in_]header[=yes], | ||
34 | [gl_cv_minmax_in_]header[=no])]) | ||
35 | if test $gl_cv_minmax_in_[]header = yes; then | ||
36 | AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1, | ||
37 | [Define to 1 if <$1> defines the MIN and MAX macros.]) | ||
38 | fi | ||
39 | m4_popdef([HEADER]) | ||
40 | m4_popdef([header]) | ||
41 | ]) | ||
diff --git a/m4/mountlist.m4 b/gl/m4/mountlist.m4 index b2a2e12..c25f44e 100644 --- a/m4/mountlist.m4 +++ b/gl/m4/mountlist.m4 | |||
@@ -1,13 +1,11 @@ | |||
1 | #serial 8 | 1 | #serial 9 |
2 | dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | AC_DEFUN([gl_MOUNTLIST], | 7 | AC_DEFUN([gl_MOUNTLIST], |
8 | [ | 8 | [ |
9 | AC_LIBSOURCES([mountlist.c, mountlist.h]) | ||
10 | |||
11 | gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], | 9 | gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], |
12 | [gl_cv_list_mounted_fs=no]) | 10 | [gl_cv_list_mounted_fs=no]) |
13 | if test $gl_cv_list_mounted_fs = yes; then | 11 | if test $gl_cv_list_mounted_fs = yes; then |
diff --git a/gl/m4/netinet_in_h.m4 b/gl/m4/netinet_in_h.m4 new file mode 100644 index 0000000..d73531a --- /dev/null +++ b/gl/m4/netinet_in_h.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # netinet_in_h.m4 serial 1 | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl Written by Simon Josefsson | ||
8 | |||
9 | AC_DEFUN([gl_HEADER_NETINET_IN], | ||
10 | [ | ||
11 | AC_CHECK_HEADERS_ONCE([netinet/in.h]) | ||
12 | if test $ac_cv_header_netinet_in_h = yes; then | ||
13 | NETINET_IN_H='' | ||
14 | else | ||
15 | NETINET_IN_H='netinet/in.h' | ||
16 | fi | ||
17 | AC_SUBST(NETINET_IN_H) | ||
18 | ]) | ||
@@ -1,5 +1,5 @@ | |||
1 | # nls.m4 serial 2 (gettext-0.14.3) | 1 | # nls.m4 serial 3 (gettext-0.15) |
2 | dnl Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1995-2003, 2005-2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -29,23 +29,3 @@ AC_DEFUN([AM_NLS], | |||
29 | AC_MSG_RESULT($USE_NLS) | 29 | AC_MSG_RESULT($USE_NLS) |
30 | AC_SUBST(USE_NLS) | 30 | AC_SUBST(USE_NLS) |
31 | ]) | 31 | ]) |
32 | |||
33 | AC_DEFUN([AM_MKINSTALLDIRS], | ||
34 | [ | ||
35 | dnl Tell automake >= 1.10 to complain if mkinstalldirs is missing. | ||
36 | m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([mkinstalldirs])]) | ||
37 | dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly | ||
38 | dnl find the mkinstalldirs script in another subdir but $(top_srcdir). | ||
39 | dnl Try to locate it. | ||
40 | MKINSTALLDIRS= | ||
41 | if test -n "$ac_aux_dir"; then | ||
42 | case "$ac_aux_dir" in | ||
43 | /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;; | ||
44 | *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;; | ||
45 | esac | ||
46 | fi | ||
47 | if test -z "$MKINSTALLDIRS"; then | ||
48 | MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs" | ||
49 | fi | ||
50 | AC_SUBST(MKINSTALLDIRS) | ||
51 | ]) | ||
diff --git a/m4/onceonly_2_57.m4 b/gl/m4/onceonly_2_57.m4 index 14d3c0b..15884b3 100644 --- a/m4/onceonly_2_57.m4 +++ b/gl/m4/onceonly_2_57.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # onceonly_2_57.m4 serial 3 | 1 | # onceonly_2_57.m4 serial 4 |
2 | dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. |
3 | dnl This file is free software, distributed under the terms of the GNU | 3 | dnl This file is free software, distributed under the terms of the GNU |
4 | dnl General Public License. As a special exception to the GNU General | 4 | dnl General Public License. As a special exception to the GNU General |
5 | dnl Public License, this file may be distributed as part of a program | 5 | 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 | |||
7 | dnl the same distribution terms as the rest of that program. | 7 | dnl the same distribution terms as the rest of that program. |
8 | 8 | ||
9 | dnl This file defines some "once only" variants of standard autoconf macros. | 9 | dnl This file defines some "once only" variants of standard autoconf macros. |
10 | dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS | 10 | dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS |
11 | dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS | 11 | dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS |
12 | dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS | 12 | dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS |
13 | dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC | 13 | dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL |
14 | dnl The advantage is that the check for each of the headers/functions/decls | 14 | dnl The advantage is that the check for each of the headers/functions/decls |
15 | dnl will be put only once into the 'configure' file. It keeps the size of | 15 | dnl will be put only once into the 'configure' file. It keeps the size of |
16 | dnl the 'configure' file down, and avoids redundant output when 'configure' | 16 | dnl the 'configure' file down, and avoids redundant output when 'configure' |
@@ -1,5 +1,5 @@ | |||
1 | # po.m4 serial 7 (gettext-0.14.3) | 1 | # po.m4 serial 13 (gettext-0.15) |
2 | dnl Copyright (C) 1995-2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -24,7 +24,7 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
24 | [ | 24 | [ |
25 | AC_REQUIRE([AC_PROG_MAKE_SET])dnl | 25 | AC_REQUIRE([AC_PROG_MAKE_SET])dnl |
26 | AC_REQUIRE([AC_PROG_INSTALL])dnl | 26 | AC_REQUIRE([AC_PROG_INSTALL])dnl |
27 | AC_REQUIRE([AM_MKINSTALLDIRS])dnl | 27 | AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake |
28 | AC_REQUIRE([AM_NLS])dnl | 28 | AC_REQUIRE([AM_NLS])dnl |
29 | 29 | ||
30 | dnl Perform the following tests also if --disable-nls has been given, | 30 | dnl Perform the following tests also if --disable-nls has been given, |
@@ -39,6 +39,22 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
39 | :) | 39 | :) |
40 | AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) | 40 | AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) |
41 | 41 | ||
42 | dnl Test whether it is GNU msgfmt >= 0.15. | ||
43 | changequote(,)dnl | ||
44 | case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in | ||
45 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; | ||
46 | *) MSGFMT_015=$MSGFMT ;; | ||
47 | esac | ||
48 | changequote([,])dnl | ||
49 | AC_SUBST([MSGFMT_015]) | ||
50 | changequote(,)dnl | ||
51 | case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in | ||
52 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; | ||
53 | *) GMSGFMT_015=$GMSGFMT ;; | ||
54 | esac | ||
55 | changequote([,])dnl | ||
56 | AC_SUBST([GMSGFMT_015]) | ||
57 | |||
42 | dnl Search for GNU xgettext 0.12 or newer in the PATH. | 58 | dnl Search for GNU xgettext 0.12 or newer in the PATH. |
43 | dnl The first test excludes Solaris xgettext and early GNU xgettext versions. | 59 | dnl The first test excludes Solaris xgettext and early GNU xgettext versions. |
44 | dnl The second test excludes FreeBSD xgettext. | 60 | dnl The second test excludes FreeBSD xgettext. |
@@ -49,44 +65,26 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
49 | dnl Remove leftover from FreeBSD xgettext call. | 65 | dnl Remove leftover from FreeBSD xgettext call. |
50 | rm -f messages.po | 66 | rm -f messages.po |
51 | 67 | ||
68 | dnl Test whether it is GNU xgettext >= 0.15. | ||
69 | changequote(,)dnl | ||
70 | case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in | ||
71 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; | ||
72 | *) XGETTEXT_015=$XGETTEXT ;; | ||
73 | esac | ||
74 | changequote([,])dnl | ||
75 | AC_SUBST([XGETTEXT_015]) | ||
76 | |||
52 | dnl Search for GNU msgmerge 0.11 or newer in the PATH. | 77 | dnl Search for GNU msgmerge 0.11 or newer in the PATH. |
53 | AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, | 78 | AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, |
54 | [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) | 79 | [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) |
55 | 80 | ||
56 | dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. | 81 | dnl Installation directories. |
57 | dnl Test whether we really found GNU msgfmt. | 82 | dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we |
58 | if test "$GMSGFMT" != ":"; then | 83 | dnl have to define it here, so that it can be used in po/Makefile. |
59 | dnl If it is no GNU msgfmt we define it as : so that the | 84 | test -n "$localedir" || localedir='${datadir}/locale' |
60 | dnl Makefiles still can work. | 85 | AC_SUBST([localedir]) |
61 | if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 && | ||
62 | (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then | ||
63 | : ; | ||
64 | else | ||
65 | GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'` | ||
66 | AC_MSG_RESULT( | ||
67 | [found $GMSGFMT program is not GNU msgfmt; ignore it]) | ||
68 | GMSGFMT=":" | ||
69 | fi | ||
70 | fi | ||
71 | |||
72 | dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. | ||
73 | dnl Test whether we really found GNU xgettext. | ||
74 | if test "$XGETTEXT" != ":"; then | ||
75 | dnl If it is no GNU xgettext we define it as : so that the | ||
76 | dnl Makefiles still can work. | ||
77 | if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 && | ||
78 | (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then | ||
79 | : ; | ||
80 | else | ||
81 | AC_MSG_RESULT( | ||
82 | [found xgettext program is not GNU xgettext; ignore it]) | ||
83 | XGETTEXT=":" | ||
84 | fi | ||
85 | dnl Remove leftover from FreeBSD xgettext call. | ||
86 | rm -f messages.po | ||
87 | fi | ||
88 | 86 | ||
89 | AC_OUTPUT_COMMANDS([ | 87 | AC_CONFIG_COMMANDS([po-directories], [[ |
90 | for ac_file in $CONFIG_FILES; do | 88 | for ac_file in $CONFIG_FILES; do |
91 | # Support "outfile[:infile[:infile...]]" | 89 | # Support "outfile[:infile[:infile...]]" |
92 | case "$ac_file" in | 90 | case "$ac_file" in |
@@ -123,11 +121,12 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
123 | test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" | 121 | test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" |
124 | fi | 122 | fi |
125 | ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` | 123 | ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` |
126 | # Hide the ALL_LINGUAS assigment from automake. | 124 | # Hide the ALL_LINGUAS assigment from automake < 1.5. |
127 | eval 'ALL_LINGUAS''=$ALL_LINGUAS_' | 125 | eval 'ALL_LINGUAS''=$ALL_LINGUAS_' |
128 | POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" | 126 | POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" |
129 | else | 127 | else |
130 | # The set of available languages was given in configure.in. | 128 | # The set of available languages was given in configure.in. |
129 | # Hide the ALL_LINGUAS assigment from automake < 1.5. | ||
131 | eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' | 130 | eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' |
132 | fi | 131 | fi |
133 | # Compute POFILES | 132 | # Compute POFILES |
@@ -197,10 +196,10 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
197 | fi | 196 | fi |
198 | ;; | 197 | ;; |
199 | esac | 198 | esac |
200 | done], | 199 | done]], |
201 | [# Capture the value of obsolete ALL_LINGUAS because we need it to compute | 200 | [# Capture the value of obsolete ALL_LINGUAS because we need it to compute |
202 | # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it | 201 | # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it |
203 | # from automake. | 202 | # from automake < 1.5. |
204 | eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' | 203 | eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' |
205 | # Capture the value of LINGUAS because we need it to compute CATALOGS. | 204 | # Capture the value of LINGUAS because we need it to compute CATALOGS. |
206 | LINGUAS="${LINGUAS-%UNSET%}" | 205 | LINGUAS="${LINGUAS-%UNSET%}" |
@@ -286,7 +285,7 @@ x | |||
286 | changequote([,])dnl | 285 | changequote([,])dnl |
287 | 286 | ||
288 | # Set POTFILES to the value of the Makefile variable POTFILES. | 287 | # Set POTFILES to the value of the Makefile variable POTFILES. |
289 | sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`" | 288 | sed_x_POTFILES=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'` |
290 | POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"` | 289 | POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"` |
291 | # Compute POTFILES_DEPS as | 290 | # Compute POTFILES_DEPS as |
292 | # $(foreach file, $(POTFILES), $(top_srcdir)/$(file)) | 291 | # $(foreach file, $(POTFILES), $(top_srcdir)/$(file)) |
@@ -305,10 +304,10 @@ changequote([,])dnl | |||
305 | POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" | 304 | POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" |
306 | else | 305 | else |
307 | # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS. | 306 | # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS. |
308 | sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`" | 307 | sed_x_LINGUAS=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'` |
309 | ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"` | 308 | ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"` |
310 | fi | 309 | fi |
311 | # Hide the ALL_LINGUAS assigment from automake. | 310 | # Hide the ALL_LINGUAS assigment from automake < 1.5. |
312 | eval 'ALL_LINGUAS''=$ALL_LINGUAS_' | 311 | eval 'ALL_LINGUAS''=$ALL_LINGUAS_' |
313 | # Compute POFILES | 312 | # Compute POFILES |
314 | # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) | 313 | # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) |
diff --git a/gl/m4/printf-posix.m4 b/gl/m4/printf-posix.m4 new file mode 100644 index 0000000..af10170 --- /dev/null +++ b/gl/m4/printf-posix.m4 | |||
@@ -0,0 +1,44 @@ | |||
1 | # printf-posix.m4 serial 2 (gettext-0.13.1) | ||
2 | dnl Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | dnl Test whether the printf() function supports POSIX/XSI format strings with | ||
9 | dnl positions. | ||
10 | |||
11 | AC_DEFUN([gt_PRINTF_POSIX], | ||
12 | [ | ||
13 | AC_REQUIRE([AC_PROG_CC]) | ||
14 | AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings], | ||
15 | gt_cv_func_printf_posix, | ||
16 | [ | ||
17 | AC_TRY_RUN([ | ||
18 | #include <stdio.h> | ||
19 | #include <string.h> | ||
20 | /* The string "%2$d %1$d", with dollar characters protected from the shell's | ||
21 | dollar expansion (possibly an autoconf bug). */ | ||
22 | static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; | ||
23 | static char buf[100]; | ||
24 | int main () | ||
25 | { | ||
26 | sprintf (buf, format, 33, 55); | ||
27 | return (strcmp (buf, "55 33") != 0); | ||
28 | }], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no, | ||
29 | [ | ||
30 | AC_EGREP_CPP(notposix, [ | ||
31 | #if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ | ||
32 | notposix | ||
33 | #endif | ||
34 | ], gt_cv_func_printf_posix="guessing no", | ||
35 | gt_cv_func_printf_posix="guessing yes") | ||
36 | ]) | ||
37 | ]) | ||
38 | case $gt_cv_func_printf_posix in | ||
39 | *yes) | ||
40 | AC_DEFINE(HAVE_POSIX_PRINTF, 1, | ||
41 | [Define if your printf() function supports format strings with positions.]) | ||
42 | ;; | ||
43 | esac | ||
44 | ]) | ||
diff --git a/m4/progtest.m4 b/gl/m4/progtest.m4 index a56365c..a56365c 100644 --- a/m4/progtest.m4 +++ b/gl/m4/progtest.m4 | |||
diff --git a/m4/regex.m4 b/gl/m4/regex.m4 index 8ea4fe9..25da645 100644 --- a/m4/regex.m4 +++ b/gl/m4/regex.m4 | |||
@@ -1,7 +1,7 @@ | |||
1 | #serial 31 | 1 | #serial 42 |
2 | 2 | ||
3 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free | 3 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, |
4 | # Software Foundation, Inc. | 4 | # 2006, 2007 Free Software Foundation, Inc. |
5 | # | 5 | # |
6 | # This file is free software; the Free Software Foundation | 6 | # This file is free software; the Free Software Foundation |
7 | # gives unlimited permission to copy and/or distribute it, | 7 | # gives unlimited permission to copy and/or distribute it, |
@@ -14,34 +14,7 @@ AC_PREREQ([2.50]) | |||
14 | 14 | ||
15 | AC_DEFUN([gl_REGEX], | 15 | AC_DEFUN([gl_REGEX], |
16 | [ | 16 | [ |
17 | AC_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t | 17 | AC_CHECK_HEADERS_ONCE([locale.h]) |
18 | |||
19 | AC_CACHE_CHECK([whether off_t can be used in a switch statement], | ||
20 | [gl_cv_type_off_t_switch], | ||
21 | [AC_COMPILE_IFELSE( | ||
22 | [AC_LANG_PROGRAM( | ||
23 | [AC_INCLUDES_DEFAULT], | ||
24 | [[off_t o = -1; | ||
25 | switch (o) | ||
26 | { | ||
27 | case -2: | ||
28 | return 1; | ||
29 | case -1: | ||
30 | return 2; | ||
31 | default: | ||
32 | return 0; | ||
33 | } | ||
34 | ]])], | ||
35 | [gl_cv_type_off_t_switch=yes], | ||
36 | [gl_cv_type_off_t_switch=no])]) | ||
37 | if test $gl_cv_type_off_t_switch = yes; then | ||
38 | AC_DEFINE([_REGEX_LARGE_OFFSETS], 1, | ||
39 | [Define if you want regoff_t to be at least as wide POSIX requires.]) | ||
40 | fi | ||
41 | |||
42 | AC_LIBSOURCES( | ||
43 | [regcomp.c, regex.c, regex.h, | ||
44 | regex_internal.c, regex_internal.h, regexec.c]) | ||
45 | 18 | ||
46 | AC_ARG_WITH([included-regex], | 19 | AC_ARG_WITH([included-regex], |
47 | [AC_HELP_STRING([--without-included-regex], | 20 | [AC_HELP_STRING([--without-included-regex], |
@@ -49,30 +22,64 @@ AC_DEFUN([gl_REGEX], | |||
49 | systems with recent-enough versions of the GNU C | 22 | systems with recent-enough versions of the GNU C |
50 | Library (use with caution on other systems)])]) | 23 | Library (use with caution on other systems)])]) |
51 | 24 | ||
52 | case $with_included_regex in | 25 | case $with_included_regex in #( |
53 | yes|no) ac_use_included_regex=$with_included_regex | 26 | yes|no) ac_use_included_regex=$with_included_regex |
54 | ;; | 27 | ;; |
55 | '') | 28 | '') |
56 | # If the system regex support is good enough that it passes the the | 29 | # If the system regex support is good enough that it passes the |
57 | # following run test, then default to *not* using the included regex.c. | 30 | # following run test, then default to *not* using the included regex.c. |
58 | # If cross compiling, assume the test would fail and use the included | 31 | # If cross compiling, assume the test would fail and use the included |
59 | # regex.c. The first failing regular expression is from `Spencer ere | 32 | # regex.c. The first failing regular expression is from `Spencer ere |
60 | # test #75' in grep-2.3. | 33 | # test #75' in grep-2.3. |
61 | AC_CACHE_CHECK([for working re_compile_pattern], | 34 | AC_CACHE_CHECK([for working re_compile_pattern], |
62 | [gl_cv_func_re_compile_pattern_broken], | 35 | [gl_cv_func_re_compile_pattern_working], |
63 | [AC_RUN_IFELSE( | 36 | [AC_RUN_IFELSE( |
64 | [AC_LANG_PROGRAM( | 37 | [AC_LANG_PROGRAM( |
65 | [AC_INCLUDES_DEFAULT | 38 | [AC_INCLUDES_DEFAULT |
66 | #include <regex.h>], | 39 | #if HAVE_LOCALE_H |
40 | #include <locale.h> | ||
41 | #endif | ||
42 | #include <limits.h> | ||
43 | #include <regex.h> | ||
44 | ], | ||
67 | [[static struct re_pattern_buffer regex; | 45 | [[static struct re_pattern_buffer regex; |
46 | unsigned char folded_chars[UCHAR_MAX + 1]; | ||
47 | int i; | ||
68 | const char *s; | 48 | const char *s; |
69 | struct re_registers regs; | 49 | struct re_registers regs; |
70 | /* Use the POSIX-compliant spelling with leading REG_, | 50 | |
71 | rather than the traditional GNU spelling with leading RE_, | 51 | #if HAVE_LOCALE_H |
72 | so that we reject older libc implementations. */ | 52 | /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html |
73 | re_set_syntax (REG_SYNTAX_POSIX_EGREP); | 53 | This test needs valgrind to catch the bug on Debian |
54 | GNU/Linux 3.1 x86, but it might catch the bug better | ||
55 | on other platforms and it shouldn't hurt to try the | ||
56 | test here. */ | ||
57 | if (setlocale (LC_ALL, "en_US.UTF-8")) | ||
58 | { | ||
59 | static char const pat[] = "insert into"; | ||
60 | static char const data[] = | ||
61 | "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; | ||
62 | re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE | ||
63 | | RE_ICASE); | ||
64 | memset (®ex, 0, sizeof regex); | ||
65 | s = re_compile_pattern (pat, sizeof pat - 1, ®ex); | ||
66 | if (s) | ||
67 | return 1; | ||
68 | if (re_search (®ex, data, sizeof data - 1, | ||
69 | 0, sizeof data - 1, ®s) | ||
70 | != -1) | ||
71 | return 1; | ||
72 | if (! setlocale (LC_ALL, "C")) | ||
73 | return 1; | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | re_set_syntax (RE_SYNTAX_POSIX_EGREP); | ||
74 | memset (®ex, 0, sizeof (regex)); | 78 | memset (®ex, 0, sizeof (regex)); |
75 | s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex); | 79 | for (i = 0; i <= UCHAR_MAX; i++) |
80 | folded_chars[i] = i; | ||
81 | regex.translate = folded_chars; | ||
82 | s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); | ||
76 | /* This should fail with _Invalid character class name_ error. */ | 83 | /* This should fail with _Invalid character class name_ error. */ |
77 | if (!s) | 84 | if (!s) |
78 | exit (1); | 85 | exit (1); |
@@ -106,10 +113,9 @@ AC_DEFUN([gl_REGEX], | |||
106 | exit (1); | 113 | exit (1); |
107 | 114 | ||
108 | /* The version of regex.c in older versions of gnulib | 115 | /* The version of regex.c in older versions of gnulib |
109 | ignored REG_IGNORE_CASE (which was then called RE_ICASE). | 116 | ignored RE_ICASE. Detect that problem too. */ |
110 | Detect that problem too. */ | ||
111 | memset (®ex, 0, sizeof (regex)); | 117 | memset (®ex, 0, sizeof (regex)); |
112 | re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE); | 118 | re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); |
113 | s = re_compile_pattern ("x", 1, ®ex); | 119 | s = re_compile_pattern ("x", 1, ®ex); |
114 | if (s) | 120 | if (s) |
115 | exit (1); | 121 | exit (1); |
@@ -123,24 +129,29 @@ AC_DEFUN([gl_REGEX], | |||
123 | exit (1); | 129 | exit (1); |
124 | 130 | ||
125 | /* Reject hosts whose regoff_t values are too narrow. | 131 | /* Reject hosts whose regoff_t values are too narrow. |
126 | These include glibc 2.3.5 on hosts with 64-bit off_t | 132 | These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t |
127 | and 32-bit int, and Solaris 10 on hosts with 32-bit int | 133 | and 32-bit int. */ |
128 | and _FILE_OFFSET_BITS=64. */ | 134 | if (sizeof (regoff_t) < sizeof (ptrdiff_t) |
129 | if (sizeof (regoff_t) < sizeof (off_t)) | 135 | || sizeof (regoff_t) < sizeof (ssize_t)) |
130 | exit (1); | 136 | exit (1); |
131 | 137 | ||
132 | exit (0);]])], | 138 | exit (0);]])], |
133 | [gl_cv_func_re_compile_pattern_broken=no], | 139 | [gl_cv_func_re_compile_pattern_working=yes], |
134 | [gl_cv_func_re_compile_pattern_broken=yes], | 140 | [gl_cv_func_re_compile_pattern_working=no], |
135 | dnl When crosscompiling, assume it is broken. | 141 | dnl When crosscompiling, assume it is not working. |
136 | [gl_cv_func_re_compile_pattern_broken=yes])]) | 142 | [gl_cv_func_re_compile_pattern_working=no])]) |
137 | ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken | 143 | case $gl_cv_func_re_compile_pattern_working in #( |
144 | yes) ac_use_included_regex=no;; #( | ||
145 | no) ac_use_included_regex=yes;; | ||
146 | esac | ||
138 | ;; | 147 | ;; |
139 | *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) | 148 | *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) |
140 | ;; | 149 | ;; |
141 | esac | 150 | esac |
142 | 151 | ||
143 | if test $ac_use_included_regex = yes; then | 152 | if test $ac_use_included_regex = yes; then |
153 | AC_DEFINE([_REGEX_LARGE_OFFSETS], 1, | ||
154 | [Define if you want regoff_t to be at least as wide POSIX requires.]) | ||
144 | AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], | 155 | AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], |
145 | [Define to rpl_re_syntax_options if the replacement should be used.]) | 156 | [Define to rpl_re_syntax_options if the replacement should be used.]) |
146 | AC_DEFINE([re_set_syntax], [rpl_re_set_syntax], | 157 | AC_DEFINE([re_set_syntax], [rpl_re_set_syntax], |
@@ -180,8 +191,8 @@ AC_DEFUN([gl_REGEX], | |||
180 | AC_DEFUN([gl_PREREQ_REGEX], | 191 | AC_DEFUN([gl_PREREQ_REGEX], |
181 | [ | 192 | [ |
182 | AC_REQUIRE([AC_GNU_SOURCE]) | 193 | AC_REQUIRE([AC_GNU_SOURCE]) |
183 | AC_REQUIRE([gl_C_RESTRICT]) | 194 | AC_REQUIRE([AC_C_RESTRICT]) |
184 | AC_REQUIRE([AM_LANGINFO_CODESET]) | 195 | AC_REQUIRE([AM_LANGINFO_CODESET]) |
185 | AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h]) | 196 | AC_CHECK_FUNCS_ONCE([iswctype mbrtowc mempcpy wcrtomb wcscoll]) |
186 | AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll]) | 197 | AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>]) |
187 | ]) | 198 | ]) |
diff --git a/gl/m4/safe-read.m4 b/gl/m4/safe-read.m4 new file mode 100644 index 0000000..7a89d0a --- /dev/null +++ b/gl/m4/safe-read.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # safe-read.m4 serial 5 | ||
2 | dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_SAFE_READ], | ||
8 | [ | ||
9 | AC_LIBOBJ([safe-read]) | ||
10 | |||
11 | gl_PREREQ_SAFE_READ | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/safe-read.c. | ||
15 | AC_DEFUN([gl_PREREQ_SAFE_READ], | ||
16 | [ | ||
17 | AC_REQUIRE([gt_TYPE_SSIZE_T]) | ||
18 | ]) | ||
diff --git a/gl/m4/safe-write.m4 b/gl/m4/safe-write.m4 new file mode 100644 index 0000000..db119ff --- /dev/null +++ b/gl/m4/safe-write.m4 | |||
@@ -0,0 +1,18 @@ | |||
1 | # safe-write.m4 serial 3 | ||
2 | dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_SAFE_WRITE], | ||
8 | [ | ||
9 | AC_LIBOBJ([safe-write]) | ||
10 | |||
11 | gl_PREREQ_SAFE_WRITE | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/safe-write.c. | ||
15 | AC_DEFUN([gl_PREREQ_SAFE_WRITE], | ||
16 | [ | ||
17 | gl_PREREQ_SAFE_READ | ||
18 | ]) | ||
diff --git a/gl/m4/size_max.m4 b/gl/m4/size_max.m4 new file mode 100644 index 0000000..6cb4868 --- /dev/null +++ b/gl/m4/size_max.m4 | |||
@@ -0,0 +1,68 @@ | |||
1 | # size_max.m4 serial 6 | ||
2 | dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | AC_DEFUN([gl_SIZE_MAX], | ||
10 | [ | ||
11 | AC_CHECK_HEADERS(stdint.h) | ||
12 | dnl First test whether the system already has SIZE_MAX. | ||
13 | AC_MSG_CHECKING([for SIZE_MAX]) | ||
14 | AC_CACHE_VAL([gl_cv_size_max], [ | ||
15 | gl_cv_size_max= | ||
16 | AC_EGREP_CPP([Found it], [ | ||
17 | #include <limits.h> | ||
18 | #if HAVE_STDINT_H | ||
19 | #include <stdint.h> | ||
20 | #endif | ||
21 | #ifdef SIZE_MAX | ||
22 | Found it | ||
23 | #endif | ||
24 | ], gl_cv_size_max=yes) | ||
25 | if test -z "$gl_cv_size_max"; then | ||
26 | dnl Define it ourselves. Here we assume that the type 'size_t' is not wider | ||
27 | dnl than the type 'unsigned long'. Try hard to find a definition that can | ||
28 | dnl be used in a preprocessor #if, i.e. doesn't contain a cast. | ||
29 | AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], | ||
30 | [#include <stddef.h> | ||
31 | #include <limits.h>], size_t_bits_minus_1=) | ||
32 | AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], | ||
33 | [#include <stddef.h>], fits_in_uint=) | ||
34 | if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then | ||
35 | if test $fits_in_uint = 1; then | ||
36 | dnl Even though SIZE_MAX fits in an unsigned int, it must be of type | ||
37 | dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. | ||
38 | AC_TRY_COMPILE([#include <stddef.h> | ||
39 | extern size_t foo; | ||
40 | extern unsigned long foo; | ||
41 | ], [], fits_in_uint=0) | ||
42 | fi | ||
43 | dnl We cannot use 'expr' to simplify this expression, because 'expr' | ||
44 | dnl works only with 'long' integers in the host environment, while we | ||
45 | dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. | ||
46 | if test $fits_in_uint = 1; then | ||
47 | gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" | ||
48 | else | ||
49 | gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" | ||
50 | fi | ||
51 | else | ||
52 | dnl Shouldn't happen, but who knows... | ||
53 | gl_cv_size_max='((size_t)~(size_t)0)' | ||
54 | fi | ||
55 | fi | ||
56 | ]) | ||
57 | AC_MSG_RESULT([$gl_cv_size_max]) | ||
58 | if test "$gl_cv_size_max" != yes; then | ||
59 | AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], | ||
60 | [Define as the maximum value of type 'size_t', if the system doesn't define it.]) | ||
61 | fi | ||
62 | ]) | ||
63 | |||
64 | dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. | ||
65 | dnl Remove this when we can assume autoconf >= 2.61. | ||
66 | m4_ifdef([AC_COMPUTE_INT], [], [ | ||
67 | AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) | ||
68 | ]) | ||
diff --git a/gl/m4/snprintf.m4 b/gl/m4/snprintf.m4 new file mode 100644 index 0000000..432e037 --- /dev/null +++ b/gl/m4/snprintf.m4 | |||
@@ -0,0 +1,15 @@ | |||
1 | # snprintf.m4 serial 2 | ||
2 | dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_SNPRINTF], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(snprintf) | ||
10 | AC_CHECK_DECLS_ONCE(snprintf) | ||
11 | gl_PREREQ_SNPRINTF | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/snprintf.c. | ||
15 | AC_DEFUN([gl_PREREQ_SNPRINTF], [:]) | ||
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4 new file mode 100644 index 0000000..5e3765a --- /dev/null +++ b/gl/m4/socklen.m4 | |||
@@ -0,0 +1,52 @@ | |||
1 | # socklen.m4 serial 4 | ||
2 | dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Albert Chin, Windows fixes from Simon Josefsson. | ||
8 | |||
9 | dnl Check for socklen_t: historically on BSD it is an int, and in | ||
10 | dnl POSIX 1g it is a type of its own, but some platforms use different | ||
11 | dnl types for the argument to getsockopt, getpeername, etc. So we | ||
12 | dnl have to test to find something that will work. | ||
13 | |||
14 | dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find | ||
15 | dnl it there first. That file is included by gnulib's socket_.h, which | ||
16 | dnl all users of this module should include. Cygwin must not include | ||
17 | dnl ws2tcpip.h. | ||
18 | AC_DEFUN([gl_TYPE_SOCKLEN_T], | ||
19 | [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl | ||
20 | AC_CHECK_TYPE([socklen_t], , | ||
21 | [AC_MSG_CHECKING([for socklen_t equivalent]) | ||
22 | AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv], | ||
23 | [# Systems have either "struct sockaddr *" or | ||
24 | # "void *" as the second argument to getpeername | ||
25 | gl_cv_socklen_t_equiv= | ||
26 | for arg2 in "struct sockaddr" void; do | ||
27 | for t in int size_t "unsigned int" "long int" "unsigned long int"; do | ||
28 | AC_TRY_COMPILE( | ||
29 | [#include <sys/types.h> | ||
30 | #include <sys/socket.h> | ||
31 | |||
32 | int getpeername (int, $arg2 *, $t *);], | ||
33 | [$t len; | ||
34 | getpeername (0, 0, &len);], | ||
35 | [gl_cv_socklen_t_equiv="$t"]) | ||
36 | test "$gl_cv_socklen_t_equiv" != "" && break | ||
37 | done | ||
38 | test "$gl_cv_socklen_t_equiv" != "" && break | ||
39 | done | ||
40 | ]) | ||
41 | if test "$gl_cv_socklen_t_equiv" = ""; then | ||
42 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) | ||
43 | fi | ||
44 | AC_MSG_RESULT([$gl_cv_socklen_t_equiv]) | ||
45 | AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], | ||
46 | [type to use in place of socklen_t if not defined])], | ||
47 | [#include <sys/types.h> | ||
48 | #if HAVE_SYS_SOCKET_H | ||
49 | # include <sys/socket.h> | ||
50 | #elif HAVE_WS2TCPIP_H | ||
51 | # include <ws2tcpip.h> | ||
52 | #endif])]) | ||
diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4 new file mode 100644 index 0000000..25d9755 --- /dev/null +++ b/gl/m4/sockpfaf.m4 | |||
@@ -0,0 +1,58 @@ | |||
1 | # sockpfaf.m4 serial 5 | ||
2 | dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl Test for some common socket protocol families (PF_INET, PF_INET6, ...) | ||
8 | dnl and some common address families (AF_INET, AF_INET6, ...). | ||
9 | dnl This test assumes that a system supports an address family if and only if | ||
10 | dnl it supports the corresponding protocol family. | ||
11 | |||
12 | dnl From Bruno Haible. | ||
13 | |||
14 | AC_DEFUN([gl_SOCKET_FAMILIES], | ||
15 | [ | ||
16 | AC_REQUIRE([gl_HEADER_SYS_SOCKET]) | ||
17 | AC_CHECK_HEADERS_ONCE([netinet/in.h]) | ||
18 | |||
19 | AC_MSG_CHECKING(for IPv4 sockets) | ||
20 | AC_CACHE_VAL(gl_cv_socket_ipv4, | ||
21 | [AC_TRY_COMPILE([#include <sys/types.h> | ||
22 | #ifdef HAVE_SYS_SOCKET_H | ||
23 | #include <sys/socket.h> | ||
24 | #endif | ||
25 | #ifdef HAVE_NETINET_IN_H | ||
26 | #include <netinet/in.h> | ||
27 | #endif | ||
28 | #ifdef HAVE_WINSOCK2_H | ||
29 | #include <winsock2.h> | ||
30 | #endif], | ||
31 | [int x = AF_INET; struct in_addr y; struct sockaddr_in z; | ||
32 | if (&x && &y && &z) return 0;], | ||
33 | gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)]) | ||
34 | AC_MSG_RESULT($gl_cv_socket_ipv4) | ||
35 | if test $gl_cv_socket_ipv4 = yes; then | ||
36 | AC_DEFINE(HAVE_IPV4, 1, [Define to 1 if <sys/socket.h> defines AF_INET.]) | ||
37 | fi | ||
38 | |||
39 | AC_MSG_CHECKING(for IPv6 sockets) | ||
40 | AC_CACHE_VAL(gl_cv_socket_ipv6, | ||
41 | [AC_TRY_COMPILE([#include <sys/types.h> | ||
42 | #ifdef HAVE_SYS_SOCKET_H | ||
43 | #include <sys/socket.h> | ||
44 | #endif | ||
45 | #ifdef HAVE_NETINET_IN_H | ||
46 | #include <netinet/in.h> | ||
47 | #endif | ||
48 | #ifdef HAVE_WINSOCK2_H | ||
49 | #include <winsock2.h> | ||
50 | #endif], | ||
51 | [int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; | ||
52 | if (&x && &y && &z) return 0;], | ||
53 | gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)]) | ||
54 | AC_MSG_RESULT($gl_cv_socket_ipv6) | ||
55 | if test $gl_cv_socket_ipv6 = yes; then | ||
56 | AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if <sys/socket.h> defines AF_INET6.]) | ||
57 | fi | ||
58 | ]) | ||
diff --git a/gl/m4/ssize_t.m4 b/gl/m4/ssize_t.m4 new file mode 100644 index 0000000..4eaef93 --- /dev/null +++ b/gl/m4/ssize_t.m4 | |||
@@ -0,0 +1,21 @@ | |||
1 | # ssize_t.m4 serial 4 (gettext-0.15) | ||
2 | dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | dnl Test whether ssize_t is defined. | ||
9 | |||
10 | AC_DEFUN([gt_TYPE_SSIZE_T], | ||
11 | [ | ||
12 | AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t], | ||
13 | [AC_TRY_COMPILE([#include <sys/types.h>], | ||
14 | [int x = sizeof (ssize_t *) + sizeof (ssize_t); | ||
15 | return !x;], | ||
16 | [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])]) | ||
17 | if test $gt_cv_ssize_t = no; then | ||
18 | AC_DEFINE([ssize_t], [int], | ||
19 | [Define as a signed type of the same size as size_t.]) | ||
20 | fi | ||
21 | ]) | ||
diff --git a/m4/stdbool.m4 b/gl/m4/stdbool.m4 index 162f1df..2204ecd 100644 --- a/m4/stdbool.m4 +++ b/gl/m4/stdbool.m4 | |||
@@ -1,6 +1,6 @@ | |||
1 | # Check for stdbool.h that conforms to C99. | 1 | # Check for stdbool.h that conforms to C99. |
2 | 2 | ||
3 | dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. |
4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
6 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
@@ -64,9 +64,9 @@ AC_DEFUN([AC_HEADER_STDBOOL], | |||
64 | char a[true == 1 ? 1 : -1]; | 64 | char a[true == 1 ? 1 : -1]; |
65 | char b[false == 0 ? 1 : -1]; | 65 | char b[false == 0 ? 1 : -1]; |
66 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | 66 | char c[__bool_true_false_are_defined == 1 ? 1 : -1]; |
67 | char d[(bool) -0.5 == true ? 1 : -1]; | 67 | char d[(bool) 0.5 == true ? 1 : -1]; |
68 | bool e = &s; | 68 | bool e = &s; |
69 | char f[(_Bool) -0.0 == false ? 1 : -1]; | 69 | char f[(_Bool) 0.0 == false ? 1 : -1]; |
70 | char g[true]; | 70 | char g[true]; |
71 | char h[sizeof (_Bool)]; | 71 | char h[sizeof (_Bool)]; |
72 | char i[sizeof s.t]; | 72 | char i[sizeof s.t]; |
@@ -74,10 +74,10 @@ AC_DEFUN([AC_HEADER_STDBOOL], | |||
74 | _Bool n[m]; | 74 | _Bool n[m]; |
75 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | 75 | char o[sizeof n == m * sizeof n[0] ? 1 : -1]; |
76 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | 76 | char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; |
77 | #if defined __xlc__ || __GNUC__ | 77 | #if defined __xlc__ || defined __GNUC__ |
78 | /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 | 78 | /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 |
79 | reported by James Lemley on 2005-10-05; see | 79 | reported by James Lemley on 2005-10-05; see |
80 | <http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html>. | 80 | http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html |
81 | This test is not quite right, since xlc is allowed to | 81 | This test is not quite right, since xlc is allowed to |
82 | reject this program, as the initializer for xlcbug is | 82 | reject this program, as the initializer for xlcbug is |
83 | not one of the forms that C requires support for. | 83 | not one of the forms that C requires support for. |
@@ -86,10 +86,17 @@ AC_DEFUN([AC_HEADER_STDBOOL], | |||
86 | Let us hope that IBM fixes the xlc bug, and also adds | 86 | Let us hope that IBM fixes the xlc bug, and also adds |
87 | support for this kind of constant expression. In the | 87 | support for this kind of constant expression. In the |
88 | meantime, this test will reject xlc, which is OK, since | 88 | meantime, this test will reject xlc, which is OK, since |
89 | our stdbool.h substitute should suffice. */ | 89 | our stdbool.h substitute should suffice. We also test |
90 | this with GCC, where it should work, to detect more | ||
91 | quickly whether someone messes up the test in the | ||
92 | future. */ | ||
90 | char digs[] = "0123456789"; | 93 | char digs[] = "0123456789"; |
91 | int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); | 94 | int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); |
92 | #endif | 95 | #endif |
96 | /* Catch a bug in an HP-UX C compiler. See | ||
97 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | ||
98 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | ||
99 | */ | ||
93 | _Bool q = true; | 100 | _Bool q = true; |
94 | _Bool *pq = &q; | 101 | _Bool *pq = &q; |
95 | ], | 102 | ], |
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4 new file mode 100644 index 0000000..1a4b4a6 --- /dev/null +++ b/gl/m4/stdint.m4 | |||
@@ -0,0 +1,369 @@ | |||
1 | # stdint.m4 serial 22 | ||
2 | dnl Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert and Bruno Haible. | ||
8 | dnl Test whether <stdint.h> is supported or must be substituted. | ||
9 | |||
10 | AC_DEFUN([gl_STDINT_H], | ||
11 | [ | ||
12 | AC_PREREQ(2.59)dnl | ||
13 | |||
14 | dnl Check for long long int and unsigned long long int. | ||
15 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | ||
16 | if test $ac_cv_type_long_long_int = yes; then | ||
17 | HAVE_LONG_LONG_INT=1 | ||
18 | else | ||
19 | HAVE_LONG_LONG_INT=0 | ||
20 | fi | ||
21 | AC_SUBST([HAVE_LONG_LONG_INT]) | ||
22 | AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) | ||
23 | if test $ac_cv_type_unsigned_long_long_int = yes; then | ||
24 | HAVE_UNSIGNED_LONG_LONG_INT=1 | ||
25 | else | ||
26 | HAVE_UNSIGNED_LONG_LONG_INT=0 | ||
27 | fi | ||
28 | AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) | ||
29 | |||
30 | dnl Check for <inttypes.h>. | ||
31 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. | ||
32 | if test $ac_cv_header_inttypes_h = yes; then | ||
33 | HAVE_INTTYPES_H=1 | ||
34 | else | ||
35 | HAVE_INTTYPES_H=0 | ||
36 | fi | ||
37 | AC_SUBST([HAVE_INTTYPES_H]) | ||
38 | |||
39 | dnl Check for <sys/types.h>. | ||
40 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. | ||
41 | if test $ac_cv_header_sys_types_h = yes; then | ||
42 | HAVE_SYS_TYPES_H=1 | ||
43 | else | ||
44 | HAVE_SYS_TYPES_H=0 | ||
45 | fi | ||
46 | AC_SUBST([HAVE_SYS_TYPES_H]) | ||
47 | |||
48 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_stdint_h. | ||
49 | if test $ac_cv_header_stdint_h = yes; then | ||
50 | gl_ABSOLUTE_HEADER([stdint.h]) | ||
51 | ABSOLUTE_STDINT_H=\"$gl_cv_absolute_stdint_h\" | ||
52 | HAVE_STDINT_H=1 | ||
53 | else | ||
54 | ABSOLUTE_STDINT_H=\"no/such/file/stdint.h\" | ||
55 | HAVE_STDINT_H=0 | ||
56 | fi | ||
57 | AC_SUBST([ABSOLUTE_STDINT_H]) | ||
58 | AC_SUBST([HAVE_STDINT_H]) | ||
59 | |||
60 | dnl Now see whether we need a substitute <stdint.h>. Use | ||
61 | dnl ABSOLUTE_STDINT_H, not <stdint.h>, so that it also works during | ||
62 | dnl a "config.status --recheck" if a stdint.h has been | ||
63 | dnl created in the build directory. | ||
64 | if test $ac_cv_header_stdint_h = yes; then | ||
65 | AC_CACHE_CHECK([whether stdint.h conforms to C99], | ||
66 | [gl_cv_header_working_stdint_h], | ||
67 | [gl_cv_header_working_stdint_h=no | ||
68 | AC_COMPILE_IFELSE([ | ||
69 | AC_LANG_PROGRAM([[ | ||
70 | #include <stddef.h> | ||
71 | #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ | ||
72 | #define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ | ||
73 | #include ABSOLUTE_STDINT_H | ||
74 | #ifdef INT8_MAX | ||
75 | int8_t a1 = INT8_MAX; | ||
76 | int8_t a1min = INT8_MIN; | ||
77 | #endif | ||
78 | #ifdef INT16_MAX | ||
79 | int16_t a2 = INT16_MAX; | ||
80 | int16_t a2min = INT16_MIN; | ||
81 | #endif | ||
82 | #ifdef INT32_MAX | ||
83 | int32_t a3 = INT32_MAX; | ||
84 | int32_t a3min = INT32_MIN; | ||
85 | #endif | ||
86 | #ifdef INT64_MAX | ||
87 | int64_t a4 = INT64_MAX; | ||
88 | int64_t a4min = INT64_MIN; | ||
89 | #endif | ||
90 | #ifdef UINT8_MAX | ||
91 | uint8_t b1 = UINT8_MAX; | ||
92 | #else | ||
93 | typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; | ||
94 | #endif | ||
95 | #ifdef UINT16_MAX | ||
96 | uint16_t b2 = UINT16_MAX; | ||
97 | #endif | ||
98 | #ifdef UINT32_MAX | ||
99 | uint32_t b3 = UINT32_MAX; | ||
100 | #endif | ||
101 | #ifdef UINT64_MAX | ||
102 | uint64_t b4 = UINT64_MAX; | ||
103 | #endif | ||
104 | int_least8_t c1 = INT8_C (0x7f); | ||
105 | int_least8_t c1max = INT_LEAST8_MAX; | ||
106 | int_least8_t c1min = INT_LEAST8_MIN; | ||
107 | int_least16_t c2 = INT16_C (0x7fff); | ||
108 | int_least16_t c2max = INT_LEAST16_MAX; | ||
109 | int_least16_t c2min = INT_LEAST16_MIN; | ||
110 | int_least32_t c3 = INT32_C (0x7fffffff); | ||
111 | int_least32_t c3max = INT_LEAST32_MAX; | ||
112 | int_least32_t c3min = INT_LEAST32_MIN; | ||
113 | int_least64_t c4 = INT64_C (0x7fffffffffffffff); | ||
114 | int_least64_t c4max = INT_LEAST64_MAX; | ||
115 | int_least64_t c4min = INT_LEAST64_MIN; | ||
116 | uint_least8_t d1 = UINT8_C (0xff); | ||
117 | uint_least8_t d1max = UINT_LEAST8_MAX; | ||
118 | uint_least16_t d2 = UINT16_C (0xffff); | ||
119 | uint_least16_t d2max = UINT_LEAST16_MAX; | ||
120 | uint_least32_t d3 = UINT32_C (0xffffffff); | ||
121 | uint_least32_t d3max = UINT_LEAST32_MAX; | ||
122 | uint_least64_t d4 = UINT64_C (0xffffffffffffffff); | ||
123 | uint_least64_t d4max = UINT_LEAST64_MAX; | ||
124 | int_fast8_t e1 = INT_FAST8_MAX; | ||
125 | int_fast8_t e1min = INT_FAST8_MIN; | ||
126 | int_fast16_t e2 = INT_FAST16_MAX; | ||
127 | int_fast16_t e2min = INT_FAST16_MIN; | ||
128 | int_fast32_t e3 = INT_FAST32_MAX; | ||
129 | int_fast32_t e3min = INT_FAST32_MIN; | ||
130 | int_fast64_t e4 = INT_FAST64_MAX; | ||
131 | int_fast64_t e4min = INT_FAST64_MIN; | ||
132 | uint_fast8_t f1 = UINT_FAST8_MAX; | ||
133 | uint_fast16_t f2 = UINT_FAST16_MAX; | ||
134 | uint_fast32_t f3 = UINT_FAST32_MAX; | ||
135 | uint_fast64_t f4 = UINT_FAST64_MAX; | ||
136 | #ifdef INTPTR_MAX | ||
137 | intptr_t g = INTPTR_MAX; | ||
138 | intptr_t gmin = INTPTR_MIN; | ||
139 | #endif | ||
140 | #ifdef UINTPTR_MAX | ||
141 | uintptr_t h = UINTPTR_MAX; | ||
142 | #endif | ||
143 | intmax_t i = INTMAX_MAX; | ||
144 | uintmax_t j = UINTMAX_MAX; | ||
145 | struct s { | ||
146 | int check_PTRDIFF: PTRDIFF_MIN < 0 && 0 < PTRDIFF_MAX ? 1 : -1; | ||
147 | int check_SIG_ATOMIC: SIG_ATOMIC_MIN <= 0 && 0 < SIG_ATOMIC_MAX ? 1 : -1; | ||
148 | int check_SIZE: 0 < SIZE_MAX ? 1 : -1; | ||
149 | int check_WCHAR: WCHAR_MIN <= 0 && 0 < WCHAR_MAX ? 1 : -1; | ||
150 | int check_WINT: WINT_MIN <= 0 && 0 < WINT_MAX ? 1 : -1; | ||
151 | |||
152 | /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ | ||
153 | int check_UINT8_C: | ||
154 | (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; | ||
155 | int check_UINT16_C: | ||
156 | (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; | ||
157 | |||
158 | /* Detect bugs in OpenBSD 3.9 stdint.h. */ | ||
159 | #ifdef UINT8_MAX | ||
160 | int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; | ||
161 | #endif | ||
162 | #ifdef UINT16_MAX | ||
163 | int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; | ||
164 | #endif | ||
165 | #ifdef UINT32_MAX | ||
166 | int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; | ||
167 | #endif | ||
168 | #ifdef UINT64_MAX | ||
169 | int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; | ||
170 | #endif | ||
171 | int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; | ||
172 | int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; | ||
173 | int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; | ||
174 | int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; | ||
175 | int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; | ||
176 | int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; | ||
177 | int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; | ||
178 | int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; | ||
179 | int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; | ||
180 | int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; | ||
181 | int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; | ||
182 | }; | ||
183 | ]])], | ||
184 | [gl_cv_header_working_stdint_h=yes])]) | ||
185 | fi | ||
186 | if test "$gl_cv_header_working_stdint_h" = yes; then | ||
187 | STDINT_H= | ||
188 | else | ||
189 | dnl Check for <sys/inttypes.h>, and for | ||
190 | dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5). | ||
191 | AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) | ||
192 | if test $ac_cv_header_sys_inttypes_h = yes; then | ||
193 | HAVE_SYS_INTTYPES_H=1 | ||
194 | else | ||
195 | HAVE_SYS_INTTYPES_H=0 | ||
196 | fi | ||
197 | AC_SUBST([HAVE_SYS_INTTYPES_H]) | ||
198 | if test $ac_cv_header_sys_bitypes_h = yes; then | ||
199 | HAVE_SYS_BITYPES_H=1 | ||
200 | else | ||
201 | HAVE_SYS_BITYPES_H=0 | ||
202 | fi | ||
203 | AC_SUBST([HAVE_SYS_BITYPES_H]) | ||
204 | |||
205 | gl_STDINT_TYPE_PROPERTIES | ||
206 | STDINT_H=stdint.h | ||
207 | fi | ||
208 | AC_SUBST(STDINT_H) | ||
209 | ]) | ||
210 | |||
211 | dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) | ||
212 | dnl Determine the size of each of the given types in bits. | ||
213 | AC_DEFUN([gl_STDINT_BITSIZEOF], | ||
214 | [ | ||
215 | dnl Use a shell loop, to avoid bloating configure, and | ||
216 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | ||
217 | dnl config.h.in, | ||
218 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | ||
219 | AC_FOREACH([gltype], [$1], | ||
220 | [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), | ||
221 | [Define to the number of bits in type ']gltype['.])]) | ||
222 | for gltype in $1 ; do | ||
223 | AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], | ||
224 | [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], | ||
225 | [$2 | ||
226 | #include <limits.h>], [result=unknown]) | ||
227 | eval gl_cv_bitsizeof_${gltype}=\$result | ||
228 | ]) | ||
229 | eval result=\$gl_cv_bitsizeof_${gltype} | ||
230 | if test $result = unknown; then | ||
231 | dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, | ||
232 | dnl do a syntax check even on unused #if conditions and give an error | ||
233 | dnl on valid C code like this: | ||
234 | dnl #if 0 | ||
235 | dnl # if > 32 | ||
236 | dnl # endif | ||
237 | dnl #endif | ||
238 | result=0 | ||
239 | fi | ||
240 | GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | ||
241 | AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) | ||
242 | eval BITSIZEOF_${GLTYPE}=\$result | ||
243 | done | ||
244 | AC_FOREACH([gltype], [$1], | ||
245 | [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) | ||
246 | ]) | ||
247 | |||
248 | dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) | ||
249 | dnl Determine the signedness of each of the given types. | ||
250 | dnl Define HAVE_SIGNED_TYPE if type is signed. | ||
251 | AC_DEFUN([gl_CHECK_TYPES_SIGNED], | ||
252 | [ | ||
253 | dnl Use a shell loop, to avoid bloating configure, and | ||
254 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | ||
255 | dnl config.h.in, | ||
256 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | ||
257 | AC_FOREACH([gltype], [$1], | ||
258 | [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), | ||
259 | [Define to 1 if ']gltype[' is a signed integer type.])]) | ||
260 | for gltype in $1 ; do | ||
261 | AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], | ||
262 | [AC_COMPILE_IFELSE( | ||
263 | [AC_LANG_PROGRAM([$2[ | ||
264 | int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], | ||
265 | result=yes, result=no) | ||
266 | eval gl_cv_type_${gltype}_signed=\$result | ||
267 | ]) | ||
268 | eval result=\$gl_cv_type_${gltype}_signed | ||
269 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | ||
270 | if test "$result" = yes; then | ||
271 | AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1) | ||
272 | eval HAVE_SIGNED_${GLTYPE}=1 | ||
273 | else | ||
274 | eval HAVE_SIGNED_${GLTYPE}=0 | ||
275 | fi | ||
276 | done | ||
277 | AC_FOREACH([gltype], [$1], | ||
278 | [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) | ||
279 | ]) | ||
280 | |||
281 | dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) | ||
282 | dnl Determine the suffix to use for integer constants of the given types. | ||
283 | dnl Define t_SUFFIX for each such type. | ||
284 | AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], | ||
285 | [ | ||
286 | dnl Use a shell loop, to avoid bloating configure, and | ||
287 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | ||
288 | dnl config.h.in, | ||
289 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | ||
290 | AC_FOREACH([gltype], [$1], | ||
291 | [AH_TEMPLATE(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], | ||
292 | [Define to l, ll, u, ul, ull, etc., as suitable for | ||
293 | constants of type ']gltype['.])]) | ||
294 | for gltype in $1 ; do | ||
295 | AC_CACHE_CHECK([for $gltype integer literal suffix], | ||
296 | [gl_cv_type_${gltype}_suffix], | ||
297 | [eval gl_cv_type_${gltype}_suffix=no | ||
298 | eval result=\$gl_cv_type_${gltype}_signed | ||
299 | if test "$result" = yes; then | ||
300 | glsufu= | ||
301 | else | ||
302 | glsufu=u | ||
303 | fi | ||
304 | for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do | ||
305 | case $glsuf in | ||
306 | '') gltype1='int';; | ||
307 | l) gltype1='long int';; | ||
308 | ll) gltype1='long long int';; | ||
309 | i64) gltype1='__int64';; | ||
310 | u) gltype1='unsigned int';; | ||
311 | ul) gltype1='unsigned long int';; | ||
312 | ull) gltype1='unsigned long long int';; | ||
313 | ui64)gltype1='unsigned __int64';; | ||
314 | esac | ||
315 | AC_COMPILE_IFELSE( | ||
316 | [AC_LANG_PROGRAM([$2 | ||
317 | extern $gltype foo; | ||
318 | extern $gltype1 foo;])], | ||
319 | [eval gl_cv_type_${gltype}_suffix=\$glsuf]) | ||
320 | eval result=\$gl_cv_type_${gltype}_suffix | ||
321 | test "$result" != no && break | ||
322 | done]) | ||
323 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | ||
324 | eval result=\$gl_cv_type_${gltype}_suffix | ||
325 | test "$result" = no && result= | ||
326 | eval ${GLTYPE}_SUFFIX=\$result | ||
327 | AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], $result) | ||
328 | done | ||
329 | AC_FOREACH([gltype], [$1], | ||
330 | [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) | ||
331 | ]) | ||
332 | |||
333 | dnl gl_STDINT_INCLUDES | ||
334 | AC_DEFUN([gl_STDINT_INCLUDES], | ||
335 | [[ | ||
336 | /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | ||
337 | included before <wchar.h>. */ | ||
338 | #include <stddef.h> | ||
339 | #include <signal.h> | ||
340 | #include <stdio.h> | ||
341 | #include <time.h> | ||
342 | #include <wchar.h> | ||
343 | ]]) | ||
344 | |||
345 | dnl gl_STDINT_TYPE_PROPERTIES | ||
346 | dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t | ||
347 | dnl of interest to stdint_.h. | ||
348 | AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], | ||
349 | [ | ||
350 | gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], | ||
351 | [gl_STDINT_INCLUDES]) | ||
352 | gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], | ||
353 | [gl_STDINT_INCLUDES]) | ||
354 | gl_cv_type_ptrdiff_t_signed=yes | ||
355 | gl_cv_type_size_t_signed=no | ||
356 | gl_INTEGER_TYPE_SUFFIX([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], | ||
357 | [gl_STDINT_INCLUDES]) | ||
358 | ]) | ||
359 | |||
360 | dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. | ||
361 | dnl Remove this when we can assume autoconf >= 2.61. | ||
362 | m4_ifdef([AC_COMPUTE_INT], [], [ | ||
363 | AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) | ||
364 | ]) | ||
365 | |||
366 | # Hey Emacs! | ||
367 | # Local Variables: | ||
368 | # indent-tabs-mode: nil | ||
369 | # End: | ||
diff --git a/m4/stdint_h.m4 b/gl/m4/stdint_h.m4 index 3355f35..db9a8ac 100644 --- a/m4/stdint_h.m4 +++ b/gl/m4/stdint_h.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # stdint_h.m4 serial 5 | 1 | # stdint_h.m4 serial 6 |
2 | dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -15,7 +15,7 @@ AC_DEFUN([gl_AC_HEADER_STDINT_H], | |||
15 | [AC_TRY_COMPILE( | 15 | [AC_TRY_COMPILE( |
16 | [#include <sys/types.h> | 16 | [#include <sys/types.h> |
17 | #include <stdint.h>], | 17 | #include <stdint.h>], |
18 | [uintmax_t i = (uintmax_t) -1;], | 18 | [uintmax_t i = (uintmax_t) -1; return !i;], |
19 | gl_cv_header_stdint_h=yes, | 19 | gl_cv_header_stdint_h=yes, |
20 | gl_cv_header_stdint_h=no)]) | 20 | gl_cv_header_stdint_h=no)]) |
21 | if test $gl_cv_header_stdint_h = yes; then | 21 | if test $gl_cv_header_stdint_h = yes; then |
diff --git a/gl/m4/strcase.m4 b/gl/m4/strcase.m4 new file mode 100644 index 0000000..ae82790 --- /dev/null +++ b/gl/m4/strcase.m4 | |||
@@ -0,0 +1,39 @@ | |||
1 | # strcase.m4 serial 4 | ||
2 | dnl Copyright (C) 2002, 2005-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_STRCASE], | ||
8 | [ | ||
9 | gl_FUNC_STRCASECMP | ||
10 | gl_FUNC_STRNCASECMP | ||
11 | ]) | ||
12 | |||
13 | AC_DEFUN([gl_FUNC_STRCASECMP], | ||
14 | [ | ||
15 | dnl No known system has a strcasecmp() function that works correctly in | ||
16 | dnl multibyte locales. Therefore we use our version always. | ||
17 | AC_LIBOBJ(strcasecmp) | ||
18 | gl_PREREQ_STRCASECMP | ||
19 | ]) | ||
20 | |||
21 | AC_DEFUN([gl_FUNC_STRNCASECMP], | ||
22 | [ | ||
23 | AC_REPLACE_FUNCS(strncasecmp) | ||
24 | AC_CHECK_DECLS(strncasecmp) | ||
25 | if test $ac_cv_func_strncasecmp = no; then | ||
26 | gl_PREREQ_STRNCASECMP | ||
27 | fi | ||
28 | ]) | ||
29 | |||
30 | # Prerequisites of lib/strcasecmp.c. | ||
31 | AC_DEFUN([gl_PREREQ_STRCASECMP], [ | ||
32 | AC_REQUIRE([gl_FUNC_MBRTOWC]) | ||
33 | : | ||
34 | ]) | ||
35 | |||
36 | # Prerequisites of lib/strncasecmp.c. | ||
37 | AC_DEFUN([gl_PREREQ_STRNCASECMP], [ | ||
38 | : | ||
39 | ]) | ||
diff --git a/gl/m4/strdup.m4 b/gl/m4/strdup.m4 new file mode 100644 index 0000000..f7786e9 --- /dev/null +++ b/gl/m4/strdup.m4 | |||
@@ -0,0 +1,15 @@ | |||
1 | # strdup.m4 serial 7 | ||
2 | dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_STRDUP], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(strdup) | ||
10 | AC_CHECK_DECLS_ONCE(strdup) | ||
11 | gl_PREREQ_STRDUP | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/strdup.c. | ||
15 | AC_DEFUN([gl_PREREQ_STRDUP], [:]) | ||
diff --git a/gl/m4/strndup.m4 b/gl/m4/strndup.m4 new file mode 100644 index 0000000..dd5780b --- /dev/null +++ b/gl/m4/strndup.m4 | |||
@@ -0,0 +1,48 @@ | |||
1 | # strndup.m4 serial 11 | ||
2 | dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_STRNDUP], | ||
8 | [ | ||
9 | dnl Persuade glibc <string.h> to declare strndup(). | ||
10 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
11 | |||
12 | AC_CHECK_DECLS_ONCE([strndup]) | ||
13 | |||
14 | # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. | ||
15 | AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup, | ||
16 | [AC_RUN_IFELSE([ | ||
17 | AC_LANG_PROGRAM([#include <string.h> | ||
18 | #include <stdlib.h>], [[ | ||
19 | #ifndef HAVE_DECL_STRNDUP | ||
20 | extern char *strndup (const char *, size_t); | ||
21 | #endif | ||
22 | char *s; | ||
23 | s = strndup ("some longer string", 15); | ||
24 | free (s); | ||
25 | s = strndup ("shorter string", 13); | ||
26 | return s[13] != '\0';]])], | ||
27 | [gl_cv_func_strndup=yes], | ||
28 | [gl_cv_func_strndup=no], | ||
29 | [AC_CHECK_FUNC([strndup], | ||
30 | [AC_EGREP_CPP([too risky], [ | ||
31 | #ifdef _AIX | ||
32 | too risky | ||
33 | #endif | ||
34 | ], | ||
35 | [gl_cv_func_strndup=no], | ||
36 | [gl_cv_func_strndup=yes])], | ||
37 | [gl_cv_func_strndup=no])])]) | ||
38 | if test $gl_cv_func_strndup = yes; then | ||
39 | AC_DEFINE([HAVE_STRNDUP], 1, | ||
40 | [Define if you have the strndup() function and it works.]) | ||
41 | else | ||
42 | AC_LIBOBJ([strndup]) | ||
43 | gl_PREREQ_STRNDUP | ||
44 | fi | ||
45 | ]) | ||
46 | |||
47 | # Prerequisites of lib/strndup.c. | ||
48 | AC_DEFUN([gl_PREREQ_STRNDUP], [:]) | ||
diff --git a/gl/m4/strnlen.m4 b/gl/m4/strnlen.m4 new file mode 100644 index 0000000..0213a8a --- /dev/null +++ b/gl/m4/strnlen.m4 | |||
@@ -0,0 +1,27 @@ | |||
1 | # strnlen.m4 serial 6 | ||
2 | dnl Copyright (C) 2002-2003, 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_STRNLEN], | ||
8 | [ | ||
9 | dnl Persuade glibc <string.h> to declare strnlen(). | ||
10 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
11 | |||
12 | AC_FUNC_STRNLEN | ||
13 | if test $ac_cv_func_strnlen_working = no; then | ||
14 | # This is necessary because automake-1.6.1 doens't understand | ||
15 | # that the above use of AC_FUNC_STRNLEN means we may have to use | ||
16 | # lib/strnlen.c. | ||
17 | #AC_LIBOBJ(strnlen) | ||
18 | AC_DEFINE(strnlen, rpl_strnlen, | ||
19 | [Define to rpl_strnlen if the replacement function should be used.]) | ||
20 | gl_PREREQ_STRNLEN | ||
21 | fi | ||
22 | ]) | ||
23 | |||
24 | # Prerequisites of lib/strnlen.c. | ||
25 | AC_DEFUN([gl_PREREQ_STRNLEN], [ | ||
26 | AC_CHECK_DECLS_ONCE(strnlen) | ||
27 | ]) | ||
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4 new file mode 100644 index 0000000..d3e45b4 --- /dev/null +++ b/gl/m4/sys_socket_h.m4 | |||
@@ -0,0 +1,23 @@ | |||
1 | # sys_socket_h.m4 serial 2 | ||
2 | dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Simon Josefsson. | ||
8 | |||
9 | AC_DEFUN([gl_HEADER_SYS_SOCKET], | ||
10 | [ | ||
11 | AC_CHECK_HEADERS_ONCE([sys/socket.h]) | ||
12 | if test $ac_cv_header_sys_socket_h = yes; then | ||
13 | SYS_SOCKET_H='' | ||
14 | else | ||
15 | dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make | ||
16 | dnl the check for those headers unconditional; yet cygwin reports | ||
17 | dnl that the headers are present but cannot be compiled (since on | ||
18 | dnl cygwin, all socket information should come from sys/socket.h). | ||
19 | AC_CHECK_HEADERS([winsock2.h ws2tcpip.h]) | ||
20 | SYS_SOCKET_H='sys/socket.h' | ||
21 | fi | ||
22 | AC_SUBST(SYS_SOCKET_H) | ||
23 | ]) | ||
diff --git a/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4 index bf83ed7..bf83ed7 100644 --- a/m4/uintmax_t.m4 +++ b/gl/m4/uintmax_t.m4 | |||
diff --git a/gl/m4/ulonglong.m4 b/gl/m4/ulonglong.m4 new file mode 100644 index 0000000..9fae98e --- /dev/null +++ b/gl/m4/ulonglong.m4 | |||
@@ -0,0 +1,48 @@ | |||
1 | # ulonglong.m4 serial 6 | ||
2 | dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | # Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. | ||
10 | # This fixes a bug in Autoconf 2.60, but can be removed once we | ||
11 | # assume 2.61 everywhere. | ||
12 | |||
13 | # Note: If the type 'unsigned long long int' exists but is only 32 bits | ||
14 | # large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT | ||
15 | # will not be defined. In this case you can treat 'unsigned long long int' | ||
16 | # like 'unsigned long int'. | ||
17 | |||
18 | AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], | ||
19 | [ | ||
20 | AC_CACHE_CHECK([for unsigned long long int], | ||
21 | [ac_cv_type_unsigned_long_long_int], | ||
22 | [AC_LINK_IFELSE( | ||
23 | [AC_LANG_PROGRAM( | ||
24 | [[unsigned long long int ull = 18446744073709551615ULL; | ||
25 | typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 | ||
26 | ? 1 : -1)]; | ||
27 | int i = 63;]], | ||
28 | [[unsigned long long int ullmax = 18446744073709551615ull; | ||
29 | return (ull << 63 | ull >> 63 | ull << i | ull >> i | ||
30 | | ullmax / ull | ullmax % ull);]])], | ||
31 | [ac_cv_type_unsigned_long_long_int=yes], | ||
32 | [ac_cv_type_unsigned_long_long_int=no])]) | ||
33 | if test $ac_cv_type_unsigned_long_long_int = yes; then | ||
34 | AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, | ||
35 | [Define to 1 if the system has the type `unsigned long long int'.]) | ||
36 | fi | ||
37 | ]) | ||
38 | |||
39 | # This macro is obsolescent and should go away soon. | ||
40 | AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], | ||
41 | [ | ||
42 | AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) | ||
43 | ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int | ||
44 | if test $ac_cv_type_unsigned_long_long = yes; then | ||
45 | AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, | ||
46 | [Define if you have the 'unsigned long long' type.]) | ||
47 | fi | ||
48 | ]) | ||
diff --git a/m4/unistd-safer.m4 b/gl/m4/unistd-safer.m4 index 6fbe4c6..09adf93 100644 --- a/m4/unistd-safer.m4 +++ b/gl/m4/unistd-safer.m4 | |||
@@ -1,12 +1,12 @@ | |||
1 | #serial 7 | 1 | #serial 8 |
2 | dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | AC_DEFUN([gl_UNISTD_SAFER], | 7 | AC_DEFUN([gl_UNISTD_SAFER], |
8 | [ | 8 | [ |
9 | AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h]) | 9 | AC_CHECK_FUNCS_ONCE([pipe]) |
10 | AC_LIBOBJ([dup-safer]) | 10 | AC_LIBOBJ([dup-safer]) |
11 | AC_LIBOBJ([fd-safer]) | 11 | AC_LIBOBJ([fd-safer]) |
12 | AC_LIBOBJ([pipe-safer]) | 12 | AC_LIBOBJ([pipe-safer]) |
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4 new file mode 100644 index 0000000..9d499df --- /dev/null +++ b/gl/m4/unistd_h.m4 | |||
@@ -0,0 +1,32 @@ | |||
1 | # unistd_h.m4 serial 3 | ||
2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl Written by Simon Josefsson | ||
8 | |||
9 | AC_DEFUN([gl_HEADER_UNISTD], | ||
10 | [ | ||
11 | AC_CHECK_HEADERS([unistd.h], [ | ||
12 | UNISTD_H='' | ||
13 | ], [ | ||
14 | UNISTD_H='unistd.h' | ||
15 | ]) | ||
16 | AC_SUBST(UNISTD_H) | ||
17 | dnl This module decides to build unistd.h if it is missing. | ||
18 | dnl The fchdir module decides to build unistd.h if fchdir() is missing. | ||
19 | dnl Therefore check for the prerequisites of lib/unistd.h always. | ||
20 | gl_PREREQ_UNISTD | ||
21 | ]) | ||
22 | |||
23 | dnl Prerequisites of lib/unistd.h. | ||
24 | AC_DEFUN([gl_PREREQ_UNISTD], | ||
25 | [ | ||
26 | AC_CHECK_HEADERS_ONCE([unistd.h]) | ||
27 | if test $ac_cv_header_unistd_h = yes; then | ||
28 | gl_ABSOLUTE_HEADER([unistd.h]) | ||
29 | ABSOLUTE_UNISTD_H=\"$gl_cv_absolute_unistd_h\" | ||
30 | fi | ||
31 | AC_SUBST([ABSOLUTE_UNISTD_H]) | ||
32 | ]) | ||
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4 new file mode 100644 index 0000000..72c9a13 --- /dev/null +++ b/gl/m4/vasnprintf.m4 | |||
@@ -0,0 +1,57 @@ | |||
1 | # vasnprintf.m4 serial 7 | ||
2 | dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_VASNPRINTF], | ||
8 | [ | ||
9 | AC_REQUIRE([gl_EOVERFLOW]) | ||
10 | AC_REPLACE_FUNCS(vasnprintf) | ||
11 | if test $ac_cv_func_vasnprintf = no; then | ||
12 | AC_LIBOBJ(printf-args) | ||
13 | AC_LIBOBJ(printf-parse) | ||
14 | AC_LIBOBJ(asnprintf) | ||
15 | gl_PREREQ_PRINTF_ARGS | ||
16 | gl_PREREQ_PRINTF_PARSE | ||
17 | gl_PREREQ_VASNPRINTF | ||
18 | gl_PREREQ_ASNPRINTF | ||
19 | fi | ||
20 | ]) | ||
21 | |||
22 | # Prequisites of lib/printf-args.h, lib/printf-args.c. | ||
23 | AC_DEFUN([gl_PREREQ_PRINTF_ARGS], | ||
24 | [ | ||
25 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | ||
26 | AC_REQUIRE([gt_TYPE_LONGDOUBLE]) | ||
27 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | ||
28 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
29 | ]) | ||
30 | |||
31 | # Prequisites of lib/printf-parse.h, lib/printf-parse.c. | ||
32 | AC_DEFUN([gl_PREREQ_PRINTF_PARSE], | ||
33 | [ | ||
34 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | ||
35 | AC_REQUIRE([gt_TYPE_LONGDOUBLE]) | ||
36 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | ||
37 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
38 | AC_REQUIRE([AC_TYPE_SIZE_T]) | ||
39 | AC_CHECK_TYPES(ptrdiff_t) | ||
40 | AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) | ||
41 | ]) | ||
42 | |||
43 | # Prerequisites of lib/vasnprintf.c. | ||
44 | AC_DEFUN([gl_PREREQ_VASNPRINTF], | ||
45 | [ | ||
46 | AC_REQUIRE([AC_FUNC_ALLOCA]) | ||
47 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | ||
48 | AC_REQUIRE([gt_TYPE_LONGDOUBLE]) | ||
49 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | ||
50 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
51 | AC_CHECK_FUNCS(snprintf wcslen) | ||
52 | ]) | ||
53 | |||
54 | # Prerequisites of lib/asnprintf.c. | ||
55 | AC_DEFUN([gl_PREREQ_ASNPRINTF], | ||
56 | [ | ||
57 | ]) | ||
diff --git a/gl/m4/vasprintf.m4 b/gl/m4/vasprintf.m4 new file mode 100644 index 0000000..18ca632 --- /dev/null +++ b/gl/m4/vasprintf.m4 | |||
@@ -0,0 +1,33 @@ | |||
1 | # vasprintf.m4 serial 2 | ||
2 | dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_VASPRINTF], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(vasprintf) | ||
10 | if test $ac_cv_func_vasprintf = no; then | ||
11 | AC_LIBOBJ(asprintf) | ||
12 | gl_PREREQ_VASPRINTF_H | ||
13 | gl_PREREQ_VASPRINTF | ||
14 | gl_PREREQ_ASPRINTF | ||
15 | fi | ||
16 | ]) | ||
17 | |||
18 | # Prerequisites of lib/vasprintf.h. | ||
19 | AC_DEFUN([gl_PREREQ_VASPRINTF_H], | ||
20 | [ | ||
21 | dnl Persuade glibc <stdio.h> to declare asprintf() and vasprintf(). | ||
22 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
23 | ]) | ||
24 | |||
25 | # Prerequisites of lib/vasprintf.c. | ||
26 | AC_DEFUN([gl_PREREQ_VASPRINTF], | ||
27 | [ | ||
28 | ]) | ||
29 | |||
30 | # Prerequisites of lib/asprintf.c. | ||
31 | AC_DEFUN([gl_PREREQ_ASPRINTF], | ||
32 | [ | ||
33 | ]) | ||
diff --git a/gl/m4/visibility.m4 b/gl/m4/visibility.m4 new file mode 100644 index 0000000..2ff6330 --- /dev/null +++ b/gl/m4/visibility.m4 | |||
@@ -0,0 +1,52 @@ | |||
1 | # visibility.m4 serial 1 (gettext-0.15) | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | dnl Tests whether the compiler supports the command-line option | ||
10 | dnl -fvisibility=hidden and the function and variable attributes | ||
11 | dnl __attribute__((__visibility__("hidden"))) and | ||
12 | dnl __attribute__((__visibility__("default"))). | ||
13 | dnl Does *not* test for __visibility__("protected") - which has tricky | ||
14 | dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on | ||
15 | dnl MacOS X. | ||
16 | dnl Does *not* test for __visibility__("internal") - which has processor | ||
17 | dnl dependent semantics. | ||
18 | dnl Does *not* test for #pragma GCC visibility push(hidden) - which is | ||
19 | dnl "really only recommended for legacy code". | ||
20 | dnl Set the variable CFLAG_VISIBILITY. | ||
21 | dnl Defines and sets the variable HAVE_VISIBILITY. | ||
22 | |||
23 | AC_DEFUN([gl_VISIBILITY], | ||
24 | [ | ||
25 | AC_REQUIRE([AC_PROG_CC]) | ||
26 | CFLAG_VISIBILITY= | ||
27 | HAVE_VISIBILITY=0 | ||
28 | if test -n "$GCC"; then | ||
29 | AC_MSG_CHECKING([for simple visibility declarations]) | ||
30 | AC_CACHE_VAL(gl_cv_cc_visibility, [ | ||
31 | gl_save_CFLAGS="$CFLAGS" | ||
32 | CFLAGS="$CFLAGS -fvisibility=hidden" | ||
33 | AC_TRY_COMPILE( | ||
34 | [extern __attribute__((__visibility__("hidden"))) int hiddenvar; | ||
35 | extern __attribute__((__visibility__("default"))) int exportedvar; | ||
36 | extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); | ||
37 | extern __attribute__((__visibility__("default"))) int exportedfunc (void);], | ||
38 | [], | ||
39 | gl_cv_cc_visibility=yes, | ||
40 | gl_cv_cc_visibility=no) | ||
41 | CFLAGS="$gl_save_CFLAGS"]) | ||
42 | AC_MSG_RESULT([$gl_cv_cc_visibility]) | ||
43 | if test $gl_cv_cc_visibility = yes; then | ||
44 | CFLAG_VISIBILITY="-fvisibility=hidden" | ||
45 | HAVE_VISIBILITY=1 | ||
46 | fi | ||
47 | fi | ||
48 | AC_SUBST([CFLAG_VISIBILITY]) | ||
49 | AC_SUBST([HAVE_VISIBILITY]) | ||
50 | AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], | ||
51 | [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) | ||
52 | ]) | ||
diff --git a/gl/m4/vsnprintf.m4 b/gl/m4/vsnprintf.m4 new file mode 100644 index 0000000..cb8a9b1 --- /dev/null +++ b/gl/m4/vsnprintf.m4 | |||
@@ -0,0 +1,15 @@ | |||
1 | # vsnprintf.m4 serial 2 | ||
2 | dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_VSNPRINTF], | ||
8 | [ | ||
9 | AC_REPLACE_FUNCS(vsnprintf) | ||
10 | AC_CHECK_DECLS_ONCE(vsnprintf) | ||
11 | gl_PREREQ_VSNPRINTF | ||
12 | ]) | ||
13 | |||
14 | # Prerequisites of lib/vsnprintf.c. | ||
15 | AC_DEFUN([gl_PREREQ_VSNPRINTF], [:]) | ||
diff --git a/gl/m4/wchar.m4 b/gl/m4/wchar.m4 new file mode 100644 index 0000000..068f22d --- /dev/null +++ b/gl/m4/wchar.m4 | |||
@@ -0,0 +1,29 @@ | |||
1 | dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues. | ||
2 | |||
3 | dnl Copyright (C) 2007 Free Software Foundation, Inc. | ||
4 | dnl This file is free software; the Free Software Foundation | ||
5 | dnl gives unlimited permission to copy and/or distribute it, | ||
6 | dnl with or without modifications, as long as this notice is preserved. | ||
7 | |||
8 | dnl Written by Eric Blake. | ||
9 | |||
10 | # wchar.m4 serial 1 | ||
11 | |||
12 | AC_DEFUN([gl_WCHAR_H], | ||
13 | [ | ||
14 | AC_CACHE_CHECK([whether <wchar.h> is standalone], | ||
15 | [gl_cv_header_wchar_h_standalone], | ||
16 | [AC_COMPILE_IFELSE([[#include <wchar.h> | ||
17 | wchar_t w;]], | ||
18 | [gl_cv_header_wchar_h_standalone=yes], | ||
19 | [gl_cv_header_wchar_h_standalone=no])]) | ||
20 | if test $gl_cv_header_wchar_h_standalone = yes; then | ||
21 | WCHAR_H= | ||
22 | else | ||
23 | gl_ABSOLUTE_HEADER([wchar.h]) | ||
24 | ABSOLUTE_WCHAR_H=\"$gl_cv_absolute_wchar_h\" | ||
25 | WCHAR_H=wchar.h | ||
26 | fi | ||
27 | AC_SUBST([ABSOLUTE_WCHAR_H]) | ||
28 | AC_SUBST([WCHAR_H]) | ||
29 | ]) | ||
diff --git a/m4/wchar_t.m4 b/gl/m4/wchar_t.m4 index cde2129..cde2129 100644 --- a/m4/wchar_t.m4 +++ b/gl/m4/wchar_t.m4 | |||
diff --git a/gl/m4/wctype.m4 b/gl/m4/wctype.m4 new file mode 100644 index 0000000..62994c6 --- /dev/null +++ b/gl/m4/wctype.m4 | |||
@@ -0,0 +1,41 @@ | |||
1 | dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it. | ||
2 | |||
3 | dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. | ||
4 | dnl This file is free software; the Free Software Foundation | ||
5 | dnl gives unlimited permission to copy and/or distribute it, | ||
6 | dnl with or without modifications, as long as this notice is preserved. | ||
7 | |||
8 | dnl Written by Paul Eggert. | ||
9 | |||
10 | AC_DEFUN([gl_WCTYPE_H], | ||
11 | [ | ||
12 | AC_CHECK_FUNCS_ONCE([iswcntrl]) | ||
13 | AC_CHECK_HEADERS_ONCE([wctype.h]) | ||
14 | AC_REQUIRE([AC_C_INLINE]) | ||
15 | |||
16 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
17 | if test $gt_cv_c_wint_t = yes; then | ||
18 | HAVE_WINT_T=1 | ||
19 | else | ||
20 | HAVE_WINT_T=0 | ||
21 | fi | ||
22 | AC_SUBST([HAVE_WINT_T]) | ||
23 | |||
24 | WCTYPE_H=wctype.h | ||
25 | if test $ac_cv_header_wctype_h = yes; then | ||
26 | if test "$ac_cv_func_iswcntrl" = yes; then | ||
27 | WCTYPE_H= | ||
28 | fi | ||
29 | dnl Compute ABSOLUTE_WCTYPE_H even if WCTYPE_H is empty, | ||
30 | dnl for the benefit of builds from non-distclean directories. | ||
31 | gl_ABSOLUTE_HEADER([wctype.h]) | ||
32 | ABSOLUTE_WCTYPE_H=\"$gl_cv_absolute_wctype_h\" | ||
33 | HAVE_WCTYPE_H=1 | ||
34 | else | ||
35 | ABSOLUTE_WCTYPE_H=\"no/such/file/wctype.h\" | ||
36 | HAVE_WCTYPE_H=0 | ||
37 | fi | ||
38 | AC_SUBST([ABSOLUTE_WCTYPE_H]) | ||
39 | AC_SUBST([HAVE_WCTYPE_H]) | ||
40 | AC_SUBST([WCTYPE_H]) | ||
41 | ]) | ||
diff --git a/gl/m4/wcwidth.m4 b/gl/m4/wcwidth.m4 new file mode 100644 index 0000000..b483499 --- /dev/null +++ b/gl/m4/wcwidth.m4 | |||
@@ -0,0 +1,30 @@ | |||
1 | # wcwidth.m4 serial 8 | ||
2 | dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FUNC_WCWIDTH], | ||
8 | [ | ||
9 | dnl Persuade glibc <wchar.h> to declare wcwidth(). | ||
10 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
11 | |||
12 | AC_REQUIRE([AC_C_INLINE]) | ||
13 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | ||
14 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
15 | |||
16 | AC_CHECK_HEADERS_ONCE([wchar.h]) | ||
17 | AC_CHECK_FUNCS_ONCE([wcwidth]) | ||
18 | |||
19 | AC_CHECK_DECLS([wcwidth], [], [], [ | ||
20 | /* AIX 3.2.5 declares wcwidth in <string.h>. */ | ||
21 | #include <string.h> | ||
22 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
23 | <wchar.h>. | ||
24 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included | ||
25 | before <wchar.h>. */ | ||
26 | #include <stddef.h> | ||
27 | #include <stdio.h> | ||
28 | #include <time.h> | ||
29 | #include <wchar.h> | ||
30 | ])]) | ||
diff --git a/m4/wint_t.m4 b/gl/m4/wint_t.m4 index b8fff9c..3706c04 100644 --- a/m4/wint_t.m4 +++ b/gl/m4/wint_t.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # wint_t.m4 serial 1 (gettext-0.12) | 1 | # wint_t.m4 serial 2 (gettext-0.12) |
2 | dnl Copyright (C) 2003 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -11,7 +11,15 @@ dnl Prerequisite: AC_PROG_CC | |||
11 | AC_DEFUN([gt_TYPE_WINT_T], | 11 | AC_DEFUN([gt_TYPE_WINT_T], |
12 | [ | 12 | [ |
13 | AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, | 13 | AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, |
14 | [AC_TRY_COMPILE([#include <wchar.h> | 14 | [AC_TRY_COMPILE([ |
15 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
16 | <wchar.h>. | ||
17 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included | ||
18 | before <wchar.h>. */ | ||
19 | #include <stddef.h> | ||
20 | #include <stdio.h> | ||
21 | #include <time.h> | ||
22 | #include <wchar.h> | ||
15 | wint_t foo = (wchar_t)'\0';], , | 23 | wint_t foo = (wchar_t)'\0';], , |
16 | gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) | 24 | gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) |
17 | if test $gt_cv_c_wint_t = yes; then | 25 | if test $gt_cv_c_wint_t = yes; then |
diff --git a/m4/xalloc.m4 b/gl/m4/xalloc.m4 index c0847dd..837a948 100644 --- a/m4/xalloc.m4 +++ b/gl/m4/xalloc.m4 | |||
@@ -1,12 +1,11 @@ | |||
1 | # xalloc.m4 serial 12 | 1 | # xalloc.m4 serial 16 |
2 | dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
6 | 6 | ||
7 | AC_DEFUN([gl_XALLOC], | 7 | AC_DEFUN([gl_XALLOC], |
8 | [ | 8 | [ |
9 | AC_LIBSOURCES([xmalloc.c, xalloc.h]) | ||
10 | AC_LIBOBJ([xmalloc]) | 9 | AC_LIBOBJ([xmalloc]) |
11 | 10 | ||
12 | gl_PREREQ_XALLOC | 11 | gl_PREREQ_XALLOC |
@@ -15,11 +14,11 @@ AC_DEFUN([gl_XALLOC], | |||
15 | 14 | ||
16 | # Prerequisites of lib/xalloc.h. | 15 | # Prerequisites of lib/xalloc.h. |
17 | AC_DEFUN([gl_PREREQ_XALLOC], [ | 16 | AC_DEFUN([gl_PREREQ_XALLOC], [ |
17 | AC_REQUIRE([gl_INLINE]) | ||
18 | : | 18 | : |
19 | ]) | 19 | ]) |
20 | 20 | ||
21 | # Prerequisites of lib/xmalloc.c. | 21 | # Prerequisites of lib/xmalloc.c. |
22 | AC_DEFUN([gl_PREREQ_XMALLOC], [ | 22 | AC_DEFUN([gl_PREREQ_XMALLOC], [ |
23 | AC_REQUIRE([AC_C_INLINE]) | ||
24 | : | 23 | : |
25 | ]) | 24 | ]) |
diff --git a/gl/m4/xsize.m4 b/gl/m4/xsize.m4 new file mode 100644 index 0000000..85bb721 --- /dev/null +++ b/gl/m4/xsize.m4 | |||
@@ -0,0 +1,13 @@ | |||
1 | # xsize.m4 serial 3 | ||
2 | dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_XSIZE], | ||
8 | [ | ||
9 | dnl Prerequisites of lib/xsize.h. | ||
10 | AC_REQUIRE([gl_SIZE_MAX]) | ||
11 | AC_REQUIRE([AC_C_INLINE]) | ||
12 | AC_CHECK_HEADERS(stdint.h) | ||
13 | ]) | ||
diff --git a/gl/m4/xstrndup.m4 b/gl/m4/xstrndup.m4 new file mode 100644 index 0000000..8a30ab1 --- /dev/null +++ b/gl/m4/xstrndup.m4 | |||
@@ -0,0 +1,15 @@ | |||
1 | # xstrndup.m4 serial 2 | ||
2 | dnl Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_XSTRNDUP], | ||
8 | [ | ||
9 | gl_PREREQ_XSTRNDUP | ||
10 | ]) | ||
11 | |||
12 | # Prerequisites of lib/xstrndup.c. | ||
13 | AC_DEFUN([gl_PREREQ_XSTRNDUP], [ | ||
14 | : | ||
15 | ]) | ||
diff --git a/lib/malloc.c b/gl/malloc.c index 58fa611..d4dae3e 100644 --- a/lib/malloc.c +++ b/gl/malloc.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* malloc() function that is glibc compatible. | 1 | /* malloc() function that is glibc compatible. |
2 | Copyright (C) 1997, 1998 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1997, 1998, 2006 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +18,7 @@ | |||
17 | 18 | ||
18 | /* written by Jim Meyering */ | 19 | /* written by Jim Meyering */ |
19 | 20 | ||
20 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | #undef malloc | 22 | #undef malloc |
24 | 23 | ||
25 | #include <stdlib.h> | 24 | #include <stdlib.h> |
diff --git a/lib/xstrdup.c b/gl/mbchar.c index 58f18be..95373f5 100644 --- a/lib/xstrdup.c +++ b/gl/mbchar.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* xstrdup.c -- copy a string with out of memory checking | 1 | /* Copyright (C) 2001, 2006 Free Software Foundation, Inc. |
2 | Copyright (C) 1990, 1996, 1998, 2001, 2003 Free Software Foundation, Inc. | ||
3 | 2 | ||
4 | This program is free software; you can redistribute it and/or modify | 3 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 4 | it under the terms of the GNU General Public License as published by |
@@ -15,19 +14,23 @@ | |||
15 | along with this program; if not, write to the Free Software Foundation, | 14 | along with this program; if not, write to the Free Software Foundation, |
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 15 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 | 16 | ||
18 | #if HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | 17 | ||
22 | /* Specification. */ | 18 | #include <config.h> |
23 | #include "xalloc.h" | ||
24 | 19 | ||
25 | #include <string.h> | 20 | #include <limits.h> |
26 | 21 | ||
27 | /* Return a newly allocated copy of STRING. */ | 22 | #include "mbchar.h" |
28 | 23 | ||
29 | char * | 24 | #if IS_BASIC_ASCII |
30 | xstrdup (const char *string) | 25 | |
26 | /* Bit table of characters in the ISO C "basic character set". */ | ||
27 | const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = | ||
31 | { | 28 | { |
32 | return xclone (string, strlen (string) + 1); | 29 | 0x00001a00, /* '\t' '\v' '\f' */ |
33 | } | 30 | 0xffffffef, /* ' '...'#' '%'...'?' */ |
31 | 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ | ||
32 | 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ | ||
33 | /* The remaining bits are 0. */ | ||
34 | }; | ||
35 | |||
36 | #endif /* IS_BASIC_ASCII */ | ||
diff --git a/gl/mbchar.h b/gl/mbchar.h new file mode 100644 index 0000000..f3e28ef --- /dev/null +++ b/gl/mbchar.h | |||
@@ -0,0 +1,353 @@ | |||
1 | /* Multibyte character data type. | ||
2 | Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
17 | |||
18 | /* Written by Bruno Haible <bruno@clisp.org>. */ | ||
19 | |||
20 | /* A multibyte character is a short subsequence of a char* string, | ||
21 | representing a single wide character. | ||
22 | |||
23 | We use multibyte characters instead of wide characters because of | ||
24 | the following goals: | ||
25 | 1) correct multibyte handling, i.e. operate according to the LC_CTYPE | ||
26 | locale, | ||
27 | 2) ease of maintenance, i.e. the maintainer needs not know all details | ||
28 | of the ISO C 99 standard, | ||
29 | 3) don't fail grossly if the input is not in the encoding set by the | ||
30 | locale, because often different encodings are in use in the same | ||
31 | countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...), | ||
32 | 4) fast in the case of ASCII characters, | ||
33 | 5) portability, i.e. don't make unportable assumptions about wchar_t. | ||
34 | |||
35 | Multibyte characters are only accessed through the mb* macros. | ||
36 | |||
37 | mb_ptr (mbc) | ||
38 | return a pointer to the beginning of the multibyte sequence. | ||
39 | |||
40 | mb_len (mbc) | ||
41 | returns the number of bytes occupied by the multibyte sequence. | ||
42 | Always > 0. | ||
43 | |||
44 | mb_iseq (mbc, sc) | ||
45 | returns true if mbc is the standard ASCII character sc. | ||
46 | |||
47 | mb_isnul (mbc) | ||
48 | returns true if mbc is the nul character. | ||
49 | |||
50 | mb_cmp (mbc1, mbc2) | ||
51 | returns a positive, zero, or negative value depending on whether mbc1 | ||
52 | sorts after, same or before mbc2. | ||
53 | |||
54 | mb_casecmp (mbc1, mbc2) | ||
55 | returns a positive, zero, or negative value depending on whether mbc1 | ||
56 | sorts after, same or before mbc2, modulo upper/lowercase conversion. | ||
57 | |||
58 | mb_equal (mbc1, mbc2) | ||
59 | returns true if mbc1 and mbc2 are equal. | ||
60 | |||
61 | mb_caseequal (mbc1, mbc2) | ||
62 | returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion. | ||
63 | |||
64 | mb_isalnum (mbc) | ||
65 | returns true if mbc is alphanumeric. | ||
66 | |||
67 | mb_isalpha (mbc) | ||
68 | returns true if mbc is alphabetic. | ||
69 | |||
70 | mb_isascii(mbc) | ||
71 | returns true if mbc is plain ASCII. | ||
72 | |||
73 | mb_isblank (mbc) | ||
74 | returns true if mbc is a blank. | ||
75 | |||
76 | mb_iscntrl (mbc) | ||
77 | returns true if mbc is a control character. | ||
78 | |||
79 | mb_isdigit (mbc) | ||
80 | returns true if mbc is a decimal digit. | ||
81 | |||
82 | mb_isgraph (mbc) | ||
83 | returns true if mbc is a graphic character. | ||
84 | |||
85 | mb_islower (mbc) | ||
86 | returns true if mbc is lowercase. | ||
87 | |||
88 | mb_isprint (mbc) | ||
89 | returns true if mbc is a printable character. | ||
90 | |||
91 | mb_ispunct (mbc) | ||
92 | returns true if mbc is a punctuation character. | ||
93 | |||
94 | mb_isspace (mbc) | ||
95 | returns true if mbc is a space character. | ||
96 | |||
97 | mb_isupper (mbc) | ||
98 | returns true if mbc is uppercase. | ||
99 | |||
100 | mb_isxdigit (mbc) | ||
101 | returns true if mbc is a hexadecimal digit. | ||
102 | |||
103 | mb_width (mbc) | ||
104 | returns the number of columns on the output device occupied by mbc. | ||
105 | Always >= 0. | ||
106 | |||
107 | mb_putc (mbc, stream) | ||
108 | outputs mbc on stream, a byte oriented FILE stream opened for output. | ||
109 | |||
110 | mb_setascii (&mbc, sc) | ||
111 | assigns the standard ASCII character sc to mbc. | ||
112 | |||
113 | mb_copy (&destmbc, &srcmbc) | ||
114 | copies srcmbc to destmbc. | ||
115 | |||
116 | Here are the function prototypes of the macros. | ||
117 | |||
118 | extern const char * mb_ptr (const mbchar_t mbc); | ||
119 | extern size_t mb_len (const mbchar_t mbc); | ||
120 | extern bool mb_iseq (const mbchar_t mbc, char sc); | ||
121 | extern bool mb_isnul (const mbchar_t mbc); | ||
122 | extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); | ||
123 | extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); | ||
124 | extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); | ||
125 | extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); | ||
126 | extern bool mb_isalnum (const mbchar_t mbc); | ||
127 | extern bool mb_isalpha (const mbchar_t mbc); | ||
128 | extern bool mb_isascii (const mbchar_t mbc); | ||
129 | extern bool mb_isblank (const mbchar_t mbc); | ||
130 | extern bool mb_iscntrl (const mbchar_t mbc); | ||
131 | extern bool mb_isdigit (const mbchar_t mbc); | ||
132 | extern bool mb_isgraph (const mbchar_t mbc); | ||
133 | extern bool mb_islower (const mbchar_t mbc); | ||
134 | extern bool mb_isprint (const mbchar_t mbc); | ||
135 | extern bool mb_ispunct (const mbchar_t mbc); | ||
136 | extern bool mb_isspace (const mbchar_t mbc); | ||
137 | extern bool mb_isupper (const mbchar_t mbc); | ||
138 | extern bool mb_isxdigit (const mbchar_t mbc); | ||
139 | extern int mb_width (const mbchar_t mbc); | ||
140 | extern void mb_putc (const mbchar_t mbc, FILE *stream); | ||
141 | extern void mb_setascii (mbchar_t *new, char sc); | ||
142 | extern void mb_copy (mbchar_t *new, const mbchar_t *old); | ||
143 | */ | ||
144 | |||
145 | #ifndef _MBCHAR_H | ||
146 | #define _MBCHAR_H 1 | ||
147 | |||
148 | #include <stdbool.h> | ||
149 | #include <string.h> | ||
150 | |||
151 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
152 | <wchar.h>. | ||
153 | BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before | ||
154 | <wchar.h>. */ | ||
155 | #include <stdio.h> | ||
156 | #include <time.h> | ||
157 | #include <wchar.h> | ||
158 | #include <wctype.h> | ||
159 | |||
160 | #include "wcwidth.h" | ||
161 | |||
162 | #define MBCHAR_BUF_SIZE 24 | ||
163 | |||
164 | struct mbchar | ||
165 | { | ||
166 | const char *ptr; /* pointer to current character */ | ||
167 | size_t bytes; /* number of bytes of current character, > 0 */ | ||
168 | bool wc_valid; /* true if wc is a valid wide character */ | ||
169 | wchar_t wc; /* if wc_valid: the current character */ | ||
170 | char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ | ||
171 | }; | ||
172 | |||
173 | /* EOF (not a real character) is represented with bytes = 0 and | ||
174 | wc_valid = false. */ | ||
175 | |||
176 | typedef struct mbchar mbchar_t; | ||
177 | |||
178 | /* Access the current character. */ | ||
179 | #define mb_ptr(mbc) ((mbc).ptr) | ||
180 | #define mb_len(mbc) ((mbc).bytes) | ||
181 | |||
182 | /* Comparison of characters. */ | ||
183 | #define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) | ||
184 | #define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) | ||
185 | #define mb_cmp(mbc1, mbc2) \ | ||
186 | ((mbc1).wc_valid \ | ||
187 | ? ((mbc2).wc_valid \ | ||
188 | ? (int) (mbc1).wc - (int) (mbc2).wc \ | ||
189 | : -1) \ | ||
190 | : ((mbc2).wc_valid \ | ||
191 | ? 1 \ | ||
192 | : (mbc1).bytes == (mbc2).bytes \ | ||
193 | ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ | ||
194 | : (mbc1).bytes < (mbc2).bytes \ | ||
195 | ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ | ||
196 | : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) | ||
197 | #define mb_casecmp(mbc1, mbc2) \ | ||
198 | ((mbc1).wc_valid \ | ||
199 | ? ((mbc2).wc_valid \ | ||
200 | ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ | ||
201 | : -1) \ | ||
202 | : ((mbc2).wc_valid \ | ||
203 | ? 1 \ | ||
204 | : (mbc1).bytes == (mbc2).bytes \ | ||
205 | ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ | ||
206 | : (mbc1).bytes < (mbc2).bytes \ | ||
207 | ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ | ||
208 | : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) | ||
209 | #define mb_equal(mbc1, mbc2) \ | ||
210 | ((mbc1).wc_valid && (mbc2).wc_valid \ | ||
211 | ? (mbc1).wc == (mbc2).wc \ | ||
212 | : (mbc1).bytes == (mbc2).bytes \ | ||
213 | && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) | ||
214 | #define mb_caseequal(mbc1, mbc2) \ | ||
215 | ((mbc1).wc_valid && (mbc2).wc_valid \ | ||
216 | ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ | ||
217 | : (mbc1).bytes == (mbc2).bytes \ | ||
218 | && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) | ||
219 | |||
220 | /* <ctype.h>, <wctype.h> classification. */ | ||
221 | #define mb_isascii(mbc) \ | ||
222 | ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127) | ||
223 | #define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc)) | ||
224 | #define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc)) | ||
225 | #define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc)) | ||
226 | #define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc)) | ||
227 | #define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc)) | ||
228 | #define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc)) | ||
229 | #define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc)) | ||
230 | #define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc)) | ||
231 | #define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc)) | ||
232 | #define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc)) | ||
233 | #define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc)) | ||
234 | #define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc)) | ||
235 | |||
236 | /* Extra <wchar.h> function. */ | ||
237 | |||
238 | /* Unprintable characters appear as a small box of width 1. */ | ||
239 | #define MB_UNPRINTABLE_WIDTH 1 | ||
240 | |||
241 | static inline int | ||
242 | mb_width_aux (wint_t wc) | ||
243 | { | ||
244 | int w = wcwidth (wc); | ||
245 | /* For unprintable characters, arbitrarily return 0 for control characters | ||
246 | and MB_UNPRINTABLE_WIDTH otherwise. */ | ||
247 | return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH); | ||
248 | } | ||
249 | |||
250 | #define mb_width(mbc) \ | ||
251 | ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH) | ||
252 | |||
253 | /* Output. */ | ||
254 | #define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream)) | ||
255 | |||
256 | /* Assignment. */ | ||
257 | #define mb_setascii(mbc, sc) \ | ||
258 | ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \ | ||
259 | (mbc)->wc = (mbc)->buf[0] = (sc)) | ||
260 | |||
261 | /* Copying a character. */ | ||
262 | static inline void | ||
263 | mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) | ||
264 | { | ||
265 | if (old_mbc->ptr == &old_mbc->buf[0]) | ||
266 | { | ||
267 | memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); | ||
268 | new_mbc->ptr = &new_mbc->buf[0]; | ||
269 | } | ||
270 | else | ||
271 | new_mbc->ptr = old_mbc->ptr; | ||
272 | new_mbc->bytes = old_mbc->bytes; | ||
273 | if ((new_mbc->wc_valid = old_mbc->wc_valid)) | ||
274 | new_mbc->wc = old_mbc->wc; | ||
275 | } | ||
276 | |||
277 | |||
278 | /* is_basic(c) tests whether the single-byte character c is in the | ||
279 | ISO C "basic character set". | ||
280 | This is a convenience function, and is in this file only to share code | ||
281 | between mbiter_multi.h and mbfile_multi.h. */ | ||
282 | #if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ | ||
283 | && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ | ||
284 | && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ | ||
285 | && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ | ||
286 | && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ | ||
287 | && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ | ||
288 | && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ | ||
289 | && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ | ||
290 | && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ | ||
291 | && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ | ||
292 | && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ | ||
293 | && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ | ||
294 | && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ | ||
295 | && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ | ||
296 | && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ | ||
297 | && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ | ||
298 | && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ | ||
299 | && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ | ||
300 | && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ | ||
301 | && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ | ||
302 | && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ | ||
303 | && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ | ||
304 | && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) | ||
305 | /* The character set is ISO-646, not EBCDIC. */ | ||
306 | # define IS_BASIC_ASCII 1 | ||
307 | |||
308 | extern const unsigned int is_basic_table[]; | ||
309 | |||
310 | static inline bool | ||
311 | is_basic (char c) | ||
312 | { | ||
313 | return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) | ||
314 | & 1; | ||
315 | } | ||
316 | |||
317 | #else | ||
318 | |||
319 | static inline bool | ||
320 | is_basic (char c) | ||
321 | { | ||
322 | switch (c) | ||
323 | { | ||
324 | case '\t': case '\v': case '\f': | ||
325 | case ' ': case '!': case '"': case '#': case '%': | ||
326 | case '&': case '\'': case '(': case ')': case '*': | ||
327 | case '+': case ',': case '-': case '.': case '/': | ||
328 | case '0': case '1': case '2': case '3': case '4': | ||
329 | case '5': case '6': case '7': case '8': case '9': | ||
330 | case ':': case ';': case '<': case '=': case '>': | ||
331 | case '?': | ||
332 | case 'A': case 'B': case 'C': case 'D': case 'E': | ||
333 | case 'F': case 'G': case 'H': case 'I': case 'J': | ||
334 | case 'K': case 'L': case 'M': case 'N': case 'O': | ||
335 | case 'P': case 'Q': case 'R': case 'S': case 'T': | ||
336 | case 'U': case 'V': case 'W': case 'X': case 'Y': | ||
337 | case 'Z': | ||
338 | case '[': case '\\': case ']': case '^': case '_': | ||
339 | case 'a': case 'b': case 'c': case 'd': case 'e': | ||
340 | case 'f': case 'g': case 'h': case 'i': case 'j': | ||
341 | case 'k': case 'l': case 'm': case 'n': case 'o': | ||
342 | case 'p': case 'q': case 'r': case 's': case 't': | ||
343 | case 'u': case 'v': case 'w': case 'x': case 'y': | ||
344 | case 'z': case '{': case '|': case '}': case '~': | ||
345 | return 1; | ||
346 | default: | ||
347 | return 0; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | #endif | ||
352 | |||
353 | #endif /* _MBCHAR_H */ | ||
diff --git a/gl/mbuiter.h b/gl/mbuiter.h new file mode 100644 index 0000000..9da3a6c --- /dev/null +++ b/gl/mbuiter.h | |||
@@ -0,0 +1,203 @@ | |||
1 | /* Iterating through multibyte strings: macros for multi-byte encodings. | ||
2 | Copyright (C) 2001, 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
17 | |||
18 | /* Written by Bruno Haible <bruno@clisp.org>. */ | ||
19 | |||
20 | /* The macros in this file implement forward iteration through a | ||
21 | multi-byte string, without knowing its length a-priori. | ||
22 | |||
23 | With these macros, an iteration loop that looks like | ||
24 | |||
25 | char *iter; | ||
26 | for (iter = buf; *iter != '\0'; iter++) | ||
27 | { | ||
28 | do_something (*iter); | ||
29 | } | ||
30 | |||
31 | becomes | ||
32 | |||
33 | mbui_iterator_t iter; | ||
34 | for (mbui_init (iter, buf); mbui_avail (iter); mbui_advance (iter)) | ||
35 | { | ||
36 | do_something (mbui_cur_ptr (iter), mb_len (mbui_cur (iter))); | ||
37 | } | ||
38 | |||
39 | The benefit of these macros over plain use of mbrtowc is: | ||
40 | - Handling of invalid multibyte sequences is possible without | ||
41 | making the code more complicated, while still preserving the | ||
42 | invalid multibyte sequences. | ||
43 | |||
44 | Compared to mbiter.h, the macros here don't need to know the string's | ||
45 | length a-priori. The downside is that at each step, the look-ahead | ||
46 | that guards against overrunning the terminating '\0' is more expensive. | ||
47 | The mbui_* macros are therefore suitable when there is a high probability | ||
48 | that only the first few multibyte characters need to be inspected. | ||
49 | Whereas the mbi_* macros are better if usually the iteration runs | ||
50 | through the entire string. | ||
51 | |||
52 | mbui_iterator_t | ||
53 | is a type usable for variable declarations. | ||
54 | |||
55 | mbui_init (iter, startptr) | ||
56 | initializes the iterator, starting at startptr. | ||
57 | |||
58 | mbui_avail (iter) | ||
59 | returns true if there are more multibyte chracters available before | ||
60 | the end of string is reached. In this case, mbui_cur (iter) is | ||
61 | initialized to the next multibyte chracter. | ||
62 | |||
63 | mbui_advance (iter) | ||
64 | advances the iterator by one multibyte character. | ||
65 | |||
66 | mbui_cur (iter) | ||
67 | returns the current multibyte character, of type mbchar_t. All the | ||
68 | macros defined in mbchar.h can be used on it. | ||
69 | |||
70 | mbui_cur_ptr (iter) | ||
71 | return a pointer to the beginning of the current multibyte character. | ||
72 | |||
73 | mbui_reloc (iter, ptrdiff) | ||
74 | relocates iterator when the string is moved by ptrdiff bytes. | ||
75 | |||
76 | Here are the function prototypes of the macros. | ||
77 | |||
78 | extern void mbui_init (mbui_iterator_t iter, const char *startptr); | ||
79 | extern bool mbui_avail (mbui_iterator_t iter); | ||
80 | extern void mbui_advance (mbui_iterator_t iter); | ||
81 | extern mbchar_t mbui_cur (mbui_iterator_t iter); | ||
82 | extern const char * mbui_cur_ptr (mbui_iterator_t iter); | ||
83 | extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff); | ||
84 | */ | ||
85 | |||
86 | #ifndef _MBUITER_H | ||
87 | #define _MBUITER_H 1 | ||
88 | |||
89 | #include <assert.h> | ||
90 | #include <stdbool.h> | ||
91 | #include <stdlib.h> | ||
92 | |||
93 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
94 | <wchar.h>. | ||
95 | BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before | ||
96 | <wchar.h>. */ | ||
97 | #include <stdio.h> | ||
98 | #include <time.h> | ||
99 | #include <wchar.h> | ||
100 | |||
101 | #include "mbchar.h" | ||
102 | #include "strnlen1.h" | ||
103 | |||
104 | struct mbuiter_multi | ||
105 | { | ||
106 | bool in_shift; /* true if next byte may not be interpreted as ASCII */ | ||
107 | mbstate_t state; /* if in_shift: current shift state */ | ||
108 | bool next_done; /* true if mbui_avail has already filled the following */ | ||
109 | struct mbchar cur; /* the current character: | ||
110 | const char *cur.ptr pointer to current character | ||
111 | The following are only valid after mbui_avail. | ||
112 | size_t cur.bytes number of bytes of current character | ||
113 | bool cur.wc_valid true if wc is a valid wide character | ||
114 | wchar_t cur.wc if wc_valid: the current character | ||
115 | */ | ||
116 | }; | ||
117 | |||
118 | static inline void | ||
119 | mbuiter_multi_next (struct mbuiter_multi *iter) | ||
120 | { | ||
121 | if (iter->next_done) | ||
122 | return; | ||
123 | if (iter->in_shift) | ||
124 | goto with_shift; | ||
125 | /* Handle most ASCII characters quickly, without calling mbrtowc(). */ | ||
126 | if (is_basic (*iter->cur.ptr)) | ||
127 | { | ||
128 | /* These characters are part of the basic character set. ISO C 99 | ||
129 | guarantees that their wide character code is identical to their | ||
130 | char code. */ | ||
131 | iter->cur.bytes = 1; | ||
132 | iter->cur.wc = *iter->cur.ptr; | ||
133 | iter->cur.wc_valid = true; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | assert (mbsinit (&iter->state)); | ||
138 | iter->in_shift = true; | ||
139 | with_shift: | ||
140 | iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr, | ||
141 | strnlen1 (iter->cur.ptr, MB_CUR_MAX), | ||
142 | &iter->state); | ||
143 | if (iter->cur.bytes == (size_t) -1) | ||
144 | { | ||
145 | /* An invalid multibyte sequence was encountered. */ | ||
146 | iter->cur.bytes = 1; | ||
147 | iter->cur.wc_valid = false; | ||
148 | /* Whether to set iter->in_shift = false and reset iter->state | ||
149 | or not is not very important; the string is bogus anyway. */ | ||
150 | } | ||
151 | else if (iter->cur.bytes == (size_t) -2) | ||
152 | { | ||
153 | /* An incomplete multibyte character at the end. */ | ||
154 | iter->cur.bytes = strlen (iter->cur.ptr); | ||
155 | iter->cur.wc_valid = false; | ||
156 | /* Whether to set iter->in_shift = false and reset iter->state | ||
157 | or not is not important; the string end is reached anyway. */ | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | if (iter->cur.bytes == 0) | ||
162 | { | ||
163 | /* A null wide character was encountered. */ | ||
164 | iter->cur.bytes = 1; | ||
165 | assert (*iter->cur.ptr == '\0'); | ||
166 | assert (iter->cur.wc == 0); | ||
167 | } | ||
168 | iter->cur.wc_valid = true; | ||
169 | |||
170 | /* When in the initial state, we can go back treating ASCII | ||
171 | characters more quickly. */ | ||
172 | if (mbsinit (&iter->state)) | ||
173 | iter->in_shift = false; | ||
174 | } | ||
175 | } | ||
176 | iter->next_done = true; | ||
177 | } | ||
178 | |||
179 | static inline void | ||
180 | mbuiter_multi_reloc (struct mbuiter_multi *iter, ptrdiff_t ptrdiff) | ||
181 | { | ||
182 | iter->cur.ptr += ptrdiff; | ||
183 | } | ||
184 | |||
185 | /* Iteration macros. */ | ||
186 | typedef struct mbuiter_multi mbui_iterator_t; | ||
187 | #define mbui_init(iter, startptr) \ | ||
188 | ((iter).cur.ptr = (startptr), \ | ||
189 | (iter).in_shift = false, memset (&(iter).state, '\0', sizeof (mbstate_t)), \ | ||
190 | (iter).next_done = false) | ||
191 | #define mbui_avail(iter) \ | ||
192 | (mbuiter_multi_next (&(iter)), !mb_isnul ((iter).cur)) | ||
193 | #define mbui_advance(iter) \ | ||
194 | ((iter).cur.ptr += (iter).cur.bytes, (iter).next_done = false) | ||
195 | |||
196 | /* Access to the current character. */ | ||
197 | #define mbui_cur(iter) (iter).cur | ||
198 | #define mbui_cur_ptr(iter) (iter).cur.ptr | ||
199 | |||
200 | /* Relocation. */ | ||
201 | #define mbui_reloc(iter, ptrdiff) mbuiter_multi_reloc (&iter, ptrdiff) | ||
202 | |||
203 | #endif /* _MBUITER_H */ | ||
diff --git a/gl/memchr.c b/gl/memchr.c new file mode 100644 index 0000000..d44ad6d --- /dev/null +++ b/gl/memchr.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006 Free | ||
2 | Software Foundation, Inc. | ||
3 | |||
4 | Based on strlen implementation by Torbjorn Granlund (tege@sics.se), | ||
5 | with help from Dan Sahlin (dan@sics.se) and | ||
6 | commentary by Jim Blandy (jimb@ai.mit.edu); | ||
7 | adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), | ||
8 | and implemented by Roland McGrath (roland@ai.mit.edu). | ||
9 | |||
10 | NOTE: The canonical source of this file is maintained with the GNU C Library. | ||
11 | Bugs can be reported to bug-glibc@prep.ai.mit.edu. | ||
12 | |||
13 | This program is free software; you can redistribute it and/or modify it | ||
14 | under the terms of the GNU General Public License as published by the | ||
15 | Free Software Foundation; either version 2, or (at your option) any | ||
16 | later version. | ||
17 | |||
18 | This program is distributed in the hope that it will be useful, | ||
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | GNU General Public License for more details. | ||
22 | |||
23 | You should have received a copy of the GNU General Public License | ||
24 | along with this program; if not, write to the Free Software Foundation, | ||
25 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
26 | |||
27 | #ifndef _LIBC | ||
28 | # include <config.h> | ||
29 | #endif | ||
30 | |||
31 | #include <string.h> | ||
32 | |||
33 | #include <stddef.h> | ||
34 | |||
35 | #if defined _LIBC | ||
36 | # include <memcopy.h> | ||
37 | #else | ||
38 | # define reg_char char | ||
39 | #endif | ||
40 | |||
41 | #include <limits.h> | ||
42 | |||
43 | #if HAVE_BP_SYM_H || defined _LIBC | ||
44 | # include <bp-sym.h> | ||
45 | #else | ||
46 | # define BP_SYM(sym) sym | ||
47 | #endif | ||
48 | |||
49 | #undef memchr | ||
50 | #undef __memchr | ||
51 | |||
52 | /* Search no more than N bytes of S for C. */ | ||
53 | void * | ||
54 | __memchr (void const *s, int c_in, size_t n) | ||
55 | { | ||
56 | const unsigned char *char_ptr; | ||
57 | const unsigned long int *longword_ptr; | ||
58 | unsigned long int longword, magic_bits, charmask; | ||
59 | unsigned reg_char c; | ||
60 | int i; | ||
61 | |||
62 | c = (unsigned char) c_in; | ||
63 | |||
64 | /* Handle the first few characters by reading one character at a time. | ||
65 | Do this until CHAR_PTR is aligned on a longword boundary. */ | ||
66 | for (char_ptr = (const unsigned char *) s; | ||
67 | n > 0 && (size_t) char_ptr % sizeof longword != 0; | ||
68 | --n, ++char_ptr) | ||
69 | if (*char_ptr == c) | ||
70 | return (void *) char_ptr; | ||
71 | |||
72 | /* All these elucidatory comments refer to 4-byte longwords, | ||
73 | but the theory applies equally well to any size longwords. */ | ||
74 | |||
75 | longword_ptr = (const unsigned long int *) char_ptr; | ||
76 | |||
77 | /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits | ||
78 | the "holes." Note that there is a hole just to the left of | ||
79 | each byte, with an extra at the end: | ||
80 | |||
81 | bits: 01111110 11111110 11111110 11111111 | ||
82 | bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD | ||
83 | |||
84 | The 1-bits make sure that carries propagate to the next 0-bit. | ||
85 | The 0-bits provide holes for carries to fall into. */ | ||
86 | |||
87 | /* Set MAGIC_BITS to be this pattern of 1 and 0 bits. | ||
88 | Set CHARMASK to be a longword, each of whose bytes is C. */ | ||
89 | |||
90 | magic_bits = 0xfefefefe; | ||
91 | charmask = c | (c << 8); | ||
92 | charmask |= charmask << 16; | ||
93 | #if 0xffffffffU < ULONG_MAX | ||
94 | magic_bits |= magic_bits << 32; | ||
95 | charmask |= charmask << 32; | ||
96 | if (8 < sizeof longword) | ||
97 | for (i = 64; i < sizeof longword * 8; i *= 2) | ||
98 | { | ||
99 | magic_bits |= magic_bits << i; | ||
100 | charmask |= charmask << i; | ||
101 | } | ||
102 | #endif | ||
103 | magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1); | ||
104 | |||
105 | /* Instead of the traditional loop which tests each character, | ||
106 | we will test a longword at a time. The tricky part is testing | ||
107 | if *any of the four* bytes in the longword in question are zero. */ | ||
108 | while (n >= sizeof longword) | ||
109 | { | ||
110 | /* We tentatively exit the loop if adding MAGIC_BITS to | ||
111 | LONGWORD fails to change any of the hole bits of LONGWORD. | ||
112 | |||
113 | 1) Is this safe? Will it catch all the zero bytes? | ||
114 | Suppose there is a byte with all zeros. Any carry bits | ||
115 | propagating from its left will fall into the hole at its | ||
116 | least significant bit and stop. Since there will be no | ||
117 | carry from its most significant bit, the LSB of the | ||
118 | byte to the left will be unchanged, and the zero will be | ||
119 | detected. | ||
120 | |||
121 | 2) Is this worthwhile? Will it ignore everything except | ||
122 | zero bytes? Suppose every byte of LONGWORD has a bit set | ||
123 | somewhere. There will be a carry into bit 8. If bit 8 | ||
124 | is set, this will carry into bit 16. If bit 8 is clear, | ||
125 | one of bits 9-15 must be set, so there will be a carry | ||
126 | into bit 16. Similarly, there will be a carry into bit | ||
127 | 24. If one of bits 24-30 is set, there will be a carry | ||
128 | into bit 31, so all of the hole bits will be changed. | ||
129 | |||
130 | The one misfire occurs when bits 24-30 are clear and bit | ||
131 | 31 is set; in this case, the hole at bit 31 is not | ||
132 | changed. If we had access to the processor carry flag, | ||
133 | we could close this loophole by putting the fourth hole | ||
134 | at bit 32! | ||
135 | |||
136 | So it ignores everything except 128's, when they're aligned | ||
137 | properly. | ||
138 | |||
139 | 3) But wait! Aren't we looking for C, not zero? | ||
140 | Good point. So what we do is XOR LONGWORD with a longword, | ||
141 | each of whose bytes is C. This turns each byte that is C | ||
142 | into a zero. */ | ||
143 | |||
144 | longword = *longword_ptr++ ^ charmask; | ||
145 | |||
146 | /* Add MAGIC_BITS to LONGWORD. */ | ||
147 | if ((((longword + magic_bits) | ||
148 | |||
149 | /* Set those bits that were unchanged by the addition. */ | ||
150 | ^ ~longword) | ||
151 | |||
152 | /* Look at only the hole bits. If any of the hole bits | ||
153 | are unchanged, most likely one of the bytes was a | ||
154 | zero. */ | ||
155 | & ~magic_bits) != 0) | ||
156 | { | ||
157 | /* Which of the bytes was C? If none of them were, it was | ||
158 | a misfire; continue the search. */ | ||
159 | |||
160 | const unsigned char *cp = (const unsigned char *) (longword_ptr - 1); | ||
161 | |||
162 | if (cp[0] == c) | ||
163 | return (void *) cp; | ||
164 | if (cp[1] == c) | ||
165 | return (void *) &cp[1]; | ||
166 | if (cp[2] == c) | ||
167 | return (void *) &cp[2]; | ||
168 | if (cp[3] == c) | ||
169 | return (void *) &cp[3]; | ||
170 | if (4 < sizeof longword && cp[4] == c) | ||
171 | return (void *) &cp[4]; | ||
172 | if (5 < sizeof longword && cp[5] == c) | ||
173 | return (void *) &cp[5]; | ||
174 | if (6 < sizeof longword && cp[6] == c) | ||
175 | return (void *) &cp[6]; | ||
176 | if (7 < sizeof longword && cp[7] == c) | ||
177 | return (void *) &cp[7]; | ||
178 | if (8 < sizeof longword) | ||
179 | for (i = 8; i < sizeof longword; i++) | ||
180 | if (cp[i] == c) | ||
181 | return (void *) &cp[i]; | ||
182 | } | ||
183 | |||
184 | n -= sizeof longword; | ||
185 | } | ||
186 | |||
187 | char_ptr = (const unsigned char *) longword_ptr; | ||
188 | |||
189 | while (n-- > 0) | ||
190 | { | ||
191 | if (*char_ptr == c) | ||
192 | return (void *) char_ptr; | ||
193 | else | ||
194 | ++char_ptr; | ||
195 | } | ||
196 | |||
197 | return 0; | ||
198 | } | ||
199 | #ifdef weak_alias | ||
200 | weak_alias (__memchr, BP_SYM (memchr)) | ||
201 | #endif | ||
diff --git a/gl/minmax.h b/gl/minmax.h new file mode 100644 index 0000000..975ea76 --- /dev/null +++ b/gl/minmax.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* MIN, MAX macros. | ||
2 | Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _MINMAX_H | ||
19 | #define _MINMAX_H | ||
20 | |||
21 | /* Note: MIN, MAX are also defined in <sys/param.h> on some systems | ||
22 | (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about | ||
23 | MIN, MAX macro redefinitions on some systems; the workaround is to | ||
24 | #include this file as the last one among the #include list. */ | ||
25 | |||
26 | /* Before we define the following symbols we get the <limits.h> file | ||
27 | since otherwise we get redefinitions on some systems if <limits.h> is | ||
28 | included after this file. Likewise for <sys/param.h>. | ||
29 | If more than one of these system headers define MIN and MAX, pick just | ||
30 | one of the headers (because the definitions most likely are the same). */ | ||
31 | #if HAVE_MINMAX_IN_LIMITS_H | ||
32 | # include <limits.h> | ||
33 | #elif HAVE_MINMAX_IN_SYS_PARAM_H | ||
34 | # include <sys/param.h> | ||
35 | #endif | ||
36 | |||
37 | /* Note: MIN and MAX should be used with two arguments of the | ||
38 | same type. They might not return the minimum and maximum of their two | ||
39 | arguments, if the arguments have different types or have unusual | ||
40 | floating-point values. For example, on a typical host with 32-bit 'int', | ||
41 | 64-bit 'long long', and 64-bit IEEE 754 'double' types: | ||
42 | |||
43 | MAX (-1, 2147483648) returns 4294967295. | ||
44 | MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. | ||
45 | MAX (NaN, 0.0) returns 0.0. | ||
46 | MAX (+0.0, -0.0) returns -0.0. | ||
47 | |||
48 | and in each case the answer is in some sense bogus. */ | ||
49 | |||
50 | /* MAX(a,b) returns the maximum of A and B. */ | ||
51 | #ifndef MAX | ||
52 | # define MAX(a,b) ((a) > (b) ? (a) : (b)) | ||
53 | #endif | ||
54 | |||
55 | /* MIN(a,b) returns the minimum of A and B. */ | ||
56 | #ifndef MIN | ||
57 | # define MIN(a,b) ((a) < (b) ? (a) : (b)) | ||
58 | #endif | ||
59 | |||
60 | #endif /* _MINMAX_H */ | ||
diff --git a/lib/mountlist.c b/gl/mountlist.c index a1dca0a..bb01f91 100644 --- a/lib/mountlist.c +++ b/gl/mountlist.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* mountlist.c -- return a list of mounted file systems | 1 | /* mountlist.c -- return a list of mounted file systems |
2 | 2 | ||
3 | Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, | 3 | Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4 | 2004, 2005 Free Software Foundation, Inc. | 4 | 2004, 2005, 2006 Free Software Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -17,12 +17,11 @@ | |||
17 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | #include "mountlist.h" | 22 | #include "mountlist.h" |
25 | 23 | ||
24 | #include <limits.h> | ||
26 | #include <stdio.h> | 25 | #include <stdio.h> |
27 | #include <stdlib.h> | 26 | #include <stdlib.h> |
28 | #include <string.h> | 27 | #include <string.h> |
@@ -81,6 +80,10 @@ char *strstr (); | |||
81 | # include <sys/mount.h> | 80 | # include <sys/mount.h> |
82 | #endif | 81 | #endif |
83 | 82 | ||
83 | #ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ | ||
84 | # include <sys/statvfs.h> | ||
85 | #endif | ||
86 | |||
84 | #ifdef MOUNTED_GETMNT /* Ultrix. */ | 87 | #ifdef MOUNTED_GETMNT /* Ultrix. */ |
85 | # include <sys/mount.h> | 88 | # include <sys/mount.h> |
86 | # include <sys/fs_types.h> | 89 | # include <sys/fs_types.h> |
@@ -101,11 +104,6 @@ char *strstr (); | |||
101 | # include <sys/statfs.h> | 104 | # include <sys/statfs.h> |
102 | #endif | 105 | #endif |
103 | 106 | ||
104 | #ifdef STAT_STATVFS | ||
105 | # include <sys/statvfs.h> | ||
106 | # define statfs statvfs | ||
107 | #endif | ||
108 | |||
109 | #ifdef MOUNTED_LISTMNTENT | 107 | #ifdef MOUNTED_LISTMNTENT |
110 | # include <mntent.h> | 108 | # include <mntent.h> |
111 | #endif | 109 | #endif |
@@ -145,29 +143,42 @@ char *strstr (); | |||
145 | # define SIZE_MAX ((size_t) -1) | 143 | # define SIZE_MAX ((size_t) -1) |
146 | #endif | 144 | #endif |
147 | 145 | ||
146 | /* The results of open() in this file are not used with fchdir, | ||
147 | therefore save some unnecessary work in fchdir.c. */ | ||
148 | #undef open | ||
149 | #undef close | ||
150 | |||
151 | /* The results of opendir() in this file are not used with dirfd and fchdir, | ||
152 | therefore save some unnecessary work in fchdir.c. */ | ||
153 | #undef opendir | ||
154 | #undef closedir | ||
155 | |||
148 | #ifndef ME_DUMMY | 156 | #ifndef ME_DUMMY |
149 | # define ME_DUMMY(Fs_name, Fs_type) \ | 157 | # define ME_DUMMY(Fs_name, Fs_type) \ |
150 | (strcmp (Fs_type, "autofs") == 0 \ | 158 | (strcmp (Fs_type, "autofs") == 0 \ |
151 | || strcmp (Fs_type, "none") == 0 \ | 159 | || strcmp (Fs_type, "none") == 0 \ |
152 | || strcmp (Fs_type, "proc") == 0 \ | 160 | || strcmp (Fs_type, "proc") == 0 \ |
153 | || strcmp (Fs_type, "subfs") == 0 \ | 161 | || strcmp (Fs_type, "subfs") == 0 \ |
162 | /* for NetBSD 3.0 */ \ | ||
163 | || strcmp (Fs_type, "kernfs") == 0 \ | ||
154 | /* for Irix 6.5 */ \ | 164 | /* for Irix 6.5 */ \ |
155 | || strcmp (Fs_type, "ignore") == 0) | 165 | || strcmp (Fs_type, "ignore") == 0) |
156 | #endif | 166 | #endif |
157 | 167 | ||
158 | #ifndef ME_REMOTE | 168 | #ifndef ME_REMOTE |
159 | /* A file system is `remote' if its Fs_name contains a `:' | 169 | /* A file system is `remote' if its Fs_name contains a `:' |
160 | or if (it is of type smbfs and its Fs_name starts with `//'). */ | 170 | or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */ |
161 | # define ME_REMOTE(Fs_name, Fs_type) \ | 171 | # define ME_REMOTE(Fs_name, Fs_type) \ |
162 | (strchr (Fs_name, ':') != 0 \ | 172 | (strchr (Fs_name, ':') != NULL \ |
163 | || ((Fs_name)[0] == '/' \ | 173 | || ((Fs_name)[0] == '/' \ |
164 | && (Fs_name)[1] == '/' \ | 174 | && (Fs_name)[1] == '/' \ |
165 | && strcmp (Fs_type, "smbfs") == 0)) | 175 | && (strcmp (Fs_type, "smbfs") == 0 \ |
176 | || strcmp (Fs_type, "cifs") == 0))) | ||
166 | #endif | 177 | #endif |
167 | 178 | ||
168 | #if MOUNTED_GETMNTINFO | 179 | #if MOUNTED_GETMNTINFO |
169 | 180 | ||
170 | # if ! HAVE_F_FSTYPENAME_IN_STATFS && ! STAT_STATVFS | 181 | # if ! HAVE_STRUCT_STATFS_F_FSTYPENAME |
171 | static char * | 182 | static char * |
172 | fstype_to_string (short int t) | 183 | fstype_to_string (short int t) |
173 | { | 184 | { |
@@ -261,13 +272,12 @@ fstype_to_string (short int t) | |||
261 | return "?"; | 272 | return "?"; |
262 | } | 273 | } |
263 | } | 274 | } |
264 | # endif /* ! HAVE_F_FSTYPENAME_IN_STATFS */ | 275 | # endif |
265 | 276 | ||
266 | /* __NetBSD__ || BSD_NET2 || __OpenBSD__ */ | ||
267 | static char * | 277 | static char * |
268 | fsp_to_string (const struct statfs *fsp) | 278 | fsp_to_string (const struct statfs *fsp) |
269 | { | 279 | { |
270 | # if defined HAVE_F_FSTYPENAME_IN_STATFS || defined STAT_STATVFS | 280 | # if HAVE_STRUCT_STATFS_F_FSTYPENAME |
271 | return (char *) (fsp->f_fstypename); | 281 | return (char *) (fsp->f_fstypename); |
272 | # else | 282 | # else |
273 | return fstype_to_string (fsp->f_type); | 283 | return fstype_to_string (fsp->f_type); |
@@ -290,6 +300,44 @@ fstype_to_string (int t) | |||
290 | } | 300 | } |
291 | #endif /* MOUNTED_VMOUNT */ | 301 | #endif /* MOUNTED_VMOUNT */ |
292 | 302 | ||
303 | |||
304 | #if defined MOUNTED_GETMNTENT1 || defined MOUNTED_GETMNTENT2 | ||
305 | |||
306 | /* Return the device number from MOUNT_OPTIONS, if possible. | ||
307 | Otherwise return (dev_t) -1. */ | ||
308 | |||
309 | static dev_t | ||
310 | dev_from_mount_options (char const *mount_options) | ||
311 | { | ||
312 | /* GNU/Linux allows file system implementations to define their own | ||
313 | meaning for "dev=" mount options, so don't trust the meaning | ||
314 | here. */ | ||
315 | # ifndef __linux__ | ||
316 | |||
317 | static char const dev_pattern[] = ",dev="; | ||
318 | char const *devopt = strstr (mount_options, dev_pattern); | ||
319 | |||
320 | if (devopt) | ||
321 | { | ||
322 | char const *optval = devopt + sizeof dev_pattern - 1; | ||
323 | char *optvalend; | ||
324 | unsigned long int dev; | ||
325 | errno = 0; | ||
326 | dev = strtoul (optval, &optvalend, 16); | ||
327 | if (optval != optvalend | ||
328 | && (*optvalend == '\0' || *optvalend == ',') | ||
329 | && ! (dev == ULONG_MAX && errno == ERANGE) | ||
330 | && dev == (dev_t) dev) | ||
331 | return dev; | ||
332 | } | ||
333 | |||
334 | # endif | ||
335 | |||
336 | return -1; | ||
337 | } | ||
338 | |||
339 | #endif | ||
340 | |||
293 | /* Return a list of the currently mounted file systems, or NULL on error. | 341 | /* Return a list of the currently mounted file systems, or NULL on error. |
294 | Add each entry to the tail of the list so that they stay in order. | 342 | Add each entry to the tail of the list so that they stay in order. |
295 | If NEED_FS_TYPE is true, ensure that the file system type fields in | 343 | If NEED_FS_TYPE is true, ensure that the file system type fields in |
@@ -332,12 +380,11 @@ read_file_system_list (bool need_fs_type) | |||
332 | } | 380 | } |
333 | #endif | 381 | #endif |
334 | 382 | ||
335 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ | 383 | #ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ |
336 | { | 384 | { |
337 | struct mntent *mnt; | 385 | struct mntent *mnt; |
338 | char *table = MOUNTED; | 386 | char *table = MOUNTED; |
339 | FILE *fp; | 387 | FILE *fp; |
340 | char *devopt; | ||
341 | 388 | ||
342 | fp = setmntent (table, "r"); | 389 | fp = setmntent (table, "r"); |
343 | if (fp == NULL) | 390 | if (fp == NULL) |
@@ -352,11 +399,7 @@ read_file_system_list (bool need_fs_type) | |||
352 | me->me_type_malloced = 1; | 399 | me->me_type_malloced = 1; |
353 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 400 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
354 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 401 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
355 | devopt = strstr (mnt->mnt_opts, "dev="); | 402 | me->me_dev = dev_from_mount_options (mnt->mnt_opts); |
356 | if (devopt) | ||
357 | me->me_dev = strtoul (devopt + 4, NULL, 16); | ||
358 | else | ||
359 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | ||
360 | 403 | ||
361 | /* Add to the linked list. */ | 404 | /* Add to the linked list. */ |
362 | *mtail = me; | 405 | *mtail = me; |
@@ -396,6 +439,32 @@ read_file_system_list (bool need_fs_type) | |||
396 | } | 439 | } |
397 | #endif /* MOUNTED_GETMNTINFO */ | 440 | #endif /* MOUNTED_GETMNTINFO */ |
398 | 441 | ||
442 | #ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ | ||
443 | { | ||
444 | struct statvfs *fsp; | ||
445 | int entries; | ||
446 | |||
447 | entries = getmntinfo (&fsp, MNT_NOWAIT); | ||
448 | if (entries < 0) | ||
449 | return NULL; | ||
450 | for (; entries-- > 0; fsp++) | ||
451 | { | ||
452 | me = xmalloc (sizeof *me); | ||
453 | me->me_devname = xstrdup (fsp->f_mntfromname); | ||
454 | me->me_mountdir = xstrdup (fsp->f_mntonname); | ||
455 | me->me_type = xstrdup (fsp->f_fstypename); | ||
456 | me->me_type_malloced = 1; | ||
457 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | ||
458 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | ||
459 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | ||
460 | |||
461 | /* Add to the linked list. */ | ||
462 | *mtail = me; | ||
463 | mtail = &me->me_next; | ||
464 | } | ||
465 | } | ||
466 | #endif /* MOUNTED_GETMNTINFO2 */ | ||
467 | |||
399 | #ifdef MOUNTED_GETMNT /* Ultrix. */ | 468 | #ifdef MOUNTED_GETMNT /* Ultrix. */ |
400 | { | 469 | { |
401 | int offset = 0; | 470 | int offset = 0; |
@@ -630,7 +699,7 @@ read_file_system_list (bool need_fs_type) | |||
630 | } | 699 | } |
631 | #endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ | 700 | #endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ |
632 | 701 | ||
633 | #ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */ | 702 | #ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ |
634 | { | 703 | { |
635 | struct mntent **mnttbl = getmnttbl (), **ent; | 704 | struct mntent **mnttbl = getmnttbl (), **ent; |
636 | for (ent=mnttbl;*ent;ent++) | 705 | for (ent=mnttbl;*ent;ent++) |
@@ -704,7 +773,7 @@ read_file_system_list (bool need_fs_type) | |||
704 | me->me_type_malloced = 1; | 773 | me->me_type_malloced = 1; |
705 | me->me_dummy = MNT_IGNORE (&mnt) != 0; | 774 | me->me_dummy = MNT_IGNORE (&mnt) != 0; |
706 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 775 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
707 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 776 | me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); |
708 | 777 | ||
709 | /* Add to the linked list. */ | 778 | /* Add to the linked list. */ |
710 | *mtail = me; | 779 | *mtail = me; |
diff --git a/lib/mountlist.h b/gl/mountlist.h index 7f5a6f7..7f5a6f7 100644 --- a/lib/mountlist.h +++ b/gl/mountlist.h | |||
diff --git a/lib/open-safer.c b/gl/open-safer.c index d3ba894..04a72eb 100644 --- a/lib/open-safer.c +++ b/gl/open-safer.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* Invoke open, but avoid some glitches. | 1 | /* Invoke open, but avoid some glitches. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +18,7 @@ | |||
17 | 18 | ||
18 | /* Written by Paul Eggert. */ | 19 | /* Written by Paul Eggert. */ |
19 | 20 | ||
20 | #ifdef HAVE_CONFIG_H | 21 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 22 | ||
24 | #include "fcntl-safer.h" | 23 | #include "fcntl-safer.h" |
25 | 24 | ||
diff --git a/lib/pipe-safer.c b/gl/pipe-safer.c index fb02d72..e4431b3 100644 --- a/lib/pipe-safer.c +++ b/gl/pipe-safer.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Invoke pipe, but avoid some glitches. | 1 | /* Invoke pipe, but avoid some glitches. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -17,34 +17,41 @@ | |||
17 | 17 | ||
18 | /* Written by Jim Meyering. */ | 18 | /* Written by Jim Meyering. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | #include "unistd-safer.h" | 22 | #include "unistd-safer.h" |
25 | 23 | ||
26 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <errno.h> | ||
27 | 26 | ||
28 | /* Like pipe, but ensure that neither of the file descriptors is | 27 | /* Like pipe, but ensure that neither of the file descriptors is |
29 | STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ | 28 | STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. Fail with ENOSYS on |
29 | platforms that lack pipe. */ | ||
30 | 30 | ||
31 | int | 31 | int |
32 | pipe_safer (int fd[2]) | 32 | pipe_safer (int fd[2]) |
33 | { | 33 | { |
34 | int fail = pipe (fd); | 34 | #if HAVE_PIPE |
35 | if (fail) | 35 | if (pipe (fd) == 0) |
36 | return fail; | 36 | { |
37 | 37 | int i; | |
38 | { | 38 | for (i = 0; i < 2; i++) |
39 | int i; | 39 | { |
40 | for (i = 0; i < 2; i++) | 40 | fd[i] = fd_safer (fd[i]); |
41 | { | 41 | if (fd[i] < 0) |
42 | int f = fd_safer (fd[i]); | 42 | { |
43 | if (f < 0) | 43 | int e = errno; |
44 | return -1; | 44 | close (fd[1 - i]); |
45 | fd[i] = f; | 45 | errno = e; |
46 | } | 46 | return -1; |
47 | } | 47 | } |
48 | 48 | } | |
49 | return 0; | 49 | |
50 | return 0; | ||
51 | } | ||
52 | #else | ||
53 | errno = ENOSYS; | ||
54 | #endif | ||
55 | |||
56 | return -1; | ||
50 | } | 57 | } |
diff --git a/gl/printf-args.c b/gl/printf-args.c new file mode 100644 index 0000000..358801c --- /dev/null +++ b/gl/printf-args.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* Decomposed printf argument list. | ||
2 | Copyright (C) 1999, 2002-2003, 2005-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "printf-args.h" | ||
22 | |||
23 | #ifdef STATIC | ||
24 | STATIC | ||
25 | #endif | ||
26 | int | ||
27 | printf_fetchargs (va_list args, arguments *a) | ||
28 | { | ||
29 | size_t i; | ||
30 | argument *ap; | ||
31 | |||
32 | for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) | ||
33 | switch (ap->type) | ||
34 | { | ||
35 | case TYPE_SCHAR: | ||
36 | ap->a.a_schar = va_arg (args, /*signed char*/ int); | ||
37 | break; | ||
38 | case TYPE_UCHAR: | ||
39 | ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); | ||
40 | break; | ||
41 | case TYPE_SHORT: | ||
42 | ap->a.a_short = va_arg (args, /*short*/ int); | ||
43 | break; | ||
44 | case TYPE_USHORT: | ||
45 | ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); | ||
46 | break; | ||
47 | case TYPE_INT: | ||
48 | ap->a.a_int = va_arg (args, int); | ||
49 | break; | ||
50 | case TYPE_UINT: | ||
51 | ap->a.a_uint = va_arg (args, unsigned int); | ||
52 | break; | ||
53 | case TYPE_LONGINT: | ||
54 | ap->a.a_longint = va_arg (args, long int); | ||
55 | break; | ||
56 | case TYPE_ULONGINT: | ||
57 | ap->a.a_ulongint = va_arg (args, unsigned long int); | ||
58 | break; | ||
59 | #ifdef HAVE_LONG_LONG_INT | ||
60 | case TYPE_LONGLONGINT: | ||
61 | ap->a.a_longlongint = va_arg (args, long long int); | ||
62 | break; | ||
63 | case TYPE_ULONGLONGINT: | ||
64 | ap->a.a_ulonglongint = va_arg (args, unsigned long long int); | ||
65 | break; | ||
66 | #endif | ||
67 | case TYPE_DOUBLE: | ||
68 | ap->a.a_double = va_arg (args, double); | ||
69 | break; | ||
70 | #ifdef HAVE_LONG_DOUBLE | ||
71 | case TYPE_LONGDOUBLE: | ||
72 | ap->a.a_longdouble = va_arg (args, long double); | ||
73 | break; | ||
74 | #endif | ||
75 | case TYPE_CHAR: | ||
76 | ap->a.a_char = va_arg (args, int); | ||
77 | break; | ||
78 | #ifdef HAVE_WINT_T | ||
79 | case TYPE_WIDE_CHAR: | ||
80 | /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by | ||
81 | default argument promotions", this is not the case in mingw32, | ||
82 | where wint_t is 'unsigned short'. */ | ||
83 | ap->a.a_wide_char = | ||
84 | (sizeof (wint_t) < sizeof (int) | ||
85 | ? va_arg (args, int) | ||
86 | : va_arg (args, wint_t)); | ||
87 | break; | ||
88 | #endif | ||
89 | case TYPE_STRING: | ||
90 | ap->a.a_string = va_arg (args, const char *); | ||
91 | /* A null pointer is an invalid argument for "%s", but in practice | ||
92 | it occurs quite frequently in printf statements that produce | ||
93 | debug output. Use a fallback in this case. */ | ||
94 | if (ap->a.a_string == NULL) | ||
95 | ap->a.a_string = "(NULL)"; | ||
96 | break; | ||
97 | #ifdef HAVE_WCHAR_T | ||
98 | case TYPE_WIDE_STRING: | ||
99 | ap->a.a_wide_string = va_arg (args, const wchar_t *); | ||
100 | /* A null pointer is an invalid argument for "%ls", but in practice | ||
101 | it occurs quite frequently in printf statements that produce | ||
102 | debug output. Use a fallback in this case. */ | ||
103 | if (ap->a.a_wide_string == NULL) | ||
104 | { | ||
105 | static const wchar_t wide_null_string[] = | ||
106 | { | ||
107 | (wchar_t)'(', | ||
108 | (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', | ||
109 | (wchar_t)')', | ||
110 | (wchar_t)0 | ||
111 | }; | ||
112 | ap->a.a_wide_string = wide_null_string; | ||
113 | } | ||
114 | break; | ||
115 | #endif | ||
116 | case TYPE_POINTER: | ||
117 | ap->a.a_pointer = va_arg (args, void *); | ||
118 | break; | ||
119 | case TYPE_COUNT_SCHAR_POINTER: | ||
120 | ap->a.a_count_schar_pointer = va_arg (args, signed char *); | ||
121 | break; | ||
122 | case TYPE_COUNT_SHORT_POINTER: | ||
123 | ap->a.a_count_short_pointer = va_arg (args, short *); | ||
124 | break; | ||
125 | case TYPE_COUNT_INT_POINTER: | ||
126 | ap->a.a_count_int_pointer = va_arg (args, int *); | ||
127 | break; | ||
128 | case TYPE_COUNT_LONGINT_POINTER: | ||
129 | ap->a.a_count_longint_pointer = va_arg (args, long int *); | ||
130 | break; | ||
131 | #ifdef HAVE_LONG_LONG_INT | ||
132 | case TYPE_COUNT_LONGLONGINT_POINTER: | ||
133 | ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); | ||
134 | break; | ||
135 | #endif | ||
136 | default: | ||
137 | /* Unknown type. */ | ||
138 | return -1; | ||
139 | } | ||
140 | return 0; | ||
141 | } | ||
diff --git a/gl/printf-args.h b/gl/printf-args.h new file mode 100644 index 0000000..5759da0 --- /dev/null +++ b/gl/printf-args.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /* Decomposed printf argument list. | ||
2 | Copyright (C) 1999, 2002-2003, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _PRINTF_ARGS_H | ||
19 | #define _PRINTF_ARGS_H | ||
20 | |||
21 | /* Get size_t. */ | ||
22 | #include <stddef.h> | ||
23 | |||
24 | /* Get wchar_t. */ | ||
25 | #ifdef HAVE_WCHAR_T | ||
26 | # include <stddef.h> | ||
27 | #endif | ||
28 | |||
29 | /* Get wint_t. */ | ||
30 | #ifdef HAVE_WINT_T | ||
31 | # include <wchar.h> | ||
32 | #endif | ||
33 | |||
34 | /* Get va_list. */ | ||
35 | #include <stdarg.h> | ||
36 | |||
37 | |||
38 | /* Argument types */ | ||
39 | typedef enum | ||
40 | { | ||
41 | TYPE_NONE, | ||
42 | TYPE_SCHAR, | ||
43 | TYPE_UCHAR, | ||
44 | TYPE_SHORT, | ||
45 | TYPE_USHORT, | ||
46 | TYPE_INT, | ||
47 | TYPE_UINT, | ||
48 | TYPE_LONGINT, | ||
49 | TYPE_ULONGINT, | ||
50 | #ifdef HAVE_LONG_LONG_INT | ||
51 | TYPE_LONGLONGINT, | ||
52 | TYPE_ULONGLONGINT, | ||
53 | #endif | ||
54 | TYPE_DOUBLE, | ||
55 | #ifdef HAVE_LONG_DOUBLE | ||
56 | TYPE_LONGDOUBLE, | ||
57 | #endif | ||
58 | TYPE_CHAR, | ||
59 | #ifdef HAVE_WINT_T | ||
60 | TYPE_WIDE_CHAR, | ||
61 | #endif | ||
62 | TYPE_STRING, | ||
63 | #ifdef HAVE_WCHAR_T | ||
64 | TYPE_WIDE_STRING, | ||
65 | #endif | ||
66 | TYPE_POINTER, | ||
67 | TYPE_COUNT_SCHAR_POINTER, | ||
68 | TYPE_COUNT_SHORT_POINTER, | ||
69 | TYPE_COUNT_INT_POINTER, | ||
70 | TYPE_COUNT_LONGINT_POINTER | ||
71 | #ifdef HAVE_LONG_LONG_INT | ||
72 | , TYPE_COUNT_LONGLONGINT_POINTER | ||
73 | #endif | ||
74 | } arg_type; | ||
75 | |||
76 | /* Polymorphic argument */ | ||
77 | typedef struct | ||
78 | { | ||
79 | arg_type type; | ||
80 | union | ||
81 | { | ||
82 | signed char a_schar; | ||
83 | unsigned char a_uchar; | ||
84 | short a_short; | ||
85 | unsigned short a_ushort; | ||
86 | int a_int; | ||
87 | unsigned int a_uint; | ||
88 | long int a_longint; | ||
89 | unsigned long int a_ulongint; | ||
90 | #ifdef HAVE_LONG_LONG_INT | ||
91 | long long int a_longlongint; | ||
92 | unsigned long long int a_ulonglongint; | ||
93 | #endif | ||
94 | float a_float; | ||
95 | double a_double; | ||
96 | #ifdef HAVE_LONG_DOUBLE | ||
97 | long double a_longdouble; | ||
98 | #endif | ||
99 | int a_char; | ||
100 | #ifdef HAVE_WINT_T | ||
101 | wint_t a_wide_char; | ||
102 | #endif | ||
103 | const char* a_string; | ||
104 | #ifdef HAVE_WCHAR_T | ||
105 | const wchar_t* a_wide_string; | ||
106 | #endif | ||
107 | void* a_pointer; | ||
108 | signed char * a_count_schar_pointer; | ||
109 | short * a_count_short_pointer; | ||
110 | int * a_count_int_pointer; | ||
111 | long int * a_count_longint_pointer; | ||
112 | #ifdef HAVE_LONG_LONG_INT | ||
113 | long long int * a_count_longlongint_pointer; | ||
114 | #endif | ||
115 | } | ||
116 | a; | ||
117 | } | ||
118 | argument; | ||
119 | |||
120 | typedef struct | ||
121 | { | ||
122 | size_t count; | ||
123 | argument *arg; | ||
124 | } | ||
125 | arguments; | ||
126 | |||
127 | |||
128 | /* Fetch the arguments, putting them into a. */ | ||
129 | #ifdef STATIC | ||
130 | STATIC | ||
131 | #else | ||
132 | extern | ||
133 | #endif | ||
134 | int printf_fetchargs (va_list args, arguments *a); | ||
135 | |||
136 | #endif /* _PRINTF_ARGS_H */ | ||
diff --git a/gl/printf-parse.c b/gl/printf-parse.c new file mode 100644 index 0000000..9a86f77 --- /dev/null +++ b/gl/printf-parse.c | |||
@@ -0,0 +1,543 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 1999-2000, 2002-2003, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #if WIDE_CHAR_VERSION | ||
22 | # include "wprintf-parse.h" | ||
23 | #else | ||
24 | # include "printf-parse.h" | ||
25 | #endif | ||
26 | |||
27 | /* Get size_t, NULL. */ | ||
28 | #include <stddef.h> | ||
29 | |||
30 | /* Get intmax_t. */ | ||
31 | #if HAVE_STDINT_H_WITH_UINTMAX | ||
32 | # include <stdint.h> | ||
33 | #endif | ||
34 | #if HAVE_INTTYPES_H_WITH_UINTMAX | ||
35 | # include <inttypes.h> | ||
36 | #endif | ||
37 | |||
38 | /* malloc(), realloc(), free(). */ | ||
39 | #include <stdlib.h> | ||
40 | |||
41 | /* Checked size_t computations. */ | ||
42 | #include "xsize.h" | ||
43 | |||
44 | #if WIDE_CHAR_VERSION | ||
45 | # define PRINTF_PARSE wprintf_parse | ||
46 | # define CHAR_T wchar_t | ||
47 | # define DIRECTIVE wchar_t_directive | ||
48 | # define DIRECTIVES wchar_t_directives | ||
49 | #else | ||
50 | # define PRINTF_PARSE printf_parse | ||
51 | # define CHAR_T char | ||
52 | # define DIRECTIVE char_directive | ||
53 | # define DIRECTIVES char_directives | ||
54 | #endif | ||
55 | |||
56 | #ifdef STATIC | ||
57 | STATIC | ||
58 | #endif | ||
59 | int | ||
60 | PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) | ||
61 | { | ||
62 | const CHAR_T *cp = format; /* pointer into format */ | ||
63 | size_t arg_posn = 0; /* number of regular arguments consumed */ | ||
64 | size_t d_allocated; /* allocated elements of d->dir */ | ||
65 | size_t a_allocated; /* allocated elements of a->arg */ | ||
66 | size_t max_width_length = 0; | ||
67 | size_t max_precision_length = 0; | ||
68 | |||
69 | d->count = 0; | ||
70 | d_allocated = 1; | ||
71 | d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); | ||
72 | if (d->dir == NULL) | ||
73 | /* Out of memory. */ | ||
74 | return -1; | ||
75 | |||
76 | a->count = 0; | ||
77 | a_allocated = 0; | ||
78 | a->arg = NULL; | ||
79 | |||
80 | #define REGISTER_ARG(_index_,_type_) \ | ||
81 | { \ | ||
82 | size_t n = (_index_); \ | ||
83 | if (n >= a_allocated) \ | ||
84 | { \ | ||
85 | size_t memory_size; \ | ||
86 | argument *memory; \ | ||
87 | \ | ||
88 | a_allocated = xtimes (a_allocated, 2); \ | ||
89 | if (a_allocated <= n) \ | ||
90 | a_allocated = xsum (n, 1); \ | ||
91 | memory_size = xtimes (a_allocated, sizeof (argument)); \ | ||
92 | if (size_overflow_p (memory_size)) \ | ||
93 | /* Overflow, would lead to out of memory. */ \ | ||
94 | goto error; \ | ||
95 | memory = (argument *) (a->arg \ | ||
96 | ? realloc (a->arg, memory_size) \ | ||
97 | : malloc (memory_size)); \ | ||
98 | if (memory == NULL) \ | ||
99 | /* Out of memory. */ \ | ||
100 | goto error; \ | ||
101 | a->arg = memory; \ | ||
102 | } \ | ||
103 | while (a->count <= n) \ | ||
104 | a->arg[a->count++].type = TYPE_NONE; \ | ||
105 | if (a->arg[n].type == TYPE_NONE) \ | ||
106 | a->arg[n].type = (_type_); \ | ||
107 | else if (a->arg[n].type != (_type_)) \ | ||
108 | /* Ambiguous type for positional argument. */ \ | ||
109 | goto error; \ | ||
110 | } | ||
111 | |||
112 | while (*cp != '\0') | ||
113 | { | ||
114 | CHAR_T c = *cp++; | ||
115 | if (c == '%') | ||
116 | { | ||
117 | size_t arg_index = ARG_NONE; | ||
118 | DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ | ||
119 | |||
120 | /* Initialize the next directive. */ | ||
121 | dp->dir_start = cp - 1; | ||
122 | dp->flags = 0; | ||
123 | dp->width_start = NULL; | ||
124 | dp->width_end = NULL; | ||
125 | dp->width_arg_index = ARG_NONE; | ||
126 | dp->precision_start = NULL; | ||
127 | dp->precision_end = NULL; | ||
128 | dp->precision_arg_index = ARG_NONE; | ||
129 | dp->arg_index = ARG_NONE; | ||
130 | |||
131 | /* Test for positional argument. */ | ||
132 | if (*cp >= '0' && *cp <= '9') | ||
133 | { | ||
134 | const CHAR_T *np; | ||
135 | |||
136 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
137 | ; | ||
138 | if (*np == '$') | ||
139 | { | ||
140 | size_t n = 0; | ||
141 | |||
142 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
143 | n = xsum (xtimes (n, 10), *np - '0'); | ||
144 | if (n == 0) | ||
145 | /* Positional argument 0. */ | ||
146 | goto error; | ||
147 | if (size_overflow_p (n)) | ||
148 | /* n too large, would lead to out of memory later. */ | ||
149 | goto error; | ||
150 | arg_index = n - 1; | ||
151 | cp = np + 1; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /* Read the flags. */ | ||
156 | for (;;) | ||
157 | { | ||
158 | if (*cp == '\'') | ||
159 | { | ||
160 | dp->flags |= FLAG_GROUP; | ||
161 | cp++; | ||
162 | } | ||
163 | else if (*cp == '-') | ||
164 | { | ||
165 | dp->flags |= FLAG_LEFT; | ||
166 | cp++; | ||
167 | } | ||
168 | else if (*cp == '+') | ||
169 | { | ||
170 | dp->flags |= FLAG_SHOWSIGN; | ||
171 | cp++; | ||
172 | } | ||
173 | else if (*cp == ' ') | ||
174 | { | ||
175 | dp->flags |= FLAG_SPACE; | ||
176 | cp++; | ||
177 | } | ||
178 | else if (*cp == '#') | ||
179 | { | ||
180 | dp->flags |= FLAG_ALT; | ||
181 | cp++; | ||
182 | } | ||
183 | else if (*cp == '0') | ||
184 | { | ||
185 | dp->flags |= FLAG_ZERO; | ||
186 | cp++; | ||
187 | } | ||
188 | else | ||
189 | break; | ||
190 | } | ||
191 | |||
192 | /* Parse the field width. */ | ||
193 | if (*cp == '*') | ||
194 | { | ||
195 | dp->width_start = cp; | ||
196 | cp++; | ||
197 | dp->width_end = cp; | ||
198 | if (max_width_length < 1) | ||
199 | max_width_length = 1; | ||
200 | |||
201 | /* Test for positional argument. */ | ||
202 | if (*cp >= '0' && *cp <= '9') | ||
203 | { | ||
204 | const CHAR_T *np; | ||
205 | |||
206 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
207 | ; | ||
208 | if (*np == '$') | ||
209 | { | ||
210 | size_t n = 0; | ||
211 | |||
212 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
213 | n = xsum (xtimes (n, 10), *np - '0'); | ||
214 | if (n == 0) | ||
215 | /* Positional argument 0. */ | ||
216 | goto error; | ||
217 | if (size_overflow_p (n)) | ||
218 | /* n too large, would lead to out of memory later. */ | ||
219 | goto error; | ||
220 | dp->width_arg_index = n - 1; | ||
221 | cp = np + 1; | ||
222 | } | ||
223 | } | ||
224 | if (dp->width_arg_index == ARG_NONE) | ||
225 | { | ||
226 | dp->width_arg_index = arg_posn++; | ||
227 | if (dp->width_arg_index == ARG_NONE) | ||
228 | /* arg_posn wrapped around. */ | ||
229 | goto error; | ||
230 | } | ||
231 | REGISTER_ARG (dp->width_arg_index, TYPE_INT); | ||
232 | } | ||
233 | else if (*cp >= '0' && *cp <= '9') | ||
234 | { | ||
235 | size_t width_length; | ||
236 | |||
237 | dp->width_start = cp; | ||
238 | for (; *cp >= '0' && *cp <= '9'; cp++) | ||
239 | ; | ||
240 | dp->width_end = cp; | ||
241 | width_length = dp->width_end - dp->width_start; | ||
242 | if (max_width_length < width_length) | ||
243 | max_width_length = width_length; | ||
244 | } | ||
245 | |||
246 | /* Parse the precision. */ | ||
247 | if (*cp == '.') | ||
248 | { | ||
249 | cp++; | ||
250 | if (*cp == '*') | ||
251 | { | ||
252 | dp->precision_start = cp - 1; | ||
253 | cp++; | ||
254 | dp->precision_end = cp; | ||
255 | if (max_precision_length < 2) | ||
256 | max_precision_length = 2; | ||
257 | |||
258 | /* Test for positional argument. */ | ||
259 | if (*cp >= '0' && *cp <= '9') | ||
260 | { | ||
261 | const CHAR_T *np; | ||
262 | |||
263 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
264 | ; | ||
265 | if (*np == '$') | ||
266 | { | ||
267 | size_t n = 0; | ||
268 | |||
269 | for (np = cp; *np >= '0' && *np <= '9'; np++) | ||
270 | n = xsum (xtimes (n, 10), *np - '0'); | ||
271 | if (n == 0) | ||
272 | /* Positional argument 0. */ | ||
273 | goto error; | ||
274 | if (size_overflow_p (n)) | ||
275 | /* n too large, would lead to out of memory | ||
276 | later. */ | ||
277 | goto error; | ||
278 | dp->precision_arg_index = n - 1; | ||
279 | cp = np + 1; | ||
280 | } | ||
281 | } | ||
282 | if (dp->precision_arg_index == ARG_NONE) | ||
283 | { | ||
284 | dp->precision_arg_index = arg_posn++; | ||
285 | if (dp->precision_arg_index == ARG_NONE) | ||
286 | /* arg_posn wrapped around. */ | ||
287 | goto error; | ||
288 | } | ||
289 | REGISTER_ARG (dp->precision_arg_index, TYPE_INT); | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | size_t precision_length; | ||
294 | |||
295 | dp->precision_start = cp - 1; | ||
296 | for (; *cp >= '0' && *cp <= '9'; cp++) | ||
297 | ; | ||
298 | dp->precision_end = cp; | ||
299 | precision_length = dp->precision_end - dp->precision_start; | ||
300 | if (max_precision_length < precision_length) | ||
301 | max_precision_length = precision_length; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | { | ||
306 | arg_type type; | ||
307 | |||
308 | /* Parse argument type/size specifiers. */ | ||
309 | { | ||
310 | int flags = 0; | ||
311 | |||
312 | for (;;) | ||
313 | { | ||
314 | if (*cp == 'h') | ||
315 | { | ||
316 | flags |= (1 << (flags & 1)); | ||
317 | cp++; | ||
318 | } | ||
319 | else if (*cp == 'L') | ||
320 | { | ||
321 | flags |= 4; | ||
322 | cp++; | ||
323 | } | ||
324 | else if (*cp == 'l') | ||
325 | { | ||
326 | flags += 8; | ||
327 | cp++; | ||
328 | } | ||
329 | #ifdef HAVE_INTMAX_T | ||
330 | else if (*cp == 'j') | ||
331 | { | ||
332 | if (sizeof (intmax_t) > sizeof (long)) | ||
333 | { | ||
334 | /* intmax_t = long long */ | ||
335 | flags += 16; | ||
336 | } | ||
337 | else if (sizeof (intmax_t) > sizeof (int)) | ||
338 | { | ||
339 | /* intmax_t = long */ | ||
340 | flags += 8; | ||
341 | } | ||
342 | cp++; | ||
343 | } | ||
344 | #endif | ||
345 | else if (*cp == 'z' || *cp == 'Z') | ||
346 | { | ||
347 | /* 'z' is standardized in ISO C 99, but glibc uses 'Z' | ||
348 | because the warning facility in gcc-2.95.2 understands | ||
349 | only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ | ||
350 | if (sizeof (size_t) > sizeof (long)) | ||
351 | { | ||
352 | /* size_t = long long */ | ||
353 | flags += 16; | ||
354 | } | ||
355 | else if (sizeof (size_t) > sizeof (int)) | ||
356 | { | ||
357 | /* size_t = long */ | ||
358 | flags += 8; | ||
359 | } | ||
360 | cp++; | ||
361 | } | ||
362 | else if (*cp == 't') | ||
363 | { | ||
364 | if (sizeof (ptrdiff_t) > sizeof (long)) | ||
365 | { | ||
366 | /* ptrdiff_t = long long */ | ||
367 | flags += 16; | ||
368 | } | ||
369 | else if (sizeof (ptrdiff_t) > sizeof (int)) | ||
370 | { | ||
371 | /* ptrdiff_t = long */ | ||
372 | flags += 8; | ||
373 | } | ||
374 | cp++; | ||
375 | } | ||
376 | else | ||
377 | break; | ||
378 | } | ||
379 | |||
380 | /* Read the conversion character. */ | ||
381 | c = *cp++; | ||
382 | switch (c) | ||
383 | { | ||
384 | case 'd': case 'i': | ||
385 | #ifdef HAVE_LONG_LONG_INT | ||
386 | /* If 'long long' exists and is larger than 'long': */ | ||
387 | if (flags >= 16 || (flags & 4)) | ||
388 | type = TYPE_LONGLONGINT; | ||
389 | else | ||
390 | #endif | ||
391 | /* If 'long long' exists and is the same as 'long', we parse | ||
392 | "lld" into TYPE_LONGINT. */ | ||
393 | if (flags >= 8) | ||
394 | type = TYPE_LONGINT; | ||
395 | else if (flags & 2) | ||
396 | type = TYPE_SCHAR; | ||
397 | else if (flags & 1) | ||
398 | type = TYPE_SHORT; | ||
399 | else | ||
400 | type = TYPE_INT; | ||
401 | break; | ||
402 | case 'o': case 'u': case 'x': case 'X': | ||
403 | #ifdef HAVE_LONG_LONG_INT | ||
404 | /* If 'long long' exists and is larger than 'long': */ | ||
405 | if (flags >= 16 || (flags & 4)) | ||
406 | type = TYPE_ULONGLONGINT; | ||
407 | else | ||
408 | #endif | ||
409 | /* If 'unsigned long long' exists and is the same as | ||
410 | 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ | ||
411 | if (flags >= 8) | ||
412 | type = TYPE_ULONGINT; | ||
413 | else if (flags & 2) | ||
414 | type = TYPE_UCHAR; | ||
415 | else if (flags & 1) | ||
416 | type = TYPE_USHORT; | ||
417 | else | ||
418 | type = TYPE_UINT; | ||
419 | break; | ||
420 | case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': | ||
421 | case 'a': case 'A': | ||
422 | #ifdef HAVE_LONG_DOUBLE | ||
423 | if (flags >= 16 || (flags & 4)) | ||
424 | type = TYPE_LONGDOUBLE; | ||
425 | else | ||
426 | #endif | ||
427 | type = TYPE_DOUBLE; | ||
428 | break; | ||
429 | case 'c': | ||
430 | if (flags >= 8) | ||
431 | #ifdef HAVE_WINT_T | ||
432 | type = TYPE_WIDE_CHAR; | ||
433 | #else | ||
434 | goto error; | ||
435 | #endif | ||
436 | else | ||
437 | type = TYPE_CHAR; | ||
438 | break; | ||
439 | #ifdef HAVE_WINT_T | ||
440 | case 'C': | ||
441 | type = TYPE_WIDE_CHAR; | ||
442 | c = 'c'; | ||
443 | break; | ||
444 | #endif | ||
445 | case 's': | ||
446 | if (flags >= 8) | ||
447 | #ifdef HAVE_WCHAR_T | ||
448 | type = TYPE_WIDE_STRING; | ||
449 | #else | ||
450 | goto error; | ||
451 | #endif | ||
452 | else | ||
453 | type = TYPE_STRING; | ||
454 | break; | ||
455 | #ifdef HAVE_WCHAR_T | ||
456 | case 'S': | ||
457 | type = TYPE_WIDE_STRING; | ||
458 | c = 's'; | ||
459 | break; | ||
460 | #endif | ||
461 | case 'p': | ||
462 | type = TYPE_POINTER; | ||
463 | break; | ||
464 | case 'n': | ||
465 | #ifdef HAVE_LONG_LONG_INT | ||
466 | /* If 'long long' exists and is larger than 'long': */ | ||
467 | if (flags >= 16 || (flags & 4)) | ||
468 | type = TYPE_COUNT_LONGLONGINT_POINTER; | ||
469 | else | ||
470 | #endif | ||
471 | /* If 'long long' exists and is the same as 'long', we parse | ||
472 | "lln" into TYPE_COUNT_LONGINT_POINTER. */ | ||
473 | if (flags >= 8) | ||
474 | type = TYPE_COUNT_LONGINT_POINTER; | ||
475 | else if (flags & 2) | ||
476 | type = TYPE_COUNT_SCHAR_POINTER; | ||
477 | else if (flags & 1) | ||
478 | type = TYPE_COUNT_SHORT_POINTER; | ||
479 | else | ||
480 | type = TYPE_COUNT_INT_POINTER; | ||
481 | break; | ||
482 | case '%': | ||
483 | type = TYPE_NONE; | ||
484 | break; | ||
485 | default: | ||
486 | /* Unknown conversion character. */ | ||
487 | goto error; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | if (type != TYPE_NONE) | ||
492 | { | ||
493 | dp->arg_index = arg_index; | ||
494 | if (dp->arg_index == ARG_NONE) | ||
495 | { | ||
496 | dp->arg_index = arg_posn++; | ||
497 | if (dp->arg_index == ARG_NONE) | ||
498 | /* arg_posn wrapped around. */ | ||
499 | goto error; | ||
500 | } | ||
501 | REGISTER_ARG (dp->arg_index, type); | ||
502 | } | ||
503 | dp->conversion = c; | ||
504 | dp->dir_end = cp; | ||
505 | } | ||
506 | |||
507 | d->count++; | ||
508 | if (d->count >= d_allocated) | ||
509 | { | ||
510 | size_t memory_size; | ||
511 | DIRECTIVE *memory; | ||
512 | |||
513 | d_allocated = xtimes (d_allocated, 2); | ||
514 | memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); | ||
515 | if (size_overflow_p (memory_size)) | ||
516 | /* Overflow, would lead to out of memory. */ | ||
517 | goto error; | ||
518 | memory = (DIRECTIVE *) realloc (d->dir, memory_size); | ||
519 | if (memory == NULL) | ||
520 | /* Out of memory. */ | ||
521 | goto error; | ||
522 | d->dir = memory; | ||
523 | } | ||
524 | } | ||
525 | } | ||
526 | d->dir[d->count].dir_start = cp; | ||
527 | |||
528 | d->max_width_length = max_width_length; | ||
529 | d->max_precision_length = max_precision_length; | ||
530 | return 0; | ||
531 | |||
532 | error: | ||
533 | if (a->arg) | ||
534 | free (a->arg); | ||
535 | if (d->dir) | ||
536 | free (d->dir); | ||
537 | return -1; | ||
538 | } | ||
539 | |||
540 | #undef DIRECTIVES | ||
541 | #undef DIRECTIVE | ||
542 | #undef CHAR_T | ||
543 | #undef PRINTF_PARSE | ||
diff --git a/gl/printf-parse.h b/gl/printf-parse.h new file mode 100644 index 0000000..82a0d37 --- /dev/null +++ b/gl/printf-parse.h | |||
@@ -0,0 +1,74 @@ | |||
1 | /* Parse printf format string. | ||
2 | Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _PRINTF_PARSE_H | ||
19 | #define _PRINTF_PARSE_H | ||
20 | |||
21 | #include "printf-args.h" | ||
22 | |||
23 | |||
24 | /* Flags */ | ||
25 | #define FLAG_GROUP 1 /* ' flag */ | ||
26 | #define FLAG_LEFT 2 /* - flag */ | ||
27 | #define FLAG_SHOWSIGN 4 /* + flag */ | ||
28 | #define FLAG_SPACE 8 /* space flag */ | ||
29 | #define FLAG_ALT 16 /* # flag */ | ||
30 | #define FLAG_ZERO 32 | ||
31 | |||
32 | /* arg_index value indicating that no argument is consumed. */ | ||
33 | #define ARG_NONE (~(size_t)0) | ||
34 | |||
35 | /* A parsed directive. */ | ||
36 | typedef struct | ||
37 | { | ||
38 | const char* dir_start; | ||
39 | const char* dir_end; | ||
40 | int flags; | ||
41 | const char* width_start; | ||
42 | const char* width_end; | ||
43 | size_t width_arg_index; | ||
44 | const char* precision_start; | ||
45 | const char* precision_end; | ||
46 | size_t precision_arg_index; | ||
47 | char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ | ||
48 | size_t arg_index; | ||
49 | } | ||
50 | char_directive; | ||
51 | |||
52 | /* A parsed format string. */ | ||
53 | typedef struct | ||
54 | { | ||
55 | size_t count; | ||
56 | char_directive *dir; | ||
57 | size_t max_width_length; | ||
58 | size_t max_precision_length; | ||
59 | } | ||
60 | char_directives; | ||
61 | |||
62 | |||
63 | /* Parses the format string. Fills in the number N of directives, and fills | ||
64 | in directives[0], ..., directives[N-1], and sets directives[N].dir_start | ||
65 | to the end of the format string. Also fills in the arg_type fields of the | ||
66 | arguments and the needed count of arguments. */ | ||
67 | #ifdef STATIC | ||
68 | STATIC | ||
69 | #else | ||
70 | extern | ||
71 | #endif | ||
72 | int printf_parse (const char *format, char_directives *d, arguments *a); | ||
73 | |||
74 | #endif /* _PRINTF_PARSE_H */ | ||
diff --git a/lib/regcomp.c b/gl/regcomp.c index 279b20c..8df6bb8 100644 --- a/lib/regcomp.c +++ b/gl/regcomp.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
@@ -18,11 +18,11 @@ | |||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, | 20 | static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, |
21 | Idx length, reg_syntax_t syntax); | 21 | size_t length, reg_syntax_t syntax); |
22 | static void re_compile_fastmap_iter (regex_t *bufp, | 22 | static void re_compile_fastmap_iter (regex_t *bufp, |
23 | const re_dfastate_t *init_state, | 23 | const re_dfastate_t *init_state, |
24 | char *fastmap); | 24 | char *fastmap); |
25 | static reg_errcode_t init_dfa (re_dfa_t *dfa, Idx pat_len); | 25 | static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len); |
26 | #ifdef RE_ENABLE_I18N | 26 | #ifdef RE_ENABLE_I18N |
27 | static void free_charset (re_charset_t *cset); | 27 | static void free_charset (re_charset_t *cset); |
28 | #endif /* RE_ENABLE_I18N */ | 28 | #endif /* RE_ENABLE_I18N */ |
@@ -55,7 +55,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa); | |||
55 | static Idx fetch_number (re_string_t *input, re_token_t *token, | 55 | static Idx fetch_number (re_string_t *input, re_token_t *token, |
56 | reg_syntax_t syntax); | 56 | reg_syntax_t syntax); |
57 | static int peek_token (re_token_t *token, re_string_t *input, | 57 | static int peek_token (re_token_t *token, re_string_t *input, |
58 | reg_syntax_t syntax); | 58 | reg_syntax_t syntax) internal_function; |
59 | static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, | 59 | static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, |
60 | reg_syntax_t syntax, reg_errcode_t *err); | 60 | reg_syntax_t syntax, reg_errcode_t *err); |
61 | static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg, | 61 | 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, | |||
86 | re_string_t *regexp, | 86 | re_string_t *regexp, |
87 | re_token_t *token); | 87 | re_token_t *token); |
88 | #ifdef RE_ENABLE_I18N | 88 | #ifdef RE_ENABLE_I18N |
89 | static reg_errcode_t build_equiv_class (bitset sbcset, | 89 | static reg_errcode_t build_equiv_class (bitset_t sbcset, |
90 | re_charset_t *mbcset, | 90 | re_charset_t *mbcset, |
91 | Idx *equiv_class_alloc, | 91 | Idx *equiv_class_alloc, |
92 | const unsigned char *name); | 92 | const unsigned char *name); |
93 | static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans, | 93 | static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, |
94 | bitset sbcset, | 94 | bitset_t sbcset, |
95 | re_charset_t *mbcset, | 95 | re_charset_t *mbcset, |
96 | Idx *char_class_alloc, | 96 | Idx *char_class_alloc, |
97 | const unsigned char *class_name, | 97 | const unsigned char *class_name, |
98 | reg_syntax_t syntax); | 98 | reg_syntax_t syntax); |
99 | #else /* not RE_ENABLE_I18N */ | 99 | #else /* not RE_ENABLE_I18N */ |
100 | static reg_errcode_t build_equiv_class (bitset sbcset, | 100 | static reg_errcode_t build_equiv_class (bitset_t sbcset, |
101 | const unsigned char *name); | 101 | const unsigned char *name); |
102 | static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans, | 102 | static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, |
103 | bitset sbcset, | 103 | bitset_t sbcset, |
104 | const unsigned char *class_name, | 104 | const unsigned char *class_name, |
105 | reg_syntax_t syntax); | 105 | reg_syntax_t syntax); |
106 | #endif /* not RE_ENABLE_I18N */ | 106 | #endif /* not RE_ENABLE_I18N */ |
107 | static bin_tree_t *build_charclass_op (re_dfa_t *dfa, | 107 | static bin_tree_t *build_charclass_op (re_dfa_t *dfa, |
108 | unsigned REG_TRANSLATE_TYPE trans, | 108 | RE_TRANSLATE_TYPE trans, |
109 | const unsigned char *class_name, | 109 | const unsigned char *class_name, |
110 | const unsigned char *extra, | 110 | const unsigned char *extra, |
111 | bool non_match, reg_errcode_t *err); | 111 | bool non_match, reg_errcode_t *err); |
@@ -125,7 +125,7 @@ static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node); | |||
125 | POSIX doesn't require that we do anything for REG_NOERROR, | 125 | POSIX doesn't require that we do anything for REG_NOERROR, |
126 | but why not be nice? */ | 126 | but why not be nice? */ |
127 | 127 | ||
128 | const char __re_error_msgid[] attribute_hidden = | 128 | static const char __re_error_msgid[] = |
129 | { | 129 | { |
130 | #define REG_NOERROR_IDX 0 | 130 | #define REG_NOERROR_IDX 0 |
131 | gettext_noop ("Success") /* REG_NOERROR */ | 131 | gettext_noop ("Success") /* REG_NOERROR */ |
@@ -179,7 +179,7 @@ const char __re_error_msgid[] attribute_hidden = | |||
179 | gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ | 179 | gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ |
180 | }; | 180 | }; |
181 | 181 | ||
182 | const size_t __re_error_msgid_idx[] attribute_hidden = | 182 | static const size_t __re_error_msgid_idx[] = |
183 | { | 183 | { |
184 | REG_NOERROR_IDX, | 184 | REG_NOERROR_IDX, |
185 | REG_NOMATCH_IDX, | 185 | REG_NOMATCH_IDX, |
@@ -206,22 +206,30 @@ const size_t __re_error_msgid_idx[] attribute_hidden = | |||
206 | compiles PATTERN (of length LENGTH) and puts the result in BUFP. | 206 | compiles PATTERN (of length LENGTH) and puts the result in BUFP. |
207 | Returns 0 if the pattern was valid, otherwise an error string. | 207 | Returns 0 if the pattern was valid, otherwise an error string. |
208 | 208 | ||
209 | Assumes the `re_allocated' (and perhaps `re_buffer') and `translate' fields | 209 | Assumes the `allocated' (and perhaps `buffer') and `translate' fields |
210 | are set in BUFP on entry. */ | 210 | are set in BUFP on entry. */ |
211 | 211 | ||
212 | #ifdef _LIBC | ||
213 | const char * | ||
214 | re_compile_pattern (pattern, length, bufp) | ||
215 | const char *pattern; | ||
216 | size_t length; | ||
217 | struct re_pattern_buffer *bufp; | ||
218 | #else /* size_t might promote */ | ||
212 | const char * | 219 | const char * |
213 | re_compile_pattern (const char *pattern, size_t length, | 220 | re_compile_pattern (const char *pattern, size_t length, |
214 | struct re_pattern_buffer *bufp) | 221 | struct re_pattern_buffer *bufp) |
222 | #endif | ||
215 | { | 223 | { |
216 | reg_errcode_t ret; | 224 | reg_errcode_t ret; |
217 | 225 | ||
218 | /* And GNU code determines whether or not to get register information | 226 | /* And GNU code determines whether or not to get register information |
219 | by passing null for the REGS argument to re_match, etc., not by | 227 | by passing null for the REGS argument to re_match, etc., not by |
220 | setting re_no_sub, unless REG_NO_SUB is set. */ | 228 | setting no_sub, unless RE_NO_SUB is set. */ |
221 | bufp->re_no_sub = !!(re_syntax_options & REG_NO_SUB); | 229 | bufp->no_sub = !!(re_syntax_options & RE_NO_SUB); |
222 | 230 | ||
223 | /* Match anchors at newline. */ | 231 | /* Match anchors at newline. */ |
224 | bufp->re_newline_anchor = 1; | 232 | bufp->newline_anchor = 1; |
225 | 233 | ||
226 | ret = re_compile_internal (bufp, pattern, length, re_syntax_options); | 234 | ret = re_compile_internal (bufp, pattern, length, re_syntax_options); |
227 | 235 | ||
@@ -249,7 +257,8 @@ reg_syntax_t re_syntax_options; | |||
249 | defined in regex.h. We return the old syntax. */ | 257 | defined in regex.h. We return the old syntax. */ |
250 | 258 | ||
251 | reg_syntax_t | 259 | reg_syntax_t |
252 | re_set_syntax (reg_syntax_t syntax) | 260 | re_set_syntax (syntax) |
261 | reg_syntax_t syntax; | ||
253 | { | 262 | { |
254 | reg_syntax_t ret = re_syntax_options; | 263 | reg_syntax_t ret = re_syntax_options; |
255 | 264 | ||
@@ -261,10 +270,11 @@ weak_alias (__re_set_syntax, re_set_syntax) | |||
261 | #endif | 270 | #endif |
262 | 271 | ||
263 | int | 272 | int |
264 | re_compile_fastmap (struct re_pattern_buffer *bufp) | 273 | re_compile_fastmap (bufp) |
274 | struct re_pattern_buffer *bufp; | ||
265 | { | 275 | { |
266 | re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; | 276 | re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; |
267 | char *fastmap = bufp->re_fastmap; | 277 | char *fastmap = bufp->fastmap; |
268 | 278 | ||
269 | memset (fastmap, '\0', sizeof (char) * SBC_MAX); | 279 | memset (fastmap, '\0', sizeof (char) * SBC_MAX); |
270 | re_compile_fastmap_iter (bufp, dfa->init_state, fastmap); | 280 | re_compile_fastmap_iter (bufp, dfa->init_state, fastmap); |
@@ -274,7 +284,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp) | |||
274 | re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap); | 284 | re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap); |
275 | if (dfa->init_state != dfa->init_state_begbuf) | 285 | if (dfa->init_state != dfa->init_state_begbuf) |
276 | re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap); | 286 | re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap); |
277 | bufp->re_fastmap_accurate = 1; | 287 | bufp->fastmap_accurate = 1; |
278 | return 0; | 288 | return 0; |
279 | } | 289 | } |
280 | #ifdef _LIBC | 290 | #ifdef _LIBC |
@@ -297,9 +307,9 @@ static void | |||
297 | re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | 307 | re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, |
298 | char *fastmap) | 308 | char *fastmap) |
299 | { | 309 | { |
300 | re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; | 310 | re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; |
301 | Idx node_cnt; | 311 | Idx node_cnt; |
302 | bool icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE)); | 312 | bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE)); |
303 | for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) | 313 | for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) |
304 | { | 314 | { |
305 | Idx node = init_state->nodes.elems[node_cnt]; | 315 | 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, | |||
309 | { | 319 | { |
310 | re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c); | 320 | re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c); |
311 | #ifdef RE_ENABLE_I18N | 321 | #ifdef RE_ENABLE_I18N |
312 | if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1) | 322 | if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) |
313 | { | 323 | { |
314 | unsigned char buf[MB_LEN_MAX]; | 324 | unsigned char buf[MB_LEN_MAX]; |
315 | unsigned char *p; | 325 | unsigned char *p; |
@@ -322,7 +332,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | |||
322 | && dfa->nodes[node].type == CHARACTER | 332 | && dfa->nodes[node].type == CHARACTER |
323 | && dfa->nodes[node].mb_partial) | 333 | && dfa->nodes[node].mb_partial) |
324 | *p++ = dfa->nodes[node].opr.c; | 334 | *p++ = dfa->nodes[node].opr.c; |
325 | memset (&state, 0, sizeof (state)); | 335 | memset (&state, '\0', sizeof (state)); |
326 | if (mbrtowc (&wc, (const char *) buf, p - buf, | 336 | if (mbrtowc (&wc, (const char *) buf, p - buf, |
327 | &state) == p - buf | 337 | &state) == p - buf |
328 | && (__wcrtomb ((char *) buf, towlower (wc), &state) | 338 | && (__wcrtomb ((char *) buf, towlower (wc), &state) |
@@ -333,11 +343,15 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | |||
333 | } | 343 | } |
334 | else if (type == SIMPLE_BRACKET) | 344 | else if (type == SIMPLE_BRACKET) |
335 | { | 345 | { |
336 | int i, j, ch; | 346 | int i, ch; |
337 | for (i = 0, ch = 0; i < BITSET_WORDS; ++i) | 347 | for (i = 0, ch = 0; i < BITSET_WORDS; ++i) |
338 | for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) | 348 | { |
339 | if (dfa->nodes[node].opr.sbcset[i] & ((bitset_word) 1 << j)) | 349 | int j; |
340 | re_set_fastmap (fastmap, icase, ch); | 350 | bitset_word_t w = dfa->nodes[node].opr.sbcset[i]; |
351 | for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) | ||
352 | if (w & ((bitset_word_t) 1 << j)) | ||
353 | re_set_fastmap (fastmap, icase, ch); | ||
354 | } | ||
341 | } | 355 | } |
342 | #ifdef RE_ENABLE_I18N | 356 | #ifdef RE_ENABLE_I18N |
343 | else if (type == COMPLEX_BRACKET) | 357 | else if (type == COMPLEX_BRACKET) |
@@ -376,7 +390,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | |||
376 | memset (&state, '\0', sizeof (state)); | 390 | memset (&state, '\0', sizeof (state)); |
377 | if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1) | 391 | if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1) |
378 | re_set_fastmap (fastmap, icase, *(unsigned char *) buf); | 392 | re_set_fastmap (fastmap, icase, *(unsigned char *) buf); |
379 | if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1) | 393 | if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) |
380 | { | 394 | { |
381 | if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) | 395 | if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) |
382 | != (size_t) -1) | 396 | != (size_t) -1) |
@@ -393,7 +407,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | |||
393 | { | 407 | { |
394 | memset (fastmap, '\1', sizeof (char) * SBC_MAX); | 408 | memset (fastmap, '\1', sizeof (char) * SBC_MAX); |
395 | if (type == END_OF_RE) | 409 | if (type == END_OF_RE) |
396 | bufp->re_can_be_null = 1; | 410 | bufp->can_be_null = 1; |
397 | return; | 411 | return; |
398 | } | 412 | } |
399 | } | 413 | } |
@@ -405,14 +419,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, | |||
405 | PREG is a regex_t *. We do not expect any fields to be initialized, | 419 | PREG is a regex_t *. We do not expect any fields to be initialized, |
406 | since POSIX says we shouldn't. Thus, we set | 420 | since POSIX says we shouldn't. Thus, we set |
407 | 421 | ||
408 | `re_buffer' to the compiled pattern; | 422 | `buffer' to the compiled pattern; |
409 | `re_used' to the length of the compiled pattern; | 423 | `used' to the length of the compiled pattern; |
410 | `re_syntax' to REG_SYNTAX_POSIX_EXTENDED if the | 424 | `syntax' to RE_SYNTAX_POSIX_EXTENDED if the |
411 | REG_EXTENDED bit in CFLAGS is set; otherwise, to | 425 | REG_EXTENDED bit in CFLAGS is set; otherwise, to |
412 | REG_SYNTAX_POSIX_BASIC; | 426 | RE_SYNTAX_POSIX_BASIC; |
413 | `re_newline_anchor' to REG_NEWLINE being set in CFLAGS; | 427 | `newline_anchor' to REG_NEWLINE being set in CFLAGS; |
414 | `re_fastmap' to an allocated space for the fastmap; | 428 | `fastmap' to an allocated space for the fastmap; |
415 | `re_fastmap_accurate' to zero; | 429 | `fastmap_accurate' to zero; |
416 | `re_nsub' to the number of subexpressions in PATTERN. | 430 | `re_nsub' to the number of subexpressions in PATTERN. |
417 | 431 | ||
418 | PATTERN is the address of the pattern string. | 432 | 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, | |||
436 | the return codes and their meanings.) */ | 450 | the return codes and their meanings.) */ |
437 | 451 | ||
438 | int | 452 | int |
439 | regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) | 453 | regcomp (preg, pattern, cflags) |
454 | regex_t *__restrict preg; | ||
455 | const char *__restrict pattern; | ||
456 | int cflags; | ||
440 | { | 457 | { |
441 | reg_errcode_t ret; | 458 | reg_errcode_t ret; |
442 | reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? REG_SYNTAX_POSIX_EXTENDED | 459 | reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED |
443 | : REG_SYNTAX_POSIX_BASIC); | 460 | : RE_SYNTAX_POSIX_BASIC); |
444 | 461 | ||
445 | preg->re_buffer = NULL; | 462 | preg->buffer = NULL; |
446 | preg->re_allocated = 0; | 463 | preg->allocated = 0; |
447 | preg->re_used = 0; | 464 | preg->used = 0; |
448 | 465 | ||
449 | /* Try to allocate space for the fastmap. */ | 466 | /* Try to allocate space for the fastmap. */ |
450 | preg->re_fastmap = re_malloc (char, SBC_MAX); | 467 | preg->fastmap = re_malloc (char, SBC_MAX); |
451 | if (BE (preg->re_fastmap == NULL, 0)) | 468 | if (BE (preg->fastmap == NULL, 0)) |
452 | return REG_ESPACE; | 469 | return REG_ESPACE; |
453 | 470 | ||
454 | syntax |= (cflags & REG_ICASE) ? REG_IGNORE_CASE : 0; | 471 | syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0; |
455 | 472 | ||
456 | /* If REG_NEWLINE is set, newlines are treated differently. */ | 473 | /* If REG_NEWLINE is set, newlines are treated differently. */ |
457 | if (cflags & REG_NEWLINE) | 474 | if (cflags & REG_NEWLINE) |
458 | { /* REG_NEWLINE implies neither . nor [^...] match newline. */ | 475 | { /* REG_NEWLINE implies neither . nor [^...] match newline. */ |
459 | syntax &= ~REG_DOT_NEWLINE; | 476 | syntax &= ~RE_DOT_NEWLINE; |
460 | syntax |= REG_HAT_LISTS_NOT_NEWLINE; | 477 | syntax |= RE_HAT_LISTS_NOT_NEWLINE; |
461 | /* It also changes the matching behavior. */ | 478 | /* It also changes the matching behavior. */ |
462 | preg->re_newline_anchor = 1; | 479 | preg->newline_anchor = 1; |
463 | } | 480 | } |
464 | else | 481 | else |
465 | preg->re_newline_anchor = 0; | 482 | preg->newline_anchor = 0; |
466 | preg->re_no_sub = !!(cflags & REG_NOSUB); | 483 | preg->no_sub = !!(cflags & REG_NOSUB); |
467 | preg->re_translate = NULL; | 484 | preg->translate = NULL; |
468 | 485 | ||
469 | ret = re_compile_internal (preg, pattern, strlen (pattern), syntax); | 486 | ret = re_compile_internal (preg, pattern, strlen (pattern), syntax); |
470 | 487 | ||
@@ -473,7 +490,7 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) | |||
473 | if (ret == REG_ERPAREN) | 490 | if (ret == REG_ERPAREN) |
474 | ret = REG_EPAREN; | 491 | ret = REG_EPAREN; |
475 | 492 | ||
476 | /* We have already checked preg->re_fastmap != NULL. */ | 493 | /* We have already checked preg->fastmap != NULL. */ |
477 | if (BE (ret == REG_NOERROR, 1)) | 494 | if (BE (ret == REG_NOERROR, 1)) |
478 | /* Compute the fastmap now, since regexec cannot modify the pattern | 495 | /* Compute the fastmap now, since regexec cannot modify the pattern |
479 | buffer. This function never fails in this implementation. */ | 496 | buffer. This function never fails in this implementation. */ |
@@ -481,8 +498,8 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) | |||
481 | else | 498 | else |
482 | { | 499 | { |
483 | /* Some error occurred while compiling the expression. */ | 500 | /* Some error occurred while compiling the expression. */ |
484 | re_free (preg->re_fastmap); | 501 | re_free (preg->fastmap); |
485 | preg->re_fastmap = NULL; | 502 | preg->fastmap = NULL; |
486 | } | 503 | } |
487 | 504 | ||
488 | return (int) ret; | 505 | return (int) ret; |
@@ -494,9 +511,18 @@ weak_alias (__regcomp, regcomp) | |||
494 | /* Returns a message corresponding to an error code, ERRCODE, returned | 511 | /* Returns a message corresponding to an error code, ERRCODE, returned |
495 | from either regcomp or regexec. We don't use PREG here. */ | 512 | from either regcomp or regexec. We don't use PREG here. */ |
496 | 513 | ||
514 | #ifdef _LIBC | ||
515 | size_t | ||
516 | regerror (errcode, preg, errbuf, errbuf_size) | ||
517 | int errcode; | ||
518 | const regex_t *__restrict preg; | ||
519 | char *__restrict errbuf; | ||
520 | size_t errbuf_size; | ||
521 | #else /* size_t might promote */ | ||
497 | size_t | 522 | size_t |
498 | regerror (int errcode, const regex_t *__restrict preg, | 523 | regerror (int errcode, const regex_t *__restrict preg, |
499 | char *__restrict errbuf, size_t errbuf_size) | 524 | char *__restrict errbuf, size_t errbuf_size) |
525 | #endif | ||
500 | { | 526 | { |
501 | const char *msg; | 527 | const char *msg; |
502 | size_t msg_size; | 528 | size_t msg_size; |
@@ -541,21 +567,18 @@ weak_alias (__regerror, regerror) | |||
541 | UTF-8 is used. Otherwise we would allocate memory just to initialize | 567 | UTF-8 is used. Otherwise we would allocate memory just to initialize |
542 | it the same all the time. UTF-8 is the preferred encoding so this is | 568 | it the same all the time. UTF-8 is the preferred encoding so this is |
543 | a worthwhile optimization. */ | 569 | a worthwhile optimization. */ |
544 | static const bitset utf8_sb_map = | 570 | static const bitset_t utf8_sb_map = |
545 | { | 571 | { |
546 | /* Set the first 128 bits. */ | 572 | /* Set the first 128 bits. */ |
547 | # if 2 < BITSET_WORDS | 573 | # if 4 * BITSET_WORD_BITS < ASCII_CHARS |
548 | BITSET_WORD_MAX, | 574 | # error "bitset_word_t is narrower than 32 bits" |
549 | # endif | 575 | # elif 3 * BITSET_WORD_BITS < ASCII_CHARS |
550 | # if 4 < BITSET_WORDS | 576 | BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX, |
551 | BITSET_WORD_MAX, | 577 | # elif 2 * BITSET_WORD_BITS < ASCII_CHARS |
552 | # endif | 578 | BITSET_WORD_MAX, BITSET_WORD_MAX, |
553 | # if 6 < BITSET_WORDS | 579 | # elif 1 * BITSET_WORD_BITS < ASCII_CHARS |
554 | BITSET_WORD_MAX, | 580 | BITSET_WORD_MAX, |
555 | # endif | 581 | # endif |
556 | # if 8 < BITSET_WORDS | ||
557 | # error "Invalid BITSET_WORDS" | ||
558 | # endif | ||
559 | (BITSET_WORD_MAX | 582 | (BITSET_WORD_MAX |
560 | >> (SBC_MAX % BITSET_WORD_BITS == 0 | 583 | >> (SBC_MAX % BITSET_WORD_BITS == 0 |
561 | ? 0 | 584 | ? 0 |
@@ -615,19 +638,20 @@ free_dfa_content (re_dfa_t *dfa) | |||
615 | /* Free dynamically allocated space used by PREG. */ | 638 | /* Free dynamically allocated space used by PREG. */ |
616 | 639 | ||
617 | void | 640 | void |
618 | regfree (regex_t *preg) | 641 | regfree (preg) |
642 | regex_t *preg; | ||
619 | { | 643 | { |
620 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 644 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
621 | if (BE (dfa != NULL, 1)) | 645 | if (BE (dfa != NULL, 1)) |
622 | free_dfa_content (dfa); | 646 | free_dfa_content (dfa); |
623 | preg->re_buffer = NULL; | 647 | preg->buffer = NULL; |
624 | preg->re_allocated = 0; | 648 | preg->allocated = 0; |
625 | 649 | ||
626 | re_free (preg->re_fastmap); | 650 | re_free (preg->fastmap); |
627 | preg->re_fastmap = NULL; | 651 | preg->fastmap = NULL; |
628 | 652 | ||
629 | re_free (preg->re_translate); | 653 | re_free (preg->translate); |
630 | preg->re_translate = NULL; | 654 | preg->translate = NULL; |
631 | } | 655 | } |
632 | #ifdef _LIBC | 656 | #ifdef _LIBC |
633 | weak_alias (__regfree, regfree) | 657 | weak_alias (__regfree, regfree) |
@@ -648,31 +672,32 @@ char * | |||
648 | regcomp/regexec above without link errors. */ | 672 | regcomp/regexec above without link errors. */ |
649 | weak_function | 673 | weak_function |
650 | # endif | 674 | # endif |
651 | re_comp (const char *s) | 675 | re_comp (s) |
676 | const char *s; | ||
652 | { | 677 | { |
653 | reg_errcode_t ret; | 678 | reg_errcode_t ret; |
654 | char *fastmap; | 679 | char *fastmap; |
655 | 680 | ||
656 | if (!s) | 681 | if (!s) |
657 | { | 682 | { |
658 | if (!re_comp_buf.re_buffer) | 683 | if (!re_comp_buf.buffer) |
659 | return gettext ("No previous regular expression"); | 684 | return gettext ("No previous regular expression"); |
660 | return 0; | 685 | return 0; |
661 | } | 686 | } |
662 | 687 | ||
663 | if (re_comp_buf.re_buffer) | 688 | if (re_comp_buf.buffer) |
664 | { | 689 | { |
665 | fastmap = re_comp_buf.re_fastmap; | 690 | fastmap = re_comp_buf.fastmap; |
666 | re_comp_buf.re_fastmap = NULL; | 691 | re_comp_buf.fastmap = NULL; |
667 | __regfree (&re_comp_buf); | 692 | __regfree (&re_comp_buf); |
668 | memset (&re_comp_buf, '\0', sizeof (re_comp_buf)); | 693 | memset (&re_comp_buf, '\0', sizeof (re_comp_buf)); |
669 | re_comp_buf.re_fastmap = fastmap; | 694 | re_comp_buf.fastmap = fastmap; |
670 | } | 695 | } |
671 | 696 | ||
672 | if (re_comp_buf.re_fastmap == NULL) | 697 | if (re_comp_buf.fastmap == NULL) |
673 | { | 698 | { |
674 | re_comp_buf.re_fastmap = (char *) malloc (SBC_MAX); | 699 | re_comp_buf.fastmap = (char *) malloc (SBC_MAX); |
675 | if (re_comp_buf.re_fastmap == NULL) | 700 | if (re_comp_buf.fastmap == NULL) |
676 | return (char *) gettext (__re_error_msgid | 701 | return (char *) gettext (__re_error_msgid |
677 | + __re_error_msgid_idx[(int) REG_ESPACE]); | 702 | + __re_error_msgid_idx[(int) REG_ESPACE]); |
678 | } | 703 | } |
@@ -681,7 +706,7 @@ re_comp (const char *s) | |||
681 | don't need to initialize the pattern buffer fields which affect it. */ | 706 | don't need to initialize the pattern buffer fields which affect it. */ |
682 | 707 | ||
683 | /* Match anchors at newlines. */ | 708 | /* Match anchors at newlines. */ |
684 | re_comp_buf.re_newline_anchor = 1; | 709 | re_comp_buf.newline_anchor = 1; |
685 | 710 | ||
686 | ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options); | 711 | ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options); |
687 | 712 | ||
@@ -706,7 +731,7 @@ libc_freeres_fn (free_mem) | |||
706 | SYNTAX indicate regular expression's syntax. */ | 731 | SYNTAX indicate regular expression's syntax. */ |
707 | 732 | ||
708 | static reg_errcode_t | 733 | static reg_errcode_t |
709 | re_compile_internal (regex_t *preg, const char *pattern, Idx length, | 734 | re_compile_internal (regex_t *preg, const char * pattern, size_t length, |
710 | reg_syntax_t syntax) | 735 | reg_syntax_t syntax) |
711 | { | 736 | { |
712 | reg_errcode_t err = REG_NOERROR; | 737 | reg_errcode_t err = REG_NOERROR; |
@@ -714,55 +739,56 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, | |||
714 | re_string_t regexp; | 739 | re_string_t regexp; |
715 | 740 | ||
716 | /* Initialize the pattern buffer. */ | 741 | /* Initialize the pattern buffer. */ |
717 | preg->re_fastmap_accurate = 0; | 742 | preg->fastmap_accurate = 0; |
718 | preg->re_syntax = syntax; | 743 | preg->syntax = syntax; |
719 | preg->re_not_bol = preg->re_not_eol = 0; | 744 | preg->not_bol = preg->not_eol = 0; |
720 | preg->re_used = 0; | 745 | preg->used = 0; |
721 | preg->re_nsub = 0; | 746 | preg->re_nsub = 0; |
722 | preg->re_can_be_null = 0; | 747 | preg->can_be_null = 0; |
723 | preg->re_regs_allocated = REG_UNALLOCATED; | 748 | preg->regs_allocated = REGS_UNALLOCATED; |
724 | 749 | ||
725 | /* Initialize the dfa. */ | 750 | /* Initialize the dfa. */ |
726 | dfa = (re_dfa_t *) preg->re_buffer; | 751 | dfa = (re_dfa_t *) preg->buffer; |
727 | if (BE (preg->re_allocated < sizeof (re_dfa_t), 0)) | 752 | if (BE (preg->allocated < sizeof (re_dfa_t), 0)) |
728 | { | 753 | { |
729 | /* If zero allocated, but buffer is non-null, try to realloc | 754 | /* If zero allocated, but buffer is non-null, try to realloc |
730 | enough space. This loses if buffer's address is bogus, but | 755 | enough space. This loses if buffer's address is bogus, but |
731 | that is the user's responsibility. If buffer is null this | 756 | that is the user's responsibility. If ->buffer is NULL this |
732 | is a simple allocation. */ | 757 | is a simple allocation. */ |
733 | dfa = re_realloc (preg->re_buffer, re_dfa_t, 1); | 758 | dfa = re_realloc (preg->buffer, re_dfa_t, 1); |
734 | if (dfa == NULL) | 759 | if (dfa == NULL) |
735 | return REG_ESPACE; | 760 | return REG_ESPACE; |
736 | preg->re_allocated = sizeof (re_dfa_t); | 761 | preg->allocated = sizeof (re_dfa_t); |
737 | preg->re_buffer = (unsigned char *) dfa; | 762 | preg->buffer = (unsigned char *) dfa; |
738 | } | 763 | } |
739 | preg->re_used = sizeof (re_dfa_t); | 764 | preg->used = sizeof (re_dfa_t); |
740 | |||
741 | __libc_lock_init (dfa->lock); | ||
742 | 765 | ||
743 | err = init_dfa (dfa, length); | 766 | err = init_dfa (dfa, length); |
744 | if (BE (err != REG_NOERROR, 0)) | 767 | if (BE (err != REG_NOERROR, 0)) |
745 | { | 768 | { |
746 | free_dfa_content (dfa); | 769 | free_dfa_content (dfa); |
747 | preg->re_buffer = NULL; | 770 | preg->buffer = NULL; |
748 | preg->re_allocated = 0; | 771 | preg->allocated = 0; |
749 | return err; | 772 | return err; |
750 | } | 773 | } |
751 | #ifdef DEBUG | 774 | #ifdef DEBUG |
775 | /* Note: length+1 will not overflow since it is checked in init_dfa. */ | ||
752 | dfa->re_str = re_malloc (char, length + 1); | 776 | dfa->re_str = re_malloc (char, length + 1); |
753 | strncpy (dfa->re_str, pattern, length + 1); | 777 | strncpy (dfa->re_str, pattern, length + 1); |
754 | #endif | 778 | #endif |
755 | 779 | ||
756 | err = re_string_construct (®exp, pattern, length, preg->re_translate, | 780 | __libc_lock_init (dfa->lock); |
757 | syntax & REG_IGNORE_CASE, dfa); | 781 | |
782 | err = re_string_construct (®exp, pattern, length, preg->translate, | ||
783 | syntax & RE_ICASE, dfa); | ||
758 | if (BE (err != REG_NOERROR, 0)) | 784 | if (BE (err != REG_NOERROR, 0)) |
759 | { | 785 | { |
760 | re_compile_internal_free_return: | 786 | re_compile_internal_free_return: |
761 | free_workarea_compile (preg); | 787 | free_workarea_compile (preg); |
762 | re_string_destruct (®exp); | 788 | re_string_destruct (®exp); |
763 | free_dfa_content (dfa); | 789 | free_dfa_content (dfa); |
764 | preg->re_buffer = NULL; | 790 | preg->buffer = NULL; |
765 | preg->re_allocated = 0; | 791 | preg->allocated = 0; |
766 | return err; | 792 | return err; |
767 | } | 793 | } |
768 | 794 | ||
@@ -779,7 +805,7 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, | |||
779 | 805 | ||
780 | #ifdef RE_ENABLE_I18N | 806 | #ifdef RE_ENABLE_I18N |
781 | /* If possible, do searching in single byte encoding to speed things up. */ | 807 | /* If possible, do searching in single byte encoding to speed things up. */ |
782 | if (dfa->is_utf8 && !(syntax & REG_IGNORE_CASE) && preg->re_translate == NULL) | 808 | if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL) |
783 | optimize_utf8 (dfa); | 809 | optimize_utf8 (dfa); |
784 | #endif | 810 | #endif |
785 | 811 | ||
@@ -793,8 +819,8 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, | |||
793 | if (BE (err != REG_NOERROR, 0)) | 819 | if (BE (err != REG_NOERROR, 0)) |
794 | { | 820 | { |
795 | free_dfa_content (dfa); | 821 | free_dfa_content (dfa); |
796 | preg->re_buffer = NULL; | 822 | preg->buffer = NULL; |
797 | preg->re_allocated = 0; | 823 | preg->allocated = 0; |
798 | } | 824 | } |
799 | 825 | ||
800 | return err; | 826 | return err; |
@@ -804,27 +830,45 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, | |||
804 | as the initial length of some arrays. */ | 830 | as the initial length of some arrays. */ |
805 | 831 | ||
806 | static reg_errcode_t | 832 | static reg_errcode_t |
807 | init_dfa (re_dfa_t *dfa, Idx pat_len) | 833 | init_dfa (re_dfa_t *dfa, size_t pat_len) |
808 | { | 834 | { |
809 | __re_size_t table_size; | 835 | __re_size_t table_size; |
810 | #ifndef _LIBC | 836 | #ifndef _LIBC |
811 | char *codeset_name; | 837 | char *codeset_name; |
812 | #endif | 838 | #endif |
839 | #ifdef RE_ENABLE_I18N | ||
840 | size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); | ||
841 | #else | ||
842 | size_t max_i18n_object_size = 0; | ||
843 | #endif | ||
844 | size_t max_object_size = | ||
845 | MAX (sizeof (struct re_state_table_entry), | ||
846 | MAX (sizeof (re_token_t), | ||
847 | MAX (sizeof (re_node_set), | ||
848 | MAX (sizeof (regmatch_t), | ||
849 | max_i18n_object_size)))); | ||
813 | 850 | ||
814 | memset (dfa, '\0', sizeof (re_dfa_t)); | 851 | memset (dfa, '\0', sizeof (re_dfa_t)); |
815 | 852 | ||
816 | /* Force allocation of str_tree_storage the first time. */ | 853 | /* Force allocation of str_tree_storage the first time. */ |
817 | dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; | 854 | dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; |
818 | 855 | ||
856 | /* Avoid overflows. The extra "/ 2" is for the table_size doubling | ||
857 | calculation below, and for similar doubling calculations | ||
858 | elsewhere. And it's <= rather than <, because some of the | ||
859 | doubling calculations add 1 afterwards. */ | ||
860 | if (BE (SIZE_MAX / max_object_size / 2 <= pat_len, 0)) | ||
861 | return REG_ESPACE; | ||
862 | |||
819 | dfa->nodes_alloc = pat_len + 1; | 863 | dfa->nodes_alloc = pat_len + 1; |
820 | dfa->nodes = re_xmalloc (re_token_t, dfa->nodes_alloc); | 864 | dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc); |
821 | 865 | ||
822 | /* table_size = 2 ^ ceil(log pat_len) */ | 866 | /* table_size = 2 ^ ceil(log pat_len) */ |
823 | for (table_size = 1; table_size <= pat_len; table_size <<= 1) | 867 | for (table_size = 1; ; table_size <<= 1) |
824 | if (0 < (Idx) -1 && table_size == 0) | 868 | if (table_size > pat_len) |
825 | return REG_ESPACE; | 869 | break; |
826 | 870 | ||
827 | dfa->state_table = re_calloc (struct re_state_table_entry, table_size); | 871 | dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size); |
828 | dfa->state_hash_mask = table_size - 1; | 872 | dfa->state_hash_mask = table_size - 1; |
829 | 873 | ||
830 | dfa->mb_cur_max = MB_CUR_MAX; | 874 | dfa->mb_cur_max = MB_CUR_MAX; |
@@ -867,7 +911,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) | |||
867 | { | 911 | { |
868 | int i, j, ch; | 912 | int i, j, ch; |
869 | 913 | ||
870 | dfa->sb_char = re_calloc (bitset_word, BITSET_WORDS); | 914 | dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); |
871 | if (BE (dfa->sb_char == NULL, 0)) | 915 | if (BE (dfa->sb_char == NULL, 0)) |
872 | return REG_ESPACE; | 916 | return REG_ESPACE; |
873 | 917 | ||
@@ -877,7 +921,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) | |||
877 | { | 921 | { |
878 | wint_t wch = __btowc (ch); | 922 | wint_t wch = __btowc (ch); |
879 | if (wch != WEOF) | 923 | if (wch != WEOF) |
880 | dfa->sb_char[i] |= (bitset_word) 1 << j; | 924 | dfa->sb_char[i] |= (bitset_word_t) 1 << j; |
881 | # ifndef _LIBC | 925 | # ifndef _LIBC |
882 | if (isascii (ch) && wch != ch) | 926 | if (isascii (ch) && wch != ch) |
883 | dfa->map_notascii = 1; | 927 | dfa->map_notascii = 1; |
@@ -897,6 +941,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) | |||
897 | character used by some operators like "\<", "\>", etc. */ | 941 | character used by some operators like "\<", "\>", etc. */ |
898 | 942 | ||
899 | static void | 943 | static void |
944 | internal_function | ||
900 | init_word_char (re_dfa_t *dfa) | 945 | init_word_char (re_dfa_t *dfa) |
901 | { | 946 | { |
902 | int i, j, ch; | 947 | int i, j, ch; |
@@ -904,7 +949,7 @@ init_word_char (re_dfa_t *dfa) | |||
904 | for (i = 0, ch = 0; i < BITSET_WORDS; ++i) | 949 | for (i = 0, ch = 0; i < BITSET_WORDS; ++i) |
905 | for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) | 950 | for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) |
906 | if (isalnum (ch) || ch == '_') | 951 | if (isalnum (ch) || ch == '_') |
907 | dfa->word_char[i] |= (bitset_word) 1 << j; | 952 | dfa->word_char[i] |= (bitset_word_t) 1 << j; |
908 | } | 953 | } |
909 | 954 | ||
910 | /* Free the work area which are only used while compiling. */ | 955 | /* Free the work area which are only used while compiling. */ |
@@ -912,7 +957,7 @@ init_word_char (re_dfa_t *dfa) | |||
912 | static void | 957 | static void |
913 | free_workarea_compile (regex_t *preg) | 958 | free_workarea_compile (regex_t *preg) |
914 | { | 959 | { |
915 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 960 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
916 | bin_tree_storage_t *storage, *next; | 961 | bin_tree_storage_t *storage, *next; |
917 | for (storage = dfa->str_tree_storage; storage; storage = next) | 962 | for (storage = dfa->str_tree_storage; storage; storage = next) |
918 | { | 963 | { |
@@ -1022,7 +1067,7 @@ optimize_utf8 (re_dfa_t *dfa) | |||
1022 | switch (dfa->nodes[node].type) | 1067 | switch (dfa->nodes[node].type) |
1023 | { | 1068 | { |
1024 | case CHARACTER: | 1069 | case CHARACTER: |
1025 | if (dfa->nodes[node].opr.c >= 0x80) | 1070 | if (dfa->nodes[node].opr.c >= ASCII_CHARS) |
1026 | mb_chars = true; | 1071 | mb_chars = true; |
1027 | break; | 1072 | break; |
1028 | case ANCHOR: | 1073 | case ANCHOR: |
@@ -1053,11 +1098,10 @@ optimize_utf8 (re_dfa_t *dfa) | |||
1053 | case SIMPLE_BRACKET: | 1098 | case SIMPLE_BRACKET: |
1054 | /* Just double check. */ | 1099 | /* Just double check. */ |
1055 | { | 1100 | { |
1056 | int rshift = | 1101 | int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0 |
1057 | (SBC_MAX / 2 % BITSET_WORD_BITS == 0 | 1102 | ? 0 |
1058 | ? 0 | 1103 | : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS); |
1059 | : BITSET_WORD_BITS - SBC_MAX / 2 % BITSET_WORD_BITS); | 1104 | for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) |
1060 | for (i = SBC_MAX / 2 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) | ||
1061 | { | 1105 | { |
1062 | if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0) | 1106 | if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0) |
1063 | return; | 1107 | return; |
@@ -1073,7 +1117,7 @@ optimize_utf8 (re_dfa_t *dfa) | |||
1073 | for (node = 0; node < dfa->nodes_len; ++node) | 1117 | for (node = 0; node < dfa->nodes_len; ++node) |
1074 | { | 1118 | { |
1075 | if (dfa->nodes[node].type == CHARACTER | 1119 | if (dfa->nodes[node].type == CHARACTER |
1076 | && dfa->nodes[node].opr.c >= 0x80) | 1120 | && dfa->nodes[node].opr.c >= ASCII_CHARS) |
1077 | dfa->nodes[node].mb_partial = 0; | 1121 | dfa->nodes[node].mb_partial = 0; |
1078 | else if (dfa->nodes[node].type == OP_PERIOD) | 1122 | else if (dfa->nodes[node].type == OP_PERIOD) |
1079 | dfa->nodes[node].type = OP_UTF8_PERIOD; | 1123 | dfa->nodes[node].type = OP_UTF8_PERIOD; |
@@ -1092,19 +1136,19 @@ optimize_utf8 (re_dfa_t *dfa) | |||
1092 | static reg_errcode_t | 1136 | static reg_errcode_t |
1093 | analyze (regex_t *preg) | 1137 | analyze (regex_t *preg) |
1094 | { | 1138 | { |
1095 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 1139 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
1096 | reg_errcode_t ret; | 1140 | reg_errcode_t ret; |
1097 | 1141 | ||
1098 | /* Allocate arrays. */ | 1142 | /* Allocate arrays. */ |
1099 | dfa->nexts = re_malloc (Idx, dfa->nodes_alloc); | 1143 | dfa->nexts = re_malloc (Idx, dfa->nodes_alloc); |
1100 | dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); | 1144 | dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); |
1101 | dfa->edests = re_xmalloc (re_node_set, dfa->nodes_alloc); | 1145 | dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc); |
1102 | dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); | 1146 | dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); |
1103 | if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL | 1147 | if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL |
1104 | || dfa->eclosures == NULL, 0)) | 1148 | || dfa->eclosures == NULL, 0)) |
1105 | return REG_ESPACE; | 1149 | return REG_ESPACE; |
1106 | 1150 | ||
1107 | dfa->subexp_map = re_xmalloc (Idx, preg->re_nsub); | 1151 | dfa->subexp_map = re_malloc (Idx, preg->re_nsub); |
1108 | if (dfa->subexp_map != NULL) | 1152 | if (dfa->subexp_map != NULL) |
1109 | { | 1153 | { |
1110 | Idx i; | 1154 | Idx i; |
@@ -1137,10 +1181,10 @@ analyze (regex_t *preg) | |||
1137 | 1181 | ||
1138 | /* We only need this during the prune_impossible_nodes pass in regexec.c; | 1182 | /* We only need this during the prune_impossible_nodes pass in regexec.c; |
1139 | skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */ | 1183 | skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */ |
1140 | if ((!preg->re_no_sub && preg->re_nsub > 0 && dfa->has_plural_match) | 1184 | if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match) |
1141 | || dfa->nbackref) | 1185 | || dfa->nbackref) |
1142 | { | 1186 | { |
1143 | dfa->inveclosures = re_xmalloc (re_node_set, dfa->nodes_len); | 1187 | dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); |
1144 | if (BE (dfa->inveclosures == NULL, 0)) | 1188 | if (BE (dfa->inveclosures == NULL, 0)) |
1145 | return REG_ESPACE; | 1189 | return REG_ESPACE; |
1146 | ret = calc_inveclosure (dfa); | 1190 | ret = calc_inveclosure (dfa); |
@@ -1240,7 +1284,7 @@ optimize_subexps (void *extra, bin_tree_t *node) | |||
1240 | 1284 | ||
1241 | dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; | 1285 | dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; |
1242 | if (other_idx < BITSET_WORD_BITS) | 1286 | if (other_idx < BITSET_WORD_BITS) |
1243 | dfa->used_bkref_map &= ~ ((bitset_word) 1 << other_idx); | 1287 | dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx); |
1244 | } | 1288 | } |
1245 | 1289 | ||
1246 | return REG_NOERROR; | 1290 | return REG_NOERROR; |
@@ -1273,18 +1317,19 @@ lower_subexps (void *extra, bin_tree_t *node) | |||
1273 | static bin_tree_t * | 1317 | static bin_tree_t * |
1274 | lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node) | 1318 | lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node) |
1275 | { | 1319 | { |
1276 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 1320 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
1277 | bin_tree_t *body = node->left; | 1321 | bin_tree_t *body = node->left; |
1278 | bin_tree_t *op, *cls, *tree1, *tree; | 1322 | bin_tree_t *op, *cls, *tree1, *tree; |
1279 | 1323 | ||
1280 | if (preg->re_no_sub | 1324 | if (preg->no_sub |
1281 | /* We do not optimize empty subexpressions, because otherwise we may | 1325 | /* We do not optimize empty subexpressions, because otherwise we may |
1282 | have bad CONCAT nodes with NULL children. This is obviously not | 1326 | have bad CONCAT nodes with NULL children. This is obviously not |
1283 | very common, so we do not lose much. An example that triggers | 1327 | very common, so we do not lose much. An example that triggers |
1284 | this case is the sed "script" /\(\)/x. */ | 1328 | this case is the sed "script" /\(\)/x. */ |
1285 | && node->left != NULL | 1329 | && node->left != NULL |
1286 | && ! (node->token.opr.idx < BITSET_WORD_BITS | 1330 | && (node->token.opr.idx >= BITSET_WORD_BITS |
1287 | && dfa->used_bkref_map & ((bitset_word) 1 << node->token.opr.idx))) | 1331 | || !(dfa->used_bkref_map |
1332 | & ((bitset_word_t) 1 << node->token.opr.idx)))) | ||
1288 | return node->left; | 1333 | return node->left; |
1289 | 1334 | ||
1290 | /* Convert the SUBEXP node to the concatenation of an | 1335 | /* Convert the SUBEXP node to the concatenation of an |
@@ -1410,9 +1455,9 @@ link_nfa_nodes (void *extra, bin_tree_t *node) | |||
1410 | to their own constraint. */ | 1455 | to their own constraint. */ |
1411 | 1456 | ||
1412 | static reg_errcode_t | 1457 | static reg_errcode_t |
1413 | duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, | 1458 | internal_function |
1414 | Idx top_clone_node, Idx root_node, | 1459 | duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node, |
1415 | unsigned int init_constraint) | 1460 | Idx root_node, unsigned int init_constraint) |
1416 | { | 1461 | { |
1417 | Idx org_node, clone_node; | 1462 | Idx org_node, clone_node; |
1418 | bool ok; | 1463 | bool ok; |
@@ -1458,8 +1503,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, | |||
1458 | /* ...but if the node is root_node itself, it means the | 1503 | /* ...but if the node is root_node itself, it means the |
1459 | epsilon closure have a loop, then tie it to the | 1504 | epsilon closure have a loop, then tie it to the |
1460 | destination of the root_node. */ | 1505 | destination of the root_node. */ |
1461 | ok = re_node_set_insert (dfa->edests + clone_node, | 1506 | ok = re_node_set_insert (dfa->edests + clone_node, org_dest); |
1462 | org_dest); | ||
1463 | if (BE (! ok, 0)) | 1507 | if (BE (! ok, 0)) |
1464 | return REG_ESPACE; | 1508 | return REG_ESPACE; |
1465 | break; | 1509 | break; |
@@ -1652,8 +1696,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) | |||
1652 | && dfa->edests[node].nelem | 1696 | && dfa->edests[node].nelem |
1653 | && !dfa->nodes[dfa->edests[node].elems[0]].duplicated) | 1697 | && !dfa->nodes[dfa->edests[node].elems[0]].duplicated) |
1654 | { | 1698 | { |
1655 | Idx org_node, cur_node; | ||
1656 | org_node = cur_node = node; | ||
1657 | err = duplicate_node_closure (dfa, node, node, node, constraint); | 1699 | err = duplicate_node_closure (dfa, node, node, node, constraint); |
1658 | if (BE (err != REG_NOERROR, 0)) | 1700 | if (BE (err != REG_NOERROR, 0)) |
1659 | return err; | 1701 | return err; |
@@ -1711,6 +1753,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) | |||
1711 | We must not use this function inside bracket expressions. */ | 1753 | We must not use this function inside bracket expressions. */ |
1712 | 1754 | ||
1713 | static void | 1755 | static void |
1756 | internal_function | ||
1714 | fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) | 1757 | fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) |
1715 | { | 1758 | { |
1716 | re_string_skip_bytes (input, peek_token (result, input, syntax)); | 1759 | 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) | |||
1720 | We must not use this function inside bracket expressions. */ | 1763 | We must not use this function inside bracket expressions. */ |
1721 | 1764 | ||
1722 | static int | 1765 | static int |
1766 | internal_function | ||
1723 | peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | 1767 | peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) |
1724 | { | 1768 | { |
1725 | unsigned char c; | 1769 | unsigned char c; |
@@ -1770,97 +1814,97 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | |||
1770 | switch (c2) | 1814 | switch (c2) |
1771 | { | 1815 | { |
1772 | case '|': | 1816 | case '|': |
1773 | if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_NO_BK_VBAR)) | 1817 | if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR)) |
1774 | token->type = OP_ALT; | 1818 | token->type = OP_ALT; |
1775 | break; | 1819 | break; |
1776 | case '1': case '2': case '3': case '4': case '5': | 1820 | case '1': case '2': case '3': case '4': case '5': |
1777 | case '6': case '7': case '8': case '9': | 1821 | case '6': case '7': case '8': case '9': |
1778 | if (!(syntax & REG_NO_BK_REFS)) | 1822 | if (!(syntax & RE_NO_BK_REFS)) |
1779 | { | 1823 | { |
1780 | token->type = OP_BACK_REF; | 1824 | token->type = OP_BACK_REF; |
1781 | token->opr.idx = c2 - '1'; | 1825 | token->opr.idx = c2 - '1'; |
1782 | } | 1826 | } |
1783 | break; | 1827 | break; |
1784 | case '<': | 1828 | case '<': |
1785 | if (!(syntax & REG_NO_GNU_OPS)) | 1829 | if (!(syntax & RE_NO_GNU_OPS)) |
1786 | { | 1830 | { |
1787 | token->type = ANCHOR; | 1831 | token->type = ANCHOR; |
1788 | token->opr.ctx_type = WORD_FIRST; | 1832 | token->opr.ctx_type = WORD_FIRST; |
1789 | } | 1833 | } |
1790 | break; | 1834 | break; |
1791 | case '>': | 1835 | case '>': |
1792 | if (!(syntax & REG_NO_GNU_OPS)) | 1836 | if (!(syntax & RE_NO_GNU_OPS)) |
1793 | { | 1837 | { |
1794 | token->type = ANCHOR; | 1838 | token->type = ANCHOR; |
1795 | token->opr.ctx_type = WORD_LAST; | 1839 | token->opr.ctx_type = WORD_LAST; |
1796 | } | 1840 | } |
1797 | break; | 1841 | break; |
1798 | case 'b': | 1842 | case 'b': |
1799 | if (!(syntax & REG_NO_GNU_OPS)) | 1843 | if (!(syntax & RE_NO_GNU_OPS)) |
1800 | { | 1844 | { |
1801 | token->type = ANCHOR; | 1845 | token->type = ANCHOR; |
1802 | token->opr.ctx_type = WORD_DELIM; | 1846 | token->opr.ctx_type = WORD_DELIM; |
1803 | } | 1847 | } |
1804 | break; | 1848 | break; |
1805 | case 'B': | 1849 | case 'B': |
1806 | if (!(syntax & REG_NO_GNU_OPS)) | 1850 | if (!(syntax & RE_NO_GNU_OPS)) |
1807 | { | 1851 | { |
1808 | token->type = ANCHOR; | 1852 | token->type = ANCHOR; |
1809 | token->opr.ctx_type = NOT_WORD_DELIM; | 1853 | token->opr.ctx_type = NOT_WORD_DELIM; |
1810 | } | 1854 | } |
1811 | break; | 1855 | break; |
1812 | case 'w': | 1856 | case 'w': |
1813 | if (!(syntax & REG_NO_GNU_OPS)) | 1857 | if (!(syntax & RE_NO_GNU_OPS)) |
1814 | token->type = OP_WORD; | 1858 | token->type = OP_WORD; |
1815 | break; | 1859 | break; |
1816 | case 'W': | 1860 | case 'W': |
1817 | if (!(syntax & REG_NO_GNU_OPS)) | 1861 | if (!(syntax & RE_NO_GNU_OPS)) |
1818 | token->type = OP_NOTWORD; | 1862 | token->type = OP_NOTWORD; |
1819 | break; | 1863 | break; |
1820 | case 's': | 1864 | case 's': |
1821 | if (!(syntax & REG_NO_GNU_OPS)) | 1865 | if (!(syntax & RE_NO_GNU_OPS)) |
1822 | token->type = OP_SPACE; | 1866 | token->type = OP_SPACE; |
1823 | break; | 1867 | break; |
1824 | case 'S': | 1868 | case 'S': |
1825 | if (!(syntax & REG_NO_GNU_OPS)) | 1869 | if (!(syntax & RE_NO_GNU_OPS)) |
1826 | token->type = OP_NOTSPACE; | 1870 | token->type = OP_NOTSPACE; |
1827 | break; | 1871 | break; |
1828 | case '`': | 1872 | case '`': |
1829 | if (!(syntax & REG_NO_GNU_OPS)) | 1873 | if (!(syntax & RE_NO_GNU_OPS)) |
1830 | { | 1874 | { |
1831 | token->type = ANCHOR; | 1875 | token->type = ANCHOR; |
1832 | token->opr.ctx_type = BUF_FIRST; | 1876 | token->opr.ctx_type = BUF_FIRST; |
1833 | } | 1877 | } |
1834 | break; | 1878 | break; |
1835 | case '\'': | 1879 | case '\'': |
1836 | if (!(syntax & REG_NO_GNU_OPS)) | 1880 | if (!(syntax & RE_NO_GNU_OPS)) |
1837 | { | 1881 | { |
1838 | token->type = ANCHOR; | 1882 | token->type = ANCHOR; |
1839 | token->opr.ctx_type = BUF_LAST; | 1883 | token->opr.ctx_type = BUF_LAST; |
1840 | } | 1884 | } |
1841 | break; | 1885 | break; |
1842 | case '(': | 1886 | case '(': |
1843 | if (!(syntax & REG_NO_BK_PARENS)) | 1887 | if (!(syntax & RE_NO_BK_PARENS)) |
1844 | token->type = OP_OPEN_SUBEXP; | 1888 | token->type = OP_OPEN_SUBEXP; |
1845 | break; | 1889 | break; |
1846 | case ')': | 1890 | case ')': |
1847 | if (!(syntax & REG_NO_BK_PARENS)) | 1891 | if (!(syntax & RE_NO_BK_PARENS)) |
1848 | token->type = OP_CLOSE_SUBEXP; | 1892 | token->type = OP_CLOSE_SUBEXP; |
1849 | break; | 1893 | break; |
1850 | case '+': | 1894 | case '+': |
1851 | if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM)) | 1895 | if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) |
1852 | token->type = OP_DUP_PLUS; | 1896 | token->type = OP_DUP_PLUS; |
1853 | break; | 1897 | break; |
1854 | case '?': | 1898 | case '?': |
1855 | if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM)) | 1899 | if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) |
1856 | token->type = OP_DUP_QUESTION; | 1900 | token->type = OP_DUP_QUESTION; |
1857 | break; | 1901 | break; |
1858 | case '{': | 1902 | case '{': |
1859 | if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES))) | 1903 | if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) |
1860 | token->type = OP_OPEN_DUP_NUM; | 1904 | token->type = OP_OPEN_DUP_NUM; |
1861 | break; | 1905 | break; |
1862 | case '}': | 1906 | case '}': |
1863 | if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES))) | 1907 | if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) |
1864 | token->type = OP_CLOSE_DUP_NUM; | 1908 | token->type = OP_CLOSE_DUP_NUM; |
1865 | break; | 1909 | break; |
1866 | default: | 1910 | default: |
@@ -1883,38 +1927,38 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | |||
1883 | switch (c) | 1927 | switch (c) |
1884 | { | 1928 | { |
1885 | case '\n': | 1929 | case '\n': |
1886 | if (syntax & REG_NEWLINE_ALT) | 1930 | if (syntax & RE_NEWLINE_ALT) |
1887 | token->type = OP_ALT; | 1931 | token->type = OP_ALT; |
1888 | break; | 1932 | break; |
1889 | case '|': | 1933 | case '|': |
1890 | if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_NO_BK_VBAR)) | 1934 | if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR)) |
1891 | token->type = OP_ALT; | 1935 | token->type = OP_ALT; |
1892 | break; | 1936 | break; |
1893 | case '*': | 1937 | case '*': |
1894 | token->type = OP_DUP_ASTERISK; | 1938 | token->type = OP_DUP_ASTERISK; |
1895 | break; | 1939 | break; |
1896 | case '+': | 1940 | case '+': |
1897 | if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM)) | 1941 | if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) |
1898 | token->type = OP_DUP_PLUS; | 1942 | token->type = OP_DUP_PLUS; |
1899 | break; | 1943 | break; |
1900 | case '?': | 1944 | case '?': |
1901 | if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM)) | 1945 | if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) |
1902 | token->type = OP_DUP_QUESTION; | 1946 | token->type = OP_DUP_QUESTION; |
1903 | break; | 1947 | break; |
1904 | case '{': | 1948 | case '{': |
1905 | if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES)) | 1949 | if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) |
1906 | token->type = OP_OPEN_DUP_NUM; | 1950 | token->type = OP_OPEN_DUP_NUM; |
1907 | break; | 1951 | break; |
1908 | case '}': | 1952 | case '}': |
1909 | if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES)) | 1953 | if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) |
1910 | token->type = OP_CLOSE_DUP_NUM; | 1954 | token->type = OP_CLOSE_DUP_NUM; |
1911 | break; | 1955 | break; |
1912 | case '(': | 1956 | case '(': |
1913 | if (syntax & REG_NO_BK_PARENS) | 1957 | if (syntax & RE_NO_BK_PARENS) |
1914 | token->type = OP_OPEN_SUBEXP; | 1958 | token->type = OP_OPEN_SUBEXP; |
1915 | break; | 1959 | break; |
1916 | case ')': | 1960 | case ')': |
1917 | if (syntax & REG_NO_BK_PARENS) | 1961 | if (syntax & RE_NO_BK_PARENS) |
1918 | token->type = OP_CLOSE_SUBEXP; | 1962 | token->type = OP_CLOSE_SUBEXP; |
1919 | break; | 1963 | break; |
1920 | case '[': | 1964 | case '[': |
@@ -1924,18 +1968,18 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | |||
1924 | token->type = OP_PERIOD; | 1968 | token->type = OP_PERIOD; |
1925 | break; | 1969 | break; |
1926 | case '^': | 1970 | case '^': |
1927 | if (!(syntax & (REG_CONTEXT_INDEP_ANCHORS | REG_CARET_ANCHORS_HERE)) && | 1971 | if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && |
1928 | re_string_cur_idx (input) != 0) | 1972 | re_string_cur_idx (input) != 0) |
1929 | { | 1973 | { |
1930 | char prev = re_string_peek_byte (input, -1); | 1974 | char prev = re_string_peek_byte (input, -1); |
1931 | if (!(syntax & REG_NEWLINE_ALT) || prev != '\n') | 1975 | if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') |
1932 | break; | 1976 | break; |
1933 | } | 1977 | } |
1934 | token->type = ANCHOR; | 1978 | token->type = ANCHOR; |
1935 | token->opr.ctx_type = LINE_FIRST; | 1979 | token->opr.ctx_type = LINE_FIRST; |
1936 | break; | 1980 | break; |
1937 | case '$': | 1981 | case '$': |
1938 | if (!(syntax & REG_CONTEXT_INDEP_ANCHORS) && | 1982 | if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && |
1939 | re_string_cur_idx (input) + 1 != re_string_length (input)) | 1983 | re_string_cur_idx (input) + 1 != re_string_length (input)) |
1940 | { | 1984 | { |
1941 | re_token_t next; | 1985 | re_token_t next; |
@@ -1958,6 +2002,7 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | |||
1958 | We must not use this function out of bracket expressions. */ | 2002 | We must not use this function out of bracket expressions. */ |
1959 | 2003 | ||
1960 | static int | 2004 | static int |
2005 | internal_function | ||
1961 | peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | 2006 | peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) |
1962 | { | 2007 | { |
1963 | unsigned char c; | 2008 | unsigned char c; |
@@ -1978,7 +2023,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) | |||
1978 | } | 2023 | } |
1979 | #endif /* RE_ENABLE_I18N */ | 2024 | #endif /* RE_ENABLE_I18N */ |
1980 | 2025 | ||
1981 | if (c == '\\' && (syntax & REG_BACKSLASH_ESCAPE_IN_LISTS) | 2026 | if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) |
1982 | && re_string_cur_idx (input) + 1 < re_string_length (input)) | 2027 | && re_string_cur_idx (input) + 1 < re_string_length (input)) |
1983 | { | 2028 | { |
1984 | /* In this case, '\' escape a character. */ | 2029 | /* 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) | |||
2008 | token->type = OP_OPEN_EQUIV_CLASS; | 2053 | token->type = OP_OPEN_EQUIV_CLASS; |
2009 | break; | 2054 | break; |
2010 | case ':': | 2055 | case ':': |
2011 | if (syntax & REG_CHAR_CLASSES) | 2056 | if (syntax & RE_CHAR_CLASSES) |
2012 | { | 2057 | { |
2013 | token->type = OP_OPEN_CHAR_CLASS; | 2058 | token->type = OP_OPEN_CHAR_CLASS; |
2014 | break; | 2059 | break; |
@@ -2057,11 +2102,11 @@ static bin_tree_t * | |||
2057 | parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, | 2102 | parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, |
2058 | reg_errcode_t *err) | 2103 | reg_errcode_t *err) |
2059 | { | 2104 | { |
2060 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 2105 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
2061 | bin_tree_t *tree, *eor, *root; | 2106 | bin_tree_t *tree, *eor, *root; |
2062 | re_token_t current_token; | 2107 | re_token_t current_token; |
2063 | dfa->syntax = syntax; | 2108 | dfa->syntax = syntax; |
2064 | fetch_token (¤t_token, regexp, syntax | REG_CARET_ANCHORS_HERE); | 2109 | fetch_token (¤t_token, regexp, syntax | RE_CARET_ANCHORS_HERE); |
2065 | tree = parse_reg_exp (regexp, preg, ¤t_token, syntax, 0, err); | 2110 | tree = parse_reg_exp (regexp, preg, ¤t_token, syntax, 0, err); |
2066 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) | 2111 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) |
2067 | return NULL; | 2112 | return NULL; |
@@ -2091,7 +2136,7 @@ static bin_tree_t * | |||
2091 | parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, | 2136 | parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, |
2092 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) | 2137 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) |
2093 | { | 2138 | { |
2094 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 2139 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
2095 | bin_tree_t *tree, *branch = NULL; | 2140 | bin_tree_t *tree, *branch = NULL; |
2096 | tree = parse_branch (regexp, preg, token, syntax, nest, err); | 2141 | tree = parse_branch (regexp, preg, token, syntax, nest, err); |
2097 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) | 2142 | 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, | |||
2099 | 2144 | ||
2100 | while (token->type == OP_ALT) | 2145 | while (token->type == OP_ALT) |
2101 | { | 2146 | { |
2102 | fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE); | 2147 | fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); |
2103 | if (token->type != OP_ALT && token->type != END_OF_RE | 2148 | if (token->type != OP_ALT && token->type != END_OF_RE |
2104 | && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) | 2149 | && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) |
2105 | { | 2150 | { |
@@ -2132,8 +2177,8 @@ static bin_tree_t * | |||
2132 | parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, | 2177 | parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, |
2133 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) | 2178 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) |
2134 | { | 2179 | { |
2135 | bin_tree_t *tree, *exp; | 2180 | bin_tree_t *tree, *expr; |
2136 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 2181 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
2137 | tree = parse_expression (regexp, preg, token, syntax, nest, err); | 2182 | tree = parse_expression (regexp, preg, token, syntax, nest, err); |
2138 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) | 2183 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) |
2139 | return NULL; | 2184 | return NULL; |
@@ -2141,14 +2186,14 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, | |||
2141 | while (token->type != OP_ALT && token->type != END_OF_RE | 2186 | while (token->type != OP_ALT && token->type != END_OF_RE |
2142 | && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) | 2187 | && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) |
2143 | { | 2188 | { |
2144 | exp = parse_expression (regexp, preg, token, syntax, nest, err); | 2189 | expr = parse_expression (regexp, preg, token, syntax, nest, err); |
2145 | if (BE (*err != REG_NOERROR && exp == NULL, 0)) | 2190 | if (BE (*err != REG_NOERROR && expr == NULL, 0)) |
2146 | { | 2191 | { |
2147 | return NULL; | 2192 | return NULL; |
2148 | } | 2193 | } |
2149 | if (tree != NULL && exp != NULL) | 2194 | if (tree != NULL && expr != NULL) |
2150 | { | 2195 | { |
2151 | tree = create_tree (dfa, tree, exp, CONCAT); | 2196 | tree = create_tree (dfa, tree, expr, CONCAT); |
2152 | if (tree == NULL) | 2197 | if (tree == NULL) |
2153 | { | 2198 | { |
2154 | *err = REG_ESPACE; | 2199 | *err = REG_ESPACE; |
@@ -2156,8 +2201,8 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, | |||
2156 | } | 2201 | } |
2157 | } | 2202 | } |
2158 | else if (tree == NULL) | 2203 | else if (tree == NULL) |
2159 | tree = exp; | 2204 | tree = expr; |
2160 | /* Otherwise exp == NULL, we don't need to create new tree. */ | 2205 | /* Otherwise expr == NULL, we don't need to create new tree. */ |
2161 | } | 2206 | } |
2162 | return tree; | 2207 | return tree; |
2163 | } | 2208 | } |
@@ -2172,7 +2217,7 @@ static bin_tree_t * | |||
2172 | parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, | 2217 | parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, |
2173 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) | 2218 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) |
2174 | { | 2219 | { |
2175 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 2220 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
2176 | bin_tree_t *tree; | 2221 | bin_tree_t *tree; |
2177 | switch (token->type) | 2222 | switch (token->type) |
2178 | { | 2223 | { |
@@ -2229,7 +2274,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, | |||
2229 | dfa->has_mb_node = 1; | 2274 | dfa->has_mb_node = 1; |
2230 | break; | 2275 | break; |
2231 | case OP_OPEN_DUP_NUM: | 2276 | case OP_OPEN_DUP_NUM: |
2232 | if (syntax & REG_CONTEXT_INVALID_DUP) | 2277 | if (syntax & RE_CONTEXT_INVALID_DUP) |
2233 | { | 2278 | { |
2234 | *err = REG_BADRPT; | 2279 | *err = REG_BADRPT; |
2235 | return NULL; | 2280 | return NULL; |
@@ -2238,12 +2283,12 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, | |||
2238 | case OP_DUP_ASTERISK: | 2283 | case OP_DUP_ASTERISK: |
2239 | case OP_DUP_PLUS: | 2284 | case OP_DUP_PLUS: |
2240 | case OP_DUP_QUESTION: | 2285 | case OP_DUP_QUESTION: |
2241 | if (syntax & REG_CONTEXT_INVALID_OPS) | 2286 | if (syntax & RE_CONTEXT_INVALID_OPS) |
2242 | { | 2287 | { |
2243 | *err = REG_BADRPT; | 2288 | *err = REG_BADRPT; |
2244 | return NULL; | 2289 | return NULL; |
2245 | } | 2290 | } |
2246 | else if (syntax & REG_CONTEXT_INDEP_OPS) | 2291 | else if (syntax & RE_CONTEXT_INDEP_OPS) |
2247 | { | 2292 | { |
2248 | fetch_token (token, regexp, syntax); | 2293 | fetch_token (token, regexp, syntax); |
2249 | return parse_expression (regexp, preg, token, syntax, nest, err); | 2294 | 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, | |||
2251 | /* else fall through */ | 2296 | /* else fall through */ |
2252 | case OP_CLOSE_SUBEXP: | 2297 | case OP_CLOSE_SUBEXP: |
2253 | if ((token->type == OP_CLOSE_SUBEXP) && | 2298 | if ((token->type == OP_CLOSE_SUBEXP) && |
2254 | !(syntax & REG_UNMATCHED_RIGHT_PAREN_ORD)) | 2299 | !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) |
2255 | { | 2300 | { |
2256 | *err = REG_ERPAREN; | 2301 | *err = REG_ERPAREN; |
2257 | return NULL; | 2302 | return NULL; |
@@ -2365,7 +2410,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, | |||
2365 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) | 2410 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) |
2366 | return NULL; | 2411 | return NULL; |
2367 | /* In BRE consecutive duplications are not allowed. */ | 2412 | /* In BRE consecutive duplications are not allowed. */ |
2368 | if ((syntax & REG_CONTEXT_INVALID_DUP) | 2413 | if ((syntax & RE_CONTEXT_INVALID_DUP) |
2369 | && (token->type == OP_DUP_ASTERISK | 2414 | && (token->type == OP_DUP_ASTERISK |
2370 | || token->type == OP_OPEN_DUP_NUM)) | 2415 | || token->type == OP_OPEN_DUP_NUM)) |
2371 | { | 2416 | { |
@@ -2388,12 +2433,12 @@ static bin_tree_t * | |||
2388 | parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, | 2433 | parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, |
2389 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) | 2434 | reg_syntax_t syntax, Idx nest, reg_errcode_t *err) |
2390 | { | 2435 | { |
2391 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 2436 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
2392 | bin_tree_t *tree; | 2437 | bin_tree_t *tree; |
2393 | size_t cur_nsub; | 2438 | size_t cur_nsub; |
2394 | cur_nsub = preg->re_nsub++; | 2439 | cur_nsub = preg->re_nsub++; |
2395 | 2440 | ||
2396 | fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE); | 2441 | fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); |
2397 | 2442 | ||
2398 | /* The subexpression may be a null string. */ | 2443 | /* The subexpression may be a null string. */ |
2399 | if (token->type == OP_CLOSE_SUBEXP) | 2444 | 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, | |||
2454 | if (BE (start == REG_ERROR || end == REG_ERROR, 0)) | 2499 | if (BE (start == REG_ERROR || end == REG_ERROR, 0)) |
2455 | { | 2500 | { |
2456 | /* Invalid sequence. */ | 2501 | /* Invalid sequence. */ |
2457 | if (BE (!(syntax & REG_INVALID_INTERVAL_ORD), 0)) | 2502 | if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0)) |
2458 | { | 2503 | { |
2459 | if (token->type == END_OF_RE) | 2504 | if (token->type == END_OF_RE) |
2460 | *err = REG_EBRACE; | 2505 | *err = REG_EBRACE; |
@@ -2565,11 +2610,14 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, | |||
2565 | update it. */ | 2610 | update it. */ |
2566 | 2611 | ||
2567 | static reg_errcode_t | 2612 | static reg_errcode_t |
2568 | build_range_exp (bitset sbcset, | 2613 | internal_function |
2569 | # ifdef RE_ENABLE_I18N | 2614 | # ifdef RE_ENABLE_I18N |
2570 | re_charset_t *mbcset, Idx *range_alloc, | 2615 | build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, |
2571 | # endif | ||
2572 | bracket_elem_t *start_elem, bracket_elem_t *end_elem) | 2616 | bracket_elem_t *start_elem, bracket_elem_t *end_elem) |
2617 | # else /* not RE_ENABLE_I18N */ | ||
2618 | build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, | ||
2619 | bracket_elem_t *end_elem) | ||
2620 | # endif /* not RE_ENABLE_I18N */ | ||
2573 | { | 2621 | { |
2574 | unsigned int start_ch, end_ch; | 2622 | unsigned int start_ch, end_ch; |
2575 | /* Equivalence Classes and Character Classes can't be a range start/end. */ | 2623 | /* Equivalence Classes and Character Classes can't be a range start/end. */ |
@@ -2589,7 +2637,8 @@ build_range_exp (bitset sbcset, | |||
2589 | # ifdef RE_ENABLE_I18N | 2637 | # ifdef RE_ENABLE_I18N |
2590 | { | 2638 | { |
2591 | wchar_t wc; | 2639 | wchar_t wc; |
2592 | wint_t start_wc, end_wc; | 2640 | wint_t start_wc; |
2641 | wint_t end_wc; | ||
2593 | wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; | 2642 | wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; |
2594 | 2643 | ||
2595 | start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch | 2644 | start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch |
@@ -2623,11 +2672,12 @@ build_range_exp (bitset sbcset, | |||
2623 | wchar_t *new_array_start, *new_array_end; | 2672 | wchar_t *new_array_start, *new_array_end; |
2624 | Idx new_nranges; | 2673 | Idx new_nranges; |
2625 | 2674 | ||
2626 | new_nranges = mbcset->nranges; | 2675 | /* +1 in case of mbcset->nranges is 0. */ |
2676 | new_nranges = 2 * mbcset->nranges + 1; | ||
2627 | /* Use realloc since mbcset->range_starts and mbcset->range_ends | 2677 | /* Use realloc since mbcset->range_starts and mbcset->range_ends |
2628 | are NULL if *range_alloc == 0. */ | 2678 | are NULL if *range_alloc == 0. */ |
2629 | new_array_start = re_x2realloc (mbcset->range_starts, wchar_t, | 2679 | new_array_start = re_realloc (mbcset->range_starts, wchar_t, |
2630 | &new_nranges); | 2680 | new_nranges); |
2631 | new_array_end = re_realloc (mbcset->range_ends, wchar_t, | 2681 | new_array_end = re_realloc (mbcset->range_ends, wchar_t, |
2632 | new_nranges); | 2682 | new_nranges); |
2633 | 2683 | ||
@@ -2681,7 +2731,8 @@ build_range_exp (bitset sbcset, | |||
2681 | pointer argument since we may update it. */ | 2731 | pointer argument since we may update it. */ |
2682 | 2732 | ||
2683 | static reg_errcode_t | 2733 | static reg_errcode_t |
2684 | build_collating_symbol (bitset sbcset, | 2734 | internal_function |
2735 | build_collating_symbol (bitset_t sbcset, | ||
2685 | # ifdef RE_ENABLE_I18N | 2736 | # ifdef RE_ENABLE_I18N |
2686 | re_charset_t *mbcset, Idx *coll_sym_alloc, | 2737 | re_charset_t *mbcset, Idx *coll_sym_alloc, |
2687 | # endif | 2738 | # endif |
@@ -2719,27 +2770,34 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2719 | 2770 | ||
2720 | auto inline int32_t | 2771 | auto inline int32_t |
2721 | __attribute ((always_inline)) | 2772 | __attribute ((always_inline)) |
2722 | seek_collating_symbol_entry (const unsigned char *name, size_t name_len) | 2773 | seek_collating_symbol_entry (name, name_len) |
2774 | const unsigned char *name; | ||
2775 | size_t name_len; | ||
2723 | { | 2776 | { |
2724 | int32_t hash = elem_hash ((const char *) name, name_len); | 2777 | int32_t hash = elem_hash ((const char *) name, name_len); |
2725 | int32_t elem = hash % table_size; | 2778 | int32_t elem = hash % table_size; |
2726 | int32_t second = hash % (table_size - 2); | 2779 | if (symb_table[2 * elem] != 0) |
2727 | while (symb_table[2 * elem] != 0) | 2780 | { |
2728 | { | 2781 | int32_t second = hash % (table_size - 2) + 1; |
2729 | /* First compare the hashing value. */ | 2782 | |
2730 | if (symb_table[2 * elem] == hash | 2783 | do |
2731 | /* Compare the length of the name. */ | ||
2732 | && name_len == extra[symb_table[2 * elem + 1]] | ||
2733 | /* Compare the name. */ | ||
2734 | && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], | ||
2735 | name_len) == 0) | ||
2736 | { | 2784 | { |
2737 | /* Yep, this is the entry. */ | 2785 | /* First compare the hashing value. */ |
2738 | break; | 2786 | if (symb_table[2 * elem] == hash |
2739 | } | 2787 | /* Compare the length of the name. */ |
2788 | && name_len == extra[symb_table[2 * elem + 1]] | ||
2789 | /* Compare the name. */ | ||
2790 | && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], | ||
2791 | name_len) == 0) | ||
2792 | { | ||
2793 | /* Yep, this is the entry. */ | ||
2794 | break; | ||
2795 | } | ||
2740 | 2796 | ||
2741 | /* Next entry. */ | 2797 | /* Next entry. */ |
2742 | elem += second; | 2798 | elem += second; |
2799 | } | ||
2800 | while (symb_table[2 * elem] != 0); | ||
2743 | } | 2801 | } |
2744 | return elem; | 2802 | return elem; |
2745 | } | 2803 | } |
@@ -2750,7 +2808,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2750 | 2808 | ||
2751 | auto inline unsigned int | 2809 | auto inline unsigned int |
2752 | __attribute ((always_inline)) | 2810 | __attribute ((always_inline)) |
2753 | lookup_collation_sequence_value (bracket_elem_t *br_elem) | 2811 | lookup_collation_sequence_value (br_elem) |
2812 | bracket_elem_t *br_elem; | ||
2754 | { | 2813 | { |
2755 | if (br_elem->type == SB_CHAR) | 2814 | if (br_elem->type == SB_CHAR) |
2756 | { | 2815 | { |
@@ -2817,9 +2876,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2817 | 2876 | ||
2818 | auto inline reg_errcode_t | 2877 | auto inline reg_errcode_t |
2819 | __attribute ((always_inline)) | 2878 | __attribute ((always_inline)) |
2820 | build_range_exp (bitset sbcset, re_charset_t *mbcset, | 2879 | build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem) |
2821 | Idx *range_alloc, | 2880 | re_charset_t *mbcset; |
2822 | bracket_elem_t *start_elem, bracket_elem_t *end_elem) | 2881 | Idx *range_alloc; |
2882 | bitset_t sbcset; | ||
2883 | bracket_elem_t *start_elem, *end_elem; | ||
2823 | { | 2884 | { |
2824 | unsigned int ch; | 2885 | unsigned int ch; |
2825 | uint32_t start_collseq; | 2886 | uint32_t start_collseq; |
@@ -2837,7 +2898,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2837 | /* Check start/end collation sequence values. */ | 2898 | /* Check start/end collation sequence values. */ |
2838 | if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) | 2899 | if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) |
2839 | return REG_ECOLLATE; | 2900 | return REG_ECOLLATE; |
2840 | if (BE ((syntax & REG_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) | 2901 | if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) |
2841 | return REG_ERANGE; | 2902 | return REG_ERANGE; |
2842 | 2903 | ||
2843 | /* Got valid collation sequence values, add them as a new entry. | 2904 | /* 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, | |||
2854 | uint32_t *new_array_end; | 2915 | uint32_t *new_array_end; |
2855 | Idx new_nranges; | 2916 | Idx new_nranges; |
2856 | 2917 | ||
2857 | new_nranges = mbcset->nranges; | 2918 | /* +1 in case of mbcset->nranges is 0. */ |
2858 | new_array_start = re_x2realloc (mbcset->range_starts, uint32_t, | 2919 | new_nranges = 2 * mbcset->nranges + 1; |
2859 | &new_nranges); | 2920 | new_array_start = re_realloc (mbcset->range_starts, uint32_t, |
2921 | new_nranges); | ||
2860 | new_array_end = re_realloc (mbcset->range_ends, uint32_t, | 2922 | new_array_end = re_realloc (mbcset->range_ends, uint32_t, |
2861 | new_nranges); | 2923 | new_nranges); |
2862 | 2924 | ||
@@ -2897,8 +2959,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2897 | 2959 | ||
2898 | auto inline reg_errcode_t | 2960 | auto inline reg_errcode_t |
2899 | __attribute ((always_inline)) | 2961 | __attribute ((always_inline)) |
2900 | build_collating_symbol (bitset sbcset, re_charset_t *mbcset, | 2962 | build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name) |
2901 | Idx *coll_sym_alloc, const unsigned char *name) | 2963 | re_charset_t *mbcset; |
2964 | Idx *coll_sym_alloc; | ||
2965 | bitset_t sbcset; | ||
2966 | const unsigned char *name; | ||
2902 | { | 2967 | { |
2903 | int32_t elem, idx; | 2968 | int32_t elem, idx; |
2904 | size_t name_len = strlen ((const char *) name); | 2969 | 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, | |||
2927 | if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0)) | 2992 | if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0)) |
2928 | { | 2993 | { |
2929 | /* Not enough, realloc it. */ | 2994 | /* Not enough, realloc it. */ |
2930 | Idx new_coll_sym_alloc = mbcset->ncoll_syms; | 2995 | /* +1 in case of mbcset->ncoll_syms is 0. */ |
2996 | Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1; | ||
2931 | /* Use realloc since mbcset->coll_syms is NULL | 2997 | /* Use realloc since mbcset->coll_syms is NULL |
2932 | if *alloc == 0. */ | 2998 | if *alloc == 0. */ |
2933 | int32_t *new_coll_syms = re_x2realloc (mbcset->coll_syms, int32_t, | 2999 | int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t, |
2934 | &new_coll_sym_alloc); | 3000 | new_coll_sym_alloc); |
2935 | if (BE (new_coll_syms == NULL, 0)) | 3001 | if (BE (new_coll_syms == NULL, 0)) |
2936 | return REG_ESPACE; | 3002 | return REG_ESPACE; |
2937 | mbcset->coll_syms = new_coll_syms; | 3003 | 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, | |||
2973 | /* | 3039 | /* |
2974 | if (MB_CUR_MAX > 1) | 3040 | if (MB_CUR_MAX > 1) |
2975 | */ | 3041 | */ |
2976 | collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); | 3042 | collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); |
2977 | table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); | 3043 | table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); |
2978 | symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, | 3044 | symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, |
2979 | _NL_COLLATE_SYMB_TABLEMB); | 3045 | _NL_COLLATE_SYMB_TABLEMB); |
@@ -2981,9 +3047,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, | |||
2981 | _NL_COLLATE_SYMB_EXTRAMB); | 3047 | _NL_COLLATE_SYMB_EXTRAMB); |
2982 | } | 3048 | } |
2983 | #endif | 3049 | #endif |
2984 | sbcset = re_calloc (bitset_word, BITSET_WORDS); | 3050 | sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); |
2985 | #ifdef RE_ENABLE_I18N | 3051 | #ifdef RE_ENABLE_I18N |
2986 | mbcset = re_calloc (re_charset_t, 1); | 3052 | mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); |
2987 | #endif /* RE_ENABLE_I18N */ | 3053 | #endif /* RE_ENABLE_I18N */ |
2988 | #ifdef RE_ENABLE_I18N | 3054 | #ifdef RE_ENABLE_I18N |
2989 | if (BE (sbcset == NULL || mbcset == NULL, 0)) | 3055 | 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, | |||
3007 | mbcset->non_match = 1; | 3073 | mbcset->non_match = 1; |
3008 | #endif /* not RE_ENABLE_I18N */ | 3074 | #endif /* not RE_ENABLE_I18N */ |
3009 | non_match = true; | 3075 | non_match = true; |
3010 | if (syntax & REG_HAT_LISTS_NOT_NEWLINE) | 3076 | if (syntax & RE_HAT_LISTS_NOT_NEWLINE) |
3011 | bitset_set (sbcset, '\0'); | 3077 | bitset_set (sbcset, '\0'); |
3012 | re_string_skip_bytes (regexp, token_len); /* Skip a token. */ | 3078 | re_string_skip_bytes (regexp, token_len); /* Skip a token. */ |
3013 | token_len = peek_token_bracket (token, regexp, syntax); | 3079 | 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, | |||
3115 | { | 3181 | { |
3116 | wchar_t *new_mbchars; | 3182 | wchar_t *new_mbchars; |
3117 | /* Not enough, realloc it. */ | 3183 | /* Not enough, realloc it. */ |
3118 | mbchar_alloc = mbcset->nmbchars; | 3184 | /* +1 in case of mbcset->nmbchars is 0. */ |
3185 | mbchar_alloc = 2 * mbcset->nmbchars + 1; | ||
3119 | /* Use realloc since array is NULL if *alloc == 0. */ | 3186 | /* Use realloc since array is NULL if *alloc == 0. */ |
3120 | new_mbchars = re_x2realloc (mbcset->mbchars, wchar_t, | 3187 | new_mbchars = re_realloc (mbcset->mbchars, wchar_t, |
3121 | &mbchar_alloc); | 3188 | mbchar_alloc); |
3122 | if (BE (new_mbchars == NULL, 0)) | 3189 | if (BE (new_mbchars == NULL, 0)) |
3123 | goto parse_bracket_exp_espace; | 3190 | goto parse_bracket_exp_espace; |
3124 | mbcset->mbchars = new_mbchars; | 3191 | mbcset->mbchars = new_mbchars; |
@@ -3331,13 +3398,14 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp, | |||
3331 | is a pointer argument sinse we may update it. */ | 3398 | is a pointer argument sinse we may update it. */ |
3332 | 3399 | ||
3333 | static reg_errcode_t | 3400 | static reg_errcode_t |
3334 | build_equiv_class (bitset sbcset, | ||
3335 | #ifdef RE_ENABLE_I18N | 3401 | #ifdef RE_ENABLE_I18N |
3336 | re_charset_t *mbcset, Idx *equiv_class_alloc, | 3402 | build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, |
3337 | #endif | 3403 | Idx *equiv_class_alloc, const unsigned char *name) |
3338 | const unsigned char *name) | 3404 | #else /* not RE_ENABLE_I18N */ |
3405 | build_equiv_class (bitset_t sbcset, const unsigned char *name) | ||
3406 | #endif /* not RE_ENABLE_I18N */ | ||
3339 | { | 3407 | { |
3340 | #if defined _LIBC | 3408 | #ifdef _LIBC |
3341 | uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); | 3409 | uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); |
3342 | if (nrules != 0) | 3410 | if (nrules != 0) |
3343 | { | 3411 | { |
@@ -3392,11 +3460,12 @@ build_equiv_class (bitset sbcset, | |||
3392 | if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) | 3460 | if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) |
3393 | { | 3461 | { |
3394 | /* Not enough, realloc it. */ | 3462 | /* Not enough, realloc it. */ |
3395 | Idx new_equiv_class_alloc = mbcset->nequiv_classes; | 3463 | /* +1 in case of mbcset->nequiv_classes is 0. */ |
3464 | Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1; | ||
3396 | /* Use realloc since the array is NULL if *alloc == 0. */ | 3465 | /* Use realloc since the array is NULL if *alloc == 0. */ |
3397 | int32_t *new_equiv_classes = re_x2realloc (mbcset->equiv_classes, | 3466 | int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes, |
3398 | int32_t, | 3467 | int32_t, |
3399 | &new_equiv_class_alloc); | 3468 | new_equiv_class_alloc); |
3400 | if (BE (new_equiv_classes == NULL, 0)) | 3469 | if (BE (new_equiv_classes == NULL, 0)) |
3401 | return REG_ESPACE; | 3470 | return REG_ESPACE; |
3402 | mbcset->equiv_classes = new_equiv_classes; | 3471 | mbcset->equiv_classes = new_equiv_classes; |
@@ -3421,18 +3490,21 @@ build_equiv_class (bitset sbcset, | |||
3421 | is a pointer argument sinse we may update it. */ | 3490 | is a pointer argument sinse we may update it. */ |
3422 | 3491 | ||
3423 | static reg_errcode_t | 3492 | static reg_errcode_t |
3424 | build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, | ||
3425 | #ifdef RE_ENABLE_I18N | 3493 | #ifdef RE_ENABLE_I18N |
3494 | build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, | ||
3426 | re_charset_t *mbcset, Idx *char_class_alloc, | 3495 | re_charset_t *mbcset, Idx *char_class_alloc, |
3427 | #endif | ||
3428 | const unsigned char *class_name, reg_syntax_t syntax) | 3496 | const unsigned char *class_name, reg_syntax_t syntax) |
3497 | #else /* not RE_ENABLE_I18N */ | ||
3498 | build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, | ||
3499 | const unsigned char *class_name, reg_syntax_t syntax) | ||
3500 | #endif /* not RE_ENABLE_I18N */ | ||
3429 | { | 3501 | { |
3430 | int i; | 3502 | int i; |
3431 | const char *name = (const char *) class_name; | 3503 | const char *name = (const char *) class_name; |
3432 | 3504 | ||
3433 | /* In case of REG_ICASE "upper" and "lower" match the both of | 3505 | /* In case of REG_ICASE "upper" and "lower" match the both of |
3434 | upper and lower cases. */ | 3506 | upper and lower cases. */ |
3435 | if ((syntax & REG_IGNORE_CASE) | 3507 | if ((syntax & RE_ICASE) |
3436 | && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0)) | 3508 | && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0)) |
3437 | name = "alpha"; | 3509 | name = "alpha"; |
3438 | 3510 | ||
@@ -3441,10 +3513,11 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, | |||
3441 | if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) | 3513 | if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) |
3442 | { | 3514 | { |
3443 | /* Not enough, realloc it. */ | 3515 | /* Not enough, realloc it. */ |
3444 | Idx new_char_class_alloc = mbcset->nchar_classes; | 3516 | /* +1 in case of mbcset->nchar_classes is 0. */ |
3517 | Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1; | ||
3445 | /* Use realloc since array is NULL if *alloc == 0. */ | 3518 | /* Use realloc since array is NULL if *alloc == 0. */ |
3446 | wctype_t *new_char_classes = re_x2realloc (mbcset->char_classes, wctype_t, | 3519 | wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t, |
3447 | &new_char_class_alloc); | 3520 | new_char_class_alloc); |
3448 | if (BE (new_char_classes == NULL, 0)) | 3521 | if (BE (new_char_classes == NULL, 0)) |
3449 | return REG_ESPACE; | 3522 | return REG_ESPACE; |
3450 | mbcset->char_classes = new_char_classes; | 3523 | mbcset->char_classes = new_char_classes; |
@@ -3454,39 +3527,45 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, | |||
3454 | #endif /* RE_ENABLE_I18N */ | 3527 | #endif /* RE_ENABLE_I18N */ |
3455 | 3528 | ||
3456 | #define BUILD_CHARCLASS_LOOP(ctype_func) \ | 3529 | #define BUILD_CHARCLASS_LOOP(ctype_func) \ |
3457 | for (i = 0; i < SBC_MAX; ++i) \ | 3530 | do { \ |
3531 | if (BE (trans != NULL, 0)) \ | ||
3458 | { \ | 3532 | { \ |
3459 | if (ctype_func (i)) \ | 3533 | for (i = 0; i < SBC_MAX; ++i) \ |
3460 | { \ | 3534 | if (ctype_func (i)) \ |
3461 | int ch = trans ? trans[i] : i; \ | 3535 | bitset_set (sbcset, trans[i]); \ |
3462 | bitset_set (sbcset, ch); \ | 3536 | } \ |
3463 | } \ | 3537 | else \ |
3464 | } | 3538 | { \ |
3539 | for (i = 0; i < SBC_MAX; ++i) \ | ||
3540 | if (ctype_func (i)) \ | ||
3541 | bitset_set (sbcset, i); \ | ||
3542 | } \ | ||
3543 | } while (0) | ||
3465 | 3544 | ||
3466 | if (strcmp (name, "alnum") == 0) | 3545 | if (strcmp (name, "alnum") == 0) |
3467 | BUILD_CHARCLASS_LOOP (isalnum) | 3546 | BUILD_CHARCLASS_LOOP (isalnum); |
3468 | else if (strcmp (name, "cntrl") == 0) | 3547 | else if (strcmp (name, "cntrl") == 0) |
3469 | BUILD_CHARCLASS_LOOP (iscntrl) | 3548 | BUILD_CHARCLASS_LOOP (iscntrl); |
3470 | else if (strcmp (name, "lower") == 0) | 3549 | else if (strcmp (name, "lower") == 0) |
3471 | BUILD_CHARCLASS_LOOP (islower) | 3550 | BUILD_CHARCLASS_LOOP (islower); |
3472 | else if (strcmp (name, "space") == 0) | 3551 | else if (strcmp (name, "space") == 0) |
3473 | BUILD_CHARCLASS_LOOP (isspace) | 3552 | BUILD_CHARCLASS_LOOP (isspace); |
3474 | else if (strcmp (name, "alpha") == 0) | 3553 | else if (strcmp (name, "alpha") == 0) |
3475 | BUILD_CHARCLASS_LOOP (isalpha) | 3554 | BUILD_CHARCLASS_LOOP (isalpha); |
3476 | else if (strcmp (name, "digit") == 0) | 3555 | else if (strcmp (name, "digit") == 0) |
3477 | BUILD_CHARCLASS_LOOP (isdigit) | 3556 | BUILD_CHARCLASS_LOOP (isdigit); |
3478 | else if (strcmp (name, "print") == 0) | 3557 | else if (strcmp (name, "print") == 0) |
3479 | BUILD_CHARCLASS_LOOP (isprint) | 3558 | BUILD_CHARCLASS_LOOP (isprint); |
3480 | else if (strcmp (name, "upper") == 0) | 3559 | else if (strcmp (name, "upper") == 0) |
3481 | BUILD_CHARCLASS_LOOP (isupper) | 3560 | BUILD_CHARCLASS_LOOP (isupper); |
3482 | else if (strcmp (name, "blank") == 0) | 3561 | else if (strcmp (name, "blank") == 0) |
3483 | BUILD_CHARCLASS_LOOP (isblank) | 3562 | BUILD_CHARCLASS_LOOP (isblank); |
3484 | else if (strcmp (name, "graph") == 0) | 3563 | else if (strcmp (name, "graph") == 0) |
3485 | BUILD_CHARCLASS_LOOP (isgraph) | 3564 | BUILD_CHARCLASS_LOOP (isgraph); |
3486 | else if (strcmp (name, "punct") == 0) | 3565 | else if (strcmp (name, "punct") == 0) |
3487 | BUILD_CHARCLASS_LOOP (ispunct) | 3566 | BUILD_CHARCLASS_LOOP (ispunct); |
3488 | else if (strcmp (name, "xdigit") == 0) | 3567 | else if (strcmp (name, "xdigit") == 0) |
3489 | BUILD_CHARCLASS_LOOP (isxdigit) | 3568 | BUILD_CHARCLASS_LOOP (isxdigit); |
3490 | else | 3569 | else |
3491 | return REG_ECTYPE; | 3570 | return REG_ECTYPE; |
3492 | 3571 | ||
@@ -3494,10 +3573,10 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, | |||
3494 | } | 3573 | } |
3495 | 3574 | ||
3496 | static bin_tree_t * | 3575 | static bin_tree_t * |
3497 | build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, | 3576 | build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans, |
3498 | const unsigned char *class_name, | 3577 | const unsigned char *class_name, |
3499 | const unsigned char *extra, | 3578 | const unsigned char *extra, bool non_match, |
3500 | bool non_match, reg_errcode_t *err) | 3579 | reg_errcode_t *err) |
3501 | { | 3580 | { |
3502 | re_bitset_ptr_t sbcset; | 3581 | re_bitset_ptr_t sbcset; |
3503 | #ifdef RE_ENABLE_I18N | 3582 | #ifdef RE_ENABLE_I18N |
@@ -3508,9 +3587,9 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, | |||
3508 | re_token_t br_token; | 3587 | re_token_t br_token; |
3509 | bin_tree_t *tree; | 3588 | bin_tree_t *tree; |
3510 | 3589 | ||
3511 | sbcset = re_calloc (bitset_word, BITSET_WORDS); | 3590 | sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); |
3512 | #ifdef RE_ENABLE_I18N | 3591 | #ifdef RE_ENABLE_I18N |
3513 | mbcset = re_calloc (re_charset_t, 1); | 3592 | mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); |
3514 | #endif /* RE_ENABLE_I18N */ | 3593 | #endif /* RE_ENABLE_I18N */ |
3515 | 3594 | ||
3516 | #ifdef RE_ENABLE_I18N | 3595 | #ifdef RE_ENABLE_I18N |
@@ -3527,7 +3606,7 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, | |||
3527 | { | 3606 | { |
3528 | #ifdef RE_ENABLE_I18N | 3607 | #ifdef RE_ENABLE_I18N |
3529 | /* | 3608 | /* |
3530 | if (syntax & REG_HAT_LISTS_NOT_NEWLINE) | 3609 | if (syntax & RE_HAT_LISTS_NOT_NEWLINE) |
3531 | bitset_set(cset->sbcset, '\0'); | 3610 | bitset_set(cset->sbcset, '\0'); |
3532 | */ | 3611 | */ |
3533 | mbcset->non_match = 1; | 3612 | mbcset->non_match = 1; |
@@ -3627,7 +3706,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) | |||
3627 | || num == REG_ERROR) | 3706 | || num == REG_ERROR) |
3628 | ? REG_ERROR | 3707 | ? REG_ERROR |
3629 | : ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0')); | 3708 | : ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0')); |
3630 | num = (num > REG_DUP_MAX) ? REG_ERROR : num; | 3709 | num = (num > RE_DUP_MAX) ? REG_ERROR : num; |
3631 | } | 3710 | } |
3632 | return num; | 3711 | return num; |
3633 | } | 3712 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002, 2003 Free Software Foundation, Inc. | 2 | Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
@@ -17,8 +17,11 @@ | |||
17 | with this program; if not, write to the Free Software Foundation, | 17 | with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | 21 | |
22 | /* Make sure noone compiles this code with a C++ compiler. */ | ||
23 | #if defined __cplusplus && defined _LIBC | ||
24 | # error "This is C code, use a C compiler" | ||
22 | #endif | 25 | #endif |
23 | 26 | ||
24 | #ifdef _LIBC | 27 | #ifdef _LIBC |
@@ -1,6 +1,6 @@ | |||
1 | /* Definitions for data structures and routines for the regular | 1 | /* Definitions for data structures and routines for the regular |
2 | expression library. | 2 | expression library. |
3 | Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005 | 3 | Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006 |
4 | Free Software Foundation, Inc. | 4 | Free Software Foundation, Inc. |
5 | This file is part of the GNU C Library. | 5 | This file is part of the GNU C Library. |
6 | 6 | ||
@@ -28,19 +28,13 @@ | |||
28 | extern "C" { | 28 | extern "C" { |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | /* Define _REGEX_SOURCE to get definitions that are incompatible with | 31 | /* Define __USE_GNU_REGEX to declare GNU extensions that violate the |
32 | POSIX. */ | 32 | POSIX name space rules. */ |
33 | #if (!defined _REGEX_SOURCE \ | 33 | #undef __USE_GNU_REGEX |
34 | && (defined _GNU_SOURCE \ | 34 | #if (defined _GNU_SOURCE \ |
35 | || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \ | 35 | || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \ |
36 | && !defined _XOPEN_SOURCE))) | 36 | && !defined _XOPEN_SOURCE)) |
37 | # define _REGEX_SOURCE 1 | 37 | # define __USE_GNU_REGEX 1 |
38 | #endif | ||
39 | |||
40 | #if defined _REGEX_SOURCE && defined VMS | ||
41 | /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it | ||
42 | should be there. */ | ||
43 | # include <stddef.h> | ||
44 | #endif | 38 | #endif |
45 | 39 | ||
46 | #ifdef _REGEX_LARGE_OFFSETS | 40 | #ifdef _REGEX_LARGE_OFFSETS |
@@ -53,11 +47,13 @@ extern "C" { | |||
53 | 47 | ||
54 | /* The type of the offset of a byte within a string. | 48 | /* The type of the offset of a byte within a string. |
55 | For historical reasons POSIX 1003.1-2004 requires that regoff_t be | 49 | For historical reasons POSIX 1003.1-2004 requires that regoff_t be |
56 | at least as wide as off_t. This is a bit odd (and many common | 50 | at least as wide as off_t. However, many common POSIX platforms set |
57 | POSIX platforms set it to the more-sensible ssize_t) but we might | 51 | regoff_t to the more-sensible ssize_t and the Open Group has |
58 | as well conform. We don't know of any hosts where ssize_t is wider | 52 | signalled its intention to change the requirement to be that |
59 | than off_t, so off_t is safe. */ | 53 | regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN |
60 | typedef off_t regoff_t; | 54 | 60 (2005-08-25). We don't know of any hosts where ssize_t or |
55 | ptrdiff_t is wider than ssize_t, so ssize_t is safe. */ | ||
56 | typedef ssize_t regoff_t; | ||
61 | 57 | ||
62 | /* The type of nonnegative object indexes. Traditionally, GNU regex | 58 | /* The type of nonnegative object indexes. Traditionally, GNU regex |
63 | uses 'int' for these. Code that uses __re_idx_t should work | 59 | uses 'int' for these. Code that uses __re_idx_t should work |
@@ -97,20 +93,22 @@ typedef unsigned long int active_reg_t; | |||
97 | add or remove a bit, only one other definition need change. */ | 93 | add or remove a bit, only one other definition need change. */ |
98 | typedef unsigned long int reg_syntax_t; | 94 | typedef unsigned long int reg_syntax_t; |
99 | 95 | ||
96 | #ifdef __USE_GNU_REGEX | ||
97 | |||
100 | /* If this bit is not set, then \ inside a bracket expression is literal. | 98 | /* If this bit is not set, then \ inside a bracket expression is literal. |
101 | If set, then such a \ quotes the following character. */ | 99 | If set, then such a \ quotes the following character. */ |
102 | #define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul | 100 | # define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) |
103 | 101 | ||
104 | /* If this bit is not set, then + and ? are operators, and \+ and \? are | 102 | /* If this bit is not set, then + and ? are operators, and \+ and \? are |
105 | literals. | 103 | literals. |
106 | If set, then \+ and \? are operators and + and ? are literals. */ | 104 | If set, then \+ and \? are operators and + and ? are literals. */ |
107 | #define REG_BK_PLUS_QM (1ul << 1) | 105 | # define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) |
108 | 106 | ||
109 | /* If this bit is set, then character classes are supported. They are: | 107 | /* If this bit is set, then character classes are supported. They are: |
110 | [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], | 108 | [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], |
111 | [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. | 109 | [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. |
112 | If not set, then character classes are not supported. */ | 110 | If not set, then character classes are not supported. */ |
113 | #define REG_CHAR_CLASSES (1ul << 2) | 111 | # define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) |
114 | 112 | ||
115 | /* If this bit is set, then ^ and $ are always anchors (outside bracket | 113 | /* If this bit is set, then ^ and $ are always anchors (outside bracket |
116 | expressions, of course). | 114 | expressions, of course). |
@@ -120,11 +118,11 @@ typedef unsigned long int reg_syntax_t; | |||
120 | $ is an anchor if it is at the end of a regular expression, or | 118 | $ is an anchor if it is at the end of a regular expression, or |
121 | before a close-group or an alternation operator. | 119 | before a close-group or an alternation operator. |
122 | 120 | ||
123 | This bit could be (re)combined with REG_CONTEXT_INDEP_OPS, because | 121 | This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because |
124 | POSIX draft 11.2 says that * etc. in leading positions is undefined. | 122 | POSIX draft 11.2 says that * etc. in leading positions is undefined. |
125 | We already implemented a previous draft which made those constructs | 123 | We already implemented a previous draft which made those constructs |
126 | invalid, though, so we haven't changed the code back. */ | 124 | invalid, though, so we haven't changed the code back. */ |
127 | #define REG_CONTEXT_INDEP_ANCHORS (1ul << 3) | 125 | # define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) |
128 | 126 | ||
129 | /* If this bit is set, then special characters are always special | 127 | /* If this bit is set, then special characters are always special |
130 | regardless of where they are in the pattern. | 128 | regardless of where they are in the pattern. |
@@ -132,70 +130,71 @@ typedef unsigned long int reg_syntax_t; | |||
132 | some contexts; otherwise they are ordinary. Specifically, | 130 | some contexts; otherwise they are ordinary. Specifically, |
133 | * + ? and intervals are only special when not after the beginning, | 131 | * + ? and intervals are only special when not after the beginning, |
134 | open-group, or alternation operator. */ | 132 | open-group, or alternation operator. */ |
135 | #define REG_CONTEXT_INDEP_OPS (1ul << 4) | 133 | # define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) |
136 | 134 | ||
137 | /* If this bit is set, then *, +, ?, and { cannot be first in an re or | 135 | /* If this bit is set, then *, +, ?, and { cannot be first in an re or |
138 | immediately after an alternation or begin-group operator. */ | 136 | immediately after an alternation or begin-group operator. */ |
139 | #define REG_CONTEXT_INVALID_OPS (1ul << 5) | 137 | # define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) |
140 | 138 | ||
141 | /* If this bit is set, then . matches newline. | 139 | /* If this bit is set, then . matches newline. |
142 | If not set, then it doesn't. */ | 140 | If not set, then it doesn't. */ |
143 | #define REG_DOT_NEWLINE (1ul << 6) | 141 | # define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) |
144 | 142 | ||
145 | /* If this bit is set, then . doesn't match NUL. | 143 | /* If this bit is set, then . doesn't match NUL. |
146 | If not set, then it does. */ | 144 | If not set, then it does. */ |
147 | #define REG_DOT_NOT_NULL (1ul << 7) | 145 | # define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) |
148 | 146 | ||
149 | /* If this bit is set, nonmatching lists [^...] do not match newline. | 147 | /* If this bit is set, nonmatching lists [^...] do not match newline. |
150 | If not set, they do. */ | 148 | If not set, they do. */ |
151 | #define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8) | 149 | # define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) |
152 | 150 | ||
153 | /* If this bit is set, either \{...\} or {...} defines an | 151 | /* If this bit is set, either \{...\} or {...} defines an |
154 | interval, depending on REG_NO_BK_BRACES. | 152 | interval, depending on RE_NO_BK_BRACES. |
155 | If not set, \{, \}, {, and } are literals. */ | 153 | If not set, \{, \}, {, and } are literals. */ |
156 | #define REG_INTERVALS (1ul << 9) | 154 | # define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) |
157 | 155 | ||
158 | /* If this bit is set, +, ? and | aren't recognized as operators. | 156 | /* If this bit is set, +, ? and | aren't recognized as operators. |
159 | If not set, they are. */ | 157 | If not set, they are. */ |
160 | #define REG_LIMITED_OPS (1ul << 10) | 158 | # define RE_LIMITED_OPS (RE_INTERVALS << 1) |
161 | 159 | ||
162 | /* If this bit is set, newline is an alternation operator. | 160 | /* If this bit is set, newline is an alternation operator. |
163 | If not set, newline is literal. */ | 161 | If not set, newline is literal. */ |
164 | #define REG_NEWLINE_ALT (1ul << 11) | 162 | # define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) |
165 | 163 | ||
166 | /* If this bit is set, then `{...}' defines an interval, and \{ and \} | 164 | /* If this bit is set, then `{...}' defines an interval, and \{ and \} |
167 | are literals. | 165 | are literals. |
168 | If not set, then `\{...\}' defines an interval. */ | 166 | If not set, then `\{...\}' defines an interval. */ |
169 | #define REG_NO_BK_BRACES (1ul << 12) | 167 | # define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) |
170 | 168 | ||
171 | /* If this bit is set, (...) defines a group, and \( and \) are literals. | 169 | /* If this bit is set, (...) defines a group, and \( and \) are literals. |
172 | If not set, \(...\) defines a group, and ( and ) are literals. */ | 170 | If not set, \(...\) defines a group, and ( and ) are literals. */ |
173 | #define REG_NO_BK_PARENS (1ul << 13) | 171 | # define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) |
174 | 172 | ||
175 | /* If this bit is set, then \<digit> matches <digit>. | 173 | /* If this bit is set, then \<digit> matches <digit>. |
176 | If not set, then \<digit> is a back-reference. */ | 174 | If not set, then \<digit> is a back-reference. */ |
177 | #define REG_NO_BK_REFS (1ul << 14) | 175 | # define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) |
178 | 176 | ||
179 | /* If this bit is set, then | is an alternation operator, and \| is literal. | 177 | /* If this bit is set, then | is an alternation operator, and \| is literal. |
180 | If not set, then \| is an alternation operator, and | is literal. */ | 178 | If not set, then \| is an alternation operator, and | is literal. */ |
181 | #define REG_NO_BK_VBAR (1ul << 15) | 179 | # define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) |
182 | 180 | ||
183 | /* If this bit is set, then an ending range point collating higher | 181 | /* If this bit is set, then an ending range point collating higher |
184 | than the starting range point, as in [z-a], is invalid. | 182 | than the starting range point, as in [z-a], is invalid. |
185 | If not set, the containing range is empty and does not match any string. */ | 183 | If not set, then when ending range point collates higher than the |
186 | #define REG_NO_EMPTY_RANGES (1ul << 16) | 184 | starting range point, the range is ignored. */ |
185 | # define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) | ||
187 | 186 | ||
188 | /* If this bit is set, then an unmatched ) is ordinary. | 187 | /* If this bit is set, then an unmatched ) is ordinary. |
189 | If not set, then an unmatched ) is invalid. */ | 188 | If not set, then an unmatched ) is invalid. */ |
190 | #define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17) | 189 | # define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) |
191 | 190 | ||
192 | /* If this bit is set, succeed as soon as we match the whole pattern, | 191 | /* If this bit is set, succeed as soon as we match the whole pattern, |
193 | without further backtracking. */ | 192 | without further backtracking. */ |
194 | #define REG_NO_POSIX_BACKTRACKING (1ul << 18) | 193 | # define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) |
195 | 194 | ||
196 | /* If this bit is set, do not process the GNU regex operators. | 195 | /* If this bit is set, do not process the GNU regex operators. |
197 | If not set, then the GNU regex operators are recognized. */ | 196 | If not set, then the GNU regex operators are recognized. */ |
198 | #define REG_NO_GNU_OPS (1ul << 19) | 197 | # define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) |
199 | 198 | ||
200 | /* If this bit is set, turn on internal regex debugging. | 199 | /* If this bit is set, turn on internal regex debugging. |
201 | If not set, and debugging was on, turn it off. | 200 | If not set, and debugging was on, turn it off. |
@@ -203,29 +202,31 @@ typedef unsigned long int reg_syntax_t; | |||
203 | We define this bit always, so that all that's needed to turn on | 202 | We define this bit always, so that all that's needed to turn on |
204 | debugging is to recompile regex.c; the calling code can always have | 203 | debugging is to recompile regex.c; the calling code can always have |
205 | this bit set, and it won't affect anything in the normal case. */ | 204 | this bit set, and it won't affect anything in the normal case. */ |
206 | #define REG_DEBUG (1ul << 20) | 205 | # define RE_DEBUG (RE_NO_GNU_OPS << 1) |
207 | 206 | ||
208 | /* If this bit is set, a syntactically invalid interval is treated as | 207 | /* If this bit is set, a syntactically invalid interval is treated as |
209 | a string of ordinary characters. For example, the ERE 'a{1' is | 208 | a string of ordinary characters. For example, the ERE 'a{1' is |
210 | treated as 'a\{1'. */ | 209 | treated as 'a\{1'. */ |
211 | #define REG_INVALID_INTERVAL_ORD (1ul << 21) | 210 | # define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) |
212 | 211 | ||
213 | /* If this bit is set, then ignore case when matching. | 212 | /* If this bit is set, then ignore case when matching. |
214 | If not set, then case is significant. */ | 213 | If not set, then case is significant. */ |
215 | #define REG_IGNORE_CASE (1ul << 22) | 214 | # define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) |
216 | 215 | ||
217 | /* This bit is used internally like REG_CONTEXT_INDEP_ANCHORS but only | 216 | /* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only |
218 | for ^, because it is difficult to scan the regex backwards to find | 217 | for ^, because it is difficult to scan the regex backwards to find |
219 | whether ^ should be special. */ | 218 | whether ^ should be special. */ |
220 | #define REG_CARET_ANCHORS_HERE (1ul << 23) | 219 | # define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) |
221 | 220 | ||
222 | /* If this bit is set, then \{ cannot be first in an bre or | 221 | /* If this bit is set, then \{ cannot be first in an bre or |
223 | immediately after an alternation or begin-group operator. */ | 222 | immediately after an alternation or begin-group operator. */ |
224 | #define REG_CONTEXT_INVALID_DUP (1ul << 24) | 223 | # define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) |
225 | 224 | ||
226 | /* If this bit is set, then no_sub will be set to 1 during | 225 | /* If this bit is set, then no_sub will be set to 1 during |
227 | re_compile_pattern. */ | 226 | re_compile_pattern. */ |
228 | #define REG_NO_SUB (1ul << 25) | 227 | # define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) |
228 | |||
229 | #endif /* defined __USE_GNU_REGEX */ | ||
229 | 230 | ||
230 | /* This global variable defines the particular regexp syntax to use (for | 231 | /* This global variable defines the particular regexp syntax to use (for |
231 | some interfaces). When a regexp is compiled, the syntax used is | 232 | some interfaces). When a regexp is compiled, the syntax used is |
@@ -233,82 +234,99 @@ typedef unsigned long int reg_syntax_t; | |||
233 | already-compiled regexps. */ | 234 | already-compiled regexps. */ |
234 | extern reg_syntax_t re_syntax_options; | 235 | extern reg_syntax_t re_syntax_options; |
235 | 236 | ||
237 | #ifdef __USE_GNU_REGEX | ||
236 | /* Define combinations of the above bits for the standard possibilities. | 238 | /* Define combinations of the above bits for the standard possibilities. |
237 | (The [[[ comments delimit what gets put into the Texinfo file, so | 239 | (The [[[ comments delimit what gets put into the Texinfo file, so |
238 | don't delete them!) */ | 240 | don't delete them!) */ |
239 | /* [[[begin syntaxes]]] */ | 241 | /* [[[begin syntaxes]]] */ |
240 | #define REG_SYNTAX_EMACS 0 | 242 | # define RE_SYNTAX_EMACS 0 |
241 | 243 | ||
242 | #define REG_SYNTAX_AWK \ | 244 | # define RE_SYNTAX_AWK \ |
243 | (REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \ | 245 | (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ |
244 | | REG_NO_BK_PARENS | REG_NO_BK_REFS \ | 246 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \ |
245 | | REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \ | 247 | | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ |
246 | | REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \ | 248 | | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ |
247 | | REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS) | 249 | | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) |
248 | 250 | ||
249 | #define REG_SYNTAX_GNU_AWK \ | 251 | # define RE_SYNTAX_GNU_AWK \ |
250 | ((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ | 252 | ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ |
251 | | REG_DEBUG) \ | 253 | & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ |
252 | & ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \ | 254 | | RE_CONTEXT_INVALID_OPS )) |
253 | | REG_CONTEXT_INVALID_OPS )) | 255 | |
254 | 256 | # define RE_SYNTAX_POSIX_AWK \ | |
255 | #define REG_SYNTAX_POSIX_AWK \ | 257 | (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ |
256 | (REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ | 258 | | RE_INTERVALS | RE_NO_GNU_OPS) |
257 | | REG_INTERVALS | REG_NO_GNU_OPS) | 259 | |
258 | 260 | # define RE_SYNTAX_GREP \ | |
259 | #define REG_SYNTAX_GREP \ | 261 | (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ |
260 | (REG_BK_PLUS_QM | REG_CHAR_CLASSES \ | 262 | | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ |
261 | | REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \ | 263 | | RE_NEWLINE_ALT) |
262 | | REG_NEWLINE_ALT) | 264 | |
263 | 265 | # define RE_SYNTAX_EGREP \ | |
264 | #define REG_SYNTAX_EGREP \ | 266 | (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ |
265 | (REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \ | 267 | | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ |
266 | | REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \ | 268 | | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ |
267 | | REG_NEWLINE_ALT | REG_NO_BK_PARENS \ | 269 | | RE_NO_BK_VBAR) |
268 | | REG_NO_BK_VBAR) | 270 | |
269 | 271 | # define RE_SYNTAX_POSIX_EGREP \ | |
270 | #define REG_SYNTAX_POSIX_EGREP \ | 272 | (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ |
271 | (REG_SYNTAX_EGREP | REG_INTERVALS | REG_NO_BK_BRACES \ | 273 | | RE_INVALID_INTERVAL_ORD) |
272 | | REG_INVALID_INTERVAL_ORD) | ||
273 | 274 | ||
274 | /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ | 275 | /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ |
275 | #define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC | 276 | # define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC |
276 | 277 | ||
277 | #define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC | 278 | # define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC |
278 | 279 | ||
279 | /* Syntax bits common to both basic and extended POSIX regex syntax. */ | 280 | /* Syntax bits common to both basic and extended POSIX regex syntax. */ |
280 | #define _REG_SYNTAX_POSIX_COMMON \ | 281 | # define _RE_SYNTAX_POSIX_COMMON \ |
281 | (REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \ | 282 | (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ |
282 | | REG_INTERVALS | REG_NO_EMPTY_RANGES) | 283 | | RE_INTERVALS | RE_NO_EMPTY_RANGES) |
283 | 284 | ||
284 | #define REG_SYNTAX_POSIX_BASIC \ | 285 | # define RE_SYNTAX_POSIX_BASIC \ |
285 | (_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP) | 286 | (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) |
286 | 287 | ||
287 | /* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes | 288 | /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes |
288 | REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this | 289 | RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this |
289 | isn't minimal, since other operators, such as \`, aren't disabled. */ | 290 | isn't minimal, since other operators, such as \`, aren't disabled. */ |
290 | #define REG_SYNTAX_POSIX_MINIMAL_BASIC \ | 291 | # define RE_SYNTAX_POSIX_MINIMAL_BASIC \ |
291 | (_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS) | 292 | (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) |
292 | 293 | ||
293 | #define REG_SYNTAX_POSIX_EXTENDED \ | 294 | # define RE_SYNTAX_POSIX_EXTENDED \ |
294 | (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ | 295 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ |
295 | | REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \ | 296 | | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ |
296 | | REG_NO_BK_PARENS | REG_NO_BK_VBAR \ | 297 | | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ |
297 | | REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD) | 298 | | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) |
298 | 299 | ||
299 | /* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is | 300 | /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is |
300 | removed and REG_NO_BK_REFS is added. */ | 301 | removed and RE_NO_BK_REFS is added. */ |
301 | #define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \ | 302 | # define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ |
302 | (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ | 303 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ |
303 | | REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \ | 304 | | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ |
304 | | REG_NO_BK_PARENS | REG_NO_BK_REFS \ | 305 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \ |
305 | | REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD) | 306 | | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) |
306 | /* [[[end syntaxes]]] */ | 307 | /* [[[end syntaxes]]] */ |
308 | |||
309 | #endif /* defined __USE_GNU_REGEX */ | ||
307 | 310 | ||
308 | /* Maximum number of duplicates an interval can allow. This is | 311 | #ifdef __USE_GNU_REGEX |
309 | distinct from RE_DUP_MAX, to conform to POSIX name space rules and | 312 | |
310 | to avoid collisions with <limits.h>. */ | 313 | /* Maximum number of duplicates an interval can allow. POSIX-conforming |
311 | #define REG_DUP_MAX 32767 | 314 | systems might define this in <limits.h>, but we want our |
315 | value, so remove any previous define. */ | ||
316 | # ifdef RE_DUP_MAX | ||
317 | # undef RE_DUP_MAX | ||
318 | # endif | ||
319 | |||
320 | /* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored | ||
321 | the counter as a 2-byte signed integer. This is no longer true, so | ||
322 | RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to | ||
323 | ((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined. | ||
324 | However, there would be a huge performance problem if someone | ||
325 | actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains | ||
326 | its historical value. */ | ||
327 | # define RE_DUP_MAX (0x7fff) | ||
328 | |||
329 | #endif /* defined __USE_GNU_REGEX */ | ||
312 | 330 | ||
313 | 331 | ||
314 | /* POSIX `cflags' bits (i.e., information for `regcomp'). */ | 332 | /* POSIX `cflags' bits (i.e., information for `regcomp'). */ |
@@ -354,72 +372,55 @@ extern reg_syntax_t re_syntax_options; | |||
354 | typedef enum | 372 | typedef enum |
355 | { | 373 | { |
356 | _REG_ENOSYS = -1, /* This will never happen for this implementation. */ | 374 | _REG_ENOSYS = -1, /* This will never happen for this implementation. */ |
357 | #define REG_ENOSYS _REG_ENOSYS | 375 | _REG_NOERROR = 0, /* Success. */ |
358 | |||
359 | _REG_NOERROR, /* Success. */ | ||
360 | #define REG_NOERROR _REG_NOERROR | ||
361 | |||
362 | _REG_NOMATCH, /* Didn't find a match (for regexec). */ | 376 | _REG_NOMATCH, /* Didn't find a match (for regexec). */ |
363 | #define REG_NOMATCH _REG_NOMATCH | ||
364 | 377 | ||
365 | /* POSIX regcomp return error codes. (In the order listed in the | 378 | /* POSIX regcomp return error codes. (In the order listed in the |
366 | standard.) */ | 379 | standard.) */ |
367 | |||
368 | _REG_BADPAT, /* Invalid pattern. */ | 380 | _REG_BADPAT, /* Invalid pattern. */ |
369 | #define REG_BADPAT _REG_BADPAT | 381 | _REG_ECOLLATE, /* Invalid collating element. */ |
370 | |||
371 | _REG_ECOLLATE, /* Inalid collating element. */ | ||
372 | #define REG_ECOLLATE _REG_ECOLLATE | ||
373 | |||
374 | _REG_ECTYPE, /* Invalid character class name. */ | 382 | _REG_ECTYPE, /* Invalid character class name. */ |
375 | #define REG_ECTYPE _REG_ECTYPE | ||
376 | |||
377 | _REG_EESCAPE, /* Trailing backslash. */ | 383 | _REG_EESCAPE, /* Trailing backslash. */ |
378 | #define REG_EESCAPE _REG_EESCAPE | ||
379 | |||
380 | _REG_ESUBREG, /* Invalid back reference. */ | 384 | _REG_ESUBREG, /* Invalid back reference. */ |
381 | #define REG_ESUBREG _REG_ESUBREG | ||
382 | |||
383 | _REG_EBRACK, /* Unmatched left bracket. */ | 385 | _REG_EBRACK, /* Unmatched left bracket. */ |
384 | #define REG_EBRACK _REG_EBRACK | ||
385 | |||
386 | _REG_EPAREN, /* Parenthesis imbalance. */ | 386 | _REG_EPAREN, /* Parenthesis imbalance. */ |
387 | #define REG_EPAREN _REG_EPAREN | ||
388 | |||
389 | _REG_EBRACE, /* Unmatched \{. */ | 387 | _REG_EBRACE, /* Unmatched \{. */ |
390 | #define REG_EBRACE _REG_EBRACE | ||
391 | |||
392 | _REG_BADBR, /* Invalid contents of \{\}. */ | 388 | _REG_BADBR, /* Invalid contents of \{\}. */ |
393 | #define REG_BADBR _REG_BADBR | ||
394 | |||
395 | _REG_ERANGE, /* Invalid range end. */ | 389 | _REG_ERANGE, /* Invalid range end. */ |
396 | #define REG_ERANGE _REG_ERANGE | ||
397 | |||
398 | _REG_ESPACE, /* Ran out of memory. */ | 390 | _REG_ESPACE, /* Ran out of memory. */ |
399 | #define REG_ESPACE _REG_ESPACE | ||
400 | |||
401 | _REG_BADRPT, /* No preceding re for repetition op. */ | 391 | _REG_BADRPT, /* No preceding re for repetition op. */ |
402 | #define REG_BADRPT _REG_BADRPT | ||
403 | 392 | ||
404 | /* Error codes we've added. */ | 393 | /* Error codes we've added. */ |
405 | |||
406 | _REG_EEND, /* Premature end. */ | 394 | _REG_EEND, /* Premature end. */ |
407 | #define REG_EEND _REG_EEND | ||
408 | |||
409 | _REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ | 395 | _REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ |
410 | #define REG_ESIZE _REG_ESIZE | ||
411 | |||
412 | _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ | 396 | _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ |
413 | #define REG_ERPAREN _REG_ERPAREN | ||
414 | |||
415 | } reg_errcode_t; | 397 | } reg_errcode_t; |
398 | |||
399 | #ifdef _XOPEN_SOURCE | ||
400 | # define REG_ENOSYS _REG_ENOSYS | ||
401 | #endif | ||
402 | #define REG_NOERROR _REG_NOERROR | ||
403 | #define REG_NOMATCH _REG_NOMATCH | ||
404 | #define REG_BADPAT _REG_BADPAT | ||
405 | #define REG_ECOLLATE _REG_ECOLLATE | ||
406 | #define REG_ECTYPE _REG_ECTYPE | ||
407 | #define REG_EESCAPE _REG_EESCAPE | ||
408 | #define REG_ESUBREG _REG_ESUBREG | ||
409 | #define REG_EBRACK _REG_EBRACK | ||
410 | #define REG_EPAREN _REG_EPAREN | ||
411 | #define REG_EBRACE _REG_EBRACE | ||
412 | #define REG_BADBR _REG_BADBR | ||
413 | #define REG_ERANGE _REG_ERANGE | ||
414 | #define REG_ESPACE _REG_ESPACE | ||
415 | #define REG_BADRPT _REG_BADRPT | ||
416 | #define REG_EEND _REG_EEND | ||
417 | #define REG_ESIZE _REG_ESIZE | ||
418 | #define REG_ERPAREN _REG_ERPAREN | ||
416 | 419 | ||
417 | /* In the traditional GNU implementation, regex.h defined member names | 420 | /* struct re_pattern_buffer normally uses member names like `buffer' |
418 | like `buffer' that POSIX does not allow. These members now have | 421 | that POSIX does not allow. In POSIX mode these members have names |
419 | names with leading `re_' (e.g., `re_buffer'). Support the old | 422 | with leading `re_' (e.g., `re_buffer'). */ |
420 | names only if _REGEX_SOURCE is defined. New programs should use | 423 | #ifdef __USE_GNU_REGEX |
421 | the new names. */ | ||
422 | #ifdef _REGEX_SOURCE | ||
423 | # define _REG_RE_NAME(id) id | 424 | # define _REG_RE_NAME(id) id |
424 | # define _REG_RM_NAME(id) id | 425 | # define _REG_RM_NAME(id) id |
425 | #else | 426 | #else |
@@ -428,88 +429,87 @@ typedef enum | |||
428 | #endif | 429 | #endif |
429 | 430 | ||
430 | /* The user can specify the type of the re_translate member by | 431 | /* The user can specify the type of the re_translate member by |
431 | defining the macro REG_TRANSLATE_TYPE. In the traditional GNU | 432 | defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned |
432 | implementation, this macro was named RE_TRANSLATE_TYPE, but POSIX | 433 | char *. This pollutes the POSIX name space, so in POSIX mode just |
433 | does not allow this. Support the old name only if _REGEX_SOURCE | 434 | use unsigned char *. */ |
434 | and if the new name is not defined. New programs should use the new | 435 | #ifdef __USE_GNU_REGEX |
435 | name. */ | 436 | # ifndef RE_TRANSLATE_TYPE |
436 | #ifndef REG_TRANSLATE_TYPE | 437 | # define RE_TRANSLATE_TYPE unsigned char * |
437 | # if defined _REGEX_SOURCE && defined RE_TRANSLATE_TYPE | ||
438 | # define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE | ||
439 | # else | ||
440 | # define REG_TRANSLATE_TYPE char * | ||
441 | # endif | 438 | # endif |
439 | # define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE | ||
440 | #else | ||
441 | # define REG_TRANSLATE_TYPE unsigned char * | ||
442 | #endif | 442 | #endif |
443 | 443 | ||
444 | /* This data structure represents a compiled pattern. Before calling | 444 | /* This data structure represents a compiled pattern. Before calling |
445 | the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap', | 445 | the pattern compiler, the fields `buffer', `allocated', `fastmap', |
446 | `re_translate', and `re_no_sub' can be set. After the pattern has been | 446 | `translate', and `no_sub' can be set. After the pattern has been |
447 | compiled, the `re_nsub' field is available. All other fields are | 447 | compiled, the `re_nsub' field is available. All other fields are |
448 | private to the regex routines. */ | 448 | private to the regex routines. */ |
449 | 449 | ||
450 | struct re_pattern_buffer | 450 | struct re_pattern_buffer |
451 | { | 451 | { |
452 | /* [[[begin pattern_buffer]]] */ | 452 | /* Space that holds the compiled pattern. It is declared as |
453 | /* Space that holds the compiled pattern. It is declared as | 453 | `unsigned char *' because its elements are sometimes used as |
454 | `unsigned char *' because its elements are | 454 | array indexes. */ |
455 | sometimes used as array indexes. */ | ||
456 | unsigned char *_REG_RE_NAME (buffer); | 455 | unsigned char *_REG_RE_NAME (buffer); |
457 | 456 | ||
458 | /* Number of bytes to which `re_buffer' points. */ | 457 | /* Number of bytes to which `buffer' points. */ |
459 | __re_long_size_t _REG_RE_NAME (allocated); | 458 | __re_long_size_t _REG_RE_NAME (allocated); |
460 | 459 | ||
461 | /* Number of bytes actually used in `re_buffer'. */ | 460 | /* Number of bytes actually used in `buffer'. */ |
462 | __re_long_size_t _REG_RE_NAME (used); | 461 | __re_long_size_t _REG_RE_NAME (used); |
463 | 462 | ||
464 | /* Syntax setting with which the pattern was compiled. */ | 463 | /* Syntax setting with which the pattern was compiled. */ |
465 | reg_syntax_t _REG_RE_NAME (syntax); | 464 | reg_syntax_t _REG_RE_NAME (syntax); |
466 | 465 | ||
467 | /* Pointer to a fastmap, if any, otherwise zero. re_search uses | 466 | /* Pointer to a fastmap, if any, otherwise zero. re_search uses the |
468 | the fastmap, if there is one, to skip over impossible | 467 | fastmap, if there is one, to skip over impossible starting points |
469 | starting points for matches. */ | 468 | for matches. */ |
470 | char *_REG_RE_NAME (fastmap); | 469 | char *_REG_RE_NAME (fastmap); |
471 | 470 | ||
472 | /* Either a translate table to apply to all characters before | 471 | /* Either a translate table to apply to all characters before |
473 | comparing them, or zero for no translation. The translation | 472 | comparing them, or zero for no translation. The translation is |
474 | is applied to a pattern when it is compiled and to a string | 473 | applied to a pattern when it is compiled and to a string when it |
475 | when it is matched. */ | 474 | is matched. */ |
476 | REG_TRANSLATE_TYPE _REG_RE_NAME (translate); | 475 | REG_TRANSLATE_TYPE _REG_RE_NAME (translate); |
477 | 476 | ||
478 | /* Number of subexpressions found by the compiler. */ | 477 | /* Number of subexpressions found by the compiler. */ |
479 | size_t re_nsub; | 478 | size_t re_nsub; |
480 | 479 | ||
481 | /* Zero if this pattern cannot match the empty string, one else. | 480 | /* Zero if this pattern cannot match the empty string, one else. |
482 | Well, in truth it's used only in `re_search_2', to see | 481 | Well, in truth it's used only in `re_search_2', to see whether or |
483 | whether or not we should use the fastmap, so we don't set | 482 | not we should use the fastmap, so we don't set this absolutely |
484 | this absolutely perfectly; see `re_compile_fastmap' (the | 483 | perfectly; see `re_compile_fastmap' (the `duplicate' case). */ |
485 | `duplicate' case). */ | ||
486 | unsigned int _REG_RE_NAME (can_be_null) : 1; | 484 | unsigned int _REG_RE_NAME (can_be_null) : 1; |
487 | 485 | ||
488 | /* If REG_UNALLOCATED, allocate space in the `regs' structure | 486 | /* If REGS_UNALLOCATED, allocate space in the `regs' structure |
489 | for `max (REG_NREGS, re_nsub + 1)' groups. | 487 | for `max (RE_NREGS, re_nsub + 1)' groups. |
490 | If REG_REALLOCATE, reallocate space if necessary. | 488 | If REGS_REALLOCATE, reallocate space if necessary. |
491 | If REG_FIXED, use what's there. */ | 489 | If REGS_FIXED, use what's there. */ |
492 | #define REG_UNALLOCATED 0 | 490 | #ifdef __USE_GNU_REGEX |
493 | #define REG_REALLOCATE 1 | 491 | # define REGS_UNALLOCATED 0 |
494 | #define REG_FIXED 2 | 492 | # define REGS_REALLOCATE 1 |
493 | # define REGS_FIXED 2 | ||
494 | #endif | ||
495 | unsigned int _REG_RE_NAME (regs_allocated) : 2; | 495 | unsigned int _REG_RE_NAME (regs_allocated) : 2; |
496 | 496 | ||
497 | /* Set to zero when `regex_compile' compiles a pattern; set to one | 497 | /* Set to zero when `regex_compile' compiles a pattern; set to one |
498 | by `re_compile_fastmap' if it updates the fastmap. */ | 498 | by `re_compile_fastmap' if it updates the fastmap. */ |
499 | unsigned int _REG_RE_NAME (fastmap_accurate) : 1; | 499 | unsigned int _REG_RE_NAME (fastmap_accurate) : 1; |
500 | 500 | ||
501 | /* If set, `re_match_2' does not return information about | 501 | /* If set, `re_match_2' does not return information about |
502 | subexpressions. */ | 502 | subexpressions. */ |
503 | unsigned int _REG_RE_NAME (no_sub) : 1; | 503 | unsigned int _REG_RE_NAME (no_sub) : 1; |
504 | 504 | ||
505 | /* If set, a beginning-of-line anchor doesn't match at the | 505 | /* If set, a beginning-of-line anchor doesn't match at the beginning |
506 | beginning of the string. */ | 506 | of the string. */ |
507 | unsigned int _REG_RE_NAME (not_bol) : 1; | 507 | unsigned int _REG_RE_NAME (not_bol) : 1; |
508 | 508 | ||
509 | /* Similarly for an end-of-line anchor. */ | 509 | /* Similarly for an end-of-line anchor. */ |
510 | unsigned int _REG_RE_NAME (not_eol) : 1; | 510 | unsigned int _REG_RE_NAME (not_eol) : 1; |
511 | 511 | ||
512 | /* If true, an anchor at a newline matches. */ | 512 | /* If true, an anchor at a newline matches. */ |
513 | unsigned int _REG_RE_NAME (newline_anchor) : 1; | 513 | unsigned int _REG_RE_NAME (newline_anchor) : 1; |
514 | 514 | ||
515 | /* [[[end pattern_buffer]]] */ | 515 | /* [[[end pattern_buffer]]] */ |
@@ -527,11 +527,11 @@ struct re_registers | |||
527 | }; | 527 | }; |
528 | 528 | ||
529 | 529 | ||
530 | /* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer, | 530 | /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, |
531 | `re_match_2' returns information about at least this many registers | 531 | `re_match_2' returns information about at least this many registers |
532 | the first time a `regs' structure is passed. */ | 532 | the first time a `regs' structure is passed. */ |
533 | #ifndef REG_NREGS | 533 | #if !defined RE_NREGS && defined __USE_GNU_REGEX |
534 | # define REG_NREGS 30 | 534 | # define RE_NREGS 30 |
535 | #endif | 535 | #endif |
536 | 536 | ||
537 | 537 | ||
@@ -567,7 +567,7 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); | |||
567 | compiled into BUFFER. Start searching at position START, for RANGE | 567 | compiled into BUFFER. Start searching at position START, for RANGE |
568 | characters. Return the starting position of the match, -1 for no | 568 | characters. Return the starting position of the match, -1 for no |
569 | match, or -2 for an internal error. Also return register | 569 | match, or -2 for an internal error. Also return register |
570 | information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */ | 570 | information in REGS (if REGS and BUFFER->no_sub are nonzero). */ |
571 | extern regoff_t re_search (struct re_pattern_buffer *__buffer, | 571 | extern regoff_t re_search (struct re_pattern_buffer *__buffer, |
572 | const char *__string, __re_idx_t __length, | 572 | const char *__string, __re_idx_t __length, |
573 | __re_idx_t __start, regoff_t __range, | 573 | __re_idx_t __start, regoff_t __range, |
@@ -635,13 +635,17 @@ extern int re_exec (const char *); | |||
635 | # endif | 635 | # endif |
636 | # endif | 636 | # endif |
637 | #endif | 637 | #endif |
638 | /* gcc 3.1 and up support the [restrict] syntax, but g++ doesn't. */ | 638 | /* gcc 3.1 and up support the [restrict] syntax. Don't trust |
639 | #ifndef __restrict_arr | 639 | sys/cdefs.h's definition of __restrict_arr, though, as it |
640 | # if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && !defined __cplusplus | 640 | mishandles gcc -ansi -pedantic. */ |
641 | # define __restrict_arr __restrict | 641 | #undef __restrict_arr |
642 | # else | 642 | #if ((199901L <= __STDC_VERSION__ \ |
643 | # define __restrict_arr | 643 | || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ |
644 | # endif | 644 | && !__STRICT_ANSI__)) \ |
645 | && !defined __GNUG__) | ||
646 | # define __restrict_arr __restrict | ||
647 | #else | ||
648 | # define __restrict_arr | ||
645 | #endif | 649 | #endif |
646 | 650 | ||
647 | /* POSIX compatibility. */ | 651 | /* POSIX compatibility. */ |
@@ -660,110 +664,8 @@ extern size_t regerror (int __errcode, const regex_t *__restrict __preg, | |||
660 | extern void regfree (regex_t *__preg); | 664 | extern void regfree (regex_t *__preg); |
661 | 665 | ||
662 | 666 | ||
663 | #ifdef _REGEX_SOURCE | ||
664 | |||
665 | /* Define the POSIX-compatible member names in terms of the | ||
666 | incompatible (and deprecated) names established by _REG_RE_NAME. | ||
667 | New programs should use the re_* names. */ | ||
668 | |||
669 | # define re_allocated allocated | ||
670 | # define re_buffer buffer | ||
671 | # define re_can_be_null can_be_null | ||
672 | # define re_fastmap fastmap | ||
673 | # define re_fastmap_accurate fastmap_accurate | ||
674 | # define re_newline_anchor newline_anchor | ||
675 | # define re_no_sub no_sub | ||
676 | # define re_not_bol not_bol | ||
677 | # define re_not_eol not_eol | ||
678 | # define re_regs_allocated regs_allocated | ||
679 | # define re_syntax syntax | ||
680 | # define re_translate translate | ||
681 | # define re_used used | ||
682 | |||
683 | /* Similarly for _REG_RM_NAME. */ | ||
684 | |||
685 | # define rm_end end | ||
686 | # define rm_num_regs num_regs | ||
687 | # define rm_start start | ||
688 | |||
689 | /* Undef RE_DUP_MAX first, in case the user has already included a | ||
690 | <limits.h> with an incompatible definition. | ||
691 | |||
692 | On GNU systems, the most common spelling for RE_DUP_MAX's value in | ||
693 | <limits.h> is (0x7ffff), so define RE_DUP_MAX to that, not to | ||
694 | REG_DUP_MAX. This avoid some duplicate-macro-definition warnings | ||
695 | with programs that include <limits.h> after this file. | ||
696 | |||
697 | New programs should not assume that regex.h defines RE_DUP_MAX; to | ||
698 | get the value of RE_DUP_MAX, they should instead include <limits.h> | ||
699 | and possibly invoke the sysconf function. */ | ||
700 | |||
701 | # undef RE_DUP_MAX | ||
702 | # define RE_DUP_MAX (0x7fff) | ||
703 | |||
704 | /* Define the following symbols for backward source compatibility. | ||
705 | These symbols violate the POSIX name space rules, and new programs | ||
706 | should avoid them. */ | ||
707 | |||
708 | # define REGS_FIXED REG_FIXED | ||
709 | # define REGS_REALLOCATE REG_REALLOCATE | ||
710 | # define REGS_UNALLOCATED REG_UNALLOCATED | ||
711 | # define RE_BACKSLASH_ESCAPE_IN_LISTS REG_BACKSLASH_ESCAPE_IN_LISTS | ||
712 | # define RE_BK_PLUS_QM REG_BK_PLUS_QM | ||
713 | # define RE_CARET_ANCHORS_HERE REG_CARET_ANCHORS_HERE | ||
714 | # define RE_CHAR_CLASSES REG_CHAR_CLASSES | ||
715 | # define RE_CONTEXT_INDEP_ANCHORS REG_CONTEXT_INDEP_ANCHORS | ||
716 | # define RE_CONTEXT_INDEP_OPS REG_CONTEXT_INDEP_OPS | ||
717 | # define RE_CONTEXT_INVALID_DUP REG_CONTEXT_INVALID_DUP | ||
718 | # define RE_CONTEXT_INVALID_OPS REG_CONTEXT_INVALID_OPS | ||
719 | # define RE_DEBUG REG_DEBUG | ||
720 | # define RE_DOT_NEWLINE REG_DOT_NEWLINE | ||
721 | # define RE_DOT_NOT_NULL REG_DOT_NOT_NULL | ||
722 | # define RE_HAT_LISTS_NOT_NEWLINE REG_HAT_LISTS_NOT_NEWLINE | ||
723 | # define RE_ICASE REG_IGNORE_CASE /* avoid collision with REG_ICASE */ | ||
724 | # define RE_INTERVALS REG_INTERVALS | ||
725 | # define RE_INVALID_INTERVAL_ORD REG_INVALID_INTERVAL_ORD | ||
726 | # define RE_LIMITED_OPS REG_LIMITED_OPS | ||
727 | # define RE_NEWLINE_ALT REG_NEWLINE_ALT | ||
728 | # define RE_NO_BK_BRACES REG_NO_BK_BRACES | ||
729 | # define RE_NO_BK_PARENS REG_NO_BK_PARENS | ||
730 | # define RE_NO_BK_REFS REG_NO_BK_REFS | ||
731 | # define RE_NO_BK_VBAR REG_NO_BK_VBAR | ||
732 | # define RE_NO_EMPTY_RANGES REG_NO_EMPTY_RANGES | ||
733 | # define RE_NO_GNU_OPS REG_NO_GNU_OPS | ||
734 | # define RE_NO_POSIX_BACKTRACKING REG_NO_POSIX_BACKTRACKING | ||
735 | # define RE_NO_SUB REG_NO_SUB | ||
736 | # define RE_NREGS REG_NREGS | ||
737 | # define RE_SYNTAX_AWK REG_SYNTAX_AWK | ||
738 | # define RE_SYNTAX_ED REG_SYNTAX_ED | ||
739 | # define RE_SYNTAX_EGREP REG_SYNTAX_EGREP | ||
740 | # define RE_SYNTAX_EMACS REG_SYNTAX_EMACS | ||
741 | # define RE_SYNTAX_GNU_AWK REG_SYNTAX_GNU_AWK | ||
742 | # define RE_SYNTAX_GREP REG_SYNTAX_GREP | ||
743 | # define RE_SYNTAX_POSIX_AWK REG_SYNTAX_POSIX_AWK | ||
744 | # define RE_SYNTAX_POSIX_BASIC REG_SYNTAX_POSIX_BASIC | ||
745 | # define RE_SYNTAX_POSIX_EGREP REG_SYNTAX_POSIX_EGREP | ||
746 | # define RE_SYNTAX_POSIX_EXTENDED REG_SYNTAX_POSIX_EXTENDED | ||
747 | # define RE_SYNTAX_POSIX_MINIMAL_BASIC REG_SYNTAX_POSIX_MINIMAL_BASIC | ||
748 | # define RE_SYNTAX_POSIX_MINIMAL_EXTENDED REG_SYNTAX_POSIX_MINIMAL_EXTENDED | ||
749 | # define RE_SYNTAX_SED REG_SYNTAX_SED | ||
750 | # define RE_UNMATCHED_RIGHT_PAREN_ORD REG_UNMATCHED_RIGHT_PAREN_ORD | ||
751 | # ifndef RE_TRANSLATE_TYPE | ||
752 | # define RE_TRANSLATE_TYPE REG_TRANSLATE_TYPE | ||
753 | # endif | ||
754 | |||
755 | #endif /* defined _REGEX_SOURCE */ | ||
756 | |||
757 | #ifdef __cplusplus | 667 | #ifdef __cplusplus |
758 | } | 668 | } |
759 | #endif /* C++ */ | 669 | #endif /* C++ */ |
760 | 670 | ||
761 | #endif /* regex.h */ | 671 | #endif /* regex.h */ |
762 | |||
763 | /* | ||
764 | Local variables: | ||
765 | make-backup-files: t | ||
766 | version-control: t | ||
767 | trim-versions-without-asking: nil | ||
768 | End: | ||
769 | */ | ||
diff --git a/lib/regex_internal.c b/gl/regex_internal.c index ad618cf..78e16f3 100644 --- a/lib/regex_internal.c +++ b/gl/regex_internal.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | static void re_string_construct_common (const char *str, Idx len, | 20 | static void re_string_construct_common (const char *str, Idx len, |
21 | re_string_t *pstr, | 21 | re_string_t *pstr, |
22 | REG_TRANSLATE_TYPE trans, bool icase, | 22 | RE_TRANSLATE_TYPE trans, bool icase, |
23 | const re_dfa_t *dfa) internal_function; | 23 | const re_dfa_t *dfa) internal_function; |
24 | static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, | 24 | static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, |
25 | const re_node_set *nodes, | 25 | const re_node_set *nodes, |
@@ -37,7 +37,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, | |||
37 | static reg_errcode_t | 37 | static reg_errcode_t |
38 | internal_function | 38 | internal_function |
39 | re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, | 39 | re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, |
40 | REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) | 40 | RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) |
41 | { | 41 | { |
42 | reg_errcode_t ret; | 42 | reg_errcode_t ret; |
43 | Idx init_buf_len; | 43 | Idx init_buf_len; |
@@ -65,7 +65,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, | |||
65 | static reg_errcode_t | 65 | static reg_errcode_t |
66 | internal_function | 66 | internal_function |
67 | re_string_construct (re_string_t *pstr, const char *str, Idx len, | 67 | re_string_construct (re_string_t *pstr, const char *str, Idx len, |
68 | REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) | 68 | RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) |
69 | { | 69 | { |
70 | reg_errcode_t ret; | 70 | reg_errcode_t ret; |
71 | memset (pstr, '\0', sizeof (re_string_t)); | 71 | memset (pstr, '\0', sizeof (re_string_t)); |
@@ -132,13 +132,20 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) | |||
132 | #ifdef RE_ENABLE_I18N | 132 | #ifdef RE_ENABLE_I18N |
133 | if (pstr->mb_cur_max > 1) | 133 | if (pstr->mb_cur_max > 1) |
134 | { | 134 | { |
135 | wint_t *new_wcs = re_xrealloc (pstr->wcs, wint_t, new_buf_len); | 135 | wint_t *new_wcs; |
136 | |||
137 | /* Avoid overflow. */ | ||
138 | size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx)); | ||
139 | if (BE (SIZE_MAX / max_object_size < new_buf_len, 0)) | ||
140 | return REG_ESPACE; | ||
141 | |||
142 | new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); | ||
136 | if (BE (new_wcs == NULL, 0)) | 143 | if (BE (new_wcs == NULL, 0)) |
137 | return REG_ESPACE; | 144 | return REG_ESPACE; |
138 | pstr->wcs = new_wcs; | 145 | pstr->wcs = new_wcs; |
139 | if (pstr->offsets != NULL) | 146 | if (pstr->offsets != NULL) |
140 | { | 147 | { |
141 | Idx *new_offsets = re_xrealloc (pstr->offsets, Idx, new_buf_len); | 148 | Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len); |
142 | if (BE (new_offsets == NULL, 0)) | 149 | if (BE (new_offsets == NULL, 0)) |
143 | return REG_ESPACE; | 150 | return REG_ESPACE; |
144 | pstr->offsets = new_offsets; | 151 | pstr->offsets = new_offsets; |
@@ -161,13 +168,13 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) | |||
161 | static void | 168 | static void |
162 | internal_function | 169 | internal_function |
163 | re_string_construct_common (const char *str, Idx len, re_string_t *pstr, | 170 | re_string_construct_common (const char *str, Idx len, re_string_t *pstr, |
164 | REG_TRANSLATE_TYPE trans, bool icase, | 171 | RE_TRANSLATE_TYPE trans, bool icase, |
165 | const re_dfa_t *dfa) | 172 | const re_dfa_t *dfa) |
166 | { | 173 | { |
167 | pstr->raw_mbs = (const unsigned char *) str; | 174 | pstr->raw_mbs = (const unsigned char *) str; |
168 | pstr->len = len; | 175 | pstr->len = len; |
169 | pstr->raw_len = len; | 176 | pstr->raw_len = len; |
170 | pstr->trans = (unsigned REG_TRANSLATE_TYPE) trans; | 177 | pstr->trans = trans; |
171 | pstr->icase = icase; | 178 | pstr->icase = icase; |
172 | pstr->mbs_allocated = (trans != NULL || icase); | 179 | pstr->mbs_allocated = (trans != NULL || icase); |
173 | pstr->mb_cur_max = dfa->mb_cur_max; | 180 | pstr->mb_cur_max = dfa->mb_cur_max; |
@@ -301,7 +308,7 @@ build_wcs_upper_buffer (re_string_t *pstr) | |||
301 | mbclen = mbrtowc (&wc, | 308 | mbclen = mbrtowc (&wc, |
302 | ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx | 309 | ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx |
303 | + byte_idx), remain_len, &pstr->cur_state); | 310 | + byte_idx), remain_len, &pstr->cur_state); |
304 | if (BE ((size_t) (mbclen + 2) > 2, 1)) | 311 | if (BE (mbclen < (size_t) -2, 1)) |
305 | { | 312 | { |
306 | wchar_t wcu = wc; | 313 | wchar_t wcu = wc; |
307 | if (iswlower (wc)) | 314 | if (iswlower (wc)) |
@@ -369,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) | |||
369 | else | 376 | else |
370 | p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; | 377 | p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; |
371 | mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state); | 378 | mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state); |
372 | if (BE ((size_t) (mbclen + 2) > 2, 1)) | 379 | if (BE (mbclen < (size_t) -2, 1)) |
373 | { | 380 | { |
374 | wchar_t wcu = wc; | 381 | wchar_t wcu = wc; |
375 | if (iswlower (wc)) | 382 | if (iswlower (wc)) |
@@ -392,7 +399,7 @@ build_wcs_upper_buffer (re_string_t *pstr) | |||
392 | 399 | ||
393 | if (pstr->offsets == NULL) | 400 | if (pstr->offsets == NULL) |
394 | { | 401 | { |
395 | pstr->offsets = re_xmalloc (Idx, pstr->bufs_len); | 402 | pstr->offsets = re_malloc (Idx, pstr->bufs_len); |
396 | 403 | ||
397 | if (pstr->offsets == NULL) | 404 | if (pstr->offsets == NULL) |
398 | return REG_ESPACE; | 405 | return REG_ESPACE; |
@@ -481,27 +488,34 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc) | |||
481 | mbstate_t prev_st; | 488 | mbstate_t prev_st; |
482 | Idx rawbuf_idx; | 489 | Idx rawbuf_idx; |
483 | size_t mbclen; | 490 | size_t mbclen; |
484 | wchar_t wc = 0; | 491 | wint_t wc = WEOF; |
485 | 492 | ||
486 | /* Skip the characters which are not necessary to check. */ | 493 | /* Skip the characters which are not necessary to check. */ |
487 | for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len; | 494 | for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len; |
488 | rawbuf_idx < new_raw_idx;) | 495 | rawbuf_idx < new_raw_idx;) |
489 | { | 496 | { |
497 | wchar_t wc2; | ||
490 | Idx remain_len; | 498 | Idx remain_len; |
491 | remain_len = pstr->len - rawbuf_idx; | 499 | remain_len = pstr->len - rawbuf_idx; |
492 | prev_st = pstr->cur_state; | 500 | prev_st = pstr->cur_state; |
493 | mbclen = mbrtowc (&wc, (const char *) pstr->raw_mbs + rawbuf_idx, | 501 | mbclen = mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx, |
494 | remain_len, &pstr->cur_state); | 502 | remain_len, &pstr->cur_state); |
495 | if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) | 503 | if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) |
496 | { | 504 | { |
497 | /* We treat these cases as a singlebyte character. */ | 505 | /* We treat these cases as a single byte character. */ |
506 | if (mbclen == 0 || remain_len == 0) | ||
507 | wc = L'\0'; | ||
508 | else | ||
509 | wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx); | ||
498 | mbclen = 1; | 510 | mbclen = 1; |
499 | pstr->cur_state = prev_st; | 511 | pstr->cur_state = prev_st; |
500 | } | 512 | } |
513 | else | ||
514 | wc = wc2; | ||
501 | /* Then proceed the next character. */ | 515 | /* Then proceed the next character. */ |
502 | rawbuf_idx += mbclen; | 516 | rawbuf_idx += mbclen; |
503 | } | 517 | } |
504 | *last_wc = (wint_t) wc; | 518 | *last_wc = wc; |
505 | return rawbuf_idx; | 519 | return rawbuf_idx; |
506 | } | 520 | } |
507 | #endif /* RE_ENABLE_I18N */ | 521 | #endif /* RE_ENABLE_I18N */ |
@@ -583,34 +597,98 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) | |||
583 | 597 | ||
584 | if (BE (offset != 0, 1)) | 598 | if (BE (offset != 0, 1)) |
585 | { | 599 | { |
586 | /* Are the characters which are already checked remain? */ | 600 | /* Should the already checked characters be kept? */ |
587 | if (BE (offset < pstr->valid_raw_len, 1) | 601 | if (BE (offset < pstr->valid_raw_len, 1)) |
588 | #ifdef RE_ENABLE_I18N | ||
589 | /* Handling this would enlarge the code too much. | ||
590 | Accept a slowdown in that case. */ | ||
591 | && pstr->offsets_needed == 0 | ||
592 | #endif | ||
593 | ) | ||
594 | { | 602 | { |
595 | /* Yes, move them to the front of the buffer. */ | 603 | /* Yes, move them to the front of the buffer. */ |
596 | pstr->tip_context = re_string_context_at (pstr, offset - 1, eflags); | ||
597 | #ifdef RE_ENABLE_I18N | 604 | #ifdef RE_ENABLE_I18N |
598 | if (pstr->mb_cur_max > 1) | 605 | if (BE (pstr->offsets_needed, 0)) |
599 | memmove (pstr->wcs, pstr->wcs + offset, | 606 | { |
600 | (pstr->valid_len - offset) * sizeof (wint_t)); | 607 | Idx low = 0, high = pstr->valid_len, mid; |
608 | do | ||
609 | { | ||
610 | mid = (high + low) / 2; | ||
611 | if (pstr->offsets[mid] > offset) | ||
612 | high = mid; | ||
613 | else if (pstr->offsets[mid] < offset) | ||
614 | low = mid + 1; | ||
615 | else | ||
616 | break; | ||
617 | } | ||
618 | while (low < high); | ||
619 | if (pstr->offsets[mid] < offset) | ||
620 | ++mid; | ||
621 | pstr->tip_context = re_string_context_at (pstr, mid - 1, | ||
622 | eflags); | ||
623 | /* This can be quite complicated, so handle specially | ||
624 | only the common and easy case where the character with | ||
625 | different length representation of lower and upper | ||
626 | case is present at or after offset. */ | ||
627 | if (pstr->valid_len > offset | ||
628 | && mid == offset && pstr->offsets[mid] == offset) | ||
629 | { | ||
630 | memmove (pstr->wcs, pstr->wcs + offset, | ||
631 | (pstr->valid_len - offset) * sizeof (wint_t)); | ||
632 | memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); | ||
633 | pstr->valid_len -= offset; | ||
634 | pstr->valid_raw_len -= offset; | ||
635 | for (low = 0; low < pstr->valid_len; low++) | ||
636 | pstr->offsets[low] = pstr->offsets[low + offset] - offset; | ||
637 | } | ||
638 | else | ||
639 | { | ||
640 | /* Otherwise, just find out how long the partial multibyte | ||
641 | character at offset is and fill it with WEOF/255. */ | ||
642 | pstr->len = pstr->raw_len - idx + offset; | ||
643 | pstr->stop = pstr->raw_stop - idx + offset; | ||
644 | pstr->offsets_needed = 0; | ||
645 | while (mid > 0 && pstr->offsets[mid - 1] == offset) | ||
646 | --mid; | ||
647 | while (mid < pstr->valid_len) | ||
648 | if (pstr->wcs[mid] != WEOF) | ||
649 | break; | ||
650 | else | ||
651 | ++mid; | ||
652 | if (mid == pstr->valid_len) | ||
653 | pstr->valid_len = 0; | ||
654 | else | ||
655 | { | ||
656 | pstr->valid_len = pstr->offsets[mid] - offset; | ||
657 | if (pstr->valid_len) | ||
658 | { | ||
659 | for (low = 0; low < pstr->valid_len; ++low) | ||
660 | pstr->wcs[low] = WEOF; | ||
661 | memset (pstr->mbs, 255, pstr->valid_len); | ||
662 | } | ||
663 | } | ||
664 | pstr->valid_raw_len = pstr->valid_len; | ||
665 | } | ||
666 | } | ||
667 | else | ||
668 | #endif | ||
669 | { | ||
670 | pstr->tip_context = re_string_context_at (pstr, offset - 1, | ||
671 | eflags); | ||
672 | #ifdef RE_ENABLE_I18N | ||
673 | if (pstr->mb_cur_max > 1) | ||
674 | memmove (pstr->wcs, pstr->wcs + offset, | ||
675 | (pstr->valid_len - offset) * sizeof (wint_t)); | ||
601 | #endif /* RE_ENABLE_I18N */ | 676 | #endif /* RE_ENABLE_I18N */ |
602 | if (BE (pstr->mbs_allocated, 0)) | 677 | if (BE (pstr->mbs_allocated, 0)) |
603 | memmove (pstr->mbs, pstr->mbs + offset, | 678 | memmove (pstr->mbs, pstr->mbs + offset, |
604 | pstr->valid_len - offset); | 679 | pstr->valid_len - offset); |
605 | pstr->valid_len -= offset; | 680 | pstr->valid_len -= offset; |
606 | pstr->valid_raw_len -= offset; | 681 | pstr->valid_raw_len -= offset; |
607 | #if DEBUG | 682 | #if DEBUG |
608 | assert (pstr->valid_len > 0); | 683 | assert (pstr->valid_len > 0); |
609 | #endif | 684 | #endif |
685 | } | ||
610 | } | 686 | } |
611 | else | 687 | else |
612 | { | 688 | { |
613 | /* No, skip all characters until IDX. */ | 689 | /* No, skip all characters until IDX. */ |
690 | Idx prev_valid_len = pstr->valid_len; | ||
691 | |||
614 | #ifdef RE_ENABLE_I18N | 692 | #ifdef RE_ENABLE_I18N |
615 | if (BE (pstr->offsets_needed, 0)) | 693 | if (BE (pstr->offsets_needed, 0)) |
616 | { | 694 | { |
@@ -620,7 +698,6 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) | |||
620 | } | 698 | } |
621 | #endif | 699 | #endif |
622 | pstr->valid_len = 0; | 700 | pstr->valid_len = 0; |
623 | pstr->valid_raw_len = 0; | ||
624 | #ifdef RE_ENABLE_I18N | 701 | #ifdef RE_ENABLE_I18N |
625 | if (pstr->mb_cur_max > 1) | 702 | if (pstr->mb_cur_max > 1) |
626 | { | 703 | { |
@@ -635,60 +712,80 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) | |||
635 | byte other than 0x80 - 0xbf. */ | 712 | byte other than 0x80 - 0xbf. */ |
636 | raw = pstr->raw_mbs + pstr->raw_mbs_idx; | 713 | raw = pstr->raw_mbs + pstr->raw_mbs_idx; |
637 | end = raw + (offset - pstr->mb_cur_max); | 714 | end = raw + (offset - pstr->mb_cur_max); |
638 | for (p = raw + offset - 1; p >= end; --p) | 715 | if (end < pstr->raw_mbs) |
639 | if ((*p & 0xc0) != 0x80) | 716 | end = pstr->raw_mbs; |
640 | { | 717 | p = raw + offset - 1; |
641 | mbstate_t cur_state; | 718 | #ifdef _LIBC |
642 | wchar_t wc2; | 719 | /* We know the wchar_t encoding is UCS4, so for the simple |
643 | Idx mlen = raw + pstr->len - p; | 720 | case, ASCII characters, skip the conversion step. */ |
644 | unsigned char buf[6]; | 721 | if (isascii (*p) && BE (pstr->trans == NULL, 1)) |
645 | size_t mbclen; | 722 | { |
646 | 723 | memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); | |
647 | q = p; | 724 | /* pstr->valid_len = 0; */ |
648 | if (BE (pstr->trans != NULL, 0)) | 725 | wc = (wchar_t) *p; |
649 | { | 726 | } |
650 | int i = mlen < 6 ? mlen : 6; | 727 | else |
651 | while (--i >= 0) | 728 | #endif |
652 | buf[i] = pstr->trans[p[i]]; | 729 | for (; p >= end; --p) |
653 | q = buf; | 730 | if ((*p & 0xc0) != 0x80) |
654 | } | 731 | { |
655 | /* XXX Don't use mbrtowc, we know which conversion | 732 | mbstate_t cur_state; |
656 | to use (UTF-8 -> UCS4). */ | 733 | wchar_t wc2; |
657 | memset (&cur_state, 0, sizeof (cur_state)); | 734 | Idx mlen = raw + pstr->len - p; |
658 | mbclen = mbrtowc (&wc2, (const char *) p, mlen, | 735 | unsigned char buf[6]; |
659 | &cur_state); | 736 | size_t mbclen; |
660 | if (raw + offset - p <= mbclen && mbclen < (size_t) -2) | 737 | |
661 | { | 738 | q = p; |
662 | memset (&pstr->cur_state, '\0', | 739 | if (BE (pstr->trans != NULL, 0)) |
663 | sizeof (mbstate_t)); | 740 | { |
664 | pstr->valid_len = mbclen - (raw + offset - p); | 741 | int i = mlen < 6 ? mlen : 6; |
665 | wc = wc2; | 742 | while (--i >= 0) |
666 | } | 743 | buf[i] = pstr->trans[p[i]]; |
667 | break; | 744 | q = buf; |
668 | } | 745 | } |
746 | /* XXX Don't use mbrtowc, we know which conversion | ||
747 | to use (UTF-8 -> UCS4). */ | ||
748 | memset (&cur_state, 0, sizeof (cur_state)); | ||
749 | mbclen = mbrtowc (&wc2, (const char *) p, mlen, | ||
750 | &cur_state); | ||
751 | if (raw + offset - p <= mbclen | ||
752 | && mbclen < (size_t) -2) | ||
753 | { | ||
754 | memset (&pstr->cur_state, '\0', | ||
755 | sizeof (mbstate_t)); | ||
756 | pstr->valid_len = mbclen - (raw + offset - p); | ||
757 | wc = wc2; | ||
758 | } | ||
759 | break; | ||
760 | } | ||
669 | } | 761 | } |
670 | 762 | ||
671 | if (wc == WEOF) | 763 | if (wc == WEOF) |
672 | pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx; | 764 | pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx; |
765 | if (wc == WEOF) | ||
766 | pstr->tip_context | ||
767 | = re_string_context_at (pstr, prev_valid_len - 1, eflags); | ||
768 | else | ||
769 | pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) | ||
770 | && IS_WIDE_WORD_CHAR (wc)) | ||
771 | ? CONTEXT_WORD | ||
772 | : ((IS_WIDE_NEWLINE (wc) | ||
773 | && pstr->newline_anchor) | ||
774 | ? CONTEXT_NEWLINE : 0)); | ||
673 | if (BE (pstr->valid_len, 0)) | 775 | if (BE (pstr->valid_len, 0)) |
674 | { | 776 | { |
675 | for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) | 777 | for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) |
676 | pstr->wcs[wcs_idx] = WEOF; | 778 | pstr->wcs[wcs_idx] = WEOF; |
677 | if (pstr->mbs_allocated) | 779 | if (pstr->mbs_allocated) |
678 | memset (pstr->mbs, -1, pstr->valid_len); | 780 | memset (pstr->mbs, 255, pstr->valid_len); |
679 | } | 781 | } |
680 | pstr->valid_raw_len = pstr->valid_len; | 782 | pstr->valid_raw_len = pstr->valid_len; |
681 | pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) | ||
682 | && IS_WIDE_WORD_CHAR (wc)) | ||
683 | ? CONTEXT_WORD | ||
684 | : ((IS_WIDE_NEWLINE (wc) | ||
685 | && pstr->newline_anchor) | ||
686 | ? CONTEXT_NEWLINE : 0)); | ||
687 | } | 783 | } |
688 | else | 784 | else |
689 | #endif /* RE_ENABLE_I18N */ | 785 | #endif /* RE_ENABLE_I18N */ |
690 | { | 786 | { |
691 | int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; | 787 | int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; |
788 | pstr->valid_raw_len = 0; | ||
692 | if (pstr->trans) | 789 | if (pstr->trans) |
693 | c = pstr->trans[c]; | 790 | c = pstr->trans[c]; |
694 | pstr->tip_context = (bitset_contain (pstr->word_char, c) | 791 | pstr->tip_context = (bitset_contain (pstr->word_char, c) |
@@ -719,15 +816,15 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) | |||
719 | } | 816 | } |
720 | else | 817 | else |
721 | #endif /* RE_ENABLE_I18N */ | 818 | #endif /* RE_ENABLE_I18N */ |
722 | if (BE (pstr->mbs_allocated, 0)) | 819 | if (BE (pstr->mbs_allocated, 0)) |
723 | { | 820 | { |
724 | if (pstr->icase) | 821 | if (pstr->icase) |
725 | build_upper_buffer (pstr); | 822 | build_upper_buffer (pstr); |
726 | else if (pstr->trans != NULL) | 823 | else if (pstr->trans != NULL) |
727 | re_string_translate_buffer (pstr); | 824 | re_string_translate_buffer (pstr); |
728 | } | 825 | } |
729 | else | 826 | else |
730 | pstr->valid_len = pstr->len; | 827 | pstr->valid_len = pstr->len; |
731 | 828 | ||
732 | pstr->cur_idx = 0; | 829 | pstr->cur_idx = 0; |
733 | return REG_NOERROR; | 830 | return REG_NOERROR; |
@@ -873,7 +970,7 @@ re_node_set_alloc (re_node_set *set, Idx size) | |||
873 | { | 970 | { |
874 | set->alloc = size; | 971 | set->alloc = size; |
875 | set->nelem = 0; | 972 | set->nelem = 0; |
876 | set->elems = re_xmalloc (Idx, size); | 973 | set->elems = re_malloc (Idx, size); |
877 | if (BE (set->elems == NULL, 0)) | 974 | if (BE (set->elems == NULL, 0)) |
878 | return REG_ESPACE; | 975 | return REG_ESPACE; |
879 | return REG_NOERROR; | 976 | return REG_NOERROR; |
@@ -939,7 +1036,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src) | |||
939 | dest->alloc = dest->nelem = 0; | 1036 | dest->alloc = dest->nelem = 0; |
940 | return REG_ESPACE; | 1037 | return REG_ESPACE; |
941 | } | 1038 | } |
942 | memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]); | 1039 | memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); |
943 | } | 1040 | } |
944 | else | 1041 | else |
945 | re_node_set_init_empty (dest); | 1042 | re_node_set_init_empty (dest); |
@@ -964,12 +1061,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, | |||
964 | if (src1->nelem + src2->nelem + dest->nelem > dest->alloc) | 1061 | if (src1->nelem + src2->nelem + dest->nelem > dest->alloc) |
965 | { | 1062 | { |
966 | Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; | 1063 | Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; |
967 | Idx *new_elems; | 1064 | Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); |
968 | if (sizeof (Idx) < 3 | ||
969 | && (new_alloc < dest->alloc | ||
970 | || ((Idx) (src1->nelem + src2->nelem) < src1->nelem))) | ||
971 | return REG_ESPACE; | ||
972 | new_elems = re_xrealloc (dest->elems, Idx, new_alloc); | ||
973 | if (BE (new_elems == NULL, 0)) | 1065 | if (BE (new_elems == NULL, 0)) |
974 | return REG_ESPACE; | 1066 | return REG_ESPACE; |
975 | dest->elems = new_elems; | 1067 | dest->elems = new_elems; |
@@ -1038,7 +1130,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, | |||
1038 | } | 1130 | } |
1039 | 1131 | ||
1040 | /* Copy remaining SRC elements. */ | 1132 | /* Copy remaining SRC elements. */ |
1041 | memcpy (dest->elems, dest->elems + sbase, delta * sizeof dest->elems[0]); | 1133 | memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx)); |
1042 | 1134 | ||
1043 | return REG_NOERROR; | 1135 | return REG_NOERROR; |
1044 | } | 1136 | } |
@@ -1055,9 +1147,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1, | |||
1055 | if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0) | 1147 | if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0) |
1056 | { | 1148 | { |
1057 | dest->alloc = src1->nelem + src2->nelem; | 1149 | dest->alloc = src1->nelem + src2->nelem; |
1058 | if (sizeof (Idx) < 2 && dest->alloc < src1->nelem) | 1150 | dest->elems = re_malloc (Idx, dest->alloc); |
1059 | return REG_ESPACE; | ||
1060 | dest->elems = re_xmalloc (Idx, dest->alloc); | ||
1061 | if (BE (dest->elems == NULL, 0)) | 1151 | if (BE (dest->elems == NULL, 0)) |
1062 | return REG_ESPACE; | 1152 | return REG_ESPACE; |
1063 | } | 1153 | } |
@@ -1085,13 +1175,13 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1, | |||
1085 | if (i1 < src1->nelem) | 1175 | if (i1 < src1->nelem) |
1086 | { | 1176 | { |
1087 | memcpy (dest->elems + id, src1->elems + i1, | 1177 | memcpy (dest->elems + id, src1->elems + i1, |
1088 | (src1->nelem - i1) * sizeof dest->elems[0]); | 1178 | (src1->nelem - i1) * sizeof (Idx)); |
1089 | id += src1->nelem - i1; | 1179 | id += src1->nelem - i1; |
1090 | } | 1180 | } |
1091 | else if (i2 < src2->nelem) | 1181 | else if (i2 < src2->nelem) |
1092 | { | 1182 | { |
1093 | memcpy (dest->elems + id, src2->elems + i2, | 1183 | memcpy (dest->elems + id, src2->elems + i2, |
1094 | (src2->nelem - i2) * sizeof dest->elems[0]); | 1184 | (src2->nelem - i2) * sizeof (Idx)); |
1095 | id += src2->nelem - i2; | 1185 | id += src2->nelem - i2; |
1096 | } | 1186 | } |
1097 | dest->nelem = id; | 1187 | dest->nelem = id; |
@@ -1108,17 +1198,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) | |||
1108 | Idx is, id, sbase, delta; | 1198 | Idx is, id, sbase, delta; |
1109 | if (src == NULL || src->nelem == 0) | 1199 | if (src == NULL || src->nelem == 0) |
1110 | return REG_NOERROR; | 1200 | return REG_NOERROR; |
1111 | if (sizeof (Idx) < 3 | ||
1112 | && ((Idx) (2 * src->nelem) < src->nelem | ||
1113 | || (Idx) (2 * src->nelem + dest->nelem) < dest->nelem)) | ||
1114 | return REG_ESPACE; | ||
1115 | if (dest->alloc < 2 * src->nelem + dest->nelem) | 1201 | if (dest->alloc < 2 * src->nelem + dest->nelem) |
1116 | { | 1202 | { |
1117 | Idx new_alloc = src->nelem + dest->alloc; | 1203 | Idx new_alloc = 2 * (src->nelem + dest->alloc); |
1118 | Idx *new_buffer; | 1204 | Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc); |
1119 | if (sizeof (Idx) < 4 && new_alloc < dest->alloc) | ||
1120 | return REG_ESPACE; | ||
1121 | new_buffer = re_x2realloc (dest->elems, Idx, &new_alloc); | ||
1122 | if (BE (new_buffer == NULL, 0)) | 1205 | if (BE (new_buffer == NULL, 0)) |
1123 | return REG_ESPACE; | 1206 | return REG_ESPACE; |
1124 | dest->elems = new_buffer; | 1207 | dest->elems = new_buffer; |
@@ -1128,7 +1211,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) | |||
1128 | if (BE (dest->nelem == 0, 0)) | 1211 | if (BE (dest->nelem == 0, 0)) |
1129 | { | 1212 | { |
1130 | dest->nelem = src->nelem; | 1213 | dest->nelem = src->nelem; |
1131 | memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]); | 1214 | memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); |
1132 | return REG_NOERROR; | 1215 | return REG_NOERROR; |
1133 | } | 1216 | } |
1134 | 1217 | ||
@@ -1150,8 +1233,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) | |||
1150 | { | 1233 | { |
1151 | /* If DEST is exhausted, the remaining items of SRC must be unique. */ | 1234 | /* If DEST is exhausted, the remaining items of SRC must be unique. */ |
1152 | sbase -= is + 1; | 1235 | sbase -= is + 1; |
1153 | memcpy (dest->elems + sbase, src->elems, | 1236 | memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx)); |
1154 | (is + 1) * sizeof dest->elems[0]); | ||
1155 | } | 1237 | } |
1156 | 1238 | ||
1157 | id = dest->nelem - 1; | 1239 | id = dest->nelem - 1; |
@@ -1180,7 +1262,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) | |||
1180 | { | 1262 | { |
1181 | /* Copy remaining SRC elements. */ | 1263 | /* Copy remaining SRC elements. */ |
1182 | memcpy (dest->elems, dest->elems + sbase, | 1264 | memcpy (dest->elems, dest->elems + sbase, |
1183 | delta * sizeof dest->elems[0]); | 1265 | delta * sizeof (Idx)); |
1184 | break; | 1266 | break; |
1185 | } | 1267 | } |
1186 | } | 1268 | } |
@@ -1200,7 +1282,7 @@ re_node_set_insert (re_node_set *set, Idx elem) | |||
1200 | Idx idx; | 1282 | Idx idx; |
1201 | /* In case the set is empty. */ | 1283 | /* In case the set is empty. */ |
1202 | if (set->alloc == 0) | 1284 | if (set->alloc == 0) |
1203 | return re_node_set_init_1 (set, elem) == REG_NOERROR; | 1285 | return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1); |
1204 | 1286 | ||
1205 | if (BE (set->nelem, 0) == 0) | 1287 | if (BE (set->nelem, 0) == 0) |
1206 | { | 1288 | { |
@@ -1213,7 +1295,9 @@ re_node_set_insert (re_node_set *set, Idx elem) | |||
1213 | /* Realloc if we need. */ | 1295 | /* Realloc if we need. */ |
1214 | if (set->alloc == set->nelem) | 1296 | if (set->alloc == set->nelem) |
1215 | { | 1297 | { |
1216 | Idx *new_elems = re_x2realloc (set->elems, Idx, &set->alloc); | 1298 | Idx *new_elems; |
1299 | set->alloc = set->alloc * 2; | ||
1300 | new_elems = re_realloc (set->elems, Idx, set->alloc); | ||
1217 | if (BE (new_elems == NULL, 0)) | 1301 | if (BE (new_elems == NULL, 0)) |
1218 | return false; | 1302 | return false; |
1219 | set->elems = new_elems; | 1303 | set->elems = new_elems; |
@@ -1251,7 +1335,8 @@ re_node_set_insert_last (re_node_set *set, Idx elem) | |||
1251 | if (set->alloc == set->nelem) | 1335 | if (set->alloc == set->nelem) |
1252 | { | 1336 | { |
1253 | Idx *new_elems; | 1337 | Idx *new_elems; |
1254 | new_elems = re_x2realloc (set->elems, Idx, &set->alloc); | 1338 | set->alloc = (set->alloc + 1) * 2; |
1339 | new_elems = re_realloc (set->elems, Idx, set->alloc); | ||
1255 | if (BE (new_elems == NULL, 0)) | 1340 | if (BE (new_elems == NULL, 0)) |
1256 | return false; | 1341 | return false; |
1257 | set->elems = new_elems; | 1342 | set->elems = new_elems; |
@@ -1321,21 +1406,28 @@ static Idx | |||
1321 | internal_function | 1406 | internal_function |
1322 | re_dfa_add_node (re_dfa_t *dfa, re_token_t token) | 1407 | re_dfa_add_node (re_dfa_t *dfa, re_token_t token) |
1323 | { | 1408 | { |
1324 | int type = token.type; | ||
1325 | if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) | 1409 | if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) |
1326 | { | 1410 | { |
1327 | Idx new_nodes_alloc = dfa->nodes_alloc; | 1411 | size_t new_nodes_alloc = dfa->nodes_alloc * 2; |
1328 | Idx *new_nexts, *new_indices; | 1412 | Idx *new_nexts, *new_indices; |
1329 | re_node_set *new_edests, *new_eclosures; | 1413 | re_node_set *new_edests, *new_eclosures; |
1414 | re_token_t *new_nodes; | ||
1415 | size_t max_object_size = | ||
1416 | MAX (sizeof (re_token_t), | ||
1417 | MAX (sizeof (re_node_set), | ||
1418 | sizeof (Idx))); | ||
1419 | |||
1420 | /* Avoid overflows. */ | ||
1421 | if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0)) | ||
1422 | return REG_MISSING; | ||
1330 | 1423 | ||
1331 | re_token_t *new_nodes = re_x2realloc (dfa->nodes, re_token_t, | 1424 | new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); |
1332 | &new_nodes_alloc); | ||
1333 | if (BE (new_nodes == NULL, 0)) | 1425 | if (BE (new_nodes == NULL, 0)) |
1334 | return REG_MISSING; | 1426 | return REG_MISSING; |
1335 | dfa->nodes = new_nodes; | 1427 | dfa->nodes = new_nodes; |
1336 | new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); | 1428 | new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); |
1337 | new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); | 1429 | new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); |
1338 | new_edests = re_xrealloc (dfa->edests, re_node_set, new_nodes_alloc); | 1430 | new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); |
1339 | new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); | 1431 | new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); |
1340 | if (BE (new_nexts == NULL || new_indices == NULL | 1432 | if (BE (new_nexts == NULL || new_indices == NULL |
1341 | || new_edests == NULL || new_eclosures == NULL, 0)) | 1433 | || new_edests == NULL || new_eclosures == NULL, 0)) |
@@ -1349,8 +1441,11 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token) | |||
1349 | dfa->nodes[dfa->nodes_len] = token; | 1441 | dfa->nodes[dfa->nodes_len] = token; |
1350 | dfa->nodes[dfa->nodes_len].constraint = 0; | 1442 | dfa->nodes[dfa->nodes_len].constraint = 0; |
1351 | #ifdef RE_ENABLE_I18N | 1443 | #ifdef RE_ENABLE_I18N |
1444 | { | ||
1445 | int type = token.type; | ||
1352 | dfa->nodes[dfa->nodes_len].accept_mb = | 1446 | dfa->nodes[dfa->nodes_len].accept_mb = |
1353 | (type == OP_PERIOD && dfa->mb_cur_max > 1) || type == COMPLEX_BRACKET; | 1447 | (type == OP_PERIOD && dfa->mb_cur_max > 1) || type == COMPLEX_BRACKET; |
1448 | } | ||
1354 | #endif | 1449 | #endif |
1355 | dfa->nexts[dfa->nodes_len] = REG_MISSING; | 1450 | dfa->nexts[dfa->nodes_len] = REG_MISSING; |
1356 | re_node_set_init_empty (dfa->edests + dfa->nodes_len); | 1451 | re_node_set_init_empty (dfa->edests + dfa->nodes_len); |
@@ -1378,9 +1473,10 @@ calc_state_hash (const re_node_set *nodes, unsigned int context) | |||
1378 | - We never return non-NULL value in case of any errors, it is for | 1473 | - We never return non-NULL value in case of any errors, it is for |
1379 | optimization. */ | 1474 | optimization. */ |
1380 | 1475 | ||
1381 | static re_dfastate_t* | 1476 | static re_dfastate_t * |
1382 | internal_function | 1477 | internal_function |
1383 | re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) | 1478 | re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, |
1479 | const re_node_set *nodes) | ||
1384 | { | 1480 | { |
1385 | re_hashval_t hash; | 1481 | re_hashval_t hash; |
1386 | re_dfastate_t *new_state; | 1482 | re_dfastate_t *new_state; |
@@ -1409,13 +1505,10 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) | |||
1409 | 1505 | ||
1410 | /* There are no appropriate state in the dfa, create the new one. */ | 1506 | /* There are no appropriate state in the dfa, create the new one. */ |
1411 | new_state = create_ci_newstate (dfa, nodes, hash); | 1507 | new_state = create_ci_newstate (dfa, nodes, hash); |
1412 | if (BE (new_state != NULL, 1)) | 1508 | if (BE (new_state == NULL, 0)) |
1413 | return new_state; | 1509 | *err = REG_ESPACE; |
1414 | else | 1510 | |
1415 | { | 1511 | return new_state; |
1416 | *err = REG_ESPACE; | ||
1417 | return NULL; | ||
1418 | } | ||
1419 | } | 1512 | } |
1420 | 1513 | ||
1421 | /* Search for the state whose node_set is equivalent to NODES and | 1514 | /* Search for the state whose node_set is equivalent to NODES and |
@@ -1428,9 +1521,9 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) | |||
1428 | - We never return non-NULL value in case of any errors, it is for | 1521 | - We never return non-NULL value in case of any errors, it is for |
1429 | optimization. */ | 1522 | optimization. */ |
1430 | 1523 | ||
1431 | static re_dfastate_t* | 1524 | static re_dfastate_t * |
1432 | internal_function | 1525 | internal_function |
1433 | re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, | 1526 | re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, |
1434 | const re_node_set *nodes, unsigned int context) | 1527 | const re_node_set *nodes, unsigned int context) |
1435 | { | 1528 | { |
1436 | re_hashval_t hash; | 1529 | re_hashval_t hash; |
@@ -1459,13 +1552,10 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, | |||
1459 | } | 1552 | } |
1460 | /* There are no appropriate state in `dfa', create the new one. */ | 1553 | /* There are no appropriate state in `dfa', create the new one. */ |
1461 | new_state = create_cd_newstate (dfa, nodes, context, hash); | 1554 | new_state = create_cd_newstate (dfa, nodes, context, hash); |
1462 | if (BE (new_state != NULL, 1)) | 1555 | if (BE (new_state == NULL, 0)) |
1463 | return new_state; | 1556 | *err = REG_ESPACE; |
1464 | else | 1557 | |
1465 | { | 1558 | return new_state; |
1466 | *err = REG_ESPACE; | ||
1467 | return NULL; | ||
1468 | } | ||
1469 | } | 1559 | } |
1470 | 1560 | ||
1471 | /* Finish initialization of the new state NEWSTATE, and using its hash value | 1561 | /* Finish initialization of the new state NEWSTATE, and using its hash value |
@@ -1473,8 +1563,8 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, | |||
1473 | indicates the error code if failed. */ | 1563 | indicates the error code if failed. */ |
1474 | 1564 | ||
1475 | static reg_errcode_t | 1565 | static reg_errcode_t |
1476 | internal_function | 1566 | register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, |
1477 | register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) | 1567 | re_hashval_t hash) |
1478 | { | 1568 | { |
1479 | struct re_state_table_entry *spot; | 1569 | struct re_state_table_entry *spot; |
1480 | reg_errcode_t err; | 1570 | reg_errcode_t err; |
@@ -1488,19 +1578,16 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) | |||
1488 | { | 1578 | { |
1489 | Idx elem = newstate->nodes.elems[i]; | 1579 | Idx elem = newstate->nodes.elems[i]; |
1490 | if (!IS_EPSILON_NODE (dfa->nodes[elem].type)) | 1580 | if (!IS_EPSILON_NODE (dfa->nodes[elem].type)) |
1491 | { | 1581 | if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0)) |
1492 | bool ok = re_node_set_insert_last (&newstate->non_eps_nodes, elem); | 1582 | return REG_ESPACE; |
1493 | if (BE (! ok, 0)) | ||
1494 | return REG_ESPACE; | ||
1495 | } | ||
1496 | } | 1583 | } |
1497 | 1584 | ||
1498 | spot = dfa->state_table + (hash & dfa->state_hash_mask); | 1585 | spot = dfa->state_table + (hash & dfa->state_hash_mask); |
1499 | if (BE (spot->alloc <= spot->num, 0)) | 1586 | if (BE (spot->alloc <= spot->num, 0)) |
1500 | { | 1587 | { |
1501 | Idx new_alloc = spot->num; | 1588 | Idx new_alloc = 2 * spot->num + 2; |
1502 | re_dfastate_t **new_array = re_x2realloc (spot->array, re_dfastate_t *, | 1589 | re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *, |
1503 | &new_alloc); | 1590 | new_alloc); |
1504 | if (BE (new_array == NULL, 0)) | 1591 | if (BE (new_array == NULL, 0)) |
1505 | return REG_ESPACE; | 1592 | return REG_ESPACE; |
1506 | spot->array = new_array; | 1593 | spot->array = new_array; |
@@ -1510,6 +1597,22 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) | |||
1510 | return REG_NOERROR; | 1597 | return REG_NOERROR; |
1511 | } | 1598 | } |
1512 | 1599 | ||
1600 | static void | ||
1601 | free_state (re_dfastate_t *state) | ||
1602 | { | ||
1603 | re_node_set_free (&state->non_eps_nodes); | ||
1604 | re_node_set_free (&state->inveclosure); | ||
1605 | if (state->entrance_nodes != &state->nodes) | ||
1606 | { | ||
1607 | re_node_set_free (state->entrance_nodes); | ||
1608 | re_free (state->entrance_nodes); | ||
1609 | } | ||
1610 | re_node_set_free (&state->nodes); | ||
1611 | re_free (state->word_trtable); | ||
1612 | re_free (state->trtable); | ||
1613 | re_free (state); | ||
1614 | } | ||
1615 | |||
1513 | /* Create the new state which is independ of contexts. | 1616 | /* Create the new state which is independ of contexts. |
1514 | Return the new state if succeeded, otherwise return NULL. */ | 1617 | Return the new state if succeeded, otherwise return NULL. */ |
1515 | 1618 | ||
@@ -1522,7 +1625,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, | |||
1522 | reg_errcode_t err; | 1625 | reg_errcode_t err; |
1523 | re_dfastate_t *newstate; | 1626 | re_dfastate_t *newstate; |
1524 | 1627 | ||
1525 | newstate = re_calloc (re_dfastate_t, 1); | 1628 | newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); |
1526 | if (BE (newstate == NULL, 0)) | 1629 | if (BE (newstate == NULL, 0)) |
1527 | return NULL; | 1630 | return NULL; |
1528 | err = re_node_set_init_copy (&newstate->nodes, nodes); | 1631 | err = re_node_set_init_copy (&newstate->nodes, nodes); |
@@ -1572,7 +1675,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, | |||
1572 | reg_errcode_t err; | 1675 | reg_errcode_t err; |
1573 | re_dfastate_t *newstate; | 1676 | re_dfastate_t *newstate; |
1574 | 1677 | ||
1575 | newstate = re_calloc (re_dfastate_t, 1); | 1678 | newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); |
1576 | if (BE (newstate == NULL, 0)) | 1679 | if (BE (newstate == NULL, 0)) |
1577 | return NULL; | 1680 | return NULL; |
1578 | err = re_node_set_init_copy (&newstate->nodes, nodes); | 1681 | err = re_node_set_init_copy (&newstate->nodes, nodes); |
@@ -1637,20 +1740,3 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, | |||
1637 | } | 1740 | } |
1638 | return newstate; | 1741 | return newstate; |
1639 | } | 1742 | } |
1640 | |||
1641 | static void | ||
1642 | internal_function | ||
1643 | free_state (re_dfastate_t *state) | ||
1644 | { | ||
1645 | re_node_set_free (&state->non_eps_nodes); | ||
1646 | re_node_set_free (&state->inveclosure); | ||
1647 | if (state->entrance_nodes != &state->nodes) | ||
1648 | { | ||
1649 | re_node_set_free (state->entrance_nodes); | ||
1650 | re_free (state->entrance_nodes); | ||
1651 | } | ||
1652 | re_node_set_free (&state->nodes); | ||
1653 | re_free (state->word_trtable); | ||
1654 | re_free (state->trtable); | ||
1655 | re_free (state); | ||
1656 | } | ||
diff --git a/lib/regex_internal.h b/gl/regex_internal.h index a36ae4c..b0f7e65 100644 --- a/lib/regex_internal.h +++ b/gl/regex_internal.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
@@ -37,23 +37,20 @@ | |||
37 | #if defined HAVE_LOCALE_H || defined _LIBC | 37 | #if defined HAVE_LOCALE_H || defined _LIBC |
38 | # include <locale.h> | 38 | # include <locale.h> |
39 | #endif | 39 | #endif |
40 | #if defined HAVE_WCHAR_H || defined _LIBC | 40 | |
41 | # include <wchar.h> | 41 | #include <wchar.h> |
42 | #endif /* HAVE_WCHAR_H || _LIBC */ | 42 | #include <wctype.h> |
43 | #if defined HAVE_WCTYPE_H || defined _LIBC | 43 | #include <stdint.h> |
44 | # include <wctype.h> | ||
45 | #endif /* HAVE_WCTYPE_H || _LIBC */ | ||
46 | #if defined _LIBC | 44 | #if defined _LIBC |
47 | # include <bits/libc-lock.h> | 45 | # include <bits/libc-lock.h> |
48 | #else | 46 | #else |
49 | # define __libc_lock_define(CLASS,NAME) | ||
50 | # define __libc_lock_init(NAME) do { } while (0) | 47 | # define __libc_lock_init(NAME) do { } while (0) |
51 | # define __libc_lock_lock(NAME) do { } while (0) | 48 | # define __libc_lock_lock(NAME) do { } while (0) |
52 | # define __libc_lock_unlock(NAME) do { } while (0) | 49 | # define __libc_lock_unlock(NAME) do { } while (0) |
53 | #endif | 50 | #endif |
54 | 51 | ||
55 | /* In case that the system doesn't have isblank(). */ | 52 | /* In case that the system doesn't have isblank(). */ |
56 | #if !defined _LIBC && !defined HAVE_ISBLANK && !defined isblank | 53 | #if !defined _LIBC && !HAVE_DECL_ISBLANK && !defined isblank |
57 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') | 54 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') |
58 | #endif | 55 | #endif |
59 | 56 | ||
@@ -84,7 +81,12 @@ | |||
84 | # define gettext_noop(String) String | 81 | # define gettext_noop(String) String |
85 | #endif | 82 | #endif |
86 | 83 | ||
87 | #if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC | 84 | /* For loser systems without the definition. */ |
85 | #ifndef SIZE_MAX | ||
86 | # define SIZE_MAX ((size_t) -1) | ||
87 | #endif | ||
88 | |||
89 | #if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC | ||
88 | # define RE_ENABLE_I18N | 90 | # define RE_ENABLE_I18N |
89 | #endif | 91 | #endif |
90 | 92 | ||
@@ -92,10 +94,16 @@ | |||
92 | # define BE(expr, val) __builtin_expect (expr, val) | 94 | # define BE(expr, val) __builtin_expect (expr, val) |
93 | #else | 95 | #else |
94 | # define BE(expr, val) (expr) | 96 | # define BE(expr, val) (expr) |
97 | # ifdef _LIBC | ||
98 | # define inline | ||
99 | # endif | ||
95 | #endif | 100 | #endif |
96 | 101 | ||
97 | /* Number of single byte character. */ | 102 | /* Number of ASCII characters. */ |
98 | #define SBC_MAX 256 | 103 | #define ASCII_CHARS 0x80 |
104 | |||
105 | /* Number of single byte characters. */ | ||
106 | #define SBC_MAX (UCHAR_MAX + 1) | ||
99 | 107 | ||
100 | #define COLL_ELEM_LEN_MAX 8 | 108 | #define COLL_ELEM_LEN_MAX 8 |
101 | 109 | ||
@@ -122,9 +130,6 @@ | |||
122 | # define __attribute(arg) | 130 | # define __attribute(arg) |
123 | #endif | 131 | #endif |
124 | 132 | ||
125 | extern const char __re_error_msgid[] attribute_hidden; | ||
126 | extern const size_t __re_error_msgid_idx[] attribute_hidden; | ||
127 | |||
128 | typedef __re_idx_t Idx; | 133 | typedef __re_idx_t Idx; |
129 | 134 | ||
130 | /* Special return value for failure to match. */ | 135 | /* Special return value for failure to match. */ |
@@ -152,15 +157,15 @@ typedef __re_size_t re_hashval_t; | |||
152 | 157 | ||
153 | /* An integer used to represent a set of bits. It must be unsigned, | 158 | /* An integer used to represent a set of bits. It must be unsigned, |
154 | and must be at least as wide as unsigned int. */ | 159 | and must be at least as wide as unsigned int. */ |
155 | typedef unsigned long int bitset_word; | 160 | typedef unsigned long int bitset_word_t; |
156 | 161 | /* All bits set in a bitset_word_t. */ | |
157 | /* Maximum value of a bitset word. It must be useful in preprocessor | ||
158 | contexts, and must be consistent with bitset_word. */ | ||
159 | #define BITSET_WORD_MAX ULONG_MAX | 162 | #define BITSET_WORD_MAX ULONG_MAX |
160 | 163 | ||
161 | /* Number of bits in a bitset word. Avoid greater-than-32-bit | 164 | /* Number of bits in a bitset_word_t. For portability to hosts with |
162 | integers and unconditional shifts by more than 31 bits, as they're | 165 | padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)'; |
163 | not portable. */ | 166 | instead, deduce it directly from BITSET_WORD_MAX. Avoid |
167 | greater-than-32-bit integers and unconditional shifts by more than | ||
168 | 31 bits, as they're not portable. */ | ||
164 | #if BITSET_WORD_MAX == 0xffffffff | 169 | #if BITSET_WORD_MAX == 0xffffffff |
165 | # define BITSET_WORD_BITS 32 | 170 | # define BITSET_WORD_BITS 32 |
166 | #elif BITSET_WORD_MAX >> 31 >> 5 == 1 | 171 | #elif BITSET_WORD_MAX >> 31 >> 5 == 1 |
@@ -182,16 +187,20 @@ typedef unsigned long int bitset_word; | |||
182 | # if BITSET_WORD_BITS <= SBC_MAX | 187 | # if BITSET_WORD_BITS <= SBC_MAX |
183 | # error "Invalid SBC_MAX" | 188 | # error "Invalid SBC_MAX" |
184 | # endif | 189 | # endif |
190 | #elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff | ||
191 | /* Work around a bug in 64-bit PGC (before version 6.1-2), where the | ||
192 | preprocessor mishandles large unsigned values as if they were signed. */ | ||
193 | # define BITSET_WORD_BITS 64 | ||
185 | #else | 194 | #else |
186 | # error "Add case for new bitset_word size" | 195 | # error "Add case for new bitset_word_t size" |
187 | #endif | 196 | #endif |
188 | 197 | ||
189 | /* Number of bitset words in a bitset. */ | 198 | /* Number of bitset_word_t values in a bitset_t. */ |
190 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) | 199 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) |
191 | 200 | ||
192 | typedef bitset_word bitset[BITSET_WORDS]; | 201 | typedef bitset_word_t bitset_t[BITSET_WORDS]; |
193 | typedef bitset_word *re_bitset_ptr_t; | 202 | typedef bitset_word_t *re_bitset_ptr_t; |
194 | typedef const bitset_word *re_const_bitset_ptr_t; | 203 | typedef const bitset_word_t *re_const_bitset_ptr_t; |
195 | 204 | ||
196 | #define PREV_WORD_CONSTRAINT 0x0001 | 205 | #define PREV_WORD_CONSTRAINT 0x0001 |
197 | #define PREV_NOTWORD_CONSTRAINT 0x0002 | 206 | #define PREV_NOTWORD_CONSTRAINT 0x0002 |
@@ -336,7 +345,7 @@ typedef struct | |||
336 | Idx idx; /* for BACK_REF */ | 345 | Idx idx; /* for BACK_REF */ |
337 | re_context_type ctx_type; /* for ANCHOR */ | 346 | re_context_type ctx_type; /* for ANCHOR */ |
338 | } opr; | 347 | } opr; |
339 | #if __GNUC__ >= 2 | 348 | #if __GNUC__ >= 2 && !__STRICT_ANSI__ |
340 | re_token_type_t type : 8; | 349 | re_token_type_t type : 8; |
341 | #else | 350 | #else |
342 | re_token_type_t type; | 351 | re_token_type_t type; |
@@ -397,7 +406,7 @@ struct re_string_t | |||
397 | the beginning of the input string. */ | 406 | the beginning of the input string. */ |
398 | unsigned int tip_context; | 407 | unsigned int tip_context; |
399 | /* The translation passed as a part of an argument of re_compile_pattern. */ | 408 | /* The translation passed as a part of an argument of re_compile_pattern. */ |
400 | unsigned REG_TRANSLATE_TYPE trans; | 409 | RE_TRANSLATE_TYPE trans; |
401 | /* Copy of re_dfa_t's word_char. */ | 410 | /* Copy of re_dfa_t's word_char. */ |
402 | re_const_bitset_ptr_t word_char; | 411 | re_const_bitset_ptr_t word_char; |
403 | /* true if REG_ICASE. */ | 412 | /* true if REG_ICASE. */ |
@@ -434,10 +443,9 @@ static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) | |||
434 | #endif /* RE_ENABLE_I18N */ | 443 | #endif /* RE_ENABLE_I18N */ |
435 | static void build_upper_buffer (re_string_t *pstr) internal_function; | 444 | static void build_upper_buffer (re_string_t *pstr) internal_function; |
436 | static void re_string_translate_buffer (re_string_t *pstr) internal_function; | 445 | static void re_string_translate_buffer (re_string_t *pstr) internal_function; |
437 | static unsigned int re_string_context_at (const re_string_t *input, | 446 | static unsigned int re_string_context_at (const re_string_t *input, Idx idx, |
438 | Idx idx, int eflags) | 447 | int eflags) |
439 | internal_function __attribute ((pure)); | 448 | internal_function __attribute ((pure)); |
440 | |||
441 | #define re_string_peek_byte(pstr, offset) \ | 449 | #define re_string_peek_byte(pstr, offset) \ |
442 | ((pstr)->mbs[(pstr)->cur_idx + offset]) | 450 | ((pstr)->mbs[(pstr)->cur_idx + offset]) |
443 | #define re_string_fetch_byte(pstr) \ | 451 | #define re_string_fetch_byte(pstr) \ |
@@ -470,71 +478,14 @@ static unsigned int re_string_context_at (const re_string_t *input, | |||
470 | # endif | 478 | # endif |
471 | #endif | 479 | #endif |
472 | 480 | ||
481 | #ifndef MAX | ||
482 | # define MAX(a,b) ((a) < (b) ? (b) : (a)) | ||
483 | #endif | ||
484 | |||
473 | #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) | 485 | #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) |
474 | #define re_xmalloc(t,n) ((t *) re_xnmalloc (n, sizeof (t))) | ||
475 | #define re_calloc(t,n) ((t *) calloc (n, sizeof (t))) | ||
476 | #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) | 486 | #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) |
477 | #define re_xrealloc(p,t,n) ((t *) re_xnrealloc (p, n, sizeof (t))) | ||
478 | #define re_x2realloc(p,t,pn) ((t *) re_x2nrealloc (p, pn, sizeof (t))) | ||
479 | #define re_free(p) free (p) | 487 | #define re_free(p) free (p) |
480 | 488 | ||
481 | #ifndef SIZE_MAX | ||
482 | # define SIZE_MAX ((size_t) -1) | ||
483 | #endif | ||
484 | |||
485 | /* Return true if an array of N objects, each of size S, cannot exist | ||
486 | due to size arithmetic overflow. S must be nonzero. */ | ||
487 | static inline bool | ||
488 | re_alloc_oversized (size_t n, size_t s) | ||
489 | { | ||
490 | return BE (SIZE_MAX / s < n, 0); | ||
491 | } | ||
492 | |||
493 | /* Return true if an array of (2 * N + 1) objects, each of size S, | ||
494 | cannot exist due to size arithmetic overflow. S must be nonzero. */ | ||
495 | static inline bool | ||
496 | re_x2alloc_oversized (size_t n, size_t s) | ||
497 | { | ||
498 | return BE ((SIZE_MAX / s - 1) / 2 < n, 0); | ||
499 | } | ||
500 | |||
501 | /* Allocate an array of N objects, each with S bytes of memory, | ||
502 | dynamically, with error checking. S must be nonzero. */ | ||
503 | static inline void * | ||
504 | re_xnmalloc (size_t n, size_t s) | ||
505 | { | ||
506 | return re_alloc_oversized (n, s) ? NULL : malloc (n * s); | ||
507 | } | ||
508 | |||
509 | /* Change the size of an allocated block of memory P to an array of N | ||
510 | objects each of S bytes, with error checking. S must be nonzero. */ | ||
511 | static inline void * | ||
512 | re_xnrealloc (void *p, size_t n, size_t s) | ||
513 | { | ||
514 | return re_alloc_oversized (n, s) ? NULL : realloc (p, n * s); | ||
515 | } | ||
516 | |||
517 | /* Reallocate a block of memory P to an array of (2 * (*PN) + 1) | ||
518 | objects each of S bytes, with error checking. S must be nonzero. | ||
519 | If the allocation is successful, set *PN to the new allocation | ||
520 | count and return the resulting pointer. Otherwise, return | ||
521 | NULL. */ | ||
522 | static inline void * | ||
523 | re_x2nrealloc (void *p, size_t *pn, size_t s) | ||
524 | { | ||
525 | if (re_x2alloc_oversized (*pn, s)) | ||
526 | return NULL; | ||
527 | else | ||
528 | { | ||
529 | /* Add 1 in case *PN is zero. */ | ||
530 | size_t n1 = 2 * *pn + 1; | ||
531 | p = realloc (p, n1 * s); | ||
532 | if (BE (p != NULL, 1)) | ||
533 | *pn = n1; | ||
534 | return p; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | struct bin_tree_t | 489 | struct bin_tree_t |
539 | { | 490 | { |
540 | struct bin_tree_t *parent; | 491 | struct bin_tree_t *parent; |
@@ -664,9 +615,9 @@ typedef struct | |||
664 | /* The string object corresponding to the input string. */ | 615 | /* The string object corresponding to the input string. */ |
665 | re_string_t input; | 616 | re_string_t input; |
666 | #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) | 617 | #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) |
667 | re_dfa_t *const dfa; | 618 | const re_dfa_t *const dfa; |
668 | #else | 619 | #else |
669 | re_dfa_t *dfa; | 620 | const re_dfa_t *dfa; |
670 | #endif | 621 | #endif |
671 | /* EFLAGS of the argument of regexec. */ | 622 | /* EFLAGS of the argument of regexec. */ |
672 | int eflags; | 623 | int eflags; |
@@ -713,8 +664,8 @@ struct re_fail_stack_t | |||
713 | struct re_dfa_t | 664 | struct re_dfa_t |
714 | { | 665 | { |
715 | re_token_t *nodes; | 666 | re_token_t *nodes; |
716 | Idx nodes_alloc; | 667 | size_t nodes_alloc; |
717 | Idx nodes_len; | 668 | size_t nodes_len; |
718 | Idx *nexts; | 669 | Idx *nexts; |
719 | Idx *org_indices; | 670 | Idx *org_indices; |
720 | re_node_set *edests; | 671 | re_node_set *edests; |
@@ -736,8 +687,8 @@ struct re_dfa_t | |||
736 | Idx nbackref; /* The number of backreference in this dfa. */ | 687 | Idx nbackref; /* The number of backreference in this dfa. */ |
737 | 688 | ||
738 | /* Bitmap expressing which backreference is used. */ | 689 | /* Bitmap expressing which backreference is used. */ |
739 | bitset_word used_bkref_map; | 690 | bitset_word_t used_bkref_map; |
740 | bitset_word completed_bkref_map; | 691 | bitset_word_t completed_bkref_map; |
741 | 692 | ||
742 | unsigned int has_plural_match : 1; | 693 | unsigned int has_plural_match : 1; |
743 | /* If this dfa has "multibyte node", which is a backreference or | 694 | /* If this dfa has "multibyte node", which is a backreference or |
@@ -748,13 +699,15 @@ struct re_dfa_t | |||
748 | unsigned int map_notascii : 1; | 699 | unsigned int map_notascii : 1; |
749 | unsigned int word_ops_used : 1; | 700 | unsigned int word_ops_used : 1; |
750 | int mb_cur_max; | 701 | int mb_cur_max; |
751 | bitset word_char; | 702 | bitset_t word_char; |
752 | reg_syntax_t syntax; | 703 | reg_syntax_t syntax; |
753 | Idx *subexp_map; | 704 | Idx *subexp_map; |
754 | #ifdef DEBUG | 705 | #ifdef DEBUG |
755 | char* re_str; | 706 | char* re_str; |
756 | #endif | 707 | #endif |
708 | #ifdef _LIBC | ||
757 | __libc_lock_define (, lock) | 709 | __libc_lock_define (, lock) |
710 | #endif | ||
758 | }; | 711 | }; |
759 | 712 | ||
760 | #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set)) | 713 | #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set)) |
@@ -762,8 +715,6 @@ struct re_dfa_t | |||
762 | (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1)) | 715 | (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1)) |
763 | #define re_node_set_empty(p) ((p)->nelem = 0) | 716 | #define re_node_set_empty(p) ((p)->nelem = 0) |
764 | #define re_node_set_free(set) re_free ((set)->elems) | 717 | #define re_node_set_free(set) re_free ((set)->elems) |
765 | |||
766 | static void free_state (re_dfastate_t *state) internal_function; | ||
767 | 718 | ||
768 | 719 | ||
769 | typedef enum | 720 | typedef enum |
@@ -787,76 +738,76 @@ typedef struct | |||
787 | } bracket_elem_t; | 738 | } bracket_elem_t; |
788 | 739 | ||
789 | 740 | ||
790 | /* Inline functions for bitset operation. */ | 741 | /* Inline functions for bitset_t operation. */ |
791 | 742 | ||
792 | static inline void | 743 | static inline void |
793 | bitset_set (bitset set, Idx i) | 744 | bitset_set (bitset_t set, Idx i) |
794 | { | 745 | { |
795 | set[i / BITSET_WORD_BITS] |= (bitset_word) 1 << i % BITSET_WORD_BITS; | 746 | set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; |
796 | } | 747 | } |
797 | 748 | ||
798 | static inline void | 749 | static inline void |
799 | bitset_clear (bitset set, Idx i) | 750 | bitset_clear (bitset_t set, Idx i) |
800 | { | 751 | { |
801 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word) 1 << i % BITSET_WORD_BITS); | 752 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); |
802 | } | 753 | } |
803 | 754 | ||
804 | static inline bool | 755 | static inline bool |
805 | bitset_contain (const bitset set, Idx i) | 756 | bitset_contain (const bitset_t set, Idx i) |
806 | { | 757 | { |
807 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; | 758 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; |
808 | } | 759 | } |
809 | 760 | ||
810 | static inline void | 761 | static inline void |
811 | bitset_empty (bitset set) | 762 | bitset_empty (bitset_t set) |
812 | { | 763 | { |
813 | memset (set, 0, sizeof (bitset)); | 764 | memset (set, '\0', sizeof (bitset_t)); |
814 | } | 765 | } |
815 | 766 | ||
816 | static inline void | 767 | static inline void |
817 | bitset_set_all (bitset set) | 768 | bitset_set_all (bitset_t set) |
818 | { | 769 | { |
819 | memset (set, -1, sizeof (bitset_word) * (SBC_MAX / BITSET_WORD_BITS)); | 770 | memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); |
820 | if (SBC_MAX % BITSET_WORD_BITS != 0) | 771 | if (SBC_MAX % BITSET_WORD_BITS != 0) |
821 | set[BITSET_WORDS - 1] = | 772 | set[BITSET_WORDS - 1] = |
822 | ((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; | 773 | ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; |
823 | } | 774 | } |
824 | 775 | ||
825 | static inline void | 776 | static inline void |
826 | bitset_copy (bitset dest, const bitset src) | 777 | bitset_copy (bitset_t dest, const bitset_t src) |
827 | { | 778 | { |
828 | memcpy (dest, src, sizeof (bitset)); | 779 | memcpy (dest, src, sizeof (bitset_t)); |
829 | } | 780 | } |
830 | 781 | ||
831 | static inline void | 782 | static inline void |
832 | bitset_not (bitset set) | 783 | bitset_not (bitset_t set) |
833 | { | 784 | { |
834 | int i; | 785 | int bitset_i; |
835 | for (i = 0; i < SBC_MAX / BITSET_WORD_BITS; ++i) | 786 | for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i) |
836 | set[i] = ~set[i]; | 787 | set[bitset_i] = ~set[bitset_i]; |
837 | if (SBC_MAX % BITSET_WORD_BITS != 0) | 788 | if (SBC_MAX % BITSET_WORD_BITS != 0) |
838 | set[BITSET_WORDS - 1] = | 789 | set[BITSET_WORDS - 1] = |
839 | ((((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1) | 790 | ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1) |
840 | & ~set[BITSET_WORDS - 1]); | 791 | & ~set[BITSET_WORDS - 1]); |
841 | } | 792 | } |
842 | 793 | ||
843 | static inline void | 794 | static inline void |
844 | bitset_merge (bitset dest, const bitset src) | 795 | bitset_merge (bitset_t dest, const bitset_t src) |
845 | { | 796 | { |
846 | int i; | 797 | int bitset_i; |
847 | for (i = 0; i < BITSET_WORDS; ++i) | 798 | for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) |
848 | dest[i] |= src[i]; | 799 | dest[bitset_i] |= src[bitset_i]; |
849 | } | 800 | } |
850 | 801 | ||
851 | static inline void | 802 | static inline void |
852 | bitset_mask (bitset dest, const bitset src) | 803 | bitset_mask (bitset_t dest, const bitset_t src) |
853 | { | 804 | { |
854 | int i; | 805 | int bitset_i; |
855 | for (i = 0; i < BITSET_WORDS; ++i) | 806 | for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) |
856 | dest[i] &= src[i]; | 807 | dest[bitset_i] &= src[bitset_i]; |
857 | } | 808 | } |
858 | 809 | ||
859 | #if defined RE_ENABLE_I18N | 810 | #ifdef RE_ENABLE_I18N |
860 | /* Inline functions for re_string. */ | 811 | /* Inline functions for re_string. */ |
861 | static inline int | 812 | static inline int |
862 | internal_function __attribute ((pure)) | 813 | internal_function __attribute ((pure)) |
@@ -884,11 +835,11 @@ static int | |||
884 | internal_function __attribute ((pure)) | 835 | internal_function __attribute ((pure)) |
885 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) | 836 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) |
886 | { | 837 | { |
887 | #ifdef _LIBC | 838 | # ifdef _LIBC |
888 | const unsigned char *p, *extra; | 839 | const unsigned char *p, *extra; |
889 | const int32_t *table, *indirect; | 840 | const int32_t *table, *indirect; |
890 | int32_t tmp; | 841 | int32_t tmp; |
891 | # include <locale/weight.h> | 842 | # include <locale/weight.h> |
892 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); | 843 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); |
893 | 844 | ||
894 | if (nrules != 0) | 845 | if (nrules != 0) |
@@ -903,7 +854,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) | |||
903 | return p - pstr->mbs - idx; | 854 | return p - pstr->mbs - idx; |
904 | } | 855 | } |
905 | else | 856 | else |
906 | #endif /* _LIBC */ | 857 | # endif /* _LIBC */ |
907 | return 1; | 858 | return 1; |
908 | } | 859 | } |
909 | #endif /* RE_ENABLE_I18N */ | 860 | #endif /* RE_ENABLE_I18N */ |
diff --git a/lib/regexec.c b/gl/regexec.c index a85077c..7c186aa 100644 --- a/lib/regexec.c +++ b/gl/regexec.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
@@ -51,68 +51,79 @@ static regoff_t re_search_stub (struct re_pattern_buffer *bufp, | |||
51 | regoff_t range, Idx stop, | 51 | regoff_t range, Idx stop, |
52 | struct re_registers *regs, | 52 | struct re_registers *regs, |
53 | bool ret_len) internal_function; | 53 | bool ret_len) internal_function; |
54 | static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, | 54 | static unsigned int re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, |
55 | Idx nregs, int regs_allocated) internal_function; | 55 | Idx nregs, int regs_allocated) |
56 | internal_function; | ||
56 | static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) | 57 | static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) |
57 | internal_function; | 58 | internal_function; |
58 | static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match, | 59 | static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match, |
59 | Idx *p_match_first) | 60 | Idx *p_match_first) internal_function; |
60 | internal_function; | ||
61 | static Idx check_halt_state_context (const re_match_context_t *mctx, | 61 | static Idx check_halt_state_context (const re_match_context_t *mctx, |
62 | const re_dfastate_t *state, Idx idx) | 62 | const re_dfastate_t *state, Idx idx) |
63 | internal_function; | 63 | internal_function; |
64 | static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch, | 64 | static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, |
65 | regmatch_t *prev_idx_match, Idx cur_node, | 65 | regmatch_t *prev_idx_match, Idx cur_node, |
66 | Idx cur_idx, Idx nmatch) internal_function; | 66 | Idx cur_idx, Idx nmatch) internal_function; |
67 | static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, | 67 | static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, |
68 | Idx str_idx, Idx dest_node, Idx nregs, | 68 | Idx str_idx, Idx dest_node, Idx nregs, |
69 | regmatch_t *regs, | 69 | regmatch_t *regs, |
70 | re_node_set *eps_via_nodes) internal_function; | 70 | re_node_set *eps_via_nodes) |
71 | internal_function; | ||
71 | static reg_errcode_t set_regs (const regex_t *preg, | 72 | static reg_errcode_t set_regs (const regex_t *preg, |
72 | const re_match_context_t *mctx, | 73 | const re_match_context_t *mctx, |
73 | size_t nmatch, regmatch_t *pmatch, | 74 | size_t nmatch, regmatch_t *pmatch, |
74 | bool fl_backtrack) internal_function; | 75 | bool fl_backtrack) internal_function; |
75 | static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function; | 76 | static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) |
77 | internal_function; | ||
76 | 78 | ||
77 | #ifdef RE_ENABLE_I18N | 79 | #ifdef RE_ENABLE_I18N |
78 | static int sift_states_iter_mb (const re_match_context_t *mctx, | 80 | static int sift_states_iter_mb (const re_match_context_t *mctx, |
79 | re_sift_context_t *sctx, | 81 | re_sift_context_t *sctx, |
80 | Idx node_idx, Idx str_idx, Idx max_str_idx) internal_function; | 82 | Idx node_idx, Idx str_idx, Idx max_str_idx) |
83 | internal_function; | ||
81 | #endif /* RE_ENABLE_I18N */ | 84 | #endif /* RE_ENABLE_I18N */ |
82 | static reg_errcode_t sift_states_backward (re_match_context_t *mctx, | 85 | static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, |
83 | re_sift_context_t *sctx) internal_function; | 86 | re_sift_context_t *sctx) |
84 | static reg_errcode_t build_sifted_states (re_match_context_t *mctx, | 87 | internal_function; |
88 | static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, | ||
85 | re_sift_context_t *sctx, Idx str_idx, | 89 | re_sift_context_t *sctx, Idx str_idx, |
86 | re_node_set *cur_dest) internal_function; | 90 | re_node_set *cur_dest) |
87 | static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx, | 91 | internal_function; |
92 | static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, | ||
88 | re_sift_context_t *sctx, | 93 | re_sift_context_t *sctx, |
89 | Idx str_idx, | 94 | Idx str_idx, |
90 | re_node_set *dest_nodes) internal_function; | 95 | re_node_set *dest_nodes) |
91 | static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa, | 96 | internal_function; |
97 | static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, | ||
92 | re_node_set *dest_nodes, | 98 | re_node_set *dest_nodes, |
93 | const re_node_set *candidates) internal_function; | 99 | const re_node_set *candidates) |
100 | internal_function; | ||
94 | static bool check_dst_limits (const re_match_context_t *mctx, | 101 | static bool check_dst_limits (const re_match_context_t *mctx, |
95 | const re_node_set *limits, | 102 | const re_node_set *limits, |
96 | Idx dst_node, Idx dst_idx, Idx src_node, | 103 | Idx dst_node, Idx dst_idx, Idx src_node, |
97 | Idx src_idx) internal_function; | 104 | Idx src_idx) internal_function; |
98 | static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, | 105 | static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, |
99 | int boundaries, Idx subexp_idx, | 106 | int boundaries, Idx subexp_idx, |
100 | Idx from_node, Idx bkref_idx) internal_function; | 107 | Idx from_node, Idx bkref_idx) |
108 | internal_function; | ||
101 | static int check_dst_limits_calc_pos (const re_match_context_t *mctx, | 109 | static int check_dst_limits_calc_pos (const re_match_context_t *mctx, |
102 | Idx limit, Idx subexp_idx, | 110 | Idx limit, Idx subexp_idx, |
103 | Idx node, Idx str_idx, | 111 | Idx node, Idx str_idx, |
104 | Idx bkref_idx) internal_function; | 112 | Idx bkref_idx) internal_function; |
105 | static reg_errcode_t check_subexp_limits (re_dfa_t *dfa, | 113 | static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, |
106 | re_node_set *dest_nodes, | 114 | re_node_set *dest_nodes, |
107 | const re_node_set *candidates, | 115 | const re_node_set *candidates, |
108 | re_node_set *limits, | 116 | re_node_set *limits, |
109 | struct re_backref_cache_entry *bkref_ents, | 117 | struct re_backref_cache_entry *bkref_ents, |
110 | Idx str_idx) internal_function; | 118 | Idx str_idx) internal_function; |
111 | static reg_errcode_t sift_states_bkref (re_match_context_t *mctx, | 119 | static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, |
112 | re_sift_context_t *sctx, | 120 | re_sift_context_t *sctx, |
113 | Idx str_idx, const re_node_set *candidates) internal_function; | 121 | Idx str_idx, const re_node_set *candidates) |
114 | static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, | 122 | internal_function; |
115 | re_dfastate_t **src, Idx num) internal_function; | 123 | static reg_errcode_t merge_state_array (const re_dfa_t *dfa, |
124 | re_dfastate_t **dst, | ||
125 | re_dfastate_t **src, Idx num) | ||
126 | internal_function; | ||
116 | static re_dfastate_t *find_recover_state (reg_errcode_t *err, | 127 | static re_dfastate_t *find_recover_state (reg_errcode_t *err, |
117 | re_match_context_t *mctx) internal_function; | 128 | re_match_context_t *mctx) internal_function; |
118 | static re_dfastate_t *transit_state (reg_errcode_t *err, | 129 | static re_dfastate_t *transit_state (reg_errcode_t *err, |
@@ -120,27 +131,33 @@ static re_dfastate_t *transit_state (reg_errcode_t *err, | |||
120 | re_dfastate_t *state) internal_function; | 131 | re_dfastate_t *state) internal_function; |
121 | static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, | 132 | static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, |
122 | re_match_context_t *mctx, | 133 | re_match_context_t *mctx, |
123 | re_dfastate_t *next_state) internal_function; | 134 | re_dfastate_t *next_state) |
135 | internal_function; | ||
124 | static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, | 136 | static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, |
125 | re_node_set *cur_nodes, | 137 | re_node_set *cur_nodes, |
126 | Idx str_idx) internal_function; | 138 | Idx str_idx) internal_function; |
127 | #if 0 | 139 | #if 0 |
128 | static re_dfastate_t *transit_state_sb (reg_errcode_t *err, | 140 | static re_dfastate_t *transit_state_sb (reg_errcode_t *err, |
129 | re_match_context_t *mctx, | 141 | re_match_context_t *mctx, |
130 | re_dfastate_t *pstate) internal_function; | 142 | re_dfastate_t *pstate) |
143 | internal_function; | ||
131 | #endif | 144 | #endif |
132 | #ifdef RE_ENABLE_I18N | 145 | #ifdef RE_ENABLE_I18N |
133 | static reg_errcode_t transit_state_mb (re_match_context_t *mctx, | 146 | static reg_errcode_t transit_state_mb (re_match_context_t *mctx, |
134 | re_dfastate_t *pstate) internal_function; | 147 | re_dfastate_t *pstate) |
148 | internal_function; | ||
135 | #endif /* RE_ENABLE_I18N */ | 149 | #endif /* RE_ENABLE_I18N */ |
136 | static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, | 150 | static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, |
137 | const re_node_set *nodes) internal_function; | 151 | const re_node_set *nodes) |
152 | internal_function; | ||
138 | static reg_errcode_t get_subexp (re_match_context_t *mctx, | 153 | static reg_errcode_t get_subexp (re_match_context_t *mctx, |
139 | Idx bkref_node, Idx bkref_str_idx) internal_function; | 154 | Idx bkref_node, Idx bkref_str_idx) |
155 | internal_function; | ||
140 | static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, | 156 | static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, |
141 | const re_sub_match_top_t *sub_top, | 157 | const re_sub_match_top_t *sub_top, |
142 | re_sub_match_last_t *sub_last, | 158 | re_sub_match_last_t *sub_last, |
143 | Idx bkref_node, Idx bkref_str) internal_function; | 159 | Idx bkref_node, Idx bkref_str) |
160 | internal_function; | ||
144 | static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, | 161 | static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, |
145 | Idx subexp_idx, int type) internal_function; | 162 | Idx subexp_idx, int type) internal_function; |
146 | static reg_errcode_t check_arrival (re_match_context_t *mctx, | 163 | 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, | |||
150 | static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, | 167 | static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, |
151 | Idx str_idx, | 168 | Idx str_idx, |
152 | re_node_set *cur_nodes, | 169 | re_node_set *cur_nodes, |
153 | re_node_set *next_nodes) internal_function; | 170 | re_node_set *next_nodes) |
154 | static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa, | 171 | internal_function; |
172 | static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, | ||
155 | re_node_set *cur_nodes, | 173 | re_node_set *cur_nodes, |
156 | Idx ex_subexp, int type) internal_function; | 174 | Idx ex_subexp, int type) |
157 | static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa, | 175 | internal_function; |
176 | static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, | ||
158 | re_node_set *dst_nodes, | 177 | re_node_set *dst_nodes, |
159 | Idx target, Idx ex_subexp, | 178 | Idx target, Idx ex_subexp, |
160 | int type) internal_function; | 179 | int type) internal_function; |
161 | static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, | 180 | static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, |
162 | re_node_set *cur_nodes, Idx cur_str, | 181 | re_node_set *cur_nodes, Idx cur_str, |
163 | Idx subexp_num, int type) internal_function; | 182 | Idx subexp_num, int type) |
164 | static bool build_trtable (re_dfa_t *dfa, | 183 | internal_function; |
184 | static bool build_trtable (const re_dfa_t *dfa, | ||
165 | re_dfastate_t *state) internal_function; | 185 | re_dfastate_t *state) internal_function; |
166 | #ifdef RE_ENABLE_I18N | 186 | #ifdef RE_ENABLE_I18N |
167 | static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, | 187 | static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, |
168 | const re_string_t *input, Idx idx) internal_function; | 188 | const re_string_t *input, Idx idx) |
189 | internal_function; | ||
169 | # ifdef _LIBC | 190 | # ifdef _LIBC |
170 | static unsigned int find_collation_sequence_value (const unsigned char *mbs, | 191 | static unsigned int find_collation_sequence_value (const unsigned char *mbs, |
171 | size_t name_len) internal_function; | 192 | size_t name_len) |
193 | internal_function; | ||
172 | # endif /* _LIBC */ | 194 | # endif /* _LIBC */ |
173 | #endif /* RE_ENABLE_I18N */ | 195 | #endif /* RE_ENABLE_I18N */ |
174 | static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, | 196 | static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, |
175 | const re_dfastate_t *state, | 197 | const re_dfastate_t *state, |
176 | re_node_set *states_node, | 198 | re_node_set *states_node, |
177 | bitset *states_ch) internal_function; | 199 | bitset_t *states_ch) internal_function; |
178 | static bool check_node_accept (const re_match_context_t *mctx, | 200 | static bool check_node_accept (const re_match_context_t *mctx, |
179 | const re_token_t *node, Idx idx) | 201 | const re_token_t *node, Idx idx) |
180 | internal_function; | 202 | internal_function; |
181 | static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function; | 203 | static reg_errcode_t extend_buffers (re_match_context_t *mctx) |
204 | internal_function; | ||
182 | 205 | ||
183 | /* Entry point for POSIX code. */ | 206 | /* Entry point for POSIX code. */ |
184 | 207 | ||
@@ -197,13 +220,17 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function | |||
197 | We return 0 if we find a match and REG_NOMATCH if not. */ | 220 | We return 0 if we find a match and REG_NOMATCH if not. */ |
198 | 221 | ||
199 | int | 222 | int |
200 | regexec (const regex_t *__restrict preg, const char *__restrict string, | 223 | regexec (preg, string, nmatch, pmatch, eflags) |
201 | size_t nmatch, regmatch_t pmatch[], int eflags) | 224 | const regex_t *__restrict preg; |
225 | const char *__restrict string; | ||
226 | size_t nmatch; | ||
227 | regmatch_t pmatch[]; | ||
228 | int eflags; | ||
202 | { | 229 | { |
203 | reg_errcode_t err; | 230 | reg_errcode_t err; |
204 | Idx start, length; | 231 | Idx start, length; |
205 | #ifdef _LIBC | 232 | #ifdef _LIBC |
206 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 233 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
207 | #endif | 234 | #endif |
208 | 235 | ||
209 | if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) | 236 | if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) |
@@ -221,7 +248,7 @@ regexec (const regex_t *__restrict preg, const char *__restrict string, | |||
221 | } | 248 | } |
222 | 249 | ||
223 | __libc_lock_lock (dfa->lock); | 250 | __libc_lock_lock (dfa->lock); |
224 | if (preg->re_no_sub) | 251 | if (preg->no_sub) |
225 | err = re_search_internal (preg, string, length, start, length, | 252 | err = re_search_internal (preg, string, length, start, length, |
226 | length, 0, NULL, eflags); | 253 | length, 0, NULL, eflags); |
227 | else | 254 | else |
@@ -271,8 +298,8 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); | |||
271 | the first STOP characters of the concatenation of the strings should be | 298 | the first STOP characters of the concatenation of the strings should be |
272 | concerned. | 299 | concerned. |
273 | 300 | ||
274 | If REGS is not NULL, and BUFP->re_no_sub is not set, the offsets of the match | 301 | If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match |
275 | and all groups is stroed in REGS. (For the "_2" variants, the offsets are | 302 | and all groups is stored in REGS. (For the "_2" variants, the offsets are |
276 | computed relative to the concatenation, not relative to the individual | 303 | computed relative to the concatenation, not relative to the individual |
277 | strings.) | 304 | strings.) |
278 | 305 | ||
@@ -281,8 +308,11 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); | |||
281 | match was found and -2 indicates an internal error. */ | 308 | match was found and -2 indicates an internal error. */ |
282 | 309 | ||
283 | regoff_t | 310 | regoff_t |
284 | re_match (struct re_pattern_buffer *bufp, const char *string, | 311 | re_match (bufp, string, length, start, regs) |
285 | Idx length, Idx start, struct re_registers *regs) | 312 | struct re_pattern_buffer *bufp; |
313 | const char *string; | ||
314 | Idx length, start; | ||
315 | struct re_registers *regs; | ||
286 | { | 316 | { |
287 | return re_search_stub (bufp, string, length, start, 0, length, regs, true); | 317 | return re_search_stub (bufp, string, length, start, 0, length, regs, true); |
288 | } | 318 | } |
@@ -291,8 +321,12 @@ weak_alias (__re_match, re_match) | |||
291 | #endif | 321 | #endif |
292 | 322 | ||
293 | regoff_t | 323 | regoff_t |
294 | re_search (struct re_pattern_buffer *bufp, const char *string, | 324 | re_search (bufp, string, length, start, range, regs) |
295 | Idx length, Idx start, regoff_t range, struct re_registers *regs) | 325 | struct re_pattern_buffer *bufp; |
326 | const char *string; | ||
327 | Idx length, start; | ||
328 | regoff_t range; | ||
329 | struct re_registers *regs; | ||
296 | { | 330 | { |
297 | return re_search_stub (bufp, string, length, start, range, length, regs, | 331 | return re_search_stub (bufp, string, length, start, range, length, regs, |
298 | false); | 332 | false); |
@@ -302,10 +336,11 @@ weak_alias (__re_search, re_search) | |||
302 | #endif | 336 | #endif |
303 | 337 | ||
304 | regoff_t | 338 | regoff_t |
305 | re_match_2 (struct re_pattern_buffer *bufp, | 339 | re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) |
306 | const char *string1, Idx length1, | 340 | struct re_pattern_buffer *bufp; |
307 | const char *string2, Idx length2, | 341 | const char *string1, *string2; |
308 | Idx start, struct re_registers *regs, Idx stop) | 342 | Idx length1, length2, start, stop; |
343 | struct re_registers *regs; | ||
309 | { | 344 | { |
310 | return re_search_2_stub (bufp, string1, length1, string2, length2, | 345 | return re_search_2_stub (bufp, string1, length1, string2, length2, |
311 | start, 0, regs, stop, true); | 346 | start, 0, regs, stop, true); |
@@ -315,10 +350,12 @@ weak_alias (__re_match_2, re_match_2) | |||
315 | #endif | 350 | #endif |
316 | 351 | ||
317 | regoff_t | 352 | regoff_t |
318 | re_search_2 (struct re_pattern_buffer *bufp, | 353 | re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) |
319 | const char *string1, Idx length1, | 354 | struct re_pattern_buffer *bufp; |
320 | const char *string2, Idx length2, | 355 | const char *string1, *string2; |
321 | Idx start, regoff_t range, struct re_registers *regs, Idx stop) | 356 | Idx length1, length2, start, stop; |
357 | regoff_t range; | ||
358 | struct re_registers *regs; | ||
322 | { | 359 | { |
323 | return re_search_2_stub (bufp, string1, length1, string2, length2, | 360 | return re_search_2_stub (bufp, string1, length1, string2, length2, |
324 | start, range, regs, stop, false); | 361 | start, range, regs, stop, false); |
@@ -351,8 +388,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp, | |||
351 | 388 | ||
352 | if (BE (s == NULL, 0)) | 389 | if (BE (s == NULL, 0)) |
353 | return -2; | 390 | return -2; |
391 | #ifdef _LIBC | ||
392 | memcpy (__mempcpy (s, string1, length1), string2, length2); | ||
393 | #else | ||
354 | memcpy (s, string1, length1); | 394 | memcpy (s, string1, length1); |
355 | memcpy (s + length1, string2, length2); | 395 | memcpy (s + length1, string2, length2); |
396 | #endif | ||
356 | str = s; | 397 | str = s; |
357 | } | 398 | } |
358 | else | 399 | else |
@@ -384,59 +425,37 @@ re_search_stub (struct re_pattern_buffer *bufp, | |||
384 | regoff_t rval; | 425 | regoff_t rval; |
385 | int eflags = 0; | 426 | int eflags = 0; |
386 | #ifdef _LIBC | 427 | #ifdef _LIBC |
387 | re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; | 428 | re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; |
388 | #endif | 429 | #endif |
389 | Idx last_start = start + range; | 430 | Idx last_start = start + range; |
390 | 431 | ||
391 | /* Check for out-of-range. */ | 432 | /* Check for out-of-range. */ |
392 | if (BE (start < 0 || start > length, 0)) | 433 | if (BE (start < 0 || start > length, 0)) |
393 | return -1; | 434 | return -1; |
394 | if (sizeof start < sizeof range) | 435 | if (BE (length < last_start || (0 <= range && last_start < start), 0)) |
395 | { | 436 | last_start = length; |
396 | regoff_t length_offset = length; | 437 | else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) |
397 | regoff_t start_offset = start; | 438 | last_start = 0; |
398 | if (BE (length_offset - start_offset < range, 0)) | ||
399 | last_start = length; | ||
400 | else if (BE (range < - start_offset, 0)) | ||
401 | last_start = 0; | ||
402 | } | ||
403 | else | ||
404 | { | ||
405 | if (BE ((last_start < start) != (range < 0), 0)) | ||
406 | { | ||
407 | /* Overflow occurred when computing last_start; substitute | ||
408 | the extreme value. */ | ||
409 | last_start = range < 0 ? 0 : length; | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | if (BE (length < last_start, 0)) | ||
414 | last_start = length; | ||
415 | else if (BE (last_start < 0, 0)) | ||
416 | last_start = 0; | ||
417 | } | ||
418 | } | ||
419 | 439 | ||
420 | __libc_lock_lock (dfa->lock); | 440 | __libc_lock_lock (dfa->lock); |
421 | 441 | ||
422 | eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0; | 442 | eflags |= (bufp->not_bol) ? REG_NOTBOL : 0; |
423 | eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0; | 443 | eflags |= (bufp->not_eol) ? REG_NOTEOL : 0; |
424 | 444 | ||
425 | /* Compile fastmap if we haven't yet. */ | 445 | /* Compile fastmap if we haven't yet. */ |
426 | if (start < last_start && bufp->re_fastmap != NULL | 446 | if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) |
427 | && !bufp->re_fastmap_accurate) | ||
428 | re_compile_fastmap (bufp); | 447 | re_compile_fastmap (bufp); |
429 | 448 | ||
430 | if (BE (bufp->re_no_sub, 0)) | 449 | if (BE (bufp->no_sub, 0)) |
431 | regs = NULL; | 450 | regs = NULL; |
432 | 451 | ||
433 | /* We need at least 1 register. */ | 452 | /* We need at least 1 register. */ |
434 | if (regs == NULL) | 453 | if (regs == NULL) |
435 | nregs = 1; | 454 | nregs = 1; |
436 | else if (BE (bufp->re_regs_allocated == REG_FIXED | 455 | else if (BE (bufp->regs_allocated == REGS_FIXED |
437 | && regs->rm_num_regs <= bufp->re_nsub, 0)) | 456 | && regs->num_regs <= bufp->re_nsub, 0)) |
438 | { | 457 | { |
439 | nregs = regs->rm_num_regs; | 458 | nregs = regs->num_regs; |
440 | if (BE (nregs < 1, 0)) | 459 | if (BE (nregs < 1, 0)) |
441 | { | 460 | { |
442 | /* Nothing can be copied to regs. */ | 461 | /* Nothing can be copied to regs. */ |
@@ -446,7 +465,7 @@ re_search_stub (struct re_pattern_buffer *bufp, | |||
446 | } | 465 | } |
447 | else | 466 | else |
448 | nregs = bufp->re_nsub + 1; | 467 | nregs = bufp->re_nsub + 1; |
449 | pmatch = re_xmalloc (regmatch_t, nregs); | 468 | pmatch = re_malloc (regmatch_t, nregs); |
450 | if (BE (pmatch == NULL, 0)) | 469 | if (BE (pmatch == NULL, 0)) |
451 | { | 470 | { |
452 | rval = -2; | 471 | rval = -2; |
@@ -464,9 +483,9 @@ re_search_stub (struct re_pattern_buffer *bufp, | |||
464 | else if (regs != NULL) | 483 | else if (regs != NULL) |
465 | { | 484 | { |
466 | /* If caller wants register contents data back, copy them. */ | 485 | /* If caller wants register contents data back, copy them. */ |
467 | bufp->re_regs_allocated = re_copy_regs (regs, pmatch, nregs, | 486 | bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, |
468 | bufp->re_regs_allocated); | 487 | bufp->regs_allocated); |
469 | if (BE (bufp->re_regs_allocated == REG_UNALLOCATED, 0)) | 488 | if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) |
470 | rval = -2; | 489 | rval = -2; |
471 | } | 490 | } |
472 | 491 | ||
@@ -486,58 +505,68 @@ re_search_stub (struct re_pattern_buffer *bufp, | |||
486 | return rval; | 505 | return rval; |
487 | } | 506 | } |
488 | 507 | ||
489 | static unsigned | 508 | static unsigned int |
490 | internal_function | 509 | internal_function |
491 | re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, | 510 | re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, |
492 | int regs_allocated) | 511 | int regs_allocated) |
493 | { | 512 | { |
494 | int rval = REG_REALLOCATE; | 513 | int rval = REGS_REALLOCATE; |
495 | Idx i; | 514 | Idx i; |
496 | Idx need_regs = nregs + 1; | 515 | Idx need_regs = nregs + 1; |
497 | /* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code | 516 | /* We need one extra element beyond `num_regs' for the `-1' marker GNU code |
498 | uses. */ | 517 | uses. */ |
499 | 518 | ||
500 | /* Have the register data arrays been allocated? */ | 519 | /* Have the register data arrays been allocated? */ |
501 | if (regs_allocated == REG_UNALLOCATED) | 520 | if (regs_allocated == REGS_UNALLOCATED) |
502 | { /* No. So allocate them with malloc. */ | 521 | { /* No. So allocate them with malloc. */ |
503 | regs->rm_start = re_xmalloc (regoff_t, need_regs); | 522 | regs->start = re_malloc (regoff_t, need_regs); |
504 | regs->rm_end = re_malloc (regoff_t, need_regs); | 523 | if (BE (regs->start == NULL, 0)) |
505 | if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0)) | 524 | return REGS_UNALLOCATED; |
506 | return REG_UNALLOCATED; | 525 | regs->end = re_malloc (regoff_t, need_regs); |
507 | regs->rm_num_regs = need_regs; | 526 | if (BE (regs->end == NULL, 0)) |
527 | { | ||
528 | re_free (regs->start); | ||
529 | return REGS_UNALLOCATED; | ||
530 | } | ||
531 | regs->num_regs = need_regs; | ||
508 | } | 532 | } |
509 | else if (regs_allocated == REG_REALLOCATE) | 533 | else if (regs_allocated == REGS_REALLOCATE) |
510 | { /* Yes. If we need more elements than were already | 534 | { /* Yes. If we need more elements than were already |
511 | allocated, reallocate them. If we need fewer, just | 535 | allocated, reallocate them. If we need fewer, just |
512 | leave it alone. */ | 536 | leave it alone. */ |
513 | if (BE (need_regs > regs->rm_num_regs, 0)) | 537 | if (BE (need_regs > regs->num_regs, 0)) |
514 | { | 538 | { |
515 | regoff_t *new_start = | 539 | regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); |
516 | re_xrealloc (regs->rm_start, regoff_t, need_regs); | 540 | regoff_t *new_end; |
517 | regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs); | 541 | if (BE (new_start == NULL, 0)) |
518 | if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0)) | 542 | return REGS_UNALLOCATED; |
519 | return REG_UNALLOCATED; | 543 | new_end = re_realloc (regs->end, regoff_t, need_regs); |
520 | regs->rm_start = new_start; | 544 | if (BE (new_end == NULL, 0)) |
521 | regs->rm_end = new_end; | 545 | { |
522 | regs->rm_num_regs = need_regs; | 546 | re_free (new_start); |
547 | return REGS_UNALLOCATED; | ||
548 | } | ||
549 | regs->start = new_start; | ||
550 | regs->end = new_end; | ||
551 | regs->num_regs = need_regs; | ||
523 | } | 552 | } |
524 | } | 553 | } |
525 | else | 554 | else |
526 | { | 555 | { |
527 | assert (regs_allocated == REG_FIXED); | 556 | assert (regs_allocated == REGS_FIXED); |
528 | /* This function may not be called with REG_FIXED and nregs too big. */ | 557 | /* This function may not be called with REGS_FIXED and nregs too big. */ |
529 | assert (regs->rm_num_regs >= nregs); | 558 | assert (regs->num_regs >= nregs); |
530 | rval = REG_FIXED; | 559 | rval = REGS_FIXED; |
531 | } | 560 | } |
532 | 561 | ||
533 | /* Copy the regs. */ | 562 | /* Copy the regs. */ |
534 | for (i = 0; i < nregs; ++i) | 563 | for (i = 0; i < nregs; ++i) |
535 | { | 564 | { |
536 | regs->rm_start[i] = pmatch[i].rm_so; | 565 | regs->start[i] = pmatch[i].rm_so; |
537 | regs->rm_end[i] = pmatch[i].rm_eo; | 566 | regs->end[i] = pmatch[i].rm_eo; |
538 | } | 567 | } |
539 | for ( ; i < regs->rm_num_regs; ++i) | 568 | for ( ; i < regs->num_regs; ++i) |
540 | regs->rm_start[i] = regs->rm_end[i] = -1; | 569 | regs->start[i] = regs->end[i] = -1; |
541 | 570 | ||
542 | return rval; | 571 | return rval; |
543 | } | 572 | } |
@@ -556,21 +585,24 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, | |||
556 | freeing the old data. */ | 585 | freeing the old data. */ |
557 | 586 | ||
558 | void | 587 | void |
559 | re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, | 588 | re_set_registers (bufp, regs, num_regs, starts, ends) |
560 | __re_size_t num_regs, regoff_t *starts, regoff_t *ends) | 589 | struct re_pattern_buffer *bufp; |
590 | struct re_registers *regs; | ||
591 | __re_size_t num_regs; | ||
592 | regoff_t *starts, *ends; | ||
561 | { | 593 | { |
562 | if (num_regs) | 594 | if (num_regs) |
563 | { | 595 | { |
564 | bufp->re_regs_allocated = REG_REALLOCATE; | 596 | bufp->regs_allocated = REGS_REALLOCATE; |
565 | regs->rm_num_regs = num_regs; | 597 | regs->num_regs = num_regs; |
566 | regs->rm_start = starts; | 598 | regs->start = starts; |
567 | regs->rm_end = ends; | 599 | regs->end = ends; |
568 | } | 600 | } |
569 | else | 601 | else |
570 | { | 602 | { |
571 | bufp->re_regs_allocated = REG_UNALLOCATED; | 603 | bufp->regs_allocated = REGS_UNALLOCATED; |
572 | regs->rm_num_regs = 0; | 604 | regs->num_regs = 0; |
573 | regs->rm_start = regs->rm_end = NULL; | 605 | regs->start = regs->end = NULL; |
574 | } | 606 | } |
575 | } | 607 | } |
576 | #ifdef _LIBC | 608 | #ifdef _LIBC |
@@ -585,7 +617,8 @@ int | |||
585 | # ifdef _LIBC | 617 | # ifdef _LIBC |
586 | weak_function | 618 | weak_function |
587 | # endif | 619 | # endif |
588 | re_exec (const char *s) | 620 | re_exec (s) |
621 | const char *s; | ||
589 | { | 622 | { |
590 | return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); | 623 | return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); |
591 | } | 624 | } |
@@ -611,12 +644,13 @@ re_search_internal (const regex_t *preg, | |||
611 | int eflags) | 644 | int eflags) |
612 | { | 645 | { |
613 | reg_errcode_t err; | 646 | reg_errcode_t err; |
614 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 647 | const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; |
615 | Idx left_lim, right_lim; | 648 | Idx left_lim, right_lim; |
616 | int incr; | 649 | int incr; |
617 | bool fl_longest_match; | 650 | bool fl_longest_match; |
618 | int match_kind; | 651 | int match_kind; |
619 | Idx match_first, match_last = REG_MISSING; | 652 | Idx match_first; |
653 | Idx match_last = REG_MISSING; | ||
620 | Idx extra_nmatch; | 654 | Idx extra_nmatch; |
621 | bool sb; | 655 | bool sb; |
622 | int ch; | 656 | int ch; |
@@ -625,11 +659,10 @@ re_search_internal (const regex_t *preg, | |||
625 | #else | 659 | #else |
626 | re_match_context_t mctx; | 660 | re_match_context_t mctx; |
627 | #endif | 661 | #endif |
628 | char *fastmap = ((preg->re_fastmap != NULL && preg->re_fastmap_accurate | 662 | char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate |
629 | && start != last_start && !preg->re_can_be_null) | 663 | && start != last_start && !preg->can_be_null) |
630 | ? preg->re_fastmap : NULL); | 664 | ? preg->fastmap : NULL); |
631 | unsigned REG_TRANSLATE_TYPE t = | 665 | RE_TRANSLATE_TYPE t = preg->translate; |
632 | (unsigned REG_TRANSLATE_TYPE) preg->re_translate; | ||
633 | 666 | ||
634 | #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) | 667 | #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) |
635 | memset (&mctx, '\0', sizeof (re_match_context_t)); | 668 | memset (&mctx, '\0', sizeof (re_match_context_t)); |
@@ -640,7 +673,7 @@ re_search_internal (const regex_t *preg, | |||
640 | nmatch -= extra_nmatch; | 673 | nmatch -= extra_nmatch; |
641 | 674 | ||
642 | /* Check if the DFA haven't been compiled. */ | 675 | /* Check if the DFA haven't been compiled. */ |
643 | if (BE (preg->re_used == 0 || dfa->init_state == NULL | 676 | if (BE (preg->used == 0 || dfa->init_state == NULL |
644 | || dfa->init_state_word == NULL || dfa->init_state_nl == NULL | 677 | || dfa->init_state_word == NULL || dfa->init_state_nl == NULL |
645 | || dfa->init_state_begbuf == NULL, 0)) | 678 | || dfa->init_state_begbuf == NULL, 0)) |
646 | return REG_NOMATCH; | 679 | return REG_NOMATCH; |
@@ -651,12 +684,12 @@ re_search_internal (const regex_t *preg, | |||
651 | #endif | 684 | #endif |
652 | 685 | ||
653 | /* If initial states with non-begbuf contexts have no elements, | 686 | /* If initial states with non-begbuf contexts have no elements, |
654 | the regex must be anchored. If preg->re_newline_anchor is set, | 687 | the regex must be anchored. If preg->newline_anchor is set, |
655 | we'll never use init_state_nl, so do not check it. */ | 688 | we'll never use init_state_nl, so do not check it. */ |
656 | if (dfa->init_state->nodes.nelem == 0 | 689 | if (dfa->init_state->nodes.nelem == 0 |
657 | && dfa->init_state_word->nodes.nelem == 0 | 690 | && dfa->init_state_word->nodes.nelem == 0 |
658 | && (dfa->init_state_nl->nodes.nelem == 0 | 691 | && (dfa->init_state_nl->nodes.nelem == 0 |
659 | || !preg->re_newline_anchor)) | 692 | || !preg->newline_anchor)) |
660 | { | 693 | { |
661 | if (start != 0 && last_start != 0) | 694 | if (start != 0 && last_start != 0) |
662 | return REG_NOMATCH; | 695 | return REG_NOMATCH; |
@@ -667,13 +700,12 @@ re_search_internal (const regex_t *preg, | |||
667 | fl_longest_match = (nmatch != 0 || dfa->nbackref); | 700 | fl_longest_match = (nmatch != 0 || dfa->nbackref); |
668 | 701 | ||
669 | err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, | 702 | err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, |
670 | preg->re_translate, | 703 | preg->translate, preg->syntax & RE_ICASE, dfa); |
671 | preg->re_syntax & REG_IGNORE_CASE, dfa); | ||
672 | if (BE (err != REG_NOERROR, 0)) | 704 | if (BE (err != REG_NOERROR, 0)) |
673 | goto free_return; | 705 | goto free_return; |
674 | mctx.input.stop = stop; | 706 | mctx.input.stop = stop; |
675 | mctx.input.raw_stop = stop; | 707 | mctx.input.raw_stop = stop; |
676 | mctx.input.newline_anchor = preg->re_newline_anchor; | 708 | mctx.input.newline_anchor = preg->newline_anchor; |
677 | 709 | ||
678 | err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); | 710 | err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); |
679 | if (BE (err != REG_NOERROR, 0)) | 711 | if (BE (err != REG_NOERROR, 0)) |
@@ -685,7 +717,14 @@ re_search_internal (const regex_t *preg, | |||
685 | multi character collating element. */ | 717 | multi character collating element. */ |
686 | if (nmatch > 1 || dfa->has_mb_node) | 718 | if (nmatch > 1 || dfa->has_mb_node) |
687 | { | 719 | { |
688 | mctx.state_log = re_xmalloc (re_dfastate_t *, mctx.input.bufs_len + 1); | 720 | /* Avoid overflow. */ |
721 | if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0)) | ||
722 | { | ||
723 | err = REG_ESPACE; | ||
724 | goto free_return; | ||
725 | } | ||
726 | |||
727 | mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); | ||
689 | if (BE (mctx.state_log == NULL, 0)) | 728 | if (BE (mctx.state_log == NULL, 0)) |
690 | { | 729 | { |
691 | err = REG_ESPACE; | 730 | err = REG_ESPACE; |
@@ -706,7 +745,7 @@ re_search_internal (const regex_t *preg, | |||
706 | sb = dfa->mb_cur_max == 1; | 745 | sb = dfa->mb_cur_max == 1; |
707 | match_kind = | 746 | match_kind = |
708 | (fastmap | 747 | (fastmap |
709 | ? ((sb || !(preg->re_syntax & REG_IGNORE_CASE || t) ? 4 : 0) | 748 | ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0) |
710 | | (start <= last_start ? 2 : 0) | 749 | | (start <= last_start ? 2 : 0) |
711 | | (t != NULL ? 1 : 0)) | 750 | | (t != NULL ? 1 : 0)) |
712 | : 8); | 751 | : 8); |
@@ -828,13 +867,13 @@ re_search_internal (const regex_t *preg, | |||
828 | else | 867 | else |
829 | { | 868 | { |
830 | mctx.match_last = match_last; | 869 | mctx.match_last = match_last; |
831 | if ((!preg->re_no_sub && nmatch > 1) || dfa->nbackref) | 870 | if ((!preg->no_sub && nmatch > 1) || dfa->nbackref) |
832 | { | 871 | { |
833 | re_dfastate_t *pstate = mctx.state_log[match_last]; | 872 | re_dfastate_t *pstate = mctx.state_log[match_last]; |
834 | mctx.last_node = check_halt_state_context (&mctx, pstate, | 873 | mctx.last_node = check_halt_state_context (&mctx, pstate, |
835 | match_last); | 874 | match_last); |
836 | } | 875 | } |
837 | if ((!preg->re_no_sub && nmatch > 1 && dfa->has_plural_match) | 876 | if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match) |
838 | || dfa->nbackref) | 877 | || dfa->nbackref) |
839 | { | 878 | { |
840 | err = prune_impossible_nodes (&mctx); | 879 | err = prune_impossible_nodes (&mctx); |
@@ -873,7 +912,7 @@ re_search_internal (const regex_t *preg, | |||
873 | the maximum possible regoff_t value. We need a new error | 912 | the maximum possible regoff_t value. We need a new error |
874 | code REG_OVERFLOW. */ | 913 | code REG_OVERFLOW. */ |
875 | 914 | ||
876 | if (!preg->re_no_sub && nmatch > 1) | 915 | if (!preg->no_sub && nmatch > 1) |
877 | { | 916 | { |
878 | err = set_regs (preg, &mctx, nmatch, pmatch, | 917 | err = set_regs (preg, &mctx, nmatch, pmatch, |
879 | dfa->has_plural_match && dfa->nbackref > 0); | 918 | dfa->has_plural_match && dfa->nbackref > 0); |
@@ -934,7 +973,7 @@ static reg_errcode_t | |||
934 | internal_function | 973 | internal_function |
935 | prune_impossible_nodes (re_match_context_t *mctx) | 974 | prune_impossible_nodes (re_match_context_t *mctx) |
936 | { | 975 | { |
937 | re_dfa_t *const dfa = mctx->dfa; | 976 | const re_dfa_t *const dfa = mctx->dfa; |
938 | Idx halt_node, match_last; | 977 | Idx halt_node, match_last; |
939 | reg_errcode_t ret; | 978 | reg_errcode_t ret; |
940 | re_dfastate_t **sifted_states; | 979 | re_dfastate_t **sifted_states; |
@@ -945,7 +984,12 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
945 | #endif | 984 | #endif |
946 | match_last = mctx->match_last; | 985 | match_last = mctx->match_last; |
947 | halt_node = mctx->last_node; | 986 | halt_node = mctx->last_node; |
948 | sifted_states = re_xmalloc (re_dfastate_t *, match_last + 1); | 987 | |
988 | /* Avoid overflow. */ | ||
989 | if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0)) | ||
990 | return REG_ESPACE; | ||
991 | |||
992 | sifted_states = re_malloc (re_dfastate_t *, match_last + 1); | ||
949 | if (BE (sifted_states == NULL, 0)) | 993 | if (BE (sifted_states == NULL, 0)) |
950 | { | 994 | { |
951 | ret = REG_ESPACE; | 995 | ret = REG_ESPACE; |
@@ -953,7 +997,7 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
953 | } | 997 | } |
954 | if (dfa->nbackref) | 998 | if (dfa->nbackref) |
955 | { | 999 | { |
956 | lim_states = re_xmalloc (re_dfastate_t *, match_last + 1); | 1000 | lim_states = re_malloc (re_dfastate_t *, match_last + 1); |
957 | if (BE (lim_states == NULL, 0)) | 1001 | if (BE (lim_states == NULL, 0)) |
958 | { | 1002 | { |
959 | ret = REG_ESPACE; | 1003 | ret = REG_ESPACE; |
@@ -1021,7 +1065,7 @@ __attribute ((always_inline)) internal_function | |||
1021 | acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, | 1065 | acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, |
1022 | Idx idx) | 1066 | Idx idx) |
1023 | { | 1067 | { |
1024 | re_dfa_t *const dfa = mctx->dfa; | 1068 | const re_dfa_t *const dfa = mctx->dfa; |
1025 | if (dfa->init_state->has_constraint) | 1069 | if (dfa->init_state->has_constraint) |
1026 | { | 1070 | { |
1027 | unsigned int context; | 1071 | unsigned int context; |
@@ -1063,7 +1107,7 @@ internal_function | |||
1063 | check_matching (re_match_context_t *mctx, bool fl_longest_match, | 1107 | check_matching (re_match_context_t *mctx, bool fl_longest_match, |
1064 | Idx *p_match_first) | 1108 | Idx *p_match_first) |
1065 | { | 1109 | { |
1066 | re_dfa_t *const dfa = mctx->dfa; | 1110 | const re_dfa_t *const dfa = mctx->dfa; |
1067 | reg_errcode_t err; | 1111 | reg_errcode_t err; |
1068 | Idx match = 0; | 1112 | Idx match = 0; |
1069 | Idx match_last = REG_MISSING; | 1113 | Idx match_last = REG_MISSING; |
@@ -1233,11 +1277,11 @@ check_halt_state_context (const re_match_context_t *mctx, | |||
1233 | 1277 | ||
1234 | static Idx | 1278 | static Idx |
1235 | internal_function | 1279 | internal_function |
1236 | proceed_next_node (const re_match_context_t *mctx, | 1280 | proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, |
1237 | Idx nregs, regmatch_t *regs, Idx *pidx, Idx node, | 1281 | Idx *pidx, Idx node, re_node_set *eps_via_nodes, |
1238 | re_node_set *eps_via_nodes, struct re_fail_stack_t *fs) | 1282 | struct re_fail_stack_t *fs) |
1239 | { | 1283 | { |
1240 | re_dfa_t *const dfa = mctx->dfa; | 1284 | const re_dfa_t *const dfa = mctx->dfa; |
1241 | Idx i; | 1285 | Idx i; |
1242 | bool ok; | 1286 | bool ok; |
1243 | if (IS_EPSILON_NODE (dfa->nodes[node].type)) | 1287 | 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, | |||
1342 | Idx num = fs->num++; | 1386 | Idx num = fs->num++; |
1343 | if (fs->num == fs->alloc) | 1387 | if (fs->num == fs->alloc) |
1344 | { | 1388 | { |
1345 | struct re_fail_stack_ent_t *new_array = | 1389 | struct re_fail_stack_ent_t *new_array; |
1346 | re_x2realloc (fs->stack, struct re_fail_stack_ent_t, &fs->alloc); | 1390 | new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) |
1391 | * fs->alloc * 2)); | ||
1347 | if (new_array == NULL) | 1392 | if (new_array == NULL) |
1348 | return REG_ESPACE; | 1393 | return REG_ESPACE; |
1394 | fs->alloc *= 2; | ||
1349 | fs->stack = new_array; | 1395 | fs->stack = new_array; |
1350 | } | 1396 | } |
1351 | fs->stack[num].idx = str_idx; | 1397 | fs->stack[num].idx = str_idx; |
1352 | fs->stack[num].node = dest_node; | 1398 | fs->stack[num].node = dest_node; |
1353 | fs->stack[num].regs = re_xmalloc (regmatch_t, nregs); | 1399 | fs->stack[num].regs = re_malloc (regmatch_t, nregs); |
1354 | if (fs->stack[num].regs == NULL) | 1400 | if (fs->stack[num].regs == NULL) |
1355 | return REG_ESPACE; | 1401 | return REG_ESPACE; |
1356 | memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); | 1402 | 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, | |||
1360 | 1406 | ||
1361 | static Idx | 1407 | static Idx |
1362 | internal_function | 1408 | internal_function |
1363 | pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, | 1409 | pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, |
1364 | Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes) | 1410 | regmatch_t *regs, re_node_set *eps_via_nodes) |
1365 | { | 1411 | { |
1366 | Idx num = --fs->num; | 1412 | Idx num = --fs->num; |
1367 | assert (REG_VALID_INDEX (num)); | 1413 | assert (REG_VALID_INDEX (num)); |
@@ -1380,10 +1426,10 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, | |||
1380 | 1426 | ||
1381 | static reg_errcode_t | 1427 | static reg_errcode_t |
1382 | internal_function | 1428 | internal_function |
1383 | set_regs (const regex_t *preg, const re_match_context_t *mctx, | 1429 | set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, |
1384 | size_t nmatch, regmatch_t *pmatch, bool fl_backtrack) | 1430 | regmatch_t *pmatch, bool fl_backtrack) |
1385 | { | 1431 | { |
1386 | re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; | 1432 | const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; |
1387 | Idx idx, cur_node; | 1433 | Idx idx, cur_node; |
1388 | re_node_set eps_via_nodes; | 1434 | re_node_set eps_via_nodes; |
1389 | struct re_fail_stack_t *fs; | 1435 | struct re_fail_stack_t *fs; |
@@ -1398,7 +1444,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, | |||
1398 | if (fl_backtrack) | 1444 | if (fl_backtrack) |
1399 | { | 1445 | { |
1400 | fs = &fs_body; | 1446 | fs = &fs_body; |
1401 | fs->stack = re_xmalloc (struct re_fail_stack_ent_t, fs->alloc); | 1447 | fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc); |
1402 | if (fs->stack == NULL) | 1448 | if (fs->stack == NULL) |
1403 | return REG_ESPACE; | 1449 | return REG_ESPACE; |
1404 | } | 1450 | } |
@@ -1408,11 +1454,6 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, | |||
1408 | cur_node = dfa->init_node; | 1454 | cur_node = dfa->init_node; |
1409 | re_node_set_init_empty (&eps_via_nodes); | 1455 | re_node_set_init_empty (&eps_via_nodes); |
1410 | 1456 | ||
1411 | if (re_alloc_oversized (nmatch, sizeof (regmatch_t))) | ||
1412 | { | ||
1413 | free_fail_stack_return (fs); | ||
1414 | return REG_ESPACE; | ||
1415 | } | ||
1416 | if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) | 1457 | if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) |
1417 | prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); | 1458 | prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); |
1418 | else | 1459 | else |
@@ -1509,8 +1550,8 @@ free_fail_stack_return (struct re_fail_stack_t *fs) | |||
1509 | 1550 | ||
1510 | static void | 1551 | static void |
1511 | internal_function | 1552 | internal_function |
1512 | update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, | 1553 | update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, |
1513 | Idx cur_node, Idx cur_idx, Idx nmatch) | 1554 | regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) |
1514 | { | 1555 | { |
1515 | int type = dfa->nodes[cur_node].type; | 1556 | int type = dfa->nodes[cur_node].type; |
1516 | if (type == OP_OPEN_SUBEXP) | 1557 | if (type == OP_OPEN_SUBEXP) |
@@ -1581,7 +1622,7 @@ update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, | |||
1581 | 1622 | ||
1582 | static reg_errcode_t | 1623 | static reg_errcode_t |
1583 | internal_function | 1624 | internal_function |
1584 | sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx) | 1625 | sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) |
1585 | { | 1626 | { |
1586 | reg_errcode_t err; | 1627 | reg_errcode_t err; |
1587 | int null_cnt = 0; | 1628 | int null_cnt = 0; |
@@ -1639,11 +1680,11 @@ sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx) | |||
1639 | 1680 | ||
1640 | static reg_errcode_t | 1681 | static reg_errcode_t |
1641 | internal_function | 1682 | internal_function |
1642 | build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx, | 1683 | build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, |
1643 | Idx str_idx, re_node_set *cur_dest) | 1684 | Idx str_idx, re_node_set *cur_dest) |
1644 | { | 1685 | { |
1645 | re_dfa_t *const dfa = mctx->dfa; | 1686 | const re_dfa_t *const dfa = mctx->dfa; |
1646 | re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; | 1687 | const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; |
1647 | Idx i; | 1688 | Idx i; |
1648 | 1689 | ||
1649 | /* Then build the next sifted state. | 1690 | /* 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) | |||
1726 | 1767 | ||
1727 | static reg_errcode_t | 1768 | static reg_errcode_t |
1728 | internal_function | 1769 | internal_function |
1729 | merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, | 1770 | merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, |
1730 | Idx num) | 1771 | re_dfastate_t **src, Idx num) |
1731 | { | 1772 | { |
1732 | Idx st_idx; | 1773 | Idx st_idx; |
1733 | reg_errcode_t err; | 1774 | reg_errcode_t err; |
@@ -1753,11 +1794,12 @@ merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, | |||
1753 | 1794 | ||
1754 | static reg_errcode_t | 1795 | static reg_errcode_t |
1755 | internal_function | 1796 | internal_function |
1756 | update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx, | 1797 | update_cur_sifted_state (const re_match_context_t *mctx, |
1757 | Idx str_idx, re_node_set *dest_nodes) | 1798 | re_sift_context_t *sctx, Idx str_idx, |
1799 | re_node_set *dest_nodes) | ||
1758 | { | 1800 | { |
1759 | re_dfa_t *const dfa = mctx->dfa; | 1801 | const re_dfa_t *const dfa = mctx->dfa; |
1760 | reg_errcode_t err; | 1802 | reg_errcode_t err = REG_NOERROR; |
1761 | const re_node_set *candidates; | 1803 | const re_node_set *candidates; |
1762 | candidates = ((mctx->state_log[str_idx] == NULL) ? NULL | 1804 | candidates = ((mctx->state_log[str_idx] == NULL) ? NULL |
1763 | : &mctx->state_log[str_idx]->nodes); | 1805 | : &mctx->state_log[str_idx]->nodes); |
@@ -1800,7 +1842,7 @@ update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx, | |||
1800 | 1842 | ||
1801 | static reg_errcode_t | 1843 | static reg_errcode_t |
1802 | internal_function | 1844 | internal_function |
1803 | add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes, | 1845 | add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, |
1804 | const re_node_set *candidates) | 1846 | const re_node_set *candidates) |
1805 | { | 1847 | { |
1806 | reg_errcode_t err = REG_NOERROR; | 1848 | reg_errcode_t err = REG_NOERROR; |
@@ -1825,7 +1867,7 @@ add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes, | |||
1825 | 1867 | ||
1826 | static reg_errcode_t | 1868 | static reg_errcode_t |
1827 | internal_function | 1869 | internal_function |
1828 | sub_epsilon_src_nodes (re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, | 1870 | sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, |
1829 | const re_node_set *candidates) | 1871 | const re_node_set *candidates) |
1830 | { | 1872 | { |
1831 | Idx ecl_idx; | 1873 | Idx ecl_idx; |
@@ -1877,7 +1919,7 @@ internal_function | |||
1877 | check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, | 1919 | check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, |
1878 | Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) | 1920 | Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) |
1879 | { | 1921 | { |
1880 | re_dfa_t *const dfa = mctx->dfa; | 1922 | const re_dfa_t *const dfa = mctx->dfa; |
1881 | Idx lim_idx, src_pos, dst_pos; | 1923 | Idx lim_idx, src_pos, dst_pos; |
1882 | 1924 | ||
1883 | Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx); | 1925 | Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx); |
@@ -1913,8 +1955,8 @@ internal_function | |||
1913 | check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, | 1955 | check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, |
1914 | Idx subexp_idx, Idx from_node, Idx bkref_idx) | 1956 | Idx subexp_idx, Idx from_node, Idx bkref_idx) |
1915 | { | 1957 | { |
1916 | re_dfa_t *const dfa = mctx->dfa; | 1958 | const re_dfa_t *const dfa = mctx->dfa; |
1917 | re_node_set *eclosures = dfa->eclosures + from_node; | 1959 | const re_node_set *eclosures = dfa->eclosures + from_node; |
1918 | Idx node_idx; | 1960 | Idx node_idx; |
1919 | 1961 | ||
1920 | /* Else, we are on the boundary: examine the nodes on the epsilon | 1962 | /* 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, | |||
1938 | 1980 | ||
1939 | if (subexp_idx < BITSET_WORD_BITS | 1981 | if (subexp_idx < BITSET_WORD_BITS |
1940 | && !(ent->eps_reachable_subexps_map | 1982 | && !(ent->eps_reachable_subexps_map |
1941 | & ((bitset_word) 1 << subexp_idx))) | 1983 | & ((bitset_word_t) 1 << subexp_idx))) |
1942 | continue; | 1984 | continue; |
1943 | 1985 | ||
1944 | /* Recurse trying to reach the OP_OPEN_SUBEXP and | 1986 | /* 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, | |||
1965 | return 0; | 2007 | return 0; |
1966 | 2008 | ||
1967 | if (subexp_idx < BITSET_WORD_BITS) | 2009 | if (subexp_idx < BITSET_WORD_BITS) |
1968 | ent->eps_reachable_subexps_map &= | 2010 | ent->eps_reachable_subexps_map |
1969 | ~ ((bitset_word) 1 << subexp_idx); | 2011 | &= ~((bitset_word_t) 1 << subexp_idx); |
1970 | } | 2012 | } |
1971 | while (ent++->more); | 2013 | while (ent++->more); |
1972 | } | 2014 | } |
@@ -1992,9 +2034,9 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, | |||
1992 | 2034 | ||
1993 | static int | 2035 | static int |
1994 | internal_function | 2036 | internal_function |
1995 | check_dst_limits_calc_pos (const re_match_context_t *mctx, | 2037 | check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, |
1996 | Idx limit, Idx subexp_idx, | 2038 | Idx subexp_idx, Idx from_node, Idx str_idx, |
1997 | Idx from_node, Idx str_idx, Idx bkref_idx) | 2039 | Idx bkref_idx) |
1998 | { | 2040 | { |
1999 | struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; | 2041 | struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; |
2000 | int boundaries; | 2042 | int boundaries; |
@@ -2022,7 +2064,7 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx, | |||
2022 | 2064 | ||
2023 | static reg_errcode_t | 2065 | static reg_errcode_t |
2024 | internal_function | 2066 | internal_function |
2025 | check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes, | 2067 | check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, |
2026 | const re_node_set *candidates, re_node_set *limits, | 2068 | const re_node_set *candidates, re_node_set *limits, |
2027 | struct re_backref_cache_entry *bkref_ents, Idx str_idx) | 2069 | struct re_backref_cache_entry *bkref_ents, Idx str_idx) |
2028 | { | 2070 | { |
@@ -2110,10 +2152,10 @@ check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes, | |||
2110 | 2152 | ||
2111 | static reg_errcode_t | 2153 | static reg_errcode_t |
2112 | internal_function | 2154 | internal_function |
2113 | sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, | 2155 | sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, |
2114 | Idx str_idx, const re_node_set *candidates) | 2156 | Idx str_idx, const re_node_set *candidates) |
2115 | { | 2157 | { |
2116 | re_dfa_t *const dfa = mctx->dfa; | 2158 | const re_dfa_t *const dfa = mctx->dfa; |
2117 | reg_errcode_t err; | 2159 | reg_errcode_t err; |
2118 | Idx node_idx, node; | 2160 | Idx node_idx, node; |
2119 | re_sift_context_t local_sctx; | 2161 | re_sift_context_t local_sctx; |
@@ -2141,8 +2183,10 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, | |||
2141 | enabled_idx = first_idx; | 2183 | enabled_idx = first_idx; |
2142 | do | 2184 | do |
2143 | { | 2185 | { |
2186 | Idx subexp_len; | ||
2187 | Idx to_idx; | ||
2188 | Idx dst_node; | ||
2144 | bool ok; | 2189 | bool ok; |
2145 | Idx subexp_len, to_idx, dst_node; | ||
2146 | re_dfastate_t *cur_state; | 2190 | re_dfastate_t *cur_state; |
2147 | 2191 | ||
2148 | if (entry->node != node) | 2192 | if (entry->node != node) |
@@ -2211,7 +2255,7 @@ internal_function | |||
2211 | sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, | 2255 | sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, |
2212 | Idx node_idx, Idx str_idx, Idx max_str_idx) | 2256 | Idx node_idx, Idx str_idx, Idx max_str_idx) |
2213 | { | 2257 | { |
2214 | re_dfa_t *const dfa = mctx->dfa; | 2258 | const re_dfa_t *const dfa = mctx->dfa; |
2215 | int naccepted; | 2259 | int naccepted; |
2216 | /* Check the node can accept `multi byte'. */ | 2260 | /* Check the node can accept `multi byte'. */ |
2217 | naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); | 2261 | naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); |
@@ -2299,7 +2343,7 @@ internal_function | |||
2299 | merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, | 2343 | merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, |
2300 | re_dfastate_t *next_state) | 2344 | re_dfastate_t *next_state) |
2301 | { | 2345 | { |
2302 | re_dfa_t *const dfa = mctx->dfa; | 2346 | const re_dfa_t *const dfa = mctx->dfa; |
2303 | Idx cur_idx = re_string_cur_idx (&mctx->input); | 2347 | Idx cur_idx = re_string_cur_idx (&mctx->input); |
2304 | 2348 | ||
2305 | if (cur_idx > mctx->state_log_top) | 2349 | if (cur_idx > mctx->state_log_top) |
@@ -2377,7 +2421,7 @@ static re_dfastate_t * | |||
2377 | internal_function | 2421 | internal_function |
2378 | find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) | 2422 | find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) |
2379 | { | 2423 | { |
2380 | re_dfastate_t *cur_state = NULL; | 2424 | re_dfastate_t *cur_state; |
2381 | do | 2425 | do |
2382 | { | 2426 | { |
2383 | Idx max = mctx->state_log_top; | 2427 | Idx max = mctx->state_log_top; |
@@ -2409,7 +2453,7 @@ internal_function | |||
2409 | check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, | 2453 | check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, |
2410 | Idx str_idx) | 2454 | Idx str_idx) |
2411 | { | 2455 | { |
2412 | re_dfa_t *const dfa = mctx->dfa; | 2456 | const re_dfa_t *const dfa = mctx->dfa; |
2413 | Idx node_idx; | 2457 | Idx node_idx; |
2414 | reg_errcode_t err; | 2458 | reg_errcode_t err; |
2415 | 2459 | ||
@@ -2424,7 +2468,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
2424 | if (dfa->nodes[node].type == OP_OPEN_SUBEXP | 2468 | if (dfa->nodes[node].type == OP_OPEN_SUBEXP |
2425 | && dfa->nodes[node].opr.idx < BITSET_WORD_BITS | 2469 | && dfa->nodes[node].opr.idx < BITSET_WORD_BITS |
2426 | && (dfa->used_bkref_map | 2470 | && (dfa->used_bkref_map |
2427 | & ((bitset_word) 1 << dfa->nodes[node].opr.idx))) | 2471 | & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) |
2428 | { | 2472 | { |
2429 | err = match_ctx_add_subtop (mctx, node, str_idx); | 2473 | err = match_ctx_add_subtop (mctx, node, str_idx); |
2430 | if (BE (err != REG_NOERROR, 0)) | 2474 | if (BE (err != REG_NOERROR, 0)) |
@@ -2442,7 +2486,7 @@ static re_dfastate_t * | |||
2442 | transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, | 2486 | transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, |
2443 | re_dfastate_t *state) | 2487 | re_dfastate_t *state) |
2444 | { | 2488 | { |
2445 | re_dfa_t *const dfa = mctx->dfa; | 2489 | const re_dfa_t *const dfa = mctx->dfa; |
2446 | re_node_set next_nodes; | 2490 | re_node_set next_nodes; |
2447 | re_dfastate_t *next_state; | 2491 | re_dfastate_t *next_state; |
2448 | Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input); | 2492 | Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input); |
@@ -2481,7 +2525,7 @@ static reg_errcode_t | |||
2481 | internal_function | 2525 | internal_function |
2482 | transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) | 2526 | transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) |
2483 | { | 2527 | { |
2484 | re_dfa_t *const dfa = mctx->dfa; | 2528 | const re_dfa_t *const dfa = mctx->dfa; |
2485 | reg_errcode_t err; | 2529 | reg_errcode_t err; |
2486 | Idx i; | 2530 | Idx i; |
2487 | 2531 | ||
@@ -2535,7 +2579,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) | |||
2535 | if (BE (err != REG_NOERROR, 0)) | 2579 | if (BE (err != REG_NOERROR, 0)) |
2536 | return err; | 2580 | return err; |
2537 | } | 2581 | } |
2538 | context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags); | 2582 | context = re_string_context_at (&mctx->input, dest_idx - 1, |
2583 | mctx->eflags); | ||
2539 | mctx->state_log[dest_idx] | 2584 | mctx->state_log[dest_idx] |
2540 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); | 2585 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); |
2541 | if (dest_state != NULL) | 2586 | if (dest_state != NULL) |
@@ -2551,7 +2596,7 @@ static reg_errcode_t | |||
2551 | internal_function | 2596 | internal_function |
2552 | transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | 2597 | transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) |
2553 | { | 2598 | { |
2554 | re_dfa_t *const dfa = mctx->dfa; | 2599 | const re_dfa_t *const dfa = mctx->dfa; |
2555 | reg_errcode_t err; | 2600 | reg_errcode_t err; |
2556 | Idx i; | 2601 | Idx i; |
2557 | Idx cur_str_idx = re_string_cur_idx (&mctx->input); | 2602 | Idx cur_str_idx = re_string_cur_idx (&mctx->input); |
@@ -2665,14 +2710,15 @@ static reg_errcode_t | |||
2665 | internal_function | 2710 | internal_function |
2666 | get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | 2711 | get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) |
2667 | { | 2712 | { |
2668 | re_dfa_t *const dfa = mctx->dfa; | 2713 | const re_dfa_t *const dfa = mctx->dfa; |
2669 | Idx subexp_num, sub_top_idx; | 2714 | Idx subexp_num, sub_top_idx; |
2670 | const char *buf = (const char *) re_string_get_buffer (&mctx->input); | 2715 | const char *buf = (const char *) re_string_get_buffer (&mctx->input); |
2671 | /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ | 2716 | /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ |
2672 | Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); | 2717 | Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); |
2673 | if (cache_idx != REG_MISSING) | 2718 | if (cache_idx != REG_MISSING) |
2674 | { | 2719 | { |
2675 | const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx; | 2720 | const struct re_backref_cache_entry *entry |
2721 | = mctx->bkref_ents + cache_idx; | ||
2676 | do | 2722 | do |
2677 | if (entry->node == bkref_node) | 2723 | if (entry->node == bkref_node) |
2678 | return REG_NOERROR; /* We already checked it. */ | 2724 | 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) | |||
2719 | buf = (const char *) re_string_get_buffer (&mctx->input); | 2765 | buf = (const char *) re_string_get_buffer (&mctx->input); |
2720 | } | 2766 | } |
2721 | if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0) | 2767 | if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0) |
2722 | break; /* We don't need to search this sub expression any more. */ | 2768 | /* We don't need to search this sub expression any more. */ |
2769 | break; | ||
2723 | } | 2770 | } |
2724 | bkref_str_off += sl_str_diff; | 2771 | bkref_str_off += sl_str_diff; |
2725 | sl_str += sl_str_diff; | 2772 | sl_str += sl_str_diff; |
@@ -2771,20 +2818,22 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
2771 | continue; | 2818 | continue; |
2772 | /* Does this state have a ')' of the sub expression? */ | 2819 | /* Does this state have a ')' of the sub expression? */ |
2773 | nodes = &mctx->state_log[sl_str]->nodes; | 2820 | nodes = &mctx->state_log[sl_str]->nodes; |
2774 | cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP); | 2821 | cls_node = find_subexp_node (dfa, nodes, subexp_num, |
2822 | OP_CLOSE_SUBEXP); | ||
2775 | if (cls_node == REG_MISSING) | 2823 | if (cls_node == REG_MISSING) |
2776 | continue; /* No. */ | 2824 | continue; /* No. */ |
2777 | if (sub_top->path == NULL) | 2825 | if (sub_top->path == NULL) |
2778 | { | 2826 | { |
2779 | sub_top->path = re_calloc (state_array_t, | 2827 | sub_top->path = calloc (sizeof (state_array_t), |
2780 | sl_str - sub_top->str_idx + 1); | 2828 | sl_str - sub_top->str_idx + 1); |
2781 | if (sub_top->path == NULL) | 2829 | if (sub_top->path == NULL) |
2782 | return REG_ESPACE; | 2830 | return REG_ESPACE; |
2783 | } | 2831 | } |
2784 | /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node | 2832 | /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node |
2785 | in the current context? */ | 2833 | in the current context? */ |
2786 | err = check_arrival (mctx, sub_top->path, sub_top->node, | 2834 | err = check_arrival (mctx, sub_top->path, sub_top->node, |
2787 | sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP); | 2835 | sub_top->str_idx, cls_node, sl_str, |
2836 | OP_CLOSE_SUBEXP); | ||
2788 | if (err == REG_NOMATCH) | 2837 | if (err == REG_NOMATCH) |
2789 | continue; | 2838 | continue; |
2790 | if (BE (err != REG_NOERROR, 0)) | 2839 | 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, | |||
2816 | Idx to_idx; | 2865 | Idx to_idx; |
2817 | /* Can the subexpression arrive the back reference? */ | 2866 | /* Can the subexpression arrive the back reference? */ |
2818 | err = check_arrival (mctx, &sub_last->path, sub_last->node, | 2867 | err = check_arrival (mctx, &sub_last->path, sub_last->node, |
2819 | sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP); | 2868 | sub_last->str_idx, bkref_node, bkref_str, |
2869 | OP_OPEN_SUBEXP); | ||
2820 | if (err != REG_NOERROR) | 2870 | if (err != REG_NOERROR) |
2821 | return err; | 2871 | return err; |
2822 | err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, | 2872 | 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, | |||
2859 | 2909 | ||
2860 | static reg_errcode_t | 2910 | static reg_errcode_t |
2861 | internal_function | 2911 | internal_function |
2862 | check_arrival (re_match_context_t *mctx, state_array_t *path, | 2912 | check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, |
2863 | Idx top_node, Idx top_str, Idx last_node, Idx last_str, | 2913 | Idx top_str, Idx last_node, Idx last_str, int type) |
2864 | int type) | ||
2865 | { | 2914 | { |
2866 | re_dfa_t *const dfa = mctx->dfa; | 2915 | const re_dfa_t *const dfa = mctx->dfa; |
2867 | reg_errcode_t err; | 2916 | reg_errcode_t err = REG_NOERROR; |
2868 | Idx subexp_num, backup_cur_idx, str_idx, null_cnt; | 2917 | Idx subexp_num, backup_cur_idx, str_idx, null_cnt; |
2869 | re_dfastate_t *cur_state = NULL; | 2918 | re_dfastate_t *cur_state = NULL; |
2870 | re_node_set *cur_nodes, next_nodes; | 2919 | re_node_set *cur_nodes, next_nodes; |
@@ -2878,18 +2927,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
2878 | re_dfastate_t **new_array; | 2927 | re_dfastate_t **new_array; |
2879 | Idx old_alloc = path->alloc; | 2928 | Idx old_alloc = path->alloc; |
2880 | Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1; | 2929 | Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1; |
2881 | if (BE (new_alloc < old_alloc, 0)) | 2930 | if (BE (new_alloc < old_alloc, 0) |
2931 | || BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) | ||
2882 | return REG_ESPACE; | 2932 | return REG_ESPACE; |
2883 | new_array = re_xrealloc (path->array, re_dfastate_t *, new_alloc); | 2933 | new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); |
2884 | if (BE (new_array == NULL, 0)) | 2934 | if (BE (new_array == NULL, 0)) |
2885 | return REG_ESPACE; | 2935 | return REG_ESPACE; |
2886 | path->array = new_array; | 2936 | path->array = new_array; |
2887 | path->alloc = new_alloc; | 2937 | path->alloc = new_alloc; |
2888 | memset (new_array + old_alloc, '\0', | 2938 | memset (new_array + old_alloc, '\0', |
2889 | sizeof (re_dfastate_t *) * (new_alloc - old_alloc)); | 2939 | sizeof (re_dfastate_t *) * (path->alloc - old_alloc)); |
2890 | } | 2940 | } |
2891 | 2941 | ||
2892 | str_idx = path->next_idx == 0 ? top_str : path->next_idx; | 2942 | str_idx = path->next_idx ? path->next_idx : top_str; |
2893 | 2943 | ||
2894 | /* Temporary modify MCTX. */ | 2944 | /* Temporary modify MCTX. */ |
2895 | backup_state_log = mctx->state_log; | 2945 | backup_state_log = mctx->state_log; |
@@ -2917,7 +2967,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
2917 | if (cur_state && cur_state->has_backref) | 2967 | if (cur_state && cur_state->has_backref) |
2918 | { | 2968 | { |
2919 | err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); | 2969 | err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); |
2920 | if (BE ( err != REG_NOERROR, 0)) | 2970 | if (BE (err != REG_NOERROR, 0)) |
2921 | return err; | 2971 | return err; |
2922 | } | 2972 | } |
2923 | else | 2973 | else |
@@ -2929,7 +2979,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
2929 | { | 2979 | { |
2930 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, | 2980 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, |
2931 | subexp_num, type); | 2981 | subexp_num, type); |
2932 | if (BE ( err != REG_NOERROR, 0)) | 2982 | if (BE (err != REG_NOERROR, 0)) |
2933 | { | 2983 | { |
2934 | re_node_set_free (&next_nodes); | 2984 | re_node_set_free (&next_nodes); |
2935 | return err; | 2985 | return err; |
@@ -2960,7 +3010,8 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
2960 | if (cur_state) | 3010 | if (cur_state) |
2961 | { | 3011 | { |
2962 | err = check_arrival_add_next_nodes (mctx, str_idx, | 3012 | err = check_arrival_add_next_nodes (mctx, str_idx, |
2963 | &cur_state->non_eps_nodes, &next_nodes); | 3013 | &cur_state->non_eps_nodes, |
3014 | &next_nodes); | ||
2964 | if (BE (err != REG_NOERROR, 0)) | 3015 | if (BE (err != REG_NOERROR, 0)) |
2965 | { | 3016 | { |
2966 | re_node_set_free (&next_nodes); | 3017 | re_node_set_free (&next_nodes); |
@@ -2978,7 +3029,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
2978 | } | 3029 | } |
2979 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, | 3030 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, |
2980 | subexp_num, type); | 3031 | subexp_num, type); |
2981 | if (BE ( err != REG_NOERROR, 0)) | 3032 | if (BE (err != REG_NOERROR, 0)) |
2982 | { | 3033 | { |
2983 | re_node_set_free (&next_nodes); | 3034 | re_node_set_free (&next_nodes); |
2984 | return err; | 3035 | return err; |
@@ -3021,13 +3072,12 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, | |||
3021 | static reg_errcode_t | 3072 | static reg_errcode_t |
3022 | internal_function | 3073 | internal_function |
3023 | check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, | 3074 | check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, |
3024 | re_node_set *cur_nodes, | 3075 | re_node_set *cur_nodes, re_node_set *next_nodes) |
3025 | re_node_set *next_nodes) | ||
3026 | { | 3076 | { |
3027 | re_dfa_t *const dfa = mctx->dfa; | 3077 | const re_dfa_t *const dfa = mctx->dfa; |
3028 | bool ok; | 3078 | bool ok; |
3029 | Idx cur_idx; | 3079 | Idx cur_idx; |
3030 | reg_errcode_t err; | 3080 | reg_errcode_t err = REG_NOERROR; |
3031 | re_node_set union_set; | 3081 | re_node_set union_set; |
3032 | re_node_set_init_empty (&union_set); | 3082 | re_node_set_init_empty (&union_set); |
3033 | for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx) | 3083 | 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, | |||
3100 | 3150 | ||
3101 | static reg_errcode_t | 3151 | static reg_errcode_t |
3102 | internal_function | 3152 | internal_function |
3103 | check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, | 3153 | check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, |
3104 | Idx ex_subexp, int type) | 3154 | Idx ex_subexp, int type) |
3105 | { | 3155 | { |
3106 | reg_errcode_t err; | 3156 | reg_errcode_t err; |
@@ -3118,7 +3168,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, | |||
3118 | for (idx = 0; idx < cur_nodes->nelem; ++idx) | 3168 | for (idx = 0; idx < cur_nodes->nelem; ++idx) |
3119 | { | 3169 | { |
3120 | Idx cur_node = cur_nodes->elems[idx]; | 3170 | Idx cur_node = cur_nodes->elems[idx]; |
3121 | re_node_set *eclosure = dfa->eclosures + cur_node; | 3171 | const re_node_set *eclosure = dfa->eclosures + cur_node; |
3122 | outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); | 3172 | outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); |
3123 | if (outside_node == REG_MISSING) | 3173 | if (outside_node == REG_MISSING) |
3124 | { | 3174 | { |
@@ -3153,7 +3203,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, | |||
3153 | 3203 | ||
3154 | static reg_errcode_t | 3204 | static reg_errcode_t |
3155 | internal_function | 3205 | internal_function |
3156 | check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, | 3206 | check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, |
3157 | Idx target, Idx ex_subexp, int type) | 3207 | Idx target, Idx ex_subexp, int type) |
3158 | { | 3208 | { |
3159 | Idx cur_node; | 3209 | Idx cur_node; |
@@ -3179,12 +3229,12 @@ check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, | |||
3179 | break; | 3229 | break; |
3180 | if (dfa->edests[cur_node].nelem == 2) | 3230 | if (dfa->edests[cur_node].nelem == 2) |
3181 | { | 3231 | { |
3182 | reg_errcode_t ret = | 3232 | reg_errcode_t err; |
3183 | check_arrival_expand_ecl_sub (dfa, dst_nodes, | 3233 | err = check_arrival_expand_ecl_sub (dfa, dst_nodes, |
3184 | dfa->edests[cur_node].elems[1], | 3234 | dfa->edests[cur_node].elems[1], |
3185 | ex_subexp, type); | 3235 | ex_subexp, type); |
3186 | if (BE (ret != REG_NOERROR, 0)) | 3236 | if (BE (err != REG_NOERROR, 0)) |
3187 | return ret; | 3237 | return err; |
3188 | } | 3238 | } |
3189 | cur_node = dfa->edests[cur_node].elems[0]; | 3239 | cur_node = dfa->edests[cur_node].elems[0]; |
3190 | } | 3240 | } |
@@ -3201,7 +3251,7 @@ internal_function | |||
3201 | expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, | 3251 | expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, |
3202 | Idx cur_str, Idx subexp_num, int type) | 3252 | Idx cur_str, Idx subexp_num, int type) |
3203 | { | 3253 | { |
3204 | re_dfa_t *const dfa = mctx->dfa; | 3254 | const re_dfa_t *const dfa = mctx->dfa; |
3205 | reg_errcode_t err; | 3255 | reg_errcode_t err; |
3206 | Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); | 3256 | Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); |
3207 | struct re_backref_cache_entry *ent; | 3257 | struct re_backref_cache_entry *ent; |
@@ -3287,25 +3337,26 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
3287 | 3337 | ||
3288 | static bool | 3338 | static bool |
3289 | internal_function | 3339 | internal_function |
3290 | build_trtable (re_dfa_t *dfa, re_dfastate_t *state) | 3340 | build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) |
3291 | { | 3341 | { |
3292 | reg_errcode_t err; | 3342 | reg_errcode_t err; |
3293 | Idx i, j; | 3343 | Idx i, j; |
3294 | int ch; | 3344 | int ch; |
3295 | bool need_word_trtable = false; | 3345 | bool need_word_trtable = false; |
3296 | bitset_word elem, mask; | 3346 | bitset_word_t elem, mask; |
3297 | bool dests_node_malloced = false, dest_states_malloced = false; | 3347 | bool dests_node_malloced = false; |
3348 | bool dest_states_malloced = false; | ||
3298 | Idx ndests; /* Number of the destination states from `state'. */ | 3349 | Idx ndests; /* Number of the destination states from `state'. */ |
3299 | re_dfastate_t **trtable; | 3350 | re_dfastate_t **trtable; |
3300 | re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; | 3351 | re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; |
3301 | re_node_set follows, *dests_node; | 3352 | re_node_set follows, *dests_node; |
3302 | bitset *dests_ch; | 3353 | bitset_t *dests_ch; |
3303 | bitset acceptable; | 3354 | bitset_t acceptable; |
3304 | 3355 | ||
3305 | struct dests_alloc | 3356 | struct dests_alloc |
3306 | { | 3357 | { |
3307 | re_node_set dests_node[SBC_MAX]; | 3358 | re_node_set dests_node[SBC_MAX]; |
3308 | bitset dests_ch[SBC_MAX]; | 3359 | bitset_t dests_ch[SBC_MAX]; |
3309 | } *dests_alloc; | 3360 | } *dests_alloc; |
3310 | 3361 | ||
3311 | /* We build DFA states which corresponds to the destination nodes | 3362 | /* We build DFA states which corresponds to the destination nodes |
@@ -3313,7 +3364,7 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) | |||
3313 | destination state contains, and `dests_ch[i]' represents the | 3364 | destination state contains, and `dests_ch[i]' represents the |
3314 | characters which i-th destination state accepts. */ | 3365 | characters which i-th destination state accepts. */ |
3315 | if (__libc_use_alloca (sizeof (struct dests_alloc))) | 3366 | if (__libc_use_alloca (sizeof (struct dests_alloc))) |
3316 | dests_alloc = (struct dests_alloc *) alloca (sizeof dests_alloc[0]); | 3367 | dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); |
3317 | else | 3368 | else |
3318 | { | 3369 | { |
3319 | dests_alloc = re_malloc (struct dests_alloc, 1); | 3370 | dests_alloc = re_malloc (struct dests_alloc, 1); |
@@ -3336,7 +3387,8 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) | |||
3336 | free (dests_alloc); | 3387 | free (dests_alloc); |
3337 | if (ndests == 0) | 3388 | if (ndests == 0) |
3338 | { | 3389 | { |
3339 | state->trtable = re_calloc (re_dfastate_t *, SBC_MAX); | 3390 | state->trtable = (re_dfastate_t **) |
3391 | calloc (sizeof (re_dfastate_t *), SBC_MAX); | ||
3340 | return true; | 3392 | return true; |
3341 | } | 3393 | } |
3342 | return false; | 3394 | return false; |
@@ -3347,12 +3399,13 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) | |||
3347 | goto out_free; | 3399 | goto out_free; |
3348 | 3400 | ||
3349 | /* Avoid arithmetic overflow in size calculation. */ | 3401 | /* Avoid arithmetic overflow in size calculation. */ |
3350 | if (BE (((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX) | 3402 | if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) |
3351 | / (3 * sizeof (re_dfastate_t *))) | 3403 | / (3 * sizeof (re_dfastate_t *))) |
3352 | < ndests, 0)) | 3404 | < ndests), |
3405 | 0)) | ||
3353 | goto out_free; | 3406 | goto out_free; |
3354 | 3407 | ||
3355 | if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX | 3408 | if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX |
3356 | + ndests * 3 * sizeof (re_dfastate_t *))) | 3409 | + ndests * 3 * sizeof (re_dfastate_t *))) |
3357 | dest_states = (re_dfastate_t **) | 3410 | dest_states = (re_dfastate_t **) |
3358 | alloca (ndests * 3 * sizeof (re_dfastate_t *)); | 3411 | alloca (ndests * 3 * sizeof (re_dfastate_t *)); |
@@ -3428,7 +3481,8 @@ out_free: | |||
3428 | character, or we are in a single-byte character set so we can | 3481 | character, or we are in a single-byte character set so we can |
3429 | discern by looking at the character code: allocate a | 3482 | discern by looking at the character code: allocate a |
3430 | 256-entry transition table. */ | 3483 | 256-entry transition table. */ |
3431 | trtable = state->trtable = re_calloc (re_dfastate_t *, SBC_MAX); | 3484 | trtable = state->trtable = |
3485 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); | ||
3432 | if (BE (trtable == NULL, 0)) | 3486 | if (BE (trtable == NULL, 0)) |
3433 | goto out_free; | 3487 | goto out_free; |
3434 | 3488 | ||
@@ -3458,7 +3512,8 @@ out_free: | |||
3458 | by looking at the character code: build two 256-entry | 3512 | by looking at the character code: build two 256-entry |
3459 | transition tables, one starting at trtable[0] and one | 3513 | transition tables, one starting at trtable[0] and one |
3460 | starting at trtable[SBC_MAX]. */ | 3514 | starting at trtable[SBC_MAX]. */ |
3461 | trtable = state->word_trtable = re_calloc (re_dfastate_t *, 2 * SBC_MAX); | 3515 | trtable = state->word_trtable = |
3516 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); | ||
3462 | if (BE (trtable == NULL, 0)) | 3517 | if (BE (trtable == NULL, 0)) |
3463 | goto out_free; | 3518 | goto out_free; |
3464 | 3519 | ||
@@ -3518,13 +3573,13 @@ out_free: | |||
3518 | static Idx | 3573 | static Idx |
3519 | internal_function | 3574 | internal_function |
3520 | group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | 3575 | group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, |
3521 | re_node_set *dests_node, bitset *dests_ch) | 3576 | re_node_set *dests_node, bitset_t *dests_ch) |
3522 | { | 3577 | { |
3523 | reg_errcode_t err; | 3578 | reg_errcode_t err; |
3524 | bool ok; | 3579 | bool ok; |
3525 | Idx i, j, k; | 3580 | Idx i, j, k; |
3526 | Idx ndests; /* Number of the destinations from `state'. */ | 3581 | Idx ndests; /* Number of the destinations from `state'. */ |
3527 | bitset accepts; /* Characters a node can accept. */ | 3582 | bitset_t accepts; /* Characters a node can accept. */ |
3528 | const re_node_set *cur_nodes = &state->nodes; | 3583 | const re_node_set *cur_nodes = &state->nodes; |
3529 | bitset_empty (accepts); | 3584 | bitset_empty (accepts); |
3530 | ndests = 0; | 3585 | ndests = 0; |
@@ -3551,21 +3606,21 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
3551 | else | 3606 | else |
3552 | #endif | 3607 | #endif |
3553 | bitset_set_all (accepts); | 3608 | bitset_set_all (accepts); |
3554 | if (!(dfa->syntax & REG_DOT_NEWLINE)) | 3609 | if (!(dfa->syntax & RE_DOT_NEWLINE)) |
3555 | bitset_clear (accepts, '\n'); | 3610 | bitset_clear (accepts, '\n'); |
3556 | if (dfa->syntax & REG_DOT_NOT_NULL) | 3611 | if (dfa->syntax & RE_DOT_NOT_NULL) |
3557 | bitset_clear (accepts, '\0'); | 3612 | bitset_clear (accepts, '\0'); |
3558 | } | 3613 | } |
3559 | #ifdef RE_ENABLE_I18N | 3614 | #ifdef RE_ENABLE_I18N |
3560 | else if (type == OP_UTF8_PERIOD) | 3615 | else if (type == OP_UTF8_PERIOD) |
3561 | { | 3616 | { |
3562 | if (SBC_MAX / 2 % BITSET_WORD_BITS == 0) | 3617 | if (ASCII_CHARS % BITSET_WORD_BITS == 0) |
3563 | memset (accepts, -1, sizeof accepts / 2); | 3618 | memset (accepts, -1, ASCII_CHARS / CHAR_BIT); |
3564 | else | 3619 | else |
3565 | bitset_merge (accepts, utf8_sb_map); | 3620 | bitset_merge (accepts, utf8_sb_map); |
3566 | if (!(dfa->syntax & REG_DOT_NEWLINE)) | 3621 | if (!(dfa->syntax & RE_DOT_NEWLINE)) |
3567 | bitset_clear (accepts, '\n'); | 3622 | bitset_clear (accepts, '\n'); |
3568 | if (dfa->syntax & REG_DOT_NOT_NULL) | 3623 | if (dfa->syntax & RE_DOT_NOT_NULL) |
3569 | bitset_clear (accepts, '\0'); | 3624 | bitset_clear (accepts, '\0'); |
3570 | } | 3625 | } |
3571 | #endif | 3626 | #endif |
@@ -3593,7 +3648,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
3593 | 3648 | ||
3594 | if (constraint & NEXT_WORD_CONSTRAINT) | 3649 | if (constraint & NEXT_WORD_CONSTRAINT) |
3595 | { | 3650 | { |
3596 | bitset_word any_set = 0; | 3651 | bitset_word_t any_set = 0; |
3597 | if (type == CHARACTER && !node->word_char) | 3652 | if (type == CHARACTER && !node->word_char) |
3598 | { | 3653 | { |
3599 | bitset_empty (accepts); | 3654 | bitset_empty (accepts); |
@@ -3612,7 +3667,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
3612 | } | 3667 | } |
3613 | if (constraint & NEXT_NOTWORD_CONSTRAINT) | 3668 | if (constraint & NEXT_NOTWORD_CONSTRAINT) |
3614 | { | 3669 | { |
3615 | bitset_word any_set = 0; | 3670 | bitset_word_t any_set = 0; |
3616 | if (type == CHARACTER && node->word_char) | 3671 | if (type == CHARACTER && node->word_char) |
3617 | { | 3672 | { |
3618 | bitset_empty (accepts); | 3673 | bitset_empty (accepts); |
@@ -3635,10 +3690,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
3635 | state. Above, we make sure that accepts is not empty. */ | 3690 | state. Above, we make sure that accepts is not empty. */ |
3636 | for (j = 0; j < ndests; ++j) | 3691 | for (j = 0; j < ndests; ++j) |
3637 | { | 3692 | { |
3638 | bitset intersec; /* Intersection sets, see below. */ | 3693 | bitset_t intersec; /* Intersection sets, see below. */ |
3639 | bitset remains; | 3694 | bitset_t remains; |
3640 | /* Flags, see below. */ | 3695 | /* Flags, see below. */ |
3641 | bitset_word has_intersec, not_subset, not_consumed; | 3696 | bitset_word_t has_intersec, not_subset, not_consumed; |
3642 | 3697 | ||
3643 | /* Optimization, skip if this state doesn't accept the character. */ | 3698 | /* Optimization, skip if this state doesn't accept the character. */ |
3644 | if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c)) | 3699 | 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, | |||
3710 | 3765 | ||
3711 | static int | 3766 | static int |
3712 | internal_function | 3767 | internal_function |
3713 | check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, | 3768 | check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, |
3714 | const re_string_t *input, Idx str_idx) | 3769 | const re_string_t *input, Idx str_idx) |
3715 | { | 3770 | { |
3716 | const re_token_t *node = dfa->nodes + node_idx; | 3771 | const re_token_t *node = dfa->nodes + node_idx; |
@@ -3776,9 +3831,9 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, | |||
3776 | /* FIXME: I don't think this if is needed, as both '\n' | 3831 | /* FIXME: I don't think this if is needed, as both '\n' |
3777 | and '\0' are char_len == 1. */ | 3832 | and '\0' are char_len == 1. */ |
3778 | /* '.' accepts any one character except the following two cases. */ | 3833 | /* '.' accepts any one character except the following two cases. */ |
3779 | if ((!(dfa->syntax & REG_DOT_NEWLINE) && | 3834 | if ((!(dfa->syntax & RE_DOT_NEWLINE) && |
3780 | re_string_byte_at (input, str_idx) == '\n') || | 3835 | re_string_byte_at (input, str_idx) == '\n') || |
3781 | ((dfa->syntax & REG_DOT_NOT_NULL) && | 3836 | ((dfa->syntax & RE_DOT_NOT_NULL) && |
3782 | re_string_byte_at (input, str_idx) == '\0')) | 3837 | re_string_byte_at (input, str_idx) == '\0')) |
3783 | return 0; | 3838 | return 0; |
3784 | return char_len; | 3839 | return char_len; |
@@ -3911,7 +3966,7 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, | |||
3911 | # endif /* _LIBC */ | 3966 | # endif /* _LIBC */ |
3912 | { | 3967 | { |
3913 | /* match with range expression? */ | 3968 | /* match with range expression? */ |
3914 | #if __GNUC__ >= 2 | 3969 | #if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && __STRICT_ANSI__) |
3915 | wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'}; | 3970 | wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'}; |
3916 | #else | 3971 | #else |
3917 | wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; | 3972 | wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; |
@@ -3945,6 +4000,7 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, | |||
3945 | 4000 | ||
3946 | # ifdef _LIBC | 4001 | # ifdef _LIBC |
3947 | static unsigned int | 4002 | static unsigned int |
4003 | internal_function | ||
3948 | find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) | 4004 | find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) |
3949 | { | 4005 | { |
3950 | uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); | 4006 | 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, | |||
4028 | 4084 | ||
4029 | #ifdef RE_ENABLE_I18N | 4085 | #ifdef RE_ENABLE_I18N |
4030 | case OP_UTF8_PERIOD: | 4086 | case OP_UTF8_PERIOD: |
4031 | if (ch >= 0x80) | 4087 | if (ch >= ASCII_CHARS) |
4032 | return false; | 4088 | return false; |
4033 | /* FALLTHROUGH */ | 4089 | /* FALLTHROUGH */ |
4034 | #endif | 4090 | #endif |
4035 | case OP_PERIOD: | 4091 | case OP_PERIOD: |
4036 | if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE)) | 4092 | if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) |
4037 | || (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL))) | 4093 | || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) |
4038 | return false; | 4094 | return false; |
4039 | break; | 4095 | break; |
4040 | 4096 | ||
@@ -4064,6 +4120,10 @@ extend_buffers (re_match_context_t *mctx) | |||
4064 | reg_errcode_t ret; | 4120 | reg_errcode_t ret; |
4065 | re_string_t *pstr = &mctx->input; | 4121 | re_string_t *pstr = &mctx->input; |
4066 | 4122 | ||
4123 | /* Avoid overflow. */ | ||
4124 | if (BE (SIZE_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0)) | ||
4125 | return REG_ESPACE; | ||
4126 | |||
4067 | /* Double the lengthes of the buffers. */ | 4127 | /* Double the lengthes of the buffers. */ |
4068 | ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); | 4128 | ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); |
4069 | if (BE (ret != REG_NOERROR, 0)) | 4129 | if (BE (ret != REG_NOERROR, 0)) |
@@ -4075,8 +4135,8 @@ extend_buffers (re_match_context_t *mctx) | |||
4075 | /* XXX We have no indication of the size of this buffer. If this | 4135 | /* XXX We have no indication of the size of this buffer. If this |
4076 | allocation fail we have no indication that the state_log array | 4136 | allocation fail we have no indication that the state_log array |
4077 | does not have the right size. */ | 4137 | does not have the right size. */ |
4078 | re_dfastate_t **new_array = re_xrealloc (mctx->state_log, re_dfastate_t *, | 4138 | re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, |
4079 | pstr->bufs_len + 1); | 4139 | pstr->bufs_len + 1); |
4080 | if (BE (new_array == NULL, 0)) | 4140 | if (BE (new_array == NULL, 0)) |
4081 | return REG_ESPACE; | 4141 | return REG_ESPACE; |
4082 | mctx->state_log = new_array; | 4142 | mctx->state_log = new_array; |
@@ -4124,8 +4184,15 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) | |||
4124 | mctx->match_last = REG_MISSING; | 4184 | mctx->match_last = REG_MISSING; |
4125 | if (n > 0) | 4185 | if (n > 0) |
4126 | { | 4186 | { |
4127 | mctx->bkref_ents = re_xmalloc (struct re_backref_cache_entry, n); | 4187 | /* Avoid overflow. */ |
4128 | mctx->sub_tops = re_xmalloc (re_sub_match_top_t *, n); | 4188 | size_t max_object_size = |
4189 | MAX (sizeof (struct re_backref_cache_entry), | ||
4190 | sizeof (re_sub_match_top_t *)); | ||
4191 | if (BE (SIZE_MAX / max_object_size < n, 0)) | ||
4192 | return REG_ESPACE; | ||
4193 | |||
4194 | mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); | ||
4195 | mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); | ||
4129 | if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) | 4196 | if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) |
4130 | return REG_ESPACE; | 4197 | return REG_ESPACE; |
4131 | } | 4198 | } |
@@ -4191,14 +4258,14 @@ match_ctx_free (re_match_context_t *mctx) | |||
4191 | 4258 | ||
4192 | static reg_errcode_t | 4259 | static reg_errcode_t |
4193 | internal_function | 4260 | internal_function |
4194 | match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, | 4261 | match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, |
4195 | Idx from, Idx to) | 4262 | Idx to) |
4196 | { | 4263 | { |
4197 | if (mctx->nbkref_ents >= mctx->abkref_ents) | 4264 | if (mctx->nbkref_ents >= mctx->abkref_ents) |
4198 | { | 4265 | { |
4199 | struct re_backref_cache_entry* new_entry; | 4266 | struct re_backref_cache_entry* new_entry; |
4200 | new_entry = re_x2realloc (mctx->bkref_ents, struct re_backref_cache_entry, | 4267 | new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, |
4201 | &mctx->abkref_ents); | 4268 | mctx->abkref_ents * 2); |
4202 | if (BE (new_entry == NULL, 0)) | 4269 | if (BE (new_entry == NULL, 0)) |
4203 | { | 4270 | { |
4204 | re_free (mctx->bkref_ents); | 4271 | re_free (mctx->bkref_ents); |
@@ -4206,8 +4273,8 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, | |||
4206 | } | 4273 | } |
4207 | mctx->bkref_ents = new_entry; | 4274 | mctx->bkref_ents = new_entry; |
4208 | memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', | 4275 | memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', |
4209 | (sizeof (struct re_backref_cache_entry) | 4276 | sizeof (struct re_backref_cache_entry) * mctx->abkref_ents); |
4210 | * (mctx->abkref_ents - mctx->nbkref_ents))); | 4277 | mctx->abkref_ents *= 2; |
4211 | } | 4278 | } |
4212 | if (mctx->nbkref_ents > 0 | 4279 | if (mctx->nbkref_ents > 0 |
4213 | && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx) | 4280 | && 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) | |||
4271 | #endif | 4338 | #endif |
4272 | if (BE (mctx->nsub_tops == mctx->asub_tops, 0)) | 4339 | if (BE (mctx->nsub_tops == mctx->asub_tops, 0)) |
4273 | { | 4340 | { |
4274 | Idx new_asub_tops = mctx->asub_tops; | 4341 | Idx new_asub_tops = mctx->asub_tops * 2; |
4275 | re_sub_match_top_t **new_array = re_x2realloc (mctx->sub_tops, | 4342 | re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, |
4276 | re_sub_match_top_t *, | 4343 | re_sub_match_top_t *, |
4277 | &new_asub_tops); | 4344 | new_asub_tops); |
4278 | if (BE (new_array == NULL, 0)) | 4345 | if (BE (new_array == NULL, 0)) |
4279 | return REG_ESPACE; | 4346 | return REG_ESPACE; |
4280 | mctx->sub_tops = new_array; | 4347 | mctx->sub_tops = new_array; |
4281 | mctx->asub_tops = new_asub_tops; | 4348 | mctx->asub_tops = new_asub_tops; |
4282 | } | 4349 | } |
4283 | mctx->sub_tops[mctx->nsub_tops] = re_calloc (re_sub_match_top_t, 1); | 4350 | mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); |
4284 | if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) | 4351 | if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) |
4285 | return REG_ESPACE; | 4352 | return REG_ESPACE; |
4286 | mctx->sub_tops[mctx->nsub_tops]->node = node; | 4353 | 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) | |||
4298 | re_sub_match_last_t *new_entry; | 4365 | re_sub_match_last_t *new_entry; |
4299 | if (BE (subtop->nlasts == subtop->alasts, 0)) | 4366 | if (BE (subtop->nlasts == subtop->alasts, 0)) |
4300 | { | 4367 | { |
4301 | Idx new_alasts = subtop->alasts; | 4368 | Idx new_alasts = 2 * subtop->alasts + 1; |
4302 | re_sub_match_last_t **new_array = re_x2realloc (subtop->lasts, | 4369 | re_sub_match_last_t **new_array = re_realloc (subtop->lasts, |
4303 | re_sub_match_last_t *, | 4370 | re_sub_match_last_t *, |
4304 | &new_alasts); | 4371 | new_alasts); |
4305 | if (BE (new_array == NULL, 0)) | 4372 | if (BE (new_array == NULL, 0)) |
4306 | return NULL; | 4373 | return NULL; |
4307 | subtop->lasts = new_array; | 4374 | subtop->lasts = new_array; |
4308 | subtop->alasts = new_alasts; | 4375 | subtop->alasts = new_alasts; |
4309 | } | 4376 | } |
4310 | new_entry = re_calloc (re_sub_match_last_t, 1); | 4377 | new_entry = calloc (1, sizeof (re_sub_match_last_t)); |
4311 | if (BE (new_entry != NULL, 1)) | 4378 | if (BE (new_entry != NULL, 1)) |
4312 | { | 4379 | { |
4313 | subtop->lasts[subtop->nlasts] = new_entry; | 4380 | 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) | |||
4320 | 4387 | ||
4321 | static void | 4388 | static void |
4322 | internal_function | 4389 | internal_function |
4323 | sift_ctx_init (re_sift_context_t *sctx, | 4390 | sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, |
4324 | re_dfastate_t **sifted_sts, | 4391 | re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx) |
4325 | re_dfastate_t **limited_sts, | ||
4326 | Idx last_node, Idx last_str_idx) | ||
4327 | { | 4392 | { |
4328 | sctx->sifted_states = sifted_sts; | 4393 | sctx->sifted_states = sifted_sts; |
4329 | sctx->limited_states = limited_sts; | 4394 | sctx->limited_states = limited_sts; |
diff --git a/lib/safe-read.c b/gl/safe-read.c index 9caf846..b7bf1d5 100644 --- a/lib/safe-read.c +++ b/gl/safe-read.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* An interface to read and write that retries after interrupts. | 1 | /* An interface to read and write that retries after interrupts. |
2 | 2 | ||
3 | Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005 Free Software | 3 | Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free |
4 | Foundation, Inc. | 4 | Software Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +17,7 @@ | |||
17 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | /* Specification. */ | 22 | /* Specification. */ |
25 | #ifdef SAFE_WRITE | 23 | #ifdef SAFE_WRITE |
diff --git a/lib/safe-read.h b/gl/safe-read.h index 9f8a59b..3451955 100644 --- a/lib/safe-read.h +++ b/gl/safe-read.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* An interface to read() that retries after interrupts. | 1 | /* An interface to read() that retries after interrupts. |
2 | Copyright (C) 2002 Free Software Foundation, Inc. | 2 | Copyright (C) 2002, 2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -17,9 +17,19 @@ | |||
17 | 17 | ||
18 | #include <stddef.h> | 18 | #include <stddef.h> |
19 | 19 | ||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | |||
20 | #define SAFE_READ_ERROR ((size_t) -1) | 25 | #define SAFE_READ_ERROR ((size_t) -1) |
21 | 26 | ||
22 | /* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted. | 27 | /* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted. |
23 | Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR | 28 | Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR |
24 | upon error. */ | 29 | upon error. */ |
25 | extern size_t safe_read (int fd, void *buf, size_t count); | 30 | extern size_t safe_read (int fd, void *buf, size_t count); |
31 | |||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
diff --git a/lib/safe-write.c b/gl/safe-write.c index 4c375a6..4c375a6 100644 --- a/lib/safe-write.c +++ b/gl/safe-write.c | |||
diff --git a/lib/safe-write.h b/gl/safe-write.h index c194636..c194636 100644 --- a/lib/safe-write.h +++ b/gl/safe-write.h | |||
diff --git a/gl/size_max.h b/gl/size_max.h new file mode 100644 index 0000000..ed0bc13 --- /dev/null +++ b/gl/size_max.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* size_max.h -- declare SIZE_MAX through system headers | ||
2 | Copyright (C) 2005-2006 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef GNULIB_SIZE_MAX_H | ||
20 | #define GNULIB_SIZE_MAX_H | ||
21 | |||
22 | /* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */ | ||
23 | # include <limits.h> | ||
24 | /* Get SIZE_MAX declaration on systems like glibc 2. */ | ||
25 | # if HAVE_STDINT_H | ||
26 | # include <stdint.h> | ||
27 | # endif | ||
28 | /* On systems where these include files don't define it, SIZE_MAX is defined | ||
29 | in config.h. */ | ||
30 | |||
31 | #endif /* GNULIB_SIZE_MAX_H */ | ||
diff --git a/gl/snprintf.c b/gl/snprintf.c new file mode 100644 index 0000000..db1ca9a --- /dev/null +++ b/gl/snprintf.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 2004, 2006 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson and Paul Eggert. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #include <config.h> | ||
20 | |||
21 | #include "snprintf.h" | ||
22 | |||
23 | #include <errno.h> | ||
24 | #include <limits.h> | ||
25 | #include <stdarg.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #include "vasnprintf.h" | ||
30 | |||
31 | /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ | ||
32 | #ifndef EOVERFLOW | ||
33 | # define EOVERFLOW E2BIG | ||
34 | #endif | ||
35 | |||
36 | /* Print formatted output to string STR. Similar to sprintf, but | ||
37 | additional length SIZE limit how much is written into STR. Returns | ||
38 | string length of formatted string (which may be larger than SIZE). | ||
39 | STR may be NULL, in which case nothing will be written. On error, | ||
40 | return a negative value. */ | ||
41 | int | ||
42 | snprintf (char *str, size_t size, const char *format, ...) | ||
43 | { | ||
44 | char *output; | ||
45 | size_t len; | ||
46 | size_t lenbuf = size; | ||
47 | va_list args; | ||
48 | |||
49 | va_start (args, format); | ||
50 | output = vasnprintf (str, &lenbuf, format, args); | ||
51 | len = lenbuf; | ||
52 | va_end (args); | ||
53 | |||
54 | if (!output) | ||
55 | return -1; | ||
56 | |||
57 | if (output != str) | ||
58 | { | ||
59 | if (size) | ||
60 | { | ||
61 | size_t pruned_len = (len < size ? len : size - 1); | ||
62 | memcpy (str, output, pruned_len); | ||
63 | str[pruned_len] = '\0'; | ||
64 | } | ||
65 | |||
66 | free (output); | ||
67 | } | ||
68 | |||
69 | if (INT_MAX < len) | ||
70 | { | ||
71 | errno = EOVERFLOW; | ||
72 | return -1; | ||
73 | } | ||
74 | |||
75 | return len; | ||
76 | } | ||
diff --git a/gl/snprintf.h b/gl/snprintf.h new file mode 100644 index 0000000..5032b9e --- /dev/null +++ b/gl/snprintf.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 2004 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef SNPRINTF_H | ||
20 | #define SNPRINTF_H | ||
21 | |||
22 | /* Get snprintf declaration, if available. */ | ||
23 | #include <stdio.h> | ||
24 | |||
25 | #if defined HAVE_DECL_SNPRINTF && !HAVE_DECL_SNPRINTF | ||
26 | int snprintf (char *str, size_t size, const char *format, ...); | ||
27 | #endif | ||
28 | |||
29 | #endif /* SNPRINTF_H */ | ||
diff --git a/gl/socket_.h b/gl/socket_.h new file mode 100644 index 0000000..8b28b5e --- /dev/null +++ b/gl/socket_.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* Provide a sys/socket header file for systems lacking it (read: MinGW). | ||
2 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef _SYS_SOCKET_H | ||
20 | #define _SYS_SOCKET_H | ||
21 | |||
22 | /* This file is supposed to be used on platforms that lack | ||
23 | sys/socket.h. It is intended to provide definitions and prototypes | ||
24 | needed by an application. | ||
25 | |||
26 | Currently only MinGW is supported. See the gnulib manual regarding | ||
27 | Windows sockets. MinGW has the header files winsock2.h and | ||
28 | ws2tcpip.h that declare the sys/socket.h definitions we need. Note | ||
29 | that you can influence which definitions you get by setting the | ||
30 | WINVER symbol before including these two files. For example, | ||
31 | getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that | ||
32 | symbol is set indiriectly through WINVER). You can set this by | ||
33 | adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your | ||
34 | code may not run on older Windows releases then. My Windows 2000 | ||
35 | box was not able to run the code, for example. The situation is | ||
36 | slightly confusing because: | ||
37 | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp | ||
38 | suggests that getaddrinfo should be available on all Windows | ||
39 | releases. */ | ||
40 | |||
41 | |||
42 | #if HAVE_WINSOCK2_H | ||
43 | # include <winsock2.h> | ||
44 | #endif | ||
45 | #if HAVE_WS2TCPIP_H | ||
46 | # include <ws2tcpip.h> | ||
47 | #endif | ||
48 | |||
49 | /* For shutdown(). */ | ||
50 | #if !defined SHUT_RD && defined SD_RECEIVE | ||
51 | # define SHUT_RD SD_RECEIVE | ||
52 | #endif | ||
53 | #if !defined SHUT_WR && defined SD_SEND | ||
54 | # define SHUT_WR SD_SEND | ||
55 | #endif | ||
56 | #if !defined SHUT_RDWR && defined SD_BOTH | ||
57 | # define SHUT_RDWR SD_BOTH | ||
58 | #endif | ||
59 | |||
60 | #if defined _WIN32 || defined __WIN32__ | ||
61 | # define ENOTSOCK WSAENOTSOCK | ||
62 | # define EADDRINUSE WSAEADDRINUSE | ||
63 | # define ENETRESET WSAENETRESET | ||
64 | # define ECONNABORTED WSAECONNABORTED | ||
65 | # define ECONNRESET WSAECONNRESET | ||
66 | # define ENOTCONN WSAENOTCONN | ||
67 | # define ESHUTDOWN WSAESHUTDOWN | ||
68 | #endif | ||
69 | |||
70 | #endif /* _SYS_SOCKET_H */ | ||
diff --git a/lib/stdbool_.h b/gl/stdbool_.h index 7cd2da8..efa80ba 100644 --- a/lib/stdbool_.h +++ b/gl/stdbool_.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. | 1 | /* Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. |
2 | Written by Bruno Haible <haible@clisp.cons.org>, 2001. | 2 | Written by Bruno Haible <haible@clisp.cons.org>, 2001. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
@@ -54,47 +54,57 @@ | |||
54 | /* 7.16. Boolean type and values */ | 54 | /* 7.16. Boolean type and values */ |
55 | 55 | ||
56 | /* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same | 56 | /* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same |
57 | definitions below, which is OK. */ | 57 | definitions below, but temporarily we have to #undef them. */ |
58 | #ifdef __BEOS__ | 58 | #ifdef __BEOS__ |
59 | # include <OS.h> /* defines bool but not _Bool */ | 59 | # include <OS.h> /* defines bool but not _Bool */ |
60 | # undef false | ||
61 | # undef true | ||
60 | #endif | 62 | #endif |
61 | 63 | ||
62 | /* C++ and BeOS have a reliable bool (and _Bool, if it exists). | 64 | /* For the sake of symbolic names in gdb, we define true and false as |
63 | Otherwise, since this file is being compiled, the system | 65 | enum constants, not only as macros. |
64 | <stdbool.h> is not reliable so assume that the system _Bool is not | 66 | It is tempting to write |
65 | reliable either. Under that assumption, it is tempting to write | 67 | typedef enum { false = 0, true = 1 } _Bool; |
66 | 68 | so that gdb prints values of type 'bool' symbolically. But if we do | |
67 | typedef enum { false, true } _Bool; | ||
68 | |||
69 | so that gdb prints values of type 'bool' symbolically. But if we do | ||
70 | this, values of type '_Bool' may promote to 'int' or 'unsigned int' | 69 | this, values of type '_Bool' may promote to 'int' or 'unsigned int' |
71 | (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' | 70 | (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' |
72 | (see ISO C 99 6.3.1.1.(2)). We could instead try this: | 71 | (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the |
73 | 72 | enum; this ensures that '_Bool' promotes to 'int'. */ | |
74 | typedef enum { _Bool_dummy = -1, false, true } _Bool; | ||
75 | |||
76 | as the negative value ensures that '_Bool' promotes to 'int'. | ||
77 | However, this runs into some other problems. First, Sun's C | ||
78 | compiler when (__SUNPRO_C < 0x550 || __STDC__ == 1) issues a stupid | ||
79 | "warning: _Bool is a keyword in ISO C99". Second, IBM's AIX cc | ||
80 | compiler 6.0.0.0 (and presumably other versions) mishandles | ||
81 | subscripts involving _Bool (effectively, _Bool promotes to unsigned | ||
82 | int in this case), and we need to redefine _Bool in that case. | ||
83 | Third, HP-UX 10.20's C compiler lacks <stdbool.h> but has _Bool and | ||
84 | mishandles comparisons of _Bool to int (it promotes _Bool to | ||
85 | unsigned int). | ||
86 | |||
87 | The simplest way to work around these problems is to ignore any | ||
88 | existing definition of _Bool and use our own. */ | ||
89 | |||
90 | #if defined __cplusplus || defined __BEOS__ | 73 | #if defined __cplusplus || defined __BEOS__ |
74 | /* A compiler known to have 'bool'. */ | ||
75 | /* If the compiler already has both 'bool' and '_Bool', we can assume they | ||
76 | are the same types. */ | ||
91 | # if !@HAVE__BOOL@ | 77 | # if !@HAVE__BOOL@ |
92 | typedef bool _Bool; | 78 | typedef bool _Bool; |
93 | # endif | 79 | # endif |
94 | #else | 80 | #else |
95 | # define _Bool signed char | 81 | # if !defined __GNUC__ |
82 | /* If @HAVE__BOOL@: | ||
83 | Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when | ||
84 | the built-in _Bool type is used. See | ||
85 | http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | ||
86 | http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | ||
87 | http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html | ||
88 | Similar bugs are likely with other compilers as well; this file | ||
89 | wouldn't be used if <stdbool.h> was working. | ||
90 | So we override the _Bool type. | ||
91 | If !@HAVE__BOOL@: | ||
92 | Need to define _Bool ourselves. As 'signed char' or as an enum type? | ||
93 | Use of a typedef, with SunPRO C, leads to a stupid | ||
94 | "warning: _Bool is a keyword in ISO C99". | ||
95 | Use of an enum type, with IRIX cc, leads to a stupid | ||
96 | "warning(1185): enumerated type mixed with another type". | ||
97 | The only benefit of the enum type, debuggability, is not important | ||
98 | with these compilers. So use 'signed char' and no typedef. */ | ||
99 | # define _Bool signed char | ||
100 | enum { false = 0, true = 1 }; | ||
101 | # else | ||
102 | /* With this compiler, trust the _Bool type if the compiler has it. */ | ||
103 | # if !@HAVE__BOOL@ | ||
104 | typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; | ||
105 | # endif | ||
106 | # endif | ||
96 | #endif | 107 | #endif |
97 | |||
98 | #define bool _Bool | 108 | #define bool _Bool |
99 | 109 | ||
100 | /* The other macros must be usable in preprocessor directives. */ | 110 | /* The other macros must be usable in preprocessor directives. */ |
diff --git a/gl/stdint_.h b/gl/stdint_.h new file mode 100644 index 0000000..64ec8c5 --- /dev/null +++ b/gl/stdint_.h | |||
@@ -0,0 +1,489 @@ | |||
1 | /* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. | ||
2 | Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. | ||
3 | This file is part of gnulib. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef _GL_STDINT_H | ||
20 | #define _GL_STDINT_H | ||
21 | |||
22 | /* | ||
23 | * ISO C 99 <stdint.h> for platforms that lack it. | ||
24 | * <http://www.opengroup.org/susv3xbd/stdint.h.html> | ||
25 | */ | ||
26 | |||
27 | /* Get those types that are already defined in other system include | ||
28 | files, so that we can "#define int8_t signed char" below without | ||
29 | worrying about a later system include file containing a "typedef | ||
30 | signed char int8_t;" that will get messed up by our macro. Our | ||
31 | macros should all be consistent with the system versions, except | ||
32 | for the "fast" types and macros, which we recommend against using | ||
33 | in public interfaces due to compiler differences. */ | ||
34 | |||
35 | #if @HAVE_STDINT_H@ | ||
36 | # if defined __sgi && ! defined __c99 | ||
37 | /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users | ||
38 | with "This header file is to be used only for c99 mode compilations" | ||
39 | diagnostics. */ | ||
40 | # define __STDINT_H__ | ||
41 | # endif | ||
42 | /* Other systems may have an incomplete or buggy <stdint.h>. | ||
43 | Include it before <inttypes.h>, since any "#include <stdint.h>" | ||
44 | in <inttypes.h> would reinclude us, skipping our contents because | ||
45 | _GL_STDINT_H is defined. */ | ||
46 | # include @ABSOLUTE_STDINT_H@ | ||
47 | #endif | ||
48 | |||
49 | /* <sys/types.h> defines some of the stdint.h types as well, on glibc, | ||
50 | IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). | ||
51 | AIX 5.2 <sys/types.h> isn't needed and causes troubles. | ||
52 | MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but | ||
53 | relies on the system <stdint.h> definitions, so include | ||
54 | <sys/types.h> after @ABSOLUTE_STDINT_H@. */ | ||
55 | #if @HAVE_SYS_TYPES_H@ && ! defined _AIX | ||
56 | # include <sys/types.h> | ||
57 | #endif | ||
58 | |||
59 | /* Get LONG_MIN, LONG_MAX, ULONG_MAX. */ | ||
60 | #include <limits.h> | ||
61 | |||
62 | #if @HAVE_INTTYPES_H@ | ||
63 | /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines | ||
64 | int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. | ||
65 | <inttypes.h> also defines intptr_t and uintptr_t. */ | ||
66 | # define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H | ||
67 | # include <inttypes.h> | ||
68 | # undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H | ||
69 | #elif @HAVE_SYS_INTTYPES_H@ | ||
70 | /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and | ||
71 | the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ | ||
72 | # include <sys/inttypes.h> | ||
73 | #endif | ||
74 | |||
75 | #if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ | ||
76 | /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines | ||
77 | int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is | ||
78 | included by <sys/types.h>. */ | ||
79 | # include <sys/bitypes.h> | ||
80 | #endif | ||
81 | |||
82 | #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS | ||
83 | |||
84 | /* Get WCHAR_MIN, WCHAR_MAX. */ | ||
85 | # if ! (defined WCHAR_MIN && defined WCHAR_MAX) | ||
86 | # include <wchar.h> | ||
87 | # endif | ||
88 | |||
89 | #endif | ||
90 | |||
91 | /* Minimum and maximum values for a integer type under the usual assumption. | ||
92 | Return an unspecified value if BITS == 0, adding a check to pacify | ||
93 | picky compilers. */ | ||
94 | |||
95 | #define _STDINT_MIN(signed, bits, zero) \ | ||
96 | ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) | ||
97 | |||
98 | #define _STDINT_MAX(signed, bits, zero) \ | ||
99 | ((signed) \ | ||
100 | ? ~ _STDINT_MIN (signed, bits, zero) \ | ||
101 | : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) | ||
102 | |||
103 | /* 7.18.1.1. Exact-width integer types */ | ||
104 | |||
105 | /* Here we assume a standard architecture where the hardware integer | ||
106 | types have 8, 16, 32, optionally 64 bits. */ | ||
107 | |||
108 | #undef int8_t | ||
109 | #undef uint8_t | ||
110 | #define int8_t signed char | ||
111 | #define uint8_t unsigned char | ||
112 | |||
113 | #undef int16_t | ||
114 | #undef uint16_t | ||
115 | #define int16_t short int | ||
116 | #define uint16_t unsigned short int | ||
117 | |||
118 | #undef int32_t | ||
119 | #undef uint32_t | ||
120 | #define int32_t int | ||
121 | #define uint32_t unsigned int | ||
122 | |||
123 | #undef int64_t | ||
124 | #if LONG_MAX >> 31 >> 31 == 1 | ||
125 | # define int64_t long int | ||
126 | #elif defined _MSC_VER | ||
127 | # define int64_t __int64 | ||
128 | #elif @HAVE_LONG_LONG_INT@ | ||
129 | # define int64_t long long int | ||
130 | #endif | ||
131 | |||
132 | #undef uint64_t | ||
133 | #if ULONG_MAX >> 31 >> 31 >> 1 == 1 | ||
134 | # define uint64_t unsigned long int | ||
135 | #elif defined _MSC_VER | ||
136 | # define uint64_t unsigned __int64 | ||
137 | #elif @HAVE_UNSIGNED_LONG_LONG_INT@ | ||
138 | # define uint64_t unsigned long long int | ||
139 | #endif | ||
140 | |||
141 | /* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */ | ||
142 | #define _UINT8_T | ||
143 | #define _UINT32_T | ||
144 | #define _UINT64_T | ||
145 | |||
146 | |||
147 | /* 7.18.1.2. Minimum-width integer types */ | ||
148 | |||
149 | /* Here we assume a standard architecture where the hardware integer | ||
150 | types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types | ||
151 | are the same as the corresponding N_t types. */ | ||
152 | |||
153 | #undef int_least8_t | ||
154 | #undef uint_least8_t | ||
155 | #undef int_least16_t | ||
156 | #undef uint_least16_t | ||
157 | #undef int_least32_t | ||
158 | #undef uint_least32_t | ||
159 | #undef int_least64_t | ||
160 | #undef uint_least64_t | ||
161 | #define int_least8_t int8_t | ||
162 | #define uint_least8_t uint8_t | ||
163 | #define int_least16_t int16_t | ||
164 | #define uint_least16_t uint16_t | ||
165 | #define int_least32_t int32_t | ||
166 | #define uint_least32_t uint32_t | ||
167 | #ifdef int64_t | ||
168 | # define int_least64_t int64_t | ||
169 | #endif | ||
170 | #ifdef uint64_t | ||
171 | # define uint_least64_t uint64_t | ||
172 | #endif | ||
173 | |||
174 | /* 7.18.1.3. Fastest minimum-width integer types */ | ||
175 | |||
176 | /* Note: Other <stdint.h> substitutes may define these types differently. | ||
177 | It is not recommended to use these types in public header files. */ | ||
178 | |||
179 | /* Here we assume a standard architecture where the hardware integer | ||
180 | types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types | ||
181 | are taken from the same list of types. Assume that 'long int' | ||
182 | is fast enough for all narrower integers. */ | ||
183 | |||
184 | #undef int_fast8_t | ||
185 | #undef uint_fast8_t | ||
186 | #undef int_fast16_t | ||
187 | #undef uint_fast16_t | ||
188 | #undef int_fast32_t | ||
189 | #undef uint_fast32_t | ||
190 | #undef int_fast64_t | ||
191 | #undef uint_fast64_t | ||
192 | #define int_fast8_t long int | ||
193 | #define uint_fast8_t unsigned int_fast8_t | ||
194 | #define int_fast16_t long int | ||
195 | #define uint_fast16_t unsigned int_fast16_t | ||
196 | #define int_fast32_t long int | ||
197 | #define uint_fast32_t unsigned int_fast32_t | ||
198 | #ifdef int64_t | ||
199 | # define int_fast64_t int64_t | ||
200 | #endif | ||
201 | #ifdef uint64_t | ||
202 | # define uint_fast64_t uint64_t | ||
203 | #endif | ||
204 | |||
205 | /* 7.18.1.4. Integer types capable of holding object pointers */ | ||
206 | |||
207 | #undef intptr_t | ||
208 | #undef uintptr_t | ||
209 | #define intptr_t long int | ||
210 | #define uintptr_t unsigned long int | ||
211 | |||
212 | /* 7.18.1.5. Greatest-width integer types */ | ||
213 | |||
214 | /* Note: These types are compiler dependent. It may be unwise to use them in | ||
215 | public header files. */ | ||
216 | |||
217 | #undef intmax_t | ||
218 | #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 | ||
219 | # define intmax_t long long int | ||
220 | #elif defined int64_t | ||
221 | # define intmax_t int64_t | ||
222 | #else | ||
223 | # define intmax_t long int | ||
224 | #endif | ||
225 | |||
226 | #undef uintmax_t | ||
227 | #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 | ||
228 | # define uintmax_t unsigned long long int | ||
229 | #elif defined uint64_t | ||
230 | # define uintmax_t uint64_t | ||
231 | #else | ||
232 | # define uintmax_t unsigned long int | ||
233 | #endif | ||
234 | |||
235 | /* 7.18.2. Limits of specified-width integer types */ | ||
236 | |||
237 | #if ! defined __cplusplus || defined __STDC_LIMIT_MACROS | ||
238 | |||
239 | /* 7.18.2.1. Limits of exact-width integer types */ | ||
240 | |||
241 | /* Here we assume a standard architecture where the hardware integer | ||
242 | types have 8, 16, 32, optionally 64 bits. */ | ||
243 | |||
244 | #undef INT8_MIN | ||
245 | #undef INT8_MAX | ||
246 | #undef UINT8_MAX | ||
247 | #define INT8_MIN (~ INT8_MAX) | ||
248 | #define INT8_MAX 127 | ||
249 | #define UINT8_MAX 255 | ||
250 | |||
251 | #undef INT16_MIN | ||
252 | #undef INT16_MAX | ||
253 | #undef UINT16_MAX | ||
254 | #define INT16_MIN (~ INT16_MAX) | ||
255 | #define INT16_MAX 32767 | ||
256 | #define UINT16_MAX 65535 | ||
257 | |||
258 | #undef INT32_MIN | ||
259 | #undef INT32_MAX | ||
260 | #undef UINT32_MAX | ||
261 | #define INT32_MIN (~ INT32_MAX) | ||
262 | #define INT32_MAX 2147483647 | ||
263 | #define UINT32_MAX 4294967295U | ||
264 | |||
265 | #undef INT64_MIN | ||
266 | #undef INT64_MAX | ||
267 | #ifdef int64_t | ||
268 | # define INT64_MIN (~ INT64_MAX) | ||
269 | # define INT64_MAX INTMAX_C (9223372036854775807) | ||
270 | #endif | ||
271 | |||
272 | #undef UINT64_MAX | ||
273 | #ifdef uint64_t | ||
274 | # define UINT64_MAX UINTMAX_C (18446744073709551615) | ||
275 | #endif | ||
276 | |||
277 | /* 7.18.2.2. Limits of minimum-width integer types */ | ||
278 | |||
279 | /* Here we assume a standard architecture where the hardware integer | ||
280 | types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types | ||
281 | are the same as the corresponding N_t types. */ | ||
282 | |||
283 | #undef INT_LEAST8_MIN | ||
284 | #undef INT_LEAST8_MAX | ||
285 | #undef UINT_LEAST8_MAX | ||
286 | #define INT_LEAST8_MIN INT8_MIN | ||
287 | #define INT_LEAST8_MAX INT8_MAX | ||
288 | #define UINT_LEAST8_MAX UINT8_MAX | ||
289 | |||
290 | #undef INT_LEAST16_MIN | ||
291 | #undef INT_LEAST16_MAX | ||
292 | #undef UINT_LEAST16_MAX | ||
293 | #define INT_LEAST16_MIN INT16_MIN | ||
294 | #define INT_LEAST16_MAX INT16_MAX | ||
295 | #define UINT_LEAST16_MAX UINT16_MAX | ||
296 | |||
297 | #undef INT_LEAST32_MIN | ||
298 | #undef INT_LEAST32_MAX | ||
299 | #undef UINT_LEAST32_MAX | ||
300 | #define INT_LEAST32_MIN INT32_MIN | ||
301 | #define INT_LEAST32_MAX INT32_MAX | ||
302 | #define UINT_LEAST32_MAX UINT32_MAX | ||
303 | |||
304 | #undef INT_LEAST64_MIN | ||
305 | #undef INT_LEAST64_MAX | ||
306 | #ifdef int64_t | ||
307 | # define INT_LEAST64_MIN INT64_MIN | ||
308 | # define INT_LEAST64_MAX INT64_MAX | ||
309 | #endif | ||
310 | |||
311 | #undef UINT_LEAST64_MAX | ||
312 | #ifdef uint64_t | ||
313 | # define UINT_LEAST64_MAX UINT64_MAX | ||
314 | #endif | ||
315 | |||
316 | /* 7.18.2.3. Limits of fastest minimum-width integer types */ | ||
317 | |||
318 | /* Here we assume a standard architecture where the hardware integer | ||
319 | types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types | ||
320 | are taken from the same list of types. */ | ||
321 | |||
322 | #undef INT_FAST8_MIN | ||
323 | #undef INT_FAST8_MAX | ||
324 | #undef UINT_FAST8_MAX | ||
325 | #define INT_FAST8_MIN LONG_MIN | ||
326 | #define INT_FAST8_MAX LONG_MAX | ||
327 | #define UINT_FAST8_MAX ULONG_MAX | ||
328 | |||
329 | #undef INT_FAST16_MIN | ||
330 | #undef INT_FAST16_MAX | ||
331 | #undef UINT_FAST16_MAX | ||
332 | #define INT_FAST16_MIN LONG_MIN | ||
333 | #define INT_FAST16_MAX LONG_MAX | ||
334 | #define UINT_FAST16_MAX ULONG_MAX | ||
335 | |||
336 | #undef INT_FAST32_MIN | ||
337 | #undef INT_FAST32_MAX | ||
338 | #undef UINT_FAST32_MAX | ||
339 | #define INT_FAST32_MIN LONG_MIN | ||
340 | #define INT_FAST32_MAX LONG_MAX | ||
341 | #define UINT_FAST32_MAX ULONG_MAX | ||
342 | |||
343 | #undef INT_FAST64_MIN | ||
344 | #undef INT_FAST64_MAX | ||
345 | #ifdef int64_t | ||
346 | # define INT_FAST64_MIN INT64_MIN | ||
347 | # define INT_FAST64_MAX INT64_MAX | ||
348 | #endif | ||
349 | |||
350 | #undef UINT_FAST64_MAX | ||
351 | #ifdef uint64_t | ||
352 | # define UINT_FAST64_MAX UINT64_MAX | ||
353 | #endif | ||
354 | |||
355 | /* 7.18.2.4. Limits of integer types capable of holding object pointers */ | ||
356 | |||
357 | #undef INTPTR_MIN | ||
358 | #undef INTPTR_MAX | ||
359 | #undef UINTPTR_MAX | ||
360 | #define INTPTR_MIN LONG_MIN | ||
361 | #define INTPTR_MAX LONG_MAX | ||
362 | #define UINTPTR_MAX ULONG_MAX | ||
363 | |||
364 | /* 7.18.2.5. Limits of greatest-width integer types */ | ||
365 | |||
366 | #undef INTMAX_MIN | ||
367 | #undef INTMAX_MAX | ||
368 | #define INTMAX_MIN (~ INTMAX_MAX) | ||
369 | #ifdef INT64_MAX | ||
370 | # define INTMAX_MAX INT64_MAX | ||
371 | #else | ||
372 | # define INTMAX_MAX INT32_MAX | ||
373 | #endif | ||
374 | |||
375 | #undef UINTMAX_MAX | ||
376 | #ifdef UINT64_MAX | ||
377 | # define UINTMAX_MAX UINT64_MAX | ||
378 | #else | ||
379 | # define UINTMAX_MAX UINT32_MAX | ||
380 | #endif | ||
381 | |||
382 | /* 7.18.3. Limits of other integer types */ | ||
383 | |||
384 | /* ptrdiff_t limits */ | ||
385 | #undef PTRDIFF_MIN | ||
386 | #undef PTRDIFF_MAX | ||
387 | #define PTRDIFF_MIN \ | ||
388 | _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) | ||
389 | #define PTRDIFF_MAX \ | ||
390 | _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) | ||
391 | |||
392 | /* sig_atomic_t limits */ | ||
393 | #undef SIG_ATOMIC_MIN | ||
394 | #undef SIG_ATOMIC_MAX | ||
395 | #define SIG_ATOMIC_MIN \ | ||
396 | _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ | ||
397 | 0@SIG_ATOMIC_T_SUFFIX@) | ||
398 | #define SIG_ATOMIC_MAX \ | ||
399 | _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ | ||
400 | 0@SIG_ATOMIC_T_SUFFIX@) | ||
401 | |||
402 | |||
403 | /* size_t limit */ | ||
404 | #undef SIZE_MAX | ||
405 | #define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) | ||
406 | |||
407 | /* wchar_t limits */ | ||
408 | #undef WCHAR_MIN | ||
409 | #undef WCHAR_MAX | ||
410 | #define WCHAR_MIN \ | ||
411 | _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) | ||
412 | #define WCHAR_MAX \ | ||
413 | _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) | ||
414 | |||
415 | /* wint_t limits */ | ||
416 | #undef WINT_MIN | ||
417 | #undef WINT_MAX | ||
418 | #define WINT_MIN \ | ||
419 | _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) | ||
420 | #define WINT_MAX \ | ||
421 | _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) | ||
422 | |||
423 | #endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */ | ||
424 | |||
425 | /* 7.18.4. Macros for integer constants */ | ||
426 | |||
427 | #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS | ||
428 | |||
429 | /* 7.18.4.1. Macros for minimum-width integer constants */ | ||
430 | /* According to ISO C 99 Technical Corrigendum 1 */ | ||
431 | |||
432 | /* Here we assume a standard architecture where the hardware integer | ||
433 | types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ | ||
434 | |||
435 | #undef INT8_C | ||
436 | #undef UINT8_C | ||
437 | #define INT8_C(x) x | ||
438 | #define UINT8_C(x) x | ||
439 | |||
440 | #undef INT16_C | ||
441 | #undef UINT16_C | ||
442 | #define INT16_C(x) x | ||
443 | #define UINT16_C(x) x | ||
444 | |||
445 | #undef INT32_C | ||
446 | #undef UINT32_C | ||
447 | #define INT32_C(x) x | ||
448 | #define UINT32_C(x) x ## U | ||
449 | |||
450 | #undef INT64_C | ||
451 | #undef UINT64_C | ||
452 | #if LONG_MAX >> 31 >> 31 == 1 | ||
453 | # define INT64_C(x) x##L | ||
454 | #elif defined _MSC_VER | ||
455 | # define INT64_C(x) x##i64 | ||
456 | #elif @HAVE_LONG_LONG_INT@ | ||
457 | # define INT64_C(x) x##LL | ||
458 | #endif | ||
459 | #if ULONG_MAX >> 31 >> 31 >> 1 == 1 | ||
460 | # define UINT64_C(x) x##UL | ||
461 | #elif defined _MSC_VER | ||
462 | # define UINT64_C(x) x##ui64 | ||
463 | #elif @HAVE_UNSIGNED_LONG_LONG_INT@ | ||
464 | # define UINT64_C(x) x##ULL | ||
465 | #endif | ||
466 | |||
467 | /* 7.18.4.2. Macros for greatest-width integer constants */ | ||
468 | |||
469 | #undef INTMAX_C | ||
470 | #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 | ||
471 | # define INTMAX_C(x) x##LL | ||
472 | #elif defined int64_t | ||
473 | # define INTMAX_C(x) INT64_C(x) | ||
474 | #else | ||
475 | # define INTMAX_C(x) x##L | ||
476 | #endif | ||
477 | |||
478 | #undef UINTMAX_C | ||
479 | #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 | ||
480 | # define UINTMAX_C(x) x##ULL | ||
481 | #elif defined uint64_t | ||
482 | # define UINTMAX_C(x) UINT64_C(x) | ||
483 | #else | ||
484 | # define UINTMAX_C(x) x##UL | ||
485 | #endif | ||
486 | |||
487 | #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ | ||
488 | |||
489 | #endif /* _GL_STDINT_H */ | ||
diff --git a/lib/strcase.h b/gl/strcase.h index e420798..07d4c9a 100644 --- a/lib/strcase.h +++ b/gl/strcase.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Case-insensitive string comparison functions. | 1 | /* Case-insensitive string comparison functions. |
2 | Copyright (C) 1995-1996, 2001, 2003, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1995-1996, 2001, 2003, 2005-2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -19,13 +19,19 @@ | |||
19 | #define _STRCASE_H | 19 | #define _STRCASE_H |
20 | 20 | ||
21 | #include <stddef.h> | 21 | #include <stddef.h> |
22 | 22 | /* Include header files with a possibly conflicting declarations of strcasecmp | |
23 | before we define it as a macro, so that they will be no-ops if included | ||
24 | after strcasecmp is defined as a macro. */ | ||
25 | #include <string.h> | ||
23 | 26 | ||
24 | #ifdef __cplusplus | 27 | #ifdef __cplusplus |
25 | extern "C" { | 28 | extern "C" { |
26 | #endif | 29 | #endif |
27 | 30 | ||
28 | 31 | ||
32 | /* No known system has a strcasecmp() function that works correctly in | ||
33 | multibyte locales. Therefore we use our version always. */ | ||
34 | #define strcasecmp rpl_strcasecmp | ||
29 | /* Compare strings S1 and S2, ignoring case, returning less than, equal to or | 35 | /* Compare strings S1 and S2, ignoring case, returning less than, equal to or |
30 | greater than zero if S1 is lexicographically less than, equal to or greater | 36 | greater than zero if S1 is lexicographically less than, equal to or greater |
31 | than S2. | 37 | than S2. |
@@ -37,7 +43,9 @@ extern int strcasecmp (const char *s1, const char *s2); | |||
37 | returning less than, equal to or greater than zero if S1 is | 43 | returning less than, equal to or greater than zero if S1 is |
38 | lexicographically less than, equal to or greater than S2. | 44 | lexicographically less than, equal to or greater than S2. |
39 | Note: This function can not work correctly in multibyte locales. */ | 45 | Note: This function can not work correctly in multibyte locales. */ |
46 | #if ! HAVE_DECL_STRNCASECMP | ||
40 | extern int strncasecmp (const char *s1, const char *s2, size_t n); | 47 | extern int strncasecmp (const char *s1, const char *s2, size_t n); |
48 | #endif | ||
41 | 49 | ||
42 | 50 | ||
43 | #ifdef __cplusplus | 51 | #ifdef __cplusplus |
diff --git a/gl/strcasecmp.c b/gl/strcasecmp.c new file mode 100644 index 0000000..99d5dd2 --- /dev/null +++ b/gl/strcasecmp.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* Case-insensitive string comparison function. | ||
2 | Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. | ||
3 | Written by Bruno Haible <bruno@clisp.org>, 2005, | ||
4 | based on earlier glibc code. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #include <config.h> | ||
21 | |||
22 | /* Specification. */ | ||
23 | #include "strcase.h" | ||
24 | |||
25 | #include <ctype.h> | ||
26 | #include <limits.h> | ||
27 | |||
28 | #if HAVE_MBRTOWC | ||
29 | # include "mbuiter.h" | ||
30 | #endif | ||
31 | |||
32 | #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) | ||
33 | |||
34 | /* Compare strings S1 and S2, ignoring case, returning less than, equal to or | ||
35 | greater than zero if S1 is lexicographically less than, equal to or greater | ||
36 | than S2. | ||
37 | Note: This function may, in multibyte locales, return 0 for strings of | ||
38 | different lengths! */ | ||
39 | int | ||
40 | strcasecmp (const char *s1, const char *s2) | ||
41 | { | ||
42 | if (s1 == s2) | ||
43 | return 0; | ||
44 | |||
45 | /* Be careful not to look at the entire extent of s1 or s2 until needed. | ||
46 | This is useful because when two strings differ, the difference is | ||
47 | most often already in the very few first characters. */ | ||
48 | #if HAVE_MBRTOWC | ||
49 | if (MB_CUR_MAX > 1) | ||
50 | { | ||
51 | mbui_iterator_t iter1; | ||
52 | mbui_iterator_t iter2; | ||
53 | |||
54 | mbui_init (iter1, s1); | ||
55 | mbui_init (iter2, s2); | ||
56 | |||
57 | while (mbui_avail (iter1) && mbui_avail (iter2)) | ||
58 | { | ||
59 | int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); | ||
60 | |||
61 | if (cmp != 0) | ||
62 | return cmp; | ||
63 | |||
64 | mbui_advance (iter1); | ||
65 | mbui_advance (iter2); | ||
66 | } | ||
67 | if (mbui_avail (iter1)) | ||
68 | /* s2 terminated before s1. */ | ||
69 | return 1; | ||
70 | if (mbui_avail (iter2)) | ||
71 | /* s1 terminated before s2. */ | ||
72 | return -1; | ||
73 | return 0; | ||
74 | } | ||
75 | else | ||
76 | #endif | ||
77 | { | ||
78 | const unsigned char *p1 = (const unsigned char *) s1; | ||
79 | const unsigned char *p2 = (const unsigned char *) s2; | ||
80 | unsigned char c1, c2; | ||
81 | |||
82 | do | ||
83 | { | ||
84 | c1 = TOLOWER (*p1); | ||
85 | c2 = TOLOWER (*p2); | ||
86 | |||
87 | if (c1 == '\0') | ||
88 | break; | ||
89 | |||
90 | ++p1; | ||
91 | ++p2; | ||
92 | } | ||
93 | while (c1 == c2); | ||
94 | |||
95 | if (UCHAR_MAX <= INT_MAX) | ||
96 | return c1 - c2; | ||
97 | else | ||
98 | /* On machines where 'char' and 'int' are types of the same size, the | ||
99 | difference of two 'unsigned char' values - including the sign bit - | ||
100 | doesn't fit in an 'int'. */ | ||
101 | return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); | ||
102 | } | ||
103 | } | ||
diff --git a/gl/strdup.c b/gl/strdup.c new file mode 100644 index 0000000..17d40d6 --- /dev/null +++ b/gl/strdup.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006 Free | ||
2 | Software Foundation, Inc. | ||
3 | |||
4 | This file is part of the GNU C Library. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License along | ||
17 | with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifndef _LIBC | ||
21 | # include <config.h> | ||
22 | /* Get specification. */ | ||
23 | # include "strdup.h" | ||
24 | #endif | ||
25 | |||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #undef __strdup | ||
30 | #ifdef _LIBC | ||
31 | # undef strdup | ||
32 | #endif | ||
33 | |||
34 | #ifndef weak_alias | ||
35 | # define __strdup strdup | ||
36 | #endif | ||
37 | |||
38 | /* Duplicate S, returning an identical malloc'd string. */ | ||
39 | char * | ||
40 | __strdup (const char *s) | ||
41 | { | ||
42 | size_t len = strlen (s) + 1; | ||
43 | void *new = malloc (len); | ||
44 | |||
45 | if (new == NULL) | ||
46 | return NULL; | ||
47 | |||
48 | return (char *) memcpy (new, s, len); | ||
49 | } | ||
50 | #ifdef libc_hidden_def | ||
51 | libc_hidden_def (__strdup) | ||
52 | #endif | ||
53 | #ifdef weak_alias | ||
54 | weak_alias (__strdup, strdup) | ||
55 | #endif | ||
diff --git a/gl/strdup.h b/gl/strdup.h new file mode 100644 index 0000000..73e66e3 --- /dev/null +++ b/gl/strdup.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* strdup.h -- duplicate a string | ||
2 | Copyright (C) 2004, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef STRDUP_H_ | ||
19 | #define STRDUP_H_ | ||
20 | |||
21 | /* Get strdup declaration, if available. */ | ||
22 | #include <string.h> | ||
23 | |||
24 | #ifdef __cplusplus | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | |||
29 | #if defined HAVE_DECL_STRDUP && !HAVE_DECL_STRDUP && !defined strdup | ||
30 | /* Duplicate S, returning an identical malloc'd string. */ | ||
31 | extern char *strdup (const char *s); | ||
32 | #endif | ||
33 | |||
34 | |||
35 | #ifdef __cplusplus | ||
36 | } | ||
37 | #endif | ||
38 | |||
39 | #endif /* STRDUP_H_ */ | ||
diff --git a/gl/stripslash.c b/gl/stripslash.c new file mode 100644 index 0000000..342d497 --- /dev/null +++ b/gl/stripslash.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* stripslash.c -- remove redundant trailing slashes from a file name | ||
2 | |||
3 | Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #include <config.h> | ||
20 | |||
21 | #include "dirname.h" | ||
22 | |||
23 | /* Remove trailing slashes from FILE. Return true if a trailing slash | ||
24 | was removed. This is useful when using file name completion from a | ||
25 | shell that adds a "/" after directory names (such as tcsh and | ||
26 | bash), because on symlinks to directories, several system calls | ||
27 | have different semantics according to whether a trailing slash is | ||
28 | present. */ | ||
29 | |||
30 | bool | ||
31 | strip_trailing_slashes (char *file) | ||
32 | { | ||
33 | char *base = last_component (file); | ||
34 | char *base_lim; | ||
35 | bool had_slash; | ||
36 | |||
37 | /* last_component returns "" for file system roots, but we need to turn | ||
38 | `///' into `/'. */ | ||
39 | if (! *base) | ||
40 | base = file; | ||
41 | base_lim = base + base_len (base); | ||
42 | had_slash = (*base_lim != '\0'); | ||
43 | *base_lim = '\0'; | ||
44 | return had_slash; | ||
45 | } | ||
diff --git a/gl/strncasecmp.c b/gl/strncasecmp.c new file mode 100644 index 0000000..f59b953 --- /dev/null +++ b/gl/strncasecmp.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* strncasecmp.c -- case insensitive string comparator | ||
2 | Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "strcase.h" | ||
22 | |||
23 | #include <ctype.h> | ||
24 | #include <limits.h> | ||
25 | |||
26 | #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) | ||
27 | |||
28 | /* Compare no more than N bytes of strings S1 and S2, | ||
29 | ignoring case, returning less than, equal to or | ||
30 | greater than zero if S1 is lexicographically less | ||
31 | than, equal to or greater than S2. */ | ||
32 | |||
33 | int | ||
34 | strncasecmp (const char *s1, const char *s2, size_t n) | ||
35 | { | ||
36 | register const unsigned char *p1 = (const unsigned char *) s1; | ||
37 | register const unsigned char *p2 = (const unsigned char *) s2; | ||
38 | unsigned char c1, c2; | ||
39 | |||
40 | if (p1 == p2 || n == 0) | ||
41 | return 0; | ||
42 | |||
43 | do | ||
44 | { | ||
45 | c1 = TOLOWER (*p1); | ||
46 | c2 = TOLOWER (*p2); | ||
47 | |||
48 | if (--n == 0 || c1 == '\0') | ||
49 | break; | ||
50 | |||
51 | ++p1; | ||
52 | ++p2; | ||
53 | } | ||
54 | while (c1 == c2); | ||
55 | |||
56 | if (UCHAR_MAX <= INT_MAX) | ||
57 | return c1 - c2; | ||
58 | else | ||
59 | /* On machines where 'char' and 'int' are types of the same size, the | ||
60 | difference of two 'unsigned char' values - including the sign bit - | ||
61 | doesn't fit in an 'int'. */ | ||
62 | return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); | ||
63 | } | ||
diff --git a/gl/strndup.c b/gl/strndup.c new file mode 100644 index 0000000..290f494 --- /dev/null +++ b/gl/strndup.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* A replacement function, for systems that lack strndup. | ||
2 | |||
3 | Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free | ||
4 | Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms of the GNU General Public License as published by the | ||
8 | Free Software Foundation; either version 2, or (at your option) any | ||
9 | later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #include <config.h> | ||
21 | #include "strndup.h" | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | #include "strnlen.h" | ||
27 | |||
28 | char * | ||
29 | strndup (char const *s, size_t n) | ||
30 | { | ||
31 | size_t len = strnlen (s, n); | ||
32 | char *new = malloc (len + 1); | ||
33 | |||
34 | if (new == NULL) | ||
35 | return NULL; | ||
36 | |||
37 | new[len] = '\0'; | ||
38 | return memcpy (new, s, len); | ||
39 | } | ||
diff --git a/gl/strndup.h b/gl/strndup.h new file mode 100644 index 0000000..b983dd2 --- /dev/null +++ b/gl/strndup.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* Duplicate a size-bounded string. | ||
2 | Copyright (C) 2003, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Get size_t. */ | ||
19 | #include <stddef.h> | ||
20 | /* If HAVE_STRNDUP, get the strndup declaration. | ||
21 | If !HAVE_STRNDUP, include <string.h> now so that it doesn't cause | ||
22 | trouble if included later. */ | ||
23 | #include <string.h> | ||
24 | |||
25 | #if !HAVE_STRNDUP | ||
26 | # undef strndup | ||
27 | # define strndup rpl_strndup | ||
28 | # if !HAVE_DECL_STRNDUP /* Don't risk conflicting declarations. */ | ||
29 | /* Return a newly allocated copy of at most N bytes of STRING. */ | ||
30 | extern char *strndup (const char *string, size_t n); | ||
31 | # endif | ||
32 | #endif | ||
diff --git a/gl/strnlen.c b/gl/strnlen.c new file mode 100644 index 0000000..593fd1b --- /dev/null +++ b/gl/strnlen.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* Find the length of STRING, but scan at most MAXLEN characters. | ||
2 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #include <config.h> | ||
20 | |||
21 | #include "strnlen.h" | ||
22 | |||
23 | /* Find the length of STRING, but scan at most MAXLEN characters. | ||
24 | If no '\0' terminator is found in that many characters, return MAXLEN. */ | ||
25 | |||
26 | size_t | ||
27 | strnlen (const char *string, size_t maxlen) | ||
28 | { | ||
29 | const char *end = memchr (string, '\0', maxlen); | ||
30 | return end ? (size_t) (end - string) : maxlen; | ||
31 | } | ||
diff --git a/gl/strnlen.h b/gl/strnlen.h new file mode 100644 index 0000000..ba74dba --- /dev/null +++ b/gl/strnlen.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* Find the length of STRING, but scan at most MAXLEN characters. | ||
2 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef STRNLEN_H | ||
20 | #define STRNLEN_H | ||
21 | |||
22 | /* Get strnlen declaration, if available. */ | ||
23 | #include <string.h> | ||
24 | |||
25 | #if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN | ||
26 | /* Find the length (number of bytes) of STRING, but scan at most | ||
27 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, | ||
28 | return MAXLEN. */ | ||
29 | extern size_t strnlen(const char *string, size_t maxlen); | ||
30 | #endif | ||
31 | |||
32 | #endif /* STRNLEN_H */ | ||
diff --git a/gl/strnlen1.c b/gl/strnlen1.c new file mode 100644 index 0000000..422ed9e --- /dev/null +++ b/gl/strnlen1.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /* Find the length of STRING + 1, but scan at most MAXLEN bytes. | ||
2 | Copyright (C) 2005-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "strnlen1.h" | ||
22 | |||
23 | #include <string.h> | ||
24 | |||
25 | /* Find the length of STRING + 1, but scan at most MAXLEN bytes. | ||
26 | If no '\0' terminator is found in that many characters, return MAXLEN. */ | ||
27 | /* This is the same as strnlen (string, maxlen - 1) + 1. */ | ||
28 | size_t | ||
29 | strnlen1 (const char *string, size_t maxlen) | ||
30 | { | ||
31 | const char *end = (const char *) memchr (string, '\0', maxlen); | ||
32 | if (end != NULL) | ||
33 | return end - string + 1; | ||
34 | else | ||
35 | return maxlen; | ||
36 | } | ||
diff --git a/gl/strnlen1.h b/gl/strnlen1.h new file mode 100644 index 0000000..7ce7d0c --- /dev/null +++ b/gl/strnlen1.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* Find the length of STRING + 1, but scan at most MAXLEN bytes. | ||
2 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _STRNLEN1_H | ||
19 | #define _STRNLEN1_H | ||
20 | |||
21 | #include <stddef.h> | ||
22 | |||
23 | |||
24 | #ifdef __cplusplus | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | |||
29 | /* Find the length of STRING + 1, but scan at most MAXLEN bytes. | ||
30 | If no '\0' terminator is found in that many characters, return MAXLEN. */ | ||
31 | /* This is the same as strnlen (string, maxlen - 1) + 1. */ | ||
32 | extern size_t strnlen1 (const char *string, size_t maxlen); | ||
33 | |||
34 | |||
35 | #ifdef __cplusplus | ||
36 | } | ||
37 | #endif | ||
38 | |||
39 | |||
40 | #endif /* _STRNLEN1_H */ | ||
diff --git a/lib/unistd--.h b/gl/unistd--.h index 1fe6ce8..1fe6ce8 100644 --- a/lib/unistd--.h +++ b/gl/unistd--.h | |||
diff --git a/lib/unistd-safer.h b/gl/unistd-safer.h index f95999d..f95999d 100644 --- a/lib/unistd-safer.h +++ b/gl/unistd-safer.h | |||
diff --git a/gl/unistd_.h b/gl/unistd_.h new file mode 100644 index 0000000..36fa673 --- /dev/null +++ b/gl/unistd_.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* Substitute for and wrapper around <unistd.h>. | ||
2 | Copyright (C) 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _GL_UNISTD_H | ||
19 | #define _GL_UNISTD_H | ||
20 | |||
21 | #if HAVE_UNISTD_H | ||
22 | # include @ABSOLUTE_UNISTD_H@ | ||
23 | #endif | ||
24 | |||
25 | |||
26 | /* Declare overridden functions. */ | ||
27 | |||
28 | #ifdef __cplusplus | ||
29 | extern "C" { | ||
30 | #endif | ||
31 | |||
32 | #ifdef FCHDIR_REPLACEMENT | ||
33 | |||
34 | /* Change the process' current working directory to the directory on which | ||
35 | the given file descriptor is open. */ | ||
36 | extern int fchdir (int /*fd*/); | ||
37 | |||
38 | # define close rpl_close | ||
39 | extern int close (int); | ||
40 | # define dup rpl_dup | ||
41 | extern int dup (int); | ||
42 | # define dup2 rpl_dup2 | ||
43 | extern int dup2 (int, int); | ||
44 | |||
45 | #endif | ||
46 | |||
47 | #ifdef __cplusplus | ||
48 | } | ||
49 | #endif | ||
50 | |||
51 | |||
52 | #endif /* _GL_UNISTD_H */ | ||
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c new file mode 100644 index 0000000..0fe2aad --- /dev/null +++ b/gl/vasnprintf.c | |||
@@ -0,0 +1,889 @@ | |||
1 | /* vsprintf with automatic memory allocation. | ||
2 | Copyright (C) 1999, 2002-2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Tell glibc's <stdio.h> to provide a prototype for snprintf(). | ||
19 | This must come before <config.h> because <config.h> may include | ||
20 | <features.h>, and once <features.h> has been included, it's too late. */ | ||
21 | #ifndef _GNU_SOURCE | ||
22 | # define _GNU_SOURCE 1 | ||
23 | #endif | ||
24 | |||
25 | #include <config.h> | ||
26 | #ifndef IN_LIBINTL | ||
27 | # include <alloca.h> | ||
28 | #endif | ||
29 | |||
30 | /* Specification. */ | ||
31 | #if WIDE_CHAR_VERSION | ||
32 | # include "vasnwprintf.h" | ||
33 | #else | ||
34 | # include "vasnprintf.h" | ||
35 | #endif | ||
36 | |||
37 | #include <stdio.h> /* snprintf(), sprintf() */ | ||
38 | #include <stdlib.h> /* abort(), malloc(), realloc(), free() */ | ||
39 | #include <string.h> /* memcpy(), strlen() */ | ||
40 | #include <errno.h> /* errno */ | ||
41 | #include <limits.h> /* CHAR_BIT */ | ||
42 | #include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ | ||
43 | #if WIDE_CHAR_VERSION | ||
44 | # include "wprintf-parse.h" | ||
45 | #else | ||
46 | # include "printf-parse.h" | ||
47 | #endif | ||
48 | |||
49 | /* Checked size_t computations. */ | ||
50 | #include "xsize.h" | ||
51 | |||
52 | #ifdef HAVE_WCHAR_T | ||
53 | # ifdef HAVE_WCSLEN | ||
54 | # define local_wcslen wcslen | ||
55 | # else | ||
56 | /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid | ||
57 | a dependency towards this library, here is a local substitute. | ||
58 | Define this substitute only once, even if this file is included | ||
59 | twice in the same compilation unit. */ | ||
60 | # ifndef local_wcslen_defined | ||
61 | # define local_wcslen_defined 1 | ||
62 | static size_t | ||
63 | local_wcslen (const wchar_t *s) | ||
64 | { | ||
65 | const wchar_t *ptr; | ||
66 | |||
67 | for (ptr = s; *ptr != (wchar_t) 0; ptr++) | ||
68 | ; | ||
69 | return ptr - s; | ||
70 | } | ||
71 | # endif | ||
72 | # endif | ||
73 | #endif | ||
74 | |||
75 | #if WIDE_CHAR_VERSION | ||
76 | # define VASNPRINTF vasnwprintf | ||
77 | # define CHAR_T wchar_t | ||
78 | # define DIRECTIVE wchar_t_directive | ||
79 | # define DIRECTIVES wchar_t_directives | ||
80 | # define PRINTF_PARSE wprintf_parse | ||
81 | # define USE_SNPRINTF 1 | ||
82 | # if HAVE_DECL__SNWPRINTF | ||
83 | /* On Windows, the function swprintf() has a different signature than | ||
84 | on Unix; we use the _snwprintf() function instead. */ | ||
85 | # define SNPRINTF _snwprintf | ||
86 | # else | ||
87 | /* Unix. */ | ||
88 | # define SNPRINTF swprintf | ||
89 | # endif | ||
90 | #else | ||
91 | # define VASNPRINTF vasnprintf | ||
92 | # define CHAR_T char | ||
93 | # define DIRECTIVE char_directive | ||
94 | # define DIRECTIVES char_directives | ||
95 | # define PRINTF_PARSE printf_parse | ||
96 | # define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) | ||
97 | # if HAVE_DECL__SNPRINTF | ||
98 | /* Windows. */ | ||
99 | # define SNPRINTF _snprintf | ||
100 | # else | ||
101 | /* Unix. */ | ||
102 | # define SNPRINTF snprintf | ||
103 | # endif | ||
104 | #endif | ||
105 | |||
106 | CHAR_T * | ||
107 | VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) | ||
108 | { | ||
109 | DIRECTIVES d; | ||
110 | arguments a; | ||
111 | |||
112 | if (PRINTF_PARSE (format, &d, &a) < 0) | ||
113 | { | ||
114 | errno = EINVAL; | ||
115 | return NULL; | ||
116 | } | ||
117 | |||
118 | #define CLEANUP() \ | ||
119 | free (d.dir); \ | ||
120 | if (a.arg) \ | ||
121 | free (a.arg); | ||
122 | |||
123 | if (printf_fetchargs (args, &a) < 0) | ||
124 | { | ||
125 | CLEANUP (); | ||
126 | errno = EINVAL; | ||
127 | return NULL; | ||
128 | } | ||
129 | |||
130 | { | ||
131 | size_t buf_neededlength; | ||
132 | CHAR_T *buf; | ||
133 | CHAR_T *buf_malloced; | ||
134 | const CHAR_T *cp; | ||
135 | size_t i; | ||
136 | DIRECTIVE *dp; | ||
137 | /* Output string accumulator. */ | ||
138 | CHAR_T *result; | ||
139 | size_t allocated; | ||
140 | size_t length; | ||
141 | |||
142 | /* Allocate a small buffer that will hold a directive passed to | ||
143 | sprintf or snprintf. */ | ||
144 | buf_neededlength = | ||
145 | xsum4 (7, d.max_width_length, d.max_precision_length, 6); | ||
146 | #if HAVE_ALLOCA | ||
147 | if (buf_neededlength < 4000 / sizeof (CHAR_T)) | ||
148 | { | ||
149 | buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); | ||
150 | buf_malloced = NULL; | ||
151 | } | ||
152 | else | ||
153 | #endif | ||
154 | { | ||
155 | size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T)); | ||
156 | if (size_overflow_p (buf_memsize)) | ||
157 | goto out_of_memory_1; | ||
158 | buf = (CHAR_T *) malloc (buf_memsize); | ||
159 | if (buf == NULL) | ||
160 | goto out_of_memory_1; | ||
161 | buf_malloced = buf; | ||
162 | } | ||
163 | |||
164 | if (resultbuf != NULL) | ||
165 | { | ||
166 | result = resultbuf; | ||
167 | allocated = *lengthp; | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | result = NULL; | ||
172 | allocated = 0; | ||
173 | } | ||
174 | length = 0; | ||
175 | /* Invariants: | ||
176 | result is either == resultbuf or == NULL or malloc-allocated. | ||
177 | If length > 0, then result != NULL. */ | ||
178 | |||
179 | /* Ensures that allocated >= needed. Aborts through a jump to | ||
180 | out_of_memory if needed is SIZE_MAX or otherwise too big. */ | ||
181 | #define ENSURE_ALLOCATION(needed) \ | ||
182 | if ((needed) > allocated) \ | ||
183 | { \ | ||
184 | size_t memory_size; \ | ||
185 | CHAR_T *memory; \ | ||
186 | \ | ||
187 | allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ | ||
188 | if ((needed) > allocated) \ | ||
189 | allocated = (needed); \ | ||
190 | memory_size = xtimes (allocated, sizeof (CHAR_T)); \ | ||
191 | if (size_overflow_p (memory_size)) \ | ||
192 | goto out_of_memory; \ | ||
193 | if (result == resultbuf || result == NULL) \ | ||
194 | memory = (CHAR_T *) malloc (memory_size); \ | ||
195 | else \ | ||
196 | memory = (CHAR_T *) realloc (result, memory_size); \ | ||
197 | if (memory == NULL) \ | ||
198 | goto out_of_memory; \ | ||
199 | if (result == resultbuf && length > 0) \ | ||
200 | memcpy (memory, result, length * sizeof (CHAR_T)); \ | ||
201 | result = memory; \ | ||
202 | } | ||
203 | |||
204 | for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) | ||
205 | { | ||
206 | if (cp != dp->dir_start) | ||
207 | { | ||
208 | size_t n = dp->dir_start - cp; | ||
209 | size_t augmented_length = xsum (length, n); | ||
210 | |||
211 | ENSURE_ALLOCATION (augmented_length); | ||
212 | memcpy (result + length, cp, n * sizeof (CHAR_T)); | ||
213 | length = augmented_length; | ||
214 | } | ||
215 | if (i == d.count) | ||
216 | break; | ||
217 | |||
218 | /* Execute a single directive. */ | ||
219 | if (dp->conversion == '%') | ||
220 | { | ||
221 | size_t augmented_length; | ||
222 | |||
223 | if (!(dp->arg_index == ARG_NONE)) | ||
224 | abort (); | ||
225 | augmented_length = xsum (length, 1); | ||
226 | ENSURE_ALLOCATION (augmented_length); | ||
227 | result[length] = '%'; | ||
228 | length = augmented_length; | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | if (!(dp->arg_index != ARG_NONE)) | ||
233 | abort (); | ||
234 | |||
235 | if (dp->conversion == 'n') | ||
236 | { | ||
237 | switch (a.arg[dp->arg_index].type) | ||
238 | { | ||
239 | case TYPE_COUNT_SCHAR_POINTER: | ||
240 | *a.arg[dp->arg_index].a.a_count_schar_pointer = length; | ||
241 | break; | ||
242 | case TYPE_COUNT_SHORT_POINTER: | ||
243 | *a.arg[dp->arg_index].a.a_count_short_pointer = length; | ||
244 | break; | ||
245 | case TYPE_COUNT_INT_POINTER: | ||
246 | *a.arg[dp->arg_index].a.a_count_int_pointer = length; | ||
247 | break; | ||
248 | case TYPE_COUNT_LONGINT_POINTER: | ||
249 | *a.arg[dp->arg_index].a.a_count_longint_pointer = length; | ||
250 | break; | ||
251 | #ifdef HAVE_LONG_LONG_INT | ||
252 | case TYPE_COUNT_LONGLONGINT_POINTER: | ||
253 | *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; | ||
254 | break; | ||
255 | #endif | ||
256 | default: | ||
257 | abort (); | ||
258 | } | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | arg_type type = a.arg[dp->arg_index].type; | ||
263 | CHAR_T *p; | ||
264 | unsigned int prefix_count; | ||
265 | int prefixes[2]; | ||
266 | #if !USE_SNPRINTF | ||
267 | size_t tmp_length; | ||
268 | CHAR_T tmpbuf[700]; | ||
269 | CHAR_T *tmp; | ||
270 | |||
271 | /* Allocate a temporary buffer of sufficient size for calling | ||
272 | sprintf. */ | ||
273 | { | ||
274 | size_t width; | ||
275 | size_t precision; | ||
276 | |||
277 | width = 0; | ||
278 | if (dp->width_start != dp->width_end) | ||
279 | { | ||
280 | if (dp->width_arg_index != ARG_NONE) | ||
281 | { | ||
282 | int arg; | ||
283 | |||
284 | if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) | ||
285 | abort (); | ||
286 | arg = a.arg[dp->width_arg_index].a.a_int; | ||
287 | width = (arg < 0 ? (unsigned int) (-arg) : arg); | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | const CHAR_T *digitp = dp->width_start; | ||
292 | |||
293 | do | ||
294 | width = xsum (xtimes (width, 10), *digitp++ - '0'); | ||
295 | while (digitp != dp->width_end); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | precision = 6; | ||
300 | if (dp->precision_start != dp->precision_end) | ||
301 | { | ||
302 | if (dp->precision_arg_index != ARG_NONE) | ||
303 | { | ||
304 | int arg; | ||
305 | |||
306 | if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) | ||
307 | abort (); | ||
308 | arg = a.arg[dp->precision_arg_index].a.a_int; | ||
309 | precision = (arg < 0 ? 0 : arg); | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | const CHAR_T *digitp = dp->precision_start + 1; | ||
314 | |||
315 | precision = 0; | ||
316 | while (digitp != dp->precision_end) | ||
317 | precision = xsum (xtimes (precision, 10), *digitp++ - '0'); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | switch (dp->conversion) | ||
322 | { | ||
323 | |||
324 | case 'd': case 'i': case 'u': | ||
325 | # ifdef HAVE_LONG_LONG_INT | ||
326 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
327 | tmp_length = | ||
328 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
329 | * 0.30103 /* binary -> decimal */ | ||
330 | ) | ||
331 | + 1; /* turn floor into ceil */ | ||
332 | else | ||
333 | # endif | ||
334 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
335 | tmp_length = | ||
336 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
337 | * 0.30103 /* binary -> decimal */ | ||
338 | ) | ||
339 | + 1; /* turn floor into ceil */ | ||
340 | else | ||
341 | tmp_length = | ||
342 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
343 | * 0.30103 /* binary -> decimal */ | ||
344 | ) | ||
345 | + 1; /* turn floor into ceil */ | ||
346 | if (tmp_length < precision) | ||
347 | tmp_length = precision; | ||
348 | /* Multiply by 2, as an estimate for FLAG_GROUP. */ | ||
349 | tmp_length = xsum (tmp_length, tmp_length); | ||
350 | /* Add 1, to account for a leading sign. */ | ||
351 | tmp_length = xsum (tmp_length, 1); | ||
352 | break; | ||
353 | |||
354 | case 'o': | ||
355 | # ifdef HAVE_LONG_LONG_INT | ||
356 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
357 | tmp_length = | ||
358 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
359 | * 0.333334 /* binary -> octal */ | ||
360 | ) | ||
361 | + 1; /* turn floor into ceil */ | ||
362 | else | ||
363 | # endif | ||
364 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
365 | tmp_length = | ||
366 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
367 | * 0.333334 /* binary -> octal */ | ||
368 | ) | ||
369 | + 1; /* turn floor into ceil */ | ||
370 | else | ||
371 | tmp_length = | ||
372 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
373 | * 0.333334 /* binary -> octal */ | ||
374 | ) | ||
375 | + 1; /* turn floor into ceil */ | ||
376 | if (tmp_length < precision) | ||
377 | tmp_length = precision; | ||
378 | /* Add 1, to account for a leading sign. */ | ||
379 | tmp_length = xsum (tmp_length, 1); | ||
380 | break; | ||
381 | |||
382 | case 'x': case 'X': | ||
383 | # ifdef HAVE_LONG_LONG_INT | ||
384 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
385 | tmp_length = | ||
386 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
387 | * 0.25 /* binary -> hexadecimal */ | ||
388 | ) | ||
389 | + 1; /* turn floor into ceil */ | ||
390 | else | ||
391 | # endif | ||
392 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
393 | tmp_length = | ||
394 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
395 | * 0.25 /* binary -> hexadecimal */ | ||
396 | ) | ||
397 | + 1; /* turn floor into ceil */ | ||
398 | else | ||
399 | tmp_length = | ||
400 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
401 | * 0.25 /* binary -> hexadecimal */ | ||
402 | ) | ||
403 | + 1; /* turn floor into ceil */ | ||
404 | if (tmp_length < precision) | ||
405 | tmp_length = precision; | ||
406 | /* Add 2, to account for a leading sign or alternate form. */ | ||
407 | tmp_length = xsum (tmp_length, 2); | ||
408 | break; | ||
409 | |||
410 | case 'f': case 'F': | ||
411 | # ifdef HAVE_LONG_DOUBLE | ||
412 | if (type == TYPE_LONGDOUBLE) | ||
413 | tmp_length = | ||
414 | (unsigned int) (LDBL_MAX_EXP | ||
415 | * 0.30103 /* binary -> decimal */ | ||
416 | * 2 /* estimate for FLAG_GROUP */ | ||
417 | ) | ||
418 | + 1 /* turn floor into ceil */ | ||
419 | + 10; /* sign, decimal point etc. */ | ||
420 | else | ||
421 | # endif | ||
422 | tmp_length = | ||
423 | (unsigned int) (DBL_MAX_EXP | ||
424 | * 0.30103 /* binary -> decimal */ | ||
425 | * 2 /* estimate for FLAG_GROUP */ | ||
426 | ) | ||
427 | + 1 /* turn floor into ceil */ | ||
428 | + 10; /* sign, decimal point etc. */ | ||
429 | tmp_length = xsum (tmp_length, precision); | ||
430 | break; | ||
431 | |||
432 | case 'e': case 'E': case 'g': case 'G': | ||
433 | case 'a': case 'A': | ||
434 | tmp_length = | ||
435 | 12; /* sign, decimal point, exponent etc. */ | ||
436 | tmp_length = xsum (tmp_length, precision); | ||
437 | break; | ||
438 | |||
439 | case 'c': | ||
440 | # if defined HAVE_WINT_T && !WIDE_CHAR_VERSION | ||
441 | if (type == TYPE_WIDE_CHAR) | ||
442 | tmp_length = MB_CUR_MAX; | ||
443 | else | ||
444 | # endif | ||
445 | tmp_length = 1; | ||
446 | break; | ||
447 | |||
448 | case 's': | ||
449 | # ifdef HAVE_WCHAR_T | ||
450 | if (type == TYPE_WIDE_STRING) | ||
451 | { | ||
452 | tmp_length = | ||
453 | local_wcslen (a.arg[dp->arg_index].a.a_wide_string); | ||
454 | |||
455 | # if !WIDE_CHAR_VERSION | ||
456 | tmp_length = xtimes (tmp_length, MB_CUR_MAX); | ||
457 | # endif | ||
458 | } | ||
459 | else | ||
460 | # endif | ||
461 | tmp_length = strlen (a.arg[dp->arg_index].a.a_string); | ||
462 | break; | ||
463 | |||
464 | case 'p': | ||
465 | tmp_length = | ||
466 | (unsigned int) (sizeof (void *) * CHAR_BIT | ||
467 | * 0.25 /* binary -> hexadecimal */ | ||
468 | ) | ||
469 | + 1 /* turn floor into ceil */ | ||
470 | + 2; /* account for leading 0x */ | ||
471 | break; | ||
472 | |||
473 | default: | ||
474 | abort (); | ||
475 | } | ||
476 | |||
477 | if (tmp_length < width) | ||
478 | tmp_length = width; | ||
479 | |||
480 | tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ | ||
481 | } | ||
482 | |||
483 | if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) | ||
484 | tmp = tmpbuf; | ||
485 | else | ||
486 | { | ||
487 | size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T)); | ||
488 | |||
489 | if (size_overflow_p (tmp_memsize)) | ||
490 | /* Overflow, would lead to out of memory. */ | ||
491 | goto out_of_memory; | ||
492 | tmp = (CHAR_T *) malloc (tmp_memsize); | ||
493 | if (tmp == NULL) | ||
494 | /* Out of memory. */ | ||
495 | goto out_of_memory; | ||
496 | } | ||
497 | #endif | ||
498 | |||
499 | /* Construct the format string for calling snprintf or | ||
500 | sprintf. */ | ||
501 | p = buf; | ||
502 | *p++ = '%'; | ||
503 | if (dp->flags & FLAG_GROUP) | ||
504 | *p++ = '\''; | ||
505 | if (dp->flags & FLAG_LEFT) | ||
506 | *p++ = '-'; | ||
507 | if (dp->flags & FLAG_SHOWSIGN) | ||
508 | *p++ = '+'; | ||
509 | if (dp->flags & FLAG_SPACE) | ||
510 | *p++ = ' '; | ||
511 | if (dp->flags & FLAG_ALT) | ||
512 | *p++ = '#'; | ||
513 | if (dp->flags & FLAG_ZERO) | ||
514 | *p++ = '0'; | ||
515 | if (dp->width_start != dp->width_end) | ||
516 | { | ||
517 | size_t n = dp->width_end - dp->width_start; | ||
518 | memcpy (p, dp->width_start, n * sizeof (CHAR_T)); | ||
519 | p += n; | ||
520 | } | ||
521 | if (dp->precision_start != dp->precision_end) | ||
522 | { | ||
523 | size_t n = dp->precision_end - dp->precision_start; | ||
524 | memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); | ||
525 | p += n; | ||
526 | } | ||
527 | |||
528 | switch (type) | ||
529 | { | ||
530 | #ifdef HAVE_LONG_LONG_INT | ||
531 | case TYPE_LONGLONGINT: | ||
532 | case TYPE_ULONGLONGINT: | ||
533 | *p++ = 'l'; | ||
534 | /*FALLTHROUGH*/ | ||
535 | #endif | ||
536 | case TYPE_LONGINT: | ||
537 | case TYPE_ULONGINT: | ||
538 | #ifdef HAVE_WINT_T | ||
539 | case TYPE_WIDE_CHAR: | ||
540 | #endif | ||
541 | #ifdef HAVE_WCHAR_T | ||
542 | case TYPE_WIDE_STRING: | ||
543 | #endif | ||
544 | *p++ = 'l'; | ||
545 | break; | ||
546 | #ifdef HAVE_LONG_DOUBLE | ||
547 | case TYPE_LONGDOUBLE: | ||
548 | *p++ = 'L'; | ||
549 | break; | ||
550 | #endif | ||
551 | default: | ||
552 | break; | ||
553 | } | ||
554 | *p = dp->conversion; | ||
555 | #if USE_SNPRINTF | ||
556 | p[1] = '%'; | ||
557 | p[2] = 'n'; | ||
558 | p[3] = '\0'; | ||
559 | #else | ||
560 | p[1] = '\0'; | ||
561 | #endif | ||
562 | |||
563 | /* Construct the arguments for calling snprintf or sprintf. */ | ||
564 | prefix_count = 0; | ||
565 | if (dp->width_arg_index != ARG_NONE) | ||
566 | { | ||
567 | if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) | ||
568 | abort (); | ||
569 | prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; | ||
570 | } | ||
571 | if (dp->precision_arg_index != ARG_NONE) | ||
572 | { | ||
573 | if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) | ||
574 | abort (); | ||
575 | prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; | ||
576 | } | ||
577 | |||
578 | #if USE_SNPRINTF | ||
579 | /* Prepare checking whether snprintf returns the count | ||
580 | via %n. */ | ||
581 | ENSURE_ALLOCATION (xsum (length, 1)); | ||
582 | result[length] = '\0'; | ||
583 | #endif | ||
584 | |||
585 | for (;;) | ||
586 | { | ||
587 | size_t maxlen; | ||
588 | int count; | ||
589 | int retcount; | ||
590 | |||
591 | maxlen = allocated - length; | ||
592 | count = -1; | ||
593 | retcount = 0; | ||
594 | |||
595 | #if USE_SNPRINTF | ||
596 | # define SNPRINTF_BUF(arg) \ | ||
597 | switch (prefix_count) \ | ||
598 | { \ | ||
599 | case 0: \ | ||
600 | retcount = SNPRINTF (result + length, maxlen, buf, \ | ||
601 | arg, &count); \ | ||
602 | break; \ | ||
603 | case 1: \ | ||
604 | retcount = SNPRINTF (result + length, maxlen, buf, \ | ||
605 | prefixes[0], arg, &count); \ | ||
606 | break; \ | ||
607 | case 2: \ | ||
608 | retcount = SNPRINTF (result + length, maxlen, buf, \ | ||
609 | prefixes[0], prefixes[1], arg, \ | ||
610 | &count); \ | ||
611 | break; \ | ||
612 | default: \ | ||
613 | abort (); \ | ||
614 | } | ||
615 | #else | ||
616 | # define SNPRINTF_BUF(arg) \ | ||
617 | switch (prefix_count) \ | ||
618 | { \ | ||
619 | case 0: \ | ||
620 | count = sprintf (tmp, buf, arg); \ | ||
621 | break; \ | ||
622 | case 1: \ | ||
623 | count = sprintf (tmp, buf, prefixes[0], arg); \ | ||
624 | break; \ | ||
625 | case 2: \ | ||
626 | count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ | ||
627 | arg); \ | ||
628 | break; \ | ||
629 | default: \ | ||
630 | abort (); \ | ||
631 | } | ||
632 | #endif | ||
633 | |||
634 | switch (type) | ||
635 | { | ||
636 | case TYPE_SCHAR: | ||
637 | { | ||
638 | int arg = a.arg[dp->arg_index].a.a_schar; | ||
639 | SNPRINTF_BUF (arg); | ||
640 | } | ||
641 | break; | ||
642 | case TYPE_UCHAR: | ||
643 | { | ||
644 | unsigned int arg = a.arg[dp->arg_index].a.a_uchar; | ||
645 | SNPRINTF_BUF (arg); | ||
646 | } | ||
647 | break; | ||
648 | case TYPE_SHORT: | ||
649 | { | ||
650 | int arg = a.arg[dp->arg_index].a.a_short; | ||
651 | SNPRINTF_BUF (arg); | ||
652 | } | ||
653 | break; | ||
654 | case TYPE_USHORT: | ||
655 | { | ||
656 | unsigned int arg = a.arg[dp->arg_index].a.a_ushort; | ||
657 | SNPRINTF_BUF (arg); | ||
658 | } | ||
659 | break; | ||
660 | case TYPE_INT: | ||
661 | { | ||
662 | int arg = a.arg[dp->arg_index].a.a_int; | ||
663 | SNPRINTF_BUF (arg); | ||
664 | } | ||
665 | break; | ||
666 | case TYPE_UINT: | ||
667 | { | ||
668 | unsigned int arg = a.arg[dp->arg_index].a.a_uint; | ||
669 | SNPRINTF_BUF (arg); | ||
670 | } | ||
671 | break; | ||
672 | case TYPE_LONGINT: | ||
673 | { | ||
674 | long int arg = a.arg[dp->arg_index].a.a_longint; | ||
675 | SNPRINTF_BUF (arg); | ||
676 | } | ||
677 | break; | ||
678 | case TYPE_ULONGINT: | ||
679 | { | ||
680 | unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; | ||
681 | SNPRINTF_BUF (arg); | ||
682 | } | ||
683 | break; | ||
684 | #ifdef HAVE_LONG_LONG_INT | ||
685 | case TYPE_LONGLONGINT: | ||
686 | { | ||
687 | long long int arg = a.arg[dp->arg_index].a.a_longlongint; | ||
688 | SNPRINTF_BUF (arg); | ||
689 | } | ||
690 | break; | ||
691 | case TYPE_ULONGLONGINT: | ||
692 | { | ||
693 | unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; | ||
694 | SNPRINTF_BUF (arg); | ||
695 | } | ||
696 | break; | ||
697 | #endif | ||
698 | case TYPE_DOUBLE: | ||
699 | { | ||
700 | double arg = a.arg[dp->arg_index].a.a_double; | ||
701 | SNPRINTF_BUF (arg); | ||
702 | } | ||
703 | break; | ||
704 | #ifdef HAVE_LONG_DOUBLE | ||
705 | case TYPE_LONGDOUBLE: | ||
706 | { | ||
707 | long double arg = a.arg[dp->arg_index].a.a_longdouble; | ||
708 | SNPRINTF_BUF (arg); | ||
709 | } | ||
710 | break; | ||
711 | #endif | ||
712 | case TYPE_CHAR: | ||
713 | { | ||
714 | int arg = a.arg[dp->arg_index].a.a_char; | ||
715 | SNPRINTF_BUF (arg); | ||
716 | } | ||
717 | break; | ||
718 | #ifdef HAVE_WINT_T | ||
719 | case TYPE_WIDE_CHAR: | ||
720 | { | ||
721 | wint_t arg = a.arg[dp->arg_index].a.a_wide_char; | ||
722 | SNPRINTF_BUF (arg); | ||
723 | } | ||
724 | break; | ||
725 | #endif | ||
726 | case TYPE_STRING: | ||
727 | { | ||
728 | const char *arg = a.arg[dp->arg_index].a.a_string; | ||
729 | SNPRINTF_BUF (arg); | ||
730 | } | ||
731 | break; | ||
732 | #ifdef HAVE_WCHAR_T | ||
733 | case TYPE_WIDE_STRING: | ||
734 | { | ||
735 | const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; | ||
736 | SNPRINTF_BUF (arg); | ||
737 | } | ||
738 | break; | ||
739 | #endif | ||
740 | case TYPE_POINTER: | ||
741 | { | ||
742 | void *arg = a.arg[dp->arg_index].a.a_pointer; | ||
743 | SNPRINTF_BUF (arg); | ||
744 | } | ||
745 | break; | ||
746 | default: | ||
747 | abort (); | ||
748 | } | ||
749 | |||
750 | #if USE_SNPRINTF | ||
751 | /* Portability: Not all implementations of snprintf() | ||
752 | are ISO C 99 compliant. Determine the number of | ||
753 | bytes that snprintf() has produced or would have | ||
754 | produced. */ | ||
755 | if (count >= 0) | ||
756 | { | ||
757 | /* Verify that snprintf() has NUL-terminated its | ||
758 | result. */ | ||
759 | if (count < maxlen && result[length + count] != '\0') | ||
760 | abort (); | ||
761 | /* Portability hack. */ | ||
762 | if (retcount > count) | ||
763 | count = retcount; | ||
764 | } | ||
765 | else | ||
766 | { | ||
767 | /* snprintf() doesn't understand the '%n' | ||
768 | directive. */ | ||
769 | if (p[1] != '\0') | ||
770 | { | ||
771 | /* Don't use the '%n' directive; instead, look | ||
772 | at the snprintf() return value. */ | ||
773 | p[1] = '\0'; | ||
774 | continue; | ||
775 | } | ||
776 | else | ||
777 | { | ||
778 | /* Look at the snprintf() return value. */ | ||
779 | if (retcount < 0) | ||
780 | { | ||
781 | /* HP-UX 10.20 snprintf() is doubly deficient: | ||
782 | It doesn't understand the '%n' directive, | ||
783 | *and* it returns -1 (rather than the length | ||
784 | that would have been required) when the | ||
785 | buffer is too small. */ | ||
786 | size_t bigger_need = | ||
787 | xsum (xtimes (allocated, 2), 12); | ||
788 | ENSURE_ALLOCATION (bigger_need); | ||
789 | continue; | ||
790 | } | ||
791 | else | ||
792 | count = retcount; | ||
793 | } | ||
794 | } | ||
795 | #endif | ||
796 | |||
797 | /* Attempt to handle failure. */ | ||
798 | if (count < 0) | ||
799 | { | ||
800 | if (!(result == resultbuf || result == NULL)) | ||
801 | free (result); | ||
802 | if (buf_malloced != NULL) | ||
803 | free (buf_malloced); | ||
804 | CLEANUP (); | ||
805 | errno = EINVAL; | ||
806 | return NULL; | ||
807 | } | ||
808 | |||
809 | #if !USE_SNPRINTF | ||
810 | if (count >= tmp_length) | ||
811 | /* tmp_length was incorrectly calculated - fix the | ||
812 | code above! */ | ||
813 | abort (); | ||
814 | #endif | ||
815 | |||
816 | /* Make room for the result. */ | ||
817 | if (count >= maxlen) | ||
818 | { | ||
819 | /* Need at least count bytes. But allocate | ||
820 | proportionally, to avoid looping eternally if | ||
821 | snprintf() reports a too small count. */ | ||
822 | size_t n = | ||
823 | xmax (xsum (length, count), xtimes (allocated, 2)); | ||
824 | |||
825 | ENSURE_ALLOCATION (n); | ||
826 | #if USE_SNPRINTF | ||
827 | continue; | ||
828 | #endif | ||
829 | } | ||
830 | |||
831 | #if USE_SNPRINTF | ||
832 | /* The snprintf() result did fit. */ | ||
833 | #else | ||
834 | /* Append the sprintf() result. */ | ||
835 | memcpy (result + length, tmp, count * sizeof (CHAR_T)); | ||
836 | if (tmp != tmpbuf) | ||
837 | free (tmp); | ||
838 | #endif | ||
839 | |||
840 | length += count; | ||
841 | break; | ||
842 | } | ||
843 | } | ||
844 | } | ||
845 | } | ||
846 | |||
847 | /* Add the final NUL. */ | ||
848 | ENSURE_ALLOCATION (xsum (length, 1)); | ||
849 | result[length] = '\0'; | ||
850 | |||
851 | if (result != resultbuf && length + 1 < allocated) | ||
852 | { | ||
853 | /* Shrink the allocated memory if possible. */ | ||
854 | CHAR_T *memory; | ||
855 | |||
856 | memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); | ||
857 | if (memory != NULL) | ||
858 | result = memory; | ||
859 | } | ||
860 | |||
861 | if (buf_malloced != NULL) | ||
862 | free (buf_malloced); | ||
863 | CLEANUP (); | ||
864 | *lengthp = length; | ||
865 | /* Note that we can produce a big string of a length > INT_MAX. POSIX | ||
866 | says that snprintf() fails with errno = EOVERFLOW in this case, but | ||
867 | that's only because snprintf() returns an 'int'. This function does | ||
868 | not have this limitation. */ | ||
869 | return result; | ||
870 | |||
871 | out_of_memory: | ||
872 | if (!(result == resultbuf || result == NULL)) | ||
873 | free (result); | ||
874 | if (buf_malloced != NULL) | ||
875 | free (buf_malloced); | ||
876 | out_of_memory_1: | ||
877 | CLEANUP (); | ||
878 | errno = ENOMEM; | ||
879 | return NULL; | ||
880 | } | ||
881 | } | ||
882 | |||
883 | #undef SNPRINTF | ||
884 | #undef USE_SNPRINTF | ||
885 | #undef PRINTF_PARSE | ||
886 | #undef DIRECTIVES | ||
887 | #undef DIRECTIVE | ||
888 | #undef CHAR_T | ||
889 | #undef VASNPRINTF | ||
diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h new file mode 100644 index 0000000..894008c --- /dev/null +++ b/gl/vasnprintf.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* vsprintf with automatic memory allocation. | ||
2 | Copyright (C) 2002-2004 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _VASNPRINTF_H | ||
19 | #define _VASNPRINTF_H | ||
20 | |||
21 | /* Get va_list. */ | ||
22 | #include <stdarg.h> | ||
23 | |||
24 | /* Get size_t. */ | ||
25 | #include <stddef.h> | ||
26 | |||
27 | #ifndef __attribute__ | ||
28 | /* This feature is available in gcc versions 2.5 and later. */ | ||
29 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ | ||
30 | # define __attribute__(Spec) /* empty */ | ||
31 | # endif | ||
32 | /* The __-protected variants of `format' and `printf' attributes | ||
33 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | ||
34 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) | ||
35 | # define __format__ format | ||
36 | # define __printf__ printf | ||
37 | # endif | ||
38 | #endif | ||
39 | |||
40 | #ifdef __cplusplus | ||
41 | extern "C" { | ||
42 | #endif | ||
43 | |||
44 | /* Write formatted output to a string dynamically allocated with malloc(). | ||
45 | You can pass a preallocated buffer for the result in RESULTBUF and its | ||
46 | size in *LENGTHP; otherwise you pass RESULTBUF = NULL. | ||
47 | If successful, return the address of the string (this may be = RESULTBUF | ||
48 | if no dynamic memory allocation was necessary) and set *LENGTHP to the | ||
49 | number of resulting bytes, excluding the trailing NUL. Upon error, set | ||
50 | errno and return NULL. | ||
51 | |||
52 | When dynamic memory allocation occurs, the preallocated buffer is left | ||
53 | alone (with possibly modified contents). This makes it possible to use | ||
54 | a statically allocated or stack-allocated buffer, like this: | ||
55 | |||
56 | char buf[100]; | ||
57 | size_t len = sizeof (buf); | ||
58 | char *output = vasnprintf (buf, &len, format, args); | ||
59 | if (output == NULL) | ||
60 | ... error handling ...; | ||
61 | else | ||
62 | { | ||
63 | ... use the output string ...; | ||
64 | if (output != buf) | ||
65 | free (output); | ||
66 | } | ||
67 | */ | ||
68 | extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) | ||
69 | __attribute__ ((__format__ (__printf__, 3, 4))); | ||
70 | extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) | ||
71 | __attribute__ ((__format__ (__printf__, 3, 0))); | ||
72 | |||
73 | #ifdef __cplusplus | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | #endif /* _VASNPRINTF_H */ | ||
diff --git a/gl/vasprintf.c b/gl/vasprintf.c new file mode 100644 index 0000000..8247073 --- /dev/null +++ b/gl/vasprintf.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #include <config.h> | ||
19 | |||
20 | /* Specification. */ | ||
21 | #include "vasprintf.h" | ||
22 | |||
23 | #include <errno.h> | ||
24 | #include <limits.h> | ||
25 | #include <stdlib.h> | ||
26 | |||
27 | #include "vasnprintf.h" | ||
28 | |||
29 | /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ | ||
30 | #ifndef EOVERFLOW | ||
31 | # define EOVERFLOW E2BIG | ||
32 | #endif | ||
33 | |||
34 | int | ||
35 | vasprintf (char **resultp, const char *format, va_list args) | ||
36 | { | ||
37 | size_t length; | ||
38 | char *result = vasnprintf (NULL, &length, format, args); | ||
39 | if (result == NULL) | ||
40 | return -1; | ||
41 | |||
42 | if (length > INT_MAX) | ||
43 | { | ||
44 | free (result); | ||
45 | errno = EOVERFLOW; | ||
46 | return -1; | ||
47 | } | ||
48 | |||
49 | *resultp = result; | ||
50 | /* Return the number of resulting bytes, excluding the trailing NUL. */ | ||
51 | return length; | ||
52 | } | ||
diff --git a/gl/vasprintf.h b/gl/vasprintf.h new file mode 100644 index 0000000..ab5515c --- /dev/null +++ b/gl/vasprintf.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* vsprintf with automatic memory allocation. | ||
2 | Copyright (C) 2002-2003 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _VASPRINTF_H | ||
19 | #define _VASPRINTF_H | ||
20 | |||
21 | #if HAVE_VASPRINTF | ||
22 | |||
23 | /* Get asprintf(), vasprintf() declarations. */ | ||
24 | #include <stdio.h> | ||
25 | |||
26 | #else | ||
27 | |||
28 | /* Get va_list. */ | ||
29 | #include <stdarg.h> | ||
30 | |||
31 | #ifndef __attribute__ | ||
32 | /* This feature is available in gcc versions 2.5 and later. */ | ||
33 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ | ||
34 | # define __attribute__(Spec) /* empty */ | ||
35 | # endif | ||
36 | /* The __-protected variants of `format' and `printf' attributes | ||
37 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | ||
38 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) | ||
39 | # define __format__ format | ||
40 | # define __printf__ printf | ||
41 | # endif | ||
42 | #endif | ||
43 | |||
44 | #ifdef __cplusplus | ||
45 | extern "C" { | ||
46 | #endif | ||
47 | |||
48 | /* Write formatted output to a string dynamically allocated with malloc(). | ||
49 | If the memory allocation succeeds, store the address of the string in | ||
50 | *RESULT and return the number of resulting bytes, excluding the trailing | ||
51 | NUL. Upon memory allocation error, or some other error, return -1. */ | ||
52 | extern int asprintf (char **result, const char *format, ...) | ||
53 | __attribute__ ((__format__ (__printf__, 2, 3))); | ||
54 | extern int vasprintf (char **result, const char *format, va_list args) | ||
55 | __attribute__ ((__format__ (__printf__, 2, 0))); | ||
56 | |||
57 | #ifdef __cplusplus | ||
58 | } | ||
59 | #endif | ||
60 | |||
61 | #endif | ||
62 | |||
63 | #endif /* _VASPRINTF_H */ | ||
diff --git a/gl/vsnprintf.c b/gl/vsnprintf.c new file mode 100644 index 0000000..af567d2 --- /dev/null +++ b/gl/vsnprintf.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 2004, 2006 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | /* Specification. */ | ||
24 | #include "vsnprintf.h" | ||
25 | |||
26 | #include <errno.h> | ||
27 | #include <limits.h> | ||
28 | #include <stdarg.h> | ||
29 | #include <stdio.h> | ||
30 | #include <stdlib.h> | ||
31 | #include <string.h> | ||
32 | |||
33 | #include "vasnprintf.h" | ||
34 | |||
35 | /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ | ||
36 | #ifndef EOVERFLOW | ||
37 | # define EOVERFLOW E2BIG | ||
38 | #endif | ||
39 | |||
40 | /* Print formatted output to string STR. Similar to vsprintf, but | ||
41 | additional length SIZE limit how much is written into STR. Returns | ||
42 | string length of formatted string (which may be larger than SIZE). | ||
43 | STR may be NULL, in which case nothing will be written. On error, | ||
44 | return a negative value. */ | ||
45 | int | ||
46 | vsnprintf (char *str, size_t size, const char *format, va_list args) | ||
47 | { | ||
48 | char *output; | ||
49 | size_t len; | ||
50 | size_t lenbuf = size; | ||
51 | |||
52 | output = vasnprintf (str, &lenbuf, format, args); | ||
53 | len = lenbuf; | ||
54 | |||
55 | if (!output) | ||
56 | return -1; | ||
57 | |||
58 | if (output != str) | ||
59 | { | ||
60 | if (size) | ||
61 | { | ||
62 | size_t pruned_len = (len < size ? len : size - 1); | ||
63 | memcpy (str, output, pruned_len); | ||
64 | str[pruned_len] = '\0'; | ||
65 | } | ||
66 | |||
67 | free (output); | ||
68 | } | ||
69 | |||
70 | if (len > INT_MAX) | ||
71 | { | ||
72 | errno = EOVERFLOW; | ||
73 | return -1; | ||
74 | } | ||
75 | |||
76 | return len; | ||
77 | } | ||
diff --git a/gl/vsnprintf.h b/gl/vsnprintf.h new file mode 100644 index 0000000..f80c77a --- /dev/null +++ b/gl/vsnprintf.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* Formatted output to strings. | ||
2 | Copyright (C) 2004 Free Software Foundation, Inc. | ||
3 | Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef VSNPRINTF_H | ||
20 | #define VSNPRINTF_H | ||
21 | |||
22 | #include <stdarg.h> | ||
23 | |||
24 | /* Get vsnprintf declaration, if available. */ | ||
25 | #include <stdio.h> | ||
26 | |||
27 | #if defined HAVE_DECL_VSNPRINTF && !HAVE_DECL_VSNPRINTF | ||
28 | int vsnprintf (char *str, size_t size, const char *format, va_list args); | ||
29 | #endif | ||
30 | |||
31 | #endif /* VSNPRINTF_H */ | ||
diff --git a/gl/wchar_.h b/gl/wchar_.h new file mode 100644 index 0000000..6813a21 --- /dev/null +++ b/gl/wchar_.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* A substitute for ISO C99 <wchar.h>, for platforms that have issues. | ||
2 | |||
3 | Copyright (C) 2007 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Eric Blake. */ | ||
20 | |||
21 | /* | ||
22 | * ISO C 99 <wchar.h> for platforms that have issues. | ||
23 | * <http://www.opengroup.org/susv3xbd/wchar.h.html> | ||
24 | * | ||
25 | * For now, this just ensures proper prerequisite inclusion order. | ||
26 | */ | ||
27 | |||
28 | #ifndef _GL_WCHAR_H | ||
29 | #define _GL_WCHAR_H | ||
30 | |||
31 | /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
32 | <wchar.h>. | ||
33 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | ||
34 | included before <wchar.h>. */ | ||
35 | #include <stddef.h> | ||
36 | #include <stdio.h> | ||
37 | #include <time.h> | ||
38 | |||
39 | /* Include the original <wchar.h>. */ | ||
40 | #include @ABSOLUTE_WCHAR_H@ | ||
41 | |||
42 | #endif /* _GL_WCHAR_H */ | ||
diff --git a/gl/wctype_.h b/gl/wctype_.h new file mode 100644 index 0000000..1297c61 --- /dev/null +++ b/gl/wctype_.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* A substitute for ISO C99 <wctype.h>, for platforms that lack it. | ||
2 | |||
3 | Copyright (C) 2006, 2007 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Bruno Haible and Paul Eggert. */ | ||
20 | |||
21 | /* | ||
22 | * ISO C 99 <wctype.h> for platforms that lack it. | ||
23 | * <http://www.opengroup.org/susv3xbd/wctype.h.html> | ||
24 | * | ||
25 | * iswctype, towctrans, towlower, towupper, wctrans, wctype, | ||
26 | * wctrans_t, and wctype_t are not yet implemented. | ||
27 | */ | ||
28 | |||
29 | #ifndef _GL_WCTYPE_H | ||
30 | #define _GL_WCTYPE_H | ||
31 | |||
32 | #if @HAVE_WINT_T@ | ||
33 | /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. | ||
34 | Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before | ||
35 | <wchar.h>. | ||
36 | BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | ||
37 | included before <wchar.h>. */ | ||
38 | # include <stddef.h> | ||
39 | # include <stdio.h> | ||
40 | # include <time.h> | ||
41 | # include <wchar.h> | ||
42 | typedef wint_t __wctype_wint_t; | ||
43 | #else | ||
44 | typedef int __wctype_wint_t; | ||
45 | #endif | ||
46 | |||
47 | /* Include the original <wctype.h> if it exists. | ||
48 | BeOS 5 has the functions but no <wctype.h>. */ | ||
49 | #if @HAVE_WCTYPE_H@ | ||
50 | # include @ABSOLUTE_WCTYPE_H@ | ||
51 | #endif | ||
52 | |||
53 | /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. | ||
54 | Assume all 12 functions are implemented the same way, or not at all. */ | ||
55 | #if ! HAVE_ISWCNTRL | ||
56 | |||
57 | /* IRIX 5.3 has macros but no functions, its isw* macros refer to an | ||
58 | undefined variable _ctmp_ and to <ctype.h> macros like _P, and they | ||
59 | refer to system functions like _iswctype that are not in the | ||
60 | standard C library. Rather than try to get ancient buggy | ||
61 | implementations like this to work, just disable them. */ | ||
62 | # undef iswalnum | ||
63 | # undef iswalpha | ||
64 | # undef iswblank | ||
65 | # undef iswcntrl | ||
66 | # undef iswdigit | ||
67 | # undef iswgraph | ||
68 | # undef iswlower | ||
69 | # undef iswprint | ||
70 | # undef iswpunct | ||
71 | # undef iswspace | ||
72 | # undef iswupper | ||
73 | # undef iswxdigit | ||
74 | |||
75 | static inline int | ||
76 | iswalnum (__wctype_wint_t wc) | ||
77 | { | ||
78 | return ((wc >= '0' && wc <= '9') | ||
79 | || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); | ||
80 | } | ||
81 | |||
82 | static inline int | ||
83 | iswalpha (__wctype_wint_t wc) | ||
84 | { | ||
85 | return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; | ||
86 | } | ||
87 | |||
88 | static inline int | ||
89 | iswblank (__wctype_wint_t wc) | ||
90 | { | ||
91 | return wc == ' ' || wc == '\t'; | ||
92 | } | ||
93 | |||
94 | static inline int | ||
95 | iswcntrl (__wctype_wint_t wc) | ||
96 | { | ||
97 | return (wc & ~0x1f) == 0 || wc == 0x7f; | ||
98 | } | ||
99 | |||
100 | static inline int | ||
101 | iswdigit (__wctype_wint_t wc) | ||
102 | { | ||
103 | return wc >= '0' && wc <= '9'; | ||
104 | } | ||
105 | |||
106 | static inline int | ||
107 | iswgraph (__wctype_wint_t wc) | ||
108 | { | ||
109 | return wc >= '!' && wc <= '~'; | ||
110 | } | ||
111 | |||
112 | static inline int | ||
113 | iswlower (__wctype_wint_t wc) | ||
114 | { | ||
115 | return wc >= 'a' && wc <= 'z'; | ||
116 | } | ||
117 | |||
118 | static inline int | ||
119 | iswprint (__wctype_wint_t wc) | ||
120 | { | ||
121 | return wc >= ' ' && wc <= '~'; | ||
122 | } | ||
123 | |||
124 | static inline int | ||
125 | iswpunct (__wctype_wint_t wc) | ||
126 | { | ||
127 | return (wc >= '!' && wc <= '~' | ||
128 | && !((wc >= '0' && wc <= '9') | ||
129 | || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); | ||
130 | } | ||
131 | |||
132 | static inline int | ||
133 | iswspace (__wctype_wint_t wc) | ||
134 | { | ||
135 | return (wc == ' ' || wc == '\t' | ||
136 | || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); | ||
137 | } | ||
138 | |||
139 | static inline int | ||
140 | iswupper (__wctype_wint_t wc) | ||
141 | { | ||
142 | return wc >= 'A' && wc <= 'Z'; | ||
143 | } | ||
144 | |||
145 | static inline int | ||
146 | iswxdigit (__wctype_wint_t wc) | ||
147 | { | ||
148 | return ((wc >= '0' && wc <= '9') | ||
149 | || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); | ||
150 | } | ||
151 | |||
152 | # endif /* ! HAVE_ISWCNTRL */ | ||
153 | |||
154 | #endif /* _GL_WCTYPE_H */ | ||
diff --git a/gl/wcwidth.h b/gl/wcwidth.h new file mode 100644 index 0000000..8ed5ff8 --- /dev/null +++ b/gl/wcwidth.h | |||
@@ -0,0 +1,57 @@ | |||
1 | /* Determine the number of screen columns needed for a character. | ||
2 | Copyright (C) 2006, 2007 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _gl_WCWIDTH_H | ||
19 | #define _gl_WCWIDTH_H | ||
20 | |||
21 | #if HAVE_WCHAR_T | ||
22 | |||
23 | /* Get wcwidth if available, along with wchar_t. */ | ||
24 | # include <wchar.h> | ||
25 | |||
26 | /* Get iswprint. */ | ||
27 | # include <wctype.h> | ||
28 | |||
29 | # ifndef HAVE_DECL_WCWIDTH | ||
30 | "this configure-time declaration test was not run" | ||
31 | # endif | ||
32 | # ifndef wcwidth | ||
33 | # if !HAVE_WCWIDTH | ||
34 | |||
35 | /* wcwidth doesn't exist, so assume all printable characters have | ||
36 | width 1. */ | ||
37 | static inline int | ||
38 | wcwidth (wchar_t wc) | ||
39 | { | ||
40 | return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; | ||
41 | } | ||
42 | |||
43 | # elif !HAVE_DECL_WCWIDTH | ||
44 | |||
45 | /* wcwidth exists but is not declared. */ | ||
46 | extern | ||
47 | # ifdef __cplusplus | ||
48 | "C" | ||
49 | # endif | ||
50 | int wcwidth (int /* actually wchar_t */); | ||
51 | |||
52 | # endif | ||
53 | # endif | ||
54 | |||
55 | #endif /* HAVE_WCHAR_T */ | ||
56 | |||
57 | #endif /* _gl_WCWIDTH_H */ | ||
diff --git a/lib/xalloc-die.c b/gl/xalloc-die.c index ff5ac9e..090f060 100644 --- a/lib/xalloc-die.c +++ b/gl/xalloc-die.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* Report a memory allocation failure and exit. | 1 | /* Report a memory allocation failure and exit. |
2 | 2 | ||
3 | Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free | 3 | Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free |
4 | Software Foundation, Inc. | 4 | Software Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
@@ -17,9 +17,7 @@ | |||
17 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | 20 | #include <config.h> |
21 | # include <config.h> | ||
22 | #endif | ||
23 | 21 | ||
24 | #include "xalloc.h" | 22 | #include "xalloc.h" |
25 | 23 | ||
@@ -30,7 +28,6 @@ | |||
30 | 28 | ||
31 | #include "gettext.h" | 29 | #include "gettext.h" |
32 | #define _(msgid) gettext (msgid) | 30 | #define _(msgid) gettext (msgid) |
33 | #define N_(msgid) msgid | ||
34 | 31 | ||
35 | void | 32 | void |
36 | xalloc_die (void) | 33 | xalloc_die (void) |
diff --git a/gl/xalloc.h b/gl/xalloc.h new file mode 100644 index 0000000..17ab514 --- /dev/null +++ b/gl/xalloc.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /* xalloc.h -- malloc with out-of-memory checking | ||
2 | |||
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | ||
4 | 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifndef XALLOC_H_ | ||
21 | # define XALLOC_H_ | ||
22 | |||
23 | # include <stddef.h> | ||
24 | |||
25 | |||
26 | # ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | # endif | ||
29 | |||
30 | |||
31 | # ifndef __attribute__ | ||
32 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ | ||
33 | # define __attribute__(x) | ||
34 | # endif | ||
35 | # endif | ||
36 | |||
37 | # ifndef ATTRIBUTE_NORETURN | ||
38 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | ||
39 | # endif | ||
40 | |||
41 | /* This function is always triggered when memory is exhausted. | ||
42 | It must be defined by the application, either explicitly | ||
43 | or by using gnulib's xalloc-die module. This is the | ||
44 | function to call when one wants the program to die because of a | ||
45 | memory allocation failure. */ | ||
46 | extern void xalloc_die (void) ATTRIBUTE_NORETURN; | ||
47 | |||
48 | void *xmalloc (size_t s); | ||
49 | void *xzalloc (size_t s); | ||
50 | void *xcalloc (size_t n, size_t s); | ||
51 | void *xrealloc (void *p, size_t s); | ||
52 | void *x2realloc (void *p, size_t *pn); | ||
53 | void *xmemdup (void const *p, size_t s); | ||
54 | char *xstrdup (char const *str); | ||
55 | |||
56 | /* Return 1 if an array of N objects, each of size S, cannot exist due | ||
57 | to size arithmetic overflow. S must be positive and N must be | ||
58 | nonnegative. This is a macro, not an inline function, so that it | ||
59 | works correctly even when SIZE_MAX < N. | ||
60 | |||
61 | By gnulib convention, SIZE_MAX represents overflow in size | ||
62 | calculations, so the conservative dividend to use here is | ||
63 | SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. | ||
64 | However, malloc (SIZE_MAX) fails on all known hosts where | ||
65 | sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for | ||
66 | exactly-SIZE_MAX allocations on such hosts; this avoids a test and | ||
67 | branch when S is known to be 1. */ | ||
68 | # define xalloc_oversized(n, s) \ | ||
69 | ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) | ||
70 | |||
71 | |||
72 | /* In the following macros, T must be an elementary or structure/union or | ||
73 | typedef'ed type, or a pointer to such a type. To apply one of the | ||
74 | following macros to a function pointer or array type, you need to typedef | ||
75 | it first and use the typedef name. */ | ||
76 | |||
77 | /* Allocate an object of type T dynamically, with error checking. */ | ||
78 | /* extern t *XMALLOC (typename t); */ | ||
79 | # define XMALLOC(t) ((t *) xmalloc (sizeof (t))) | ||
80 | |||
81 | /* Allocate memory for N elements of type T, with error checking. */ | ||
82 | /* extern t *XNMALLOC (size_t n, typename t); */ | ||
83 | # define XNMALLOC(n, t) \ | ||
84 | ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) | ||
85 | |||
86 | /* Allocate an object of type T dynamically, with error checking, | ||
87 | and zero it. */ | ||
88 | /* extern t *XZALLOC (typename t); */ | ||
89 | # define XZALLOC(t) ((t *) xzalloc (sizeof (t))) | ||
90 | |||
91 | /* Allocate memory for N elements of type T, with error checking, | ||
92 | and zero it. */ | ||
93 | /* extern t *XCALLOC (size_t n, typename t); */ | ||
94 | # define XCALLOC(n, t) \ | ||
95 | ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) | ||
96 | |||
97 | |||
98 | # if HAVE_INLINE | ||
99 | # define static_inline static inline | ||
100 | # else | ||
101 | void *xnmalloc (size_t n, size_t s); | ||
102 | void *xnrealloc (void *p, size_t n, size_t s); | ||
103 | void *x2nrealloc (void *p, size_t *pn, size_t s); | ||
104 | char *xcharalloc (size_t n); | ||
105 | # endif | ||
106 | |||
107 | # ifdef static_inline | ||
108 | |||
109 | /* Allocate an array of N objects, each with S bytes of memory, | ||
110 | dynamically, with error checking. S must be nonzero. */ | ||
111 | |||
112 | static_inline void * | ||
113 | xnmalloc (size_t n, size_t s) | ||
114 | { | ||
115 | if (xalloc_oversized (n, s)) | ||
116 | xalloc_die (); | ||
117 | return xmalloc (n * s); | ||
118 | } | ||
119 | |||
120 | /* Change the size of an allocated block of memory P to an array of N | ||
121 | objects each of S bytes, with error checking. S must be nonzero. */ | ||
122 | |||
123 | static_inline void * | ||
124 | xnrealloc (void *p, size_t n, size_t s) | ||
125 | { | ||
126 | if (xalloc_oversized (n, s)) | ||
127 | xalloc_die (); | ||
128 | return xrealloc (p, n * s); | ||
129 | } | ||
130 | |||
131 | /* If P is null, allocate a block of at least *PN such objects; | ||
132 | otherwise, reallocate P so that it contains more than *PN objects | ||
133 | each of S bytes. *PN must be nonzero unless P is null, and S must | ||
134 | be nonzero. Set *PN to the new number of objects, and return the | ||
135 | pointer to the new block. *PN is never set to zero, and the | ||
136 | returned pointer is never null. | ||
137 | |||
138 | Repeated reallocations are guaranteed to make progress, either by | ||
139 | allocating an initial block with a nonzero size, or by allocating a | ||
140 | larger block. | ||
141 | |||
142 | In the following implementation, nonzero sizes are doubled so that | ||
143 | repeated reallocations have O(N log N) overall cost rather than | ||
144 | O(N**2) cost, but the specification for this function does not | ||
145 | guarantee that sizes are doubled. | ||
146 | |||
147 | Here is an example of use: | ||
148 | |||
149 | int *p = NULL; | ||
150 | size_t used = 0; | ||
151 | size_t allocated = 0; | ||
152 | |||
153 | void | ||
154 | append_int (int value) | ||
155 | { | ||
156 | if (used == allocated) | ||
157 | p = x2nrealloc (p, &allocated, sizeof *p); | ||
158 | p[used++] = value; | ||
159 | } | ||
160 | |||
161 | This causes x2nrealloc to allocate a block of some nonzero size the | ||
162 | first time it is called. | ||
163 | |||
164 | To have finer-grained control over the initial size, set *PN to a | ||
165 | nonzero value before calling this function with P == NULL. For | ||
166 | example: | ||
167 | |||
168 | int *p = NULL; | ||
169 | size_t used = 0; | ||
170 | size_t allocated = 0; | ||
171 | size_t allocated1 = 1000; | ||
172 | |||
173 | void | ||
174 | append_int (int value) | ||
175 | { | ||
176 | if (used == allocated) | ||
177 | { | ||
178 | p = x2nrealloc (p, &allocated1, sizeof *p); | ||
179 | allocated = allocated1; | ||
180 | } | ||
181 | p[used++] = value; | ||
182 | } | ||
183 | |||
184 | */ | ||
185 | |||
186 | static_inline void * | ||
187 | x2nrealloc (void *p, size_t *pn, size_t s) | ||
188 | { | ||
189 | size_t n = *pn; | ||
190 | |||
191 | if (! p) | ||
192 | { | ||
193 | if (! n) | ||
194 | { | ||
195 | /* The approximate size to use for initial small allocation | ||
196 | requests, when the invoking code specifies an old size of | ||
197 | zero. 64 bytes is the largest "small" request for the | ||
198 | GNU C library malloc. */ | ||
199 | enum { DEFAULT_MXFAST = 64 }; | ||
200 | |||
201 | n = DEFAULT_MXFAST / s; | ||
202 | n += !n; | ||
203 | } | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | if (((size_t) -1) / 2 / s < n) | ||
208 | xalloc_die (); | ||
209 | n *= 2; | ||
210 | } | ||
211 | |||
212 | *pn = n; | ||
213 | return xrealloc (p, n * s); | ||
214 | } | ||
215 | |||
216 | /* Return a pointer to a new buffer of N bytes. This is like xmalloc, | ||
217 | except it returns char *. */ | ||
218 | |||
219 | static_inline char * | ||
220 | xcharalloc (size_t n) | ||
221 | { | ||
222 | return XNMALLOC (n, char); | ||
223 | } | ||
224 | |||
225 | # endif | ||
226 | |||
227 | # ifdef __cplusplus | ||
228 | } | ||
229 | |||
230 | /* C++ does not allow conversions from void * to other pointer types | ||
231 | without a cast. Use templates to work around the problem when | ||
232 | possible. */ | ||
233 | |||
234 | template <typename T> inline T * | ||
235 | xrealloc (T *p, size_t s) | ||
236 | { | ||
237 | return (T *) xrealloc ((void *) p, s); | ||
238 | } | ||
239 | |||
240 | template <typename T> inline T * | ||
241 | xnrealloc (T *p, size_t n, size_t s) | ||
242 | { | ||
243 | return (T *) xnrealloc ((void *) p, n, s); | ||
244 | } | ||
245 | |||
246 | template <typename T> inline T * | ||
247 | x2realloc (T *p, size_t *pn) | ||
248 | { | ||
249 | return (T *) x2realloc ((void *) p, pn); | ||
250 | } | ||
251 | |||
252 | template <typename T> inline T * | ||
253 | x2nrealloc (T *p, size_t *pn, size_t s) | ||
254 | { | ||
255 | return (T *) x2nrealloc ((void *) p, pn, s); | ||
256 | } | ||
257 | |||
258 | template <typename T> inline T * | ||
259 | xmemdup (T const *p, size_t s) | ||
260 | { | ||
261 | return (T *) xmemdup ((void const *) p, s); | ||
262 | } | ||
263 | |||
264 | # endif | ||
265 | |||
266 | |||
267 | #endif /* !XALLOC_H_ */ | ||
diff --git a/gl/xmalloc.c b/gl/xmalloc.c new file mode 100644 index 0000000..318e0dd --- /dev/null +++ b/gl/xmalloc.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* xmalloc.c -- malloc with out of memory checking | ||
2 | |||
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | ||
4 | 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, | ||
5 | Inc. | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2, or (at your option) | ||
10 | any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software Foundation, | ||
19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
20 | |||
21 | #include <config.h> | ||
22 | |||
23 | #if ! HAVE_INLINE | ||
24 | # define static_inline | ||
25 | #endif | ||
26 | #include "xalloc.h" | ||
27 | #undef static_inline | ||
28 | |||
29 | #include <stdlib.h> | ||
30 | #include <string.h> | ||
31 | |||
32 | #ifndef SIZE_MAX | ||
33 | # define SIZE_MAX ((size_t) -1) | ||
34 | #endif | ||
35 | |||
36 | /* 1 if calloc is known to be compatible with GNU calloc. This | ||
37 | matters if we are not also using the calloc module, which defines | ||
38 | HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ | ||
39 | #if defined HAVE_CALLOC || defined __GLIBC__ | ||
40 | enum { HAVE_GNU_CALLOC = 1 }; | ||
41 | #else | ||
42 | enum { HAVE_GNU_CALLOC = 0 }; | ||
43 | #endif | ||
44 | |||
45 | /* Allocate N bytes of memory dynamically, with error checking. */ | ||
46 | |||
47 | void * | ||
48 | xmalloc (size_t n) | ||
49 | { | ||
50 | void *p = malloc (n); | ||
51 | if (!p && n != 0) | ||
52 | xalloc_die (); | ||
53 | return p; | ||
54 | } | ||
55 | |||
56 | /* Change the size of an allocated block of memory P to N bytes, | ||
57 | with error checking. */ | ||
58 | |||
59 | void * | ||
60 | xrealloc (void *p, size_t n) | ||
61 | { | ||
62 | p = realloc (p, n); | ||
63 | if (!p && n != 0) | ||
64 | xalloc_die (); | ||
65 | return p; | ||
66 | } | ||
67 | |||
68 | /* If P is null, allocate a block of at least *PN bytes; otherwise, | ||
69 | reallocate P so that it contains more than *PN bytes. *PN must be | ||
70 | nonzero unless P is null. Set *PN to the new block's size, and | ||
71 | return the pointer to the new block. *PN is never set to zero, and | ||
72 | the returned pointer is never null. */ | ||
73 | |||
74 | void * | ||
75 | x2realloc (void *p, size_t *pn) | ||
76 | { | ||
77 | return x2nrealloc (p, pn, 1); | ||
78 | } | ||
79 | |||
80 | /* Allocate S bytes of zeroed memory dynamically, with error checking. | ||
81 | There's no need for xnzalloc (N, S), since it would be equivalent | ||
82 | to xcalloc (N, S). */ | ||
83 | |||
84 | void * | ||
85 | xzalloc (size_t s) | ||
86 | { | ||
87 | return memset (xmalloc (s), 0, s); | ||
88 | } | ||
89 | |||
90 | /* Allocate zeroed memory for N elements of S bytes, with error | ||
91 | checking. S must be nonzero. */ | ||
92 | |||
93 | void * | ||
94 | xcalloc (size_t n, size_t s) | ||
95 | { | ||
96 | void *p; | ||
97 | /* Test for overflow, since some calloc implementations don't have | ||
98 | proper overflow checks. But omit overflow and size-zero tests if | ||
99 | HAVE_GNU_CALLOC, since GNU calloc catches overflow and never | ||
100 | returns NULL if successful. */ | ||
101 | if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) | ||
102 | || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) | ||
103 | xalloc_die (); | ||
104 | return p; | ||
105 | } | ||
106 | |||
107 | /* Clone an object P of size S, with error checking. There's no need | ||
108 | for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any | ||
109 | need for an arithmetic overflow check. */ | ||
110 | |||
111 | void * | ||
112 | xmemdup (void const *p, size_t s) | ||
113 | { | ||
114 | return memcpy (xmalloc (s), p, s); | ||
115 | } | ||
116 | |||
117 | /* Clone STRING. */ | ||
118 | |||
119 | char * | ||
120 | xstrdup (char const *string) | ||
121 | { | ||
122 | return xmemdup (string, strlen (string) + 1); | ||
123 | } | ||
diff --git a/gl/xsize.h b/gl/xsize.h new file mode 100644 index 0000000..341fb16 --- /dev/null +++ b/gl/xsize.h | |||
@@ -0,0 +1,108 @@ | |||
1 | /* xsize.h -- Checked size_t computations. | ||
2 | |||
3 | Copyright (C) 2003 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef _XSIZE_H | ||
20 | #define _XSIZE_H | ||
21 | |||
22 | /* Get size_t. */ | ||
23 | #include <stddef.h> | ||
24 | |||
25 | /* Get SIZE_MAX. */ | ||
26 | #include <limits.h> | ||
27 | #if HAVE_STDINT_H | ||
28 | # include <stdint.h> | ||
29 | #endif | ||
30 | |||
31 | /* The size of memory objects is often computed through expressions of | ||
32 | type size_t. Example: | ||
33 | void* p = malloc (header_size + n * element_size). | ||
34 | These computations can lead to overflow. When this happens, malloc() | ||
35 | returns a piece of memory that is way too small, and the program then | ||
36 | crashes while attempting to fill the memory. | ||
37 | To avoid this, the functions and macros in this file check for overflow. | ||
38 | The convention is that SIZE_MAX represents overflow. | ||
39 | malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc | ||
40 | implementation that uses mmap --, it's recommended to use size_overflow_p() | ||
41 | or size_in_bounds_p() before invoking malloc(). | ||
42 | The example thus becomes: | ||
43 | size_t size = xsum (header_size, xtimes (n, element_size)); | ||
44 | void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); | ||
45 | */ | ||
46 | |||
47 | /* Convert an arbitrary value >= 0 to type size_t. */ | ||
48 | #define xcast_size_t(N) \ | ||
49 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) | ||
50 | |||
51 | /* Sum of two sizes, with overflow check. */ | ||
52 | static inline size_t | ||
53 | #if __GNUC__ >= 3 | ||
54 | __attribute__ ((__pure__)) | ||
55 | #endif | ||
56 | xsum (size_t size1, size_t size2) | ||
57 | { | ||
58 | size_t sum = size1 + size2; | ||
59 | return (sum >= size1 ? sum : SIZE_MAX); | ||
60 | } | ||
61 | |||
62 | /* Sum of three sizes, with overflow check. */ | ||
63 | static inline size_t | ||
64 | #if __GNUC__ >= 3 | ||
65 | __attribute__ ((__pure__)) | ||
66 | #endif | ||
67 | xsum3 (size_t size1, size_t size2, size_t size3) | ||
68 | { | ||
69 | return xsum (xsum (size1, size2), size3); | ||
70 | } | ||
71 | |||
72 | /* Sum of four sizes, with overflow check. */ | ||
73 | static inline size_t | ||
74 | #if __GNUC__ >= 3 | ||
75 | __attribute__ ((__pure__)) | ||
76 | #endif | ||
77 | xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) | ||
78 | { | ||
79 | return xsum (xsum (xsum (size1, size2), size3), size4); | ||
80 | } | ||
81 | |||
82 | /* Maximum of two sizes, with overflow check. */ | ||
83 | static inline size_t | ||
84 | #if __GNUC__ >= 3 | ||
85 | __attribute__ ((__pure__)) | ||
86 | #endif | ||
87 | xmax (size_t size1, size_t size2) | ||
88 | { | ||
89 | /* No explicit check is needed here, because for any n: | ||
90 | max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ | ||
91 | return (size1 >= size2 ? size1 : size2); | ||
92 | } | ||
93 | |||
94 | /* Multiplication of a count with an element size, with overflow check. | ||
95 | The count must be >= 0 and the element size must be > 0. | ||
96 | This is a macro, not an inline function, so that it works correctly even | ||
97 | when N is of a wider tupe and N > SIZE_MAX. */ | ||
98 | #define xtimes(N, ELSIZE) \ | ||
99 | ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) | ||
100 | |||
101 | /* Check for overflow. */ | ||
102 | #define size_overflow_p(SIZE) \ | ||
103 | ((SIZE) == SIZE_MAX) | ||
104 | /* Check against overflow. */ | ||
105 | #define size_in_bounds_p(SIZE) \ | ||
106 | ((SIZE) != SIZE_MAX) | ||
107 | |||
108 | #endif /* _XSIZE_H */ | ||
diff --git a/gl/xstrndup.c b/gl/xstrndup.c new file mode 100644 index 0000000..afcbc1a --- /dev/null +++ b/gl/xstrndup.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /* Duplicate a bounded initial segment of a string, with out-of-memory | ||
2 | checking. | ||
3 | Copyright (C) 2003, 2006 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #include <config.h> | ||
20 | |||
21 | /* Specification. */ | ||
22 | #include "xstrndup.h" | ||
23 | |||
24 | #include "strndup.h" | ||
25 | #include "xalloc.h" | ||
26 | |||
27 | /* Return a newly allocated copy of at most N bytes of STRING. | ||
28 | In other words, return a copy of the initial segment of length N of | ||
29 | STRING. */ | ||
30 | char * | ||
31 | xstrndup (const char *string, size_t n) | ||
32 | { | ||
33 | char *s = strndup (string, n); | ||
34 | if (! s) | ||
35 | xalloc_die (); | ||
36 | return s; | ||
37 | } | ||
diff --git a/gl/xstrndup.h b/gl/xstrndup.h new file mode 100644 index 0000000..88354cf --- /dev/null +++ b/gl/xstrndup.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* Duplicate a bounded initial segment of a string, with out-of-memory | ||
2 | checking. | ||
3 | Copyright (C) 2003 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #include <stddef.h> | ||
20 | |||
21 | /* Return a newly allocated copy of at most N bytes of STRING. | ||
22 | In other words, return a copy of the initial segment of length N of | ||
23 | STRING. */ | ||
24 | extern char *xstrndup (const char *string, size_t n); | ||
diff --git a/lib/Makefile.am b/lib/Makefile.am index 7edac1f..3909bb9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -2,85 +2,14 @@ | |||
2 | 2 | ||
3 | SUBDIRS = tests | 3 | SUBDIRS = tests |
4 | 4 | ||
5 | noinst_LIBRARIES = libcoreutils.a libnagiosplug.a | 5 | noinst_LIBRARIES = libnagiosplug.a |
6 | 6 | ||
7 | # Will auto pick up fsusage.c mountlist.c | ||
8 | libcoreutils_a_SOURCES = \ | ||
9 | cloexec.c cloexec.h \ | ||
10 | exit.h \ | ||
11 | full-read.c full-read.h \ | ||
12 | full-write.c full-write.h \ | ||
13 | gettext.h \ | ||
14 | safe-read.c safe-read.h \ | ||
15 | safe-write.c safe-write.h strcase.h xalloc-die.c | ||
16 | 7 | ||
17 | # intprops.h required for getloadavg.c | 8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c |
18 | # This needs to be an EXTRA_DIST because the m4s | 9 | EXTRA_DIST = utils_base.h utils_disk.h |
19 | # that have AC_LIBSOURCES for intprops.h are not necessary and | ||
20 | # the getloadavg m4 is an autoconf one, so doesn't | ||
21 | # know about intprops.h. Confused? You will be! | ||
22 | EXTRA_DIST = intprops.h | ||
23 | 10 | ||
24 | other_coreutils_files = \ | 11 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
25 | error.c error.h \ | ||
26 | fsusage.c \ | ||
27 | getloadavg.c \ | ||
28 | malloc.c \ | ||
29 | mountlist.c \ | ||
30 | realloc.c \ | ||
31 | strtod.c \ | ||
32 | exitfail.c exitfail.h \ | ||
33 | fsusage.h \ | ||
34 | getopt.c getopt1.c \ | ||
35 | mountlist.h \ | ||
36 | unlocked-io.h \ | ||
37 | xalloc.h \ | ||
38 | xmalloc.c | ||
39 | |||
40 | |||
41 | libcoreutils_a_LIBADD = $(LIBOBJS) $(ALLOCA) | ||
42 | libcoreutils_a_DEPENDENCIES = $(libcoreutils_a_LIBADD) | ||
43 | lib_OBJECTS = $(libcoreutils_a_OBJECTS) | ||
44 | |||
45 | libnagiosplug_a_SOURCES = snprintf.c utils_base.c utils_disk.c | ||
46 | EXTRA_DIST += utils_base.h utils_disk.h | ||
47 | |||
48 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | ||
49 | |||
50 | print_coreutil_files: | ||
51 | @echo $(libcoreutils_a_SOURCES) $(other_coreutils_files) $(EXTRA_DIST) | ||
52 | 12 | ||
53 | test: | 13 | test: |
54 | cd tests && make test | 14 | cd tests && make test |
55 | 15 | ||
56 | # Below are from coreutil's lib/Makefile.am | ||
57 | BUILT_SOURCES = $(STDBOOL_H) | ||
58 | EXTRA_DIST += stdbool_.h | ||
59 | MOSTLYCLEANFILES = stdbool.h stdbool.ht | ||
60 | # Create stdbool.h on systems that lack a working one. | ||
61 | stdbool.h: stdbool_.h | ||
62 | sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' $(srcdir)/stdbool_.h > $@t | ||
63 | mv $@t $@ | ||
64 | |||
65 | BUILT_SOURCES += $(ALLOCA_H) | ||
66 | EXTRA_DIST += alloca_.h | ||
67 | |||
68 | # We need the following in order to create an <alloca.h> when the system | ||
69 | # doesn't have one that works with the given compiler | ||
70 | all-local $(lib_OBJECTS): $(ALLOCA_H) | ||
71 | alloca.h: alloca_.h | ||
72 | cp $(srcdir)/alloca_.h $@-t | ||
73 | mv $@-t $@ | ||
74 | MOSTLYCLEANFILES += alloca.h alloca.h-t | ||
75 | |||
76 | BUILT_SOURCES += $(GETOPT_H) | ||
77 | EXTRA_DIST += getopt_.h getopt_int.h | ||
78 | |||
79 | # We need the following in order to create an <getopt.h> when the system | ||
80 | # doesn't have one that works with the given compiler. | ||
81 | all-local $(lib_OBJECTS): $(GETOPT_H) | ||
82 | getopt.h: getopt_.h | ||
83 | cp $(srcdir)/getopt_.h $@-t | ||
84 | mv $@-t $@ | ||
85 | MOSTLYCLEANFILES += getopt.h getopt.h-t | ||
86 | |||
diff --git a/lib/basename.c b/lib/basename.c deleted file mode 100644 index 5cc97cd..0000000 --- a/lib/basename.c +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | /* basename.c -- return the last element in a file name | ||
2 | |||
3 | Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free | ||
4 | Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "dirname.h" | ||
25 | #include <string.h> | ||
26 | |||
27 | /* In general, we can't use the builtin `basename' function if available, | ||
28 | since it has different meanings in different environments. | ||
29 | In some environments the builtin `basename' modifies its argument. | ||
30 | |||
31 | Return the address of the last file name component of NAME. If | ||
32 | NAME has no file name components because it is all slashes, return | ||
33 | NAME if it is empty, the address of its last slash otherwise. */ | ||
34 | |||
35 | char * | ||
36 | base_name (char const *name) | ||
37 | { | ||
38 | char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); | ||
39 | char const *p; | ||
40 | |||
41 | for (p = base; *p; p++) | ||
42 | { | ||
43 | if (ISSLASH (*p)) | ||
44 | { | ||
45 | /* Treat multiple adjacent slashes like a single slash. */ | ||
46 | do p++; | ||
47 | while (ISSLASH (*p)); | ||
48 | |||
49 | /* If the file name ends in slash, use the trailing slash as | ||
50 | the basename if no non-slashes have been found. */ | ||
51 | if (! *p) | ||
52 | { | ||
53 | if (ISSLASH (*base)) | ||
54 | base = p - 1; | ||
55 | break; | ||
56 | } | ||
57 | |||
58 | /* *P is a non-slash preceded by a slash. */ | ||
59 | base = p; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | return (char *) base; | ||
64 | } | ||
65 | |||
66 | /* Return the length of of the basename NAME. Typically NAME is the | ||
67 | value returned by base_name. Act like strlen (NAME), except omit | ||
68 | redundant trailing slashes. */ | ||
69 | |||
70 | size_t | ||
71 | base_len (char const *name) | ||
72 | { | ||
73 | size_t len; | ||
74 | |||
75 | for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) | ||
76 | continue; | ||
77 | |||
78 | return len; | ||
79 | } | ||
diff --git a/lib/c-strtold.c b/lib/c-strtold.c deleted file mode 100644 index 5510e4a..0000000 --- a/lib/c-strtold.c +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | #define LONG 1 | ||
2 | #include "c-strtod.c" | ||
diff --git a/lib/gettext.h b/lib/gettext.h deleted file mode 100644 index 285cb31..0000000 --- a/lib/gettext.h +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | /* Convenience header for conditional use of GNU <libintl.h>. | ||
2 | Copyright (C) 1995-1998, 2000-2002, 2004 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _LIBGETTEXT_H | ||
19 | #define _LIBGETTEXT_H 1 | ||
20 | |||
21 | /* NLS can be disabled through the configure --disable-nls option. */ | ||
22 | #if ENABLE_NLS | ||
23 | |||
24 | /* Get declarations of GNU message catalog functions. */ | ||
25 | # include <libintl.h> | ||
26 | |||
27 | #else | ||
28 | |||
29 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which | ||
30 | chokes if dcgettext is defined as a macro. So include it now, to make | ||
31 | later inclusions of <locale.h> a NOP. We don't include <libintl.h> | ||
32 | as well because people using "gettext.h" will not include <libintl.h>, | ||
33 | and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> | ||
34 | is OK. */ | ||
35 | #if defined(__sun) | ||
36 | # include <locale.h> | ||
37 | #endif | ||
38 | |||
39 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include | ||
40 | <libintl.h>, which chokes if dcgettext is defined as a macro. So include | ||
41 | it now, to make later inclusions of <libintl.h> a NOP. */ | ||
42 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) | ||
43 | # include <cstdlib> | ||
44 | # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H | ||
45 | # include <libintl.h> | ||
46 | # endif | ||
47 | #endif | ||
48 | |||
49 | /* Disabled NLS. | ||
50 | The casts to 'const char *' serve the purpose of producing warnings | ||
51 | for invalid uses of the value returned from these functions. | ||
52 | On pre-ANSI systems without 'const', the config.h file is supposed to | ||
53 | contain "#define const". */ | ||
54 | # define gettext(Msgid) ((const char *) (Msgid)) | ||
55 | # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) | ||
56 | # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) | ||
57 | # define ngettext(Msgid1, Msgid2, N) \ | ||
58 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
59 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ | ||
60 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
61 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ | ||
62 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
63 | # define textdomain(Domainname) ((const char *) (Domainname)) | ||
64 | # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) | ||
65 | # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) | ||
66 | |||
67 | #endif | ||
68 | |||
69 | /* A pseudo function call that serves as a marker for the automated | ||
70 | extraction of messages, but does not call gettext(). The run-time | ||
71 | translation is done at a different place in the code. | ||
72 | The argument, String, should be a literal string. Concatenated strings | ||
73 | and other string expressions won't work. | ||
74 | The macro's expansion is not parenthesized, so that it is suitable as | ||
75 | initializer for static 'char[]' or 'const char[]' variables. */ | ||
76 | #define gettext_noop(String) String | ||
77 | |||
78 | #endif /* _LIBGETTEXT_H */ | ||
diff --git a/lib/realloc.c b/lib/realloc.c deleted file mode 100644 index fe94822..0000000 --- a/lib/realloc.c +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | /* realloc() function that is glibc compatible. | ||
2 | Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* written by Jim Meyering */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | #undef realloc | ||
24 | |||
25 | #include <stdlib.h> | ||
26 | |||
27 | /* Change the size of an allocated block of memory P to N bytes, | ||
28 | with error checking. If N is zero, change it to 1. If P is NULL, | ||
29 | use malloc. */ | ||
30 | |||
31 | void * | ||
32 | rpl_realloc (void *p, size_t n) | ||
33 | { | ||
34 | if (n == 0) | ||
35 | { | ||
36 | n = 1; | ||
37 | |||
38 | /* In theory realloc might fail, so don't rely on it to free. */ | ||
39 | free (p); | ||
40 | p = NULL; | ||
41 | } | ||
42 | |||
43 | if (p == NULL) | ||
44 | return malloc (n); | ||
45 | return realloc (p, n); | ||
46 | } | ||
diff --git a/lib/snprintf.c b/lib/snprintf.c deleted file mode 100644 index 633517d..0000000 --- a/lib/snprintf.c +++ /dev/null | |||
@@ -1,1023 +0,0 @@ | |||
1 | /* | ||
2 | * NOTE: If you change this file, please merge it into rsync, samba, etc. | ||
3 | */ | ||
4 | |||
5 | /* | ||
6 | * Copyright Patrick Powell 1995 | ||
7 | * This code is based on code written by Patrick Powell (papowell@astart.com) | ||
8 | * It may be used for any purpose as long as this notice remains intact | ||
9 | * on all source code distributions | ||
10 | */ | ||
11 | |||
12 | /************************************************************** | ||
13 | * Original: | ||
14 | * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 | ||
15 | * A bombproof version of doprnt (dopr) included. | ||
16 | * Sigh. This sort of thing is always nasty do deal with. Note that | ||
17 | * the version here does not include floating point... | ||
18 | * | ||
19 | * snprintf() is used instead of sprintf() as it does limit checks | ||
20 | * for string length. This covers a nasty loophole. | ||
21 | * | ||
22 | * The other functions are there to prevent NULL pointers from | ||
23 | * causing nast effects. | ||
24 | * | ||
25 | * More Recently: | ||
26 | * Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43 | ||
27 | * This was ugly. It is still ugly. I opted out of floating point | ||
28 | * numbers, but the formatter understands just about everything | ||
29 | * from the normal C string format, at least as far as I can tell from | ||
30 | * the Solaris 2.5 printf(3S) man page. | ||
31 | * | ||
32 | * Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1 | ||
33 | * Ok, added some minimal floating point support, which means this | ||
34 | * probably requires libm on most operating systems. Don't yet | ||
35 | * support the exponent (e,E) and sigfig (g,G). Also, fmtint() | ||
36 | * was pretty badly broken, it just wasn't being exercised in ways | ||
37 | * which showed it, so that's been fixed. Also, formated the code | ||
38 | * to mutt conventions, and removed dead code left over from the | ||
39 | * original. Also, there is now a builtin-test, just compile with: | ||
40 | * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm | ||
41 | * and run snprintf for results. | ||
42 | * | ||
43 | * Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i | ||
44 | * The PGP code was using unsigned hexadecimal formats. | ||
45 | * Unfortunately, unsigned formats simply didn't work. | ||
46 | * | ||
47 | * Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8 | ||
48 | * The original code assumed that both snprintf() and vsnprintf() were | ||
49 | * missing. Some systems only have snprintf() but not vsnprintf(), so | ||
50 | * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. | ||
51 | * | ||
52 | * Andrew Tridgell (tridge@samba.org) Oct 1998 | ||
53 | * fixed handling of %.0f | ||
54 | * added test for HAVE_LONG_DOUBLE | ||
55 | * | ||
56 | * tridge@samba.org, idra@samba.org, April 2001 | ||
57 | * got rid of fcvt code (twas buggy and made testing harder) | ||
58 | * added C99 semantics | ||
59 | * | ||
60 | * date: 2002/12/19 19:56:31; author: herb; state: Exp; lines: +2 -0 | ||
61 | * actually print args for %g and %e | ||
62 | * | ||
63 | * date: 2002/06/03 13:37:52; author: jmcd; state: Exp; lines: +8 -0 | ||
64 | * Since includes.h isn't included here, VA_COPY has to be defined here. I don't | ||
65 | * see any include file that is guaranteed to be here, so I'm defining it | ||
66 | * locally. Fixes AIX and Solaris builds. | ||
67 | * | ||
68 | * date: 2002/06/03 03:07:24; author: tridge; state: Exp; lines: +5 -13 | ||
69 | * put the ifdef for HAVE_VA_COPY in one place rather than in lots of | ||
70 | * functions | ||
71 | * | ||
72 | * date: 2002/05/17 14:51:22; author: jmcd; state: Exp; lines: +21 -4 | ||
73 | * Fix usage of va_list passed as an arg. Use __va_copy before using it | ||
74 | * when it exists. | ||
75 | * | ||
76 | * date: 2002/04/16 22:38:04; author: idra; state: Exp; lines: +20 -14 | ||
77 | * Fix incorrect zpadlen handling in fmtfp. | ||
78 | * Thanks to Ollie Oldham <ollie.oldham@metro-optix.com> for spotting it. | ||
79 | * few mods to make it easier to compile the tests. | ||
80 | * addedd the "Ollie" test to the floating point ones. | ||
81 | * | ||
82 | * Martin Pool (mbp@samba.org) April 2003 | ||
83 | * Remove NO_CONFIG_H so that the test case can be built within a source | ||
84 | * tree with less trouble. | ||
85 | * Remove unnecessary SAFE_FREE() definition. | ||
86 | * | ||
87 | * Martin Pool (mbp@samba.org) May 2003 | ||
88 | * Put in a prototype for dummy_snprintf() to quiet compiler warnings. | ||
89 | * | ||
90 | * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even | ||
91 | * if the C library has some snprintf functions already. | ||
92 | **************************************************************/ | ||
93 | |||
94 | #ifndef NO_CONFIG_H | ||
95 | #include "config.h" | ||
96 | #else | ||
97 | #define NULL 0 | ||
98 | #endif | ||
99 | |||
100 | #ifdef TEST_SNPRINTF /* need math library headers for testing */ | ||
101 | |||
102 | /* In test mode, we pretend that this system doesn't have any snprintf | ||
103 | * functions, regardless of what config.h says. */ | ||
104 | # undef HAVE_SNPRINTF | ||
105 | # undef HAVE_VSNPRINTF | ||
106 | # undef HAVE_C99_VSNPRINTF | ||
107 | # undef HAVE_ASPRINTF | ||
108 | # undef HAVE_VASPRINTF | ||
109 | # include <math.h> | ||
110 | #endif /* TEST_SNPRINTF */ | ||
111 | |||
112 | #ifdef HAVE_STRING_H | ||
113 | #include <string.h> | ||
114 | #endif | ||
115 | |||
116 | #ifdef HAVE_STRINGS_H | ||
117 | #include <strings.h> | ||
118 | #endif | ||
119 | #ifdef HAVE_CTYPE_H | ||
120 | #include <ctype.h> | ||
121 | #endif | ||
122 | #include <sys/types.h> | ||
123 | #include <stdarg.h> | ||
124 | #ifdef HAVE_STDLIB_H | ||
125 | #include <stdlib.h> | ||
126 | #endif | ||
127 | |||
128 | #if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF) | ||
129 | /* only include stdio.h if we are not re-defining snprintf or vsnprintf */ | ||
130 | #include <stdio.h> | ||
131 | /* make the compiler happy with an empty file */ | ||
132 | void dummy_snprintf(void); | ||
133 | void dummy_snprintf(void) {} | ||
134 | #endif /* HAVE_SNPRINTF, etc */ | ||
135 | |||
136 | #ifdef HAVE_LONG_DOUBLE | ||
137 | #define LDOUBLE long double | ||
138 | #else | ||
139 | #define LDOUBLE double | ||
140 | #endif | ||
141 | |||
142 | #ifdef HAVE_LONG_LONG | ||
143 | #define LLONG long long | ||
144 | #else | ||
145 | #define LLONG long | ||
146 | #endif | ||
147 | |||
148 | #ifndef VA_COPY | ||
149 | #ifdef HAVE_VA_COPY | ||
150 | #define VA_COPY(dest, src) va_copy(dest, src) | ||
151 | #else | ||
152 | #ifdef HAVE___VA_COPY | ||
153 | #define VA_COPY(dest, src) __va_copy(dest, src) | ||
154 | #else | ||
155 | #define VA_COPY(dest, src) (dest) = (src) | ||
156 | #endif | ||
157 | #endif | ||
158 | |||
159 | /* | ||
160 | * dopr(): poor man's version of doprintf | ||
161 | */ | ||
162 | |||
163 | /* format read states */ | ||
164 | #define DP_S_DEFAULT 0 | ||
165 | #define DP_S_FLAGS 1 | ||
166 | #define DP_S_MIN 2 | ||
167 | #define DP_S_DOT 3 | ||
168 | #define DP_S_MAX 4 | ||
169 | #define DP_S_MOD 5 | ||
170 | #define DP_S_CONV 6 | ||
171 | #define DP_S_DONE 7 | ||
172 | |||
173 | /* format flags - Bits */ | ||
174 | #define DP_F_MINUS (1 << 0) | ||
175 | #define DP_F_PLUS (1 << 1) | ||
176 | #define DP_F_SPACE (1 << 2) | ||
177 | #define DP_F_NUM (1 << 3) | ||
178 | #define DP_F_ZERO (1 << 4) | ||
179 | #define DP_F_UP (1 << 5) | ||
180 | #define DP_F_UNSIGNED (1 << 6) | ||
181 | |||
182 | /* Conversion Flags */ | ||
183 | #define DP_C_SHORT 1 | ||
184 | #define DP_C_LONG 2 | ||
185 | #define DP_C_LDOUBLE 3 | ||
186 | #define DP_C_LLONG 4 | ||
187 | |||
188 | #define char_to_int(p) ((p)- '0') | ||
189 | #ifndef MAX | ||
190 | #define MAX(p,q) (((p) >= (q)) ? (p) : (q)) | ||
191 | #endif | ||
192 | |||
193 | /* yes this really must be a ||. Don't muck with this (tridge) */ | ||
194 | #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) | ||
195 | |||
196 | static size_t dopr(char *buffer, size_t maxlen, const char *format, | ||
197 | va_list args_in); | ||
198 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
199 | char *value, int flags, int min, int max); | ||
200 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
201 | long value, int base, int min, int max, int flags); | ||
202 | static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, | ||
203 | LDOUBLE fvalue, int min, int max, int flags); | ||
204 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | ||
205 | |||
206 | static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | ||
207 | { | ||
208 | char ch; | ||
209 | LLONG value; | ||
210 | LDOUBLE fvalue; | ||
211 | char *strvalue; | ||
212 | int min; | ||
213 | int max; | ||
214 | int state; | ||
215 | int flags; | ||
216 | int cflags; | ||
217 | size_t currlen; | ||
218 | va_list args; | ||
219 | |||
220 | VA_COPY(args, args_in); | ||
221 | |||
222 | state = DP_S_DEFAULT; | ||
223 | currlen = flags = cflags = min = 0; | ||
224 | max = -1; | ||
225 | ch = *format++; | ||
226 | |||
227 | while (state != DP_S_DONE) { | ||
228 | if (ch == '\0') | ||
229 | state = DP_S_DONE; | ||
230 | |||
231 | switch(state) { | ||
232 | case DP_S_DEFAULT: | ||
233 | if (ch == '%') | ||
234 | state = DP_S_FLAGS; | ||
235 | else | ||
236 | dopr_outch (buffer, &currlen, maxlen, ch); | ||
237 | ch = *format++; | ||
238 | break; | ||
239 | case DP_S_FLAGS: | ||
240 | switch (ch) { | ||
241 | case '-': | ||
242 | flags |= DP_F_MINUS; | ||
243 | ch = *format++; | ||
244 | break; | ||
245 | case '+': | ||
246 | flags |= DP_F_PLUS; | ||
247 | ch = *format++; | ||
248 | break; | ||
249 | case ' ': | ||
250 | flags |= DP_F_SPACE; | ||
251 | ch = *format++; | ||
252 | break; | ||
253 | case '#': | ||
254 | flags |= DP_F_NUM; | ||
255 | ch = *format++; | ||
256 | break; | ||
257 | case '0': | ||
258 | flags |= DP_F_ZERO; | ||
259 | ch = *format++; | ||
260 | break; | ||
261 | default: | ||
262 | state = DP_S_MIN; | ||
263 | break; | ||
264 | } | ||
265 | break; | ||
266 | case DP_S_MIN: | ||
267 | if (isdigit((unsigned char)ch)) { | ||
268 | min = 10*min + char_to_int (ch); | ||
269 | ch = *format++; | ||
270 | } else if (ch == '*') { | ||
271 | min = va_arg (args, int); | ||
272 | ch = *format++; | ||
273 | state = DP_S_DOT; | ||
274 | } else { | ||
275 | state = DP_S_DOT; | ||
276 | } | ||
277 | break; | ||
278 | case DP_S_DOT: | ||
279 | if (ch == '.') { | ||
280 | state = DP_S_MAX; | ||
281 | ch = *format++; | ||
282 | } else { | ||
283 | state = DP_S_MOD; | ||
284 | } | ||
285 | break; | ||
286 | case DP_S_MAX: | ||
287 | if (isdigit((unsigned char)ch)) { | ||
288 | if (max < 0) | ||
289 | max = 0; | ||
290 | max = 10*max + char_to_int (ch); | ||
291 | ch = *format++; | ||
292 | } else if (ch == '*') { | ||
293 | max = va_arg (args, int); | ||
294 | ch = *format++; | ||
295 | state = DP_S_MOD; | ||
296 | } else { | ||
297 | state = DP_S_MOD; | ||
298 | } | ||
299 | break; | ||
300 | case DP_S_MOD: | ||
301 | switch (ch) { | ||
302 | case 'h': | ||
303 | cflags = DP_C_SHORT; | ||
304 | ch = *format++; | ||
305 | break; | ||
306 | case 'l': | ||
307 | cflags = DP_C_LONG; | ||
308 | ch = *format++; | ||
309 | if (ch == 'l') { /* It's a long long */ | ||
310 | cflags = DP_C_LLONG; | ||
311 | ch = *format++; | ||
312 | } | ||
313 | break; | ||
314 | case 'L': | ||
315 | cflags = DP_C_LDOUBLE; | ||
316 | ch = *format++; | ||
317 | break; | ||
318 | default: | ||
319 | break; | ||
320 | } | ||
321 | state = DP_S_CONV; | ||
322 | break; | ||
323 | case DP_S_CONV: | ||
324 | switch (ch) { | ||
325 | case 'd': | ||
326 | case 'i': | ||
327 | if (cflags == DP_C_SHORT) | ||
328 | value = va_arg (args, int); | ||
329 | else if (cflags == DP_C_LONG) | ||
330 | value = va_arg (args, long int); | ||
331 | else if (cflags == DP_C_LLONG) | ||
332 | value = va_arg (args, LLONG); | ||
333 | else | ||
334 | value = va_arg (args, int); | ||
335 | fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); | ||
336 | break; | ||
337 | case 'o': | ||
338 | flags |= DP_F_UNSIGNED; | ||
339 | if (cflags == DP_C_SHORT) | ||
340 | value = va_arg (args, unsigned int); | ||
341 | else if (cflags == DP_C_LONG) | ||
342 | value = (long)va_arg (args, unsigned long int); | ||
343 | else if (cflags == DP_C_LLONG) | ||
344 | value = (long)va_arg (args, unsigned LLONG); | ||
345 | else | ||
346 | value = (long)va_arg (args, unsigned int); | ||
347 | fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags); | ||
348 | break; | ||
349 | case 'u': | ||
350 | flags |= DP_F_UNSIGNED; | ||
351 | if (cflags == DP_C_SHORT) | ||
352 | value = va_arg (args, unsigned int); | ||
353 | else if (cflags == DP_C_LONG) | ||
354 | value = (long)va_arg (args, unsigned long int); | ||
355 | else if (cflags == DP_C_LLONG) | ||
356 | value = (LLONG)va_arg (args, unsigned LLONG); | ||
357 | else | ||
358 | value = (long)va_arg (args, unsigned int); | ||
359 | fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); | ||
360 | break; | ||
361 | case 'X': | ||
362 | flags |= DP_F_UP; | ||
363 | case 'x': | ||
364 | flags |= DP_F_UNSIGNED; | ||
365 | if (cflags == DP_C_SHORT) | ||
366 | value = va_arg (args, unsigned int); | ||
367 | else if (cflags == DP_C_LONG) | ||
368 | value = (long)va_arg (args, unsigned long int); | ||
369 | else if (cflags == DP_C_LLONG) | ||
370 | value = (LLONG)va_arg (args, unsigned LLONG); | ||
371 | else | ||
372 | value = (long)va_arg (args, unsigned int); | ||
373 | fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags); | ||
374 | break; | ||
375 | case 'f': | ||
376 | if (cflags == DP_C_LDOUBLE) | ||
377 | fvalue = va_arg (args, LDOUBLE); | ||
378 | else | ||
379 | fvalue = va_arg (args, double); | ||
380 | /* um, floating point? */ | ||
381 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
382 | break; | ||
383 | case 'E': | ||
384 | flags |= DP_F_UP; | ||
385 | case 'e': | ||
386 | if (cflags == DP_C_LDOUBLE) | ||
387 | fvalue = va_arg (args, LDOUBLE); | ||
388 | else | ||
389 | fvalue = va_arg (args, double); | ||
390 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
391 | break; | ||
392 | case 'G': | ||
393 | flags |= DP_F_UP; | ||
394 | case 'g': | ||
395 | if (cflags == DP_C_LDOUBLE) | ||
396 | fvalue = va_arg (args, LDOUBLE); | ||
397 | else | ||
398 | fvalue = va_arg (args, double); | ||
399 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
400 | break; | ||
401 | case 'c': | ||
402 | dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); | ||
403 | break; | ||
404 | case 's': | ||
405 | strvalue = va_arg (args, char *); | ||
406 | if (!strvalue) strvalue = "(NULL)"; | ||
407 | if (max == -1) { | ||
408 | max = strlen(strvalue); | ||
409 | } | ||
410 | if (min > 0 && max >= 0 && min > max) max = min; | ||
411 | fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max); | ||
412 | break; | ||
413 | case 'p': | ||
414 | strvalue = va_arg (args, void *); | ||
415 | fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags); | ||
416 | break; | ||
417 | case 'n': | ||
418 | if (cflags == DP_C_SHORT) { | ||
419 | short int *num; | ||
420 | num = va_arg (args, short int *); | ||
421 | *num = currlen; | ||
422 | } else if (cflags == DP_C_LONG) { | ||
423 | long int *num; | ||
424 | num = va_arg (args, long int *); | ||
425 | *num = (long int)currlen; | ||
426 | } else if (cflags == DP_C_LLONG) { | ||
427 | LLONG *num; | ||
428 | num = va_arg (args, LLONG *); | ||
429 | *num = (LLONG)currlen; | ||
430 | } else { | ||
431 | int *num; | ||
432 | num = va_arg (args, int *); | ||
433 | *num = currlen; | ||
434 | } | ||
435 | break; | ||
436 | case '%': | ||
437 | dopr_outch (buffer, &currlen, maxlen, ch); | ||
438 | break; | ||
439 | case 'w': | ||
440 | /* not supported yet, treat as next char */ | ||
441 | ch = *format++; | ||
442 | break; | ||
443 | default: | ||
444 | /* Unknown, skip */ | ||
445 | break; | ||
446 | } | ||
447 | ch = *format++; | ||
448 | state = DP_S_DEFAULT; | ||
449 | flags = cflags = min = 0; | ||
450 | max = -1; | ||
451 | break; | ||
452 | case DP_S_DONE: | ||
453 | break; | ||
454 | default: | ||
455 | /* hmm? */ | ||
456 | break; /* some picky compilers need this */ | ||
457 | } | ||
458 | } | ||
459 | if (maxlen != 0) { | ||
460 | if (currlen < maxlen - 1) | ||
461 | buffer[currlen] = '\0'; | ||
462 | else if (maxlen > 0) | ||
463 | buffer[maxlen - 1] = '\0'; | ||
464 | } | ||
465 | |||
466 | return currlen; | ||
467 | } | ||
468 | |||
469 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
470 | char *value, int flags, int min, int max) | ||
471 | { | ||
472 | int padlen, strln; /* amount to pad */ | ||
473 | int cnt = 0; | ||
474 | |||
475 | #ifdef DEBUG_SNPRINTF | ||
476 | printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value); | ||
477 | #endif | ||
478 | if (value == 0) { | ||
479 | value = "<NULL>"; | ||
480 | } | ||
481 | |||
482 | for (strln = 0; value[strln]; ++strln); /* strlen */ | ||
483 | padlen = min - strln; | ||
484 | if (padlen < 0) | ||
485 | padlen = 0; | ||
486 | if (flags & DP_F_MINUS) | ||
487 | padlen = -padlen; /* Left Justify */ | ||
488 | |||
489 | while ((padlen > 0) && (cnt < max)) { | ||
490 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
491 | --padlen; | ||
492 | ++cnt; | ||
493 | } | ||
494 | while (*value && (cnt < max)) { | ||
495 | dopr_outch (buffer, currlen, maxlen, *value++); | ||
496 | ++cnt; | ||
497 | } | ||
498 | while ((padlen < 0) && (cnt < max)) { | ||
499 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
500 | ++padlen; | ||
501 | ++cnt; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ | ||
506 | |||
507 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
508 | long value, int base, int min, int max, int flags) | ||
509 | { | ||
510 | int signvalue = 0; | ||
511 | unsigned long uvalue; | ||
512 | char convert[20]; | ||
513 | int place = 0; | ||
514 | int spadlen = 0; /* amount to space pad */ | ||
515 | int zpadlen = 0; /* amount to zero pad */ | ||
516 | int caps = 0; | ||
517 | |||
518 | if (max < 0) | ||
519 | max = 0; | ||
520 | |||
521 | uvalue = value; | ||
522 | |||
523 | if(!(flags & DP_F_UNSIGNED)) { | ||
524 | if( value < 0 ) { | ||
525 | signvalue = '-'; | ||
526 | uvalue = -value; | ||
527 | } else { | ||
528 | if (flags & DP_F_PLUS) /* Do a sign (+/i) */ | ||
529 | signvalue = '+'; | ||
530 | else if (flags & DP_F_SPACE) | ||
531 | signvalue = ' '; | ||
532 | } | ||
533 | } | ||
534 | |||
535 | if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ | ||
536 | |||
537 | do { | ||
538 | convert[place++] = | ||
539 | (caps? "0123456789ABCDEF":"0123456789abcdef") | ||
540 | [uvalue % (unsigned)base ]; | ||
541 | uvalue = (uvalue / (unsigned)base ); | ||
542 | } while(uvalue && (place < 20)); | ||
543 | if (place == 20) place--; | ||
544 | convert[place] = 0; | ||
545 | |||
546 | zpadlen = max - place; | ||
547 | spadlen = min - MAX (max, place) - (signvalue ? 1 : 0); | ||
548 | if (zpadlen < 0) zpadlen = 0; | ||
549 | if (spadlen < 0) spadlen = 0; | ||
550 | if (flags & DP_F_ZERO) { | ||
551 | zpadlen = MAX(zpadlen, spadlen); | ||
552 | spadlen = 0; | ||
553 | } | ||
554 | if (flags & DP_F_MINUS) | ||
555 | spadlen = -spadlen; /* Left Justifty */ | ||
556 | |||
557 | #ifdef DEBUG_SNPRINTF | ||
558 | printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", | ||
559 | zpadlen, spadlen, min, max, place); | ||
560 | #endif | ||
561 | |||
562 | /* Spaces */ | ||
563 | while (spadlen > 0) { | ||
564 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
565 | --spadlen; | ||
566 | } | ||
567 | |||
568 | /* Sign */ | ||
569 | if (signvalue) | ||
570 | dopr_outch (buffer, currlen, maxlen, signvalue); | ||
571 | |||
572 | /* Zeros */ | ||
573 | if (zpadlen > 0) { | ||
574 | while (zpadlen > 0) { | ||
575 | dopr_outch (buffer, currlen, maxlen, '0'); | ||
576 | --zpadlen; | ||
577 | } | ||
578 | } | ||
579 | |||
580 | /* Digits */ | ||
581 | while (place > 0) | ||
582 | dopr_outch (buffer, currlen, maxlen, convert[--place]); | ||
583 | |||
584 | /* Left Justified spaces */ | ||
585 | while (spadlen < 0) { | ||
586 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
587 | ++spadlen; | ||
588 | } | ||
589 | } | ||
590 | |||
591 | static LDOUBLE abs_val(LDOUBLE value) | ||
592 | { | ||
593 | LDOUBLE result = value; | ||
594 | |||
595 | if (value < 0) | ||
596 | result = -value; | ||
597 | |||
598 | return result; | ||
599 | } | ||
600 | |||
601 | static LDOUBLE POW10(int exp) | ||
602 | { | ||
603 | LDOUBLE result = 1; | ||
604 | |||
605 | while (exp) { | ||
606 | result *= 10; | ||
607 | exp--; | ||
608 | } | ||
609 | |||
610 | return result; | ||
611 | } | ||
612 | |||
613 | static LLONG ROUND(LDOUBLE value) | ||
614 | { | ||
615 | LLONG intpart; | ||
616 | |||
617 | intpart = (LLONG)value; | ||
618 | value = value - intpart; | ||
619 | if (value >= 0.5) intpart++; | ||
620 | |||
621 | return intpart; | ||
622 | } | ||
623 | |||
624 | /* a replacement for modf that doesn't need the math library. Should | ||
625 | be portable, but slow */ | ||
626 | static double my_modf(double x0, double *iptr) | ||
627 | { | ||
628 | int i; | ||
629 | long l; | ||
630 | double x = x0; | ||
631 | double f = 1.0; | ||
632 | |||
633 | for (i=0;i<100;i++) { | ||
634 | l = (long)x; | ||
635 | if (l <= (x+1) && l >= (x-1)) break; | ||
636 | x *= 0.1; | ||
637 | f *= 10.0; | ||
638 | } | ||
639 | |||
640 | if (i == 100) { | ||
641 | /* yikes! the number is beyond what we can handle. What do we do? */ | ||
642 | (*iptr) = 0; | ||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | if (i != 0) { | ||
647 | double i2; | ||
648 | double ret; | ||
649 | |||
650 | ret = my_modf(x0-l*f, &i2); | ||
651 | (*iptr) = l*f + i2; | ||
652 | return ret; | ||
653 | } | ||
654 | |||
655 | (*iptr) = l; | ||
656 | return x - (*iptr); | ||
657 | } | ||
658 | |||
659 | |||
660 | static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | ||
661 | LDOUBLE fvalue, int min, int max, int flags) | ||
662 | { | ||
663 | int signvalue = 0; | ||
664 | double ufvalue; | ||
665 | char iconvert[311]; | ||
666 | char fconvert[311]; | ||
667 | int iplace = 0; | ||
668 | int fplace = 0; | ||
669 | int padlen = 0; /* amount to pad */ | ||
670 | int zpadlen = 0; | ||
671 | int caps = 0; | ||
672 | int idx; | ||
673 | double intpart; | ||
674 | double fracpart; | ||
675 | double temp; | ||
676 | |||
677 | /* | ||
678 | * AIX manpage says the default is 0, but Solaris says the default | ||
679 | * is 6, and sprintf on AIX defaults to 6 | ||
680 | */ | ||
681 | if (max < 0) | ||
682 | max = 6; | ||
683 | |||
684 | ufvalue = abs_val (fvalue); | ||
685 | |||
686 | if (fvalue < 0) { | ||
687 | signvalue = '-'; | ||
688 | } else { | ||
689 | if (flags & DP_F_PLUS) { /* Do a sign (+/i) */ | ||
690 | signvalue = '+'; | ||
691 | } else { | ||
692 | if (flags & DP_F_SPACE) | ||
693 | signvalue = ' '; | ||
694 | } | ||
695 | } | ||
696 | |||
697 | #if 0 | ||
698 | if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ | ||
699 | #endif | ||
700 | |||
701 | #if 0 | ||
702 | if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */ | ||
703 | #endif | ||
704 | |||
705 | /* | ||
706 | * Sorry, we only support 16 digits past the decimal because of our | ||
707 | * conversion method | ||
708 | */ | ||
709 | if (max > 16) | ||
710 | max = 16; | ||
711 | |||
712 | /* We "cheat" by converting the fractional part to integer by | ||
713 | * multiplying by a factor of 10 | ||
714 | */ | ||
715 | |||
716 | temp = ufvalue; | ||
717 | my_modf(temp, &intpart); | ||
718 | |||
719 | fracpart = ROUND((POW10(max)) * (ufvalue - intpart)); | ||
720 | |||
721 | if (fracpart >= POW10(max)) { | ||
722 | intpart++; | ||
723 | fracpart -= POW10(max); | ||
724 | } | ||
725 | |||
726 | |||
727 | /* Convert integer part */ | ||
728 | do { | ||
729 | temp = intpart*0.1; | ||
730 | my_modf(temp, &intpart); | ||
731 | idx = (int) ((temp -intpart +0.05)* 10.0); | ||
732 | /* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ | ||
733 | /* printf ("%llf, %f, %x\n", temp, intpart, idx); */ | ||
734 | iconvert[iplace++] = | ||
735 | (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; | ||
736 | } while (intpart && (iplace < 311)); | ||
737 | if (iplace == 311) iplace--; | ||
738 | iconvert[iplace] = 0; | ||
739 | |||
740 | /* Convert fractional part */ | ||
741 | if (fracpart) | ||
742 | { | ||
743 | do { | ||
744 | temp = fracpart*0.1; | ||
745 | my_modf(temp, &fracpart); | ||
746 | idx = (int) ((temp -fracpart +0.05)* 10.0); | ||
747 | /* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */ | ||
748 | /* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */ | ||
749 | fconvert[fplace++] = | ||
750 | (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; | ||
751 | } while(fracpart && (fplace < 311)); | ||
752 | if (fplace == 311) fplace--; | ||
753 | } | ||
754 | fconvert[fplace] = 0; | ||
755 | |||
756 | /* -1 for decimal point, another -1 if we are printing a sign */ | ||
757 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | ||
758 | zpadlen = max - fplace; | ||
759 | if (zpadlen < 0) zpadlen = 0; | ||
760 | if (padlen < 0) | ||
761 | padlen = 0; | ||
762 | if (flags & DP_F_MINUS) | ||
763 | padlen = -padlen; /* Left Justifty */ | ||
764 | |||
765 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | ||
766 | if (signvalue) { | ||
767 | dopr_outch (buffer, currlen, maxlen, signvalue); | ||
768 | --padlen; | ||
769 | signvalue = 0; | ||
770 | } | ||
771 | while (padlen > 0) { | ||
772 | dopr_outch (buffer, currlen, maxlen, '0'); | ||
773 | --padlen; | ||
774 | } | ||
775 | } | ||
776 | while (padlen > 0) { | ||
777 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
778 | --padlen; | ||
779 | } | ||
780 | if (signvalue) | ||
781 | dopr_outch (buffer, currlen, maxlen, signvalue); | ||
782 | |||
783 | while (iplace > 0) | ||
784 | dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]); | ||
785 | |||
786 | #ifdef DEBUG_SNPRINTF | ||
787 | printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); | ||
788 | #endif | ||
789 | |||
790 | /* | ||
791 | * Decimal point. This should probably use locale to find the correct | ||
792 | * char to print out. | ||
793 | */ | ||
794 | if (max > 0) { | ||
795 | dopr_outch (buffer, currlen, maxlen, '.'); | ||
796 | |||
797 | while (zpadlen > 0) { | ||
798 | dopr_outch (buffer, currlen, maxlen, '0'); | ||
799 | --zpadlen; | ||
800 | } | ||
801 | |||
802 | while (fplace > 0) | ||
803 | dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); | ||
804 | } | ||
805 | |||
806 | while (padlen < 0) { | ||
807 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
808 | ++padlen; | ||
809 | } | ||
810 | } | ||
811 | |||
812 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | ||
813 | { | ||
814 | if (*currlen < maxlen) { | ||
815 | buffer[(*currlen)] = c; | ||
816 | } | ||
817 | (*currlen)++; | ||
818 | } | ||
819 | |||
820 | int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args) | ||
821 | { | ||
822 | return dopr(str, count, fmt, args); | ||
823 | } | ||
824 | #define vsnprintf smb_vsnprintf | ||
825 | #endif | ||
826 | |||
827 | /* yes this really must be a ||. Don't muck with this (tridge) | ||
828 | * | ||
829 | * The logic for these two is that we need our own definition if the | ||
830 | * OS *either* has no definition of *sprintf, or if it does have one | ||
831 | * that doesn't work properly according to the autoconf test. | ||
832 | */ | ||
833 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) | ||
834 | int smb_snprintf(char *str,size_t count,const char *fmt,...) | ||
835 | { | ||
836 | size_t ret; | ||
837 | va_list ap; | ||
838 | |||
839 | va_start(ap, fmt); | ||
840 | ret = vsnprintf(str, count, fmt, ap); | ||
841 | va_end(ap); | ||
842 | return ret; | ||
843 | } | ||
844 | #define snprintf smb_snprintf | ||
845 | #endif | ||
846 | |||
847 | #endif | ||
848 | |||
849 | #ifndef HAVE_VASPRINTF | ||
850 | int vasprintf(char **ptr, const char *format, va_list ap) | ||
851 | { | ||
852 | int ret; | ||
853 | va_list ap2; | ||
854 | |||
855 | VA_COPY(ap2, ap); | ||
856 | |||
857 | ret = vsnprintf(NULL, 0, format, ap2); | ||
858 | if (ret <= 0) return ret; | ||
859 | |||
860 | (*ptr) = (char *)malloc(ret+1); | ||
861 | if (!*ptr) return -1; | ||
862 | |||
863 | VA_COPY(ap2, ap); | ||
864 | |||
865 | ret = vsnprintf(*ptr, ret+1, format, ap2); | ||
866 | |||
867 | return ret; | ||
868 | } | ||
869 | #endif | ||
870 | |||
871 | |||
872 | #ifndef HAVE_ASPRINTF | ||
873 | int asprintf(char **ptr, const char *format, ...) | ||
874 | { | ||
875 | va_list ap; | ||
876 | int ret; | ||
877 | |||
878 | *ptr = NULL; | ||
879 | va_start(ap, format); | ||
880 | ret = vasprintf(ptr, format, ap); | ||
881 | va_end(ap); | ||
882 | |||
883 | return ret; | ||
884 | } | ||
885 | #endif | ||
886 | |||
887 | #ifdef TEST_SNPRINTF | ||
888 | |||
889 | int sprintf(char *str,const char *fmt,...); | ||
890 | |||
891 | int main (void) | ||
892 | { | ||
893 | char buf1[1024]; | ||
894 | char buf2[1024]; | ||
895 | char *fp_fmt[] = { | ||
896 | "%1.1f", | ||
897 | "%-1.5f", | ||
898 | "%1.5f", | ||
899 | "%123.9f", | ||
900 | "%10.5f", | ||
901 | "% 10.5f", | ||
902 | "%+22.9f", | ||
903 | "%+4.9f", | ||
904 | "%01.3f", | ||
905 | "%4f", | ||
906 | "%3.1f", | ||
907 | "%3.2f", | ||
908 | "%.0f", | ||
909 | "%f", | ||
910 | "-16.16f", | ||
911 | NULL | ||
912 | }; | ||
913 | double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, | ||
914 | 0.9996, 1.996, 4.136, 5.030201, 0.00205, | ||
915 | /* END LIST */ 0}; | ||
916 | char *int_fmt[] = { | ||
917 | "%-1.5d", | ||
918 | "%1.5d", | ||
919 | "%123.9d", | ||
920 | "%5.5d", | ||
921 | "%10.5d", | ||
922 | "% 10.5d", | ||
923 | "%+22.33d", | ||
924 | "%01.3d", | ||
925 | "%4d", | ||
926 | "%d", | ||
927 | NULL | ||
928 | }; | ||
929 | long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; | ||
930 | char *str_fmt[] = { | ||
931 | "10.5s", | ||
932 | "5.10s", | ||
933 | "10.1s", | ||
934 | "0.10s", | ||
935 | "10.0s", | ||
936 | "1.10s", | ||
937 | "%s", | ||
938 | "%.1s", | ||
939 | "%.10s", | ||
940 | "%10s", | ||
941 | NULL | ||
942 | }; | ||
943 | char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; | ||
944 | int x, y; | ||
945 | int fail = 0; | ||
946 | int num = 0; | ||
947 | |||
948 | printf ("Testing snprintf format codes against system sprintf...\n"); | ||
949 | |||
950 | for (x = 0; fp_fmt[x] ; x++) { | ||
951 | for (y = 0; fp_nums[y] != 0 ; y++) { | ||
952 | int l1 = snprintf(NULL, 0, fp_fmt[x], fp_nums[y]); | ||
953 | int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); | ||
954 | sprintf (buf2, fp_fmt[x], fp_nums[y]); | ||
955 | if (strcmp (buf1, buf2)) { | ||
956 | printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", | ||
957 | fp_fmt[x], buf1, buf2); | ||
958 | fail++; | ||
959 | } | ||
960 | if (l1 != l2) { | ||
961 | printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, fp_fmt[x]); | ||
962 | fail++; | ||
963 | } | ||
964 | num++; | ||
965 | } | ||
966 | } | ||
967 | |||
968 | for (x = 0; int_fmt[x] ; x++) { | ||
969 | for (y = 0; int_nums[y] != 0 ; y++) { | ||
970 | int l1 = snprintf(NULL, 0, int_fmt[x], int_nums[y]); | ||
971 | int l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]); | ||
972 | sprintf (buf2, int_fmt[x], int_nums[y]); | ||
973 | if (strcmp (buf1, buf2)) { | ||
974 | printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", | ||
975 | int_fmt[x], buf1, buf2); | ||
976 | fail++; | ||
977 | } | ||
978 | if (l1 != l2) { | ||
979 | printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, int_fmt[x]); | ||
980 | fail++; | ||
981 | } | ||
982 | num++; | ||
983 | } | ||
984 | } | ||
985 | |||
986 | for (x = 0; str_fmt[x] ; x++) { | ||
987 | for (y = 0; str_vals[y] != 0 ; y++) { | ||
988 | int l1 = snprintf(NULL, 0, str_fmt[x], str_vals[y]); | ||
989 | int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]); | ||
990 | sprintf (buf2, str_fmt[x], str_vals[y]); | ||
991 | if (strcmp (buf1, buf2)) { | ||
992 | printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", | ||
993 | str_fmt[x], buf1, buf2); | ||
994 | fail++; | ||
995 | } | ||
996 | if (l1 != l2) { | ||
997 | printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, str_fmt[x]); | ||
998 | fail++; | ||
999 | } | ||
1000 | num++; | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | printf ("%d tests failed out of %d.\n", fail, num); | ||
1005 | |||
1006 | printf("seeing how many digits we support\n"); | ||
1007 | { | ||
1008 | double v0 = 0.12345678901234567890123456789012345678901; | ||
1009 | for (x=0; x<100; x++) { | ||
1010 | double p = pow(10, x); | ||
1011 | double r = v0*p; | ||
1012 | snprintf(buf1, sizeof(buf1), "%1.1f", r); | ||
1013 | sprintf(buf2, "%1.1f", r); | ||
1014 | if (strcmp(buf1, buf2)) { | ||
1015 | printf("we seem to support %d digits\n", x-1); | ||
1016 | break; | ||
1017 | } | ||
1018 | } | ||
1019 | } | ||
1020 | |||
1021 | return 0; | ||
1022 | } | ||
1023 | #endif /* TEST_SNPRINTF */ | ||
diff --git a/lib/strtod.c b/lib/strtod.c deleted file mode 100644 index 7b48754..0000000 --- a/lib/strtod.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* Copyright (C) 1991, 1992, 1997, 1999, 2003 Free Software Foundation, Inc. | ||
2 | |||
3 | This program is free software; you can redistribute it and/or modify | ||
4 | it under the terms of the GNU General Public License as published by | ||
5 | the Free Software Foundation; either version 2, or (at your option) | ||
6 | any later version. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, | ||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program; if not, write to the Free Software Foundation, | ||
15 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
16 | |||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | |||
21 | #include <errno.h> | ||
22 | #ifndef errno | ||
23 | extern int errno; | ||
24 | #endif | ||
25 | |||
26 | #include <ctype.h> | ||
27 | |||
28 | #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) | ||
29 | # define IN_CTYPE_DOMAIN(c) 1 | ||
30 | #else | ||
31 | # define IN_CTYPE_DOMAIN(c) isascii(c) | ||
32 | #endif | ||
33 | |||
34 | #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) | ||
35 | #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) | ||
36 | #define TOLOWER(c) (IN_CTYPE_DOMAIN (c) ? tolower(c) : (c)) | ||
37 | |||
38 | #include <math.h> | ||
39 | |||
40 | #include <float.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <string.h> | ||
43 | |||
44 | /* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the | ||
45 | character after the last one used in the number is put in *ENDPTR. */ | ||
46 | double | ||
47 | strtod (const char *nptr, char **endptr) | ||
48 | { | ||
49 | register const char *s; | ||
50 | short int sign; | ||
51 | |||
52 | /* The number so far. */ | ||
53 | double num; | ||
54 | |||
55 | int got_dot; /* Found a decimal point. */ | ||
56 | int got_digit; /* Seen any digits. */ | ||
57 | |||
58 | /* The exponent of the number. */ | ||
59 | long int exponent; | ||
60 | |||
61 | if (nptr == NULL) | ||
62 | { | ||
63 | errno = EINVAL; | ||
64 | goto noconv; | ||
65 | } | ||
66 | |||
67 | s = nptr; | ||
68 | |||
69 | /* Eat whitespace. */ | ||
70 | while (ISSPACE (*s)) | ||
71 | ++s; | ||
72 | |||
73 | /* Get the sign. */ | ||
74 | sign = *s == '-' ? -1 : 1; | ||
75 | if (*s == '-' || *s == '+') | ||
76 | ++s; | ||
77 | |||
78 | num = 0.0; | ||
79 | got_dot = 0; | ||
80 | got_digit = 0; | ||
81 | exponent = 0; | ||
82 | for (;; ++s) | ||
83 | { | ||
84 | if (ISDIGIT (*s)) | ||
85 | { | ||
86 | got_digit = 1; | ||
87 | |||
88 | /* Make sure that multiplication by 10 will not overflow. */ | ||
89 | if (num > DBL_MAX * 0.1) | ||
90 | /* The value of the digit doesn't matter, since we have already | ||
91 | gotten as many digits as can be represented in a `double'. | ||
92 | This doesn't necessarily mean the result will overflow. | ||
93 | The exponent may reduce it to within range. | ||
94 | |||
95 | We just need to record that there was another | ||
96 | digit so that we can multiply by 10 later. */ | ||
97 | ++exponent; | ||
98 | else | ||
99 | num = (num * 10.0) + (*s - '0'); | ||
100 | |||
101 | /* Keep track of the number of digits after the decimal point. | ||
102 | If we just divided by 10 here, we would lose precision. */ | ||
103 | if (got_dot) | ||
104 | --exponent; | ||
105 | } | ||
106 | else if (!got_dot && *s == '.') | ||
107 | /* Record that we have found the decimal point. */ | ||
108 | got_dot = 1; | ||
109 | else | ||
110 | /* Any other character terminates the number. */ | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | if (!got_digit) | ||
115 | goto noconv; | ||
116 | |||
117 | if (TOLOWER (*s) == 'e') | ||
118 | { | ||
119 | /* Get the exponent specified after the `e' or `E'. */ | ||
120 | int save = errno; | ||
121 | char *end; | ||
122 | long int exp; | ||
123 | |||
124 | errno = 0; | ||
125 | ++s; | ||
126 | exp = strtol (s, &end, 10); | ||
127 | if (errno == ERANGE) | ||
128 | { | ||
129 | /* The exponent overflowed a `long int'. It is probably a safe | ||
130 | assumption that an exponent that cannot be represented by | ||
131 | a `long int' exceeds the limits of a `double'. */ | ||
132 | if (endptr != NULL) | ||
133 | *endptr = end; | ||
134 | if (exp < 0) | ||
135 | goto underflow; | ||
136 | else | ||
137 | goto overflow; | ||
138 | } | ||
139 | else if (end == s) | ||
140 | /* There was no exponent. Reset END to point to | ||
141 | the 'e' or 'E', so *ENDPTR will be set there. */ | ||
142 | end = (char *) s - 1; | ||
143 | errno = save; | ||
144 | s = end; | ||
145 | exponent += exp; | ||
146 | } | ||
147 | |||
148 | if (endptr != NULL) | ||
149 | *endptr = (char *) s; | ||
150 | |||
151 | if (num == 0.0) | ||
152 | return 0.0; | ||
153 | |||
154 | /* Multiply NUM by 10 to the EXPONENT power, | ||
155 | checking for overflow and underflow. */ | ||
156 | |||
157 | if (exponent < 0) | ||
158 | { | ||
159 | if (num < DBL_MIN * pow (10.0, (double) -exponent)) | ||
160 | goto underflow; | ||
161 | } | ||
162 | else if (exponent > 0) | ||
163 | { | ||
164 | if (num > DBL_MAX * pow (10.0, (double) -exponent)) | ||
165 | goto overflow; | ||
166 | } | ||
167 | |||
168 | num *= pow (10.0, (double) exponent); | ||
169 | |||
170 | return num * sign; | ||
171 | |||
172 | overflow: | ||
173 | /* Return an overflow error. */ | ||
174 | errno = ERANGE; | ||
175 | return HUGE_VAL * sign; | ||
176 | |||
177 | underflow: | ||
178 | /* Return an underflow error. */ | ||
179 | if (endptr != NULL) | ||
180 | *endptr = (char *) nptr; | ||
181 | errno = ERANGE; | ||
182 | return 0.0; | ||
183 | |||
184 | noconv: | ||
185 | /* There was no number. */ | ||
186 | if (endptr != NULL) | ||
187 | *endptr = (char *) nptr; | ||
188 | return 0.0; | ||
189 | } | ||
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index 63dee76..b03f48a 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
@@ -5,7 +5,7 @@ noinst_PROGRAMS = @EXTRA_TEST@ | |||
5 | TESTS = @EXTRA_TEST@ | 5 | TESTS = @EXTRA_TEST@ |
6 | check_PROGRAMS = @EXTRA_TEST@ | 6 | check_PROGRAMS = @EXTRA_TEST@ |
7 | 7 | ||
8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
9 | 9 | ||
10 | EXTRA_PROGRAMS = test_utils test_disk | 10 | EXTRA_PROGRAMS = test_utils test_disk |
11 | 11 | ||
diff --git a/lib/unlocked-io.h b/lib/unlocked-io.h deleted file mode 100644 index d009303..0000000 --- a/lib/unlocked-io.h +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | /* Prefer faster, non-thread-safe stdio functions if available. | ||
2 | |||
3 | Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Jim Meyering. */ | ||
20 | |||
21 | #ifndef UNLOCKED_IO_H | ||
22 | # define UNLOCKED_IO_H 1 | ||
23 | |||
24 | /* These are wrappers for functions/macros from the GNU C library, and | ||
25 | from other C libraries supporting POSIX's optional thread-safe functions. | ||
26 | |||
27 | The standard I/O functions are thread-safe. These *_unlocked ones are | ||
28 | more efficient but not thread-safe. That they're not thread-safe is | ||
29 | fine since all of the applications in this package are single threaded. | ||
30 | |||
31 | Also, some code that is shared with the GNU C library may invoke | ||
32 | the *_unlocked functions directly. On hosts that lack those | ||
33 | functions, invoke the non-thread-safe versions instead. */ | ||
34 | |||
35 | # include <stdio.h> | ||
36 | |||
37 | # if HAVE_DECL_CLEARERR_UNLOCKED | ||
38 | # undef clearerr | ||
39 | # define clearerr(x) clearerr_unlocked (x) | ||
40 | # else | ||
41 | # define clearerr_unlocked(x) clearerr (x) | ||
42 | # endif | ||
43 | |||
44 | # if HAVE_DECL_FEOF_UNLOCKED | ||
45 | # undef feof | ||
46 | # define feof(x) feof_unlocked (x) | ||
47 | # else | ||
48 | # define feof_unlocked(x) feof (x) | ||
49 | # endif | ||
50 | |||
51 | # if HAVE_DECL_FERROR_UNLOCKED | ||
52 | # undef ferror | ||
53 | # define ferror(x) ferror_unlocked (x) | ||
54 | # else | ||
55 | # define ferror_unlocked(x) ferror (x) | ||
56 | # endif | ||
57 | |||
58 | # if HAVE_DECL_FFLUSH_UNLOCKED | ||
59 | # undef fflush | ||
60 | # define fflush(x) fflush_unlocked (x) | ||
61 | # else | ||
62 | # define fflush_unlocked(x) fflush (x) | ||
63 | # endif | ||
64 | |||
65 | # if HAVE_DECL_FGETS_UNLOCKED | ||
66 | # undef fgets | ||
67 | # define fgets(x,y,z) fgets_unlocked (x,y,z) | ||
68 | # else | ||
69 | # define fgets_unlocked(x,y,z) fgets (x,y,z) | ||
70 | # endif | ||
71 | |||
72 | # if HAVE_DECL_FPUTC_UNLOCKED | ||
73 | # undef fputc | ||
74 | # define fputc(x,y) fputc_unlocked (x,y) | ||
75 | # else | ||
76 | # define fputc_unlocked(x,y) fputc (x,y) | ||
77 | # endif | ||
78 | |||
79 | # if HAVE_DECL_FPUTS_UNLOCKED | ||
80 | # undef fputs | ||
81 | # define fputs(x,y) fputs_unlocked (x,y) | ||
82 | # else | ||
83 | # define fputs_unlocked(x,y) fputs (x,y) | ||
84 | # endif | ||
85 | |||
86 | # if HAVE_DECL_FREAD_UNLOCKED | ||
87 | # undef fread | ||
88 | # define fread(w,x,y,z) fread_unlocked (w,x,y,z) | ||
89 | # else | ||
90 | # define fread_unlocked(w,x,y,z) fread (w,x,y,z) | ||
91 | # endif | ||
92 | |||
93 | # if HAVE_DECL_FWRITE_UNLOCKED | ||
94 | # undef fwrite | ||
95 | # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) | ||
96 | # else | ||
97 | # define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) | ||
98 | # endif | ||
99 | |||
100 | # if HAVE_DECL_GETC_UNLOCKED | ||
101 | # undef getc | ||
102 | # define getc(x) getc_unlocked (x) | ||
103 | # else | ||
104 | # define getc_unlocked(x) getc (x) | ||
105 | # endif | ||
106 | |||
107 | # if HAVE_DECL_GETCHAR_UNLOCKED | ||
108 | # undef getchar | ||
109 | # define getchar() getchar_unlocked () | ||
110 | # else | ||
111 | # define getchar_unlocked() getchar () | ||
112 | # endif | ||
113 | |||
114 | # if HAVE_DECL_PUTC_UNLOCKED | ||
115 | # undef putc | ||
116 | # define putc(x,y) putc_unlocked (x,y) | ||
117 | # else | ||
118 | # define putc_unlocked(x,y) putc (x,y) | ||
119 | # endif | ||
120 | |||
121 | # if HAVE_DECL_PUTCHAR_UNLOCKED | ||
122 | # undef putchar | ||
123 | # define putchar(x) putchar_unlocked (x) | ||
124 | # else | ||
125 | # define putchar_unlocked(x) putchar (x) | ||
126 | # endif | ||
127 | |||
128 | # undef flockfile | ||
129 | # define flockfile(x) ((void) 0) | ||
130 | |||
131 | # undef ftrylockfile | ||
132 | # define ftrylockfile(x) 0 | ||
133 | |||
134 | # undef funlockfile | ||
135 | # define funlockfile(x) ((void) 0) | ||
136 | |||
137 | #endif /* UNLOCKED_IO_H */ | ||
diff --git a/lib/xalloc.h b/lib/xalloc.h deleted file mode 100644 index f80977e..0000000 --- a/lib/xalloc.h +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | /* xalloc.h -- malloc with out-of-memory checking | ||
2 | |||
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | ||
4 | 1999, 2000, 2003, 2004 Free Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifndef XALLOC_H_ | ||
21 | # define XALLOC_H_ | ||
22 | |||
23 | # include <stddef.h> | ||
24 | |||
25 | |||
26 | # ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | # endif | ||
29 | |||
30 | |||
31 | # ifndef __attribute__ | ||
32 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ | ||
33 | # define __attribute__(x) | ||
34 | # endif | ||
35 | # endif | ||
36 | |||
37 | # ifndef ATTRIBUTE_NORETURN | ||
38 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | ||
39 | # endif | ||
40 | |||
41 | /* This function is always triggered when memory is exhausted. | ||
42 | It must be defined by the application, either explicitly | ||
43 | or by using gnulib's xalloc-die module. This is the | ||
44 | function to call when one wants the program to die because of a | ||
45 | memory allocation failure. */ | ||
46 | extern void xalloc_die (void) ATTRIBUTE_NORETURN; | ||
47 | |||
48 | void *xmalloc (size_t s); | ||
49 | void *xnmalloc (size_t n, size_t s); | ||
50 | void *xzalloc (size_t s); | ||
51 | void *xcalloc (size_t n, size_t s); | ||
52 | void *xrealloc (void *p, size_t s); | ||
53 | void *xnrealloc (void *p, size_t n, size_t s); | ||
54 | void *x2realloc (void *p, size_t *pn); | ||
55 | void *x2nrealloc (void *p, size_t *pn, size_t s); | ||
56 | void *xmemdup (void const *p, size_t s); | ||
57 | char *xstrdup (char const *str); | ||
58 | |||
59 | /* Return 1 if an array of N objects, each of size S, cannot exist due | ||
60 | to size arithmetic overflow. S must be positive and N must be | ||
61 | nonnegative. This is a macro, not an inline function, so that it | ||
62 | works correctly even when SIZE_MAX < N. | ||
63 | |||
64 | By gnulib convention, SIZE_MAX represents overflow in size | ||
65 | calculations, so the conservative dividend to use here is | ||
66 | SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. | ||
67 | However, malloc (SIZE_MAX) fails on all known hosts where | ||
68 | sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for | ||
69 | exactly-SIZE_MAX allocations on such hosts; this avoids a test and | ||
70 | branch when S is known to be 1. */ | ||
71 | # define xalloc_oversized(n, s) \ | ||
72 | ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) | ||
73 | |||
74 | # ifdef __cplusplus | ||
75 | } | ||
76 | # endif | ||
77 | |||
78 | |||
79 | #endif /* !XALLOC_H_ */ | ||
diff --git a/lib/xmalloc.c b/lib/xmalloc.c deleted file mode 100644 index 687633c..0000000 --- a/lib/xmalloc.c +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | /* xmalloc.c -- malloc with out of memory checking | ||
2 | |||
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | ||
4 | 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "xalloc.h" | ||
25 | |||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #ifndef SIZE_MAX | ||
30 | # define SIZE_MAX ((size_t) -1) | ||
31 | #endif | ||
32 | |||
33 | /* 1 if calloc is known to be compatible with GNU calloc. This | ||
34 | matters if we are not also using the calloc module, which defines | ||
35 | HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ | ||
36 | #if defined HAVE_CALLOC || defined __GLIBC__ | ||
37 | enum { HAVE_GNU_CALLOC = 1 }; | ||
38 | #else | ||
39 | enum { HAVE_GNU_CALLOC = 0 }; | ||
40 | #endif | ||
41 | |||
42 | /* Allocate an array of N objects, each with S bytes of memory, | ||
43 | dynamically, with error checking. S must be nonzero. */ | ||
44 | |||
45 | static inline void * | ||
46 | xnmalloc_inline (size_t n, size_t s) | ||
47 | { | ||
48 | void *p; | ||
49 | if (xalloc_oversized (n, s) || (! (p = malloc (n * s)) && n != 0)) | ||
50 | xalloc_die (); | ||
51 | return p; | ||
52 | } | ||
53 | |||
54 | void * | ||
55 | xnmalloc (size_t n, size_t s) | ||
56 | { | ||
57 | return xnmalloc_inline (n, s); | ||
58 | } | ||
59 | |||
60 | /* Allocate N bytes of memory dynamically, with error checking. */ | ||
61 | |||
62 | void * | ||
63 | xmalloc (size_t n) | ||
64 | { | ||
65 | return xnmalloc_inline (n, 1); | ||
66 | } | ||
67 | |||
68 | /* Change the size of an allocated block of memory P to an array of N | ||
69 | objects each of S bytes, with error checking. S must be nonzero. */ | ||
70 | |||
71 | static inline void * | ||
72 | xnrealloc_inline (void *p, size_t n, size_t s) | ||
73 | { | ||
74 | if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0)) | ||
75 | xalloc_die (); | ||
76 | return p; | ||
77 | } | ||
78 | |||
79 | void * | ||
80 | xnrealloc (void *p, size_t n, size_t s) | ||
81 | { | ||
82 | return xnrealloc_inline (p, n, s); | ||
83 | } | ||
84 | |||
85 | /* Change the size of an allocated block of memory P to N bytes, | ||
86 | with error checking. */ | ||
87 | |||
88 | void * | ||
89 | xrealloc (void *p, size_t n) | ||
90 | { | ||
91 | return xnrealloc_inline (p, n, 1); | ||
92 | } | ||
93 | |||
94 | |||
95 | /* If P is null, allocate a block of at least *PN such objects; | ||
96 | otherwise, reallocate P so that it contains more than *PN objects | ||
97 | each of S bytes. *PN must be nonzero unless P is null, and S must | ||
98 | be nonzero. Set *PN to the new number of objects, and return the | ||
99 | pointer to the new block. *PN is never set to zero, and the | ||
100 | returned pointer is never null. | ||
101 | |||
102 | Repeated reallocations are guaranteed to make progress, either by | ||
103 | allocating an initial block with a nonzero size, or by allocating a | ||
104 | larger block. | ||
105 | |||
106 | In the following implementation, nonzero sizes are doubled so that | ||
107 | repeated reallocations have O(N log N) overall cost rather than | ||
108 | O(N**2) cost, but the specification for this function does not | ||
109 | guarantee that sizes are doubled. | ||
110 | |||
111 | Here is an example of use: | ||
112 | |||
113 | int *p = NULL; | ||
114 | size_t used = 0; | ||
115 | size_t allocated = 0; | ||
116 | |||
117 | void | ||
118 | append_int (int value) | ||
119 | { | ||
120 | if (used == allocated) | ||
121 | p = x2nrealloc (p, &allocated, sizeof *p); | ||
122 | p[used++] = value; | ||
123 | } | ||
124 | |||
125 | This causes x2nrealloc to allocate a block of some nonzero size the | ||
126 | first time it is called. | ||
127 | |||
128 | To have finer-grained control over the initial size, set *PN to a | ||
129 | nonzero value before calling this function with P == NULL. For | ||
130 | example: | ||
131 | |||
132 | int *p = NULL; | ||
133 | size_t used = 0; | ||
134 | size_t allocated = 0; | ||
135 | size_t allocated1 = 1000; | ||
136 | |||
137 | void | ||
138 | append_int (int value) | ||
139 | { | ||
140 | if (used == allocated) | ||
141 | { | ||
142 | p = x2nrealloc (p, &allocated1, sizeof *p); | ||
143 | allocated = allocated1; | ||
144 | } | ||
145 | p[used++] = value; | ||
146 | } | ||
147 | |||
148 | */ | ||
149 | |||
150 | static inline void * | ||
151 | x2nrealloc_inline (void *p, size_t *pn, size_t s) | ||
152 | { | ||
153 | size_t n = *pn; | ||
154 | |||
155 | if (! p) | ||
156 | { | ||
157 | if (! n) | ||
158 | { | ||
159 | /* The approximate size to use for initial small allocation | ||
160 | requests, when the invoking code specifies an old size of | ||
161 | zero. 64 bytes is the largest "small" request for the | ||
162 | GNU C library malloc. */ | ||
163 | enum { DEFAULT_MXFAST = 64 }; | ||
164 | |||
165 | n = DEFAULT_MXFAST / s; | ||
166 | n += !n; | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | if (SIZE_MAX / 2 / s < n) | ||
172 | xalloc_die (); | ||
173 | n *= 2; | ||
174 | } | ||
175 | |||
176 | *pn = n; | ||
177 | return xrealloc (p, n * s); | ||
178 | } | ||
179 | |||
180 | void * | ||
181 | x2nrealloc (void *p, size_t *pn, size_t s) | ||
182 | { | ||
183 | return x2nrealloc_inline (p, pn, s); | ||
184 | } | ||
185 | |||
186 | /* If P is null, allocate a block of at least *PN bytes; otherwise, | ||
187 | reallocate P so that it contains more than *PN bytes. *PN must be | ||
188 | nonzero unless P is null. Set *PN to the new block's size, and | ||
189 | return the pointer to the new block. *PN is never set to zero, and | ||
190 | the returned pointer is never null. */ | ||
191 | |||
192 | void * | ||
193 | x2realloc (void *p, size_t *pn) | ||
194 | { | ||
195 | return x2nrealloc_inline (p, pn, 1); | ||
196 | } | ||
197 | |||
198 | /* Allocate S bytes of zeroed memory dynamically, with error checking. | ||
199 | There's no need for xnzalloc (N, S), since it would be equivalent | ||
200 | to xcalloc (N, S). */ | ||
201 | |||
202 | void * | ||
203 | xzalloc (size_t s) | ||
204 | { | ||
205 | return memset (xmalloc (s), 0, s); | ||
206 | } | ||
207 | |||
208 | /* Allocate zeroed memory for N elements of S bytes, with error | ||
209 | checking. S must be nonzero. */ | ||
210 | |||
211 | void * | ||
212 | xcalloc (size_t n, size_t s) | ||
213 | { | ||
214 | void *p; | ||
215 | /* Test for overflow, since some calloc implementations don't have | ||
216 | proper overflow checks. But omit overflow and size-zero tests if | ||
217 | HAVE_GNU_CALLOC, since GNU calloc catches overflow and never | ||
218 | returns NULL if successful. */ | ||
219 | if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) | ||
220 | || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) | ||
221 | xalloc_die (); | ||
222 | return p; | ||
223 | } | ||
224 | |||
225 | /* Clone an object P of size S, with error checking. There's no need | ||
226 | for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any | ||
227 | need for an arithmetic overflow check. */ | ||
228 | |||
229 | void * | ||
230 | xmemdup (void const *p, size_t s) | ||
231 | { | ||
232 | return memcpy (xmalloc (s), p, s); | ||
233 | } | ||
234 | |||
235 | /* Clone STRING. */ | ||
236 | |||
237 | char * | ||
238 | xstrdup (char const *string) | ||
239 | { | ||
240 | return xmemdup (string, strlen (string) + 1); | ||
241 | } | ||
diff --git a/m4/Makefile.am.in b/m4/Makefile.am.in deleted file mode 100644 index fb60ada..0000000 --- a/m4/Makefile.am.in +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | ## This is a template from which Makefile.am is generated. -*-Makefile-*- | ||
2 | |||
3 | Makefile.am: Makefile.am.in | ||
4 | rm -f $@ $@t | ||
5 | (echo "## Process this file with automake to produce Makefile.in."; \ | ||
6 | echo EXTRA_DIST =; \ | ||
7 | echo "EXTRA_DIST += Makefile.am.in"; \ | ||
8 | ls -1 *.m4 | sed 's/^/EXTRA_DIST += /'; echo ) \ | ||
9 | >> $@t | ||
10 | sed -n '/^Makefile\.am:/,$$p' $@.in >> $@t | ||
11 | chmod a-w $@t | ||
12 | mv $@t $@ | ||
13 | |||
14 | print_coreutil_files: | ||
15 | @echo $(EXTRA_DIST) | ||
diff --git a/m4/afs.m4 b/m4/afs.m4 deleted file mode 100644 index 6f7a56c..0000000 --- a/m4/afs.m4 +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | #serial 8 | ||
2 | |||
3 | # Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. | ||
4 | # This file is free software; the Free Software Foundation | ||
5 | # gives unlimited permission to copy and/or distribute it, | ||
6 | # with or without modifications, as long as this notice is preserved. | ||
7 | |||
8 | AC_DEFUN([gl_AFS], | ||
9 | [ | ||
10 | AC_ARG_WITH(afs, | ||
11 | AC_HELP_STRING([--with-afs], | ||
12 | [support for the Andrew File System [[default=no]]]), | ||
13 | test "$withval" = no || with_afs=yes, with_afs=no) | ||
14 | if test "$with_afs" = yes; then | ||
15 | AC_DEFINE(AFS, 1, [Define if you have the Andrew File System.]) | ||
16 | fi | ||
17 | ]) | ||
diff --git a/m4/basename.m4 b/m4/basename.m4 deleted file mode 100644 index 69a0996..0000000 --- a/m4/basename.m4 +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | # basename.m4 serial 1 | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_BASENAME], | ||
8 | [ | ||
9 | AC_LIBSOURCES([basename.c, dirname.h]) | ||
10 | AC_LIBOBJ([basename]) | ||
11 | |||
12 | dnl Prerequisites of lib/basename.c. | ||
13 | AC_REQUIRE([gl_AC_DOS]) | ||
14 | ]) | ||
diff --git a/m4/extensions.m4 b/m4/extensions.m4 deleted file mode 100644 index e71845f..0000000 --- a/m4/extensions.m4 +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | # Enable extensions on systems that normally disable them. | ||
2 | |||
3 | # Copyright (C) 2003 Free Software Foundation, Inc. | ||
4 | # This file is free software; the Free Software Foundation | ||
5 | # gives unlimited permission to copy and/or distribute it, | ||
6 | # with or without modifications, as long as this notice is preserved. | ||
7 | |||
8 | # gl_USE_SYSTEM_EXTENSIONS | ||
9 | # ------------------------ | ||
10 | # Enable extensions on systems that normally disable them, | ||
11 | # typically due to standards-conformance issues. | ||
12 | AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [ | ||
13 | AC_BEFORE([$0], [AC_COMPILE_IFELSE]) | ||
14 | AC_BEFORE([$0], [AC_RUN_IFELSE]) | ||
15 | |||
16 | AC_REQUIRE([AC_GNU_SOURCE]) | ||
17 | AC_REQUIRE([AC_AIX]) | ||
18 | AC_REQUIRE([AC_MINIX]) | ||
19 | |||
20 | AH_VERBATIM([__EXTENSIONS__], | ||
21 | [/* Enable extensions on Solaris. */ | ||
22 | #ifndef __EXTENSIONS__ | ||
23 | # undef __EXTENSIONS__ | ||
24 | #endif | ||
25 | #ifndef _POSIX_PTHREAD_SEMANTICS | ||
26 | # undef _POSIX_PTHREAD_SEMANTICS | ||
27 | #endif]) | ||
28 | AC_DEFINE([__EXTENSIONS__]) | ||
29 | AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) | ||
30 | ]) | ||
diff --git a/m4/fstypename.m4 b/m4/fstypename.m4 deleted file mode 100644 index 7ff33e2..0000000 --- a/m4/fstypename.m4 +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | #serial 5 | ||
2 | |||
3 | dnl From Jim Meyering. | ||
4 | dnl | ||
5 | dnl See if struct statfs has the f_fstypename member. | ||
6 | dnl If so, define HAVE_F_FSTYPENAME_IN_STATFS. | ||
7 | dnl | ||
8 | |||
9 | # Copyright (C) 1998, 1999, 2001, 2004 Free Software Foundation, Inc. | ||
10 | # This file is free software; the Free Software Foundation | ||
11 | # gives unlimited permission to copy and/or distribute it, | ||
12 | # with or without modifications, as long as this notice is preserved. | ||
13 | |||
14 | AC_DEFUN([gl_FSTYPENAME], | ||
15 | [ | ||
16 | AC_CACHE_CHECK([for f_fstypename in struct statfs], | ||
17 | fu_cv_sys_f_fstypename_in_statfs, | ||
18 | [ | ||
19 | AC_TRY_COMPILE( | ||
20 | [ | ||
21 | #include <sys/param.h> | ||
22 | #include <sys/types.h> | ||
23 | #include <sys/mount.h> | ||
24 | ], | ||
25 | [struct statfs s; int i = sizeof s.f_fstypename;], | ||
26 | fu_cv_sys_f_fstypename_in_statfs=yes, | ||
27 | fu_cv_sys_f_fstypename_in_statfs=no | ||
28 | ) | ||
29 | ] | ||
30 | ) | ||
31 | |||
32 | if test $fu_cv_sys_f_fstypename_in_statfs = yes; then | ||
33 | AC_DEFINE(HAVE_F_FSTYPENAME_IN_STATFS, 1, | ||
34 | [Define if struct statfs has the f_fstypename member.]) | ||
35 | fi | ||
36 | ] | ||
37 | ) | ||
diff --git a/m4/inttypes.m4 b/m4/inttypes.m4 deleted file mode 100644 index 779bcea..0000000 --- a/m4/inttypes.m4 +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | # inttypes.m4 serial 1 (gettext-0.11.4) | ||
2 | dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | # Define HAVE_INTTYPES_H if <inttypes.h> exists and doesn't clash with | ||
10 | # <sys/types.h>. | ||
11 | |||
12 | AC_DEFUN([gt_HEADER_INTTYPES_H], | ||
13 | [ | ||
14 | AC_CACHE_CHECK([for inttypes.h], gt_cv_header_inttypes_h, | ||
15 | [ | ||
16 | AC_TRY_COMPILE( | ||
17 | [#include <sys/types.h> | ||
18 | #include <inttypes.h>], | ||
19 | [], gt_cv_header_inttypes_h=yes, gt_cv_header_inttypes_h=no) | ||
20 | ]) | ||
21 | if test $gt_cv_header_inttypes_h = yes; then | ||
22 | AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1, | ||
23 | [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.]) | ||
24 | fi | ||
25 | ]) | ||
diff --git a/m4/longlong.m4 b/m4/longlong.m4 deleted file mode 100644 index 7b399e0..0000000 --- a/m4/longlong.m4 +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | # longlong.m4 serial 5 | ||
2 | dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | # Define HAVE_LONG_LONG if 'long long' works. | ||
10 | |||
11 | AC_DEFUN([gl_AC_TYPE_LONG_LONG], | ||
12 | [ | ||
13 | AC_CACHE_CHECK([for long long], ac_cv_type_long_long, | ||
14 | [AC_TRY_LINK([long long ll = 1LL; int i = 63;], | ||
15 | [long long llmax = (long long) -1; | ||
16 | return ll << i | ll >> i | llmax / ll | llmax % ll;], | ||
17 | ac_cv_type_long_long=yes, | ||
18 | ac_cv_type_long_long=no)]) | ||
19 | if test $ac_cv_type_long_long = yes; then | ||
20 | AC_DEFINE(HAVE_LONG_LONG, 1, | ||
21 | [Define if you have the 'long long' type.]) | ||
22 | fi | ||
23 | ]) | ||
diff --git a/m4/np_coreutils.m4 b/m4/np_coreutils.m4 deleted file mode 100644 index 77cb9f6..0000000 --- a/m4/np_coreutils.m4 +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | dnl These are for the libs and macros from coreutils | ||
2 | dnl Currently utilising v5.2.1 | ||
3 | |||
4 | dnl We use jm_ for non Autoconf macros. | ||
5 | m4_pattern_forbid([^np_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
6 | m4_pattern_forbid([^jm_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
7 | m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
8 | |||
9 | dnl These are all m4 things that need to be called | ||
10 | dnl Usually in coreutils' prereq.m4, but this is a subset that we need | ||
11 | AC_DEFUN([np_COREUTILS], | ||
12 | [ | ||
13 | AC_REQUIRE([AM_STDBOOL_H]) | ||
14 | AC_REQUIRE([gl_BASENAME]) | ||
15 | AC_REQUIRE([gl_C_STRTOLD]) | ||
16 | AC_REQUIRE([gl_EXITFAIL]) | ||
17 | AC_REQUIRE([gl_FCNTL_SAFER]) | ||
18 | AC_REQUIRE([gl_FSUSAGE]) | ||
19 | AC_REQUIRE([gl_FUNC_ALLOCA]) | ||
20 | AC_REQUIRE([gl_GETOPT]) | ||
21 | AC_REQUIRE([gl_MOUNTLIST]) | ||
22 | AC_REQUIRE([gl_REGEX]) | ||
23 | AC_REQUIRE([gl_UNISTD_SAFER]) | ||
24 | AC_REQUIRE([gl_XALLOC]) | ||
25 | AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) | ||
26 | |||
27 | dnl This is in jm-macros.m4, which calls prereq.m4, and then calls this afterwards | ||
28 | AC_REQUIRE([gl_AFS]) | ||
29 | ]) | ||
diff --git a/m4/np_curl.m4 b/m4/np_curl.m4 deleted file mode 100644 index 64c3db5..0000000 --- a/m4/np_curl.m4 +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | dnl These are for the libs and macros from curl | ||
2 | dnl Currently utilising v7.12.3 | ||
3 | |||
4 | dnl We use jm_ for non Autoconf macros. | ||
5 | dnl m4_pattern_forbid([^np_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
6 | dnl m4_pattern_forbid([^jm_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
7 | dnl m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl | ||
8 | |||
9 | dnl These are all m4 things that need to be called | ||
10 | dnl Usually in coreutils' prereq.m4, but this is a subset that we need | ||
11 | AC_DEFUN([np_CURL], | ||
12 | [ | ||
13 | AC_REQUIRE([TYPE_SOCKLEN_T]) | ||
14 | ]) | ||
15 | |||
16 | dnl Check for socklen_t: historically on BSD it is an int, and in | ||
17 | dnl POSIX 1g it is a type of its own, but some platforms use different | ||
18 | dnl types for the argument to getsockopt, getpeername, etc. So we | ||
19 | dnl have to test to find something that will work. | ||
20 | AC_DEFUN([TYPE_SOCKLEN_T], | ||
21 | [ | ||
22 | AC_CHECK_TYPE([socklen_t], ,[ | ||
23 | AC_MSG_CHECKING([for socklen_t equivalent]) | ||
24 | AC_CACHE_VAL([curl_cv_socklen_t_equiv], | ||
25 | [ | ||
26 | # Systems have either "struct sockaddr *" or | ||
27 | # "void *" as the second argument to getpeername | ||
28 | curl_cv_socklen_t_equiv= | ||
29 | for arg2 in "struct sockaddr" void; do | ||
30 | for t in int size_t unsigned long "unsigned long"; do | ||
31 | AC_TRY_COMPILE([ | ||
32 | #ifdef HAVE_SYS_TYPES_H | ||
33 | #include <sys/types.h> | ||
34 | #endif | ||
35 | #ifdef HAVE_SYS_SOCKET_H | ||
36 | #include <sys/socket.h> | ||
37 | #endif | ||
38 | |||
39 | int getpeername (int, $arg2 *, $t *); | ||
40 | ],[ | ||
41 | $t len; | ||
42 | getpeername(0,0,&len); | ||
43 | ],[ | ||
44 | curl_cv_socklen_t_equiv="$t" | ||
45 | break | ||
46 | ]) | ||
47 | done | ||
48 | done | ||
49 | |||
50 | if test "x$curl_cv_socklen_t_equiv" = x; then | ||
51 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) | ||
52 | fi | ||
53 | ]) | ||
54 | AC_MSG_RESULT($curl_cv_socklen_t_equiv) | ||
55 | AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, | ||
56 | [type to use in place of socklen_t if not defined])], | ||
57 | [#include <sys/types.h> | ||
58 | #include <sys/socket.h>]) | ||
59 | ]) | ||
60 | |||
diff --git a/m4/restrict.m4 b/m4/restrict.m4 deleted file mode 100644 index 1f3bbb9..0000000 --- a/m4/restrict.m4 +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #serial 1003 | ||
2 | dnl Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | # This macro can be removed once we can rely on Autoconf 2.57a or later, | ||
8 | # since we can then use its AC_C_RESTRICT. | ||
9 | |||
10 | # gl_C_RESTRICT | ||
11 | # -------------- | ||
12 | # Determine whether the C/C++ compiler supports the "restrict" keyword | ||
13 | # introduced in ANSI C99, or an equivalent. Do nothing if the compiler | ||
14 | # accepts it. Otherwise, if the compiler supports an equivalent, | ||
15 | # define "restrict" to be that. Here are some variants: | ||
16 | # - GCC supports both __restrict and __restrict__ | ||
17 | # - older DEC Alpha C compilers support only __restrict | ||
18 | # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C | ||
19 | # Otherwise, define "restrict" to be empty. | ||
20 | AC_DEFUN([gl_C_RESTRICT], | ||
21 | [AC_CACHE_CHECK([for C/C++ restrict keyword], gl_cv_c_restrict, | ||
22 | [gl_cv_c_restrict=no | ||
23 | # Try the official restrict keyword, then gcc's __restrict, and | ||
24 | # the less common variants. | ||
25 | for ac_kw in restrict __restrict __restrict__ _Restrict; do | ||
26 | AC_COMPILE_IFELSE([AC_LANG_SOURCE( | ||
27 | [float * $ac_kw x;])], | ||
28 | [gl_cv_c_restrict=$ac_kw; break]) | ||
29 | done | ||
30 | ]) | ||
31 | case $gl_cv_c_restrict in | ||
32 | restrict) ;; | ||
33 | no) AC_DEFINE(restrict,, | ||
34 | [Define to equivalent of C99 restrict keyword, or to nothing if this | ||
35 | is not supported. Do not define if restrict is supported directly.]) ;; | ||
36 | *) AC_DEFINE_UNQUOTED(restrict, $gl_cv_c_restrict) ;; | ||
37 | esac | ||
38 | ]) | ||
diff --git a/m4/signed.m4 b/m4/signed.m4 deleted file mode 100644 index 048f593..0000000 --- a/m4/signed.m4 +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | # signed.m4 serial 1 (gettext-0.10.40) | ||
2 | dnl Copyright (C) 2001-2002 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Bruno Haible. | ||
8 | |||
9 | AC_DEFUN([bh_C_SIGNED], | ||
10 | [ | ||
11 | AC_CACHE_CHECK([for signed], bh_cv_c_signed, | ||
12 | [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)]) | ||
13 | if test $bh_cv_c_signed = no; then | ||
14 | AC_DEFINE(signed, , | ||
15 | [Define to empty if the C compiler doesn't support this keyword.]) | ||
16 | fi | ||
17 | ]) | ||
diff --git a/m4/ulonglong.m4 b/m4/ulonglong.m4 deleted file mode 100644 index dee10cc..0000000 --- a/m4/ulonglong.m4 +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | # ulonglong.m4 serial 4 | ||
2 | dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | dnl From Paul Eggert. | ||
8 | |||
9 | # Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works. | ||
10 | |||
11 | AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], | ||
12 | [ | ||
13 | AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long, | ||
14 | [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;], | ||
15 | [unsigned long long ullmax = (unsigned long long) -1; | ||
16 | return ull << i | ull >> i | ullmax / ull | ullmax % ull;], | ||
17 | ac_cv_type_unsigned_long_long=yes, | ||
18 | ac_cv_type_unsigned_long_long=no)]) | ||
19 | if test $ac_cv_type_unsigned_long_long = yes; then | ||
20 | AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, | ||
21 | [Define if you have the 'unsigned long long' type.]) | ||
22 | fi | ||
23 | ]) | ||
diff --git a/m4/unlocked-io.m4 b/m4/unlocked-io.m4 deleted file mode 100644 index 6cbacb0..0000000 --- a/m4/unlocked-io.m4 +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | # unlocked-io.m4 serial 12 | ||
2 | |||
3 | # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software | ||
4 | # Foundation, Inc. | ||
5 | # | ||
6 | # This file is free software; the Free Software Foundation | ||
7 | # gives unlimited permission to copy and/or distribute it, | ||
8 | # with or without modifications, as long as this notice is preserved. | ||
9 | |||
10 | dnl From Jim Meyering. | ||
11 | dnl | ||
12 | dnl See if the glibc *_unlocked I/O macros or functions are available. | ||
13 | dnl Use only those *_unlocked macros or functions that are declared | ||
14 | dnl (because some of them were declared in Solaris 2.5.1 but were removed | ||
15 | dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run | ||
16 | dnl on Solaris 2.6). | ||
17 | |||
18 | AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO], | ||
19 | [ | ||
20 | AC_LIBSOURCES([unlocked-io.h]) | ||
21 | |||
22 | AC_DEFINE([USE_UNLOCKED_IO], 1, | ||
23 | [Define to 1 if you want getc etc. to use unlocked I/O if available. | ||
24 | Unlocked I/O can improve performance in unithreaded apps, | ||
25 | but it is not safe for multithreaded apps.]) | ||
26 | |||
27 | dnl Persuade glibc and Solaris <stdio.h> to declare | ||
28 | dnl fgets_unlocked(), fputs_unlocked() etc. | ||
29 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
30 | |||
31 | AC_CHECK_DECLS_ONCE( | ||
32 | [clearerr_unlocked feof_unlocked ferror_unlocked | ||
33 | fflush_unlocked fgets_unlocked fputc_unlocked fputs_unlocked | ||
34 | fread_unlocked fwrite_unlocked getc_unlocked | ||
35 | getchar_unlocked putc_unlocked putchar_unlocked]) | ||
36 | ]) | ||
diff --git a/plugins-root/Makefile.am b/plugins-root/Makefile.am index 8d33b48..d2e4e8b 100644 --- a/plugins-root/Makefile.am +++ b/plugins-root/Makefile.am | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t | 3 | VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t |
4 | 4 | ||
5 | INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl -I$(top_srcdir)/plugins @SSLINCLUDE@ | 5 | INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins @SSLINCLUDE@ |
6 | 6 | ||
7 | datadir = @datadir@ | 7 | datadir = @datadir@ |
8 | localedir = $(datadir)/locale | 8 | localedir = $(datadir)/locale |
@@ -15,7 +15,7 @@ EXTRA_PROGRAMS = pst3 | |||
15 | 15 | ||
16 | EXTRA_DIST = pst3.c | 16 | EXTRA_DIST = pst3.c |
17 | 17 | ||
18 | BASEOBJS = ../plugins/utils.o ../lib/libnagiosplug.a ../lib/libcoreutils.a | 18 | BASEOBJS = ../plugins/utils.o ../lib/libnagiosplug.a ../gl/libgnu.a |
19 | NETOBJS = ../plugins/netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) | 19 | NETOBJS = ../plugins/netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) |
20 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | 20 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) |
21 | 21 | ||
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 69b016a..4d1fbf3 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t | 3 | VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t |
4 | 4 | ||
5 | INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ | 5 | INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ |
6 | 6 | ||
7 | datadir = @datadir@ | 7 | datadir = @datadir@ |
8 | localedir = $(datadir)/locale | 8 | localedir = $(datadir)/locale |
@@ -33,7 +33,7 @@ EXTRA_DIST = t utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ | |||
33 | 33 | ||
34 | PLUGINHDRS = common.h | 34 | PLUGINHDRS = common.h |
35 | 35 | ||
36 | BASEOBJS = utils.o ../lib/libnagiosplug.a ../lib/libcoreutils.a | 36 | BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a |
37 | NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) | 37 | NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) |
38 | SSLOBJS = sslutils.o | 38 | SSLOBJS = sslutils.o |
39 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | 39 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index ee6d0cb..94214ee 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -171,7 +171,6 @@ main (int argc, char **argv) | |||
171 | char *helocmd = NULL; | 171 | char *helocmd = NULL; |
172 | char *error_msg = NULL; | 172 | char *error_msg = NULL; |
173 | struct timeval tv; | 173 | struct timeval tv; |
174 | struct hostent *hp; | ||
175 | 174 | ||
176 | setlocale (LC_ALL, ""); | 175 | setlocale (LC_ALL, ""); |
177 | bindtextdomain (PACKAGE, LOCALEDIR); | 176 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -191,9 +190,6 @@ main (int argc, char **argv) | |||
191 | printf(_("gethostname() failed!\n")); | 190 | printf(_("gethostname() failed!\n")); |
192 | return STATE_CRITICAL; | 191 | return STATE_CRITICAL; |
193 | } | 192 | } |
194 | hp = gethostbyname(localhostname); | ||
195 | if(!hp) helocmd = localhostname; | ||
196 | else helocmd = hp->h_name; | ||
197 | } else { | 193 | } else { |
198 | helocmd = localhostname; | 194 | helocmd = localhostname; |
199 | } | 195 | } |
@@ -202,6 +198,9 @@ main (int argc, char **argv) | |||
202 | else | 198 | else |
203 | asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n"); | 199 | asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n"); |
204 | 200 | ||
201 | if (verbose) | ||
202 | printf("HELOCMD: %s", helocmd); | ||
203 | |||
205 | /* initialize the MAIL command with optional FROM command */ | 204 | /* initialize the MAIL command with optional FROM command */ |
206 | asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n"); | 205 | asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n"); |
207 | 206 | ||
diff --git a/plugins/common.h b/plugins/common.h index b335743..69cd800 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -103,18 +103,11 @@ | |||
103 | #include <signal.h> | 103 | #include <signal.h> |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | /* GNU Libraries */ | ||
106 | #include <getopt.h> | 107 | #include <getopt.h> |
107 | #include <ctype.h> | 108 | #include "vasprintf.h" |
108 | 109 | #include "snprintf.h" | |
109 | #ifdef HAVE_LWRES_NETDB_H | 110 | #include "vsnprintf.h" |
110 | #include <lwres/netdb.h> | ||
111 | #else | ||
112 | # if !HAVE_GETADDRINFO | ||
113 | # include "getaddrinfo.h" | ||
114 | # else | ||
115 | # include <netdb.h> | ||
116 | # endif | ||
117 | #endif | ||
118 | 111 | ||
119 | #ifdef HAVE_LOCALE_H | 112 | #ifdef HAVE_LOCALE_H |
120 | #include <locale.h> | 113 | #include <locale.h> |
@@ -138,22 +131,6 @@ | |||
138 | # define strtoul(a,b,c) (unsigned long)atol((a)) | 131 | # define strtoul(a,b,c) (unsigned long)atol((a)) |
139 | #endif | 132 | #endif |
140 | 133 | ||
141 | #ifndef HAVE_ASPRINTF | ||
142 | int asprintf(char **strp, const char *fmt, ...); | ||
143 | #endif | ||
144 | |||
145 | #ifndef HAVE_VASPRINTF | ||
146 | /* int vasprintf(char **strp, const char *fmt, va_list ap); */ | ||
147 | #endif | ||
148 | |||
149 | #ifndef HAVE_SNPRINTF | ||
150 | int snprintf(char *str, size_t size, const char *format, ...); | ||
151 | #endif | ||
152 | |||
153 | #ifndef HAVE_VSNPRINTF | ||
154 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); | ||
155 | #endif | ||
156 | |||
157 | /* SSL implementations */ | 134 | /* SSL implementations */ |
158 | #ifdef HAVE_GNUTLS_OPENSSL_H | 135 | #ifdef HAVE_GNUTLS_OPENSSL_H |
159 | # include <gnutls/openssl.h> | 136 | # include <gnutls/openssl.h> |
diff --git a/plugins/getaddrinfo.c b/plugins/getaddrinfo.c deleted file mode 100644 index 5697820..0000000 --- a/plugins/getaddrinfo.c +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | /* | ||
2 | * This file is part of libESMTP, a library for submission of RFC 2822 | ||
3 | * formatted electronic mail messages using the SMTP protocol described | ||
4 | * in RFC 2821. | ||
5 | * Modified by Jeremy T. Bouse for use in Nagios plugins | ||
6 | * | ||
7 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | ||
8 | * | ||
9 | * This library is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU Lesser General Public | ||
11 | * License as published by the Free Software Foundation; either | ||
12 | * version 2.1 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This library is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * Lesser General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU Lesser General Public | ||
20 | * License along with this library; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | ||
23 | |||
24 | /* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface. | ||
25 | * | ||
26 | * $Id$ | ||
27 | */ | ||
28 | |||
29 | #ifdef HAVE_CONFIG_H | ||
30 | #include <config.h> | ||
31 | #endif | ||
32 | |||
33 | /* Need to turn off Posix features in glibc to build this */ | ||
34 | #undef _POSIX_C_SOURCE | ||
35 | #undef _XOPEN_SOURCE | ||
36 | |||
37 | #include <stdlib.h> | ||
38 | #include <string.h> | ||
39 | #include <ctype.h> | ||
40 | #include <errno.h> | ||
41 | |||
42 | #include <sys/socket.h> | ||
43 | #include <netinet/in.h> | ||
44 | #include <arpa/inet.h> | ||
45 | |||
46 | #include <netdb.h> | ||
47 | |||
48 | #include "gethostbyname.h" | ||
49 | #include "getaddrinfo.h" | ||
50 | |||
51 | static struct addrinfo * | ||
52 | dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) | ||
53 | { | ||
54 | struct addrinfo *ret; | ||
55 | |||
56 | ret = malloc (sizeof (struct addrinfo)); | ||
57 | if (ret == NULL) | ||
58 | return NULL; | ||
59 | memcpy (ret, info, sizeof (struct addrinfo)); | ||
60 | ret->ai_addr = malloc (addrlen); | ||
61 | if (ret->ai_addr == NULL) | ||
62 | { | ||
63 | free (ret); | ||
64 | return NULL; | ||
65 | } | ||
66 | memcpy (ret->ai_addr, addr, addrlen); | ||
67 | ret->ai_addrlen = addrlen; | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | int | ||
72 | getaddrinfo (const char *nodename, const char *servname, | ||
73 | const struct addrinfo *hints, struct addrinfo **res) | ||
74 | { | ||
75 | struct hostent *hp; | ||
76 | struct servent *servent; | ||
77 | const char *socktype; | ||
78 | int port; | ||
79 | struct addrinfo hint, result; | ||
80 | struct addrinfo *ai, *sai, *eai; | ||
81 | struct ghbnctx ghbnctx; | ||
82 | char **addrs; | ||
83 | int code; | ||
84 | |||
85 | memset (&result, 0, sizeof result); | ||
86 | |||
87 | /* default for hints */ | ||
88 | if (hints == NULL) | ||
89 | { | ||
90 | memset (&hint, 0, sizeof hint); | ||
91 | hint.ai_family = PF_UNSPEC; | ||
92 | hints = &hint; | ||
93 | } | ||
94 | |||
95 | result.ai_socktype = hints->ai_socktype; | ||
96 | |||
97 | /* Note: maintain port in host byte order to make debugging easier */ | ||
98 | if (servname != NULL) { | ||
99 | if (isdigit (*servname)) | ||
100 | port = strtol (servname, NULL, 10); | ||
101 | else if ((servent = getservbyname (servname, socktype)) != NULL) | ||
102 | port = ntohs (servent->s_port); | ||
103 | else | ||
104 | return EAI_NONAME; | ||
105 | } | ||
106 | |||
107 | /* if nodename == NULL refer to the local host for a client or any | ||
108 | for a server */ | ||
109 | if (nodename == NULL) | ||
110 | { | ||
111 | struct sockaddr_in sin; | ||
112 | |||
113 | /* check protocol family is PF_UNSPEC or PF_INET - could try harder | ||
114 | for IPv6 but that's more code than I'm prepared to write */ | ||
115 | if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET) | ||
116 | result.ai_family = AF_INET; | ||
117 | else | ||
118 | return EAI_FAMILY; | ||
119 | |||
120 | sin.sin_family = result.ai_family; | ||
121 | sin.sin_port = htons (port); | ||
122 | if (hints->ai_flags & AI_PASSIVE) | ||
123 | sin.sin_addr.s_addr = htonl (INADDR_ANY); | ||
124 | else | ||
125 | sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | ||
126 | /* Duplicate result and addr and return */ | ||
127 | *res = dup_addrinfo (&result, &sin, sizeof sin); | ||
128 | return (*res == NULL) ? EAI_MEMORY : 0; | ||
129 | } | ||
130 | |||
131 | /* If AI_NUMERIC is specified, use inet_addr to translate numbers and | ||
132 | dots notation. */ | ||
133 | if (hints->ai_flags & AI_NUMERICHOST) | ||
134 | { | ||
135 | struct sockaddr_in sin; | ||
136 | |||
137 | /* check protocol family is PF_UNSPEC or PF_INET */ | ||
138 | if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET) | ||
139 | result.ai_family = AF_INET; | ||
140 | else | ||
141 | return EAI_FAMILY; | ||
142 | |||
143 | sin.sin_family = result.ai_family; | ||
144 | sin.sin_port = htons (port); | ||
145 | sin.sin_addr.s_addr = inet_addr (nodename); | ||
146 | /* Duplicate result and addr and return */ | ||
147 | *res = dup_addrinfo (&result, &sin, sizeof sin); | ||
148 | return (*res == NULL) ? EAI_MEMORY : 0; | ||
149 | } | ||
150 | |||
151 | errno = 0; | ||
152 | hp = gethostbyname_ctx (nodename, &ghbnctx); | ||
153 | if (hp == NULL) | ||
154 | { | ||
155 | if (errno != 0) | ||
156 | { | ||
157 | free_ghbnctx (&ghbnctx); | ||
158 | return EAI_SYSTEM; | ||
159 | } | ||
160 | code = h_error_ctx (&ghbnctx); | ||
161 | switch (code) | ||
162 | { | ||
163 | case HOST_NOT_FOUND: code = EAI_NODATA; break; | ||
164 | case NO_DATA: code = EAI_NODATA; break; | ||
165 | #if defined(NO_ADDRESS) && NO_ADDRESS != NO_DATA | ||
166 | case NO_ADDRESS: code = EAI_NODATA; break; | ||
167 | #endif | ||
168 | case NO_RECOVERY: code = EAI_FAIL; break; | ||
169 | case TRY_AGAIN: code = EAI_AGAIN; break; | ||
170 | default: code = EAI_FAIL; break; | ||
171 | } | ||
172 | free_ghbnctx (&ghbnctx); | ||
173 | return code; | ||
174 | } | ||
175 | |||
176 | /* Check that the address family is acceptable. | ||
177 | */ | ||
178 | switch (hp->h_addrtype) | ||
179 | { | ||
180 | case AF_INET: | ||
181 | if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)) | ||
182 | goto eai_family; | ||
183 | break; | ||
184 | #ifdef USE_IPV6 | ||
185 | case AF_INET6: | ||
186 | if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6)) | ||
187 | goto eai_family; | ||
188 | break; | ||
189 | #endif | ||
190 | default: | ||
191 | eai_family: | ||
192 | free_ghbnctx (&ghbnctx); | ||
193 | return EAI_FAMILY; | ||
194 | } | ||
195 | |||
196 | /* For each element pointed to by hp, create an element in the | ||
197 | result linked list. */ | ||
198 | sai = eai = NULL; | ||
199 | for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) | ||
200 | { | ||
201 | struct sockaddr sa; | ||
202 | size_t addrlen; | ||
203 | |||
204 | sa.sa_family = hp->h_addrtype; | ||
205 | switch (hp->h_addrtype) | ||
206 | { | ||
207 | case AF_INET: | ||
208 | ((struct sockaddr_in *) &sa)->sin_port = htons (port); | ||
209 | memcpy (&((struct sockaddr_in *) &sa)->sin_addr, | ||
210 | *addrs, hp->h_length); | ||
211 | addrlen = sizeof (struct sockaddr_in); | ||
212 | break; | ||
213 | #ifdef USE_IPV6 | ||
214 | case AF_INET6: | ||
215 | # if SIN6_LEN | ||
216 | ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length; | ||
217 | # endif | ||
218 | ((struct sockaddr_in6 *) &sa)->sin6_port = htons (port); | ||
219 | memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr, | ||
220 | *addrs, hp->h_length); | ||
221 | addrlen = sizeof (struct sockaddr_in6); | ||
222 | break; | ||
223 | #endif | ||
224 | default: | ||
225 | continue; | ||
226 | } | ||
227 | |||
228 | result.ai_family = hp->h_addrtype; | ||
229 | ai = dup_addrinfo (&result, &sa, addrlen); | ||
230 | if (ai == NULL) | ||
231 | { | ||
232 | free_ghbnctx (&ghbnctx); | ||
233 | freeaddrinfo (sai); | ||
234 | return EAI_MEMORY; | ||
235 | } | ||
236 | if (sai == NULL) | ||
237 | sai = ai; | ||
238 | else | ||
239 | eai->ai_next = ai; | ||
240 | eai = ai; | ||
241 | } | ||
242 | |||
243 | if (sai == NULL) | ||
244 | { | ||
245 | free_ghbnctx (&ghbnctx); | ||
246 | return EAI_NODATA; | ||
247 | } | ||
248 | |||
249 | if (hints->ai_flags & AI_CANONNAME) | ||
250 | { | ||
251 | sai->ai_canonname = malloc (strlen (hp->h_name) + 1); | ||
252 | if (sai->ai_canonname == NULL) | ||
253 | { | ||
254 | free_ghbnctx (&ghbnctx); | ||
255 | freeaddrinfo (sai); | ||
256 | return EAI_MEMORY; | ||
257 | } | ||
258 | strcpy (sai->ai_canonname, hp->h_name); | ||
259 | } | ||
260 | |||
261 | free_ghbnctx (&ghbnctx); | ||
262 | *res = sai; | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | void | ||
267 | freeaddrinfo (struct addrinfo *ai) | ||
268 | { | ||
269 | struct addrinfo *next; | ||
270 | |||
271 | while (ai != NULL) | ||
272 | { | ||
273 | next = ai->ai_next; | ||
274 | if (ai->ai_canonname != NULL) | ||
275 | free (ai->ai_canonname); | ||
276 | if (ai->ai_addr != NULL) | ||
277 | free (ai->ai_addr); | ||
278 | free (ai); | ||
279 | ai = next; | ||
280 | } | ||
281 | } | ||
282 | |||
283 | const char * | ||
284 | gai_strerror (int ecode) | ||
285 | { | ||
286 | static const char *eai_descr[] = | ||
287 | { | ||
288 | "no error", | ||
289 | "address family for nodename not supported", /* EAI_ADDRFAMILY */ | ||
290 | "temporary failure in name resolution", /* EAI_AGAIN */ | ||
291 | "invalid value for ai_flags", /* EAI_BADFLAGS */ | ||
292 | "non-recoverable failure in name resolution", /* EAI_FAIL */ | ||
293 | "ai_family not supported", /* EAI_FAMILY */ | ||
294 | "memory allocation failure", /* EAI_MEMORY */ | ||
295 | "no address associated with nodename", /* EAI_NODATA */ | ||
296 | "nodename nor servname provided, or not known", /* EAI_NONAME */ | ||
297 | "servname not supported for ai_socktype", /* EAI_SERVICE */ | ||
298 | "ai_socktype not supported", /* EAI_SOCKTYPE */ | ||
299 | "system error returned in errno", /* EAI_SYSTEM */ | ||
300 | }; | ||
301 | |||
302 | if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0])) | ||
303 | return "unknown error"; | ||
304 | return eai_descr[ecode]; | ||
305 | } | ||
diff --git a/plugins/getaddrinfo.h b/plugins/getaddrinfo.h deleted file mode 100644 index d411524..0000000 --- a/plugins/getaddrinfo.h +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | #ifndef _getaddrinfo_h | ||
2 | #define _getaddrinfo_h | ||
3 | /* | ||
4 | * This file is part of libESMTP, a library for submission of RFC 2822 | ||
5 | * formatted electronic mail messages using the SMTP protocol described | ||
6 | * in RFC 2821. | ||
7 | * Modified by Jeremy T. Bouse for use in Nagios plugins | ||
8 | * | ||
9 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | ||
10 | * | ||
11 | * This library is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This library is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with this library; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | */ | ||
25 | |||
26 | /* Structure and prototypes aken from RFC 2553 | ||
27 | * | ||
28 | * $Id$ | ||
29 | */ | ||
30 | |||
31 | struct addrinfo | ||
32 | { | ||
33 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ | ||
34 | int ai_family; /* PF_xxx */ | ||
35 | int ai_socktype; /* SOCK_xxx */ | ||
36 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ | ||
37 | size_t ai_addrlen; /* length of ai_addr */ | ||
38 | char *ai_canonname; /* canonical name for nodename */ | ||
39 | struct sockaddr *ai_addr; /* binary address */ | ||
40 | struct addrinfo *ai_next; /* next structure in linked list */ | ||
41 | }; | ||
42 | |||
43 | /* Supposed to be defined in <netdb.h> */ | ||
44 | #define AI_PASSIVE 1 /* Socket address is intended for `bind'. */ | ||
45 | #define AI_CANONNAME 2 /* Request for canonical name. */ | ||
46 | #define AI_NUMERICHOST 4 /* Don't use name resolution. */ | ||
47 | |||
48 | /* Supposed to be defined in <netdb.h> */ | ||
49 | #define EAI_ADDRFAMILY 1 /* address family for nodename not supported */ | ||
50 | #define EAI_AGAIN 2 /* temporary failure in name resolution */ | ||
51 | #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ | ||
52 | #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ | ||
53 | #define EAI_FAMILY 5 /* ai_family not supported */ | ||
54 | #define EAI_MEMORY 6 /* memory allocation failure */ | ||
55 | #define EAI_NODATA 7 /* no address associated with nodename */ | ||
56 | #define EAI_NONAME 8 /* nodename nor servname provided, or not known */ | ||
57 | #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ | ||
58 | #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ | ||
59 | #define EAI_SYSTEM 11 /* system error returned in errno */ | ||
60 | |||
61 | /* RFC 2553 / Posix resolver */ | ||
62 | int getaddrinfo (const char *nodename, const char *servname, | ||
63 | const struct addrinfo *hints, struct addrinfo **res); | ||
64 | |||
65 | /* Free addrinfo structure and associated storage */ | ||
66 | void freeaddrinfo (struct addrinfo *ai); | ||
67 | |||
68 | /* Convert error return from getaddrinfo() to string */ | ||
69 | const char *gai_strerror (int code); | ||
70 | |||
71 | #endif | ||
diff --git a/plugins/gethostbyname.c b/plugins/gethostbyname.c deleted file mode 100644 index c8f39ed..0000000 --- a/plugins/gethostbyname.c +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Nagios gethostbyname_r()'s prototype. | ||
4 | * | ||
5 | * License: GPL | ||
6 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | ||
7 | * | ||
8 | * Last Modified: $Date$ | ||
9 | * | ||
10 | * Description: | ||
11 | * | ||
12 | * This file is a ghastly hack because nobody can agree on | ||
13 | * gethostbyname_r()'s prototype. | ||
14 | * | ||
15 | * License Information: | ||
16 | * | ||
17 | * This program is free software; you can redistribute it and/or modify | ||
18 | * it under the terms of the GNU General Public License as published by | ||
19 | * the Free Software Foundation; either version 2 of the License, or | ||
20 | * (at your option) any later version. | ||
21 | * | ||
22 | * This program is distributed in the hope that it will be useful, | ||
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
25 | * GNU General Public License for more details. | ||
26 | * | ||
27 | * You should have received a copy of the GNU General Public License | ||
28 | * along with this program; if not, write to the Free Software | ||
29 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
30 | * | ||
31 | * $Id$ | ||
32 | * | ||
33 | *****************************************************************************/ | ||
34 | |||
35 | #ifdef HAVE_CONFIG_H | ||
36 | #include <config.h> | ||
37 | #endif | ||
38 | |||
39 | #define _SVID_SOURCE 1 /* Need this to get gethostbyname_r() */ | ||
40 | |||
41 | #include <assert.h> | ||
42 | |||
43 | #include <stdlib.h> | ||
44 | #include <string.h> | ||
45 | #include <netdb.h> | ||
46 | #include <errno.h> | ||
47 | |||
48 | #include "gethostbyname.h" | ||
49 | |||
50 | #if HAVE_GETIPNODEBYNAME | ||
51 | |||
52 | void | ||
53 | free_ghbnctx (struct ghbnctx *ctx) | ||
54 | { | ||
55 | assert (ctx != NULL); | ||
56 | |||
57 | if (ctx->hostent != NULL) | ||
58 | freehostent (ctx->hostent); | ||
59 | } | ||
60 | |||
61 | struct hostent * | ||
62 | gethostbyname_ctx (const char *host, struct ghbnctx *ctx) | ||
63 | { | ||
64 | assert (ctx != NULL); | ||
65 | |||
66 | memset (ctx, 0, sizeof (struct ghbnctx)); | ||
67 | ctx->hostent = getipnodebyname (host, AF_UNSPEC, AI_ADDRCONFIG, &ctx->h_err); | ||
68 | return ctx->hostent; | ||
69 | } | ||
70 | |||
71 | int | ||
72 | h_error_ctx (struct ghbnctx *ctx) | ||
73 | { | ||
74 | assert (ctx != NULL); | ||
75 | |||
76 | return ctx->h_err; | ||
77 | } | ||
78 | |||
79 | #elif HAVE_GETHOSTBYNAME_R == 6 | ||
80 | |||
81 | void | ||
82 | free_ghbnctx (struct ghbnctx *ctx) | ||
83 | { | ||
84 | assert (ctx != NULL); | ||
85 | |||
86 | if (ctx->hostbuf != NULL) | ||
87 | free (ctx->hostbuf); | ||
88 | } | ||
89 | |||
90 | struct hostent * | ||
91 | gethostbyname_ctx (const char *host, struct ghbnctx *ctx) | ||
92 | { | ||
93 | struct hostent *hp; | ||
94 | char *tmp; | ||
95 | int err; | ||
96 | |||
97 | assert (ctx != NULL); | ||
98 | |||
99 | memset (ctx, 0, sizeof (struct ghbnctx)); | ||
100 | ctx->hostbuf_len = 2048; | ||
101 | if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL) | ||
102 | { | ||
103 | errno = ENOMEM; | ||
104 | return NULL; | ||
105 | } | ||
106 | while ((err = gethostbyname_r (host, | ||
107 | &ctx->hostent, ctx->hostbuf, ctx->hostbuf_len, | ||
108 | &hp, &ctx->h_err)) == ERANGE) | ||
109 | { | ||
110 | ctx->hostbuf_len += 1024; | ||
111 | if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL) | ||
112 | { | ||
113 | errno = ENOMEM; | ||
114 | return NULL; | ||
115 | } | ||
116 | ctx->hostbuf = tmp; | ||
117 | } | ||
118 | if (err != 0) | ||
119 | { | ||
120 | errno = err; | ||
121 | return NULL; | ||
122 | } | ||
123 | return hp; | ||
124 | } | ||
125 | |||
126 | int | ||
127 | h_error_ctx (struct ghbnctx *ctx) | ||
128 | { | ||
129 | assert (ctx != NULL); | ||
130 | |||
131 | return ctx->h_err; | ||
132 | } | ||
133 | |||
134 | #elif HAVE_GETHOSTBYNAME_R == 5 | ||
135 | |||
136 | void | ||
137 | free_ghbnctx (struct ghbnctx *ctx) | ||
138 | { | ||
139 | assert (ctx != NULL); | ||
140 | |||
141 | if (ctx->hostbuf != NULL) | ||
142 | free (ctx->hostbuf); | ||
143 | } | ||
144 | |||
145 | struct hostent * | ||
146 | gethostbyname_ctx (const char *host, struct ghbnctx *ctx) | ||
147 | { | ||
148 | struct hostent *hp; | ||
149 | char *tmp; | ||
150 | |||
151 | assert (ctx != NULL); | ||
152 | |||
153 | memset (ctx, 0, sizeof (struct ghbnctx)); | ||
154 | ctx->hostbuf_len = 2048; | ||
155 | if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL) | ||
156 | { | ||
157 | errno = ENOMEM; | ||
158 | return NULL; | ||
159 | } | ||
160 | while ((hp = gethostbyname_r (host, &ctx->hostent, | ||
161 | ctx->hostbuf, ctx->hostbuf_len, | ||
162 | &ctx->h_err)) == NULL && errno == ERANGE) | ||
163 | { | ||
164 | ctx->hostbuf_len += 1024; | ||
165 | if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL) | ||
166 | { | ||
167 | errno = ENOMEM; | ||
168 | return NULL; | ||
169 | } | ||
170 | ctx->hostbuf = tmp; | ||
171 | } | ||
172 | return hp; | ||
173 | } | ||
174 | |||
175 | int | ||
176 | h_error_ctx (struct ghbnctx *ctx) | ||
177 | { | ||
178 | assert (ctx != NULL); | ||
179 | |||
180 | return ctx->h_err; | ||
181 | } | ||
182 | |||
183 | #elif HAVE_GETHOSTBYNAME_R == 3 | ||
184 | |||
185 | void | ||
186 | free_ghbnctx (struct ghbnctx *ctx) | ||
187 | { | ||
188 | assert (ctx != NULL); | ||
189 | |||
190 | /* FIXME: does this need to do anything? */ | ||
191 | } | ||
192 | |||
193 | struct hostent * | ||
194 | gethostbyname_ctx (const char *host, struct ghbnctx *ctx) | ||
195 | { | ||
196 | assert (ctx != NULL); | ||
197 | |||
198 | if (!gethostbyname_r (host, &ctx->hostent, &ctx->hostent_data)) | ||
199 | { | ||
200 | ctx->h_err = h_errno; /* FIXME: is this correct? */ | ||
201 | return NULL; | ||
202 | } | ||
203 | return &ctx->hostent; | ||
204 | } | ||
205 | |||
206 | int | ||
207 | h_error_ctx (struct ghbnctx *ctx) | ||
208 | { | ||
209 | assert (ctx != NULL); | ||
210 | |||
211 | return ctx->h_err; | ||
212 | } | ||
213 | |||
214 | #else | ||
215 | |||
216 | void | ||
217 | free_ghbnctx (struct ghbnctx *ctx __attribute__ ((unused))) | ||
218 | { | ||
219 | assert (ctx != NULL); | ||
220 | } | ||
221 | |||
222 | struct hostent * | ||
223 | gethostbyname_ctx (const char *host, struct ghbnctx *ctx) | ||
224 | { | ||
225 | struct hostent *hp; | ||
226 | |||
227 | hp = gethostbyname (host); | ||
228 | if (hp == NULL) | ||
229 | ctx->h_err = h_errno; | ||
230 | return hp; | ||
231 | } | ||
232 | |||
233 | int | ||
234 | h_error_ctx (struct ghbnctx *ctx) | ||
235 | { | ||
236 | assert (ctx != NULL); | ||
237 | |||
238 | return ctx->h_err; | ||
239 | } | ||
240 | |||
241 | #endif | ||
diff --git a/plugins/gethostbyname.h b/plugins/gethostbyname.h deleted file mode 100644 index d95ab26..0000000 --- a/plugins/gethostbyname.h +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Nagios gethostbyname_r()'s prototype. | ||
4 | * | ||
5 | * License: GPL | ||
6 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | ||
7 | * | ||
8 | * Last Modified: $Date$ | ||
9 | * | ||
10 | * Description: | ||
11 | * | ||
12 | * This file is a ghastly hack because nobody can agree on | ||
13 | * gethostbyname_r()'s prototype. | ||
14 | * | ||
15 | * License Information: | ||
16 | * | ||
17 | * This program is free software; you can redistribute it and/or modify | ||
18 | * it under the terms of the GNU General Public License as published by | ||
19 | * the Free Software Foundation; either version 2 of the License, or | ||
20 | * (at your option) any later version. | ||
21 | * | ||
22 | * This program is distributed in the hope that it will be useful, | ||
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
25 | * GNU General Public License for more details. | ||
26 | * | ||
27 | * You should have received a copy of the GNU General Public License | ||
28 | * along with this program; if not, write to the Free Software | ||
29 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
30 | * | ||
31 | * $Id$ | ||
32 | *****************************************************************************/ | ||
33 | |||
34 | /************************************************************************* | ||
35 | Usage: | ||
36 | |||
37 | #include <errno.h> | ||
38 | #include "gethostbyname.h" | ||
39 | |||
40 | f () | ||
41 | { | ||
42 | struct ghbnctx ctx; | ||
43 | |||
44 | errno = 0; | ||
45 | hp = gethostbyname_ctx (host, &ctx); | ||
46 | if (hp == NULL) | ||
47 | { | ||
48 | if (errno != 0) | ||
49 | handle_value_of_errno (errno); | ||
50 | else | ||
51 | handle_value_of_h_errno (h_error_ctx (&ctx)); | ||
52 | } | ||
53 | else | ||
54 | { | ||
55 | ... | ||
56 | } | ||
57 | free_ghbnctx (&ctx); | ||
58 | } | ||
59 | *************************************************************************/ | ||
60 | |||
61 | #ifndef _gethostbyname_h | ||
62 | #define _gethostbyname_h | ||
63 | |||
64 | #if HAVE_GETIPNODEBYNAME | ||
65 | |||
66 | struct ghbnctx | ||
67 | { | ||
68 | int h_err; | ||
69 | struct hostent *hostent; | ||
70 | }; | ||
71 | |||
72 | #elif HAVE_GETHOSTBYNAME_R == 6 | ||
73 | |||
74 | struct ghbnctx | ||
75 | { | ||
76 | int h_err; | ||
77 | struct hostent hostent; | ||
78 | char *hostbuf; | ||
79 | size_t hostbuf_len; | ||
80 | }; | ||
81 | |||
82 | #elif HAVE_GETHOSTBYNAME_R == 5 | ||
83 | |||
84 | struct ghbnctx | ||
85 | { | ||
86 | int h_err; | ||
87 | struct hostent hostent; | ||
88 | char *hostbuf; | ||
89 | int hostbuf_len; | ||
90 | }; | ||
91 | |||
92 | #elif HAVE_GETHOSTBYNAME_R == 3 | ||
93 | |||
94 | struct ghbnctx | ||
95 | { | ||
96 | int h_err; | ||
97 | struct hostent_data hostent_data; | ||
98 | struct hostent hostent; | ||
99 | }; | ||
100 | |||
101 | #else | ||
102 | |||
103 | struct ghbnctx | ||
104 | { | ||
105 | int h_err; | ||
106 | }; | ||
107 | |||
108 | #endif | ||
109 | |||
110 | struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx); | ||
111 | int h_error_ctx (struct ghbnctx *ctx); | ||
112 | void free_ghbnctx (struct ghbnctx *ctx); | ||
113 | |||
114 | #endif | ||
115 | |||
diff --git a/plugins/netutils.h b/plugins/netutils.h index 3fc4ef8..b90c5e6 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -39,6 +39,7 @@ | |||
39 | #include "utils.h" | 39 | #include "utils.h" |
40 | #include <netinet/in.h> | 40 | #include <netinet/in.h> |
41 | #include <arpa/inet.h> | 41 | #include <arpa/inet.h> |
42 | #include "getaddrinfo.h" | ||
42 | 43 | ||
43 | #ifdef HAVE_SYS_UN_H | 44 | #ifdef HAVE_SYS_UN_H |
44 | # include <sys/un.h> | 45 | # include <sys/un.h> |
diff --git a/tools/setup b/tools/setup index 94bd077..7fdb980 100755 --- a/tools/setup +++ b/tools/setup | |||
@@ -18,17 +18,13 @@ else | |||
18 | echo Found GNU Make at $MAKE ... good. | 18 | echo Found GNU Make at $MAKE ... good. |
19 | fi | 19 | fi |
20 | 20 | ||
21 | ( cd m4 && $MAKE -f Makefile.am.in Makefile.am ) | ||
22 | |||
23 | # This bit is to fix SF's compile server as libtool not installed by default | 21 | # This bit is to fix SF's compile server as libtool not installed by default |
24 | extra="" | 22 | extra="" |
25 | if test -d $HOME/share/aclocal ; then | 23 | if test -d $HOME/share/aclocal ; then |
26 | extra="-I $HOME/share/aclocal" | 24 | extra="-I $HOME/share/aclocal" |
27 | fi | 25 | fi |
28 | 26 | ||
29 | # I think gettext no longer necessary, as all necessary files imported from coreutils | 27 | aclocal -I gl/m4 -I m4 $extra |
30 | #autopoint --force | ||
31 | aclocal -I m4 $extra | ||
32 | #libtoolize --force --copy | 28 | #libtoolize --force --copy |
33 | autoheader | 29 | autoheader |
34 | automake --add-missing --force-missing --copy | 30 | automake --add-missing --force-missing --copy |
diff --git a/tools/update_coreutils b/tools/update_coreutils deleted file mode 100755 index 5e195a0..0000000 --- a/tools/update_coreutils +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | # Quick script to copy coreutil files into Nagios area | ||
3 | # Pass $1 as top level of coreutils source dir | ||
4 | # Expects to be run in the lib directory | ||
5 | |||
6 | function die { echo $1; exit 1; } | ||
7 | |||
8 | function copy_if_newer { [[ $1 -nt $2 ]] && cp $1 $2; } | ||
9 | |||
10 | coreutils_dir=$1 | ||
11 | |||
12 | [[ -z $coreutils_dir ]] && die "Please specify coreutils directory" | ||
13 | |||
14 | cwd=`pwd` | ||
15 | |||
16 | [[ ${cwd##*/} != "lib" ]] && die "Must be run in lib directory" | ||
17 | |||
18 | # Get list of files from EXTRA_DIST in Makefile.am | ||
19 | # Need \\\ because the perl needs \\ but one is escaped | ||
20 | files="`perl -ne '$a=1 if s/^EXTRA_DIST\s*=\s*|libnagiosplug_a_SOURCES\s*=\s*//; $a=0 if /^\s*$/; if ($a==1) {s/\\\//; print $_}' Makefile.am`" | ||
21 | |||
22 | for i in $files ; do | ||
23 | if [[ -e $coreutils_dir/lib/$i ]] ; then | ||
24 | copy_if_newer $coreutils_dir/lib/$i ./$i | ||
25 | elif [[ -e $coreutils_dir/m4/$i ]] ; then | ||
26 | copy_if_newer $coreutils_dir/m4/$i ./$i | ||
27 | else | ||
28 | echo "Not found: $i" | ||
29 | fi | ||
30 | done | ||
31 | |||