From fe856aa957978504137c1d425815d4ed8a22be40 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Wed, 24 Jan 2007 22:47:25 +0000 Subject: [PATCH] Sync with gnulib - lots of extraneous code removed in preference to GNU code git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1580 f882894a-f735-0410-b71e-b25c423dba1c --- Makefile.am | 4 +- NEWS | 2 - config.rpath | 513 ---------------- configure.in | 195 +----- doc/developer-guidelines.sgml | 2 +- gl/Makefile.am | 607 +++++++++++++++++++ {lib => gl}/alloca.c | 4 +- {lib => gl}/alloca_.h | 26 +- gl/asnprintf.c | 35 ++ gl/asprintf.c | 35 ++ gl/basename.c | 129 ++++ {lib => gl}/c-strtod.c | 6 +- {lib => gl}/c-strtod.h | 0 {lib => gl}/cloexec.c | 7 +- {lib => gl}/cloexec.h | 0 {lib => gl}/creat-safer.c | 7 +- gl/dirname.c | 85 +++ {lib => gl}/dirname.h | 29 +- {lib => gl}/dup-safer.c | 9 +- {lib => gl}/error.c | 134 +++-- {lib => gl}/error.h | 4 +- {lib => gl}/exit.h | 2 +- {lib => gl}/exitfail.c | 6 +- {lib => gl}/exitfail.h | 0 {lib => gl}/fcntl--.h | 0 {lib => gl}/fcntl-safer.h | 0 {lib => gl}/fd-safer.c | 6 +- {lib => gl}/fsusage.c | 147 ++--- {lib => gl}/fsusage.h | 3 +- {lib => gl}/full-read.c | 0 {lib => gl}/full-read.h | 0 {lib => gl}/full-write.c | 8 +- {lib => gl}/full-write.h | 0 gl/gai_strerror.c | 77 +++ gl/getaddrinfo.c | 417 +++++++++++++ gl/getaddrinfo.h | 155 +++++ gl/gethostname.c | 52 ++ {lib => gl}/getloadavg.c | 31 +- {lib => gl}/getopt.c | 86 +-- {lib => gl}/getopt1.c | 7 +- {lib => gl}/getopt_.h | 9 +- {lib => gl}/getopt_int.h | 0 gl/gettext.h | 270 +++++++++ gl/inet_ntop.c | 238 ++++++++ gl/inet_ntop.h | 42 ++ {lib => gl}/intprops.h | 17 +- gl/m4/absolute-header.m4 | 44 ++ {m4 => gl/m4}/alloca.m4 | 28 +- gl/m4/arpa_inet_h.m4 | 18 + {m4 => gl/m4}/c-strtod.m4 | 10 +- gl/m4/cloexec.m4 | 10 + {m4 => gl/m4}/codeset.m4 | 6 +- gl/m4/dirname.m4 | 18 + {m4 => gl/m4}/dos.m4 | 41 +- gl/m4/double-slash-root.m4 | 38 ++ gl/m4/eoverflow.m4 | 70 +++ {m4 => gl/m4}/error.m4 | 0 {m4 => gl/m4}/exitfail.m4 | 5 +- gl/m4/extensions.m4 | 58 ++ {m4 => gl/m4}/fcntl-safer.m4 | 5 +- gl/m4/fstypename.m4 | 22 + {m4 => gl/m4}/fsusage.m4 | 33 +- gl/m4/getaddrinfo.m4 | 88 +++ gl/m4/gethostname.m4 | 18 + gl/m4/getloadavg.m4 | 155 +++++ {m4 => gl/m4}/getopt.m4 | 11 +- {m4 => gl/m4}/gettext.m4 | 280 +++------ gl/m4/glibc2.m4 | 30 + {m4 => gl/m4}/glibc21.m4 | 0 gl/m4/gnulib-cache.m4 | 30 + gl/m4/gnulib-common.m4 | 22 + gl/m4/gnulib-comp.m4 | 326 ++++++++++ gl/m4/gnulib-tool.m4 | 33 ++ {m4 => gl/m4}/iconv.m4 | 0 gl/m4/inet_ntop.m4 | 19 + gl/m4/inline.m4 | 40 ++ gl/m4/intdiv0.m4 | 70 +++ gl/m4/intl.m4 | 259 ++++++++ gl/m4/intldir.m4 | 19 + gl/m4/intmax.m4 | 33 ++ gl/m4/intmax_t.m4 | 61 ++ {m4 => gl/m4}/inttypes-pri.m4 | 14 +- {m4 => gl/m4}/inttypes_h.m4 | 6 +- gl/m4/lcmessage.m4 | 30 + {m4 => gl/m4}/lib-ld.m4 | 0 {m4 => gl/m4}/lib-link.m4 | 247 ++++++-- {m4 => gl/m4}/lib-prefix.m4 | 0 gl/m4/lock.m4 | 311 ++++++++++ {m4 => gl/m4}/longdouble.m4 | 7 +- gl/m4/longlong.m4 | 72 +++ {m4 => gl/m4}/ls-mntd-fs.m4 | 45 +- gl/m4/mbchar.m4 | 14 + gl/m4/mbiter.m4 | 17 + gl/m4/mbrtowc.m4 | 31 + gl/m4/memchr.m4 | 18 + gl/m4/minmax.m4 | 41 ++ {m4 => gl/m4}/mountlist.m4 | 6 +- gl/m4/netinet_in_h.m4 | 18 + {m4 => gl/m4}/nls.m4 | 24 +- {m4 => gl/m4}/onceonly_2_57.m4 | 12 +- {m4 => gl/m4}/po.m4 | 83 ++- gl/m4/printf-posix.m4 | 44 ++ {m4 => gl/m4}/progtest.m4 | 0 {m4 => gl/m4}/regex.m4 | 121 ++-- gl/m4/safe-read.m4 | 18 + gl/m4/safe-write.m4 | 18 + gl/m4/size_max.m4 | 68 +++ gl/m4/snprintf.m4 | 15 + gl/m4/socklen.m4 | 52 ++ gl/m4/sockpfaf.m4 | 58 ++ gl/m4/ssize_t.m4 | 21 + {m4 => gl/m4}/stdbool.m4 | 19 +- gl/m4/stdint.m4 | 369 ++++++++++++ {m4 => gl/m4}/stdint_h.m4 | 6 +- gl/m4/strcase.m4 | 39 ++ gl/m4/strdup.m4 | 15 + gl/m4/strndup.m4 | 48 ++ gl/m4/strnlen.m4 | 27 + gl/m4/sys_socket_h.m4 | 23 + {m4 => gl/m4}/uintmax_t.m4 | 0 gl/m4/ulonglong.m4 | 48 ++ {m4 => gl/m4}/unistd-safer.m4 | 6 +- gl/m4/unistd_h.m4 | 32 + gl/m4/vasnprintf.m4 | 57 ++ gl/m4/vasprintf.m4 | 33 ++ gl/m4/visibility.m4 | 52 ++ gl/m4/vsnprintf.m4 | 15 + gl/m4/wchar.m4 | 29 + {m4 => gl/m4}/wchar_t.m4 | 0 gl/m4/wctype.m4 | 41 ++ gl/m4/wcwidth.m4 | 30 + {m4 => gl/m4}/wint_t.m4 | 14 +- {m4 => gl/m4}/xalloc.m4 | 7 +- gl/m4/xsize.m4 | 13 + gl/m4/xstrndup.m4 | 15 + {lib => gl}/malloc.c | 7 +- lib/xstrdup.c => gl/mbchar.c | 29 +- gl/mbchar.h | 353 +++++++++++ gl/mbuiter.h | 203 +++++++ gl/memchr.c | 201 +++++++ gl/minmax.h | 60 ++ {lib => gl}/mountlist.c | 119 +++- {lib => gl}/mountlist.h | 0 {lib => gl}/open-safer.c | 7 +- {lib => gl}/pipe-safer.c | 49 +- gl/printf-args.c | 141 +++++ gl/printf-args.h | 136 +++++ gl/printf-parse.c | 543 +++++++++++++++++ gl/printf-parse.h | 74 +++ {lib => gl}/regcomp.c | 643 +++++++++++--------- {lib => gl}/regex.c | 9 +- {lib => gl}/regex.h | 532 +++++++---------- {lib => gl}/regex_internal.c | 412 ++++++++----- {lib => gl}/regex_internal.h | 215 +++---- {lib => gl}/regexec.c | 671 +++++++++++---------- {lib => gl}/safe-read.c | 8 +- {lib => gl}/safe-read.h | 12 +- {lib => gl}/safe-write.c | 0 {lib => gl}/safe-write.h | 0 gl/size_max.h | 31 + gl/snprintf.c | 76 +++ gl/snprintf.h | 29 + gl/socket_.h | 70 +++ {lib => gl}/stdbool_.h | 70 ++- gl/stdint_.h | 489 +++++++++++++++ {lib => gl}/strcase.h | 12 +- gl/strcasecmp.c | 103 ++++ gl/strdup.c | 55 ++ gl/strdup.h | 39 ++ gl/stripslash.c | 45 ++ gl/strncasecmp.c | 63 ++ gl/strndup.c | 39 ++ gl/strndup.h | 32 + gl/strnlen.c | 31 + gl/strnlen.h | 32 + gl/strnlen1.c | 36 ++ gl/strnlen1.h | 40 ++ {lib => gl}/unistd--.h | 0 {lib => gl}/unistd-safer.h | 0 gl/unistd_.h | 52 ++ gl/vasnprintf.c | 889 +++++++++++++++++++++++++++ gl/vasnprintf.h | 77 +++ gl/vasprintf.c | 52 ++ gl/vasprintf.h | 63 ++ gl/vsnprintf.c | 77 +++ gl/vsnprintf.h | 31 + gl/wchar_.h | 42 ++ gl/wctype_.h | 154 +++++ gl/wcwidth.h | 57 ++ {lib => gl}/xalloc-die.c | 7 +- gl/xalloc.h | 267 +++++++++ gl/xmalloc.c | 123 ++++ gl/xsize.h | 108 ++++ gl/xstrndup.c | 37 ++ gl/xstrndup.h | 24 + lib/Makefile.am | 79 +-- lib/basename.c | 79 --- lib/c-strtold.c | 2 - lib/gettext.h | 78 --- lib/realloc.c | 46 -- lib/snprintf.c | 1023 -------------------------------- lib/strtod.c | 189 ------ lib/tests/Makefile.am | 2 +- lib/unlocked-io.h | 137 ----- lib/xalloc.h | 79 --- lib/xmalloc.c | 241 -------- m4/Makefile.am.in | 15 - m4/afs.m4 | 17 - m4/basename.m4 | 14 - m4/extensions.m4 | 30 - m4/fstypename.m4 | 37 -- m4/inttypes.m4 | 25 - m4/longlong.m4 | 23 - m4/np_coreutils.m4 | 29 - m4/np_curl.m4 | 60 -- m4/restrict.m4 | 38 -- m4/signed.m4 | 17 - m4/ulonglong.m4 | 23 - m4/unlocked-io.m4 | 36 -- plugins-root/Makefile.am | 4 +- plugins/Makefile.am | 4 +- plugins/check_smtp.c | 7 +- plugins/common.h | 31 +- plugins/getaddrinfo.c | 305 ---------- plugins/getaddrinfo.h | 71 --- plugins/gethostbyname.c | 241 -------- plugins/gethostbyname.h | 115 ---- plugins/netutils.h | 1 + tools/setup | 6 +- tools/update_coreutils | 31 - 230 files changed, 12681 insertions(+), 5885 deletions(-) delete mode 100644 NEWS delete mode 100755 config.rpath create mode 100644 gl/Makefile.am rename {lib => gl}/alloca.c (99%) rename {lib => gl}/alloca_.h (83%) create mode 100644 gl/asnprintf.c create mode 100644 gl/asprintf.c create mode 100644 gl/basename.c rename {lib => gl}/c-strtod.c (94%) rename {lib => gl}/c-strtod.h (100%) rename {lib => gl}/cloexec.c (92%) rename {lib => gl}/cloexec.h (100%) rename {lib => gl}/creat-safer.c (90%) create mode 100644 gl/dirname.c rename {lib => gl}/dirname.h (57%) rename {lib => gl}/dup-safer.c (89%) rename {lib => gl}/error.c (77%) rename {lib => gl}/error.h (93%) rename {lib => gl}/exit.h (92%) rename {lib => gl}/exitfail.c (88%) rename {lib => gl}/exitfail.h (100%) rename {lib => gl}/fcntl--.h (100%) rename {lib => gl}/fcntl-safer.h (100%) rename {lib => gl}/fd-safer.c (94%) rename {lib => gl}/fsusage.c (81%) rename {lib => gl}/fsusage.h (93%) rename {lib => gl}/full-read.c (100%) rename {lib => gl}/full-read.h (100%) rename {lib => gl}/full-write.c (95%) rename {lib => gl}/full-write.h (100%) create mode 100644 gl/gai_strerror.c create mode 100644 gl/getaddrinfo.c create mode 100644 gl/getaddrinfo.h create mode 100644 gl/gethostname.c rename {lib => gl}/getloadavg.c (97%) rename {lib => gl}/getopt.c (94%) rename {lib => gl}/getopt1.c (97%) rename {lib => gl}/getopt_.h (96%) rename {lib => gl}/getopt_int.h (100%) create mode 100644 gl/gettext.h create mode 100644 gl/inet_ntop.c create mode 100644 gl/inet_ntop.h rename {lib => gl}/intprops.h (78%) create mode 100644 gl/m4/absolute-header.m4 rename {m4 => gl/m4}/alloca.m4 (55%) create mode 100644 gl/m4/arpa_inet_h.m4 rename {m4 => gl/m4}/c-strtod.m4 (86%) create mode 100644 gl/m4/cloexec.m4 rename {m4 => gl/m4}/codeset.m4 (79%) create mode 100644 gl/m4/dirname.m4 rename {m4 => gl/m4}/dos.m4 (57%) create mode 100644 gl/m4/double-slash-root.m4 create mode 100644 gl/m4/eoverflow.m4 rename {m4 => gl/m4}/error.m4 (100%) rename {m4 => gl/m4}/exitfail.m4 (69%) create mode 100644 gl/m4/extensions.m4 rename {m4 => gl/m4}/fcntl-safer.m4 (67%) create mode 100644 gl/m4/fstypename.m4 rename {m4 => gl/m4}/fsusage.m4 (92%) create mode 100644 gl/m4/getaddrinfo.m4 create mode 100644 gl/m4/gethostname.m4 create mode 100644 gl/m4/getloadavg.m4 rename {m4 => gl/m4}/getopt.m4 (90%) rename {m4 => gl/m4}/gettext.m4 (61%) create mode 100644 gl/m4/glibc2.m4 rename {m4 => gl/m4}/glibc21.m4 (100%) create mode 100644 gl/m4/gnulib-cache.m4 create mode 100644 gl/m4/gnulib-common.m4 create mode 100644 gl/m4/gnulib-comp.m4 create mode 100644 gl/m4/gnulib-tool.m4 rename {m4 => gl/m4}/iconv.m4 (100%) create mode 100644 gl/m4/inet_ntop.m4 create mode 100644 gl/m4/inline.m4 create mode 100644 gl/m4/intdiv0.m4 create mode 100644 gl/m4/intl.m4 create mode 100644 gl/m4/intldir.m4 create mode 100644 gl/m4/intmax.m4 create mode 100644 gl/m4/intmax_t.m4 rename {m4 => gl/m4}/inttypes-pri.m4 (74%) rename {m4 => gl/m4}/inttypes_h.m4 (85%) create mode 100644 gl/m4/lcmessage.m4 rename {m4 => gl/m4}/lib-ld.m4 (100%) rename {m4 => gl/m4}/lib-link.m4 (70%) rename {m4 => gl/m4}/lib-prefix.m4 (100%) create mode 100644 gl/m4/lock.m4 rename {m4 => gl/m4}/longdouble.m4 (79%) create mode 100644 gl/m4/longlong.m4 rename {m4 => gl/m4}/ls-mntd-fs.m4 (88%) create mode 100644 gl/m4/mbchar.m4 create mode 100644 gl/m4/mbiter.m4 create mode 100644 gl/m4/mbrtowc.m4 create mode 100644 gl/m4/memchr.m4 create mode 100644 gl/m4/minmax.m4 rename {m4 => gl/m4}/mountlist.m4 (84%) create mode 100644 gl/m4/netinet_in_h.m4 rename {m4 => gl/m4}/nls.m4 (58%) rename {m4 => gl/m4}/onceonly_2_57.m4 (90%) rename {m4 => gl/m4}/po.m4 (90%) create mode 100644 gl/m4/printf-posix.m4 rename {m4 => gl/m4}/progtest.m4 (100%) rename {m4 => gl/m4}/regex.m4 (69%) create mode 100644 gl/m4/safe-read.m4 create mode 100644 gl/m4/safe-write.m4 create mode 100644 gl/m4/size_max.m4 create mode 100644 gl/m4/snprintf.m4 create mode 100644 gl/m4/socklen.m4 create mode 100644 gl/m4/sockpfaf.m4 create mode 100644 gl/m4/ssize_t.m4 rename {m4 => gl/m4}/stdbool.m4 (82%) create mode 100644 gl/m4/stdint.m4 rename {m4 => gl/m4}/stdint_h.m4 (85%) create mode 100644 gl/m4/strcase.m4 create mode 100644 gl/m4/strdup.m4 create mode 100644 gl/m4/strndup.m4 create mode 100644 gl/m4/strnlen.m4 create mode 100644 gl/m4/sys_socket_h.m4 rename {m4 => gl/m4}/uintmax_t.m4 (100%) create mode 100644 gl/m4/ulonglong.m4 rename {m4 => gl/m4}/unistd-safer.m4 (66%) create mode 100644 gl/m4/unistd_h.m4 create mode 100644 gl/m4/vasnprintf.m4 create mode 100644 gl/m4/vasprintf.m4 create mode 100644 gl/m4/visibility.m4 create mode 100644 gl/m4/vsnprintf.m4 create mode 100644 gl/m4/wchar.m4 rename {m4 => gl/m4}/wchar_t.m4 (100%) create mode 100644 gl/m4/wctype.m4 create mode 100644 gl/m4/wcwidth.m4 rename {m4 => gl/m4}/wint_t.m4 (59%) rename {m4 => gl/m4}/xalloc.m4 (72%) create mode 100644 gl/m4/xsize.m4 create mode 100644 gl/m4/xstrndup.m4 rename {lib => gl}/malloc.c (90%) rename lib/xstrdup.c => gl/mbchar.c (58%) create mode 100644 gl/mbchar.h create mode 100644 gl/mbuiter.h create mode 100644 gl/memchr.c create mode 100644 gl/minmax.h rename {lib => gl}/mountlist.c (88%) rename {lib => gl}/mountlist.h (100%) rename {lib => gl}/open-safer.c (93%) rename {lib => gl}/pipe-safer.c (65%) create mode 100644 gl/printf-args.c create mode 100644 gl/printf-args.h create mode 100644 gl/printf-parse.c create mode 100644 gl/printf-parse.h rename {lib => gl}/regcomp.c (87%) rename {lib => gl}/regex.c (91%) rename {lib => gl}/regex.h (58%) rename {lib => gl}/regex_internal.c (84%) rename {lib => gl}/regex_internal.h (82%) rename {lib => gl}/regexec.c (88%) rename {lib => gl}/safe-read.c (93%) rename {lib => gl}/safe-read.h (89%) rename {lib => gl}/safe-write.c (100%) rename {lib => gl}/safe-write.h (100%) create mode 100644 gl/size_max.h create mode 100644 gl/snprintf.c create mode 100644 gl/snprintf.h create mode 100644 gl/socket_.h rename {lib => gl}/stdbool_.h (56%) create mode 100644 gl/stdint_.h rename {lib => gl}/strcase.h (75%) create mode 100644 gl/strcasecmp.c create mode 100644 gl/strdup.c create mode 100644 gl/strdup.h create mode 100644 gl/stripslash.c create mode 100644 gl/strncasecmp.c create mode 100644 gl/strndup.c create mode 100644 gl/strndup.h create mode 100644 gl/strnlen.c create mode 100644 gl/strnlen.h create mode 100644 gl/strnlen1.c create mode 100644 gl/strnlen1.h rename {lib => gl}/unistd--.h (100%) rename {lib => gl}/unistd-safer.h (100%) create mode 100644 gl/unistd_.h create mode 100644 gl/vasnprintf.c create mode 100644 gl/vasnprintf.h create mode 100644 gl/vasprintf.c create mode 100644 gl/vasprintf.h create mode 100644 gl/vsnprintf.c create mode 100644 gl/vsnprintf.h create mode 100644 gl/wchar_.h create mode 100644 gl/wctype_.h create mode 100644 gl/wcwidth.h rename {lib => gl}/xalloc-die.c (90%) create mode 100644 gl/xalloc.h create mode 100644 gl/xmalloc.c create mode 100644 gl/xsize.h create mode 100644 gl/xstrndup.c create mode 100644 gl/xstrndup.h delete mode 100644 lib/basename.c delete mode 100644 lib/c-strtold.c delete mode 100644 lib/gettext.h delete mode 100644 lib/realloc.c delete mode 100644 lib/snprintf.c delete mode 100644 lib/strtod.c delete mode 100644 lib/unlocked-io.h delete mode 100644 lib/xalloc.h delete mode 100644 lib/xmalloc.c delete mode 100644 m4/Makefile.am.in delete mode 100644 m4/afs.m4 delete mode 100644 m4/basename.m4 delete mode 100644 m4/extensions.m4 delete mode 100644 m4/fstypename.m4 delete mode 100644 m4/inttypes.m4 delete mode 100644 m4/longlong.m4 delete mode 100644 m4/np_coreutils.m4 delete mode 100644 m4/np_curl.m4 delete mode 100644 m4/restrict.m4 delete mode 100644 m4/signed.m4 delete mode 100644 m4/ulonglong.m4 delete mode 100644 m4/unlocked-io.m4 delete mode 100644 plugins/getaddrinfo.c delete mode 100644 plugins/getaddrinfo.h delete mode 100644 plugins/gethostbyname.c delete mode 100644 plugins/gethostbyname.h delete mode 100755 tools/update_coreutils diff --git a/Makefile.am b/Makefile.am index 22b7fe0..1fb696f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = lib plugins plugins-scripts plugins-root m4 po +SUBDIRS = gl lib plugins plugins-scripts plugins-root po EXTRA_DIST = config.rpath \ ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ @@ -9,7 +9,7 @@ EXTRA_DIST = config.rpath \ config_test/Makefile config_test/run_tests config_test/child_test.c \ tools/tinderbox_build -ACLOCAL_AMFLAGS = -I m4 +ACLOCAL_AMFLAGS = -I gl/m4 -I m4 localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" diff --git a/NEWS b/NEWS deleted file mode 100644 index 1c3c54c..0000000 --- a/NEWS +++ /dev/null @@ -1,2 +0,0 @@ -New in 1.2.9: -* 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 @@ -#! /bin/sh -# Output a system dependent set of variables, describing how to set the -# run time search path of shared libraries in an executable. -# -# Copyright 1996-2002 Free Software Foundation, Inc. -# Taken from GNU libtool, 2001 -# Originally by Gordon Matzigkeit , 1996 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. -# -# The first argument passed to this file is the canonical host specification, -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld -# should be set by the caller. -# -# The set of defined variables is at the end of this script. - -# All known linkers require a `.a' archive for static linking (except M$VC, -# which needs '.lib'). -libext=a -shlibext= - -host="$1" -host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` -host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` -host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` - -wl= -if test "$GCC" = yes; then - wl='-Wl,' -else - case "$host_os" in - aix3* | aix4* | aix5*) - wl='-Wl,' - ;; - hpux9* | hpux10* | hpux11*) - wl='-Wl,' - ;; - irix5* | irix6*) - wl='-Wl,' - ;; - linux*) - echo '__INTEL_COMPILER' > conftest.$ac_ext - if $CC -E conftest.$ac_ext >/dev/null | grep __INTEL_COMPILER >/dev/null - then - : - else - # Intel icc - wl='-Qoption,ld,' - fi - ;; - osf3* | osf4* | osf5*) - wl='-Wl,' - ;; - solaris*) - wl='-Wl,' - ;; - sunos4*) - wl='-Qoption ld ' - ;; - sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) - if test "x$host_vendor" = xsni; then - wl='-LD' - else - wl='-Wl,' - fi - ;; - esac -fi - -hardcode_libdir_flag_spec= -hardcode_libdir_separator= -hardcode_direct=no -hardcode_minus_L=no - -case "$host_os" in - cygwin* | mingw* | pw32*) - # FIXME: the MSVC++ port hasn't been tested in a loooong time - # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. - if test "$GCC" != yes; then - with_gnu_ld=no - fi - ;; - openbsd*) - with_gnu_ld=no - ;; -esac - -ld_shlibs=yes -if test "$with_gnu_ld" = yes; then - case "$host_os" in - aix3* | aix4* | aix5*) - # On AIX, the GNU linker is very broken - ld_shlibs=no - ;; - amigaos*) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_minus_L=yes - # Samuel A. Falvo II reports - # that the semantics of dynamic libraries on AmigaOS, at least up - # to version 4, is to share data among multiple programs linked - # with the same dynamic library. Since this doesn't match the - # behavior of shared libraries on other platforms, we can use - # them. - ld_shlibs=no - ;; - beos*) - if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then - : - else - ld_shlibs=no - fi - ;; - cygwin* | mingw* | pw32*) - # hardcode_libdir_flag_spec is actually meaningless, as there is - # no search path for DLLs. - hardcode_libdir_flag_spec='-L$libdir' - ;; - solaris* | sysv5*) - if $LD -v 2>&1 | egrep 'BFD 2\.8' > /dev/null; then - ld_shlibs=no - elif $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then - : - else - ld_shlibs=no - fi - ;; - sunos4*) - hardcode_direct=yes - ;; - *) - if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then - : - else - ld_shlibs=no - fi - ;; - esac - if test "$ld_shlibs" = yes; then - hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' - fi -else - case "$host_os" in - aix3*) - # Note: this linker hardcodes the directories in LIBPATH if there - # are no directories specified by -L. - hardcode_minus_L=yes - if test "$GCC" = yes; then - # Neither direct hardcoding nor static linking is supported with a - # broken collect2. - hardcode_direct=unsupported - fi - ;; - aix4* | aix5*) - if test "$host_cpu" = ia64; then - # On IA64, the linker does run time linking by default, so we don't - # have to do anything special. - aix_use_runtimelinking=no - else - aix_use_runtimelinking=no - # Test if we are trying to use run time linking or normal - # AIX style linking. If -brtl is somewhere in LDFLAGS, we - # need to do runtime linking. - case $host_os in aix4.[23]|aix4.[23].*|aix5*) - for ld_flag in $LDFLAGS; do - if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then - aix_use_runtimelinking=yes - break - fi - done - esac - fi - hardcode_direct=yes - hardcode_libdir_separator=':' - if test "$GCC" = yes; then - case $host_os in aix4.[012]|aix4.[012].*) - collect2name=`${CC} -print-prog-name=collect2` - if test -f "$collect2name" && \ - strings "$collect2name" | grep resolve_lib_name >/dev/null - then - # We have reworked collect2 - hardcode_direct=yes - else - # We have old collect2 - hardcode_direct=unsupported - hardcode_minus_L=yes - hardcode_libdir_flag_spec='-L$libdir' - hardcode_libdir_separator= - fi - esac - fi - if test "$aix_use_runtimelinking" = yes; then - hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib' - else - if test "$host_cpu" = ia64; then - hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' - else - hardcode_libdir_flag_spec='${wl}-bnolibpath ${wl}-blibpath:$libdir:/usr/lib:/lib' - fi - fi - ;; - amigaos*) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_minus_L=yes - # see comment about different semantics on the GNU ld section - ld_shlibs=no - ;; - cygwin* | mingw* | pw32*) - # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. - # hardcode_libdir_flag_spec is actually meaningless, as there is - # no search path for DLLs. - hardcode_libdir_flag_spec=' ' - libext=lib - ;; - darwin* | rhapsody*) - hardcode_direct=yes - ;; - freebsd1*) - ld_shlibs=no - ;; - freebsd2.2*) - hardcode_libdir_flag_spec='-R$libdir' - hardcode_direct=yes - ;; - freebsd2*) - hardcode_direct=yes - hardcode_minus_L=yes - ;; - freebsd*) - hardcode_libdir_flag_spec='-R$libdir' - hardcode_direct=yes - ;; - hpux9* | hpux10* | hpux11*) - hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' - hardcode_libdir_separator=: - hardcode_direct=yes - hardcode_minus_L=yes # Not in the search PATH, but as the default - # location of the library. - ;; - irix5* | irix6*) - hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' - hardcode_libdir_separator=: - ;; - netbsd*) - hardcode_libdir_flag_spec='-R$libdir' - hardcode_direct=yes - ;; - newsos6) - hardcode_direct=yes - hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' - hardcode_libdir_separator=: - ;; - openbsd*) - hardcode_direct=yes - if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then - hardcode_libdir_flag_spec='${wl}-rpath,$libdir' - else - case "$host_os" in - openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) - hardcode_libdir_flag_spec='-R$libdir' - ;; - *) - hardcode_libdir_flag_spec='${wl}-rpath,$libdir' - ;; - esac - fi - ;; - os2*) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_minus_L=yes - ;; - osf3*) - hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' - hardcode_libdir_separator=: - ;; - osf4* | osf5*) - if test "$GCC" = yes; then - hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' - else - # Both cc and cxx compiler support -rpath directly - hardcode_libdir_flag_spec='-rpath $libdir' - fi - hardcode_libdir_separator=: - ;; - sco3.2v5*) - ;; - solaris*) - hardcode_libdir_flag_spec='-R$libdir' - ;; - sunos4*) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_direct=yes - hardcode_minus_L=yes - ;; - sysv4) - if test "x$host_vendor" = xsno; then - hardcode_direct=yes # is this really true??? - else - hardcode_direct=no # Motorola manual says yes, but my tests say they lie - fi - ;; - sysv4.3*) - ;; - sysv5*) - hardcode_libdir_flag_spec= - ;; - uts4*) - hardcode_libdir_flag_spec='-L$libdir' - ;; - dgux*) - hardcode_libdir_flag_spec='-L$libdir' - ;; - sysv4*MP*) - if test -d /usr/nec; then - ld_shlibs=yes - fi - ;; - sysv4.2uw2*) - hardcode_direct=yes - hardcode_minus_L=no - ;; - sysv5uw7* | unixware7*) - ;; - *) - ld_shlibs=no - ;; - esac -fi - -# Check dynamic linker characteristics -libname_spec='lib$name' -sys_lib_dlsearch_path_spec="/lib /usr/lib" -sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" -case "$host_os" in - aix3*) - shlibext=so - ;; - aix4* | aix5*) - shlibext=so - ;; - amigaos*) - shlibext=ixlibrary - ;; - beos*) - shlibext=so - ;; - bsdi4*) - shlibext=so - sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" - sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" - ;; - cygwin* | mingw* | pw32*) - case $GCC,$host_os in - yes,cygwin*) - shlibext=dll.a - ;; - yes,mingw*) - shlibext=dll - sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | sed -e "s/^libraries://" -e "s/;/ /g"` - ;; - yes,pw32*) - shlibext=dll - ;; - *) - shlibext=dll - ;; - esac - ;; - darwin* | rhapsody*) - shlibext=dylib - ;; - freebsd1*) - ;; - freebsd*) - shlibext=so - ;; - gnu*) - shlibext=so - ;; - hpux9* | hpux10* | hpux11*) - shlibext=sl - ;; - irix5* | irix6*) - shlibext=so - case "$host_os" in - irix5*) - libsuff= shlibsuff= - ;; - *) - case $LD in - *-32|*"-32 ") libsuff= shlibsuff= ;; - *-n32|*"-n32 ") libsuff=32 shlibsuff=N32 ;; - *-64|*"-64 ") libsuff=64 shlibsuff=64 ;; - *) libsuff= shlibsuff= ;; - esac - ;; - esac - sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" - sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" - ;; - linux-gnuoldld* | linux-gnuaout* | linux-gnucoff*) - ;; - linux-gnu*) - shlibext=so - ;; - netbsd*) - shlibext=so - ;; - newsos6) - shlibext=so - ;; - openbsd*) - shlibext=so - ;; - os2*) - libname_spec='$name' - shlibext=dll - ;; - osf3* | osf4* | osf5*) - shlibext=so - sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" - sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" - ;; - sco3.2v5*) - shlibext=so - ;; - solaris*) - shlibext=so - ;; - sunos4*) - shlibext=so - ;; - sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) - shlibext=so - case "$host_vendor" in - motorola) - sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' - ;; - esac - ;; - uts4*) - shlibext=so - ;; - dgux*) - shlibext=so - ;; - sysv4*MP*) - if test -d /usr/nec; then - shlibext=so - fi - ;; -esac - -sed_quote_subst='s/\(["`$\\]\)/\\\1/g' -escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` -escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` -escaped_sys_lib_search_path_spec=`echo "X$sys_lib_search_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` -escaped_sys_lib_dlsearch_path_spec=`echo "X$sys_lib_dlsearch_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` - -sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <])]) - AC_CHECK_LIB(lwres, lwres_getaddrinfo, , - [AC_MSG_ERROR([cannot find the lwres library])], - -lnsl -lpthread) - have_getaddrinfo=yes -fi - -if test x$have_getaddrinfo != xyes ; then - AC_SEARCH_LIBS(getaddrinfo, socket resolv bind nsl c_r cr, have_getaddrinfo=yes) -fi - -dnl # Special nonsense for systems that actually have getaddrinfo but -dnl # redefine the name to something else, e.g. OSF -if test x$have_getaddrinfo != xyes ; then - AC_MSG_CHECKING(if getaddrinfo is redefined in netdb.h) - AC_TRY_LINK([ -# include - ], [ - struct addrinfo hints, *res; - int err; - - err = getaddrinfo ("host", "service", &hints, &res); - ], [ - have_getaddrinfo=yes - AC_MSG_RESULT(yes) - ], [AC_MSG_RESULT(no)]) -fi - -fi - -if test x$have_getaddrinfo != xno ; then - if test x$enable_emulate_getaddrinfo != xno ; then - AC_MSG_ERROR([getaddrinfo found but emulate-getaddrinfo was enabled]) - fi - AC_DEFINE(HAVE_GETADDRINFO, 1, - [Does system provide RFC 2553/Posix getaddrinfo?]) -else - if test x$enable_emulate_getaddrinfo != xyes ; then -dnl AC_MSG_ERROR([getaddrinfo not found: try --with-lwres or --enable-emulate-getaddrinfo]) - enable_emulate_getaddrinfo=yes - AC_MSG_WARN([enabling getaddrinfo emulation]) - fi - EXTRA_NETOBJS="$EXTRA_NETOBJS getaddrinfo.o" -fi - -if test x"$enable_emulate_getaddrinfo" != xno ; then - have_resolver=no - - dnl Try for getipnodebyname - AC_SEARCH_LIBS(getipnodebyname, resolv bind nsl c_r cr, have_resolver=yes) - if test x"$have_resolver" != xno ; then - AC_DEFINE(HAVE_GETIPNODEBYNAME, 1, - [Set when getipnodebyname is available]) - fi - - dnl Try for gethostbyname_r - if test x"$have_resolver" = xno ; then - AC_SEARCH_LIBS(gethostbyname_r, resolv bind nsl c_r cr, - [have_resolver=yes - ACX_WHICH_GETHOSTBYNAME_R]) - fi - - dnl Try for gethostbyname - if test x"$have_resolver" = xno ; then - if test x"$enable_pthreads" != xno ; then - AC_MSG_WARN([using threads but cannot find gethostbyname_r or getipnodebyname]) - fi - AC_SEARCH_LIBS(gethostbyname, resolv bind nsl, , - [AC_MSG_ERROR([cannot find gethostbyname])]) - fi - EXTRA_NETOBJS="$EXTRA_NETOBJS gethostbyname.o" - -fi dnl Checks for Kerberos. Must come before openssl checks for Redhat EL 3 AC_CHECK_HEADERS(krb5.h,FOUNDINCLUDE=yes,FOUNDINCLUDE=no) @@ -519,7 +404,7 @@ dnl AC_HEADER_STDC AC_HEADER_TIME AC_HEADER_SYS_WAIT -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) +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) AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h stdlib.h) dnl Checks for typedefs, structures, and compiler characteristics. @@ -547,37 +432,6 @@ else fi fi -AC_CHECK_FUNCS(vsnprintf snprintf asprintf vasprintf) -AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[ -AC_TRY_RUN([ -#include -#include -void foo(const char *format, ...) { - va_list ap; - int len; - char buf[5]; - - va_start(ap, format); - len = vsnprintf(buf, 0, format, ap); - va_end(ap); - if (len != 5) exit(1); - - va_start(ap, format); - len = vsnprintf(0, 0, format, ap); - va_end(ap); - if (len != 5) exit(1); - - if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1); - - exit(0); -} -main() { foo("hello"); } -], -ac_cv_HAVE_C99_VSNPRINTF=yes,ac_cv_HAVE_C99_VSNPRINTF=no,ac_cv_HAVE_C99_VSNPRINTF=cross)]) -if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then - AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf]) -fi - AC_TRY_COMPILE([#include ], [struct timeval *tv; struct timezone *tz;], @@ -606,24 +460,6 @@ AC_TRY_COMPILE([#include AC_DEFINE_UNQUOTED(SOCKET_SIZE_TYPE, $ac_cv_socket_size_type , [Define type of socket size]) -AC_ARG_WITH(proc-loadavg, - ACX_HELP_STRING([--with-proc-loadavg=PATH], - [path to /proc/loadavg or equivalent]), - ac_cv_proc_loadavg=$withval) -AC_MSG_CHECKING([for /proc/loadavg]) -if test -n "$ac_cv_proc_loadavg"; then - AC_MSG_RESULT([(command line) $ac_cv_proc_loadavg]) -elif test -f "/proc/loadavg"; then - AC_MSG_RESULT([found /proc/loadavg]) - ac_cv_proc_loadavg="/proc/loadavg" -else - AC_MSG_RESULT([no]) -fi - -if test -n "$ac_cv_proc_loadavg"; then - AC_DEFINE(HAVE_PROC_LOADAVG,1,[Define if /proc/loadavg or similar exists]) - AC_DEFINE_UNQUOTED(PROC_LOADAVG,"/proc/loadavg",[Location of /proc/loadavg]) -fi dnl #### Process table test @@ -1615,21 +1451,6 @@ elif test -f ../plugins/check_nt.c ; then EXTRAS="$EXTRAS check_nt" fi -AC_MSG_CHECKING(for va_list) -AC_TRY_COMPILE([#ifdef __STDC__ - #include - #include - #include - #else - #include - #include - #include - #endif], - [va_list args;], - [AC_MSG_RESULT(yes)], - [NEED_VA_LIST=-DNEED_VA_LIST - AC_SUBST(NEED_VA_LIST) - AC_MSG_RESULT(no)]) case $host in *bsd*) @@ -1682,8 +1503,7 @@ elif test "$ac_cv_enable_redhat_pthread_workaround" = "yes" ; then fi dnl External libraries - see ACKNOWLEDGEMENTS -np_COREUTILS -np_CURL +gl_INIT dnl Some helpful common compile errors checked here if test "$ac_cv_uname_s" = 'SunOS' -a "$ac_cv_prog_ac_ct_AR" = 'false' ; then @@ -1693,7 +1513,6 @@ fi AC_OUTPUT( Makefile lib/Makefile - m4/Makefile plugins/Makefile lib/tests/Makefile plugins-root/Makefile @@ -1727,7 +1546,6 @@ dnl ACX_FEATURE([with],[snmpgetnext-command]) dnl ACX_FEATURE([with],[ssh-command]) dnl ACX_FEATURE([with],[uptime-command]) -dnl ACX_FEATURE([with],[proc-loadavg]) dnl ACX_FEATURE([with],[proc-meminfo]) dnl ACX_FEATURE([with],[ps-command]) dnl ACX_FEATURE([with],[ps-format]) @@ -1739,7 +1557,6 @@ ACX_FEATURE([with],[ipv6]) ACX_FEATURE([with],[mysql]) ACX_FEATURE([with],[openssl]) ACX_FEATURE([with],[gnutls]) -ACX_FEATURE([enable],[emulate-getaddrinfo]) ACX_FEATURE([with],[perl]) ACX_FEATURE([with],[cgiurl]) 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 @@ gnu make 3.79 automake 1.9.2 - autoconf 2.58 + autoconf 2.59 gnu m4 1.4.2 gnu libtool 1.5 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 @@ +## DO NOT EDIT! GENERATED AUTOMATICALLY! +## Process this file with automake to produce Makefile.in. +# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=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 + +AUTOMAKE_OPTIONS = 1.5 gnits + +noinst_HEADERS = +noinst_LIBRARIES = +noinst_LTLIBRARIES = +EXTRA_DIST = +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = core *.stackdump +MOSTLYCLEANDIRS = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +AM_CPPFLAGS = + +noinst_LIBRARIES += libgnu.a + +libgnu_a_SOURCES = +libgnu_a_LIBADD = $(gl_LIBOBJS) +libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) +EXTRA_libgnu_a_SOURCES = + +## begin gnulib module alloca + + +EXTRA_DIST += alloca.c + +EXTRA_libgnu_a_SOURCES += alloca.c + +libgnu_a_LIBADD += @ALLOCA@ +libgnu_a_DEPENDENCIES += @ALLOCA@ +## end gnulib module alloca + +## begin gnulib module alloca-opt + +BUILT_SOURCES += $(ALLOCA_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +alloca.h: alloca_.h + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/alloca_.h; \ + } > $@-t + mv -f $@-t $@ +MOSTLYCLEANFILES += alloca.h alloca.h-t + +EXTRA_DIST += alloca_.h + +## end gnulib module alloca-opt + +## begin gnulib module arpa_inet + +BUILT_SOURCES += $(ARPA_INET_H) + +# We need the following in order to create when the system +# doesn't have one. +arpa/inet.h: + test -d arpa || mkdir arpa + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#include '; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t +MOSTLYCLEANDIRS += arpa + +## end gnulib module arpa_inet + +## begin gnulib module c-strtod + + +EXTRA_DIST += c-strtod.c c-strtod.h + +EXTRA_libgnu_a_SOURCES += c-strtod.c + +## end gnulib module c-strtod + +## begin gnulib module cloexec + + +EXTRA_DIST += cloexec.c cloexec.h + +EXTRA_libgnu_a_SOURCES += cloexec.c + +## end gnulib module cloexec + +## begin gnulib module dirname + + +EXTRA_DIST += basename.c dirname.c dirname.h stripslash.c + +EXTRA_libgnu_a_SOURCES += basename.c dirname.c stripslash.c + +## end gnulib module dirname + +## begin gnulib module error + + +EXTRA_DIST += error.c error.h + +EXTRA_libgnu_a_SOURCES += error.c + +## end gnulib module error + +## begin gnulib module exit + +libgnu_a_SOURCES += exit.h + +## end gnulib module exit + +## begin gnulib module exitfail + + +EXTRA_DIST += exitfail.c exitfail.h + +EXTRA_libgnu_a_SOURCES += exitfail.c + +## end gnulib module exitfail + +## begin gnulib module fcntl-safer + + +EXTRA_DIST += creat-safer.c fcntl--.h fcntl-safer.h open-safer.c + +EXTRA_libgnu_a_SOURCES += creat-safer.c open-safer.c + +## end gnulib module fcntl-safer + +## begin gnulib module fsusage + + +EXTRA_DIST += fsusage.c fsusage.h + +EXTRA_libgnu_a_SOURCES += fsusage.c + +## end gnulib module fsusage + +## begin gnulib module full-read + +libgnu_a_SOURCES += full-read.h full-read.c + +## end gnulib module full-read + +## begin gnulib module full-write + +libgnu_a_SOURCES += full-write.h full-write.c + +## end gnulib module full-write + +## begin gnulib module getaddrinfo + + +EXTRA_DIST += gai_strerror.c getaddrinfo.c getaddrinfo.h + +EXTRA_libgnu_a_SOURCES += gai_strerror.c getaddrinfo.c + +## end gnulib module getaddrinfo + +## begin gnulib module gethostname + + +EXTRA_DIST += gethostname.c + +EXTRA_libgnu_a_SOURCES += gethostname.c + +## end gnulib module gethostname + +## begin gnulib module getloadavg + + +EXTRA_DIST += getloadavg.c + +EXTRA_libgnu_a_SOURCES += getloadavg.c + +## end gnulib module getloadavg + +## begin gnulib module getopt + +BUILT_SOURCES += $(GETOPT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +getopt.h: getopt_.h + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/getopt_.h; \ + } > $@-t + mv -f $@-t $@ +MOSTLYCLEANFILES += getopt.h getopt.h-t + +EXTRA_DIST += getopt.c getopt1.c getopt_.h getopt_int.h + +EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c + +## end gnulib module getopt + +## begin gnulib module gettext + +# This is for those projects which use "gettextize --intl" to put a source-code +# copy of libintl into their package. In such projects, every Makefile.am needs +# -I$(top_builddir)/intl, so that can be found in this directory. +# For the Makefile.ams in other directories it is the maintainer's +# responsibility; for the one from gnulib we do it here. +# This option has no effect when the user disables NLS (because then the intl +# directory contains no libintl.h file) or when the project does not use +# "gettextize --intl". +AM_CPPFLAGS += -I$(top_builddir)/intl + +## end gnulib module gettext + +## begin gnulib module gettext-h + +libgnu_a_SOURCES += gettext.h + +## end gnulib module gettext-h + +## begin gnulib module inet_ntop + + +EXTRA_DIST += inet_ntop.c inet_ntop.h + +EXTRA_libgnu_a_SOURCES += inet_ntop.c + +## end gnulib module inet_ntop + +## begin gnulib module intprops + + +EXTRA_DIST += intprops.h + +## end gnulib module intprops + +## begin gnulib module malloc + + +EXTRA_DIST += malloc.c + +EXTRA_libgnu_a_SOURCES += malloc.c + +## end gnulib module malloc + +## begin gnulib module mbchar + + +EXTRA_DIST += mbchar.c mbchar.h + +EXTRA_libgnu_a_SOURCES += mbchar.c + +## end gnulib module mbchar + +## begin gnulib module mbuiter + +libgnu_a_SOURCES += mbuiter.h + +## end gnulib module mbuiter + +## begin gnulib module memchr + + +EXTRA_DIST += memchr.c + +EXTRA_libgnu_a_SOURCES += memchr.c + +## end gnulib module memchr + +## begin gnulib module minmax + +libgnu_a_SOURCES += minmax.h + +## end gnulib module minmax + +## begin gnulib module mountlist + + +EXTRA_DIST += mountlist.c mountlist.h + +EXTRA_libgnu_a_SOURCES += mountlist.c + +## end gnulib module mountlist + +## begin gnulib module netinet_in + +BUILT_SOURCES += $(NETINET_IN_H) + +# We need the following in order to create when the system +# doesn't have one. +netinet/in.h: + test -d netinet || mkdir netinet + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#include '; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t +MOSTLYCLEANDIRS += netinet + +## end gnulib module netinet_in + +## begin gnulib module regex + + +EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c + +EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c + +## end gnulib module regex + +## begin gnulib module safe-read + + +EXTRA_DIST += safe-read.c safe-read.h + +EXTRA_libgnu_a_SOURCES += safe-read.c + +## end gnulib module safe-read + +## begin gnulib module safe-write + + +EXTRA_DIST += safe-write.c safe-write.h + +EXTRA_libgnu_a_SOURCES += safe-write.c + +## end gnulib module safe-write + +## begin gnulib module size_max + +libgnu_a_SOURCES += size_max.h + +## end gnulib module size_max + +## begin gnulib module snprintf + + +EXTRA_DIST += snprintf.c snprintf.h + +EXTRA_libgnu_a_SOURCES += snprintf.c + +## end gnulib module snprintf + +## begin gnulib module stdbool + +BUILT_SOURCES += $(STDBOOL_H) + +# We need the following in order to create when the system +# doesn't have one that works. +stdbool.h: stdbool_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += stdbool.h stdbool.h-t + +EXTRA_DIST += stdbool_.h + +## end gnulib module stdbool + +## begin gnulib module stdint + +BUILT_SOURCES += $(STDINT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +stdint.h: stdint_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ + -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \ + -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ + -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ + -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \ + -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \ + -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ + -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \ + -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \ + -e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \ + -e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \ + -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \ + -e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ + -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ + -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ + < $(srcdir)/stdint_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += stdint.h stdint.h-t + +EXTRA_DIST += stdint_.h + +## end gnulib module stdint + +## begin gnulib module strcase + + +EXTRA_DIST += strcase.h strcasecmp.c strncasecmp.c + +EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c + +## end gnulib module strcase + +## begin gnulib module strdup + + +EXTRA_DIST += strdup.c strdup.h + +EXTRA_libgnu_a_SOURCES += strdup.c + +## end gnulib module strdup + +## begin gnulib module strndup + + +EXTRA_DIST += strndup.c strndup.h + +EXTRA_libgnu_a_SOURCES += strndup.c + +## end gnulib module strndup + +## begin gnulib module strnlen + + +EXTRA_DIST += strnlen.c strnlen.h + +EXTRA_libgnu_a_SOURCES += strnlen.c + +## end gnulib module strnlen + +## begin gnulib module strnlen1 + +libgnu_a_SOURCES += strnlen1.h strnlen1.c + +## end gnulib module strnlen1 + +## begin gnulib module sys_socket + +BUILT_SOURCES += $(SYS_SOCKET_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +sys/socket.h: socket_.h + @MKDIR_P@ sys + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/socket_.h; \ + } > $@-t + mv -f $@-t $@ +MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t +MOSTLYCLEANDIRS += sys + +EXTRA_DIST += socket_.h + +## end gnulib module sys_socket + +## begin gnulib module unistd + +BUILT_SOURCES += $(UNISTD_H) + +# We need the following in order to create an empty placeholder for +# when the system doesn't have one. +unistd.h: unistd_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''ABSOLUTE_UNISTD_H''@|$(ABSOLUTE_UNISTD_H)|g' \ + < $(srcdir)/unistd_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += unistd.h unistd.h-t + +EXTRA_DIST += unistd_.h + +## end gnulib module unistd + +## begin gnulib module unistd-safer + + +EXTRA_DIST += dup-safer.c fd-safer.c pipe-safer.c unistd--.h unistd-safer.h + +EXTRA_libgnu_a_SOURCES += dup-safer.c fd-safer.c pipe-safer.c + +## end gnulib module unistd-safer + +## begin gnulib module vasnprintf + + +EXTRA_DIST += asnprintf.c printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h + +EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c + +## end gnulib module vasnprintf + +## begin gnulib module vasprintf + + +EXTRA_DIST += asprintf.c vasprintf.c vasprintf.h + +EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c + +## end gnulib module vasprintf + +## begin gnulib module vsnprintf + + +EXTRA_DIST += vsnprintf.c vsnprintf.h + +EXTRA_libgnu_a_SOURCES += vsnprintf.c + +## end gnulib module vsnprintf + +## begin gnulib module wchar + +BUILT_SOURCES += $(WCHAR_H) + +# We need the following in order to create when the system +# version does not work standalone. +wchar.h: wchar_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''ABSOLUTE_WCHAR_H''@|$(ABSOLUTE_WCHAR_H)|g' \ + < $(srcdir)/wchar_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += wchar.h wchar.h-t + +EXTRA_DIST += wchar_.h + +## end gnulib module wchar + +## begin gnulib module wctype + +BUILT_SOURCES += $(WCTYPE_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +wctype.h: wctype_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ + -e 's|@''ABSOLUTE_WCTYPE_H''@|$(ABSOLUTE_WCTYPE_H)|g' \ + -e 's/@''HAVE_WCTYPE_CTMP_BUG''@/$(HAVE_WCTYPE_CTMP_BUG)/g' \ + -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ + < $(srcdir)/wctype_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += wctype.h wctype.h-t + +EXTRA_DIST += wctype_.h + +## end gnulib module wctype + +## begin gnulib module wcwidth + +libgnu_a_SOURCES += wcwidth.h + +## end gnulib module wcwidth + +## begin gnulib module xalloc + + +EXTRA_DIST += xalloc.h xmalloc.c + +EXTRA_libgnu_a_SOURCES += xmalloc.c + +## end gnulib module xalloc + +## begin gnulib module xalloc-die + +libgnu_a_SOURCES += xalloc-die.c + +## end gnulib module xalloc-die + +## begin gnulib module xsize + +libgnu_a_SOURCES += xsize.h + +## end gnulib module xsize + +## begin gnulib module xstrndup + +libgnu_a_SOURCES += xstrndup.h xstrndup.c + +## end gnulib module xstrndup + + +mostlyclean-local: mostlyclean-generic + @for dir in '' $(MOSTLYCLEANDIRS); do \ + if test -n "$$dir" && test -d $$dir; then \ + echo "rmdir $$dir"; rmdir $$dir; \ + fi; \ + done diff --git a/lib/alloca.c b/gl/alloca.c similarity index 99% rename from lib/alloca.c rename to gl/alloca.c index d1d5447..3a1f4e2 100644 --- a/lib/alloca.c +++ b/gl/alloca.c @@ -21,9 +21,7 @@ allocating any. It is a good idea to use alloca(0) in your main control loop, etc. to force garbage collection. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include diff --git a/lib/alloca_.h b/gl/alloca_.h similarity index 83% rename from lib/alloca_.h rename to gl/alloca_.h index 3e3fdf4..dd0b3e9 100644 --- a/lib/alloca_.h +++ b/gl/alloca_.h @@ -1,6 +1,6 @@ /* Memory allocation on the stack. - Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software + Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -34,19 +34,21 @@ request, the program just crashes. */ -#ifdef __GNUC__ -# define alloca __builtin_alloca -#elif defined _AIX -# define alloca __alloca -#elif defined _MSC_VER -# include -# define alloca _alloca -#else -# include -# ifdef __cplusplus +#ifndef alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _AIX +# define alloca __alloca +# elif defined _MSC_VER +# include +# define alloca _alloca +# else +# include +# ifdef __cplusplus extern "C" -# endif +# endif void *alloca (size_t); +# endif #endif #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 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "vasnprintf.h" + +#include + +char * +asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + char *result; + + va_start (args, format); + result = vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return result; +} 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 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "vasprintf.h" + +#include + +int +asprintf (char **resultp, const char *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = vasprintf (resultp, format, args); + va_end (args); + return result; +} 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 @@ +/* basename.c -- return the last element in a file name + + Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free + Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "dirname.h" + +#include +#include "xalloc.h" +#include "xstrndup.h" + +/* Return the address of the last file name component of NAME. If + NAME has no relative file name components because it is a file + system root, return the empty string. */ + +char * +last_component (char const *name) +{ + char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); + char const *p; + bool saw_slash = false; + + while (ISSLASH (*base)) + base++; + + for (p = base; *p; p++) + { + if (ISSLASH (*p)) + saw_slash = true; + else if (saw_slash) + { + base = p; + saw_slash = false; + } + } + + return (char *) base; +} + + +/* In general, we can't use the builtin `basename' function if available, + since it has different meanings in different environments. + In some environments the builtin `basename' modifies its argument. + + Return the last file name component of NAME, allocated with + xmalloc. On systems with drive letters, a leading "./" + distinguishes relative names that would otherwise look like a drive + letter. Unlike POSIX basename(), NAME cannot be NULL, + base_name("") returns "", and the first trailing slash is not + stripped. + + If lstat (NAME) would succeed, then { chdir (dir_name (NAME)); + lstat (base_name (NAME)); } will access the same file. Likewise, + if the sequence { chdir (dir_name (NAME)); + rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME + to "foo" in the same directory NAME was in. */ + +char * +base_name (char const *name) +{ + char const *base = last_component (name); + size_t length; + + /* If there is no last component, then name is a file system root or the + empty string. */ + if (! *base) + return xstrndup (name, base_len (name)); + + /* Collapse a sequence of trailing slashes into one. */ + length = base_len (base); + if (ISSLASH (base[length])) + length++; + + /* On systems with drive letters, `a/b:c' must return `./b:c' rather + than `b:c' to avoid confusion with a drive letter. On systems + with pure POSIX semantics, this is not an issue. */ + if (FILE_SYSTEM_PREFIX_LEN (base)) + { + char *p = xmalloc (length + 3); + p[0] = '.'; + p[1] = '/'; + memcpy (p + 2, base, length); + p[length + 2] = '\0'; + return p; + } + + /* Finally, copy the basename. */ + return xstrndup (base, length); +} + +/* Return the length of the basename NAME. Typically NAME is the + value returned by base_name or last_component. Act like strlen + (NAME), except omit all trailing slashes. */ + +size_t +base_len (char const *name) +{ + size_t len; + size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); + + for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) + continue; + + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1 + && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2]) + return 2; + + if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len + && len == prefix_len && ISSLASH (name[prefix_len])) + return prefix_len + 1; + + return len; +} diff --git a/lib/c-strtod.c b/gl/c-strtod.c similarity index 94% rename from lib/c-strtod.c rename to gl/c-strtod.c index 031f5f8..2234ed0 100644 --- a/lib/c-strtod.c +++ b/gl/c-strtod.c @@ -1,6 +1,6 @@ /* Convert string to double, using the C locale. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,9 +18,7 @@ /* Written by Paul Eggert. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "c-strtod.h" diff --git a/lib/c-strtod.h b/gl/c-strtod.h similarity index 100% rename from lib/c-strtod.h rename to gl/c-strtod.h diff --git a/lib/cloexec.c b/gl/cloexec.c similarity index 92% rename from lib/cloexec.c rename to gl/cloexec.c index cf2308c..6480006 100644 --- a/lib/cloexec.c +++ b/gl/cloexec.c @@ -1,5 +1,6 @@ /* closexec.c - set or clear the close-on-exec descriptor flag - Copyright (C) 1991, 2004, 2005 Free Software Foundation, Inc. + + Copyright (C) 1991, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +18,7 @@ The code is taken from glibc/manual/llio.texi */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "cloexec.h" diff --git a/lib/cloexec.h b/gl/cloexec.h similarity index 100% rename from lib/cloexec.h rename to gl/cloexec.h diff --git a/lib/creat-safer.c b/gl/creat-safer.c similarity index 90% rename from lib/creat-safer.c rename to gl/creat-safer.c index 4588de3..f4a2e59 100644 --- a/lib/creat-safer.c +++ b/gl/creat-safer.c @@ -1,5 +1,6 @@ /* Invoke creat, but avoid some glitches. - Copyright (C) 2005 Free Software Foundation, Inc. + + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +18,7 @@ /* Written by Jim Meyering. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "fcntl-safer.h" 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 @@ +/* dirname.c -- return all but the last element in a file name + + Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "dirname.h" + +#include +#include "xalloc.h" + +/* Return the length of the prefix of FILE that will be used by + dir_name. If FILE is in the working directory, this returns zero + even though `dir_name (FILE)' will return ".". Works properly even + if there are trailing slashes (by effectively ignoring them). */ + +size_t +dir_len (char const *file) +{ + size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file); + size_t length; + + /* Advance prefix_length beyond important leading slashes. */ + prefix_length += (prefix_length != 0 + ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE + && ISSLASH (file[prefix_length])) + : (ISSLASH (file[0]) + ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT + && ISSLASH (file[1]) && ! ISSLASH (file[2]) + ? 2 : 1)) + : 0)); + + /* Strip the basename and any redundant slashes before it. */ + for (length = last_component (file) - file; + prefix_length < length; length--) + if (! ISSLASH (file[length - 1])) + break; + return length; +} + + +/* In general, we can't use the builtin `dirname' function if available, + since it has different meanings in different environments. + In some environments the builtin `dirname' modifies its argument. + + Return the leading directories part of FILE, allocated with xmalloc. + Works properly even if there are trailing slashes (by effectively + ignoring them). Unlike POSIX dirname(), FILE cannot be NULL. + + If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); + lstat (base_name (FILE)); } will access the same file. Likewise, + if the sequence { chdir (dir_name (FILE)); + rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE + to "foo" in the same directory FILE was in. */ + +char * +dir_name (char const *file) +{ + size_t length = dir_len (file); + bool append_dot = (length == 0 + || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE + && length == FILE_SYSTEM_PREFIX_LEN (file) + && file[2] != '\0' && ! ISSLASH (file[2]))); + char *dir = xmalloc (length + append_dot + 1); + memcpy (dir, file, length); + if (append_dot) + dir[length++] = '.'; + dir[length] = '\0'; + return dir; +} diff --git a/lib/dirname.h b/gl/dirname.h similarity index 57% rename from lib/dirname.h rename to gl/dirname.h index 1688ae8..91e7ed3 100644 --- a/lib/dirname.h +++ b/gl/dirname.h @@ -1,6 +1,6 @@ /* Take file names apart into directory and base names. - Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,16 +31,39 @@ # endif # ifndef FILE_SYSTEM_PREFIX_LEN -# define FILE_SYSTEM_PREFIX_LEN(File_name) 0 +# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX + /* This internal macro assumes ASCII, but all hosts that support drive + letters use ASCII. */ +# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \ + <= 'z' - 'a') +# define FILE_SYSTEM_PREFIX_LEN(Filename) \ + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) +# else +# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 +# endif # endif -# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) +# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 +# endif + +# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT +# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 +# endif + +# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) +# else +# define IS_ABSOLUTE_FILE_NAME(F) \ + (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) +# endif # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) char *base_name (char const *file); char *dir_name (char const *file); size_t base_len (char const *file); size_t dir_len (char const *file); +char *last_component (char const *file); bool strip_trailing_slashes (char *file); diff --git a/lib/dup-safer.c b/gl/dup-safer.c similarity index 89% rename from lib/dup-safer.c rename to gl/dup-safer.c index 8cbee70..7b12b61 100644 --- a/lib/dup-safer.c +++ b/gl/dup-safer.c @@ -1,5 +1,6 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. + + Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +18,7 @@ /* Written by Paul Eggert. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "unistd-safer.h" @@ -36,7 +35,7 @@ int dup_safer (int fd) { -#ifdef F_DUPFD +#if defined F_DUPFD && !defined FCHDIR_REPLACEMENT return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); #else /* fd_safer calls us back, but eventually the recursion unwinds and diff --git a/lib/error.c b/gl/error.c similarity index 77% rename from lib/error.c rename to gl/error.c index 45698be..cf86343 100644 --- a/lib/error.c +++ b/gl/error.c @@ -1,5 +1,5 @@ /* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1990-1998, 2000-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ /* Written by David MacKenzie . */ -#ifdef HAVE_CONFIG_H +#if !_LIBC # include #endif @@ -34,6 +34,9 @@ #endif #ifdef _LIBC +# include +# include +# include # include # define mbsrtowcs __mbsrtowcs #endif @@ -59,6 +62,7 @@ unsigned int error_message_count; # define program_name program_invocation_name # include +# include # include /* 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, char *strerror_r (); # endif -# ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -# endif - /* The calling program should define program_name and set it to the name of the executing program. */ extern char *program_name; # if HAVE_STRERROR_R || defined strerror_r # define __strerror_r strerror_r -# endif +# endif /* HAVE_STRERROR_R || defined strerror_r */ #endif /* not _LIBC */ static void print_errno_message (int errnum) { - char const *s = NULL; + char const *s; #if defined HAVE_STRERROR_R || _LIBC char errbuf[1024]; @@ -113,23 +113,23 @@ print_errno_message (int errnum) # else if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) s = errbuf; + else + s = 0; # endif +#else + s = strerror (errnum); #endif #if !_LIBC - if (! s && ! (s = strerror (errnum))) + if (! s) s = _("Unknown system error"); #endif #if _LIBC - if (_IO_fwide (stderr, 0) > 0) - { - __fwprintf (stderr, L": %s", s); - return; - } -#endif - + __fxprintf (NULL, ": %s", s); +#else fprintf (stderr, ": %s", s); +#endif } static void @@ -140,26 +140,65 @@ error_tail (int status, int errnum, const char *message, va_list args) { # define ALLOCA_LIMIT 2000 size_t len = strlen (message) + 1; - const wchar_t *wmessage = L"out of memory"; - wchar_t *wbuf = (len < ALLOCA_LIMIT - ? alloca (len * sizeof *wbuf) - : len <= SIZE_MAX / sizeof *wbuf - ? malloc (len * sizeof *wbuf) - : NULL); - - if (wbuf) + wchar_t *wmessage = NULL; + mbstate_t st; + size_t res; + const char *tmp; + bool use_malloc = false; + + while (1) { - size_t res; - mbstate_t st; - const char *tmp = message; + if (__libc_use_alloca (len * sizeof (wchar_t))) + wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); + else + { + if (!use_malloc) + wmessage = NULL; + + wchar_t *p = (wchar_t *) realloc (wmessage, + len * sizeof (wchar_t)); + if (p == NULL) + { + free (wmessage); + fputws_unlocked (L"out of memory\n", stderr); + return; + } + wmessage = p; + use_malloc = true; + } + memset (&st, '\0', sizeof (st)); - res = mbsrtowcs (wbuf, &tmp, len, &st); - wmessage = res == (size_t) -1 ? L"???" : wbuf; + tmp = message; + + res = mbsrtowcs (wmessage, &tmp, len, &st); + if (res != len) + break; + + if (__builtin_expect (len >= SIZE_MAX / 2, 0)) + { + /* This really should not happen if everything is fine. */ + res = (size_t) -1; + break; + } + + len *= 2; + } + + if (res == (size_t) -1) + { + /* The string cannot be converted. */ + if (use_malloc) + { + free (wmessage); + use_malloc = false; + } + wmessage = (wchar_t *) L"???"; } __vfwprintf (stderr, wmessage, args); - if (! (len < ALLOCA_LIMIT)) - free (wbuf); + + if (use_malloc) + free (wmessage); } else #endif @@ -170,11 +209,10 @@ error_tail (int status, int errnum, const char *message, va_list args) if (errnum) print_errno_message (errnum); #if _LIBC - if (_IO_fwide (stderr, 0) > 0) - putwc (L'\n', stderr); - else + __fxprintf (NULL, "\n"); +#else + putc ('\n', stderr); #endif - putc ('\n', stderr); fflush (stderr); if (status) exit (status); @@ -207,11 +245,10 @@ error (int status, int errnum, const char *message, ...) else { #if _LIBC - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s: ", program_name); - else + __fxprintf (NULL, "%s: ", program_name); +#else + fprintf (stderr, "%s: ", program_name); #endif - fprintf (stderr, "%s: ", program_name); } va_start (args, message); @@ -267,22 +304,19 @@ error_at_line (int status, int errnum, const char *file_name, else { #if _LIBC - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s: ", program_name); - else + __fxprintf (NULL, "%s:", program_name); +#else + fprintf (stderr, "%s:", program_name); #endif - fprintf (stderr, "%s:", program_name); } - if (file_name != NULL) - { #if _LIBC - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s:%d: ", file_name, line_number); - else + __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", + file_name, line_number); +#else + fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", + file_name, line_number); #endif - fprintf (stderr, "%s:%d: ", file_name, line_number); - } va_start (args, message); error_tail (status, errnum, message, args); diff --git a/lib/error.h b/gl/error.h similarity index 93% rename from lib/error.h rename to gl/error.h index e5220a2..5a5f247 100644 --- a/lib/error.h +++ b/gl/error.h @@ -1,5 +1,5 @@ /* Declaration for error-reporting function - Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif /* The __-protected variants of `format' and `printf' attributes diff --git a/lib/exit.h b/gl/exit.h similarity index 92% rename from lib/exit.h rename to gl/exit.h index 9dbfb7c..e8f7738 100644 --- a/lib/exit.h +++ b/gl/exit.h @@ -21,7 +21,7 @@ /* Get exit() declaration. */ #include -/* Some systems do not define EXIT_*, even with STDC_HEADERS. */ +/* Some systems do not define EXIT_*, despite otherwise supporting C89. */ #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 #endif diff --git a/lib/exitfail.c b/gl/exitfail.c similarity index 88% rename from lib/exitfail.c rename to gl/exitfail.c index 27d38c3..97abc67 100644 --- a/lib/exitfail.c +++ b/gl/exitfail.c @@ -1,6 +1,6 @@ /* Failure exit status - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +17,7 @@ If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "exitfail.h" #include "exit.h" diff --git a/lib/exitfail.h b/gl/exitfail.h similarity index 100% rename from lib/exitfail.h rename to gl/exitfail.h diff --git a/lib/fcntl--.h b/gl/fcntl--.h similarity index 100% rename from lib/fcntl--.h rename to gl/fcntl--.h diff --git a/lib/fcntl-safer.h b/gl/fcntl-safer.h similarity index 100% rename from lib/fcntl-safer.h rename to gl/fcntl-safer.h diff --git a/lib/fd-safer.c b/gl/fd-safer.c similarity index 94% rename from lib/fd-safer.c rename to gl/fd-safer.c index 5933bcb..256bfa4 100644 --- a/lib/fd-safer.c +++ b/gl/fd-safer.c @@ -1,6 +1,6 @@ /* Return a safer copy of a file descriptor. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,9 +18,7 @@ /* Written by Paul Eggert. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "unistd-safer.h" diff --git a/lib/fsusage.c b/gl/fsusage.c similarity index 81% rename from lib/fsusage.c rename to gl/fsusage.c index b137790..337bf53 100644 --- a/lib/fsusage.c +++ b/gl/fsusage.c @@ -1,6 +1,6 @@ /* fsusage.c -- return space usage of mounted file systems - Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005 + Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -17,62 +17,49 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if HAVE_INTTYPES_H -# include -#endif -#if HAVE_STDINT_H -# include -#endif -#include -#ifndef UINTMAX_MAX -# define UINTMAX_MAX ((uintmax_t) -1) -#endif +#include -#include -#include #include "fsusage.h" #include +#include -#if HAVE_SYS_PARAM_H -# include -#endif - -#if HAVE_SYS_MOUNT_H -# include -#endif - -#if HAVE_SYS_VFS_H -# include -#endif - -#if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ -# include -#endif - -#if defined HAVE_SYS_FILSYS_H && !defined _CRAY -# include /* SVR2 */ -#endif - -#include - -#if HAVE_SYS_STATFS_H -# include -#endif - -#if HAVE_DUSTAT_H /* AIX PS/2 */ -# include -#endif - -#if HAVE_SYS_STATVFS_H /* SVR4 */ +#if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */ # include +#else +/* Don't include backward-compatibility files unless they're needed. + Eventually we'd like to remove all this cruft. */ +# include +# include +# include +# if HAVE_SYS_PARAM_H +# include +# endif +# if HAVE_SYS_MOUNT_H +# include +# endif +# if HAVE_SYS_VFS_H +# include +# endif +# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ +# include +# endif +# if defined HAVE_SYS_FILSYS_H && !defined _CRAY +# include /* SVR2 */ +# endif +# if HAVE_SYS_STATFS_H +# include +# endif +# if HAVE_DUSTAT_H /* AIX PS/2 */ +# include +# endif +# include "full-read.h" #endif -#include "full-read.h" +/* The results of open() in this file are not used with fchdir, + therefore save some unnecessary work in fchdir.c. */ +#undef open +#undef close /* Many space usage primitives use all 1 bits to denote a value that is not applicable or unknown. Propagate this information by returning @@ -83,7 +70,7 @@ && (~ (x) == (sizeof (x) < sizeof (int) \ ? - (1 << (sizeof (x) * CHAR_BIT)) \ : 0))) \ - ? UINTMAX_MAX : (x)) + ? UINTMAX_MAX : (uintmax_t) (x)) /* Extract the top bit of X as an uintmax_t value. */ #define EXTRACT_TOP_BIT(x) ((x) \ @@ -108,18 +95,19 @@ int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) { -#ifdef STAT_STATFS3_OSF1 +#if defined STAT_STATVFS /* POSIX */ - struct statfs fsd; + struct statvfs fsd; - if (statfs (file, &fsd, sizeof (struct statfs)) != 0) + if (statvfs (file, &fsd) < 0) return -1; - fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); - -#endif /* STAT_STATFS3_OSF1 */ + /* f_frsize isn't guaranteed to be supported. */ + fsp->fsu_blocksize = (fsd.f_frsize + ? PROPAGATE_ALL_ONES (fsd.f_frsize) + : PROPAGATE_ALL_ONES (fsd.f_bsize)); -#ifdef STAT_STATFS2_FS_DATA /* Ultrix */ +#elif defined STAT_STATFS2_FS_DATA /* Ultrix */ struct fs_data fsd; @@ -134,9 +122,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); -#endif /* STAT_STATFS2_FS_DATA */ - -#ifdef STAT_READ_FILSYS /* SVR2 */ +#elif defined STAT_READ_FILSYS /* SVR2 */ # ifndef SUPERBOFF # define SUPERBOFF (SUPERB * 512) # endif @@ -171,9 +157,16 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); -#endif /* STAT_READ_FILSYS */ +#elif defined STAT_STATFS3_OSF1 -#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ + struct statfs fsd; + + if (statfs (file, &fsd, sizeof (struct statfs)) != 0) + return -1; + + fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); + +#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ struct statfs fsd; @@ -197,9 +190,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) } # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ -#endif /* STAT_STATFS2_BSIZE */ - -#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */ +#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ struct statfs fsd; @@ -208,9 +199,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); -#endif /* STAT_STATFS2_FSIZE */ - -#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ +#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN # define f_bavail f_bfree @@ -230,24 +219,10 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_blocksize = 512; # endif -#endif /* STAT_STATFS4 */ - -#ifdef STAT_STATVFS /* SVR4 */ - - struct statvfs fsd; - - if (statvfs (file, &fsd) < 0) - return -1; - - /* f_frsize isn't guaranteed to be supported. */ - fsp->fsu_blocksize = (fsd.f_frsize - ? PROPAGATE_ALL_ONES (fsd.f_frsize) - : PROPAGATE_ALL_ONES (fsd.f_bsize)); - -#endif /* STAT_STATVFS */ +#endif -#if !defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS - /* !Ultrix && !SVR2 */ +#if (defined STAT_STATVFS \ + || (!defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS)) fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); 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) fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); -#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */ +#endif return 0; } diff --git a/lib/fsusage.h b/gl/fsusage.h similarity index 93% rename from lib/fsusage.h rename to gl/fsusage.h index f3eda2d..7fa9f8d 100644 --- a/lib/fsusage.h +++ b/gl/fsusage.h @@ -1,6 +1,6 @@ /* fsusage.h -- declarations for file system space usage info - Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005 Free Software + Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -22,6 +22,7 @@ #if !defined FSUSAGE_H_ # define FSUSAGE_H_ +# include # include struct fs_usage diff --git a/lib/full-read.c b/gl/full-read.c similarity index 100% rename from lib/full-read.c rename to gl/full-read.c diff --git a/lib/full-read.h b/gl/full-read.h similarity index 100% rename from lib/full-read.h rename to gl/full-read.h diff --git a/lib/full-write.c b/gl/full-write.c similarity index 95% rename from lib/full-write.c rename to gl/full-write.c index 106f3c7..cc16872 100644 --- a/lib/full-write.c +++ b/gl/full-write.c @@ -1,7 +1,7 @@ /* An interface to read and write that retries (if necessary) until complete. Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004 Free Software Foundation, Inc. + 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include /* Specification. */ #ifdef FULL_READ @@ -62,7 +60,7 @@ size_t full_rw (int fd, const void *buf, size_t count) { size_t total = 0; - const char *ptr = buf; + const char *ptr = (const char *) buf; while (count > 0) { diff --git a/lib/full-write.h b/gl/full-write.h similarity index 100% rename from lib/full-write.h rename to 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 @@ +/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Philip Blundell , 1997. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _LIBC +# include +# include "getaddrinfo.h" +#endif + +#include +#ifdef HAVE_NETDB_H +# include +#endif + +#ifdef _LIBC +# include +#else +# include "gettext.h" +# define _(String) gettext (String) +# define N_(String) String +#endif + +static struct + { + int code; + const char *msg; + } +values[] = + { + { EAI_ADDRFAMILY, N_("Address family for hostname not supported") }, + { EAI_AGAIN, N_("Temporary failure in name resolution") }, + { EAI_BADFLAGS, N_("Bad value for ai_flags") }, + { EAI_FAIL, N_("Non-recoverable failure in name resolution") }, + { EAI_FAMILY, N_("ai_family not supported") }, + { EAI_MEMORY, N_("Memory allocation failure") }, + { EAI_NODATA, N_("No address associated with hostname") }, + { EAI_NONAME, N_("Name or service not known") }, + { EAI_SERVICE, N_("Servname not supported for ai_socktype") }, + { EAI_SOCKTYPE, N_("ai_socktype not supported") }, + { EAI_SYSTEM, N_("System error") }, +#ifdef __USE_GNU + { EAI_INPROGRESS, N_("Processing request in progress") }, + { EAI_CANCELED, N_("Request canceled") }, + { EAI_NOTCANCELED, N_("Request not canceled") }, + { EAI_ALLDONE, N_("All requests done") }, + { EAI_INTR, N_("Interrupted by a signal") }, + { EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") } +#endif + }; + +const char * +gai_strerror (int code) +{ + size_t i; + for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i) + if (values[i].code == code) + return _(values[i].msg); + + return _("Unknown error"); +} +#ifdef _LIBC +libc_hidden_def (gai_strerror) +#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 @@ +/* Get address information (partial implementation). + Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software + Foundation, Inc. + Contributed by Simon Josefsson . + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "getaddrinfo.h" + +#if HAVE_NETINET_IN_H +# include +#endif + +/* Get calloc. */ +#include + +/* Get memcpy. */ +#include + +#include + +#include "gettext.h" +#define _(String) gettext (String) +#define N_(String) String + +#include "inet_ntop.h" +#include "snprintf.h" +#include "strdup.h" + +/* BeOS has AF_INET, but not PF_INET. */ +#ifndef PF_INET +# define PF_INET AF_INET +#endif +/* BeOS also lacks PF_UNSPEC. */ +#ifndef PF_UNSPEC +# define PF_UNSPEC 0 +#endif + +#if defined _WIN32 || defined __WIN32__ +# define WIN32_NATIVE +#endif + +#ifdef WIN32_NATIVE +typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, + const struct addrinfo*, + struct addrinfo**); +typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*); +typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*, + socklen_t, char*, DWORD, + char*, DWORD, int); + +static getaddrinfo_func getaddrinfo_ptr = NULL; +static freeaddrinfo_func freeaddrinfo_ptr = NULL; +static getnameinfo_func getnameinfo_ptr = NULL; + +static int +use_win32_p (void) +{ + static int done = 0; + HMODULE h; + + if (done) + return getaddrinfo_ptr ? 1 : 0; + + done = 1; + + h = GetModuleHandle ("ws2_32.dll"); + + if (h) + { + getaddrinfo_ptr = (getaddrinfo_func) GetProcAddress (h, "getaddrinfo"); + freeaddrinfo_ptr = (freeaddrinfo_func) GetProcAddress (h, "freeaddrinfo"); + getnameinfo_ptr = (getnameinfo_func) GetProcAddress (h, "getnameinfo"); + } + + /* If either is missing, something is odd. */ + if (!getaddrinfo_ptr || !freeaddrinfo_ptr || !getnameinfo_ptr) + { + getaddrinfo_ptr = NULL; + freeaddrinfo_ptr = NULL; + getnameinfo_ptr = NULL; + return 0; + } + + return 1; +} +#endif + +static inline bool +validate_family (int family) +{ + /* FIXME: Support more families. */ +#if HAVE_IPV4 + if (family == PF_INET) + return true; +#endif +#if HAVE_IPV6 + if (family == PF_INET6) + return true; +#endif + if (family == PF_UNSPEC) + return true; + return false; +} + +/* Translate name of a service location and/or a service name to set of + socket addresses. */ +int +getaddrinfo (const char *restrict nodename, + const char *restrict servname, + const struct addrinfo *restrict hints, + struct addrinfo **restrict res) +{ + struct addrinfo *tmp; + int port = 0; + struct hostent *he; + void *storage; + size_t size; +#if HAVE_IPV6 + struct v6_pair { + struct addrinfo addrinfo; + struct sockaddr_in6 sockaddr_in6; + }; +#endif +#if HAVE_IPV4 + struct v4_pair { + struct addrinfo addrinfo; + struct sockaddr_in sockaddr_in; + }; +#endif + +#ifdef WIN32_NATIVE + if (use_win32_p ()) + return getaddrinfo_ptr (nodename, servname, hints, res); +#endif + + if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE))) + /* FIXME: Support more flags. */ + return EAI_BADFLAGS; + + if (hints && !validate_family (hints->ai_family)) + return EAI_FAMILY; + + if (hints && + hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM) + /* FIXME: Support other socktype. */ + return EAI_SOCKTYPE; /* FIXME: Better return code? */ + + if (!nodename) + { + if (!(hints->ai_flags & AI_PASSIVE)) + return EAI_NONAME; + +#ifdef HAVE_IPV6 + nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; +#else + nodename = "0.0.0.0"; +#endif + } + + if (servname) + { + struct servent *se = NULL; + const char *proto = + (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; + + if (!(hints->ai_flags & AI_NUMERICSERV)) + /* FIXME: Use getservbyname_r if available. */ + se = getservbyname (servname, proto); + + if (!se) + { + char *c; + if (!(*servname >= '0' && *servname <= '9')) + return EAI_NONAME; + port = strtoul (servname, &c, 10); + if (*c || port > 0xffff) + return EAI_NONAME; + port = htons (port); + } + else + port = se->s_port; + } + + /* FIXME: Use gethostbyname_r if available. */ + he = gethostbyname (nodename); + if (!he || he->h_addr_list[0] == NULL) + return EAI_NONAME; + + switch (he->h_addrtype) + { +#if HAVE_IPV6 + case PF_INET6: + size = sizeof (struct v6_pair); + break; +#endif + +#if HAVE_IPV4 + case PF_INET: + size = sizeof (struct v4_pair); + break; +#endif + + default: + return EAI_NODATA; + } + + storage = calloc (1, size); + if (!storage) + return EAI_MEMORY; + + switch (he->h_addrtype) + { +#if HAVE_IPV6 + case PF_INET6: + { + struct v6_pair *p = storage; + struct sockaddr_in6 *sinp = &p->sockaddr_in6; + tmp = &p->addrinfo; + + if (port) + sinp->sin6_port = port; + + if (he->h_length != sizeof (sinp->sin6_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } + + memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); + + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; + } + break; +#endif + +#if HAVE_IPV4 + case PF_INET: + { + struct v4_pair *p = storage; + struct sockaddr_in *sinp = &p->sockaddr_in; + tmp = &p->addrinfo; + + if (port) + sinp->sin_port = port; + + if (he->h_length != sizeof (sinp->sin_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } + + memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); + + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; + } + break; +#endif + + default: + free (storage); + return EAI_NODATA; + } + + if (hints && hints->ai_flags & AI_CANONNAME) + { + const char *cn; + if (he->h_name) + cn = he->h_name; + else + cn = nodename; + + tmp->ai_canonname = strdup (cn); + if (!tmp->ai_canonname) + { + free (storage); + return EAI_MEMORY; + } + } + + tmp->ai_protocol = (hints) ? hints->ai_protocol : 0; + tmp->ai_socktype = (hints) ? hints->ai_socktype : 0; + tmp->ai_addr->sa_family = he->h_addrtype; + tmp->ai_family = he->h_addrtype; + + /* FIXME: If more than one address, create linked list of addrinfo's. */ + + *res = tmp; + + return 0; +} + +/* Free `addrinfo' structure AI including associated storage. */ +void +freeaddrinfo (struct addrinfo *ai) +{ +#ifdef WIN32_NATIVE + if (use_win32_p ()) + { + freeaddrinfo_ptr (ai); + return; + } +#endif + + while (ai) + { + struct addrinfo *cur; + + cur = ai; + ai = ai->ai_next; + + if (cur->ai_canonname) free (cur->ai_canonname); + free (cur); + } +} + +int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, + char *restrict node, socklen_t nodelen, + char *restrict service, socklen_t servicelen, + int flags) +{ +#ifdef WIN32_NATIVE + if (use_win32_p ()) + return getnameinfo_ptr (sa, salen, node, nodelen, + service, servicelen, flags); +#endif + + /* FIXME: Support other flags. */ + if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) || + (service && servicelen > 0 && !(flags & NI_NUMERICHOST)) || + (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV))) + return EAI_BADFLAGS; + + if (sa == NULL || salen < sizeof (sa->sa_family)) + return EAI_FAMILY; + + switch (sa->sa_family) + { +#if HAVE_IPV4 + case AF_INET: + if (salen < sizeof (struct sockaddr_in)) + return EAI_FAMILY; + break; +#endif +#if HAVE_IPV6 + case AF_INET6: + if (salen < sizeof (struct sockaddr_in6)) + return EAI_FAMILY; + break; +#endif + default: + return EAI_FAMILY; + } + + if (node && nodelen > 0 && flags & NI_NUMERICHOST) + { + switch (sa->sa_family) + { +#if HAVE_IPV4 + case AF_INET: + if (!inet_ntop (AF_INET, + &(((const struct sockaddr_in *) sa)->sin_addr), + node, nodelen)) + return EAI_SYSTEM; + break; +#endif + +#if HAVE_IPV6 + case AF_INET6: + if (!inet_ntop (AF_INET6, + &(((const struct sockaddr_in6 *) sa)->sin6_addr), + node, nodelen)) + return EAI_SYSTEM; + break; +#endif + + default: + return EAI_FAMILY; + } + } + + if (service && servicelen > 0 && flags & NI_NUMERICSERV) + switch (sa->sa_family) + { +#if HAVE_IPV4 + case AF_INET: +#endif +#if HAVE_IPV6 + case AF_INET6: +#endif + { + unsigned short int port + = ntohs (((const struct sockaddr_in *) sa)->sin_port); + if (servicelen <= snprintf (service, servicelen, "%u", port)) + return EAI_OVERFLOW; + } + break; + } + + return 0; +} 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 @@ +/* Get address information. + Copyright (C) 1996-2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + Contributed by Simon Josefsson . + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef GETADDRINFO_H +#define GETADDRINFO_H + +/* sys/socket.h in i386-unknown-freebsd4.10 and + powerpc-apple-darwin5.5 require sys/types.h, so include it first. + Then we'll also get 'socklen_t' and 'struct sockaddr' which are + used below. */ +#include +/* Get all getaddrinfo related declarations, if available. */ +#include +#ifdef HAVE_NETDB_H +# include +#endif + +#ifndef HAVE_STRUCT_ADDRINFO + +/* Structure to contain information about address of a service provider. */ +struct addrinfo +{ + int ai_flags; /* Input flags. */ + int ai_family; /* Protocol family for socket. */ + int ai_socktype; /* Socket type. */ + int ai_protocol; /* Protocol for socket. */ + socklen_t ai_addrlen; /* Length of socket address. */ + struct sockaddr *ai_addr; /* Socket address for socket. */ + char *ai_canonname; /* Canonical name for service location. */ + struct addrinfo *ai_next; /* Pointer to next in list. */ +}; +#endif + +/* Possible values for `ai_flags' field in `addrinfo' structure. */ +#ifndef AI_PASSIVE +# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ +#endif +#ifndef AI_CANONNAME +# define AI_CANONNAME 0x0002 /* Request for canonical name. */ +#endif +#ifndef AI_NUMERICSERV +# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ +#endif + +#if 0 +/* The commented out definitions below are not yet implemented in the + GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact, + cause conflicts on systems with a getaddrinfo() function which does not + define them. + + If they are restored, be sure to protect the definitions with #ifndef. */ +#define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ +#define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ +#define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ +#define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose + returned address type.. */ +#endif /* 0 */ + +/* Error values for `getaddrinfo' function. */ +#ifndef EAI_BADFLAGS +# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ +# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ +# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ +# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ +# define EAI_NODATA -5 /* No address associated with NAME. */ +# define EAI_FAMILY -6 /* `ai_family' not supported. */ +# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ +# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ +# define EAI_MEMORY -10 /* Memory allocation failure. */ +#endif +#ifndef EAI_OVERFLOW +/* Not defined on mingw32. */ +# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ +#endif +#ifndef EAI_ADDRFAMILY +/* Not defined on mingw32. */ +# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ +#endif +#ifndef EAI_SYSTEM +/* Not defined on mingw32. */ +# define EAI_SYSTEM -11 /* System error returned in `errno'. */ +#endif + +#ifdef __USE_GNU +# ifndef EAI_INPROGRESS +# define EAI_INPROGRESS -100 /* Processing request in progress. */ +# define EAI_CANCELED -101 /* Request canceled. */ +# define EAI_NOTCANCELED -102 /* Request not canceled. */ +# define EAI_ALLDONE -103 /* All requests done. */ +# define EAI_INTR -104 /* Interrupted by a signal. */ +# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ +# endif +#endif + +#if !HAVE_DECL_GETADDRINFO +/* Translate name of a service location and/or a service name to set of + socket addresses. + For more details, see the POSIX:2001 specification + . */ +extern int getaddrinfo (const char *restrict nodename, + const char *restrict servname, + const struct addrinfo *restrict hints, + struct addrinfo **restrict res); +#endif + +#if !HAVE_DECL_FREEADDRINFO +/* Free `addrinfo' structure AI including associated storage. + For more details, see the POSIX:2001 specification + . */ +extern void freeaddrinfo (struct addrinfo *ai); +#endif + +#if !HAVE_DECL_GAI_STRERROR +/* Convert error return from getaddrinfo() to a string. + For more details, see the POSIX:2001 specification + . */ +extern const char *gai_strerror (int ecode); +#endif + +#if !HAVE_DECL_GETNAMEINFO +/* Convert socket address to printable node and service names. + For more details, see the POSIX:2001 specification + . */ +extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, + char *restrict node, socklen_t nodelen, + char *restrict service, socklen_t servicelen, + int flags); + +#endif + +/* Possible flags for getnameinfo. */ +#ifndef NI_NUMERICHOST +# define NI_NUMERICHOST 1 +#endif +#ifndef NI_NUMERICSERV +# define NI_NUMERICSERV 2 +#endif + +#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 @@ +/* gethostname emulation for SysV and POSIX.1. + + Copyright (C) 1992, 2003, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* David MacKenzie */ + +#include + +#ifdef HAVE_UNAME +# include +#endif + +/* Put up to LEN chars of the host name into NAME. + Null terminate it if the name is shorter than LEN. + Return 0 if ok, -1 if error. */ + +#include + +int +gethostname (char *name, size_t len) +{ +#ifdef HAVE_UNAME + struct utsname uts; + + if (uname (&uts) == -1) + return -1; + if (len > sizeof (uts.nodename)) + { + /* More space than we need is available. */ + name[sizeof (uts.nodename)] = '\0'; + len = sizeof (uts.nodename); + } + strncpy (name, uts.nodename, len); +#else + strcpy (name, ""); /* Hardcode your system name if you want. */ +#endif + return 0; +} diff --git a/lib/getloadavg.c b/gl/getloadavg.c similarity index 97% rename from lib/getloadavg.c rename to gl/getloadavg.c index 2a50131..cfa6273 100644 --- a/lib/getloadavg.c +++ b/gl/getloadavg.c @@ -1,7 +1,8 @@ /* Get the system load averages. Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, - 1995, 1997, 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. + 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006 Free Software + Foundation, Inc. NOTE: The canonical source of this file is maintained with gnulib. Bugs can be reported to bug-gnulib@gnu.org. @@ -80,13 +81,15 @@ We also #define LDAV_PRIVILEGED if a program will require special installation to be able to call getloadavg. */ -/* This should always be first. */ -#ifdef HAVE_CONFIG_H +/* "configure" defines CONFIGURING_GETLOADAVG to sidestep problems + with partially-configured source directories. */ + +#ifndef CONFIGURING_GETLOADAVG # include +# include #endif #include -#include #include #include @@ -279,7 +282,7 @@ # endif -# ifndef FSCALE +# ifndef FSCALE /* SunOS and some others define FSCALE in sys/param.h. */ @@ -358,7 +361,7 @@ # ifdef LOAD_AVE_TYPE -# ifndef VMS +# ifndef __VMS # ifndef __linux__ # ifndef NLIST_STRUCT # include @@ -385,7 +388,7 @@ # endif /* LDAV_SYMBOL */ # endif /* __linux__ */ -# else /* VMS */ +# else /* __VMS */ # ifndef eunice # include @@ -393,7 +396,7 @@ # else /* eunice */ # include # endif /* eunice */ -# endif /* VMS */ +# endif /* __VMS */ # ifndef LDAV_CVT # define LDAV_CVT(n) ((double) (n)) @@ -473,9 +476,9 @@ static bool getloadavg_initialized; /* Offset in kmem to seek to read load average, or 0 means invalid. */ static long offset; -# if !defined (VMS) && !defined (sgi) && !defined (__linux__) +# if ! defined __VMS && ! defined sgi && ! defined __linux__ static struct nlist nl[2]; -# endif /* Not VMS or sgi */ +# endif # ifdef SUNOS_5 static kvm_t *kd; @@ -813,7 +816,7 @@ getloadavg (double loadavg[], int nelem) : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); # endif /* OSF_ALPHA */ -# if !defined (LDAV_DONE) && defined (VMS) +# if ! defined LDAV_DONE && defined __VMS /* VMS specific code -- read from the Load Ave driver. */ LOAD_AVE_TYPE load_ave[3]; @@ -851,9 +854,9 @@ getloadavg (double loadavg[], int nelem) if (!getloadavg_initialized) return -1; -# endif /* VMS */ +# endif /* ! defined LDAV_DONE && defined __VMS */ -# if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) && !defined (VMS) +# if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS /* UNIX-specific code -- read the average from /dev/kmem. */ @@ -953,7 +956,7 @@ getloadavg (double loadavg[], int nelem) if (offset == 0 || !getloadavg_initialized) return -1; -# endif /* LOAD_AVE_TYPE and not VMS */ +# endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */ # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ if (nelem > 0) diff --git a/lib/getopt.c b/gl/getopt.c similarity index 94% rename from lib/getopt.c rename to gl/getopt.c index bcb81c8..3580ad8 100644 --- a/lib/getopt.c +++ b/gl/getopt.c @@ -2,7 +2,7 @@ NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! - Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004 + Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -20,30 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* This tells Alpha OSF/1 not to define a getopt prototype in . - Ditto for AIX 3.2 and . */ -#ifndef _NO_PROTO -# define _NO_PROTO -#endif - -#ifdef HAVE_CONFIG_H +#ifndef _LIBC # include #endif -#include - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -# include -# include -#endif /* GNU C library. */ +#include "getopt.h" +#include +#include #include +#include -#ifdef VMS +#ifdef __VMS # include #endif @@ -76,7 +64,6 @@ GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ -#include "getopt.h" #include "getopt_int.h" /* For communication from `getopt' to the caller. @@ -118,16 +105,9 @@ int optopt = '?'; static struct _getopt_data getopt_data; -#ifndef __GNU_LIBRARY__ - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -#ifndef getenv +#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV extern char *getenv (); #endif - -#endif /* not __GNU_LIBRARY__ */ #ifdef _LIBC /* Stored original parameters. @@ -556,10 +536,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -634,10 +611,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -674,10 +648,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -751,10 +722,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -817,10 +785,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -868,10 +833,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -940,10 +902,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -985,10 +944,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -1027,10 +983,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); @@ -1101,10 +1054,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int old_flags2 = ((_IO_FILE *) stderr)->_flags2; ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s", buf); - else - fputs (buf, stderr); + __fxprintf (NULL, "%s", buf); ((_IO_FILE *) stderr)->_flags2 = old_flags2; _IO_funlockfile (stderr); diff --git a/lib/getopt1.c b/gl/getopt1.c similarity index 97% rename from lib/getopt1.c rename to gl/getopt1.c index 25d7926..cc0746e 100644 --- a/lib/getopt1.c +++ b/gl/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004 + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -17,13 +17,10 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif - #ifdef _LIBC # include #else +# include # include "getopt.h" #endif #include "getopt_int.h" diff --git a/lib/getopt_.h b/gl/getopt_.h similarity index 96% rename from lib/getopt_.h rename to gl/getopt_.h index 3c406e5..27fce3d 100644 --- a/lib/getopt_.h +++ b/gl/getopt_.h @@ -1,5 +1,5 @@ /* Declarations for getopt. - Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005 + Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -196,9 +196,10 @@ struct option scanning, explicitly telling `getopt' that there are no more options. - If OPTS begins with `--', then non-option arguments are treated as - arguments to the option '\0'. This behavior is specific to the GNU - `getopt'. */ + If OPTS begins with `-', then non-option arguments are treated as + arguments to the option '\1'. This behavior is specific to the GNU + `getopt'. If OPTS begins with `+', or POSIXLY_CORRECT is set in + the environment, then do not permute arguments. */ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) __THROW; diff --git a/lib/getopt_int.h b/gl/getopt_int.h similarity index 100% rename from lib/getopt_int.h rename to 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 @@ +/* Convenience header for conditional use of GNU . + Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include + +/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by + the gettext() and ngettext() macros. This is an alternative to calling + textdomain(), and is useful for libraries. */ +# ifdef DEFAULT_TEXT_DOMAIN +# undef gettext +# define gettext(Msgid) \ + dgettext (DEFAULT_TEXT_DOMAIN, Msgid) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) +# endif + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of a NOP. We don't include + as well because people using "gettext.h" will not include , + and also including would fail on SunOS 4, whereas + is OK. */ +#if defined(__sun) +# include +#endif + +/* Many header files from the libstdc++ coming with g++ 3.3 or newer include + , which chokes if dcgettext is defined as a macro. So include + it now, to make later inclusions of a NOP. */ +#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) +# include +# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H +# include +# endif +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# define gettext(Msgid) ((const char *) (Msgid)) +# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) +# define dcgettext(Domainname, Msgid, Category) \ + ((void) (Category), dgettext (Domainname, Msgid)) +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 \ + ? ((void) (Msgid2), (const char *) (Msgid1)) \ + : ((void) (Msgid1), (const char *) (Msgid2))) +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) +# define textdomain(Domainname) ((const char *) (Domainname)) +# define bindtextdomain(Domainname, Dirname) \ + ((void) (Domainname), (const char *) (Dirname)) +# define bind_textdomain_codeset(Domainname, Codeset) \ + ((void) (Domainname), (const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +/* The separator between msgctxt and msgid in a .mo file. */ +#define GETTEXT_CONTEXT_GLUE "\004" + +/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a + MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be + short and rarely need to change. + The letter 'p' stands for 'particular' or 'special'. */ +#ifdef DEFAULT_TEXT_DOMAIN +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#else +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#endif +#define dpgettext(Domainname, Msgctxt, Msgid) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) +#ifdef DEFAULT_TEXT_DOMAIN +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#else +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#endif +#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +pgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + int category) +{ + const char *translation = dcgettext (domain, msg_ctxt_id, category); + if (translation == msg_ctxt_id) + return msgid; + else + return translation; +} + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +npgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + const char *translation = + dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); + if (translation == msg_ctxt_id || translation == msgid_plural) + return (n == 1 ? msgid : msgid_plural); + else + return translation; +} + +/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID + can be arbitrary expressions. But for string literals these macros are + less efficient than those above. */ + +#include + +#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ + (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ + /* || __STDC_VERSION__ >= 199901L */ ) + +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +#include +#endif + +#define pgettext_expr(Msgctxt, Msgid) \ + dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ + dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcgettext (domain, msg_ctxt_id, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (translation != msg_ctxt_id) + return translation; + } + return msgid; +} + +#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcnpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (!(translation == msg_ctxt_id || translation == msgid_plural)) + return translation; + } + return (n == 1 ? msgid : msgid_plural); +} + +#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 @@ +/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form + + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* + * Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +/* Specification. */ +#include "inet_ntop.h" + +#include +#include +#include + +#ifndef EAFNOSUPPORT +# define EAFNOSUPPORT EINVAL +#endif + +#define NS_IN6ADDRSZ 16 +#define NS_INT16SZ 2 + +/* + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ +typedef int verify_int_size[2 * sizeof (int) - 7]; + +static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); +#if HAVE_IPV6 +static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); +#endif + + +/* char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * author: + * Paul Vixie, 1996. + */ +const char * +inet_ntop (int af, const void *restrict src, + char *restrict dst, socklen_t cnt) +{ + switch (af) + { +#if HAVE_IPV4 + case AF_INET: + return (inet_ntop4 (src, dst, cnt)); +#endif + +#if HAVE_IPV6 + case AF_INET6: + return (inet_ntop6 (src, dst, cnt)); +#endif + + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a u_char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) +{ + char tmp[sizeof "255.255.255.255"]; + int len; + + len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); + if (len < 0) + return NULL; + + if (len > size) + { + errno = ENOSPC; + return NULL; + } + + return strcpy (dst, tmp); +} + +#if HAVE_IPV6 + +/* const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + struct + { + int base, len; + } best, cur; + unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset (words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i += 2) + words[i / 2] = (src[i] << 8) | src[i + 1]; + best.base = -1; + cur.base = -1; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + if (words[i] == 0) + { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } + else + { + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && i < (best.base + best.len)) + { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen (tp); + break; + } + { + int len = sprintf (tp, "%x", words[i]); + if (len < 0) + return NULL; + tp += len; + } + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((socklen_t) (tp - tmp) > size) + { + errno = ENOSPC; + return NULL; + } + + return strcpy (dst, tmp); +} + +#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 @@ +/* Convert internet address from internal to printable, presentable format. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include +#include +#include +#include + +/* Converts an internet address from internal format to a printable, + presentable format. + AF is an internet address family, such as AF_INET or AF_INET6. + SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr' + (for AF_INET6). + DST points to a buffer having room for CNT bytes. + The printable representation of the address (in numeric form, not + surrounded by [...], no reverse DNS is done) is placed in DST, and + DST is returned. If an error occurs, the return value is NULL and + errno is set. If CNT bytes are not sufficient to hold the result, + the return value is NULL and errno is set to ENOSPC. A good value + for CNT is 46. + + For more details, see the POSIX:2001 specification + . */ + +#if !HAVE_DECL_INET_NTOP +extern const char *inet_ntop (int af, const void *restrict src, + char *restrict dst, socklen_t cnt); +#endif diff --git a/lib/intprops.h b/gl/intprops.h similarity index 78% rename from lib/intprops.h rename to gl/intprops.h index 65280b1..34f971c 100644 --- a/lib/intprops.h +++ b/gl/intprops.h @@ -53,12 +53,25 @@ ? (t) -1 \ : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) +/* Return zero if T can be determined to be an unsigned type. + Otherwise, return 1. + When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a + tighter bound. Otherwise, it overestimates the true bound by one byte + when applied to unsigned types of size 2, 4, 16, ... bytes. + The symbol signed_type_or_expr__ is private to this header file. */ +#if __GNUC__ >= 2 +# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define signed_type_or_expr__(t) 1 +#endif + /* Bound on length of the string representing an integer type or expression T. - Subtract 1 for the sign bit if t is signed; log10 (2.0) < 146/485; + Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485; add 1 for integer division truncation; add 1 more for a minus sign if needed. */ #define INT_STRLEN_BOUND(t) \ - ((sizeof (t) * CHAR_BIT - 1) * 146 / 485 + 2) + ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \ + + signed_type_or_expr__ (t) + 1) /* Bound on buffer size needed to represent an integer type or expression T, 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 @@ +# absolute-header.m4 serial 6 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Derek Price. + +# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...) +# --------------------------------------- +# Find the absolute name of a header file, assuming the header exists. +# If the header were sys/inttypes.h, this macro would define +# ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h +# in config.h +# (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"'). +# The three "///" are to pacify Sun C 5.8, which otherwise would say +# "warning: #include of /usr/include/... may be non-portable". +# Use `""', not `<>', so that the /// cannot be confused with a C99 comment. +AC_DEFUN([gl_ABSOLUTE_HEADER], +[AC_LANG_PREPROC_REQUIRE()dnl +AC_FOREACH([gl_HEADER_NAME], [$1], + [AS_VAR_PUSHDEF([gl_absolute_header], + [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl + AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], + m4_quote(m4_defn([gl_absolute_header])), + [AS_VAR_PUSHDEF([ac_header_exists], + [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl + AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl + if test AS_VAR_GET(ac_header_exists) = yes; then + AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])]) +dnl eval is necessary to expand ac_cpp. +dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. + AS_VAR_SET(gl_absolute_header, +[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | +sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#;s#^/[^/]#//&#;p;q;}'`]) + fi + AS_VAR_POPDEF([ac_header_exists])dnl + ])dnl + AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))), + ["AS_VAR_GET(gl_absolute_header)"], + [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.]) + AS_VAR_POPDEF([gl_absolute_header])dnl +])dnl +])# gl_ABSOLUTE_HEADER diff --git a/m4/alloca.m4 b/gl/m4/alloca.m4 similarity index 55% rename from m4/alloca.m4 rename to gl/m4/alloca.m4 index a9e3f45..eb62e0e 100644 --- a/m4/alloca.m4 +++ b/gl/m4/alloca.m4 @@ -1,5 +1,5 @@ -# alloca.m4 serial 5 -dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +# alloca.m4 serial 7 +dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -17,16 +17,24 @@ AC_DEFUN([gl_FUNC_ALLOCA], # Define an additional variable used in the Makefile substitution. if test $ac_cv_working_alloca_h = yes; then - AC_EGREP_CPP([Need own alloca], [ + AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ + AC_EGREP_CPP([Need own alloca], [ #if defined __GNUC__ || defined _AIX || defined _MSC_VER - Need own alloca + Need own alloca #endif - ], - [AC_DEFINE(HAVE_ALLOCA, 1, - [Define to 1 if you have `alloca' after including , - a header that may be supplied by this distribution.]) - ALLOCA_H=alloca.h], - [ALLOCA_H=]) + ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) + ]) + if test $gl_cv_rpl_alloca = yes; then + dnl OK, alloca can be implemented through a compiler built-in. + AC_DEFINE([HAVE_ALLOCA], 1, + [Define to 1 if you have 'alloca' after including , + a header that may be supplied by this distribution.]) + ALLOCA_H=alloca.h + else + dnl alloca exists as a library function, i.e. it is slow and probably + dnl a memory leak. Don't define HAVE_ALLOCA in this case. + ALLOCA_H= + fi else ALLOCA_H=alloca.h 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 @@ +# arpa_inet_h.m4 serial 1 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Simon Josefsson + +AC_DEFUN([gl_HEADER_ARPA_INET], +[ + AC_CHECK_HEADERS_ONCE([arpa/inet.h]) + if test $ac_cv_header_arpa_inet_h = yes; then + ARPA_INET_H='' + else + ARPA_INET_H='arpa/inet.h' + fi + AC_SUBST(ARPA_INET_H) +]) diff --git a/m4/c-strtod.m4 b/gl/m4/c-strtod.m4 similarity index 86% rename from m4/c-strtod.m4 rename to gl/m4/c-strtod.m4 index ffeb458..7f206c7 100644 --- a/m4/c-strtod.m4 +++ b/gl/m4/c-strtod.m4 @@ -1,6 +1,6 @@ -# c-strtod.m4 serial 6 +# c-strtod.m4 serial 9 -# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -11,7 +11,7 @@ AC_DEFUN([gl_C99_STRTOLD], [ AC_CACHE_CHECK([whether strtold conforms to C99], [gl_cv_func_c99_strtold], - [AC_COMPILE_IFELSE( + [AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[/* On HP-UX before 11.23, strtold returns a struct instead of long double. Reject implementations like that, by requiring @@ -35,7 +35,6 @@ AC_DEFUN([gl_C99_STRTOLD], AC_DEFUN([gl_C_STRTOD], [ - AC_LIBSOURCES([c-strtod.c, c-strtod.h]) AC_LIBOBJ([c-strtod]) dnl Prerequisites of lib/c-strtod.c. @@ -45,11 +44,10 @@ AC_DEFUN([gl_C_STRTOD], AC_DEFUN([gl_C_STRTOLD], [ - AC_LIBSOURCES([c-strtold.c, c-strtod.h]) AC_LIBOBJ([c-strtold]) dnl Prerequisites of lib/c-strtold.c. - AC_REQUIRE([gl_C_STRTOD]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([gl_C99_STRTOLD]) : ]) 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 @@ +#serial 6 +dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_CLOEXEC], +[ + AC_LIBOBJ([cloexec]) +]) diff --git a/m4/codeset.m4 b/gl/m4/codeset.m4 similarity index 79% rename from m4/codeset.m4 rename to gl/m4/codeset.m4 index a6e67ec..223955b 100644 --- a/m4/codeset.m4 +++ b/gl/m4/codeset.m4 @@ -1,5 +1,5 @@ -# codeset.m4 serial AM1 (gettext-0.10.40) -dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. +# codeset.m4 serial 2 (gettext-0.16) +dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -10,7 +10,7 @@ AC_DEFUN([AM_LANGINFO_CODESET], [ AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, [AC_TRY_LINK([#include ], - [char* cs = nl_langinfo(CODESET);], + [char* cs = nl_langinfo(CODESET); return !cs;], am_cv_langinfo_codeset=yes, am_cv_langinfo_codeset=no) ]) 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 @@ +#serial 7 -*- autoconf -*- +dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_DIRNAME], +[ + AC_LIBOBJ([basename]) + AC_LIBOBJ([dirname]) + AC_LIBOBJ([stripslash]) + + dnl Prerequisites of lib/dirname.h. + AC_REQUIRE([gl_AC_DOS]) + AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) + + dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c. +]) diff --git a/m4/dos.m4 b/gl/m4/dos.m4 similarity index 57% rename from m4/dos.m4 rename to gl/m4/dos.m4 index 0713cf1..dd59571 100644 --- a/m4/dos.m4 +++ b/gl/m4/dos.m4 @@ -1,9 +1,9 @@ -#serial 9 +#serial 10 -*- autoconf -*- # Define some macros required for proper operation of code in lib/*.c # on MSDOS/Windows systems. -# Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. +# Copyright (C) 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,30 +14,38 @@ AC_DEFUN([gl_AC_DOS], [ AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], [ - AC_TRY_COMPILE([], - [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ + AC_TRY_COMPILE([], + [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ neither MSDOS nor Windows #endif], - [ac_cv_win_or_dos=yes], - [ac_cv_win_or_dos=no]) + [ac_cv_win_or_dos=yes], + [ac_cv_win_or_dos=no]) ]) if test x"$ac_cv_win_or_dos" = xyes; then ac_fs_accepts_drive_letter_prefix=1 ac_fs_backslash_is_file_name_separator=1 + AC_CACHE_CHECK([whether drive letter can start relative path], + [ac_cv_drive_letter_can_be_relative], + [ + AC_TRY_COMPILE([], + [#if defined __CYGWIN__ +drive letters are always absolute +#endif], + [ac_cv_drive_letter_can_be_relative=yes], + [ac_cv_drive_letter_can_be_relative=no]) + ]) + if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then + ac_fs_drive_letter_can_be_relative=1 + else + ac_fs_drive_letter_can_be_relative=0 + fi else ac_fs_accepts_drive_letter_prefix=0 ac_fs_backslash_is_file_name_separator=0 + ac_fs_drive_letter_can_be_relative=0 fi - AH_VERBATIM(FILE_SYSTEM_PREFIX_LEN, - [#if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX -# define FILE_SYSTEM_PREFIX_LEN(Filename) \ - ((Filename)[0] && (Filename)[1] == ':' ? 2 : 0) -#else -# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 -#endif]) - AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], $ac_fs_accepts_drive_letter_prefix, [Define on systems for which file names may have a so-called @@ -55,4 +63,9 @@ neither MSDOS nor Windows $ac_fs_backslash_is_file_name_separator, [Define if the backslash character may also serve as a file name component separator.]) + + AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE], + $ac_fs_drive_letter_can_be_relative, + [Define if a drive letter prefix denotes a relative path if it is + not followed by a file name component separator.]) ]) diff --git a/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 @@ +# double-slash-root.m4 serial 2 -*- Autoconf -*- +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_DOUBLE_SLASH_ROOT], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], + [ if test x"$cross_compiling" = xyes ; then + # When cross-compiling, there is no way to tell whether // is special + # short of a list of hosts. However, the only known hosts to date + # that have a distinct // are Apollo DomainOS (too old to port to), + # Cygwin, and z/OS. If anyone knows of another system for which // has + # special semantics and is distinct from /, please report it to + # . + case $host in + *-cygwin | i370-ibm-openedition) + gl_cv_double_slash_root=yes ;; + *) + # Be optimistic and assume that / and // are the same when we + # don't know. + gl_cv_double_slash_root='unknown, assuming no' ;; + esac + else + set x `ls -di / //` + if test $[2] = $[4] && wc //dev/null >/dev/null 2>&1; then + gl_cv_double_slash_root=no + else + gl_cv_double_slash_root=yes + fi + fi]) + if test "$gl_cv_double_slash_root" = yes; then + AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], 1, + [Define to 1 if // is a file system root distinct from /.]) + fi +]) 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 @@ +# eoverflow.m4 serial 2 +dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +# The EOVERFLOW errno value ought to be defined in , according to +# POSIX. But some systems (like AIX 3) don't define it, and some systems +# (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined. + +# Define EOVERFLOW as a C macro and as a substituted macro in such a way that +# 1. on all systems, after inclusion of , EOVERFLOW is usable, +# 2. on systems where EOVERFLOW is defined elsewhere, we use the same numeric +# value. + +AC_DEFUN([gl_EOVERFLOW], +[ + AC_REQUIRE([AC_PROG_CC])dnl + + AC_CACHE_CHECK([for EOVERFLOW], ac_cv_decl_EOVERFLOW, [ + AC_EGREP_CPP(yes,[ +#include +#ifdef EOVERFLOW +yes +#endif + ], have_eoverflow=1) + if test -n "$have_eoverflow"; then + dnl EOVERFLOW exists in . Don't need to define EOVERFLOW ourselves. + ac_cv_decl_EOVERFLOW=yes + else + AC_EGREP_CPP(yes,[ +#define _XOPEN_SOURCE_EXTENDED 1 +#include +#ifdef EOVERFLOW +yes +#endif + ], have_eoverflow=1) + if test -n "$have_eoverflow"; then + dnl EOVERFLOW exists but is hidden. + dnl Define it to the same value. + AC_COMPUTE_INT([ac_cv_decl_EOVERFLOW], [EOVERFLOW], [ +#define _XOPEN_SOURCE_EXTENDED 1 +#include +/* The following two lines are a workaround against an autoconf-2.52 bug. */ +#include +#include +]) + else + dnl EOVERFLOW isn't defined by the system. Define EOVERFLOW ourselves, but + dnl don't define it as EINVAL, because snprintf() callers want to + dnl distinguish EINVAL and EOVERFLOW. + ac_cv_decl_EOVERFLOW=E2BIG + fi + fi + ]) + if test "$ac_cv_decl_EOVERFLOW" != yes; then + AC_DEFINE_UNQUOTED([EOVERFLOW], [$ac_cv_decl_EOVERFLOW], + [Define as good substitute value for EOVERFLOW.]) + EOVERFLOW="$ac_cv_decl_EOVERFLOW" + AC_SUBST(EOVERFLOW) + fi +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) diff --git a/m4/error.m4 b/gl/m4/error.m4 similarity index 100% rename from m4/error.m4 rename to gl/m4/error.m4 diff --git a/m4/exitfail.m4 b/gl/m4/exitfail.m4 similarity index 69% rename from m4/exitfail.m4 rename to gl/m4/exitfail.m4 index 5523676..b7a691e 100644 --- a/m4/exitfail.m4 +++ b/gl/m4/exitfail.m4 @@ -1,12 +1,11 @@ -# exitfail.m4 serial 5 -dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +# exitfail.m4 serial 6 +dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_EXITFAIL], [ - AC_LIBSOURCES([exitfail.c, exitfail.h]) AC_LIBOBJ([exitfail]) 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 @@ +# serial 4 -*- Autoconf -*- +# Enable extensions on systems that normally disable them. + +# Copyright (C) 2003, 2006 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS +# Autoconf. Perhaps we can remove this once we can assume Autoconf +# 2.61 or later everywhere, but since CVS Autoconf mutates rapidly +# enough in this area it's likely we'll need to redefine +# AC_USE_SYSTEM_EXTENSIONS for quite some time. + +# AC_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], +[ + AC_BEFORE([$0], [AC_COMPILE_IFELSE]) + AC_BEFORE([$0], [AC_RUN_IFELSE]) + + AC_REQUIRE([AC_GNU_SOURCE]) + AC_REQUIRE([AC_AIX]) + AC_REQUIRE([AC_MINIX]) + + AH_VERBATIM([__EXTENSIONS__], +[/* Enable extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif]) + AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], + [ac_cv_safe_to_define___extensions__], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([ +# define __EXTENSIONS__ 1 + AC_INCLUDES_DEFAULT])], + [ac_cv_safe_to_define___extensions__=yes], + [ac_cv_safe_to_define___extensions__=no])]) + test $ac_cv_safe_to_define___extensions__ = yes && + AC_DEFINE([__EXTENSIONS__]) + AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) + AC_DEFINE([_TANDEM_SOURCE]) +]) + +# gl_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], + [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])]) diff --git a/m4/fcntl-safer.m4 b/gl/m4/fcntl-safer.m4 similarity index 67% rename from m4/fcntl-safer.m4 rename to gl/m4/fcntl-safer.m4 index be210f9..3475b0a 100644 --- a/m4/fcntl-safer.m4 +++ b/gl/m4/fcntl-safer.m4 @@ -1,12 +1,11 @@ -#serial 2 -dnl Copyright (C) 2005 Free Software Foundation, Inc. +#serial 5 +dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FCNTL_SAFER], [ - AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h]) AC_LIBOBJ([open-safer]) AC_LIBOBJ([creat-safer]) ]) 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 @@ +#serial 6 + +dnl From Jim Meyering. +dnl +dnl See if struct statfs has the f_fstypename member. +dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME. +dnl + +# Copyright (C) 1998, 1999, 2001, 2004, 2006 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FSTYPENAME], +[ + AC_CHECK_MEMBERS([struct statfs.f_fstypename],,, + [ + #include + #include + #include + ]) +]) diff --git a/m4/fsusage.m4 b/gl/m4/fsusage.m4 similarity index 92% rename from m4/fsusage.m4 rename to gl/m4/fsusage.m4 index dd10f79..08bf06c 100644 --- a/m4/fsusage.m4 +++ b/gl/m4/fsusage.m4 @@ -1,7 +1,7 @@ -#serial 16 +#serial 22 # Obtaining file system usage information. -# Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005 Free Software +# Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software # Foundation, Inc. # # This file is free software; the Free Software Foundation @@ -12,8 +12,6 @@ AC_DEFUN([gl_FSUSAGE], [ - AC_LIBSOURCES([fsusage.c, fsusage.h]) - AC_CHECK_HEADERS_ONCE(sys/param.h) AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h) AC_CHECK_HEADERS(sys/mount.h, [], [], @@ -37,7 +35,7 @@ AC_DEFUN([gl_FSUSAGE], AC_DEFUN([gl_FILE_SYSTEM_USAGE], [ -echo "checking how to get file system space usage..." +AC_MSG_NOTICE([checking how to get file system space usage]) ac_fsusage_space=no # 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 # SVR4 AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs, [AC_TRY_LINK([#include -#ifdef __GLIBC__ +#if defined __GLIBC__ && !defined __BEOS__ Do not use statvfs on systems with GNU libc, because that function stats all preceding entries in /proc/mounts, and that makes df hang if even one of the corresponding file systems is hard-mounted, but not available. +statvfs in GNU libc on BeOS operates differently: it only makes a system +call. #endif #include ], [struct statvfs fsd; statvfs (0, &fsd);], @@ -74,11 +74,12 @@ if test $ac_fsusage_space = no; then #include #include #include + int main () { struct statfs fsd; fsd.f_fsize = 0; - exit (statfs (".", &fsd, sizeof (struct statfs))); + return statfs (".", &fsd, sizeof (struct statfs)) != 0; }], fu_cv_sys_stat_statfs3_osf1=yes, fu_cv_sys_stat_statfs3_osf1=no, @@ -106,11 +107,12 @@ member (AIX, 4.3BSD)]) #ifdef HAVE_SYS_VFS_H #include #endif + int main () { struct statfs fsd; fsd.f_bsize = 0; - exit (statfs (".", &fsd)); + return statfs (".", &fsd) != 0; }], fu_cv_sys_stat_statfs2_bsize=yes, fu_cv_sys_stat_statfs2_bsize=no, @@ -130,10 +132,11 @@ if test $ac_fsusage_space = no; then AC_CACHE_VAL(fu_cv_sys_stat_statfs4, [AC_TRY_RUN([#include #include + int main () { struct statfs fsd; - exit (statfs (".", &fsd, sizeof fsd, 0)); + return statfs (".", &fsd, sizeof fsd, 0) != 0; }], fu_cv_sys_stat_statfs4=yes, fu_cv_sys_stat_statfs4=no, @@ -158,11 +161,12 @@ member (4.4BSD and NetBSD)]) #ifdef HAVE_SYS_MOUNT_H #include #endif + int main () { struct statfs fsd; fsd.f_fsize = 0; - exit (statfs (".", &fsd)); + return statfs (".", &fsd) != 0; }], fu_cv_sys_stat_statfs2_fsize=yes, fu_cv_sys_stat_statfs2_fsize=no, @@ -190,12 +194,13 @@ if test $ac_fsusage_space = no; then #ifdef HAVE_SYS_FS_TYPES_H #include #endif + int main () { struct fs_data fsd; /* Ultrix's statfs returns 1 for success, 0 for not mounted, -1 for failure. */ - exit (statfs (".", &fsd) != 1); + return statfs (".", &fsd) != 1; }], fu_cv_sys_stat_fs_data=yes, fu_cv_sys_stat_fs_data=no, @@ -237,7 +242,8 @@ choke -- this is a workaround for a Sun-specific problem #endif #include #include ]], - [[struct statfs t; long c = *(t.f_spare);]])], + [[struct statfs t; long c = *(t.f_spare); + if (c) return 0;]])], [fu_cv_sys_truncating_statfs=yes], [fu_cv_sys_truncating_statfs=no])]) if test $fu_cv_sys_truncating_statfs = yes; then @@ -254,7 +260,6 @@ choke -- this is a workaround for a Sun-specific problem # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], [ - AC_REQUIRE([gl_AC_TYPE_UINTMAX_T]) - AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h) + AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h) gl_STATFS_TRUNCATES ]) 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 @@ +# getaddrinfo.m4 serial 11 +dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_GETADDRINFO], +[ + AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo]) + + AC_SEARCH_LIBS(getaddrinfo, [nsl socket]) + AC_CHECK_FUNCS(getaddrinfo,, [ + AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32, + gl_cv_w32_getaddrinfo, [ + gl_cv_w32_getaddrinfo=no + am_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_TRY_LINK([ +#ifdef HAVE_WS2TCPIP_H +#include +#endif +], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes) + LIBS="$am_save_LIBS"]) + if test "$gl_cv_w32_getaddrinfo" = "yes"; then + LIBS="$LIBS -lws2_32" + else + AC_LIBOBJ(getaddrinfo) + fi + ]) + + AC_REPLACE_FUNCS(gai_strerror) + gl_PREREQ_GETADDRINFO +]) + +# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c. +AC_DEFUN([gl_PREREQ_GETADDRINFO], [ + AC_SEARCH_LIBS(gethostbyname, [inet nsl]) + AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet]) + AC_CHECK_FUNCS(gethostbyname,, [ + AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32, + gl_cv_w32_gethostbyname, [ + gl_cv_w32_gethostbyname=no + am_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_TRY_LINK([ +#ifdef HAVE_WINSOCK2_H +#include +#endif +], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes) + LIBS="$am_save_LIBS"]) + if test "$gl_cv_w32_gethostbyname" = "yes"; then + LIBS="$LIBS -lws2_32" + fi + ]) + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_SOCKET_FAMILIES]) + AC_REQUIRE([gl_HEADER_SYS_SOCKET]) + AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([AC_GNU_SOURCE]) + AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h) + AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ + /* sys/types.h is not needed according to POSIX, but the + sys/socket.h in i386-unknown-freebsd4.10 and + powerpc-apple-darwin5.5 required it. */ +#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +]) + AC_CHECK_TYPES([struct addrinfo],,,[ +#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +]) +]) 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 @@ +# gethostname.m4 serial 2 +dnl Copyright (C) 2002 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_GETHOSTNAME], +[ + AC_REPLACE_FUNCS(gethostname) + if test $ac_cv_func_gethostname = no; then + gl_PREREQ_GETHOSTNAME + fi +]) + +# Prerequisites of lib/gethostname.c. +AC_DEFUN([gl_PREREQ_GETHOSTNAME], [ + AC_CHECK_FUNCS(uname) +]) 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 @@ +# Check for getloadavg. + +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003, +# 2006 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. +# New applications should use gl_GETLOADAVG instead. + +# gl_GETLOADAVG(LIBOBJDIR) +# ------------------------ +AC_DEFUN([gl_GETLOADAVG], +[gl_have_func=no # yes means we've found a way to get the load average. + +# Make sure getloadavg.c is where it belongs, at configure-time. +test -f "$srcdir/$1/getloadavg.c" || + AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing]) + +gl_save_LIBS=$LIBS + +# Check for getloadavg, but be sure not to touch the cache variable. +(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes + +# On HPUX9, an unprivileged user can get load averages through this function. +AC_CHECK_FUNCS(pstat_getdynamic) + +# Solaris has libkstat which does not require root. +AC_CHECK_LIB(kstat, kstat_open) +test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes + +# Some systems with -lutil have (and need) -lkvm as well, some do not. +# On Solaris, -lkvm requires nlist from -lelf, so check that first +# to get the right answer into the cache. +# For kstat on solaris, we need libelf to force the definition of SVR4 below. +if test $gl_have_func = no; then + AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS") +fi +if test $gl_have_func = no; then + AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS") + # Check for the 4.4BSD definition of getloadavg. + AC_CHECK_LIB(util, getloadavg, + [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes]) +fi + +if test $gl_have_func = no; then + # There is a commonly available library for RS/6000 AIX. + # Since it is not a standard part of AIX, it might be installed locally. + gl_getloadavg_LIBS=$LIBS + LIBS="-L/usr/local/lib $LIBS" + AC_CHECK_LIB(getloadavg, getloadavg, + [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS]) +fi + +# Make sure it is really in the library, if we think we found it, +# otherwise set up the replacement function. +AC_CHECK_FUNCS(getloadavg, [], + [gl_PREREQ_GETLOADAVG]) + +# Some definitions of getloadavg require that the program be installed setgid. +AC_CACHE_CHECK(whether getloadavg requires setgid, + gl_cv_func_getloadavg_setgid, +[AC_EGREP_CPP([Yowza Am I SETGID yet], +[#define CONFIGURING_GETLOADAVG +#include "$srcdir/$1/getloadavg.c" +#ifdef LDAV_PRIVILEGED +Yowza Am I SETGID yet +#endif +], + gl_cv_func_getloadavg_setgid=yes, + gl_cv_func_getloadavg_setgid=no)]) +if test $gl_cv_func_getloadavg_setgid = yes; then + NEED_SETGID=true + AC_DEFINE(GETLOADAVG_PRIVILEGED, 1, + [Define to 1 if the `getloadavg' function needs to be run setuid + or setgid.]) +else + NEED_SETGID=false +fi +AC_SUBST(NEED_SETGID)dnl + +if test $gl_cv_func_getloadavg_setgid = yes; then + AC_CACHE_CHECK(group of /dev/kmem, gl_cv_group_kmem, +[ # On Solaris, /dev/kmem is a symlink. Get info on the real file. + ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null` + # If we got an error (system does not support symlinks), try without -L. + test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem` + gl_cv_group_kmem=`echo $ac_ls_output \ + | sed -ne ['s/[ ][ ]*/ /g + s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/ + / /s/.* //;p']` +]) + AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl +fi +if test "x$gl_save_LIBS" = x; then + GETLOADAVG_LIBS=$LIBS +else + GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"` +fi +LIBS=$gl_save_LIBS + +AC_SUBST(GETLOADAVG_LIBS)dnl +])# gl_GETLOADAVG + + +# gl_PREREQ_GETLOADAVG +# -------------------- +# Set up the AC_LIBOBJ replacement of `getloadavg'. +AC_DEFUN([gl_PREREQ_GETLOADAVG], +[AC_LIBOBJ(getloadavg) +AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.]) +# Figure out what our getloadavg.c needs. +gl_have_func=no +AC_CHECK_HEADER(sys/dg_sys_info.h, +[gl_have_func=yes + AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with .]) + AC_CHECK_LIB(dgc, dg_sys_info)]) + +# We cannot check for , because Solaris 2 does not use dwarf (it +# uses stabs), but it is still SVR4. We cannot check for because +# Irix 4.0.5F has the header but not the library. +if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then + gl_have_func=yes + AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.]) +fi + +if test $gl_have_func = no; then + AC_CHECK_HEADER(inq_stats/cpustats.h, + [gl_have_func=yes + AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.]) + AC_DEFINE(UMAX4_3, 1, + [Define to 1 for Encore UMAX 4.3 that has + instead of .])]) +fi + +if test $gl_have_func = no; then + AC_CHECK_HEADER(sys/cpustats.h, + [gl_have_func=yes; AC_DEFINE(UMAX)]) +fi + +if test $gl_have_func = no; then + AC_CHECK_HEADERS(mach/mach.h) +fi + +AC_CHECK_HEADERS(nlist.h, +[AC_CHECK_MEMBERS([struct nlist.n_un.n_name], + [AC_DEFINE(NLIST_NAME_UNION, 1, + [Define to 1 if your `struct nlist' has an + `n_un' member. Obsolete, depend on + `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [], + [@%:@include ]) +])dnl +])# gl_PREREQ_GETLOADAVG diff --git a/m4/getopt.m4 b/gl/m4/getopt.m4 similarity index 90% rename from m4/getopt.m4 rename to gl/m4/getopt.m4 index 6b98782..c0a73b2 100644 --- a/m4/getopt.m4 +++ b/gl/m4/getopt.m4 @@ -1,11 +1,11 @@ -# getopt.m4 serial 11 -dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +# getopt.m4 serial 13 +dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. # The getopt module assume you want GNU getopt, with getopt_long etc, -# rather than vanilla POSIX getopt. This means your your code should +# rather than vanilla POSIX getopt. This means your code should # always include for the getopt prototypes. AC_DEFUN([gl_GETOPT_SUBSTITUTE], @@ -77,4 +77,7 @@ AC_DEFUN([gl_GETOPT_IFELSE], AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])]) # Prerequisites of lib/getopt*. -AC_DEFUN([gl_PREREQ_GETOPT], [:]) +AC_DEFUN([gl_PREREQ_GETOPT], +[ + AC_CHECK_DECLS_ONCE([getenv]) +]) diff --git a/m4/gettext.m4 b/gl/m4/gettext.m4 similarity index 61% rename from m4/gettext.m4 rename to gl/m4/gettext.m4 index 624a807..91c345e 100644 --- a/m4/gettext.m4 +++ b/gl/m4/gettext.m4 @@ -1,5 +1,5 @@ -# gettext.m4 serial 37 (gettext-0.14.4) -dnl Copyright (C) 1995-2005 Free Software Foundation, Inc. +# gettext.m4 serial 59 (gettext-0.16.1) +dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -15,7 +15,7 @@ dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995-2000. -dnl Bruno Haible , 2000-2003. +dnl Bruno Haible , 2000-2006. dnl Macro to add for using GNU gettext. @@ -63,8 +63,13 @@ AC_DEFUN([AM_GNU_GETTEXT], ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT ])])])]) - define([gt_included_intl], ifelse([$1], [external], [no], [yes])) + define([gt_included_intl], + ifelse([$1], [external], + ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]), + [yes])) define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) + gt_NEEDS_INIT + AM_GNU_GETTEXT_NEED([$2]) AC_REQUIRE([AM_PO_SUBDIRS])dnl ifelse(gt_included_intl, yes, [ @@ -78,7 +83,7 @@ AC_DEFUN([AM_GNU_GETTEXT], dnl Sometimes libintl requires libiconv, so first search for libiconv. dnl Ideally we would do this search only after the dnl if test "$USE_NLS" = "yes"; then - dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then + dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT dnl the configure script would need to contain the same shell code dnl again, outside any 'if'. There are two solutions: @@ -94,7 +99,7 @@ AC_DEFUN([AM_GNU_GETTEXT], gt_INTL_MACOSX dnl Set USE_NLS. - AM_NLS + AC_REQUIRE([AM_NLS]) ifelse(gt_included_intl, yes, [ BUILD_INCLUDED_LIBINTL=no @@ -104,6 +109,15 @@ AC_DEFUN([AM_GNU_GETTEXT], LTLIBINTL= POSUB= + dnl Add a version number to the cache macros. + case " $gt_needs " in + *" need-formatstring-macros "*) gt_api_version=3 ;; + *" need-ngettext "*) gt_api_version=2 ;; + *) gt_api_version=1 ;; + esac + gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" + gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" + dnl If we use NLS figure out what method if test "$USE_NLS" = "yes"; then gt_use_preinstalled_gnugettext=no @@ -122,28 +136,35 @@ AC_DEFUN([AM_GNU_GETTEXT], dnl to use. If GNU gettext is available we use this. Else we have dnl to fall back to GNU NLS library. - dnl Add a version number to the cache macros. - define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1))) - define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc]) - define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl]) - - AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc, - [AC_TRY_LINK([#include -]ifelse([$2], [need-formatstring-macros], -[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION + if test $gt_api_version -ge 3; then + gt_revision_test_code=' +#ifndef __GNU_GETTEXT_SUPPORTED_REVISION #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) #endif changequote(,)dnl typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; changequote([,])dnl -], [])[extern int _nl_msg_cat_cntr; +' + else + gt_revision_test_code= + fi + if test $gt_api_version -ge 2; then + gt_expression_test_code=' + * ngettext ("", "", 0)' + else + gt_expression_test_code= + fi + + AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], + [AC_TRY_LINK([#include +$gt_revision_test_code +extern int _nl_msg_cat_cntr; extern int *_nl_domain_bindings;], [bindtextdomain ("", ""); -return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings], - gt_cv_func_gnugettext_libc=yes, - gt_cv_func_gnugettext_libc=no)]) +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings], + [eval "$gt_func_gnugettext_libc=yes"], + [eval "$gt_func_gnugettext_libc=no"])]) - if test "$gt_cv_func_gnugettext_libc" != "yes"; then + if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then dnl Sometimes libintl requires libiconv, so first search for libiconv. ifelse(gt_included_intl, yes, , [ AM_ICONV_LINK @@ -154,52 +175,40 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], dnl even if libiconv doesn't exist. AC_LIB_LINKFLAGS_BODY([intl]) AC_CACHE_CHECK([for GNU gettext in libintl], - gt_cv_func_gnugettext_libintl, + [$gt_func_gnugettext_libintl], [gt_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $INCINTL" gt_save_LIBS="$LIBS" LIBS="$LIBS $LIBINTL" dnl Now see whether libintl exists and does not depend on libiconv. AC_TRY_LINK([#include -]ifelse([$2], [need-formatstring-macros], -[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION -#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) -#endif -changequote(,)dnl -typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; -changequote([,])dnl -], [])[extern int _nl_msg_cat_cntr; +$gt_revision_test_code +extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *);], [bindtextdomain ("", ""); -return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")], - gt_cv_func_gnugettext_libintl=yes, - gt_cv_func_gnugettext_libintl=no) +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], + [eval "$gt_func_gnugettext_libintl=yes"], + [eval "$gt_func_gnugettext_libintl=no"]) dnl Now see whether libintl exists and depends on libiconv. - if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then LIBS="$LIBS $LIBICONV" AC_TRY_LINK([#include -]ifelse([$2], [need-formatstring-macros], -[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION -#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) -#endif -changequote(,)dnl -typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; -changequote([,])dnl -], [])[extern int _nl_msg_cat_cntr; +$gt_revision_test_code +extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *);], [bindtextdomain ("", ""); -return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias ("")], +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], [LIBINTL="$LIBINTL $LIBICONV" LTLIBINTL="$LTLIBINTL $LTLIBICONV" - gt_cv_func_gnugettext_libintl=yes + eval "$gt_func_gnugettext_libintl=yes" ]) fi CPPFLAGS="$gt_save_CPPFLAGS" @@ -210,8 +219,8 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], dnl use it. But if this macro is used in GNU gettext, and GNU dnl gettext is already preinstalled in libintl, we update this dnl libintl. (Cf. the install rule in intl/Makefile.in.) - if test "$gt_cv_func_gnugettext_libc" = "yes" \ - || { test "$gt_cv_func_gnugettext_libintl" = "yes" \ + if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ + || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ && test "$PACKAGE" != gettext-runtime \ && test "$PACKAGE" != gettext-tools; }; then gt_use_preinstalled_gnugettext=yes @@ -234,8 +243,8 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], dnl Mark actions used to generate GNU NLS library. BUILD_INCLUDED_LIBINTL=yes USE_INCLUDED_LIBINTL=yes - LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV" - LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV" + LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" + LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` fi @@ -271,7 +280,7 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], if test "$USE_NLS" = "yes"; then AC_MSG_CHECKING([where the gettext function comes from]) if test "$gt_use_preinstalled_gnugettext" = "yes"; then - if test "$gt_cv_func_gnugettext_libintl" = "yes"; then + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then gt_source="external libintl" else gt_source="libc" @@ -285,7 +294,7 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], if test "$USE_NLS" = "yes"; then if test "$gt_use_preinstalled_gnugettext" = "yes"; then - if test "$gt_cv_func_gnugettext_libintl" = "yes"; then + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then AC_MSG_CHECKING([how to link with libintl]) AC_MSG_RESULT([$LIBINTL]) AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) @@ -353,134 +362,6 @@ return * gettext ("")]ifelse([$2], [need-ngettext], [ + * ngettext ("", "", 0)], ]) -dnl Checks for all prerequisites of the intl subdirectory, -dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, -dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. -AC_DEFUN([AM_INTL_SUBDIR], -[ - AC_REQUIRE([AC_PROG_INSTALL])dnl - AC_REQUIRE([AM_MKINSTALLDIRS])dnl - AC_REQUIRE([AC_PROG_CC])dnl - AC_REQUIRE([AC_CANONICAL_HOST])dnl - AC_REQUIRE([gt_GLIBC2])dnl - AC_REQUIRE([AC_PROG_RANLIB])dnl - AC_REQUIRE([AC_ISC_POSIX])dnl - AC_REQUIRE([AC_HEADER_STDC])dnl - AC_REQUIRE([AC_C_CONST])dnl - AC_REQUIRE([bh_C_SIGNED])dnl - AC_REQUIRE([AC_C_INLINE])dnl - AC_REQUIRE([AC_TYPE_OFF_T])dnl - AC_REQUIRE([AC_TYPE_SIZE_T])dnl - AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl - AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl - AC_REQUIRE([gt_TYPE_WCHAR_T])dnl - AC_REQUIRE([gt_TYPE_WINT_T])dnl - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - AC_REQUIRE([gt_TYPE_INTMAX_T]) - AC_REQUIRE([gt_PRINTF_POSIX]) - AC_REQUIRE([AC_FUNC_ALLOCA])dnl - AC_REQUIRE([AC_FUNC_MMAP])dnl - AC_REQUIRE([gl_GLIBC21])dnl - AC_REQUIRE([gt_INTDIV0])dnl - AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl - AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl - AC_REQUIRE([gt_INTTYPES_PRI])dnl - AC_REQUIRE([gl_XSIZE])dnl - AC_REQUIRE([gt_INTL_MACOSX])dnl - - AC_CHECK_TYPE([ptrdiff_t], , - [AC_DEFINE([ptrdiff_t], [long], - [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) - ]) - AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \ -stdlib.h string.h unistd.h sys/param.h]) - AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \ -mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \ -strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \ -__fsetlocking]) - - dnl Use the _snprintf function only if it is declared (because on NetBSD it - dnl is defined as a weak alias of snprintf; we prefer to use the latter). - gt_CHECK_DECL(_snprintf, [#include ]) - gt_CHECK_DECL(_snwprintf, [#include ]) - - dnl Use the *_unlocked functions only if they are declared. - dnl (because some of them were defined without being declared in Solaris - dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built - dnl on Solaris 2.5.1 to run on Solaris 2.6). - dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. - gt_CHECK_DECL(feof_unlocked, [#include ]) - gt_CHECK_DECL(fgets_unlocked, [#include ]) - gt_CHECK_DECL(getc_unlocked, [#include ]) - - case $gt_cv_func_printf_posix in - *yes) HAVE_POSIX_PRINTF=1 ;; - *) HAVE_POSIX_PRINTF=0 ;; - esac - AC_SUBST([HAVE_POSIX_PRINTF]) - if test "$ac_cv_func_asprintf" = yes; then - HAVE_ASPRINTF=1 - else - HAVE_ASPRINTF=0 - fi - AC_SUBST([HAVE_ASPRINTF]) - if test "$ac_cv_func_snprintf" = yes; then - HAVE_SNPRINTF=1 - else - HAVE_SNPRINTF=0 - fi - AC_SUBST([HAVE_SNPRINTF]) - if test "$ac_cv_func_wprintf" = yes; then - HAVE_WPRINTF=1 - else - HAVE_WPRINTF=0 - fi - AC_SUBST([HAVE_WPRINTF]) - - AM_ICONV - AM_LANGINFO_CODESET - if test $ac_cv_header_locale_h = yes; then - gt_LC_MESSAGES - fi - - if test -n "$INTL_MACOSX_LIBS"; then - CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" - fi - - dnl intl/plural.c is generated from intl/plural.y. It requires bison, - dnl because plural.y uses bison specific features. It requires at least - dnl bison-1.26 because earlier versions generate a plural.c that doesn't - dnl compile. - dnl bison is only needed for the maintainer (who touches plural.y). But in - dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put - dnl the rule in general Makefile. Now, some people carelessly touch the - dnl files or have a broken "make" program, hence the plural.c rule will - dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not - dnl present or too old. - AC_CHECK_PROGS([INTLBISON], [bison]) - if test -z "$INTLBISON"; then - ac_verc_fail=yes - else - dnl Found it, now check the version. - AC_MSG_CHECKING([version of bison]) -changequote(<<,>>)dnl - ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` - case $ac_prog_version in - '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; - 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) -changequote([,])dnl - ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; - *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; - esac - AC_MSG_RESULT([$ac_prog_version]) - fi - if test $ac_verc_fail = yes; then - INTLBISON=: - fi -]) - - dnl Checks for special options needed on MacOS X. dnl Defines INTL_MACOSX_LIBS. AC_DEFUN([gt_INTL_MACOSX], @@ -488,15 +369,12 @@ AC_DEFUN([gt_INTL_MACOSX], dnl Check for API introduced in MacOS X 10.2. AC_CACHE_CHECK([for CFPreferencesCopyAppValue], gt_cv_func_CFPreferencesCopyAppValue, - [gt_save_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" - gt_save_LIBS="$LIBS" - LIBS="$LIBS -framework CoreFoundation" - AC_TRY_LINK([#include ], + [gt_save_LIBS="$LIBS" + LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" + AC_TRY_LINK([#include ], [CFPreferencesCopyAppValue(NULL, NULL)], [gt_cv_func_CFPreferencesCopyAppValue=yes], [gt_cv_func_CFPreferencesCopyAppValue=no]) - CPPFLAGS="$gt_save_CPPFLAGS" LIBS="$gt_save_LIBS"]) if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1, @@ -504,14 +382,11 @@ AC_DEFUN([gt_INTL_MACOSX], fi dnl Check for API introduced in MacOS X 10.3. AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent, - [gt_save_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/CoreFoundation.framework/Headers" - gt_save_LIBS="$LIBS" - LIBS="$LIBS -framework CoreFoundation" - AC_TRY_LINK([#include ], [CFLocaleCopyCurrent();], + [gt_save_LIBS="$LIBS" + LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" + AC_TRY_LINK([#include ], [CFLocaleCopyCurrent();], [gt_cv_func_CFLocaleCopyCurrent=yes], [gt_cv_func_CFLocaleCopyCurrent=no]) - CPPFLAGS="$gt_save_CPPFLAGS" LIBS="$gt_save_LIBS"]) if test $gt_cv_func_CFLocaleCopyCurrent = yes; then AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1, @@ -525,23 +400,18 @@ AC_DEFUN([gt_INTL_MACOSX], ]) -dnl gt_CHECK_DECL(FUNC, INCLUDES) -dnl Check whether a function is declared. -AC_DEFUN([gt_CHECK_DECL], +dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. +m4_define([gt_NEEDS_INIT], [ - AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, - [AC_TRY_COMPILE([$2], [ -#ifndef $1 - char *p = (char *) $1; -#endif -], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) - if test $ac_cv_have_decl_$1 = yes; then - gt_value=1 - else - gt_value=0 - fi - AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], - [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) + m4_divert_text([DEFAULTS], [gt_needs=]) + m4_define([gt_NEEDS_INIT], []) +]) + + +dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) +AC_DEFUN([AM_GNU_GETTEXT_NEED], +[ + m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) ]) 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 @@ +# glibc2.m4 serial 1 +dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Test for the GNU C Library, version 2.0 or newer. +# From Bruno Haible. + +AC_DEFUN([gt_GLIBC2], + [ + AC_CACHE_CHECK(whether we are using the GNU C Library 2 or newer, + ac_cv_gnu_library_2, + [AC_EGREP_CPP([Lucky GNU user], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ >= 2) + Lucky GNU user + #endif +#endif + ], + ac_cv_gnu_library_2=yes, + ac_cv_gnu_library_2=no) + ] + ) + AC_SUBST(GLIBC2) + GLIBC2="$ac_cv_gnu_library_2" + ] +) diff --git a/m4/glibc21.m4 b/gl/m4/glibc21.m4 similarity index 100% rename from m4/glibc21.m4 rename to 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 @@ +# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the specification of how gnulib-tool is used. +# It acts as a cache: It is written and read by gnulib-tool. +# In projects using CVS, this file is meant to be stored in CVS, +# like the configure.ac and various Makefile.am files. + + +# Specification in the form of a command-line invocation: +# 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 + +# Specification in the form of a few gnulib-tool.m4 macro invocations: +gl_LOCAL_DIR([]) +gl_MODULES([dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf]) +gl_AVOID([]) +gl_SOURCE_BASE([gl]) +gl_M4_BASE([gl/m4]) +gl_DOC_BASE([doc]) +gl_TESTS_BASE([tests]) +gl_LIB([libgnu]) +gl_MAKEFILE_NAME([]) +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 @@ +# gnulib-common.m4 serial 2 +dnl Copyright (C) 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_MODULE_INDICATOR([modulename]) +# defines a C macro indicating the presence of the given module. +AC_DEFUN([gl_MODULE_INDICATOR], +[ + AC_DEFINE([GNULIB_]translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1], + [Define to 1 when using the gnulib module ]$1[.]) +]) + +# AC_PROG_MKDIR_P +# is a backport of autoconf-2.60's AC_PROG_MKDIR_P. +# Remove this macro when we can assume autoconf >= 2.60. +m4_ifdef([AC_PROG_MKDIR_P], [], [ + AC_DEFUN([AC_PROG_MKDIR_P], + [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake + MKDIR_P='$(mkdir_p)' + 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 @@ +# DO NOT EDIT! GENERATED AUTOMATICALLY! +# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the compiled summary of the specification in +# gnulib-cache.m4. It lists the computed macro invocations that need +# to be invoked from configure.ac. +# In projects using CVS, this file can be treated like other built files. + + +# This macro should be invoked from ./configure.in, in the section +# "Checks for programs", right after AC_PROG_CC, and certainly before +# any checks for libraries, header files, types and library functions. +AC_DEFUN([gl_EARLY], +[ + m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace + m4_pattern_allow([^gl_ES$])dnl a valid locale name + m4_pattern_allow([^gl_LIBOBJS$])dnl a variable + m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable + AC_REQUIRE([AC_PROG_RANLIB]) + AC_REQUIRE([AC_GNU_SOURCE]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([gl_LOCK_EARLY]) +]) + +# This macro should be invoked from ./configure.in, in the section +# "Check for header files, types and library functions". +AC_DEFUN([gl_INIT], +[ + m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) + m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) + m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) + AM_CONDITIONAL([GL_COND_LIBTOOL], [false]) + gl_cond_libtool=false + gl_libdeps= + gl_ltlibdeps= + gl_source_base='gl' + gl_FUNC_ALLOCA + gl_HEADER_ARPA_INET + gl_C_STRTOD + gl_CLOEXEC + gl_DIRNAME + gl_DOUBLE_SLASH_ROOT + gl_ERROR + gl_EXITFAIL + dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac. + gl_FCNTL_SAFER + gl_MODULE_INDICATOR([fcntl-safer]) + gl_FSUSAGE + gl_GETADDRINFO + gl_FUNC_GETHOSTNAME + gl_GETLOADAVG([$gl_source_base]) + gl_GETOPT + dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. + AM_GNU_GETTEXT_VERSION([0.15]) + gl_INET_NTOP + gl_INLINE + AC_FUNC_MALLOC + gl_MBCHAR + gl_MBITER + gl_FUNC_MEMCHR + gl_MINMAX + gl_MOUNTLIST + gl_HEADER_NETINET_IN + gl_REGEX + gl_SAFE_READ + gl_SAFE_WRITE + gl_SIZE_MAX + gl_FUNC_SNPRINTF + gl_TYPE_SOCKLEN_T + gt_TYPE_SSIZE_T + AM_STDBOOL_H + gl_STDINT_H + gl_STRCASE + gl_FUNC_STRDUP + gl_FUNC_STRNDUP + gl_FUNC_STRNLEN + gl_HEADER_SYS_SOCKET + AC_PROG_MKDIR_P + gl_HEADER_UNISTD + gl_UNISTD_SAFER + gl_FUNC_VASNPRINTF + gl_FUNC_VASPRINTF + gl_FUNC_VSNPRINTF + gl_WCHAR_H + gl_WCTYPE_H + gl_FUNC_WCWIDTH + gl_XALLOC + gl_XSIZE + gl_XSTRNDUP + LIBGNU_LIBDEPS="$gl_libdeps" + AC_SUBST([LIBGNU_LIBDEPS]) + LIBGNU_LTLIBDEPS="$gl_ltlibdeps" + AC_SUBST([LIBGNU_LTLIBDEPS]) + m4_popdef([AC_LIBSOURCES]) + m4_popdef([AC_REPLACE_FUNCS]) + m4_popdef([AC_LIBOBJ]) + AC_CONFIG_COMMANDS_PRE([ + gl_libobjs= + gl_ltlibobjs= + if test -n "$gl_LIBOBJS"; then + # Remove the extension. + sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do + gl_libobjs="$gl_libobjs $i.$ac_objext" + gl_ltlibobjs="$gl_ltlibobjs $i.lo" + done + fi + AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) + AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) + ]) +]) + +# Like AC_LIBOBJ, except that the module name goes +# into gl_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gl_LIBOBJ], + [gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext"]) + +# Like AC_REPLACE_FUNCS, except that the module name goes +# into gl_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gl_REPLACE_FUNCS], + [AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)])]) + +# Like AC_LIBSOURCES, except that it does nothing. +# We rely on EXTRA_lib..._SOURCES instead. +AC_DEFUN([gl_LIBSOURCES], + []) + +# This macro records the list of files which have been installed by +# gnulib-tool and may be removed by future gnulib-tool invocations. +AC_DEFUN([gl_FILE_LIST], [ + build-aux/config.rpath + lib/alloca.c + lib/alloca_.h + lib/asnprintf.c + lib/asprintf.c + lib/basename.c + lib/c-strtod.c + lib/c-strtod.h + lib/cloexec.c + lib/cloexec.h + lib/creat-safer.c + lib/dirname.c + lib/dirname.h + lib/dup-safer.c + lib/error.c + lib/error.h + lib/exit.h + lib/exitfail.c + lib/exitfail.h + lib/fcntl--.h + lib/fcntl-safer.h + lib/fd-safer.c + lib/fsusage.c + lib/fsusage.h + lib/full-read.c + lib/full-read.h + lib/full-write.c + lib/full-write.h + lib/gai_strerror.c + lib/getaddrinfo.c + lib/getaddrinfo.h + lib/gethostname.c + lib/getloadavg.c + lib/getopt.c + lib/getopt1.c + lib/getopt_.h + lib/getopt_int.h + lib/gettext.h + lib/inet_ntop.c + lib/inet_ntop.h + lib/intprops.h + lib/malloc.c + lib/mbchar.c + lib/mbchar.h + lib/mbuiter.h + lib/memchr.c + lib/minmax.h + lib/mountlist.c + lib/mountlist.h + lib/open-safer.c + lib/pipe-safer.c + lib/printf-args.c + lib/printf-args.h + lib/printf-parse.c + lib/printf-parse.h + lib/regcomp.c + lib/regex.c + lib/regex.h + lib/regex_internal.c + lib/regex_internal.h + lib/regexec.c + lib/safe-read.c + lib/safe-read.h + lib/safe-write.c + lib/safe-write.h + lib/size_max.h + lib/snprintf.c + lib/snprintf.h + lib/socket_.h + lib/stdbool_.h + lib/stdint_.h + lib/strcase.h + lib/strcasecmp.c + lib/strdup.c + lib/strdup.h + lib/stripslash.c + lib/strncasecmp.c + lib/strndup.c + lib/strndup.h + lib/strnlen.c + lib/strnlen.h + lib/strnlen1.c + lib/strnlen1.h + lib/unistd--.h + lib/unistd-safer.h + lib/unistd_.h + lib/vasnprintf.c + lib/vasnprintf.h + lib/vasprintf.c + lib/vasprintf.h + lib/vsnprintf.c + lib/vsnprintf.h + lib/wchar_.h + lib/wctype_.h + lib/wcwidth.h + lib/xalloc-die.c + lib/xalloc.h + lib/xmalloc.c + lib/xsize.h + lib/xstrndup.c + lib/xstrndup.h + m4/absolute-header.m4 + m4/alloca.m4 + m4/arpa_inet_h.m4 + m4/c-strtod.m4 + m4/cloexec.m4 + m4/codeset.m4 + m4/dirname.m4 + m4/dos.m4 + m4/double-slash-root.m4 + m4/eoverflow.m4 + m4/error.m4 + m4/exitfail.m4 + m4/extensions.m4 + m4/fcntl-safer.m4 + m4/fstypename.m4 + m4/fsusage.m4 + m4/getaddrinfo.m4 + m4/gethostname.m4 + m4/getloadavg.m4 + m4/getopt.m4 + m4/gettext.m4 + m4/glibc2.m4 + m4/glibc21.m4 + m4/gnulib-common.m4 + m4/iconv.m4 + m4/inet_ntop.m4 + m4/inline.m4 + m4/intdiv0.m4 + m4/intl.m4 + m4/intldir.m4 + m4/intmax.m4 + m4/intmax_t.m4 + m4/inttypes-pri.m4 + m4/inttypes_h.m4 + m4/lcmessage.m4 + m4/lib-ld.m4 + m4/lib-link.m4 + m4/lib-prefix.m4 + m4/lock.m4 + m4/longdouble.m4 + m4/longlong.m4 + m4/ls-mntd-fs.m4 + m4/mbchar.m4 + m4/mbiter.m4 + m4/mbrtowc.m4 + m4/memchr.m4 + m4/minmax.m4 + m4/mountlist.m4 + m4/netinet_in_h.m4 + m4/nls.m4 + m4/onceonly_2_57.m4 + m4/po.m4 + m4/printf-posix.m4 + m4/progtest.m4 + m4/regex.m4 + m4/safe-read.m4 + m4/safe-write.m4 + m4/size_max.m4 + m4/snprintf.m4 + m4/socklen.m4 + m4/sockpfaf.m4 + m4/ssize_t.m4 + m4/stdbool.m4 + m4/stdint.m4 + m4/stdint_h.m4 + m4/strcase.m4 + m4/strdup.m4 + m4/strndup.m4 + m4/strnlen.m4 + m4/sys_socket_h.m4 + m4/uintmax_t.m4 + m4/ulonglong.m4 + m4/unistd-safer.m4 + m4/unistd_h.m4 + m4/vasnprintf.m4 + m4/vasprintf.m4 + m4/visibility.m4 + m4/vsnprintf.m4 + m4/wchar.m4 + m4/wchar_t.m4 + m4/wctype.m4 + m4/wcwidth.m4 + m4/wint_t.m4 + m4/xalloc.m4 + m4/xsize.m4 + m4/xstrndup.m4 +]) 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 @@ +# gnulib-tool.m4 serial 1 +dnl Copyright (C) 2004-2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl The following macros need not be invoked explicitly. +dnl Invoking them does nothing except to declare default arguments +dnl for "gnulib-tool --import". + +dnl Usage: gl_MODULES([module1 module2 ...]) +AC_DEFUN([gl_MODULES], []) + +dnl Usage: gl_AVOID([module1 module2 ...]) +AC_DEFUN([gl_AVOID], []) + +dnl Usage: gl_SOURCE_BASE([DIR]) +AC_DEFUN([gl_SOURCE_BASE], []) + +dnl Usage: gl_M4_BASE([DIR]) +AC_DEFUN([gl_M4_BASE], []) + +dnl Usage: gl_LIB([LIBNAME]) +AC_DEFUN([gl_LIB], []) + +dnl Usage: gl_LGPL +AC_DEFUN([gl_LGPL], []) + +dnl Usage: gl_LIBTOOL +AC_DEFUN([gl_LIBTOOL], []) + +dnl Usage: gl_MACRO_PREFIX([PREFIX]) +AC_DEFUN([gl_MACRO_PREFIX], []) diff --git a/m4/iconv.m4 b/gl/m4/iconv.m4 similarity index 100% rename from m4/iconv.m4 rename to 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 @@ +# inet_ntop.m4 serial 3 +dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_INET_NTOP], +[ + AC_REPLACE_FUNCS(inet_ntop) + gl_PREREQ_INET_NTOP +]) + +# Prerequisites of lib/inet_ntop.h and lib/inet_ntop.c. +AC_DEFUN([gl_PREREQ_INET_NTOP], [ + AC_CHECK_HEADERS_ONCE([netinet/in.h arpa/inet.h]) + AC_CHECK_DECLS([inet_ntop],,,[#include ]) + AC_REQUIRE([gl_SOCKET_FAMILIES]) + AC_REQUIRE([AC_C_RESTRICT]) +]) 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 @@ +# inline.m4 serial 3 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Test for the 'inline' keyword or equivalent. +dnl Define 'inline' to a supported equivalent, or to nothing if not supported, +dnl like AC_C_INLINE does. Also, define HAVE_INLINE if 'inline' or an +dnl equivalent is effectively supported, i.e. if the compiler is likely to +dnl drop unused 'static inline' functions. +AC_DEFUN([gl_INLINE], +[ + AC_REQUIRE([AC_C_INLINE]) + AC_CACHE_CHECK([whether the compiler generally respects inline], + [gl_cv_c_inline_effective], + [if test $ac_cv_c_inline = no; then + gl_cv_c_inline_effective=no + else + dnl GCC defines __NO_INLINE__ if not optimizing or if -fno-inline is + dnl specified. + dnl Use AC_COMPILE_IFELSE here, not AC_EGREP_CPP, because the result + dnl depends on optimization flags, which can be in CFLAGS. + dnl (AC_EGREP_CPP looks only at the CPPFLAGS.) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], + [[#ifdef __NO_INLINE__ + #error "inline is not effective" + #endif]])], + [gl_cv_c_inline_effective=yes], + [gl_cv_c_inline_effective=no]) + fi + ]) + if test $gl_cv_c_inline_effective = yes; then + AC_DEFINE([HAVE_INLINE], 1, + [Define to 1 if the compiler supports one of the keywords + 'inline', '__inline__', '__inline' and effectively inlines + functions marked as such.]) + fi +]) 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 @@ +# intdiv0.m4 serial 1 (gettext-0.11.3) +dnl Copyright (C) 2002 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gt_INTDIV0], +[ + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + + AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], + gt_cv_int_divbyzero_sigfpe, + [ + AC_TRY_RUN([ +#include +#include + +static void +#ifdef __cplusplus +sigfpe_handler (int sig) +#else +sigfpe_handler (sig) int sig; +#endif +{ + /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ + exit (sig != SIGFPE); +} + +int x = 1; +int y = 0; +int z; +int nan; + +int main () +{ + signal (SIGFPE, sigfpe_handler); +/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ +#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) + signal (SIGTRAP, sigfpe_handler); +#endif +/* Linux/SPARC yields signal SIGILL. */ +#if defined (__sparc__) && defined (__linux__) + signal (SIGILL, sigfpe_handler); +#endif + + z = x / y; + nan = y / y; + exit (1); +} +], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, + [ + # Guess based on the CPU. + case "$host_cpu" in + alpha* | i[34567]86 | m68k | s390*) + gt_cv_int_divbyzero_sigfpe="guessing yes";; + *) + gt_cv_int_divbyzero_sigfpe="guessing no";; + esac + ]) + ]) + case "$gt_cv_int_divbyzero_sigfpe" in + *yes) value=1;; + *) value=0;; + esac + AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, + [Define if integer division by zero raises signal SIGFPE.]) +]) 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 @@ +# intl.m4 serial 3 (gettext-0.16) +dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995-2000. +dnl Bruno Haible , 2000-2006. + +AC_PREREQ(2.52) + +dnl Checks for all prerequisites of the intl subdirectory, +dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, +dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. +AC_DEFUN([AM_INTL_SUBDIR], +[ + AC_REQUIRE([AC_PROG_INSTALL])dnl + AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([gt_GLIBC2])dnl + AC_REQUIRE([AC_PROG_RANLIB])dnl + AC_REQUIRE([gl_VISIBILITY])dnl + AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl + AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl + AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl + AC_REQUIRE([gt_TYPE_WCHAR_T])dnl + AC_REQUIRE([gt_TYPE_WINT_T])dnl + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gt_TYPE_INTMAX_T]) + AC_REQUIRE([gt_PRINTF_POSIX]) + AC_REQUIRE([gl_GLIBC21])dnl + AC_REQUIRE([gl_XSIZE])dnl + AC_REQUIRE([gt_INTL_MACOSX])dnl + + AC_CHECK_TYPE([ptrdiff_t], , + [AC_DEFINE([ptrdiff_t], [long], + [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) + ]) + AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) + AC_CHECK_FUNCS([asprintf fwprintf putenv setenv setlocale snprintf wcslen]) + + dnl Use the _snprintf function only if it is declared (because on NetBSD it + dnl is defined as a weak alias of snprintf; we prefer to use the latter). + gt_CHECK_DECL(_snprintf, [#include ]) + gt_CHECK_DECL(_snwprintf, [#include ]) + + dnl Use the *_unlocked functions only if they are declared. + dnl (because some of them were defined without being declared in Solaris + dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built + dnl on Solaris 2.5.1 to run on Solaris 2.6). + dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. + gt_CHECK_DECL(getc_unlocked, [#include ]) + + case $gt_cv_func_printf_posix in + *yes) HAVE_POSIX_PRINTF=1 ;; + *) HAVE_POSIX_PRINTF=0 ;; + esac + AC_SUBST([HAVE_POSIX_PRINTF]) + if test "$ac_cv_func_asprintf" = yes; then + HAVE_ASPRINTF=1 + else + HAVE_ASPRINTF=0 + fi + AC_SUBST([HAVE_ASPRINTF]) + if test "$ac_cv_func_snprintf" = yes; then + HAVE_SNPRINTF=1 + else + HAVE_SNPRINTF=0 + fi + AC_SUBST([HAVE_SNPRINTF]) + if test "$ac_cv_func_wprintf" = yes; then + HAVE_WPRINTF=1 + else + HAVE_WPRINTF=0 + fi + AC_SUBST([HAVE_WPRINTF]) + + AM_LANGINFO_CODESET + gt_LC_MESSAGES + + dnl Compilation on mingw and Cygwin needs special Makefile rules, because + dnl 1. when we install a shared library, we must arrange to export + dnl auxiliary pointer variables for every exported variable, + dnl 2. when we install a shared library and a static library simultaneously, + dnl the include file specifies __declspec(dllimport) and therefore we + dnl must arrange to define the auxiliary pointer variables for the + dnl exported variables _also_ in the static library. + if test "$enable_shared" = yes; then + case "$host_os" in + cygwin*) is_woe32dll=yes ;; + *) is_woe32dll=no ;; + esac + else + is_woe32dll=no + fi + WOE32DLL=$is_woe32dll + AC_SUBST([WOE32DLL]) + + dnl Rename some macros and functions used for locking. + AH_BOTTOM([ +#define __libc_lock_t gl_lock_t +#define __libc_lock_define gl_lock_define +#define __libc_lock_define_initialized gl_lock_define_initialized +#define __libc_lock_init gl_lock_init +#define __libc_lock_lock gl_lock_lock +#define __libc_lock_unlock gl_lock_unlock +#define __libc_lock_recursive_t gl_recursive_lock_t +#define __libc_lock_define_recursive gl_recursive_lock_define +#define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized +#define __libc_lock_init_recursive gl_recursive_lock_init +#define __libc_lock_lock_recursive gl_recursive_lock_lock +#define __libc_lock_unlock_recursive gl_recursive_lock_unlock +#define glthread_in_use libintl_thread_in_use +#define glthread_lock_init libintl_lock_init +#define glthread_lock_lock libintl_lock_lock +#define glthread_lock_unlock libintl_lock_unlock +#define glthread_lock_destroy libintl_lock_destroy +#define glthread_rwlock_init libintl_rwlock_init +#define glthread_rwlock_rdlock libintl_rwlock_rdlock +#define glthread_rwlock_wrlock libintl_rwlock_wrlock +#define glthread_rwlock_unlock libintl_rwlock_unlock +#define glthread_rwlock_destroy libintl_rwlock_destroy +#define glthread_recursive_lock_init libintl_recursive_lock_init +#define glthread_recursive_lock_lock libintl_recursive_lock_lock +#define glthread_recursive_lock_unlock libintl_recursive_lock_unlock +#define glthread_recursive_lock_destroy libintl_recursive_lock_destroy +#define glthread_once libintl_once +#define glthread_once_call libintl_once_call +#define glthread_once_singlethreaded libintl_once_singlethreaded +]) +]) + + +dnl Checks for the core files of the intl subdirectory: +dnl dcigettext.c +dnl eval-plural.h +dnl explodename.c +dnl finddomain.c +dnl gettextP.h +dnl gmo.h +dnl hash-string.h hash-string.c +dnl l10nflist.c +dnl libgnuintl.h.in (except the *printf stuff) +dnl loadinfo.h +dnl loadmsgcat.c +dnl localealias.c +dnl log.c +dnl plural-exp.h plural-exp.c +dnl plural.y +dnl Used by libglocale. +AC_DEFUN([gt_INTL_SUBDIR_CORE], +[ + AC_REQUIRE([AC_C_INLINE])dnl + AC_REQUIRE([AC_TYPE_SIZE_T])dnl + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_REQUIRE([AC_FUNC_ALLOCA])dnl + AC_REQUIRE([AC_FUNC_MMAP])dnl + AC_REQUIRE([gt_INTDIV0])dnl + AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl + AC_REQUIRE([gt_INTTYPES_PRI])dnl + AC_REQUIRE([gl_LOCK])dnl + + AC_TRY_LINK( + [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], + [], + [AC_DEFINE([HAVE_BUILTIN_EXPECT], 1, + [Define to 1 if the compiler understands __builtin_expect.])]) + + AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) + AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ + stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ + argz_next __fsetlocking]) + + dnl Use the *_unlocked functions only if they are declared. + dnl (because some of them were defined without being declared in Solaris + dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built + dnl on Solaris 2.5.1 to run on Solaris 2.6). + dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. + gt_CHECK_DECL(feof_unlocked, [#include ]) + gt_CHECK_DECL(fgets_unlocked, [#include ]) + + AM_ICONV + + dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined, + dnl and a _NL_LOCALE_NAME macro always. + AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, + [AC_TRY_LINK([#include +#include ], + [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES));], + gt_cv_nl_locale_name=yes, + gt_cv_nl_locale_name=no) + ]) + if test $gt_cv_nl_locale_name = yes; then + AC_DEFINE(HAVE_NL_LOCALE_NAME, 1, + [Define if you have and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.]) + fi + + dnl intl/plural.c is generated from intl/plural.y. It requires bison, + dnl because plural.y uses bison specific features. It requires at least + dnl bison-1.26 because earlier versions generate a plural.c that doesn't + dnl compile. + dnl bison is only needed for the maintainer (who touches plural.y). But in + dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put + dnl the rule in general Makefile. Now, some people carelessly touch the + dnl files or have a broken "make" program, hence the plural.c rule will + dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not + dnl present or too old. + AC_CHECK_PROGS([INTLBISON], [bison]) + if test -z "$INTLBISON"; then + ac_verc_fail=yes + else + dnl Found it, now check the version. + AC_MSG_CHECKING([version of bison]) +changequote(<<,>>)dnl + ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` + case $ac_prog_version in + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; + 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) +changequote([,])dnl + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; + esac + AC_MSG_RESULT([$ac_prog_version]) + fi + if test $ac_verc_fail = yes; then + INTLBISON=: + fi +]) + + +dnl gt_CHECK_DECL(FUNC, INCLUDES) +dnl Check whether a function is declared. +AC_DEFUN([gt_CHECK_DECL], +[ + AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, + [AC_TRY_COMPILE([$2], [ +#ifndef $1 + char *p = (char *) $1; +#endif +], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) + if test $ac_cv_have_decl_$1 = yes; then + gt_value=1 + else + gt_value=0 + fi + AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], + [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) +]) 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 @@ +# intldir.m4 serial 1 (gettext-0.16) +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +AC_PREREQ(2.52) + +dnl Tells the AM_GNU_GETTEXT macro to consider an intl/ directory. +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 @@ +# intmax.m4 serial 3 (gettext-0.16) +dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether the system has the 'intmax_t' type, but don't attempt to +dnl find a replacement if it is lacking. + +AC_DEFUN([gt_TYPE_INTMAX_T], +[ + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, + [AC_TRY_COMPILE([ +#include +#include +#if HAVE_STDINT_H_WITH_UINTMAX +#include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +#include +#endif +], [intmax_t x = -1; + return !x;], + gt_cv_c_intmax_t=yes, + gt_cv_c_intmax_t=no)]) + if test $gt_cv_c_intmax_t = yes; then + AC_DEFINE(HAVE_INTMAX_T, 1, + [Define if you have the 'intmax_t' type in or .]) + fi +]) 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 @@ +# intmax_t.m4 serial 5 +dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +AC_PREREQ(2.13) + +# Define intmax_t to 'long' or 'long long' +# if it is not already defined in or . + +AC_DEFUN([gl_AC_TYPE_INTMAX_T], +[ + dnl For simplicity, we assume that a header file defines 'intmax_t' if and + dnl only if it defines 'uintmax_t'. + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then + AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + test $ac_cv_type_long_long = yes \ + && ac_type='long long' \ + || ac_type='long' + AC_DEFINE_UNQUOTED(intmax_t, $ac_type, + [Define to long or long long if and don't define.]) + else + AC_DEFINE(HAVE_INTMAX_T, 1, + [Define if you have the 'intmax_t' type in or .]) + fi +]) + +dnl An alternative would be to explicitly test for 'intmax_t'. + +AC_DEFUN([gt_AC_TYPE_INTMAX_T], +[ + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, + [AC_TRY_COMPILE([ +#include +#include +#if HAVE_STDINT_H_WITH_UINTMAX +#include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +#include +#endif +], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)]) + if test $gt_cv_c_intmax_t = yes; then + AC_DEFINE(HAVE_INTMAX_T, 1, + [Define if you have the 'intmax_t' type in or .]) + else + AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + test $ac_cv_type_long_long = yes \ + && ac_type='long long' \ + || ac_type='long' + AC_DEFINE_UNQUOTED(intmax_t, $ac_type, + [Define to long or long long if and don't define.]) + fi +]) diff --git a/m4/inttypes-pri.m4 b/gl/m4/inttypes-pri.m4 similarity index 74% rename from m4/inttypes-pri.m4 rename to gl/m4/inttypes-pri.m4 index 4d56a9a..7c7f894 100644 --- a/m4/inttypes-pri.m4 +++ b/gl/m4/inttypes-pri.m4 @@ -1,18 +1,20 @@ -# inttypes-pri.m4 serial 1 (gettext-0.11.4) -dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. +# inttypes-pri.m4 serial 4 (gettext-0.16) +dnl Copyright (C) 1997-2002, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. +AC_PREREQ(2.52) + # Define PRI_MACROS_BROKEN if exists and defines the PRI* # macros to non-string values. This is the case on AIX 4.3.3. AC_DEFUN([gt_INTTYPES_PRI], [ - AC_REQUIRE([gt_HEADER_INTTYPES_H]) - if test $gt_cv_header_inttypes_h = yes; then + AC_CHECK_HEADERS([inttypes.h]) + if test $ac_cv_header_inttypes_h = yes; then AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], gt_cv_inttypes_pri_broken, [ @@ -26,5 +28,9 @@ char *p = PRId32; if test "$gt_cv_inttypes_pri_broken" = yes; then AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, [Define if exists and defines unusable PRI* macros.]) + PRI_MACROS_BROKEN=1 + else + PRI_MACROS_BROKEN=0 fi + AC_SUBST([PRI_MACROS_BROKEN]) ]) diff --git a/m4/inttypes_h.m4 b/gl/m4/inttypes_h.m4 similarity index 85% rename from m4/inttypes_h.m4 rename to gl/m4/inttypes_h.m4 index a5d075d..edc8ecb 100644 --- a/m4/inttypes_h.m4 +++ b/gl/m4/inttypes_h.m4 @@ -1,5 +1,5 @@ -# inttypes_h.m4 serial 6 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. +# inttypes_h.m4 serial 7 +dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -15,7 +15,7 @@ AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [AC_TRY_COMPILE( [#include #include ], - [uintmax_t i = (uintmax_t) -1;], + [uintmax_t i = (uintmax_t) -1; return !i;], gl_cv_header_inttypes_h=yes, gl_cv_header_inttypes_h=no)]) 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 @@ +# lcmessage.m4 serial 4 (gettext-0.14.2) +dnl Copyright (C) 1995-2002, 2004-2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995. + +# Check whether LC_MESSAGES is available in . + +AC_DEFUN([gt_LC_MESSAGES], +[ + AC_CACHE_CHECK([for LC_MESSAGES], gt_cv_val_LC_MESSAGES, + [AC_TRY_LINK([#include ], [return LC_MESSAGES], + gt_cv_val_LC_MESSAGES=yes, gt_cv_val_LC_MESSAGES=no)]) + if test $gt_cv_val_LC_MESSAGES = yes; then + AC_DEFINE(HAVE_LC_MESSAGES, 1, + [Define if your file defines LC_MESSAGES.]) + fi +]) diff --git a/m4/lib-ld.m4 b/gl/m4/lib-ld.m4 similarity index 100% rename from m4/lib-ld.m4 rename to gl/m4/lib-ld.m4 diff --git a/m4/lib-link.m4 b/gl/m4/lib-link.m4 similarity index 70% rename from m4/lib-link.m4 rename to gl/m4/lib-link.m4 index 244a779..f157d98 100644 --- a/m4/lib-link.m4 +++ b/gl/m4/lib-link.m4 @@ -1,17 +1,19 @@ -# lib-link.m4 serial 7 (gettext-0.15) -dnl Copyright (C) 2001-2005 Free Software Foundation, Inc. +# lib-link.m4 serial 13 (gettext-0.16.2) +dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. -AC_PREREQ(2.50) +AC_PREREQ(2.54) dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and dnl augments the CPPFLAGS variable. +dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname +dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) @@ -24,13 +26,16 @@ AC_DEFUN([AC_LIB_LINKFLAGS], ac_cv_lib[]Name[]_libs="$LIB[]NAME" ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" ac_cv_lib[]Name[]_cppflags="$INC[]NAME" + ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX" ]) LIB[]NAME="$ac_cv_lib[]Name[]_libs" LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" INC[]NAME="$ac_cv_lib[]Name[]_cppflags" + LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix" AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) AC_SUBST([LIB]NAME) AC_SUBST([LTLIB]NAME) + AC_SUBST([LIB]NAME[_PREFIX]) dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the dnl results of this search when this library appears as a dependency. HAVE_LIB[]NAME=yes @@ -46,6 +51,8 @@ dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. +dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname +dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) @@ -82,17 +89,23 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], CPPFLAGS="$ac_save_CPPFLAGS" LIB[]NAME= LTLIB[]NAME= + LIB[]NAME[]_PREFIX= fi AC_SUBST([HAVE_LIB]NAME) AC_SUBST([LIB]NAME) AC_SUBST([LTLIB]NAME) + AC_SUBST([LIB]NAME[_PREFIX]) undefine([Name]) undefine([NAME]) ]) dnl Determine the platform dependent parameters needed to use rpath: -dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator, -dnl hardcode_direct, hardcode_minus_L. +dnl acl_libext, +dnl acl_shlibext, +dnl acl_hardcode_libdir_flag_spec, +dnl acl_hardcode_libdir_separator, +dnl acl_hardcode_direct, +dnl acl_hardcode_minus_L. AC_DEFUN([AC_LIB_RPATH], [ dnl Tell automake >= 1.10 to complain if config.rpath is missing. @@ -109,12 +122,14 @@ AC_DEFUN([AC_LIB_RPATH], acl_cv_rpath=done ]) wl="$acl_cv_wl" - libext="$acl_cv_libext" - shlibext="$acl_cv_shlibext" - hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" - hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" - hardcode_direct="$acl_cv_hardcode_direct" - hardcode_minus_L="$acl_cv_hardcode_minus_L" + acl_libext="$acl_cv_libext" + acl_shlibext="$acl_cv_shlibext" + acl_libname_spec="$acl_cv_libname_spec" + acl_library_names_spec="$acl_cv_library_names_spec" + acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" + acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" + acl_hardcode_direct="$acl_cv_hardcode_direct" + acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" dnl Determine whether the user wants rpath handling at all. AC_ARG_ENABLE(rpath, [ --disable-rpath do not hardcode runtime library paths], @@ -124,20 +139,24 @@ AC_DEFUN([AC_LIB_RPATH], dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. +dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found +dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_LINKFLAGS_BODY], [ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + dnl Autoconf >= 2.61 supports dots in --with options. + define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])]) dnl By default, look in $includedir and $libdir. use_additional=yes AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) - AC_LIB_ARG_WITH([lib$1-prefix], -[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib - --without-lib$1-prefix don't search for lib$1 in includedir and libdir], + AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix], +[ --with-lib]N_A_M_E[-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib + --without-lib]N_A_M_E[-prefix don't search for lib$1 in includedir and libdir], [ if test "X$withval" = "Xno"; then use_additional=no @@ -158,6 +177,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], LIB[]NAME= LTLIB[]NAME= INC[]NAME= + LIB[]NAME[]_PREFIX= rpathdirs= ltrpathdirs= names_already_handled= @@ -197,22 +217,55 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], found_la= found_so= found_a= + eval libname=\"$acl_libname_spec\" # typically: libname=lib$name + if test -n "$acl_shlibext"; then + shrext=".$acl_shlibext" # typically: shrext=.so + else + shrext= + fi if test $use_additional = yes; then - if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then - found_dir="$additional_libdir" - found_so="$additional_libdir/lib$name.$shlibext" - if test -f "$additional_libdir/lib$name.la"; then - found_la="$additional_libdir/lib$name.la" - fi - else - if test -f "$additional_libdir/lib$name.$libext"; then - found_dir="$additional_libdir" - found_a="$additional_libdir/lib$name.$libext" - if test -f "$additional_libdir/lib$name.la"; then - found_la="$additional_libdir/lib$name.la" + dir="$additional_libdir" + dnl The same code as in the loop below: + dnl First look for a shared library. + if test -n "$acl_shlibext"; then + if test -f "$dir/$libname$shrext"; then + found_dir="$dir" + found_so="$dir/$libname$shrext" + else + if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then + ver=`(cd "$dir" && \ + for f in "$libname$shrext".*; do echo "$f"; done \ + | sed -e "s,^$libname$shrext\\\\.,," \ + | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ + | sed 1q ) 2>/dev/null` + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + found_dir="$dir" + found_so="$dir/$libname$shrext.$ver" + fi + else + eval library_names=\"$acl_library_names_spec\" + for f in $library_names; do + if test -f "$dir/$f"; then + found_dir="$dir" + found_so="$dir/$f" + break + fi + done fi fi fi + dnl Then look for a static library. + if test "X$found_dir" = "X"; then + if test -f "$dir/$libname.$acl_libext"; then + found_dir="$dir" + found_a="$dir/$libname.$acl_libext" + fi + fi + if test "X$found_dir" != "X"; then + if test -f "$dir/$libname.la"; then + found_la="$dir/$libname.la" + fi + fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIB[]NAME; do @@ -220,21 +273,46 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` - if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then - found_dir="$dir" - found_so="$dir/lib$name.$shlibext" - if test -f "$dir/lib$name.la"; then - found_la="$dir/lib$name.la" - fi - else - if test -f "$dir/lib$name.$libext"; then + dnl First look for a shared library. + if test -n "$acl_shlibext"; then + if test -f "$dir/$libname$shrext"; then found_dir="$dir" - found_a="$dir/lib$name.$libext" - if test -f "$dir/lib$name.la"; then - found_la="$dir/lib$name.la" + found_so="$dir/$libname$shrext" + else + if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then + ver=`(cd "$dir" && \ + for f in "$libname$shrext".*; do echo "$f"; done \ + | sed -e "s,^$libname$shrext\\\\.,," \ + | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ + | sed 1q ) 2>/dev/null` + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + found_dir="$dir" + found_so="$dir/$libname$shrext.$ver" + fi + else + eval library_names=\"$acl_library_names_spec\" + for f in $library_names; do + if test -f "$dir/$f"; then + found_dir="$dir" + found_so="$dir/$f" + break + fi + done fi fi fi + dnl Then look for a static library. + if test "X$found_dir" = "X"; then + if test -f "$dir/$libname.$acl_libext"; then + found_dir="$dir" + found_a="$dir/$libname.$acl_libext" + fi + fi + if test "X$found_dir" != "X"; then + if test -f "$dir/$libname.la"; then + found_la="$dir/$libname.la" + fi + fi ;; esac if test "X$found_dir" != "X"; then @@ -268,12 +346,12 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], ltrpathdirs="$ltrpathdirs $found_dir" fi dnl The hardcoding into $LIBNAME is system dependent. - if test "$hardcode_direct" = yes; then + if test "$acl_hardcode_direct" = yes; then dnl Using DIR/libNAME.so during linking hardcodes DIR into the dnl resulting binary. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else - if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then + if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then dnl Use an explicit option to hardcode DIR into the resulting dnl binary. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" @@ -304,13 +382,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], if test -z "$haveit"; then LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" fi - if test "$hardcode_minus_L" != no; then + if test "$acl_hardcode_minus_L" != no; then dnl FIXME: Not sure whether we should use dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" dnl here. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else - dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH + dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH dnl here, because this doesn't fit in flags passed to the dnl compiler. So give up. No hardcoding. This affects only dnl very old systems. @@ -337,6 +415,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` + LIB[]NAME[]_PREFIX="$basedir" additional_includedir="$basedir/include" ;; esac @@ -498,18 +577,18 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], done done if test "X$rpathdirs" != "X"; then - if test -n "$hardcode_libdir_separator"; then + if test -n "$acl_hardcode_libdir_separator"; then dnl Weird platform: only the last -rpath option counts, the user must dnl pass all path elements in one option. We can arrange that for a dnl single library, but not when more than one $LIBNAMEs are used. alldirs= for found_dir in $rpathdirs; do - alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir" + alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" done - dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl. + dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. acl_save_libdir="$libdir" libdir="$alldirs" - eval flag=\"$hardcode_libdir_flag_spec\" + eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" else @@ -517,7 +596,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], for found_dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$found_dir" - eval flag=\"$hardcode_libdir_flag_spec\" + eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" done @@ -552,3 +631,79 @@ AC_DEFUN([AC_LIB_APPENDTOVAR], fi done ]) + +dnl For those cases where a variable contains several -L and -l options +dnl referring to unknown libraries and directories, this macro determines the +dnl necessary additional linker options for the runtime path. +dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) +dnl sets LDADDVAR to linker options needed together with LIBSVALUE. +dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, +dnl otherwise linking without libtool is assumed. +AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], +[ + AC_REQUIRE([AC_LIB_RPATH]) + AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) + $1= + if test "$enable_rpath" != no; then + if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then + dnl Use an explicit option to hardcode directories into the resulting + dnl binary. + rpathdirs= + next= + for opt in $2; do + if test -n "$next"; then + dir="$next" + dnl No need to hardcode the standard /usr/lib. + if test "X$dir" != "X/usr/$acl_libdirstem"; then + rpathdirs="$rpathdirs $dir" + fi + next= + else + case $opt in + -L) next=yes ;; + -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` + dnl No need to hardcode the standard /usr/lib. + if test "X$dir" != "X/usr/$acl_libdirstem"; then + rpathdirs="$rpathdirs $dir" + fi + next= ;; + *) next= ;; + esac + fi + done + if test "X$rpathdirs" != "X"; then + if test -n ""$3""; then + dnl libtool is used for linking. Use -R options. + for dir in $rpathdirs; do + $1="${$1}${$1:+ }-R$dir" + done + else + dnl The linker is used for linking directly. + if test -n "$acl_hardcode_libdir_separator"; then + dnl Weird platform: only the last -rpath option counts, the user + dnl must pass all path elements in one option. + alldirs= + for dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" + done + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + $1="$flag" + else + dnl The -rpath options are cumulative. + for dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$dir" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + $1="${$1}${$1:+ }$flag" + done + fi + fi + fi + fi + fi + AC_SUBST([$1]) +]) diff --git a/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4 similarity index 100% rename from m4/lib-prefix.m4 rename to 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 @@ +# lock.m4 serial 6 (gettext-0.16) +dnl Copyright (C) 2005-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Tests for a multithreading library to be used. +dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, +dnl USE_PTH_THREADS, USE_WIN32_THREADS +dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use +dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with +dnl libtool). +dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for +dnl programs that really need multithread functionality. The difference +dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak +dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". +dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for +dnl multithread-safe programs. + +AC_DEFUN([gl_LOCK_EARLY], +[ + AC_REQUIRE([gl_LOCK_EARLY_BODY]) +]) + +dnl The guts of gl_LOCK_EARLY. Needs to be expanded only once. + +AC_DEFUN([gl_LOCK_EARLY_BODY], +[ + dnl Ordering constraints: This macro modifies CPPFLAGS in a way that + dnl influences the result of the autoconf tests that test for *_unlocked + dnl declarations, on AIX 5 at least. Therefore it must come early. + AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl + AC_BEFORE([$0], [gl_ARGP])dnl + + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AC_GNU_SOURCE]) dnl needed for pthread_rwlock_t on glibc systems + dnl Check for multithreading. + AC_ARG_ENABLE(threads, +AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) +AC_HELP_STRING([--disable-threads], [build without multithread safety]), + [gl_use_threads=$enableval], + [case "$host_os" in + dnl Disable multithreading by default on OSF/1, because it interferes + dnl with fork()/exec(): When msgexec is linked with -lpthread, its child + dnl process gets an endless segmentation fault inside execvp(). + osf*) gl_use_threads=no ;; + *) gl_use_threads=yes ;; + esac + ]) + if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then + # For using : + case "$host_os" in + osf*) + # On OSF/1, the compiler needs the flag -D_REENTRANT so that it + # groks . cc also understands the flag -pthread, but + # we don't use it because 1. gcc-2.95 doesn't understand -pthread, + # 2. putting a flag into CPPFLAGS that has an effect on the linker + # causes the AC_TRY_LINK test below to succeed unexpectedly, + # leading to wrong values of LIBTHREAD and LTLIBTHREAD. + CPPFLAGS="$CPPFLAGS -D_REENTRANT" + ;; + esac + # Some systems optimize for single-threaded programs by default, and + # need special flags to disable these optimizations. For example, the + # definition of 'errno' in . + case "$host_os" in + aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; + solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; + esac + fi +]) + +dnl The guts of gl_LOCK. Needs to be expanded only once. + +AC_DEFUN([gl_LOCK_BODY], +[ + AC_REQUIRE([gl_LOCK_EARLY_BODY]) + gl_threads_api=none + LIBTHREAD= + LTLIBTHREAD= + LIBMULTITHREAD= + LTLIBMULTITHREAD= + if test "$gl_use_threads" != no; then + dnl Check whether the compiler and linker support weak declarations. + AC_MSG_CHECKING([whether imported symbols can be declared weak]) + gl_have_weak=no + AC_TRY_LINK([extern void xyzzy (); +#pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes]) + AC_MSG_RESULT([$gl_have_weak]) + if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then + # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that + # it groks . It's added above, in gl_LOCK_EARLY_BODY. + AC_CHECK_HEADER(pthread.h, gl_have_pthread_h=yes, gl_have_pthread_h=no) + if test "$gl_have_pthread_h" = yes; then + # Other possible tests: + # -lpthreads (FSU threads, PCthreads) + # -lgthreads + gl_have_pthread= + # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist + # in libc. IRIX 6.5 has the first one in both libc and libpthread, but + # the second one only in libpthread, and lock.c needs it. + AC_TRY_LINK([#include ], + [pthread_mutex_lock((pthread_mutex_t*)0); + pthread_mutexattr_init((pthread_mutexattr_t*)0);], + [gl_have_pthread=yes]) + # Test for libpthread by looking for pthread_kill. (Not pthread_self, + # since it is defined as a macro on OSF/1.) + if test -n "$gl_have_pthread"; then + # The program links fine without libpthread. But it may actually + # need to link with libpthread in order to create multiple threads. + AC_CHECK_LIB(pthread, pthread_kill, + [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread + # On Solaris and HP-UX, most pthread functions exist also in libc. + # Therefore pthread_in_use() needs to actually try to create a + # thread: pthread_create from libc will fail, whereas + # pthread_create will actually create a thread. + case "$host_os" in + solaris* | hpux*) + AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1, + [Define if the pthread_in_use() detection is hard.]) + esac + ]) + else + # Some library is needed. Try libpthread and libc_r. + AC_CHECK_LIB(pthread, pthread_kill, + [gl_have_pthread=yes + LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread + LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) + if test -z "$gl_have_pthread"; then + # For FreeBSD 4. + AC_CHECK_LIB(c_r, pthread_kill, + [gl_have_pthread=yes + LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r + LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r]) + fi + fi + if test -n "$gl_have_pthread"; then + gl_threads_api=posix + AC_DEFINE([USE_POSIX_THREADS], 1, + [Define if the POSIX multithreading library can be used.]) + if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then + if test $gl_have_weak = yes; then + AC_DEFINE([USE_POSIX_THREADS_WEAK], 1, + [Define if references to the POSIX multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + # OSF/1 4.0 and MacOS X 10.1 lack the pthread_rwlock_t type and the + # pthread_rwlock_* functions. + AC_CHECK_TYPE([pthread_rwlock_t], + [AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1, + [Define if the POSIX multithreading library has read/write locks.])], + [], + [#include ]) + # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. + AC_TRY_COMPILE([#include ], + [#if __FreeBSD__ == 4 +error "No, in FreeBSD 4.0 recursive mutexes actually don't work." +#else +int x = (int)PTHREAD_MUTEX_RECURSIVE; +return !x; +#endif], + [AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1, + [Define if the defines PTHREAD_MUTEX_RECURSIVE.])]) + fi + fi + fi + if test -z "$gl_have_pthread"; then + if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then + gl_have_solaristhread= + gl_save_LIBS="$LIBS" + LIBS="$LIBS -lthread" + AC_TRY_LINK([#include +#include ], + [thr_self();], + [gl_have_solaristhread=yes]) + LIBS="$gl_save_LIBS" + if test -n "$gl_have_solaristhread"; then + gl_threads_api=solaris + LIBTHREAD=-lthread + LTLIBTHREAD=-lthread + LIBMULTITHREAD="$LIBTHREAD" + LTLIBMULTITHREAD="$LTLIBTHREAD" + AC_DEFINE([USE_SOLARIS_THREADS], 1, + [Define if the old Solaris multithreading library can be used.]) + if test $gl_have_weak = yes; then + AC_DEFINE([USE_SOLARIS_THREADS_WEAK], 1, + [Define if references to the old Solaris multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + fi + fi + if test "$gl_use_threads" = pth; then + gl_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_LINKFLAGS(pth) + gl_have_pth= + gl_save_LIBS="$LIBS" + LIBS="$LIBS -lpth" + AC_TRY_LINK([#include ], [pth_self();], gl_have_pth=yes) + LIBS="$gl_save_LIBS" + if test -n "$gl_have_pth"; then + gl_threads_api=pth + LIBTHREAD="$LIBPTH" + LTLIBTHREAD="$LTLIBPTH" + LIBMULTITHREAD="$LIBTHREAD" + LTLIBMULTITHREAD="$LTLIBTHREAD" + AC_DEFINE([USE_PTH_THREADS], 1, + [Define if the GNU Pth multithreading library can be used.]) + if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then + if test $gl_have_weak = yes; then + AC_DEFINE([USE_PTH_THREADS_WEAK], 1, + [Define if references to the GNU Pth multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + else + CPPFLAGS="$gl_save_CPPFLAGS" + fi + fi + if test -z "$gl_have_pthread"; then + if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then + if { case "$host_os" in + mingw*) true;; + *) false;; + esac + }; then + gl_threads_api=win32 + AC_DEFINE([USE_WIN32_THREADS], 1, + [Define if the Win32 multithreading API can be used.]) + fi + fi + fi + fi + AC_MSG_CHECKING([for multithread API to use]) + AC_MSG_RESULT([$gl_threads_api]) + AC_SUBST(LIBTHREAD) + AC_SUBST(LTLIBTHREAD) + AC_SUBST(LIBMULTITHREAD) + AC_SUBST(LTLIBMULTITHREAD) +]) + +AC_DEFUN([gl_LOCK], +[ + AC_REQUIRE([gl_LOCK_EARLY]) + AC_REQUIRE([gl_LOCK_BODY]) + gl_PREREQ_LOCK +]) + +# Prerequisites of lib/lock.c. +AC_DEFUN([gl_PREREQ_LOCK], [ + AC_REQUIRE([AC_C_INLINE]) +]) + +dnl Survey of platforms: +dnl +dnl Platform Available Compiler Supports test-lock +dnl flavours option weak result +dnl --------------- --------- --------- -------- --------- +dnl Linux 2.4/glibc posix -lpthread Y OK +dnl +dnl GNU Hurd/glibc posix +dnl +dnl FreeBSD 5.3 posix -lc_r Y +dnl posix -lkse ? Y +dnl posix -lpthread ? Y +dnl posix -lthr Y +dnl +dnl FreeBSD 5.2 posix -lc_r Y +dnl posix -lkse Y +dnl posix -lthr Y +dnl +dnl FreeBSD 4.0,4.10 posix -lc_r Y OK +dnl +dnl NetBSD 1.6 -- +dnl +dnl OpenBSD 3.4 posix -lpthread Y OK +dnl +dnl MacOS X 10.[123] posix -lpthread Y OK +dnl +dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK +dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK +dnl +dnl HP-UX 11 posix -lpthread N (cc) OK +dnl Y (gcc) +dnl +dnl IRIX 6.5 posix -lpthread Y 0.5 +dnl +dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK +dnl +dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK +dnl -lpthread (gcc) Y +dnl +dnl Cygwin posix -lpthread Y OK +dnl +dnl Any of the above pth -lpth 0.0 +dnl +dnl Mingw win32 N OK +dnl +dnl BeOS 5 -- +dnl +dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is +dnl turned off: +dnl OK if all three tests terminate OK, +dnl 0.5 if the first test terminates OK but the second one loops endlessly, +dnl 0.0 if the first test already loops endlessly. diff --git a/m4/longdouble.m4 b/gl/m4/longdouble.m4 similarity index 79% rename from m4/longdouble.m4 rename to gl/m4/longdouble.m4 index 40cd7ce..25590f4 100644 --- a/m4/longdouble.m4 +++ b/gl/m4/longdouble.m4 @@ -1,5 +1,5 @@ -# longdouble.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +# longdouble.m4 serial 2 (gettext-0.15) +dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -8,6 +8,9 @@ dnl From Bruno Haible. dnl Test whether the compiler supports the 'long double' type. dnl Prerequisite: AC_PROG_CC +dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf +dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics. + AC_DEFUN([gt_TYPE_LONGDOUBLE], [ AC_CACHE_CHECK([for long double], gt_cv_c_long_double, diff --git a/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 @@ +# longlong.m4 serial 10 +dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +# Define HAVE_LONG_LONG_INT if 'long long int' works. +# This fixes a bug in Autoconf 2.60, but can be removed once we +# assume 2.61 everywhere. + +# Note: If the type 'long long int' exists but is only 32 bits large +# (as on some very old compilers), HAVE_LONG_LONG_INT will not be +# defined. In this case you can treat 'long long int' like 'long int'. + +AC_DEFUN([AC_TYPE_LONG_LONG_INT], +[ + AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[long long int ll = 9223372036854775807ll; + long long int nll = -9223372036854775807LL; + typedef int a[((-9223372036854775807LL < 0 + && 0 < 9223372036854775807ll) + ? 1 : -1)]; + int i = 63;]], + [[long long int llmax = 9223372036854775807ll; + return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) + | (llmax / ll) | (llmax % ll));]])], + [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. + dnl If cross compiling, assume the bug isn't important, since + dnl nobody cross compiles for this platform as far as we know. + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@include + @%:@ifndef LLONG_MAX + @%:@ define HALF \ + (1LL << (sizeof (long long int) * CHAR_BIT - 2)) + @%:@ define LLONG_MAX (HALF - 1 + HALF) + @%:@endif]], + [[long long int n = 1; + int i; + for (i = 0; ; i++) + { + long long int m = n << i; + if (m >> i != n) + return 1; + if (LLONG_MAX / 2 < m) + break; + } + return 0;]])], + [ac_cv_type_long_long_int=yes], + [ac_cv_type_long_long_int=no], + [ac_cv_type_long_long_int=yes])], + [ac_cv_type_long_long_int=no])]) + if test $ac_cv_type_long_long_int = yes; then + AC_DEFINE([HAVE_LONG_LONG_INT], 1, + [Define to 1 if the system has the type `long long int'.]) + fi +]) + +# This macro is obsolescent and should go away soon. +AC_DEFUN([gl_AC_TYPE_LONG_LONG], +[ + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + ac_cv_type_long_long=$ac_cv_type_long_long_int + if test $ac_cv_type_long_long = yes; then + AC_DEFINE(HAVE_LONG_LONG, 1, + [Define if you have the 'long long' type.]) + fi +]) diff --git a/m4/ls-mntd-fs.m4 b/gl/m4/ls-mntd-fs.m4 similarity index 88% rename from m4/ls-mntd-fs.m4 rename to 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 @@ -#serial 21 +#serial 26 # How to list mounted file systems. # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software @@ -28,7 +28,7 @@ AC_CHECK_FUNCS(getmntent) AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS], [ AC_CHECK_FUNCS(listmntent getmntinfo) -AC_CHECK_HEADERS_ONCE(sys/param.h) +AC_CHECK_HEADERS_ONCE(sys/param.h sys/statvfs.h) # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses # NGROUPS (as the array dimension for a struct member) without a definition. @@ -141,7 +141,8 @@ if test $ac_cv_func_getmntent = yes; then # endif #endif ], - [ struct mntent *mnt = 0; char *table = MOUNTED; ], + [ struct mntent *mnt = 0; char *table = MOUNTED; + if (sizeof mnt && sizeof table) return 0;], fu_cv_sys_mounted_getmntent1=yes, fu_cv_sys_mounted_getmntent1=no)]) AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1) @@ -167,6 +168,7 @@ if test $ac_cv_func_getmntent = yes; then AC_DEFINE(MOUNTED_GETMNTENT2, 1, [Define if there is a function named getmntent for reading the list of mounted file systems, and that function takes two arguments. (SVR4)]) + AC_CHECK_FUNCS(hasmntopt) fi fi @@ -232,10 +234,39 @@ if test -z "$ac_list_mounted_fs"; then ]) AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo) if test $fu_cv_sys_mounted_getmntinfo = yes; then - ac_list_mounted_fs=found - AC_DEFINE(MOUNTED_GETMNTINFO, 1, - [Define if there is a function named getmntinfo for reading the - list of mounted file systems. (4.4BSD, Darwin)]) + AC_MSG_CHECKING([whether getmntinfo returns statvfs structures]) + AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo2, + [ + AC_TRY_COMPILE([ +#if HAVE_SYS_PARAM_H +# include +#endif +#include +#if HAVE_SYS_MOUNT_H +# include +#endif +#if HAVE_SYS_STATVFS_H +# include +#endif +extern int getmntinfo (struct statfs **, int); + ], [], + [fu_cv_sys_mounted_getmntinfo2=no], + [fu_cv_sys_mounted_getmntinfo2=yes]) + ]) + AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2]) + if test $fu_cv_sys_mounted_getmntinfo2 = no; then + ac_list_mounted_fs=found + AC_DEFINE(MOUNTED_GETMNTINFO, 1, + [Define if there is a function named getmntinfo for reading the + list of mounted file systems and it returns an array of + 'struct statfs'. (4.4BSD, Darwin)]) + else + ac_list_mounted_fs=found + AC_DEFINE(MOUNTED_GETMNTINFO2, 1, + [Define if there is a function named getmntinfo for reading the + list of mounted file systems and it returns an array of + 'struct statvfs'. (NetBSD 3.0)]) + fi fi fi 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 @@ +# mbchar.m4 serial 5 +dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl autoconf tests required for use of mbchar.m4 +dnl From Bruno Haible. + +AC_DEFUN([gl_MBCHAR], +[ + AC_REQUIRE([AC_GNU_SOURCE]) + AC_LIBOBJ([mbchar]) +]) 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 @@ +# mbiter.m4 serial 2 +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl autoconf tests required for use of mbiter.h +dnl From Bruno Haible. + +AC_DEFUN([gl_MBITER], +[ + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + dnl The following line is that so the user can test HAVE_MBRTOWC before + dnl #include "mbiter.h" or "mbuiter.h". + AC_REQUIRE([gl_FUNC_MBRTOWC]) + : +]) 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 @@ +# mbrtowc.m4 serial 8 +dnl Copyright (C) 2001-2002, 2004-2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert + +dnl This file can be removed, and gl_FUNC_MBRTOWC replaced with +dnl AC_FUNC_MBRTOWC, when autoconf 2.60 can be assumed everywhere. + +AC_DEFUN([gl_FUNC_MBRTOWC], +[ + dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. + AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], + gl_cv_func_mbrtowc, + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[wchar_t wc; + char const s[] = ""; + size_t n = 1; + mbstate_t state; + return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], + gl_cv_func_mbrtowc=yes, + gl_cv_func_mbrtowc=no)]) + if test $gl_cv_func_mbrtowc = yes; then + AC_DEFINE([HAVE_MBRTOWC], 1, + [Define to 1 if mbrtowc and mbstate_t are properly declared.]) + fi +]) 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 @@ +# memchr.m4 serial 4 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MEMCHR], +[ + AC_REPLACE_FUNCS(memchr) + if test $ac_cv_func_memchr = no; then + gl_PREREQ_MEMCHR + fi +]) + +# Prerequisites of lib/memchr.c. +AC_DEFUN([gl_PREREQ_MEMCHR], [ + AC_CHECK_HEADERS(bp-sym.h) +]) 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 @@ +# minmax.m4 serial 2 +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_PREREQ(2.52) + +AC_DEFUN([gl_MINMAX], +[ + AC_REQUIRE([gl_PREREQ_MINMAX]) +]) + +# Prerequisites of lib/minmax.h. +AC_DEFUN([gl_PREREQ_MINMAX], +[ + gl_MINMAX_IN_HEADER([limits.h]) + gl_MINMAX_IN_HEADER([sys/param.h]) +]) + +dnl gl_MINMAX_IN_HEADER(HEADER) +dnl The parameter has to be a literal header name; it cannot be macro, +dnl nor a shell variable. (Because autoheader collects only AC_DEFINE +dnl invocations with a literal macro name.) +AC_DEFUN([gl_MINMAX_IN_HEADER], +[ + m4_pushdef([header], AS_TR_SH([$1])) + m4_pushdef([HEADER], AS_TR_CPP([$1])) + AC_CACHE_CHECK([whether <$1> defines MIN and MAX], + [gl_cv_minmax_in_]header, + [AC_TRY_COMPILE([#include <$1> +int x = MIN (42, 17);], [], + [gl_cv_minmax_in_]header[=yes], + [gl_cv_minmax_in_]header[=no])]) + if test $gl_cv_minmax_in_[]header = yes; then + AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1, + [Define to 1 if <$1> defines the MIN and MAX macros.]) + fi + m4_popdef([HEADER]) + m4_popdef([header]) +]) diff --git a/m4/mountlist.m4 b/gl/m4/mountlist.m4 similarity index 84% rename from m4/mountlist.m4 rename to gl/m4/mountlist.m4 index b2a2e12..c25f44e 100644 --- a/m4/mountlist.m4 +++ b/gl/m4/mountlist.m4 @@ -1,13 +1,11 @@ -#serial 8 -dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +#serial 9 +dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_MOUNTLIST], [ - AC_LIBSOURCES([mountlist.c, mountlist.h]) - gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], [gl_cv_list_mounted_fs=no]) 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 @@ +# netinet_in_h.m4 serial 1 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Simon Josefsson + +AC_DEFUN([gl_HEADER_NETINET_IN], +[ + AC_CHECK_HEADERS_ONCE([netinet/in.h]) + if test $ac_cv_header_netinet_in_h = yes; then + NETINET_IN_H='' + else + NETINET_IN_H='netinet/in.h' + fi + AC_SUBST(NETINET_IN_H) +]) diff --git a/m4/nls.m4 b/gl/m4/nls.m4 similarity index 58% rename from m4/nls.m4 rename to gl/m4/nls.m4 index 2082c3b..7967cc2 100644 --- a/m4/nls.m4 +++ b/gl/m4/nls.m4 @@ -1,5 +1,5 @@ -# nls.m4 serial 2 (gettext-0.14.3) -dnl Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc. +# nls.m4 serial 3 (gettext-0.15) +dnl Copyright (C) 1995-2003, 2005-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -29,23 +29,3 @@ AC_DEFUN([AM_NLS], AC_MSG_RESULT($USE_NLS) AC_SUBST(USE_NLS) ]) - -AC_DEFUN([AM_MKINSTALLDIRS], -[ - dnl Tell automake >= 1.10 to complain if mkinstalldirs is missing. - m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([mkinstalldirs])]) - dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly - dnl find the mkinstalldirs script in another subdir but $(top_srcdir). - dnl Try to locate it. - MKINSTALLDIRS= - if test -n "$ac_aux_dir"; then - case "$ac_aux_dir" in - /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;; - *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;; - esac - fi - if test -z "$MKINSTALLDIRS"; then - MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs" - fi - AC_SUBST(MKINSTALLDIRS) -]) diff --git a/m4/onceonly_2_57.m4 b/gl/m4/onceonly_2_57.m4 similarity index 90% rename from m4/onceonly_2_57.m4 rename to 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 @@ -# onceonly_2_57.m4 serial 3 -dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc. +# onceonly_2_57.m4 serial 4 +dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -7,10 +7,10 @@ dnl that contains a configuration script generated by Autoconf, under dnl the same distribution terms as the rest of that program. dnl This file defines some "once only" variants of standard autoconf macros. -dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS -dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS -dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS -dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC +dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS +dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS +dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS +dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL dnl The advantage is that the check for each of the headers/functions/decls dnl will be put only once into the 'configure' file. It keeps the size of dnl the 'configure' file down, and avoids redundant output when 'configure' diff --git a/m4/po.m4 b/gl/m4/po.m4 similarity index 90% rename from m4/po.m4 rename to gl/m4/po.m4 index f2795ee..00133ef 100644 --- a/m4/po.m4 +++ b/gl/m4/po.m4 @@ -1,5 +1,5 @@ -# po.m4 serial 7 (gettext-0.14.3) -dnl Copyright (C) 1995-2005 Free Software Foundation, Inc. +# po.m4 serial 13 (gettext-0.15) +dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -24,7 +24,7 @@ AC_DEFUN([AM_PO_SUBDIRS], [ AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl - AC_REQUIRE([AM_MKINSTALLDIRS])dnl + AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake AC_REQUIRE([AM_NLS])dnl dnl Perform the following tests also if --disable-nls has been given, @@ -39,6 +39,22 @@ AC_DEFUN([AM_PO_SUBDIRS], :) AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) + dnl Test whether it is GNU msgfmt >= 0.15. +changequote(,)dnl + case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; + *) MSGFMT_015=$MSGFMT ;; + esac +changequote([,])dnl + AC_SUBST([MSGFMT_015]) +changequote(,)dnl + case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; + *) GMSGFMT_015=$GMSGFMT ;; + esac +changequote([,])dnl + AC_SUBST([GMSGFMT_015]) + dnl Search for GNU xgettext 0.12 or newer in the PATH. dnl The first test excludes Solaris xgettext and early GNU xgettext versions. dnl The second test excludes FreeBSD xgettext. @@ -49,44 +65,26 @@ AC_DEFUN([AM_PO_SUBDIRS], dnl Remove leftover from FreeBSD xgettext call. rm -f messages.po + dnl Test whether it is GNU xgettext >= 0.15. +changequote(,)dnl + case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; + *) XGETTEXT_015=$XGETTEXT ;; + esac +changequote([,])dnl + AC_SUBST([XGETTEXT_015]) + dnl Search for GNU msgmerge 0.11 or newer in the PATH. AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) - dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. - dnl Test whether we really found GNU msgfmt. - if test "$GMSGFMT" != ":"; then - dnl If it is no GNU msgfmt we define it as : so that the - dnl Makefiles still can work. - if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 && - (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then - : ; - else - GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'` - AC_MSG_RESULT( - [found $GMSGFMT program is not GNU msgfmt; ignore it]) - GMSGFMT=":" - fi - fi - - dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. - dnl Test whether we really found GNU xgettext. - if test "$XGETTEXT" != ":"; then - dnl If it is no GNU xgettext we define it as : so that the - dnl Makefiles still can work. - if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 && - (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 - : ; - else - AC_MSG_RESULT( - [found xgettext program is not GNU xgettext; ignore it]) - XGETTEXT=":" - fi - dnl Remove leftover from FreeBSD xgettext call. - rm -f messages.po - fi + dnl Installation directories. + dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we + dnl have to define it here, so that it can be used in po/Makefile. + test -n "$localedir" || localedir='${datadir}/locale' + AC_SUBST([localedir]) - AC_OUTPUT_COMMANDS([ + AC_CONFIG_COMMANDS([po-directories], [[ for ac_file in $CONFIG_FILES; do # Support "outfile[:infile[:infile...]]" case "$ac_file" in @@ -123,11 +121,12 @@ AC_DEFUN([AM_PO_SUBDIRS], test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" fi ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` - # Hide the ALL_LINGUAS assigment from automake. + # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$ALL_LINGUAS_' POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" else # The set of available languages was given in configure.in. + # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' fi # Compute POFILES @@ -197,10 +196,10 @@ AC_DEFUN([AM_PO_SUBDIRS], fi ;; esac - done], + done]], [# Capture the value of obsolete ALL_LINGUAS because we need it to compute # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it - # from automake. + # from automake < 1.5. eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' # Capture the value of LINGUAS because we need it to compute CATALOGS. LINGUAS="${LINGUAS-%UNSET%}" @@ -286,7 +285,7 @@ x changequote([,])dnl # Set POTFILES to the value of the Makefile variable POTFILES. - sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`" + sed_x_POTFILES=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'` POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"` # Compute POTFILES_DEPS as # $(foreach file, $(POTFILES), $(top_srcdir)/$(file)) @@ -305,10 +304,10 @@ changequote([,])dnl POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" else # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS. - sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`" + sed_x_LINGUAS=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'` ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"` fi - # Hide the ALL_LINGUAS assigment from automake. + # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$ALL_LINGUAS_' # Compute POFILES # 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 @@ +# printf-posix.m4 serial 2 (gettext-0.13.1) +dnl Copyright (C) 2003 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether the printf() function supports POSIX/XSI format strings with +dnl positions. + +AC_DEFUN([gt_PRINTF_POSIX], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings], + gt_cv_func_printf_posix, + [ + AC_TRY_RUN([ +#include +#include +/* The string "%2$d %1$d", with dollar characters protected from the shell's + dollar expansion (possibly an autoconf bug). */ +static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; +static char buf[100]; +int main () +{ + sprintf (buf, format, 33, 55); + return (strcmp (buf, "55 33") != 0); +}], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no, + [ + AC_EGREP_CPP(notposix, [ +#if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ + notposix +#endif + ], gt_cv_func_printf_posix="guessing no", + gt_cv_func_printf_posix="guessing yes") + ]) + ]) + case $gt_cv_func_printf_posix in + *yes) + AC_DEFINE(HAVE_POSIX_PRINTF, 1, + [Define if your printf() function supports format strings with positions.]) + ;; + esac +]) diff --git a/m4/progtest.m4 b/gl/m4/progtest.m4 similarity index 100% rename from m4/progtest.m4 rename to gl/m4/progtest.m4 diff --git a/m4/regex.m4 b/gl/m4/regex.m4 similarity index 69% rename from m4/regex.m4 rename to gl/m4/regex.m4 index 8ea4fe9..25da645 100644 --- a/m4/regex.m4 +++ b/gl/m4/regex.m4 @@ -1,7 +1,7 @@ -#serial 31 +#serial 42 -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free -# Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,34 +14,7 @@ AC_PREREQ([2.50]) AC_DEFUN([gl_REGEX], [ - AC_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t - - AC_CACHE_CHECK([whether off_t can be used in a switch statement], - [gl_cv_type_off_t_switch], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT], - [[off_t o = -1; - switch (o) - { - case -2: - return 1; - case -1: - return 2; - default: - return 0; - } - ]])], - [gl_cv_type_off_t_switch=yes], - [gl_cv_type_off_t_switch=no])]) - if test $gl_cv_type_off_t_switch = yes; then - AC_DEFINE([_REGEX_LARGE_OFFSETS], 1, - [Define if you want regoff_t to be at least as wide POSIX requires.]) - fi - - AC_LIBSOURCES( - [regcomp.c, regex.c, regex.h, - regex_internal.c, regex_internal.h, regexec.c]) + AC_CHECK_HEADERS_ONCE([locale.h]) AC_ARG_WITH([included-regex], [AC_HELP_STRING([--without-included-regex], @@ -49,30 +22,64 @@ AC_DEFUN([gl_REGEX], systems with recent-enough versions of the GNU C Library (use with caution on other systems)])]) - case $with_included_regex in + case $with_included_regex in #( yes|no) ac_use_included_regex=$with_included_regex ;; '') - # If the system regex support is good enough that it passes the the + # If the system regex support is good enough that it passes the # following run test, then default to *not* using the included regex.c. # If cross compiling, assume the test would fail and use the included # regex.c. The first failing regular expression is from `Spencer ere # test #75' in grep-2.3. AC_CACHE_CHECK([for working re_compile_pattern], - [gl_cv_func_re_compile_pattern_broken], + [gl_cv_func_re_compile_pattern_working], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [AC_INCLUDES_DEFAULT - #include ], + #if HAVE_LOCALE_H + #include + #endif + #include + #include + ], [[static struct re_pattern_buffer regex; + unsigned char folded_chars[UCHAR_MAX + 1]; + int i; const char *s; struct re_registers regs; - /* Use the POSIX-compliant spelling with leading REG_, - rather than the traditional GNU spelling with leading RE_, - so that we reject older libc implementations. */ - re_set_syntax (REG_SYNTAX_POSIX_EGREP); + + #if HAVE_LOCALE_H + /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html + This test needs valgrind to catch the bug on Debian + GNU/Linux 3.1 x86, but it might catch the bug better + on other platforms and it shouldn't hurt to try the + test here. */ + if (setlocale (LC_ALL, "en_US.UTF-8")) + { + static char const pat[] = "insert into"; + static char const data[] = + "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; + re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE + | RE_ICASE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern (pat, sizeof pat - 1, ®ex); + if (s) + return 1; + if (re_search (®ex, data, sizeof data - 1, + 0, sizeof data - 1, ®s) + != -1) + return 1; + if (! setlocale (LC_ALL, "C")) + return 1; + } + #endif + + re_set_syntax (RE_SYNTAX_POSIX_EGREP); memset (®ex, 0, sizeof (regex)); - s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex); + for (i = 0; i <= UCHAR_MAX; i++) + folded_chars[i] = i; + regex.translate = folded_chars; + s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); /* This should fail with _Invalid character class name_ error. */ if (!s) exit (1); @@ -106,10 +113,9 @@ AC_DEFUN([gl_REGEX], exit (1); /* The version of regex.c in older versions of gnulib - ignored REG_IGNORE_CASE (which was then called RE_ICASE). - Detect that problem too. */ + ignored RE_ICASE. Detect that problem too. */ memset (®ex, 0, sizeof (regex)); - re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE); + re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); s = re_compile_pattern ("x", 1, ®ex); if (s) exit (1); @@ -123,24 +129,29 @@ AC_DEFUN([gl_REGEX], exit (1); /* Reject hosts whose regoff_t values are too narrow. - These include glibc 2.3.5 on hosts with 64-bit off_t - and 32-bit int, and Solaris 10 on hosts with 32-bit int - and _FILE_OFFSET_BITS=64. */ - if (sizeof (regoff_t) < sizeof (off_t)) + These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t + and 32-bit int. */ + if (sizeof (regoff_t) < sizeof (ptrdiff_t) + || sizeof (regoff_t) < sizeof (ssize_t)) exit (1); exit (0);]])], - [gl_cv_func_re_compile_pattern_broken=no], - [gl_cv_func_re_compile_pattern_broken=yes], - dnl When crosscompiling, assume it is broken. - [gl_cv_func_re_compile_pattern_broken=yes])]) - ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken + [gl_cv_func_re_compile_pattern_working=yes], + [gl_cv_func_re_compile_pattern_working=no], + dnl When crosscompiling, assume it is not working. + [gl_cv_func_re_compile_pattern_working=no])]) + case $gl_cv_func_re_compile_pattern_working in #( + yes) ac_use_included_regex=no;; #( + no) ac_use_included_regex=yes;; + esac ;; *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) ;; esac if test $ac_use_included_regex = yes; then + AC_DEFINE([_REGEX_LARGE_OFFSETS], 1, + [Define if you want regoff_t to be at least as wide POSIX requires.]) AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], [Define to rpl_re_syntax_options if the replacement should be used.]) AC_DEFINE([re_set_syntax], [rpl_re_set_syntax], @@ -180,8 +191,8 @@ AC_DEFUN([gl_REGEX], AC_DEFUN([gl_PREREQ_REGEX], [ AC_REQUIRE([AC_GNU_SOURCE]) - AC_REQUIRE([gl_C_RESTRICT]) + AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([AM_LANGINFO_CODESET]) - AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h]) - AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll]) + AC_CHECK_FUNCS_ONCE([iswctype mbrtowc mempcpy wcrtomb wcscoll]) + AC_CHECK_DECLS([isblank], [], [], [#include ]) ]) 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 @@ +# safe-read.m4 serial 5 +dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_SAFE_READ], +[ + AC_LIBOBJ([safe-read]) + + gl_PREREQ_SAFE_READ +]) + +# Prerequisites of lib/safe-read.c. +AC_DEFUN([gl_PREREQ_SAFE_READ], +[ + AC_REQUIRE([gt_TYPE_SSIZE_T]) +]) 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 @@ +# safe-write.m4 serial 3 +dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_SAFE_WRITE], +[ + AC_LIBOBJ([safe-write]) + + gl_PREREQ_SAFE_WRITE +]) + +# Prerequisites of lib/safe-write.c. +AC_DEFUN([gl_PREREQ_SAFE_WRITE], +[ + gl_PREREQ_SAFE_READ +]) 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 @@ +# size_max.m4 serial 6 +dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gl_SIZE_MAX], +[ + AC_CHECK_HEADERS(stdint.h) + dnl First test whether the system already has SIZE_MAX. + AC_MSG_CHECKING([for SIZE_MAX]) + AC_CACHE_VAL([gl_cv_size_max], [ + gl_cv_size_max= + AC_EGREP_CPP([Found it], [ +#include +#if HAVE_STDINT_H +#include +#endif +#ifdef SIZE_MAX +Found it +#endif +], gl_cv_size_max=yes) + if test -z "$gl_cv_size_max"; then + dnl Define it ourselves. Here we assume that the type 'size_t' is not wider + dnl than the type 'unsigned long'. Try hard to find a definition that can + dnl be used in a preprocessor #if, i.e. doesn't contain a cast. + AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], + [#include +#include ], size_t_bits_minus_1=) + AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], + [#include ], fits_in_uint=) + if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then + if test $fits_in_uint = 1; then + dnl Even though SIZE_MAX fits in an unsigned int, it must be of type + dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. + AC_TRY_COMPILE([#include + extern size_t foo; + extern unsigned long foo; + ], [], fits_in_uint=0) + fi + dnl We cannot use 'expr' to simplify this expression, because 'expr' + dnl works only with 'long' integers in the host environment, while we + dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. + if test $fits_in_uint = 1; then + gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" + else + gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" + fi + else + dnl Shouldn't happen, but who knows... + gl_cv_size_max='((size_t)~(size_t)0)' + fi + fi + ]) + AC_MSG_RESULT([$gl_cv_size_max]) + if test "$gl_cv_size_max" != yes; then + AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], + [Define as the maximum value of type 'size_t', if the system doesn't define it.]) + fi +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) 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 @@ +# snprintf.m4 serial 2 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_SNPRINTF], +[ + AC_REPLACE_FUNCS(snprintf) + AC_CHECK_DECLS_ONCE(snprintf) + gl_PREREQ_SNPRINTF +]) + +# Prerequisites of lib/snprintf.c. +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 @@ +# socklen.m4 serial 4 +dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Albert Chin, Windows fixes from Simon Josefsson. + +dnl Check for socklen_t: historically on BSD it is an int, and in +dnl POSIX 1g it is a type of its own, but some platforms use different +dnl types for the argument to getsockopt, getpeername, etc. So we +dnl have to test to find something that will work. + +dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find +dnl it there first. That file is included by gnulib's socket_.h, which +dnl all users of this module should include. Cygwin must not include +dnl ws2tcpip.h. +AC_DEFUN([gl_TYPE_SOCKLEN_T], + [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl + AC_CHECK_TYPE([socklen_t], , + [AC_MSG_CHECKING([for socklen_t equivalent]) + AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv], + [# Systems have either "struct sockaddr *" or + # "void *" as the second argument to getpeername + gl_cv_socklen_t_equiv= + for arg2 in "struct sockaddr" void; do + for t in int size_t "unsigned int" "long int" "unsigned long int"; do + AC_TRY_COMPILE( + [#include + #include + + int getpeername (int, $arg2 *, $t *);], + [$t len; + getpeername (0, 0, &len);], + [gl_cv_socklen_t_equiv="$t"]) + test "$gl_cv_socklen_t_equiv" != "" && break + done + test "$gl_cv_socklen_t_equiv" != "" && break + done + ]) + if test "$gl_cv_socklen_t_equiv" = ""; then + AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) + fi + AC_MSG_RESULT([$gl_cv_socklen_t_equiv]) + AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], + [type to use in place of socklen_t if not defined])], + [#include + #if HAVE_SYS_SOCKET_H + # include + #elif HAVE_WS2TCPIP_H + # include + #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 @@ +# sockpfaf.m4 serial 5 +dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Test for some common socket protocol families (PF_INET, PF_INET6, ...) +dnl and some common address families (AF_INET, AF_INET6, ...). +dnl This test assumes that a system supports an address family if and only if +dnl it supports the corresponding protocol family. + +dnl From Bruno Haible. + +AC_DEFUN([gl_SOCKET_FAMILIES], +[ + AC_REQUIRE([gl_HEADER_SYS_SOCKET]) + AC_CHECK_HEADERS_ONCE([netinet/in.h]) + + AC_MSG_CHECKING(for IPv4 sockets) + AC_CACHE_VAL(gl_cv_socket_ipv4, + [AC_TRY_COMPILE([#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#include +#endif], +[int x = AF_INET; struct in_addr y; struct sockaddr_in z; + if (&x && &y && &z) return 0;], + gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)]) + AC_MSG_RESULT($gl_cv_socket_ipv4) + if test $gl_cv_socket_ipv4 = yes; then + AC_DEFINE(HAVE_IPV4, 1, [Define to 1 if defines AF_INET.]) + fi + + AC_MSG_CHECKING(for IPv6 sockets) + AC_CACHE_VAL(gl_cv_socket_ipv6, + [AC_TRY_COMPILE([#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#include +#endif], +[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; + if (&x && &y && &z) return 0;], + gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)]) + AC_MSG_RESULT($gl_cv_socket_ipv6) + if test $gl_cv_socket_ipv6 = yes; then + AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if defines AF_INET6.]) + fi +]) 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 @@ +# ssize_t.m4 serial 4 (gettext-0.15) +dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether ssize_t is defined. + +AC_DEFUN([gt_TYPE_SSIZE_T], +[ + AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t], + [AC_TRY_COMPILE([#include ], + [int x = sizeof (ssize_t *) + sizeof (ssize_t); + return !x;], + [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])]) + if test $gt_cv_ssize_t = no; then + AC_DEFINE([ssize_t], [int], + [Define as a signed type of the same size as size_t.]) + fi +]) diff --git a/m4/stdbool.m4 b/gl/m4/stdbool.m4 similarity index 82% rename from m4/stdbool.m4 rename to gl/m4/stdbool.m4 index 162f1df..2204ecd 100644 --- a/m4/stdbool.m4 +++ b/gl/m4/stdbool.m4 @@ -1,6 +1,6 @@ # Check for stdbool.h that conforms to C99. -dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. +dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -64,9 +64,9 @@ AC_DEFUN([AC_HEADER_STDBOOL], char a[true == 1 ? 1 : -1]; char b[false == 0 ? 1 : -1]; char c[__bool_true_false_are_defined == 1 ? 1 : -1]; - char d[(bool) -0.5 == true ? 1 : -1]; + char d[(bool) 0.5 == true ? 1 : -1]; bool e = &s; - char f[(_Bool) -0.0 == false ? 1 : -1]; + char f[(_Bool) 0.0 == false ? 1 : -1]; char g[true]; char h[sizeof (_Bool)]; char i[sizeof s.t]; @@ -74,10 +74,10 @@ AC_DEFUN([AC_HEADER_STDBOOL], _Bool n[m]; char o[sizeof n == m * sizeof n[0] ? 1 : -1]; char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; - #if defined __xlc__ || __GNUC__ + #if defined __xlc__ || defined __GNUC__ /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 reported by James Lemley on 2005-10-05; see - . + http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html This test is not quite right, since xlc is allowed to reject this program, as the initializer for xlcbug is not one of the forms that C requires support for. @@ -86,10 +86,17 @@ AC_DEFUN([AC_HEADER_STDBOOL], Let us hope that IBM fixes the xlc bug, and also adds support for this kind of constant expression. In the meantime, this test will reject xlc, which is OK, since - our stdbool.h substitute should suffice. */ + our stdbool.h substitute should suffice. We also test + this with GCC, where it should work, to detect more + quickly whether someone messes up the test in the + future. */ char digs[] = "0123456789"; int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); #endif + /* Catch a bug in an HP-UX C compiler. See + http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html + */ _Bool q = true; _Bool *pq = &q; ], 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 @@ +# stdint.m4 serial 22 +dnl Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert and Bruno Haible. +dnl Test whether is supported or must be substituted. + +AC_DEFUN([gl_STDINT_H], +[ + AC_PREREQ(2.59)dnl + + dnl Check for long long int and unsigned long long int. + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + if test $ac_cv_type_long_long_int = yes; then + HAVE_LONG_LONG_INT=1 + else + HAVE_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + if test $ac_cv_type_unsigned_long_long_int = yes; then + HAVE_UNSIGNED_LONG_LONG_INT=1 + else + HAVE_UNSIGNED_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) + + dnl Check for . + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. + if test $ac_cv_header_inttypes_h = yes; then + HAVE_INTTYPES_H=1 + else + HAVE_INTTYPES_H=0 + fi + AC_SUBST([HAVE_INTTYPES_H]) + + dnl Check for . + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. + if test $ac_cv_header_sys_types_h = yes; then + HAVE_SYS_TYPES_H=1 + else + HAVE_SYS_TYPES_H=0 + fi + AC_SUBST([HAVE_SYS_TYPES_H]) + + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_stdint_h. + if test $ac_cv_header_stdint_h = yes; then + gl_ABSOLUTE_HEADER([stdint.h]) + ABSOLUTE_STDINT_H=\"$gl_cv_absolute_stdint_h\" + HAVE_STDINT_H=1 + else + ABSOLUTE_STDINT_H=\"no/such/file/stdint.h\" + HAVE_STDINT_H=0 + fi + AC_SUBST([ABSOLUTE_STDINT_H]) + AC_SUBST([HAVE_STDINT_H]) + + dnl Now see whether we need a substitute . Use + dnl ABSOLUTE_STDINT_H, not , so that it also works during + dnl a "config.status --recheck" if a stdint.h has been + dnl created in the build directory. + if test $ac_cv_header_stdint_h = yes; then + AC_CACHE_CHECK([whether stdint.h conforms to C99], + [gl_cv_header_working_stdint_h], + [gl_cv_header_working_stdint_h=no + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#include +#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ +#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ +#include ABSOLUTE_STDINT_H +#ifdef INT8_MAX +int8_t a1 = INT8_MAX; +int8_t a1min = INT8_MIN; +#endif +#ifdef INT16_MAX +int16_t a2 = INT16_MAX; +int16_t a2min = INT16_MIN; +#endif +#ifdef INT32_MAX +int32_t a3 = INT32_MAX; +int32_t a3min = INT32_MIN; +#endif +#ifdef INT64_MAX +int64_t a4 = INT64_MAX; +int64_t a4min = INT64_MIN; +#endif +#ifdef UINT8_MAX +uint8_t b1 = UINT8_MAX; +#else +typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; +#endif +#ifdef UINT16_MAX +uint16_t b2 = UINT16_MAX; +#endif +#ifdef UINT32_MAX +uint32_t b3 = UINT32_MAX; +#endif +#ifdef UINT64_MAX +uint64_t b4 = UINT64_MAX; +#endif +int_least8_t c1 = INT8_C (0x7f); +int_least8_t c1max = INT_LEAST8_MAX; +int_least8_t c1min = INT_LEAST8_MIN; +int_least16_t c2 = INT16_C (0x7fff); +int_least16_t c2max = INT_LEAST16_MAX; +int_least16_t c2min = INT_LEAST16_MIN; +int_least32_t c3 = INT32_C (0x7fffffff); +int_least32_t c3max = INT_LEAST32_MAX; +int_least32_t c3min = INT_LEAST32_MIN; +int_least64_t c4 = INT64_C (0x7fffffffffffffff); +int_least64_t c4max = INT_LEAST64_MAX; +int_least64_t c4min = INT_LEAST64_MIN; +uint_least8_t d1 = UINT8_C (0xff); +uint_least8_t d1max = UINT_LEAST8_MAX; +uint_least16_t d2 = UINT16_C (0xffff); +uint_least16_t d2max = UINT_LEAST16_MAX; +uint_least32_t d3 = UINT32_C (0xffffffff); +uint_least32_t d3max = UINT_LEAST32_MAX; +uint_least64_t d4 = UINT64_C (0xffffffffffffffff); +uint_least64_t d4max = UINT_LEAST64_MAX; +int_fast8_t e1 = INT_FAST8_MAX; +int_fast8_t e1min = INT_FAST8_MIN; +int_fast16_t e2 = INT_FAST16_MAX; +int_fast16_t e2min = INT_FAST16_MIN; +int_fast32_t e3 = INT_FAST32_MAX; +int_fast32_t e3min = INT_FAST32_MIN; +int_fast64_t e4 = INT_FAST64_MAX; +int_fast64_t e4min = INT_FAST64_MIN; +uint_fast8_t f1 = UINT_FAST8_MAX; +uint_fast16_t f2 = UINT_FAST16_MAX; +uint_fast32_t f3 = UINT_FAST32_MAX; +uint_fast64_t f4 = UINT_FAST64_MAX; +#ifdef INTPTR_MAX +intptr_t g = INTPTR_MAX; +intptr_t gmin = INTPTR_MIN; +#endif +#ifdef UINTPTR_MAX +uintptr_t h = UINTPTR_MAX; +#endif +intmax_t i = INTMAX_MAX; +uintmax_t j = UINTMAX_MAX; +struct s { + int check_PTRDIFF: PTRDIFF_MIN < 0 && 0 < PTRDIFF_MAX ? 1 : -1; + int check_SIG_ATOMIC: SIG_ATOMIC_MIN <= 0 && 0 < SIG_ATOMIC_MAX ? 1 : -1; + int check_SIZE: 0 < SIZE_MAX ? 1 : -1; + int check_WCHAR: WCHAR_MIN <= 0 && 0 < WCHAR_MAX ? 1 : -1; + int check_WINT: WINT_MIN <= 0 && 0 < WINT_MAX ? 1 : -1; + + /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ + int check_UINT8_C: + (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; + int check_UINT16_C: + (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; + + /* Detect bugs in OpenBSD 3.9 stdint.h. */ +#ifdef UINT8_MAX + int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; +#endif +#ifdef UINT16_MAX + int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; +#endif +#ifdef UINT32_MAX + int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; +#endif +#ifdef UINT64_MAX + int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; +#endif + int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; + int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; + int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; + int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; + int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; + int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; + int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; + int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; + int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; + int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; + int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; +}; + ]])], + [gl_cv_header_working_stdint_h=yes])]) + fi + if test "$gl_cv_header_working_stdint_h" = yes; then + STDINT_H= + else + dnl Check for , and for + dnl (used in Linux libc4 >= 4.6.7 and libc5). + AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) + if test $ac_cv_header_sys_inttypes_h = yes; then + HAVE_SYS_INTTYPES_H=1 + else + HAVE_SYS_INTTYPES_H=0 + fi + AC_SUBST([HAVE_SYS_INTTYPES_H]) + if test $ac_cv_header_sys_bitypes_h = yes; then + HAVE_SYS_BITYPES_H=1 + else + HAVE_SYS_BITYPES_H=0 + fi + AC_SUBST([HAVE_SYS_BITYPES_H]) + + gl_STDINT_TYPE_PROPERTIES + STDINT_H=stdint.h + fi + AC_SUBST(STDINT_H) +]) + +dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) +dnl Determine the size of each of the given types in bits. +AC_DEFUN([gl_STDINT_BITSIZEOF], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to the number of bits in type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], + [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], + [$2 +#include ], [result=unknown]) + eval gl_cv_bitsizeof_${gltype}=\$result + ]) + eval result=\$gl_cv_bitsizeof_${gltype} + if test $result = unknown; then + dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, + dnl do a syntax check even on unused #if conditions and give an error + dnl on valid C code like this: + dnl #if 0 + dnl # if > 32 + dnl # endif + dnl #endif + result=0 + fi + GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) + eval BITSIZEOF_${GLTYPE}=\$result + done + AC_FOREACH([gltype], [$1], + [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) +dnl Determine the signedness of each of the given types. +dnl Define HAVE_SIGNED_TYPE if type is signed. +AC_DEFUN([gl_CHECK_TYPES_SIGNED], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to 1 if ']gltype[' is a signed integer type.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2[ + int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], + result=yes, result=no) + eval gl_cv_type_${gltype}_signed=\$result + ]) + eval result=\$gl_cv_type_${gltype}_signed + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + if test "$result" = yes; then + AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1) + eval HAVE_SIGNED_${GLTYPE}=1 + else + eval HAVE_SIGNED_${GLTYPE}=0 + fi + done + AC_FOREACH([gltype], [$1], + [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) +dnl Determine the suffix to use for integer constants of the given types. +dnl Define t_SUFFIX for each such type. +AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], + [Define to l, ll, u, ul, ull, etc., as suitable for + constants of type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for $gltype integer literal suffix], + [gl_cv_type_${gltype}_suffix], + [eval gl_cv_type_${gltype}_suffix=no + eval result=\$gl_cv_type_${gltype}_signed + if test "$result" = yes; then + glsufu= + else + glsufu=u + fi + for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do + case $glsuf in + '') gltype1='int';; + l) gltype1='long int';; + ll) gltype1='long long int';; + i64) gltype1='__int64';; + u) gltype1='unsigned int';; + ul) gltype1='unsigned long int';; + ull) gltype1='unsigned long long int';; + ui64)gltype1='unsigned __int64';; + esac + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2 + extern $gltype foo; + extern $gltype1 foo;])], + [eval gl_cv_type_${gltype}_suffix=\$glsuf]) + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" != no && break + done]) + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" = no && result= + eval ${GLTYPE}_SUFFIX=\$result + AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], $result) + done + AC_FOREACH([gltype], [$1], + [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) +]) + +dnl gl_STDINT_INCLUDES +AC_DEFUN([gl_STDINT_INCLUDES], +[[ + /* BSD/OS 4.0.1 has a bug: , and must be + included before . */ + #include + #include + #include + #include + #include +]]) + +dnl gl_STDINT_TYPE_PROPERTIES +dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t +dnl of interest to stdint_.h. +AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], +[ + gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_cv_type_ptrdiff_t_signed=yes + gl_cv_type_size_t_signed=no + gl_INTEGER_TYPE_SUFFIX([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) + +# Hey Emacs! +# Local Variables: +# indent-tabs-mode: nil +# End: diff --git a/m4/stdint_h.m4 b/gl/m4/stdint_h.m4 similarity index 85% rename from m4/stdint_h.m4 rename to gl/m4/stdint_h.m4 index 3355f35..db9a8ac 100644 --- a/m4/stdint_h.m4 +++ b/gl/m4/stdint_h.m4 @@ -1,5 +1,5 @@ -# stdint_h.m4 serial 5 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. +# stdint_h.m4 serial 6 +dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -15,7 +15,7 @@ AC_DEFUN([gl_AC_HEADER_STDINT_H], [AC_TRY_COMPILE( [#include #include ], - [uintmax_t i = (uintmax_t) -1;], + [uintmax_t i = (uintmax_t) -1; return !i;], gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)]) 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 @@ +# strcase.m4 serial 4 +dnl Copyright (C) 2002, 2005-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STRCASE], +[ + gl_FUNC_STRCASECMP + gl_FUNC_STRNCASECMP +]) + +AC_DEFUN([gl_FUNC_STRCASECMP], +[ + dnl No known system has a strcasecmp() function that works correctly in + dnl multibyte locales. Therefore we use our version always. + AC_LIBOBJ(strcasecmp) + gl_PREREQ_STRCASECMP +]) + +AC_DEFUN([gl_FUNC_STRNCASECMP], +[ + AC_REPLACE_FUNCS(strncasecmp) + AC_CHECK_DECLS(strncasecmp) + if test $ac_cv_func_strncasecmp = no; then + gl_PREREQ_STRNCASECMP + fi +]) + +# Prerequisites of lib/strcasecmp.c. +AC_DEFUN([gl_PREREQ_STRCASECMP], [ + AC_REQUIRE([gl_FUNC_MBRTOWC]) + : +]) + +# Prerequisites of lib/strncasecmp.c. +AC_DEFUN([gl_PREREQ_STRNCASECMP], [ + : +]) 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 @@ +# strdup.m4 serial 7 +dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRDUP], +[ + AC_REPLACE_FUNCS(strdup) + AC_CHECK_DECLS_ONCE(strdup) + gl_PREREQ_STRDUP +]) + +# Prerequisites of lib/strdup.c. +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 @@ +# strndup.m4 serial 11 +dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRNDUP], +[ + dnl Persuade glibc to declare strndup(). + AC_REQUIRE([AC_GNU_SOURCE]) + + AC_CHECK_DECLS_ONCE([strndup]) + + # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. + AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup, + [AC_RUN_IFELSE([ + AC_LANG_PROGRAM([#include + #include ], [[ +#ifndef HAVE_DECL_STRNDUP + extern char *strndup (const char *, size_t); +#endif + char *s; + s = strndup ("some longer string", 15); + free (s); + s = strndup ("shorter string", 13); + return s[13] != '\0';]])], + [gl_cv_func_strndup=yes], + [gl_cv_func_strndup=no], + [AC_CHECK_FUNC([strndup], + [AC_EGREP_CPP([too risky], [ +#ifdef _AIX + too risky +#endif + ], + [gl_cv_func_strndup=no], + [gl_cv_func_strndup=yes])], + [gl_cv_func_strndup=no])])]) + if test $gl_cv_func_strndup = yes; then + AC_DEFINE([HAVE_STRNDUP], 1, + [Define if you have the strndup() function and it works.]) + else + AC_LIBOBJ([strndup]) + gl_PREREQ_STRNDUP + fi +]) + +# Prerequisites of lib/strndup.c. +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 @@ +# strnlen.m4 serial 6 +dnl Copyright (C) 2002-2003, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRNLEN], +[ + dnl Persuade glibc to declare strnlen(). + AC_REQUIRE([AC_GNU_SOURCE]) + + AC_FUNC_STRNLEN + if test $ac_cv_func_strnlen_working = no; then + # This is necessary because automake-1.6.1 doens't understand + # that the above use of AC_FUNC_STRNLEN means we may have to use + # lib/strnlen.c. + #AC_LIBOBJ(strnlen) + AC_DEFINE(strnlen, rpl_strnlen, + [Define to rpl_strnlen if the replacement function should be used.]) + gl_PREREQ_STRNLEN + fi +]) + +# Prerequisites of lib/strnlen.c. +AC_DEFUN([gl_PREREQ_STRNLEN], [ + AC_CHECK_DECLS_ONCE(strnlen) +]) diff --git a/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 @@ +# sys_socket_h.m4 serial 2 +dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson. + +AC_DEFUN([gl_HEADER_SYS_SOCKET], +[ + AC_CHECK_HEADERS_ONCE([sys/socket.h]) + if test $ac_cv_header_sys_socket_h = yes; then + SYS_SOCKET_H='' + else + dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make + dnl the check for those headers unconditional; yet cygwin reports + dnl that the headers are present but cannot be compiled (since on + dnl cygwin, all socket information should come from sys/socket.h). + AC_CHECK_HEADERS([winsock2.h ws2tcpip.h]) + SYS_SOCKET_H='sys/socket.h' + fi + AC_SUBST(SYS_SOCKET_H) +]) diff --git a/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4 similarity index 100% rename from m4/uintmax_t.m4 rename to 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 @@ +# ulonglong.m4 serial 6 +dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. +# This fixes a bug in Autoconf 2.60, but can be removed once we +# assume 2.61 everywhere. + +# Note: If the type 'unsigned long long int' exists but is only 32 bits +# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT +# will not be defined. In this case you can treat 'unsigned long long int' +# like 'unsigned long int'. + +AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], +[ + AC_CACHE_CHECK([for unsigned long long int], + [ac_cv_type_unsigned_long_long_int], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[unsigned long long int ull = 18446744073709551615ULL; + typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 + ? 1 : -1)]; + int i = 63;]], + [[unsigned long long int ullmax = 18446744073709551615ull; + return (ull << 63 | ull >> 63 | ull << i | ull >> i + | ullmax / ull | ullmax % ull);]])], + [ac_cv_type_unsigned_long_long_int=yes], + [ac_cv_type_unsigned_long_long_int=no])]) + if test $ac_cv_type_unsigned_long_long_int = yes; then + AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, + [Define to 1 if the system has the type `unsigned long long int'.]) + fi +]) + +# This macro is obsolescent and should go away soon. +AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], +[ + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int + if test $ac_cv_type_unsigned_long_long = yes; then + AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, + [Define if you have the 'unsigned long long' type.]) + fi +]) diff --git a/m4/unistd-safer.m4 b/gl/m4/unistd-safer.m4 similarity index 66% rename from m4/unistd-safer.m4 rename to gl/m4/unistd-safer.m4 index 6fbe4c6..09adf93 100644 --- a/m4/unistd-safer.m4 +++ b/gl/m4/unistd-safer.m4 @@ -1,12 +1,12 @@ -#serial 7 -dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc. +#serial 8 +dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_UNISTD_SAFER], [ - AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h]) + AC_CHECK_FUNCS_ONCE([pipe]) AC_LIBOBJ([dup-safer]) AC_LIBOBJ([fd-safer]) 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 @@ +# unistd_h.m4 serial 3 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Simon Josefsson + +AC_DEFUN([gl_HEADER_UNISTD], +[ + AC_CHECK_HEADERS([unistd.h], [ + UNISTD_H='' + ], [ + UNISTD_H='unistd.h' + ]) + AC_SUBST(UNISTD_H) + dnl This module decides to build unistd.h if it is missing. + dnl The fchdir module decides to build unistd.h if fchdir() is missing. + dnl Therefore check for the prerequisites of lib/unistd.h always. + gl_PREREQ_UNISTD +]) + +dnl Prerequisites of lib/unistd.h. +AC_DEFUN([gl_PREREQ_UNISTD], +[ + AC_CHECK_HEADERS_ONCE([unistd.h]) + if test $ac_cv_header_unistd_h = yes; then + gl_ABSOLUTE_HEADER([unistd.h]) + ABSOLUTE_UNISTD_H=\"$gl_cv_absolute_unistd_h\" + fi + AC_SUBST([ABSOLUTE_UNISTD_H]) +]) 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 @@ +# vasnprintf.m4 serial 7 +dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_VASNPRINTF], +[ + AC_REQUIRE([gl_EOVERFLOW]) + AC_REPLACE_FUNCS(vasnprintf) + if test $ac_cv_func_vasnprintf = no; then + AC_LIBOBJ(printf-args) + AC_LIBOBJ(printf-parse) + AC_LIBOBJ(asnprintf) + gl_PREREQ_PRINTF_ARGS + gl_PREREQ_PRINTF_PARSE + gl_PREREQ_VASNPRINTF + gl_PREREQ_ASNPRINTF + fi +]) + +# Prequisites of lib/printf-args.h, lib/printf-args.c. +AC_DEFUN([gl_PREREQ_PRINTF_ARGS], +[ + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_LONGDOUBLE]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) +]) + +# Prequisites of lib/printf-parse.h, lib/printf-parse.c. +AC_DEFUN([gl_PREREQ_PRINTF_PARSE], +[ + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_LONGDOUBLE]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + AC_REQUIRE([AC_TYPE_SIZE_T]) + AC_CHECK_TYPES(ptrdiff_t) + AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) +]) + +# Prerequisites of lib/vasnprintf.c. +AC_DEFUN([gl_PREREQ_VASNPRINTF], +[ + AC_REQUIRE([AC_FUNC_ALLOCA]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_LONGDOUBLE]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + AC_CHECK_FUNCS(snprintf wcslen) +]) + +# Prerequisites of lib/asnprintf.c. +AC_DEFUN([gl_PREREQ_ASNPRINTF], +[ +]) 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 @@ +# vasprintf.m4 serial 2 +dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_VASPRINTF], +[ + AC_REPLACE_FUNCS(vasprintf) + if test $ac_cv_func_vasprintf = no; then + AC_LIBOBJ(asprintf) + gl_PREREQ_VASPRINTF_H + gl_PREREQ_VASPRINTF + gl_PREREQ_ASPRINTF + fi +]) + +# Prerequisites of lib/vasprintf.h. +AC_DEFUN([gl_PREREQ_VASPRINTF_H], +[ + dnl Persuade glibc to declare asprintf() and vasprintf(). + AC_REQUIRE([AC_GNU_SOURCE]) +]) + +# Prerequisites of lib/vasprintf.c. +AC_DEFUN([gl_PREREQ_VASPRINTF], +[ +]) + +# Prerequisites of lib/asprintf.c. +AC_DEFUN([gl_PREREQ_ASPRINTF], +[ +]) 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 @@ +# visibility.m4 serial 1 (gettext-0.15) +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Tests whether the compiler supports the command-line option +dnl -fvisibility=hidden and the function and variable attributes +dnl __attribute__((__visibility__("hidden"))) and +dnl __attribute__((__visibility__("default"))). +dnl Does *not* test for __visibility__("protected") - which has tricky +dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on +dnl MacOS X. +dnl Does *not* test for __visibility__("internal") - which has processor +dnl dependent semantics. +dnl Does *not* test for #pragma GCC visibility push(hidden) - which is +dnl "really only recommended for legacy code". +dnl Set the variable CFLAG_VISIBILITY. +dnl Defines and sets the variable HAVE_VISIBILITY. + +AC_DEFUN([gl_VISIBILITY], +[ + AC_REQUIRE([AC_PROG_CC]) + CFLAG_VISIBILITY= + HAVE_VISIBILITY=0 + if test -n "$GCC"; then + AC_MSG_CHECKING([for simple visibility declarations]) + AC_CACHE_VAL(gl_cv_cc_visibility, [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fvisibility=hidden" + AC_TRY_COMPILE( + [extern __attribute__((__visibility__("hidden"))) int hiddenvar; + extern __attribute__((__visibility__("default"))) int exportedvar; + extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); + extern __attribute__((__visibility__("default"))) int exportedfunc (void);], + [], + gl_cv_cc_visibility=yes, + gl_cv_cc_visibility=no) + CFLAGS="$gl_save_CFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_visibility]) + if test $gl_cv_cc_visibility = yes; then + CFLAG_VISIBILITY="-fvisibility=hidden" + HAVE_VISIBILITY=1 + fi + fi + AC_SUBST([CFLAG_VISIBILITY]) + AC_SUBST([HAVE_VISIBILITY]) + AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], + [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) +]) 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 @@ +# vsnprintf.m4 serial 2 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_VSNPRINTF], +[ + AC_REPLACE_FUNCS(vsnprintf) + AC_CHECK_DECLS_ONCE(vsnprintf) + gl_PREREQ_VSNPRINTF +]) + +# Prerequisites of lib/vsnprintf.c. +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 @@ +dnl A placeholder for ISO C99 , for platforms that have issues. + +dnl Copyright (C) 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Eric Blake. + +# wchar.m4 serial 1 + +AC_DEFUN([gl_WCHAR_H], +[ + AC_CACHE_CHECK([whether is standalone], + [gl_cv_header_wchar_h_standalone], + [AC_COMPILE_IFELSE([[#include +wchar_t w;]], + [gl_cv_header_wchar_h_standalone=yes], + [gl_cv_header_wchar_h_standalone=no])]) + if test $gl_cv_header_wchar_h_standalone = yes; then + WCHAR_H= + else + gl_ABSOLUTE_HEADER([wchar.h]) + ABSOLUTE_WCHAR_H=\"$gl_cv_absolute_wchar_h\" + WCHAR_H=wchar.h + fi + AC_SUBST([ABSOLUTE_WCHAR_H]) + AC_SUBST([WCHAR_H]) +]) diff --git a/m4/wchar_t.m4 b/gl/m4/wchar_t.m4 similarity index 100% rename from m4/wchar_t.m4 rename to 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 @@ +dnl A placeholder for ISO C99 , for platforms that lack it. + +dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_WCTYPE_H], +[ + AC_CHECK_FUNCS_ONCE([iswcntrl]) + AC_CHECK_HEADERS_ONCE([wctype.h]) + AC_REQUIRE([AC_C_INLINE]) + + AC_REQUIRE([gt_TYPE_WINT_T]) + if test $gt_cv_c_wint_t = yes; then + HAVE_WINT_T=1 + else + HAVE_WINT_T=0 + fi + AC_SUBST([HAVE_WINT_T]) + + WCTYPE_H=wctype.h + if test $ac_cv_header_wctype_h = yes; then + if test "$ac_cv_func_iswcntrl" = yes; then + WCTYPE_H= + fi + dnl Compute ABSOLUTE_WCTYPE_H even if WCTYPE_H is empty, + dnl for the benefit of builds from non-distclean directories. + gl_ABSOLUTE_HEADER([wctype.h]) + ABSOLUTE_WCTYPE_H=\"$gl_cv_absolute_wctype_h\" + HAVE_WCTYPE_H=1 + else + ABSOLUTE_WCTYPE_H=\"no/such/file/wctype.h\" + HAVE_WCTYPE_H=0 + fi + AC_SUBST([ABSOLUTE_WCTYPE_H]) + AC_SUBST([HAVE_WCTYPE_H]) + AC_SUBST([WCTYPE_H]) +]) 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 @@ +# wcwidth.m4 serial 8 +dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_WCWIDTH], +[ + dnl Persuade glibc to declare wcwidth(). + AC_REQUIRE([AC_GNU_SOURCE]) + + AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + + AC_CHECK_HEADERS_ONCE([wchar.h]) + AC_CHECK_FUNCS_ONCE([wcwidth]) + + AC_CHECK_DECLS([wcwidth], [], [], [ +/* AIX 3.2.5 declares wcwidth in . */ +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include +])]) diff --git a/m4/wint_t.m4 b/gl/m4/wint_t.m4 similarity index 59% rename from m4/wint_t.m4 rename to gl/m4/wint_t.m4 index b8fff9c..3706c04 100644 --- a/m4/wint_t.m4 +++ b/gl/m4/wint_t.m4 @@ -1,5 +1,5 @@ -# wint_t.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2003 Free Software Foundation, Inc. +# wint_t.m4 serial 2 (gettext-0.12) +dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -11,7 +11,15 @@ dnl Prerequisite: AC_PROG_CC AC_DEFUN([gt_TYPE_WINT_T], [ AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, - [AC_TRY_COMPILE([#include + [AC_TRY_COMPILE([ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include wint_t foo = (wchar_t)'\0';], , gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) if test $gt_cv_c_wint_t = yes; then diff --git a/m4/xalloc.m4 b/gl/m4/xalloc.m4 similarity index 72% rename from m4/xalloc.m4 rename to gl/m4/xalloc.m4 index c0847dd..837a948 100644 --- a/m4/xalloc.m4 +++ b/gl/m4/xalloc.m4 @@ -1,12 +1,11 @@ -# xalloc.m4 serial 12 -dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +# xalloc.m4 serial 16 +dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_XALLOC], [ - AC_LIBSOURCES([xmalloc.c, xalloc.h]) AC_LIBOBJ([xmalloc]) gl_PREREQ_XALLOC @@ -15,11 +14,11 @@ AC_DEFUN([gl_XALLOC], # Prerequisites of lib/xalloc.h. AC_DEFUN([gl_PREREQ_XALLOC], [ + AC_REQUIRE([gl_INLINE]) : ]) # Prerequisites of lib/xmalloc.c. AC_DEFUN([gl_PREREQ_XMALLOC], [ - AC_REQUIRE([AC_C_INLINE]) : ]) 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 @@ +# xsize.m4 serial 3 +dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_XSIZE], +[ + dnl Prerequisites of lib/xsize.h. + AC_REQUIRE([gl_SIZE_MAX]) + AC_REQUIRE([AC_C_INLINE]) + AC_CHECK_HEADERS(stdint.h) +]) 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 @@ +# xstrndup.m4 serial 2 +dnl Copyright (C) 2003 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_XSTRNDUP], +[ + gl_PREREQ_XSTRNDUP +]) + +# Prerequisites of lib/xstrndup.c. +AC_DEFUN([gl_PREREQ_XSTRNDUP], [ + : +]) diff --git a/lib/malloc.c b/gl/malloc.c similarity index 90% rename from lib/malloc.c rename to gl/malloc.c index 58fa611..d4dae3e 100644 --- a/lib/malloc.c +++ b/gl/malloc.c @@ -1,5 +1,6 @@ /* malloc() function that is glibc compatible. - Copyright (C) 1997, 1998 Free Software Foundation, Inc. + + Copyright (C) 1997, 1998, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +18,7 @@ /* written by Jim Meyering */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #undef malloc #include diff --git a/lib/xstrdup.c b/gl/mbchar.c similarity index 58% rename from lib/xstrdup.c rename to gl/mbchar.c index 58f18be..95373f5 100644 --- a/lib/xstrdup.c +++ b/gl/mbchar.c @@ -1,5 +1,4 @@ -/* xstrdup.c -- copy a string with out of memory checking - Copyright (C) 1990, 1996, 1998, 2001, 2003 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,19 +14,23 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if HAVE_CONFIG_H -# include -#endif -/* Specification. */ -#include "xalloc.h" +#include -#include +#include -/* Return a newly allocated copy of STRING. */ +#include "mbchar.h" -char * -xstrdup (const char *string) +#if IS_BASIC_ASCII + +/* Bit table of characters in the ISO C "basic character set". */ +const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = { - return xclone (string, strlen (string) + 1); -} + 0x00001a00, /* '\t' '\v' '\f' */ + 0xffffffef, /* ' '...'#' '%'...'?' */ + 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ + 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ + /* The remaining bits are 0. */ +}; + +#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 @@ +/* Multibyte character data type. + Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Bruno Haible . */ + +/* A multibyte character is a short subsequence of a char* string, + representing a single wide character. + + We use multibyte characters instead of wide characters because of + the following goals: + 1) correct multibyte handling, i.e. operate according to the LC_CTYPE + locale, + 2) ease of maintenance, i.e. the maintainer needs not know all details + of the ISO C 99 standard, + 3) don't fail grossly if the input is not in the encoding set by the + locale, because often different encodings are in use in the same + countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...), + 4) fast in the case of ASCII characters, + 5) portability, i.e. don't make unportable assumptions about wchar_t. + + Multibyte characters are only accessed through the mb* macros. + + mb_ptr (mbc) + return a pointer to the beginning of the multibyte sequence. + + mb_len (mbc) + returns the number of bytes occupied by the multibyte sequence. + Always > 0. + + mb_iseq (mbc, sc) + returns true if mbc is the standard ASCII character sc. + + mb_isnul (mbc) + returns true if mbc is the nul character. + + mb_cmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2. + + mb_casecmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2, modulo upper/lowercase conversion. + + mb_equal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal. + + mb_caseequal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion. + + mb_isalnum (mbc) + returns true if mbc is alphanumeric. + + mb_isalpha (mbc) + returns true if mbc is alphabetic. + + mb_isascii(mbc) + returns true if mbc is plain ASCII. + + mb_isblank (mbc) + returns true if mbc is a blank. + + mb_iscntrl (mbc) + returns true if mbc is a control character. + + mb_isdigit (mbc) + returns true if mbc is a decimal digit. + + mb_isgraph (mbc) + returns true if mbc is a graphic character. + + mb_islower (mbc) + returns true if mbc is lowercase. + + mb_isprint (mbc) + returns true if mbc is a printable character. + + mb_ispunct (mbc) + returns true if mbc is a punctuation character. + + mb_isspace (mbc) + returns true if mbc is a space character. + + mb_isupper (mbc) + returns true if mbc is uppercase. + + mb_isxdigit (mbc) + returns true if mbc is a hexadecimal digit. + + mb_width (mbc) + returns the number of columns on the output device occupied by mbc. + Always >= 0. + + mb_putc (mbc, stream) + outputs mbc on stream, a byte oriented FILE stream opened for output. + + mb_setascii (&mbc, sc) + assigns the standard ASCII character sc to mbc. + + mb_copy (&destmbc, &srcmbc) + copies srcmbc to destmbc. + + Here are the function prototypes of the macros. + + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern void mb_setascii (mbchar_t *new, char sc); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); + */ + +#ifndef _MBCHAR_H +#define _MBCHAR_H 1 + +#include +#include + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.1 has a bug: and must be included before + . */ +#include +#include +#include +#include + +#include "wcwidth.h" + +#define MBCHAR_BUF_SIZE 24 + +struct mbchar +{ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ + char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ +}; + +/* EOF (not a real character) is represented with bytes = 0 and + wc_valid = false. */ + +typedef struct mbchar mbchar_t; + +/* Access the current character. */ +#define mb_ptr(mbc) ((mbc).ptr) +#define mb_len(mbc) ((mbc).bytes) + +/* Comparison of characters. */ +#define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) +#define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) +#define mb_cmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_casecmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_equal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) +#define mb_caseequal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) + +/* , classification. */ +#define mb_isascii(mbc) \ + ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127) +#define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc)) +#define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc)) +#define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc)) +#define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc)) +#define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc)) +#define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc)) +#define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc)) +#define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc)) +#define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc)) +#define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc)) +#define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc)) +#define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc)) + +/* Extra function. */ + +/* Unprintable characters appear as a small box of width 1. */ +#define MB_UNPRINTABLE_WIDTH 1 + +static inline int +mb_width_aux (wint_t wc) +{ + int w = wcwidth (wc); + /* For unprintable characters, arbitrarily return 0 for control characters + and MB_UNPRINTABLE_WIDTH otherwise. */ + return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH); +} + +#define mb_width(mbc) \ + ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH) + +/* Output. */ +#define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream)) + +/* Assignment. */ +#define mb_setascii(mbc, sc) \ + ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \ + (mbc)->wc = (mbc)->buf[0] = (sc)) + +/* Copying a character. */ +static inline void +mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) +{ + if (old_mbc->ptr == &old_mbc->buf[0]) + { + memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); + new_mbc->ptr = &new_mbc->buf[0]; + } + else + new_mbc->ptr = old_mbc->ptr; + new_mbc->bytes = old_mbc->bytes; + if ((new_mbc->wc_valid = old_mbc->wc_valid)) + new_mbc->wc = old_mbc->wc; +} + + +/* is_basic(c) tests whether the single-byte character c is in the + ISO C "basic character set". + This is a convenience function, and is in this file only to share code + between mbiter_multi.h and mbfile_multi.h. */ +#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) +/* The character set is ISO-646, not EBCDIC. */ +# define IS_BASIC_ASCII 1 + +extern const unsigned int is_basic_table[]; + +static inline bool +is_basic (char c) +{ + return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) + & 1; +} + +#else + +static inline bool +is_basic (char c) +{ + switch (c) + { + case '\t': case '\v': case '\f': + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + return 1; + default: + return 0; + } +} + +#endif + +#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 @@ +/* Iterating through multibyte strings: macros for multi-byte encodings. + Copyright (C) 2001, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Bruno Haible . */ + +/* The macros in this file implement forward iteration through a + multi-byte string, without knowing its length a-priori. + + With these macros, an iteration loop that looks like + + char *iter; + for (iter = buf; *iter != '\0'; iter++) + { + do_something (*iter); + } + + becomes + + mbui_iterator_t iter; + for (mbui_init (iter, buf); mbui_avail (iter); mbui_advance (iter)) + { + do_something (mbui_cur_ptr (iter), mb_len (mbui_cur (iter))); + } + + The benefit of these macros over plain use of mbrtowc is: + - Handling of invalid multibyte sequences is possible without + making the code more complicated, while still preserving the + invalid multibyte sequences. + + Compared to mbiter.h, the macros here don't need to know the string's + length a-priori. The downside is that at each step, the look-ahead + that guards against overrunning the terminating '\0' is more expensive. + The mbui_* macros are therefore suitable when there is a high probability + that only the first few multibyte characters need to be inspected. + Whereas the mbi_* macros are better if usually the iteration runs + through the entire string. + + mbui_iterator_t + is a type usable for variable declarations. + + mbui_init (iter, startptr) + initializes the iterator, starting at startptr. + + mbui_avail (iter) + returns true if there are more multibyte chracters available before + the end of string is reached. In this case, mbui_cur (iter) is + initialized to the next multibyte chracter. + + mbui_advance (iter) + advances the iterator by one multibyte character. + + mbui_cur (iter) + returns the current multibyte character, of type mbchar_t. All the + macros defined in mbchar.h can be used on it. + + mbui_cur_ptr (iter) + return a pointer to the beginning of the current multibyte character. + + mbui_reloc (iter, ptrdiff) + relocates iterator when the string is moved by ptrdiff bytes. + + Here are the function prototypes of the macros. + + extern void mbui_init (mbui_iterator_t iter, const char *startptr); + extern bool mbui_avail (mbui_iterator_t iter); + extern void mbui_advance (mbui_iterator_t iter); + extern mbchar_t mbui_cur (mbui_iterator_t iter); + extern const char * mbui_cur_ptr (mbui_iterator_t iter); + extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff); + */ + +#ifndef _MBUITER_H +#define _MBUITER_H 1 + +#include +#include +#include + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.1 has a bug: and must be included before + . */ +#include +#include +#include + +#include "mbchar.h" +#include "strnlen1.h" + +struct mbuiter_multi +{ + bool in_shift; /* true if next byte may not be interpreted as ASCII */ + mbstate_t state; /* if in_shift: current shift state */ + bool next_done; /* true if mbui_avail has already filled the following */ + struct mbchar cur; /* the current character: + const char *cur.ptr pointer to current character + The following are only valid after mbui_avail. + size_t cur.bytes number of bytes of current character + bool cur.wc_valid true if wc is a valid wide character + wchar_t cur.wc if wc_valid: the current character + */ +}; + +static inline void +mbuiter_multi_next (struct mbuiter_multi *iter) +{ + if (iter->next_done) + return; + if (iter->in_shift) + goto with_shift; + /* Handle most ASCII characters quickly, without calling mbrtowc(). */ + if (is_basic (*iter->cur.ptr)) + { + /* These characters are part of the basic character set. ISO C 99 + guarantees that their wide character code is identical to their + char code. */ + iter->cur.bytes = 1; + iter->cur.wc = *iter->cur.ptr; + iter->cur.wc_valid = true; + } + else + { + assert (mbsinit (&iter->state)); + iter->in_shift = true; + with_shift: + iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr, + strnlen1 (iter->cur.ptr, MB_CUR_MAX), + &iter->state); + if (iter->cur.bytes == (size_t) -1) + { + /* An invalid multibyte sequence was encountered. */ + iter->cur.bytes = 1; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not very important; the string is bogus anyway. */ + } + else if (iter->cur.bytes == (size_t) -2) + { + /* An incomplete multibyte character at the end. */ + iter->cur.bytes = strlen (iter->cur.ptr); + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not important; the string end is reached anyway. */ + } + else + { + if (iter->cur.bytes == 0) + { + /* A null wide character was encountered. */ + iter->cur.bytes = 1; + assert (*iter->cur.ptr == '\0'); + assert (iter->cur.wc == 0); + } + iter->cur.wc_valid = true; + + /* When in the initial state, we can go back treating ASCII + characters more quickly. */ + if (mbsinit (&iter->state)) + iter->in_shift = false; + } + } + iter->next_done = true; +} + +static inline void +mbuiter_multi_reloc (struct mbuiter_multi *iter, ptrdiff_t ptrdiff) +{ + iter->cur.ptr += ptrdiff; +} + +/* Iteration macros. */ +typedef struct mbuiter_multi mbui_iterator_t; +#define mbui_init(iter, startptr) \ + ((iter).cur.ptr = (startptr), \ + (iter).in_shift = false, memset (&(iter).state, '\0', sizeof (mbstate_t)), \ + (iter).next_done = false) +#define mbui_avail(iter) \ + (mbuiter_multi_next (&(iter)), !mb_isnul ((iter).cur)) +#define mbui_advance(iter) \ + ((iter).cur.ptr += (iter).cur.bytes, (iter).next_done = false) + +/* Access to the current character. */ +#define mbui_cur(iter) (iter).cur +#define mbui_cur_ptr(iter) (iter).cur.ptr + +/* Relocation. */ +#define mbui_reloc(iter, ptrdiff) mbuiter_multi_reloc (&iter, ptrdiff) + +#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 @@ +/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006 Free + Software Foundation, Inc. + + Based on strlen implementation by Torbjorn Granlund (tege@sics.se), + with help from Dan Sahlin (dan@sics.se) and + commentary by Jim Blandy (jimb@ai.mit.edu); + adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), + and implemented by Roland McGrath (roland@ai.mit.edu). + +NOTE: The canonical source of this file is maintained with the GNU C Library. +Bugs can be reported to bug-glibc@prep.ai.mit.edu. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _LIBC +# include +#endif + +#include + +#include + +#if defined _LIBC +# include +#else +# define reg_char char +#endif + +#include + +#if HAVE_BP_SYM_H || defined _LIBC +# include +#else +# define BP_SYM(sym) sym +#endif + +#undef memchr +#undef __memchr + +/* Search no more than N bytes of S for C. */ +void * +__memchr (void const *s, int c_in, size_t n) +{ + const unsigned char *char_ptr; + const unsigned long int *longword_ptr; + unsigned long int longword, magic_bits, charmask; + unsigned reg_char c; + int i; + + c = (unsigned char) c_in; + + /* Handle the first few characters by reading one character at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + n > 0 && (size_t) char_ptr % sizeof longword != 0; + --n, ++char_ptr) + if (*char_ptr == c) + return (void *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + longword_ptr = (const unsigned long int *) char_ptr; + + /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits + the "holes." Note that there is a hole just to the left of + each byte, with an extra at the end: + + bits: 01111110 11111110 11111110 11111111 + bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD + + The 1-bits make sure that carries propagate to the next 0-bit. + The 0-bits provide holes for carries to fall into. */ + + /* Set MAGIC_BITS to be this pattern of 1 and 0 bits. + Set CHARMASK to be a longword, each of whose bytes is C. */ + + magic_bits = 0xfefefefe; + charmask = c | (c << 8); + charmask |= charmask << 16; +#if 0xffffffffU < ULONG_MAX + magic_bits |= magic_bits << 32; + charmask |= charmask << 32; + if (8 < sizeof longword) + for (i = 64; i < sizeof longword * 8; i *= 2) + { + magic_bits |= magic_bits << i; + charmask |= charmask << i; + } +#endif + magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1); + + /* Instead of the traditional loop which tests each character, + we will test a longword at a time. The tricky part is testing + if *any of the four* bytes in the longword in question are zero. */ + while (n >= sizeof longword) + { + /* We tentatively exit the loop if adding MAGIC_BITS to + LONGWORD fails to change any of the hole bits of LONGWORD. + + 1) Is this safe? Will it catch all the zero bytes? + Suppose there is a byte with all zeros. Any carry bits + propagating from its left will fall into the hole at its + least significant bit and stop. Since there will be no + carry from its most significant bit, the LSB of the + byte to the left will be unchanged, and the zero will be + detected. + + 2) Is this worthwhile? Will it ignore everything except + zero bytes? Suppose every byte of LONGWORD has a bit set + somewhere. There will be a carry into bit 8. If bit 8 + is set, this will carry into bit 16. If bit 8 is clear, + one of bits 9-15 must be set, so there will be a carry + into bit 16. Similarly, there will be a carry into bit + 24. If one of bits 24-30 is set, there will be a carry + into bit 31, so all of the hole bits will be changed. + + The one misfire occurs when bits 24-30 are clear and bit + 31 is set; in this case, the hole at bit 31 is not + changed. If we had access to the processor carry flag, + we could close this loophole by putting the fourth hole + at bit 32! + + So it ignores everything except 128's, when they're aligned + properly. + + 3) But wait! Aren't we looking for C, not zero? + Good point. So what we do is XOR LONGWORD with a longword, + each of whose bytes is C. This turns each byte that is C + into a zero. */ + + longword = *longword_ptr++ ^ charmask; + + /* Add MAGIC_BITS to LONGWORD. */ + if ((((longword + magic_bits) + + /* Set those bits that were unchanged by the addition. */ + ^ ~longword) + + /* Look at only the hole bits. If any of the hole bits + are unchanged, most likely one of the bytes was a + zero. */ + & ~magic_bits) != 0) + { + /* Which of the bytes was C? If none of them were, it was + a misfire; continue the search. */ + + const unsigned char *cp = (const unsigned char *) (longword_ptr - 1); + + if (cp[0] == c) + return (void *) cp; + if (cp[1] == c) + return (void *) &cp[1]; + if (cp[2] == c) + return (void *) &cp[2]; + if (cp[3] == c) + return (void *) &cp[3]; + if (4 < sizeof longword && cp[4] == c) + return (void *) &cp[4]; + if (5 < sizeof longword && cp[5] == c) + return (void *) &cp[5]; + if (6 < sizeof longword && cp[6] == c) + return (void *) &cp[6]; + if (7 < sizeof longword && cp[7] == c) + return (void *) &cp[7]; + if (8 < sizeof longword) + for (i = 8; i < sizeof longword; i++) + if (cp[i] == c) + return (void *) &cp[i]; + } + + n -= sizeof longword; + } + + char_ptr = (const unsigned char *) longword_ptr; + + while (n-- > 0) + { + if (*char_ptr == c) + return (void *) char_ptr; + else + ++char_ptr; + } + + return 0; +} +#ifdef weak_alias +weak_alias (__memchr, BP_SYM (memchr)) +#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 @@ +/* MIN, MAX macros. + Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _MINMAX_H +#define _MINMAX_H + +/* Note: MIN, MAX are also defined in on some systems + (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about + MIN, MAX macro redefinitions on some systems; the workaround is to + #include this file as the last one among the #include list. */ + +/* Before we define the following symbols we get the file + since otherwise we get redefinitions on some systems if is + included after this file. Likewise for . + If more than one of these system headers define MIN and MAX, pick just + one of the headers (because the definitions most likely are the same). */ +#if HAVE_MINMAX_IN_LIMITS_H +# include +#elif HAVE_MINMAX_IN_SYS_PARAM_H +# include +#endif + +/* Note: MIN and MAX should be used with two arguments of the + same type. They might not return the minimum and maximum of their two + arguments, if the arguments have different types or have unusual + floating-point values. For example, on a typical host with 32-bit 'int', + 64-bit 'long long', and 64-bit IEEE 754 'double' types: + + MAX (-1, 2147483648) returns 4294967295. + MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. + MAX (NaN, 0.0) returns 0.0. + MAX (+0.0, -0.0) returns -0.0. + + and in each case the answer is in some sense bogus. */ + +/* MAX(a,b) returns the maximum of A and B. */ +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +/* MIN(a,b) returns the minimum of A and B. */ +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#endif /* _MINMAX_H */ diff --git a/lib/mountlist.c b/gl/mountlist.c similarity index 88% rename from lib/mountlist.c rename to gl/mountlist.c index a1dca0a..bb01f91 100644 --- a/lib/mountlist.c +++ b/gl/mountlist.c @@ -1,7 +1,7 @@ /* mountlist.c -- return a list of mounted file systems Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005 Free Software Foundation, Inc. + 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,12 +17,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "mountlist.h" +#include #include #include #include @@ -81,6 +80,10 @@ char *strstr (); # include #endif +#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ +# include +#endif + #ifdef MOUNTED_GETMNT /* Ultrix. */ # include # include @@ -101,11 +104,6 @@ char *strstr (); # include #endif -#ifdef STAT_STATVFS -# include -# define statfs statvfs -#endif - #ifdef MOUNTED_LISTMNTENT # include #endif @@ -145,29 +143,42 @@ char *strstr (); # define SIZE_MAX ((size_t) -1) #endif +/* The results of open() in this file are not used with fchdir, + therefore save some unnecessary work in fchdir.c. */ +#undef open +#undef close + +/* The results of opendir() in this file are not used with dirfd and fchdir, + therefore save some unnecessary work in fchdir.c. */ +#undef opendir +#undef closedir + #ifndef ME_DUMMY # define ME_DUMMY(Fs_name, Fs_type) \ (strcmp (Fs_type, "autofs") == 0 \ || strcmp (Fs_type, "none") == 0 \ || strcmp (Fs_type, "proc") == 0 \ || strcmp (Fs_type, "subfs") == 0 \ + /* for NetBSD 3.0 */ \ + || strcmp (Fs_type, "kernfs") == 0 \ /* for Irix 6.5 */ \ || strcmp (Fs_type, "ignore") == 0) #endif #ifndef ME_REMOTE /* A file system is `remote' if its Fs_name contains a `:' - or if (it is of type smbfs and its Fs_name starts with `//'). */ + or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */ # define ME_REMOTE(Fs_name, Fs_type) \ - (strchr (Fs_name, ':') != 0 \ + (strchr (Fs_name, ':') != NULL \ || ((Fs_name)[0] == '/' \ && (Fs_name)[1] == '/' \ - && strcmp (Fs_type, "smbfs") == 0)) + && (strcmp (Fs_type, "smbfs") == 0 \ + || strcmp (Fs_type, "cifs") == 0))) #endif #if MOUNTED_GETMNTINFO -# if ! HAVE_F_FSTYPENAME_IN_STATFS && ! STAT_STATVFS +# if ! HAVE_STRUCT_STATFS_F_FSTYPENAME static char * fstype_to_string (short int t) { @@ -261,13 +272,12 @@ fstype_to_string (short int t) return "?"; } } -# endif /* ! HAVE_F_FSTYPENAME_IN_STATFS */ +# endif -/* __NetBSD__ || BSD_NET2 || __OpenBSD__ */ static char * fsp_to_string (const struct statfs *fsp) { -# if defined HAVE_F_FSTYPENAME_IN_STATFS || defined STAT_STATVFS +# if HAVE_STRUCT_STATFS_F_FSTYPENAME return (char *) (fsp->f_fstypename); # else return fstype_to_string (fsp->f_type); @@ -290,6 +300,44 @@ fstype_to_string (int t) } #endif /* MOUNTED_VMOUNT */ + +#if defined MOUNTED_GETMNTENT1 || defined MOUNTED_GETMNTENT2 + +/* Return the device number from MOUNT_OPTIONS, if possible. + Otherwise return (dev_t) -1. */ + +static dev_t +dev_from_mount_options (char const *mount_options) +{ + /* GNU/Linux allows file system implementations to define their own + meaning for "dev=" mount options, so don't trust the meaning + here. */ +# ifndef __linux__ + + static char const dev_pattern[] = ",dev="; + char const *devopt = strstr (mount_options, dev_pattern); + + if (devopt) + { + char const *optval = devopt + sizeof dev_pattern - 1; + char *optvalend; + unsigned long int dev; + errno = 0; + dev = strtoul (optval, &optvalend, 16); + if (optval != optvalend + && (*optvalend == '\0' || *optvalend == ',') + && ! (dev == ULONG_MAX && errno == ERANGE) + && dev == (dev_t) dev) + return dev; + } + +# endif + + return -1; +} + +#endif + /* Return a list of the currently mounted file systems, or NULL on error. Add each entry to the tail of the list so that they stay in order. 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) } #endif -#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ +#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ { struct mntent *mnt; char *table = MOUNTED; FILE *fp; - char *devopt; fp = setmntent (table, "r"); if (fp == NULL) @@ -352,11 +399,7 @@ read_file_system_list (bool need_fs_type) me->me_type_malloced = 1; me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - devopt = strstr (mnt->mnt_opts, "dev="); - if (devopt) - me->me_dev = strtoul (devopt + 4, NULL, 16); - else - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + me->me_dev = dev_from_mount_options (mnt->mnt_opts); /* Add to the linked list. */ *mtail = me; @@ -396,6 +439,32 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_GETMNTINFO */ +#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ + { + struct statvfs *fsp; + int entries; + + entries = getmntinfo (&fsp, MNT_NOWAIT); + if (entries < 0) + return NULL; + for (; entries-- > 0; fsp++) + { + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (fsp->f_mntfromname); + me->me_mountdir = xstrdup (fsp->f_mntonname); + me->me_type = xstrdup (fsp->f_fstypename); + me->me_type_malloced = 1; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; + } + } +#endif /* MOUNTED_GETMNTINFO2 */ + #ifdef MOUNTED_GETMNT /* Ultrix. */ { int offset = 0; @@ -630,7 +699,7 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ -#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */ +#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ { struct mntent **mnttbl = getmnttbl (), **ent; for (ent=mnttbl;*ent;ent++) @@ -704,7 +773,7 @@ read_file_system_list (bool need_fs_type) me->me_type_malloced = 1; me->me_dummy = MNT_IGNORE (&mnt) != 0; me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); /* Add to the linked list. */ *mtail = me; diff --git a/lib/mountlist.h b/gl/mountlist.h similarity index 100% rename from lib/mountlist.h rename to gl/mountlist.h diff --git a/lib/open-safer.c b/gl/open-safer.c similarity index 93% rename from lib/open-safer.c rename to gl/open-safer.c index d3ba894..04a72eb 100644 --- a/lib/open-safer.c +++ b/gl/open-safer.c @@ -1,5 +1,6 @@ /* Invoke open, but avoid some glitches. - Copyright (C) 2005 Free Software Foundation, Inc. + + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +18,7 @@ /* Written by Paul Eggert. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "fcntl-safer.h" diff --git a/lib/pipe-safer.c b/gl/pipe-safer.c similarity index 65% rename from lib/pipe-safer.c rename to gl/pipe-safer.c index fb02d72..e4431b3 100644 --- a/lib/pipe-safer.c +++ b/gl/pipe-safer.c @@ -1,5 +1,5 @@ /* Invoke pipe, but avoid some glitches. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,34 +17,41 @@ /* Written by Jim Meyering. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "unistd-safer.h" #include +#include /* Like pipe, but ensure that neither of the file descriptors is - STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ + STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. Fail with ENOSYS on + platforms that lack pipe. */ int pipe_safer (int fd[2]) { - int fail = pipe (fd); - if (fail) - return fail; - - { - int i; - for (i = 0; i < 2; i++) - { - int f = fd_safer (fd[i]); - if (f < 0) - return -1; - fd[i] = f; - } - } - - return 0; +#if HAVE_PIPE + if (pipe (fd) == 0) + { + int i; + for (i = 0; i < 2; i++) + { + fd[i] = fd_safer (fd[i]); + if (fd[i] < 0) + { + int e = errno; + close (fd[1 - i]); + errno = e; + return -1; + } + } + + return 0; + } +#else + errno = ENOSYS; +#endif + + return -1; } 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 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002-2003, 2005-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "printf-args.h" + +#ifdef STATIC +STATIC +#endif +int +printf_fetchargs (va_list args, arguments *a) +{ + size_t i; + argument *ap; + + for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) + switch (ap->type) + { + case TYPE_SCHAR: + ap->a.a_schar = va_arg (args, /*signed char*/ int); + break; + case TYPE_UCHAR: + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; + case TYPE_SHORT: + ap->a.a_short = va_arg (args, /*short*/ int); + break; + case TYPE_USHORT: + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; + case TYPE_INT: + ap->a.a_int = va_arg (args, int); + break; + case TYPE_UINT: + ap->a.a_uint = va_arg (args, unsigned int); + break; + case TYPE_LONGINT: + ap->a.a_longint = va_arg (args, long int); + break; + case TYPE_ULONGINT: + ap->a.a_ulongint = va_arg (args, unsigned long int); + break; +#ifdef HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + ap->a.a_longlongint = va_arg (args, long long int); + break; + case TYPE_ULONGLONGINT: + ap->a.a_ulonglongint = va_arg (args, unsigned long long int); + break; +#endif + case TYPE_DOUBLE: + ap->a.a_double = va_arg (args, double); + break; +#ifdef HAVE_LONG_DOUBLE + case TYPE_LONGDOUBLE: + ap->a.a_longdouble = va_arg (args, long double); + break; +#endif + case TYPE_CHAR: + ap->a.a_char = va_arg (args, int); + break; +#ifdef HAVE_WINT_T + case TYPE_WIDE_CHAR: + /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by + default argument promotions", this is not the case in mingw32, + where wint_t is 'unsigned short'. */ + ap->a.a_wide_char = + (sizeof (wint_t) < sizeof (int) + ? va_arg (args, int) + : va_arg (args, wint_t)); + break; +#endif + case TYPE_STRING: + ap->a.a_string = va_arg (args, const char *); + /* A null pointer is an invalid argument for "%s", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_string == NULL) + ap->a.a_string = "(NULL)"; + break; +#ifdef HAVE_WCHAR_T + case TYPE_WIDE_STRING: + ap->a.a_wide_string = va_arg (args, const wchar_t *); + /* A null pointer is an invalid argument for "%ls", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_wide_string == NULL) + { + static const wchar_t wide_null_string[] = + { + (wchar_t)'(', + (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', + (wchar_t)')', + (wchar_t)0 + }; + ap->a.a_wide_string = wide_null_string; + } + break; +#endif + case TYPE_POINTER: + ap->a.a_pointer = va_arg (args, void *); + break; + case TYPE_COUNT_SCHAR_POINTER: + ap->a.a_count_schar_pointer = va_arg (args, signed char *); + break; + case TYPE_COUNT_SHORT_POINTER: + ap->a.a_count_short_pointer = va_arg (args, short *); + break; + case TYPE_COUNT_INT_POINTER: + ap->a.a_count_int_pointer = va_arg (args, int *); + break; + case TYPE_COUNT_LONGINT_POINTER: + ap->a.a_count_longint_pointer = va_arg (args, long int *); + break; +#ifdef HAVE_LONG_LONG_INT + case TYPE_COUNT_LONGLONGINT_POINTER: + ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); + break; +#endif + default: + /* Unknown type. */ + return -1; + } + return 0; +} 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 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002-2003, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _PRINTF_ARGS_H +#define _PRINTF_ARGS_H + +/* Get size_t. */ +#include + +/* Get wchar_t. */ +#ifdef HAVE_WCHAR_T +# include +#endif + +/* Get wint_t. */ +#ifdef HAVE_WINT_T +# include +#endif + +/* Get va_list. */ +#include + + +/* Argument types */ +typedef enum +{ + TYPE_NONE, + TYPE_SCHAR, + TYPE_UCHAR, + TYPE_SHORT, + TYPE_USHORT, + TYPE_INT, + TYPE_UINT, + TYPE_LONGINT, + TYPE_ULONGINT, +#ifdef HAVE_LONG_LONG_INT + TYPE_LONGLONGINT, + TYPE_ULONGLONGINT, +#endif + TYPE_DOUBLE, +#ifdef HAVE_LONG_DOUBLE + TYPE_LONGDOUBLE, +#endif + TYPE_CHAR, +#ifdef HAVE_WINT_T + TYPE_WIDE_CHAR, +#endif + TYPE_STRING, +#ifdef HAVE_WCHAR_T + TYPE_WIDE_STRING, +#endif + TYPE_POINTER, + TYPE_COUNT_SCHAR_POINTER, + TYPE_COUNT_SHORT_POINTER, + TYPE_COUNT_INT_POINTER, + TYPE_COUNT_LONGINT_POINTER +#ifdef HAVE_LONG_LONG_INT +, TYPE_COUNT_LONGLONGINT_POINTER +#endif +} arg_type; + +/* Polymorphic argument */ +typedef struct +{ + arg_type type; + union + { + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_longint; + unsigned long int a_ulongint; +#ifdef HAVE_LONG_LONG_INT + long long int a_longlongint; + unsigned long long int a_ulonglongint; +#endif + float a_float; + double a_double; +#ifdef HAVE_LONG_DOUBLE + long double a_longdouble; +#endif + int a_char; +#ifdef HAVE_WINT_T + wint_t a_wide_char; +#endif + const char* a_string; +#ifdef HAVE_WCHAR_T + const wchar_t* a_wide_string; +#endif + void* a_pointer; + signed char * a_count_schar_pointer; + short * a_count_short_pointer; + int * a_count_int_pointer; + long int * a_count_longint_pointer; +#ifdef HAVE_LONG_LONG_INT + long long int * a_count_longlongint_pointer; +#endif + } + a; +} +argument; + +typedef struct +{ + size_t count; + argument *arg; +} +arguments; + + +/* Fetch the arguments, putting them into a. */ +#ifdef STATIC +STATIC +#else +extern +#endif +int printf_fetchargs (va_list args, arguments *a); + +#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 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002-2003, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#if WIDE_CHAR_VERSION +# include "wprintf-parse.h" +#else +# include "printf-parse.h" +#endif + +/* Get size_t, NULL. */ +#include + +/* Get intmax_t. */ +#if HAVE_STDINT_H_WITH_UINTMAX +# include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +# include +#endif + +/* malloc(), realloc(), free(). */ +#include + +/* Checked size_t computations. */ +#include "xsize.h" + +#if WIDE_CHAR_VERSION +# define PRINTF_PARSE wprintf_parse +# define CHAR_T wchar_t +# define DIRECTIVE wchar_t_directive +# define DIRECTIVES wchar_t_directives +#else +# define PRINTF_PARSE printf_parse +# define CHAR_T char +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +#endif + +#ifdef STATIC +STATIC +#endif +int +PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) +{ + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ + size_t max_width_length = 0; + size_t max_precision_length = 0; + + d->count = 0; + d_allocated = 1; + d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); + if (d->dir == NULL) + /* Out of memory. */ + return -1; + + a->count = 0; + a_allocated = 0; + a->arg = NULL; + +#define REGISTER_ARG(_index_,_type_) \ + { \ + size_t n = (_index_); \ + if (n >= a_allocated) \ + { \ + size_t memory_size; \ + argument *memory; \ + \ + a_allocated = xtimes (a_allocated, 2); \ + if (a_allocated <= n) \ + a_allocated = xsum (n, 1); \ + memory_size = xtimes (a_allocated, sizeof (argument)); \ + if (size_overflow_p (memory_size)) \ + /* Overflow, would lead to out of memory. */ \ + goto error; \ + memory = (argument *) (a->arg \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto error; \ + a->arg = memory; \ + } \ + while (a->count <= n) \ + a->arg[a->count++].type = TYPE_NONE; \ + if (a->arg[n].type == TYPE_NONE) \ + a->arg[n].type = (_type_); \ + else if (a->arg[n].type != (_type_)) \ + /* Ambiguous type for positional argument. */ \ + goto error; \ + } + + while (*cp != '\0') + { + CHAR_T c = *cp++; + if (c == '%') + { + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ + + /* Initialize the next directive. */ + dp->dir_start = cp - 1; + dp->flags = 0; + dp->width_start = NULL; + dp->width_end = NULL; + dp->width_arg_index = ARG_NONE; + dp->precision_start = NULL; + dp->precision_end = NULL; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + arg_index = n - 1; + cp = np + 1; + } + } + + /* Read the flags. */ + for (;;) + { + if (*cp == '\'') + { + dp->flags |= FLAG_GROUP; + cp++; + } + else if (*cp == '-') + { + dp->flags |= FLAG_LEFT; + cp++; + } + else if (*cp == '+') + { + dp->flags |= FLAG_SHOWSIGN; + cp++; + } + else if (*cp == ' ') + { + dp->flags |= FLAG_SPACE; + cp++; + } + else if (*cp == '#') + { + dp->flags |= FLAG_ALT; + cp++; + } + else if (*cp == '0') + { + dp->flags |= FLAG_ZERO; + cp++; + } + else + break; + } + + /* Parse the field width. */ + if (*cp == '*') + { + dp->width_start = cp; + cp++; + dp->width_end = cp; + if (max_width_length < 1) + max_width_length = 1; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + dp->width_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->width_arg_index, TYPE_INT); + } + else if (*cp >= '0' && *cp <= '9') + { + size_t width_length; + + dp->width_start = cp; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->width_end = cp; + width_length = dp->width_end - dp->width_start; + if (max_width_length < width_length) + max_width_length = width_length; + } + + /* Parse the precision. */ + if (*cp == '.') + { + cp++; + if (*cp == '*') + { + dp->precision_start = cp - 1; + cp++; + dp->precision_end = cp; + if (max_precision_length < 2) + max_precision_length = 2; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory + later. */ + goto error; + dp->precision_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->precision_arg_index, TYPE_INT); + } + else + { + size_t precision_length; + + dp->precision_start = cp - 1; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->precision_end = cp; + precision_length = dp->precision_end - dp->precision_start; + if (max_precision_length < precision_length) + max_precision_length = precision_length; + } + } + + { + arg_type type; + + /* Parse argument type/size specifiers. */ + { + int flags = 0; + + for (;;) + { + if (*cp == 'h') + { + flags |= (1 << (flags & 1)); + cp++; + } + else if (*cp == 'L') + { + flags |= 4; + cp++; + } + else if (*cp == 'l') + { + flags += 8; + cp++; + } +#ifdef HAVE_INTMAX_T + else if (*cp == 'j') + { + if (sizeof (intmax_t) > sizeof (long)) + { + /* intmax_t = long long */ + flags += 16; + } + else if (sizeof (intmax_t) > sizeof (int)) + { + /* intmax_t = long */ + flags += 8; + } + cp++; + } +#endif + else if (*cp == 'z' || *cp == 'Z') + { + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + if (sizeof (size_t) > sizeof (long)) + { + /* size_t = long long */ + flags += 16; + } + else if (sizeof (size_t) > sizeof (int)) + { + /* size_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 't') + { + if (sizeof (ptrdiff_t) > sizeof (long)) + { + /* ptrdiff_t = long long */ + flags += 16; + } + else if (sizeof (ptrdiff_t) > sizeof (int)) + { + /* ptrdiff_t = long */ + flags += 8; + } + cp++; + } + else + break; + } + + /* Read the conversion character. */ + c = *cp++; + switch (c) + { + case 'd': case 'i': +#ifdef HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGLONGINT; + else +#endif + /* If 'long long' exists and is the same as 'long', we parse + "lld" into TYPE_LONGINT. */ + if (flags >= 8) + type = TYPE_LONGINT; + else if (flags & 2) + type = TYPE_SCHAR; + else if (flags & 1) + type = TYPE_SHORT; + else + type = TYPE_INT; + break; + case 'o': case 'u': case 'x': case 'X': +#ifdef HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_ULONGLONGINT; + else +#endif + /* If 'unsigned long long' exists and is the same as + 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + if (flags >= 8) + type = TYPE_ULONGINT; + else if (flags & 2) + type = TYPE_UCHAR; + else if (flags & 1) + type = TYPE_USHORT; + else + type = TYPE_UINT; + break; + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': +#ifdef HAVE_LONG_DOUBLE + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGDOUBLE; + else +#endif + type = TYPE_DOUBLE; + break; + case 'c': + if (flags >= 8) +#ifdef HAVE_WINT_T + type = TYPE_WIDE_CHAR; +#else + goto error; +#endif + else + type = TYPE_CHAR; + break; +#ifdef HAVE_WINT_T + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; +#endif + case 's': + if (flags >= 8) +#ifdef HAVE_WCHAR_T + type = TYPE_WIDE_STRING; +#else + goto error; +#endif + else + type = TYPE_STRING; + break; +#ifdef HAVE_WCHAR_T + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; +#endif + case 'p': + type = TYPE_POINTER; + break; + case 'n': +#ifdef HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_COUNT_LONGLONGINT_POINTER; + else +#endif + /* If 'long long' exists and is the same as 'long', we parse + "lln" into TYPE_COUNT_LONGINT_POINTER. */ + if (flags >= 8) + type = TYPE_COUNT_LONGINT_POINTER; + else if (flags & 2) + type = TYPE_COUNT_SCHAR_POINTER; + else if (flags & 1) + type = TYPE_COUNT_SHORT_POINTER; + else + type = TYPE_COUNT_INT_POINTER; + break; + case '%': + type = TYPE_NONE; + break; + default: + /* Unknown conversion character. */ + goto error; + } + } + + if (type != TYPE_NONE) + { + dp->arg_index = arg_index; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->arg_index, type); + } + dp->conversion = c; + dp->dir_end = cp; + } + + d->count++; + if (d->count >= d_allocated) + { + size_t memory_size; + DIRECTIVE *memory; + + d_allocated = xtimes (d_allocated, 2); + memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); + if (size_overflow_p (memory_size)) + /* Overflow, would lead to out of memory. */ + goto error; + memory = (DIRECTIVE *) realloc (d->dir, memory_size); + if (memory == NULL) + /* Out of memory. */ + goto error; + d->dir = memory; + } + } + } + d->dir[d->count].dir_start = cp; + + d->max_width_length = max_width_length; + d->max_precision_length = max_precision_length; + return 0; + +error: + if (a->arg) + free (a->arg); + if (d->dir) + free (d->dir); + return -1; +} + +#undef DIRECTIVES +#undef DIRECTIVE +#undef CHAR_T +#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 @@ +/* Parse printf format string. + Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _PRINTF_PARSE_H +#define _PRINTF_PARSE_H + +#include "printf-args.h" + + +/* Flags */ +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 + +/* arg_index value indicating that no argument is consumed. */ +#define ARG_NONE (~(size_t)0) + +/* A parsed directive. */ +typedef struct +{ + const char* dir_start; + const char* dir_end; + int flags; + const char* width_start; + const char* width_end; + size_t width_arg_index; + const char* precision_start; + const char* precision_end; + size_t precision_arg_index; + char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ + size_t arg_index; +} +char_directive; + +/* A parsed format string. */ +typedef struct +{ + size_t count; + char_directive *dir; + size_t max_width_length; + size_t max_precision_length; +} +char_directives; + + +/* Parses the format string. Fills in the number N of directives, and fills + in directives[0], ..., directives[N-1], and sets directives[N].dir_start + to the end of the format string. Also fills in the arg_type fields of the + arguments and the needed count of arguments. */ +#ifdef STATIC +STATIC +#else +extern +#endif +int printf_parse (const char *format, char_directives *d, arguments *a); + +#endif /* _PRINTF_PARSE_H */ diff --git a/lib/regcomp.c b/gl/regcomp.c similarity index 87% rename from lib/regcomp.c rename to gl/regcomp.c index 279b20c..8df6bb8 100644 --- a/lib/regcomp.c +++ b/gl/regcomp.c @@ -1,5 +1,5 @@ /* Extended regular expression matching and search library. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa . @@ -18,11 +18,11 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, - Idx length, reg_syntax_t syntax); + size_t length, reg_syntax_t syntax); static void re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, char *fastmap); -static reg_errcode_t init_dfa (re_dfa_t *dfa, Idx pat_len); +static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len); #ifdef RE_ENABLE_I18N static void free_charset (re_charset_t *cset); #endif /* RE_ENABLE_I18N */ @@ -55,7 +55,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa); static Idx fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax); static int peek_token (re_token_t *token, re_string_t *input, - reg_syntax_t syntax); + reg_syntax_t syntax) internal_function; static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, reg_errcode_t *err); static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg, @@ -86,26 +86,26 @@ static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp, re_token_t *token); #ifdef RE_ENABLE_I18N -static reg_errcode_t build_equiv_class (bitset sbcset, +static reg_errcode_t build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, Idx *equiv_class_alloc, const unsigned char *name); -static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans, - bitset sbcset, +static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, + bitset_t sbcset, re_charset_t *mbcset, Idx *char_class_alloc, const unsigned char *class_name, reg_syntax_t syntax); #else /* not RE_ENABLE_I18N */ -static reg_errcode_t build_equiv_class (bitset sbcset, +static reg_errcode_t build_equiv_class (bitset_t sbcset, const unsigned char *name); -static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans, - bitset sbcset, +static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, + bitset_t sbcset, const unsigned char *class_name, reg_syntax_t syntax); #endif /* not RE_ENABLE_I18N */ static bin_tree_t *build_charclass_op (re_dfa_t *dfa, - unsigned REG_TRANSLATE_TYPE trans, + RE_TRANSLATE_TYPE trans, const unsigned char *class_name, const unsigned char *extra, bool non_match, reg_errcode_t *err); @@ -125,7 +125,7 @@ static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node); POSIX doesn't require that we do anything for REG_NOERROR, but why not be nice? */ -const char __re_error_msgid[] attribute_hidden = +static const char __re_error_msgid[] = { #define REG_NOERROR_IDX 0 gettext_noop ("Success") /* REG_NOERROR */ @@ -179,7 +179,7 @@ const char __re_error_msgid[] attribute_hidden = gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ }; -const size_t __re_error_msgid_idx[] attribute_hidden = +static const size_t __re_error_msgid_idx[] = { REG_NOERROR_IDX, REG_NOMATCH_IDX, @@ -206,22 +206,30 @@ const size_t __re_error_msgid_idx[] attribute_hidden = compiles PATTERN (of length LENGTH) and puts the result in BUFP. Returns 0 if the pattern was valid, otherwise an error string. - Assumes the `re_allocated' (and perhaps `re_buffer') and `translate' fields + Assumes the `allocated' (and perhaps `buffer') and `translate' fields are set in BUFP on entry. */ +#ifdef _LIBC +const char * +re_compile_pattern (pattern, length, bufp) + const char *pattern; + size_t length; + struct re_pattern_buffer *bufp; +#else /* size_t might promote */ const char * re_compile_pattern (const char *pattern, size_t length, struct re_pattern_buffer *bufp) +#endif { reg_errcode_t ret; /* And GNU code determines whether or not to get register information by passing null for the REGS argument to re_match, etc., not by - setting re_no_sub, unless REG_NO_SUB is set. */ - bufp->re_no_sub = !!(re_syntax_options & REG_NO_SUB); + setting no_sub, unless RE_NO_SUB is set. */ + bufp->no_sub = !!(re_syntax_options & RE_NO_SUB); /* Match anchors at newline. */ - bufp->re_newline_anchor = 1; + bufp->newline_anchor = 1; ret = re_compile_internal (bufp, pattern, length, re_syntax_options); @@ -249,7 +257,8 @@ reg_syntax_t re_syntax_options; defined in regex.h. We return the old syntax. */ reg_syntax_t -re_set_syntax (reg_syntax_t syntax) +re_set_syntax (syntax) + reg_syntax_t syntax; { reg_syntax_t ret = re_syntax_options; @@ -261,10 +270,11 @@ weak_alias (__re_set_syntax, re_set_syntax) #endif int -re_compile_fastmap (struct re_pattern_buffer *bufp) +re_compile_fastmap (bufp) + struct re_pattern_buffer *bufp; { - re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; - char *fastmap = bufp->re_fastmap; + re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; + char *fastmap = bufp->fastmap; memset (fastmap, '\0', sizeof (char) * SBC_MAX); re_compile_fastmap_iter (bufp, dfa->init_state, fastmap); @@ -274,7 +284,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp) re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap); if (dfa->init_state != dfa->init_state_begbuf) re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap); - bufp->re_fastmap_accurate = 1; + bufp->fastmap_accurate = 1; return 0; } #ifdef _LIBC @@ -297,9 +307,9 @@ static void re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, char *fastmap) { - re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; Idx node_cnt; - bool icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE)); + bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE)); for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) { Idx node = init_state->nodes.elems[node_cnt]; @@ -309,7 +319,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, { re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c); #ifdef RE_ENABLE_I18N - if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1) + if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) { unsigned char buf[MB_LEN_MAX]; unsigned char *p; @@ -322,7 +332,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, && dfa->nodes[node].type == CHARACTER && dfa->nodes[node].mb_partial) *p++ = dfa->nodes[node].opr.c; - memset (&state, 0, sizeof (state)); + memset (&state, '\0', sizeof (state)); if (mbrtowc (&wc, (const char *) buf, p - buf, &state) == p - buf && (__wcrtomb ((char *) buf, towlower (wc), &state) @@ -333,11 +343,15 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, } else if (type == SIMPLE_BRACKET) { - int i, j, ch; + int i, ch; for (i = 0, ch = 0; i < BITSET_WORDS; ++i) - for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) - if (dfa->nodes[node].opr.sbcset[i] & ((bitset_word) 1 << j)) - re_set_fastmap (fastmap, icase, ch); + { + int j; + bitset_word_t w = dfa->nodes[node].opr.sbcset[i]; + for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) + if (w & ((bitset_word_t) 1 << j)) + re_set_fastmap (fastmap, icase, ch); + } } #ifdef RE_ENABLE_I18N else if (type == COMPLEX_BRACKET) @@ -376,7 +390,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, memset (&state, '\0', sizeof (state)); if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1) re_set_fastmap (fastmap, icase, *(unsigned char *) buf); - if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1) + if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) { if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) != (size_t) -1) @@ -393,7 +407,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, { memset (fastmap, '\1', sizeof (char) * SBC_MAX); if (type == END_OF_RE) - bufp->re_can_be_null = 1; + bufp->can_be_null = 1; return; } } @@ -405,14 +419,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, PREG is a regex_t *. We do not expect any fields to be initialized, since POSIX says we shouldn't. Thus, we set - `re_buffer' to the compiled pattern; - `re_used' to the length of the compiled pattern; - `re_syntax' to REG_SYNTAX_POSIX_EXTENDED if the + `buffer' to the compiled pattern; + `used' to the length of the compiled pattern; + `syntax' to RE_SYNTAX_POSIX_EXTENDED if the REG_EXTENDED bit in CFLAGS is set; otherwise, to - REG_SYNTAX_POSIX_BASIC; - `re_newline_anchor' to REG_NEWLINE being set in CFLAGS; - `re_fastmap' to an allocated space for the fastmap; - `re_fastmap_accurate' to zero; + RE_SYNTAX_POSIX_BASIC; + `newline_anchor' to REG_NEWLINE being set in CFLAGS; + `fastmap' to an allocated space for the fastmap; + `fastmap_accurate' to zero; `re_nsub' to the number of subexpressions in PATTERN. PATTERN is the address of the pattern string. @@ -436,35 +450,38 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, the return codes and their meanings.) */ int -regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) +regcomp (preg, pattern, cflags) + regex_t *__restrict preg; + const char *__restrict pattern; + int cflags; { reg_errcode_t ret; - reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? REG_SYNTAX_POSIX_EXTENDED - : REG_SYNTAX_POSIX_BASIC); + reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED + : RE_SYNTAX_POSIX_BASIC); - preg->re_buffer = NULL; - preg->re_allocated = 0; - preg->re_used = 0; + preg->buffer = NULL; + preg->allocated = 0; + preg->used = 0; /* Try to allocate space for the fastmap. */ - preg->re_fastmap = re_malloc (char, SBC_MAX); - if (BE (preg->re_fastmap == NULL, 0)) + preg->fastmap = re_malloc (char, SBC_MAX); + if (BE (preg->fastmap == NULL, 0)) return REG_ESPACE; - syntax |= (cflags & REG_ICASE) ? REG_IGNORE_CASE : 0; + syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0; /* If REG_NEWLINE is set, newlines are treated differently. */ if (cflags & REG_NEWLINE) { /* REG_NEWLINE implies neither . nor [^...] match newline. */ - syntax &= ~REG_DOT_NEWLINE; - syntax |= REG_HAT_LISTS_NOT_NEWLINE; + syntax &= ~RE_DOT_NEWLINE; + syntax |= RE_HAT_LISTS_NOT_NEWLINE; /* It also changes the matching behavior. */ - preg->re_newline_anchor = 1; + preg->newline_anchor = 1; } else - preg->re_newline_anchor = 0; - preg->re_no_sub = !!(cflags & REG_NOSUB); - preg->re_translate = NULL; + preg->newline_anchor = 0; + preg->no_sub = !!(cflags & REG_NOSUB); + preg->translate = NULL; ret = re_compile_internal (preg, pattern, strlen (pattern), syntax); @@ -473,7 +490,7 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) if (ret == REG_ERPAREN) ret = REG_EPAREN; - /* We have already checked preg->re_fastmap != NULL. */ + /* We have already checked preg->fastmap != NULL. */ if (BE (ret == REG_NOERROR, 1)) /* Compute the fastmap now, since regexec cannot modify the pattern buffer. This function never fails in this implementation. */ @@ -481,8 +498,8 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) else { /* Some error occurred while compiling the expression. */ - re_free (preg->re_fastmap); - preg->re_fastmap = NULL; + re_free (preg->fastmap); + preg->fastmap = NULL; } return (int) ret; @@ -494,9 +511,18 @@ weak_alias (__regcomp, regcomp) /* Returns a message corresponding to an error code, ERRCODE, returned from either regcomp or regexec. We don't use PREG here. */ +#ifdef _LIBC +size_t +regerror (errcode, preg, errbuf, errbuf_size) + int errcode; + const regex_t *__restrict preg; + char *__restrict errbuf; + size_t errbuf_size; +#else /* size_t might promote */ size_t regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, size_t errbuf_size) +#endif { const char *msg; size_t msg_size; @@ -541,20 +567,17 @@ weak_alias (__regerror, regerror) UTF-8 is used. Otherwise we would allocate memory just to initialize it the same all the time. UTF-8 is the preferred encoding so this is a worthwhile optimization. */ -static const bitset utf8_sb_map = +static const bitset_t utf8_sb_map = { /* Set the first 128 bits. */ -# if 2 < BITSET_WORDS - BITSET_WORD_MAX, -# endif -# if 4 < BITSET_WORDS - BITSET_WORD_MAX, -# endif -# if 6 < BITSET_WORDS +# if 4 * BITSET_WORD_BITS < ASCII_CHARS +# error "bitset_word_t is narrower than 32 bits" +# elif 3 * BITSET_WORD_BITS < ASCII_CHARS + BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX, +# elif 2 * BITSET_WORD_BITS < ASCII_CHARS + BITSET_WORD_MAX, BITSET_WORD_MAX, +# elif 1 * BITSET_WORD_BITS < ASCII_CHARS BITSET_WORD_MAX, -# endif -# if 8 < BITSET_WORDS -# error "Invalid BITSET_WORDS" # endif (BITSET_WORD_MAX >> (SBC_MAX % BITSET_WORD_BITS == 0 @@ -615,19 +638,20 @@ free_dfa_content (re_dfa_t *dfa) /* Free dynamically allocated space used by PREG. */ void -regfree (regex_t *preg) +regfree (preg) + regex_t *preg; { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; if (BE (dfa != NULL, 1)) free_dfa_content (dfa); - preg->re_buffer = NULL; - preg->re_allocated = 0; + preg->buffer = NULL; + preg->allocated = 0; - re_free (preg->re_fastmap); - preg->re_fastmap = NULL; + re_free (preg->fastmap); + preg->fastmap = NULL; - re_free (preg->re_translate); - preg->re_translate = NULL; + re_free (preg->translate); + preg->translate = NULL; } #ifdef _LIBC weak_alias (__regfree, regfree) @@ -648,31 +672,32 @@ char * regcomp/regexec above without link errors. */ weak_function # endif -re_comp (const char *s) +re_comp (s) + const char *s; { reg_errcode_t ret; char *fastmap; if (!s) { - if (!re_comp_buf.re_buffer) + if (!re_comp_buf.buffer) return gettext ("No previous regular expression"); return 0; } - if (re_comp_buf.re_buffer) + if (re_comp_buf.buffer) { - fastmap = re_comp_buf.re_fastmap; - re_comp_buf.re_fastmap = NULL; + fastmap = re_comp_buf.fastmap; + re_comp_buf.fastmap = NULL; __regfree (&re_comp_buf); memset (&re_comp_buf, '\0', sizeof (re_comp_buf)); - re_comp_buf.re_fastmap = fastmap; + re_comp_buf.fastmap = fastmap; } - if (re_comp_buf.re_fastmap == NULL) + if (re_comp_buf.fastmap == NULL) { - re_comp_buf.re_fastmap = (char *) malloc (SBC_MAX); - if (re_comp_buf.re_fastmap == NULL) + re_comp_buf.fastmap = (char *) malloc (SBC_MAX); + if (re_comp_buf.fastmap == NULL) return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) REG_ESPACE]); } @@ -681,7 +706,7 @@ re_comp (const char *s) don't need to initialize the pattern buffer fields which affect it. */ /* Match anchors at newlines. */ - re_comp_buf.re_newline_anchor = 1; + re_comp_buf.newline_anchor = 1; ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options); @@ -706,7 +731,7 @@ libc_freeres_fn (free_mem) SYNTAX indicate regular expression's syntax. */ static reg_errcode_t -re_compile_internal (regex_t *preg, const char *pattern, Idx length, +re_compile_internal (regex_t *preg, const char * pattern, size_t length, reg_syntax_t syntax) { reg_errcode_t err = REG_NOERROR; @@ -714,55 +739,56 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, re_string_t regexp; /* Initialize the pattern buffer. */ - preg->re_fastmap_accurate = 0; - preg->re_syntax = syntax; - preg->re_not_bol = preg->re_not_eol = 0; - preg->re_used = 0; + preg->fastmap_accurate = 0; + preg->syntax = syntax; + preg->not_bol = preg->not_eol = 0; + preg->used = 0; preg->re_nsub = 0; - preg->re_can_be_null = 0; - preg->re_regs_allocated = REG_UNALLOCATED; + preg->can_be_null = 0; + preg->regs_allocated = REGS_UNALLOCATED; /* Initialize the dfa. */ - dfa = (re_dfa_t *) preg->re_buffer; - if (BE (preg->re_allocated < sizeof (re_dfa_t), 0)) + dfa = (re_dfa_t *) preg->buffer; + if (BE (preg->allocated < sizeof (re_dfa_t), 0)) { /* If zero allocated, but buffer is non-null, try to realloc enough space. This loses if buffer's address is bogus, but - that is the user's responsibility. If buffer is null this + that is the user's responsibility. If ->buffer is NULL this is a simple allocation. */ - dfa = re_realloc (preg->re_buffer, re_dfa_t, 1); + dfa = re_realloc (preg->buffer, re_dfa_t, 1); if (dfa == NULL) return REG_ESPACE; - preg->re_allocated = sizeof (re_dfa_t); - preg->re_buffer = (unsigned char *) dfa; + preg->allocated = sizeof (re_dfa_t); + preg->buffer = (unsigned char *) dfa; } - preg->re_used = sizeof (re_dfa_t); - - __libc_lock_init (dfa->lock); + preg->used = sizeof (re_dfa_t); err = init_dfa (dfa, length); if (BE (err != REG_NOERROR, 0)) { free_dfa_content (dfa); - preg->re_buffer = NULL; - preg->re_allocated = 0; + preg->buffer = NULL; + preg->allocated = 0; return err; } #ifdef DEBUG + /* Note: length+1 will not overflow since it is checked in init_dfa. */ dfa->re_str = re_malloc (char, length + 1); strncpy (dfa->re_str, pattern, length + 1); #endif - err = re_string_construct (®exp, pattern, length, preg->re_translate, - syntax & REG_IGNORE_CASE, dfa); + __libc_lock_init (dfa->lock); + + err = re_string_construct (®exp, pattern, length, preg->translate, + syntax & RE_ICASE, dfa); if (BE (err != REG_NOERROR, 0)) { re_compile_internal_free_return: free_workarea_compile (preg); re_string_destruct (®exp); free_dfa_content (dfa); - preg->re_buffer = NULL; - preg->re_allocated = 0; + preg->buffer = NULL; + preg->allocated = 0; return err; } @@ -779,7 +805,7 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, #ifdef RE_ENABLE_I18N /* If possible, do searching in single byte encoding to speed things up. */ - if (dfa->is_utf8 && !(syntax & REG_IGNORE_CASE) && preg->re_translate == NULL) + if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL) optimize_utf8 (dfa); #endif @@ -793,8 +819,8 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, if (BE (err != REG_NOERROR, 0)) { free_dfa_content (dfa); - preg->re_buffer = NULL; - preg->re_allocated = 0; + preg->buffer = NULL; + preg->allocated = 0; } return err; @@ -804,27 +830,45 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length, as the initial length of some arrays. */ static reg_errcode_t -init_dfa (re_dfa_t *dfa, Idx pat_len) +init_dfa (re_dfa_t *dfa, size_t pat_len) { __re_size_t table_size; #ifndef _LIBC char *codeset_name; #endif +#ifdef RE_ENABLE_I18N + size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); +#else + size_t max_i18n_object_size = 0; +#endif + size_t max_object_size = + MAX (sizeof (struct re_state_table_entry), + MAX (sizeof (re_token_t), + MAX (sizeof (re_node_set), + MAX (sizeof (regmatch_t), + max_i18n_object_size)))); memset (dfa, '\0', sizeof (re_dfa_t)); /* Force allocation of str_tree_storage the first time. */ dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; + /* Avoid overflows. The extra "/ 2" is for the table_size doubling + calculation below, and for similar doubling calculations + elsewhere. And it's <= rather than <, because some of the + doubling calculations add 1 afterwards. */ + if (BE (SIZE_MAX / max_object_size / 2 <= pat_len, 0)) + return REG_ESPACE; + dfa->nodes_alloc = pat_len + 1; - dfa->nodes = re_xmalloc (re_token_t, dfa->nodes_alloc); + dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc); /* table_size = 2 ^ ceil(log pat_len) */ - for (table_size = 1; table_size <= pat_len; table_size <<= 1) - if (0 < (Idx) -1 && table_size == 0) - return REG_ESPACE; + for (table_size = 1; ; table_size <<= 1) + if (table_size > pat_len) + break; - dfa->state_table = re_calloc (struct re_state_table_entry, table_size); + dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size); dfa->state_hash_mask = table_size - 1; dfa->mb_cur_max = MB_CUR_MAX; @@ -867,7 +911,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) { int i, j, ch; - dfa->sb_char = re_calloc (bitset_word, BITSET_WORDS); + dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); if (BE (dfa->sb_char == NULL, 0)) return REG_ESPACE; @@ -877,7 +921,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) { wint_t wch = __btowc (ch); if (wch != WEOF) - dfa->sb_char[i] |= (bitset_word) 1 << j; + dfa->sb_char[i] |= (bitset_word_t) 1 << j; # ifndef _LIBC if (isascii (ch) && wch != ch) dfa->map_notascii = 1; @@ -897,6 +941,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len) character used by some operators like "\<", "\>", etc. */ static void +internal_function init_word_char (re_dfa_t *dfa) { int i, j, ch; @@ -904,7 +949,7 @@ init_word_char (re_dfa_t *dfa) for (i = 0, ch = 0; i < BITSET_WORDS; ++i) for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) if (isalnum (ch) || ch == '_') - dfa->word_char[i] |= (bitset_word) 1 << j; + dfa->word_char[i] |= (bitset_word_t) 1 << j; } /* Free the work area which are only used while compiling. */ @@ -912,7 +957,7 @@ init_word_char (re_dfa_t *dfa) static void free_workarea_compile (regex_t *preg) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_storage_t *storage, *next; for (storage = dfa->str_tree_storage; storage; storage = next) { @@ -1022,7 +1067,7 @@ optimize_utf8 (re_dfa_t *dfa) switch (dfa->nodes[node].type) { case CHARACTER: - if (dfa->nodes[node].opr.c >= 0x80) + if (dfa->nodes[node].opr.c >= ASCII_CHARS) mb_chars = true; break; case ANCHOR: @@ -1053,11 +1098,10 @@ optimize_utf8 (re_dfa_t *dfa) case SIMPLE_BRACKET: /* Just double check. */ { - int rshift = - (SBC_MAX / 2 % BITSET_WORD_BITS == 0 - ? 0 - : BITSET_WORD_BITS - SBC_MAX / 2 % BITSET_WORD_BITS); - for (i = SBC_MAX / 2 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) + int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0 + ? 0 + : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS); + for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) { if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0) return; @@ -1073,7 +1117,7 @@ optimize_utf8 (re_dfa_t *dfa) for (node = 0; node < dfa->nodes_len; ++node) { if (dfa->nodes[node].type == CHARACTER - && dfa->nodes[node].opr.c >= 0x80) + && dfa->nodes[node].opr.c >= ASCII_CHARS) dfa->nodes[node].mb_partial = 0; else if (dfa->nodes[node].type == OP_PERIOD) dfa->nodes[node].type = OP_UTF8_PERIOD; @@ -1092,19 +1136,19 @@ optimize_utf8 (re_dfa_t *dfa) static reg_errcode_t analyze (regex_t *preg) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; reg_errcode_t ret; /* Allocate arrays. */ dfa->nexts = re_malloc (Idx, dfa->nodes_alloc); dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); - dfa->edests = re_xmalloc (re_node_set, dfa->nodes_alloc); + dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc); dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL || dfa->eclosures == NULL, 0)) return REG_ESPACE; - dfa->subexp_map = re_xmalloc (Idx, preg->re_nsub); + dfa->subexp_map = re_malloc (Idx, preg->re_nsub); if (dfa->subexp_map != NULL) { Idx i; @@ -1137,10 +1181,10 @@ analyze (regex_t *preg) /* We only need this during the prune_impossible_nodes pass in regexec.c; skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */ - if ((!preg->re_no_sub && preg->re_nsub > 0 && dfa->has_plural_match) + if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match) || dfa->nbackref) { - dfa->inveclosures = re_xmalloc (re_node_set, dfa->nodes_len); + dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); if (BE (dfa->inveclosures == NULL, 0)) return REG_ESPACE; ret = calc_inveclosure (dfa); @@ -1240,7 +1284,7 @@ optimize_subexps (void *extra, bin_tree_t *node) dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; if (other_idx < BITSET_WORD_BITS) - dfa->used_bkref_map &= ~ ((bitset_word) 1 << other_idx); + dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx); } return REG_NOERROR; @@ -1273,18 +1317,19 @@ lower_subexps (void *extra, bin_tree_t *node) static bin_tree_t * lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_t *body = node->left; bin_tree_t *op, *cls, *tree1, *tree; - if (preg->re_no_sub + if (preg->no_sub /* We do not optimize empty subexpressions, because otherwise we may have bad CONCAT nodes with NULL children. This is obviously not very common, so we do not lose much. An example that triggers this case is the sed "script" /\(\)/x. */ && node->left != NULL - && ! (node->token.opr.idx < BITSET_WORD_BITS - && dfa->used_bkref_map & ((bitset_word) 1 << node->token.opr.idx))) + && (node->token.opr.idx >= BITSET_WORD_BITS + || !(dfa->used_bkref_map + & ((bitset_word_t) 1 << node->token.opr.idx)))) return node->left; /* Convert the SUBEXP node to the concatenation of an @@ -1410,9 +1455,9 @@ link_nfa_nodes (void *extra, bin_tree_t *node) to their own constraint. */ static reg_errcode_t -duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, - Idx top_clone_node, Idx root_node, - unsigned int init_constraint) +internal_function +duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node, + Idx root_node, unsigned int init_constraint) { Idx org_node, clone_node; bool ok; @@ -1458,8 +1503,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, /* ...but if the node is root_node itself, it means the epsilon closure have a loop, then tie it to the destination of the root_node. */ - ok = re_node_set_insert (dfa->edests + clone_node, - org_dest); + ok = re_node_set_insert (dfa->edests + clone_node, org_dest); if (BE (! ok, 0)) return REG_ESPACE; break; @@ -1652,8 +1696,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) && dfa->edests[node].nelem && !dfa->nodes[dfa->edests[node].elems[0]].duplicated) { - Idx org_node, cur_node; - org_node = cur_node = node; err = duplicate_node_closure (dfa, node, node, node, constraint); if (BE (err != REG_NOERROR, 0)) return err; @@ -1711,6 +1753,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) We must not use this function inside bracket expressions. */ static void +internal_function fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) { re_string_skip_bytes (input, peek_token (result, input, syntax)); @@ -1720,6 +1763,7 @@ fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) We must not use this function inside bracket expressions. */ static int +internal_function peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) { unsigned char c; @@ -1770,97 +1814,97 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) switch (c2) { case '|': - if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_NO_BK_VBAR)) + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR)) token->type = OP_ALT; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - if (!(syntax & REG_NO_BK_REFS)) + if (!(syntax & RE_NO_BK_REFS)) { token->type = OP_BACK_REF; token->opr.idx = c2 - '1'; } break; case '<': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = WORD_FIRST; } break; case '>': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = WORD_LAST; } break; case 'b': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = WORD_DELIM; } break; case 'B': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = NOT_WORD_DELIM; } break; case 'w': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) token->type = OP_WORD; break; case 'W': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) token->type = OP_NOTWORD; break; case 's': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) token->type = OP_SPACE; break; case 'S': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) token->type = OP_NOTSPACE; break; case '`': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = BUF_FIRST; } break; case '\'': - if (!(syntax & REG_NO_GNU_OPS)) + if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; token->opr.ctx_type = BUF_LAST; } break; case '(': - if (!(syntax & REG_NO_BK_PARENS)) + if (!(syntax & RE_NO_BK_PARENS)) token->type = OP_OPEN_SUBEXP; break; case ')': - if (!(syntax & REG_NO_BK_PARENS)) + if (!(syntax & RE_NO_BK_PARENS)) token->type = OP_CLOSE_SUBEXP; break; case '+': - if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM)) + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) token->type = OP_DUP_PLUS; break; case '?': - if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM)) + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) token->type = OP_DUP_QUESTION; break; case '{': - if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES))) + if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) token->type = OP_OPEN_DUP_NUM; break; case '}': - if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES))) + if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) token->type = OP_CLOSE_DUP_NUM; break; default: @@ -1883,38 +1927,38 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) switch (c) { case '\n': - if (syntax & REG_NEWLINE_ALT) + if (syntax & RE_NEWLINE_ALT) token->type = OP_ALT; break; case '|': - if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_NO_BK_VBAR)) + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR)) token->type = OP_ALT; break; case '*': token->type = OP_DUP_ASTERISK; break; case '+': - if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM)) + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) token->type = OP_DUP_PLUS; break; case '?': - if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM)) + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) token->type = OP_DUP_QUESTION; break; case '{': - if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES)) + if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) token->type = OP_OPEN_DUP_NUM; break; case '}': - if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES)) + if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) token->type = OP_CLOSE_DUP_NUM; break; case '(': - if (syntax & REG_NO_BK_PARENS) + if (syntax & RE_NO_BK_PARENS) token->type = OP_OPEN_SUBEXP; break; case ')': - if (syntax & REG_NO_BK_PARENS) + if (syntax & RE_NO_BK_PARENS) token->type = OP_CLOSE_SUBEXP; break; case '[': @@ -1924,18 +1968,18 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) token->type = OP_PERIOD; break; case '^': - if (!(syntax & (REG_CONTEXT_INDEP_ANCHORS | REG_CARET_ANCHORS_HERE)) && + if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && re_string_cur_idx (input) != 0) { char prev = re_string_peek_byte (input, -1); - if (!(syntax & REG_NEWLINE_ALT) || prev != '\n') + if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') break; } token->type = ANCHOR; token->opr.ctx_type = LINE_FIRST; break; case '$': - if (!(syntax & REG_CONTEXT_INDEP_ANCHORS) && + if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && re_string_cur_idx (input) + 1 != re_string_length (input)) { re_token_t next; @@ -1958,6 +2002,7 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) We must not use this function out of bracket expressions. */ static int +internal_function peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) { unsigned char c; @@ -1978,7 +2023,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) } #endif /* RE_ENABLE_I18N */ - if (c == '\\' && (syntax & REG_BACKSLASH_ESCAPE_IN_LISTS) + if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && re_string_cur_idx (input) + 1 < re_string_length (input)) { /* In this case, '\' escape a character. */ @@ -2008,7 +2053,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) token->type = OP_OPEN_EQUIV_CLASS; break; case ':': - if (syntax & REG_CHAR_CLASSES) + if (syntax & RE_CHAR_CLASSES) { token->type = OP_OPEN_CHAR_CLASS; break; @@ -2057,11 +2102,11 @@ static bin_tree_t * parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, reg_errcode_t *err) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_t *tree, *eor, *root; re_token_t current_token; dfa->syntax = syntax; - fetch_token (¤t_token, regexp, syntax | REG_CARET_ANCHORS_HERE); + fetch_token (¤t_token, regexp, syntax | RE_CARET_ANCHORS_HERE); tree = parse_reg_exp (regexp, preg, ¤t_token, syntax, 0, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; @@ -2091,7 +2136,7 @@ static bin_tree_t * parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, reg_syntax_t syntax, Idx nest, reg_errcode_t *err) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_t *tree, *branch = NULL; tree = parse_branch (regexp, preg, token, syntax, nest, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) @@ -2099,7 +2144,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, while (token->type == OP_ALT) { - fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE); + fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); if (token->type != OP_ALT && token->type != END_OF_RE && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) { @@ -2132,8 +2177,8 @@ static bin_tree_t * parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, reg_syntax_t syntax, Idx nest, reg_errcode_t *err) { - bin_tree_t *tree, *exp; - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + bin_tree_t *tree, *expr; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; tree = parse_expression (regexp, preg, token, syntax, nest, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; @@ -2141,14 +2186,14 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, while (token->type != OP_ALT && token->type != END_OF_RE && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) { - exp = parse_expression (regexp, preg, token, syntax, nest, err); - if (BE (*err != REG_NOERROR && exp == NULL, 0)) + expr = parse_expression (regexp, preg, token, syntax, nest, err); + if (BE (*err != REG_NOERROR && expr == NULL, 0)) { return NULL; } - if (tree != NULL && exp != NULL) + if (tree != NULL && expr != NULL) { - tree = create_tree (dfa, tree, exp, CONCAT); + tree = create_tree (dfa, tree, expr, CONCAT); if (tree == NULL) { *err = REG_ESPACE; @@ -2156,8 +2201,8 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, } } else if (tree == NULL) - tree = exp; - /* Otherwise exp == NULL, we don't need to create new tree. */ + tree = expr; + /* Otherwise expr == NULL, we don't need to create new tree. */ } return tree; } @@ -2172,7 +2217,7 @@ static bin_tree_t * parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, reg_syntax_t syntax, Idx nest, reg_errcode_t *err) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_t *tree; switch (token->type) { @@ -2229,7 +2274,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, dfa->has_mb_node = 1; break; case OP_OPEN_DUP_NUM: - if (syntax & REG_CONTEXT_INVALID_DUP) + if (syntax & RE_CONTEXT_INVALID_DUP) { *err = REG_BADRPT; return NULL; @@ -2238,12 +2283,12 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, case OP_DUP_ASTERISK: case OP_DUP_PLUS: case OP_DUP_QUESTION: - if (syntax & REG_CONTEXT_INVALID_OPS) + if (syntax & RE_CONTEXT_INVALID_OPS) { *err = REG_BADRPT; return NULL; } - else if (syntax & REG_CONTEXT_INDEP_OPS) + else if (syntax & RE_CONTEXT_INDEP_OPS) { fetch_token (token, regexp, syntax); return parse_expression (regexp, preg, token, syntax, nest, err); @@ -2251,7 +2296,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, /* else fall through */ case OP_CLOSE_SUBEXP: if ((token->type == OP_CLOSE_SUBEXP) && - !(syntax & REG_UNMATCHED_RIGHT_PAREN_ORD)) + !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) { *err = REG_ERPAREN; return NULL; @@ -2365,7 +2410,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; /* In BRE consecutive duplications are not allowed. */ - if ((syntax & REG_CONTEXT_INVALID_DUP) + if ((syntax & RE_CONTEXT_INVALID_DUP) && (token->type == OP_DUP_ASTERISK || token->type == OP_OPEN_DUP_NUM)) { @@ -2388,12 +2433,12 @@ static bin_tree_t * parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, reg_syntax_t syntax, Idx nest, reg_errcode_t *err) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; bin_tree_t *tree; size_t cur_nsub; cur_nsub = preg->re_nsub++; - fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE); + fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); /* The subexpression may be a null string. */ if (token->type == OP_CLOSE_SUBEXP) @@ -2454,7 +2499,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, if (BE (start == REG_ERROR || end == REG_ERROR, 0)) { /* Invalid sequence. */ - if (BE (!(syntax & REG_INVALID_INTERVAL_ORD), 0)) + if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0)) { if (token->type == END_OF_RE) *err = REG_EBRACE; @@ -2565,11 +2610,14 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, update it. */ static reg_errcode_t -build_range_exp (bitset sbcset, +internal_function # ifdef RE_ENABLE_I18N - re_charset_t *mbcset, Idx *range_alloc, -# endif +build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, bracket_elem_t *start_elem, bracket_elem_t *end_elem) +# else /* not RE_ENABLE_I18N */ +build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, + bracket_elem_t *end_elem) +# endif /* not RE_ENABLE_I18N */ { unsigned int start_ch, end_ch; /* Equivalence Classes and Character Classes can't be a range start/end. */ @@ -2589,7 +2637,8 @@ build_range_exp (bitset sbcset, # ifdef RE_ENABLE_I18N { wchar_t wc; - wint_t start_wc, end_wc; + wint_t start_wc; + wint_t end_wc; wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch @@ -2623,11 +2672,12 @@ build_range_exp (bitset sbcset, wchar_t *new_array_start, *new_array_end; Idx new_nranges; - new_nranges = mbcset->nranges; + /* +1 in case of mbcset->nranges is 0. */ + new_nranges = 2 * mbcset->nranges + 1; /* Use realloc since mbcset->range_starts and mbcset->range_ends are NULL if *range_alloc == 0. */ - new_array_start = re_x2realloc (mbcset->range_starts, wchar_t, - &new_nranges); + new_array_start = re_realloc (mbcset->range_starts, wchar_t, + new_nranges); new_array_end = re_realloc (mbcset->range_ends, wchar_t, new_nranges); @@ -2681,7 +2731,8 @@ build_range_exp (bitset sbcset, pointer argument since we may update it. */ static reg_errcode_t -build_collating_symbol (bitset sbcset, +internal_function +build_collating_symbol (bitset_t sbcset, # ifdef RE_ENABLE_I18N re_charset_t *mbcset, Idx *coll_sym_alloc, # endif @@ -2719,27 +2770,34 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline int32_t __attribute ((always_inline)) - seek_collating_symbol_entry (const unsigned char *name, size_t name_len) + seek_collating_symbol_entry (name, name_len) + const unsigned char *name; + size_t name_len; { int32_t hash = elem_hash ((const char *) name, name_len); int32_t elem = hash % table_size; - int32_t second = hash % (table_size - 2); - while (symb_table[2 * elem] != 0) - { - /* First compare the hashing value. */ - if (symb_table[2 * elem] == hash - /* Compare the length of the name. */ - && name_len == extra[symb_table[2 * elem + 1]] - /* Compare the name. */ - && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], - name_len) == 0) + if (symb_table[2 * elem] != 0) + { + int32_t second = hash % (table_size - 2) + 1; + + do { - /* Yep, this is the entry. */ - break; - } + /* First compare the hashing value. */ + if (symb_table[2 * elem] == hash + /* Compare the length of the name. */ + && name_len == extra[symb_table[2 * elem + 1]] + /* Compare the name. */ + && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], + name_len) == 0) + { + /* Yep, this is the entry. */ + break; + } - /* Next entry. */ - elem += second; + /* Next entry. */ + elem += second; + } + while (symb_table[2 * elem] != 0); } return elem; } @@ -2750,7 +2808,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline unsigned int __attribute ((always_inline)) - lookup_collation_sequence_value (bracket_elem_t *br_elem) + lookup_collation_sequence_value (br_elem) + bracket_elem_t *br_elem; { if (br_elem->type == SB_CHAR) { @@ -2817,9 +2876,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline reg_errcode_t __attribute ((always_inline)) - build_range_exp (bitset sbcset, re_charset_t *mbcset, - Idx *range_alloc, - bracket_elem_t *start_elem, bracket_elem_t *end_elem) + build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem) + re_charset_t *mbcset; + Idx *range_alloc; + bitset_t sbcset; + bracket_elem_t *start_elem, *end_elem; { unsigned int ch; uint32_t start_collseq; @@ -2837,7 +2898,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, /* Check start/end collation sequence values. */ if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) return REG_ECOLLATE; - if (BE ((syntax & REG_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) + if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) return REG_ERANGE; /* Got valid collation sequence values, add them as a new entry. @@ -2854,9 +2915,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, uint32_t *new_array_end; Idx new_nranges; - new_nranges = mbcset->nranges; - new_array_start = re_x2realloc (mbcset->range_starts, uint32_t, - &new_nranges); + /* +1 in case of mbcset->nranges is 0. */ + new_nranges = 2 * mbcset->nranges + 1; + new_array_start = re_realloc (mbcset->range_starts, uint32_t, + new_nranges); new_array_end = re_realloc (mbcset->range_ends, uint32_t, new_nranges); @@ -2897,8 +2959,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline reg_errcode_t __attribute ((always_inline)) - build_collating_symbol (bitset sbcset, re_charset_t *mbcset, - Idx *coll_sym_alloc, const unsigned char *name) + build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name) + re_charset_t *mbcset; + Idx *coll_sym_alloc; + bitset_t sbcset; + const unsigned char *name; { int32_t elem, idx; size_t name_len = strlen ((const char *) name); @@ -2927,11 +2992,12 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0)) { /* Not enough, realloc it. */ - Idx new_coll_sym_alloc = mbcset->ncoll_syms; + /* +1 in case of mbcset->ncoll_syms is 0. */ + Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1; /* Use realloc since mbcset->coll_syms is NULL if *alloc == 0. */ - int32_t *new_coll_syms = re_x2realloc (mbcset->coll_syms, int32_t, - &new_coll_sym_alloc); + int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t, + new_coll_sym_alloc); if (BE (new_coll_syms == NULL, 0)) return REG_ESPACE; mbcset->coll_syms = new_coll_syms; @@ -2973,7 +3039,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, /* if (MB_CUR_MAX > 1) */ - collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); + collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_TABLEMB); @@ -2981,9 +3047,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, _NL_COLLATE_SYMB_EXTRAMB); } #endif - sbcset = re_calloc (bitset_word, BITSET_WORDS); + sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); #ifdef RE_ENABLE_I18N - mbcset = re_calloc (re_charset_t, 1); + mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); #endif /* RE_ENABLE_I18N */ #ifdef RE_ENABLE_I18N if (BE (sbcset == NULL || mbcset == NULL, 0)) @@ -3007,7 +3073,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, mbcset->non_match = 1; #endif /* not RE_ENABLE_I18N */ non_match = true; - if (syntax & REG_HAT_LISTS_NOT_NEWLINE) + if (syntax & RE_HAT_LISTS_NOT_NEWLINE) bitset_set (sbcset, '\0'); re_string_skip_bytes (regexp, token_len); /* Skip a token. */ token_len = peek_token_bracket (token, regexp, syntax); @@ -3115,10 +3181,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, { wchar_t *new_mbchars; /* Not enough, realloc it. */ - mbchar_alloc = mbcset->nmbchars; + /* +1 in case of mbcset->nmbchars is 0. */ + mbchar_alloc = 2 * mbcset->nmbchars + 1; /* Use realloc since array is NULL if *alloc == 0. */ - new_mbchars = re_x2realloc (mbcset->mbchars, wchar_t, - &mbchar_alloc); + new_mbchars = re_realloc (mbcset->mbchars, wchar_t, + mbchar_alloc); if (BE (new_mbchars == NULL, 0)) goto parse_bracket_exp_espace; mbcset->mbchars = new_mbchars; @@ -3331,13 +3398,14 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp, is a pointer argument sinse we may update it. */ static reg_errcode_t -build_equiv_class (bitset sbcset, #ifdef RE_ENABLE_I18N - re_charset_t *mbcset, Idx *equiv_class_alloc, -#endif - const unsigned char *name) +build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, + Idx *equiv_class_alloc, const unsigned char *name) +#else /* not RE_ENABLE_I18N */ +build_equiv_class (bitset_t sbcset, const unsigned char *name) +#endif /* not RE_ENABLE_I18N */ { -#if defined _LIBC +#ifdef _LIBC uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); if (nrules != 0) { @@ -3392,11 +3460,12 @@ build_equiv_class (bitset sbcset, if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) { /* Not enough, realloc it. */ - Idx new_equiv_class_alloc = mbcset->nequiv_classes; + /* +1 in case of mbcset->nequiv_classes is 0. */ + Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1; /* Use realloc since the array is NULL if *alloc == 0. */ - int32_t *new_equiv_classes = re_x2realloc (mbcset->equiv_classes, - int32_t, - &new_equiv_class_alloc); + int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes, + int32_t, + new_equiv_class_alloc); if (BE (new_equiv_classes == NULL, 0)) return REG_ESPACE; mbcset->equiv_classes = new_equiv_classes; @@ -3421,18 +3490,21 @@ build_equiv_class (bitset sbcset, is a pointer argument sinse we may update it. */ static reg_errcode_t -build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, #ifdef RE_ENABLE_I18N +build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, re_charset_t *mbcset, Idx *char_class_alloc, -#endif const unsigned char *class_name, reg_syntax_t syntax) +#else /* not RE_ENABLE_I18N */ +build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, + const unsigned char *class_name, reg_syntax_t syntax) +#endif /* not RE_ENABLE_I18N */ { int i; const char *name = (const char *) class_name; /* In case of REG_ICASE "upper" and "lower" match the both of upper and lower cases. */ - if ((syntax & REG_IGNORE_CASE) + if ((syntax & RE_ICASE) && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0)) name = "alpha"; @@ -3441,10 +3513,11 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) { /* Not enough, realloc it. */ - Idx new_char_class_alloc = mbcset->nchar_classes; + /* +1 in case of mbcset->nchar_classes is 0. */ + Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1; /* Use realloc since array is NULL if *alloc == 0. */ - wctype_t *new_char_classes = re_x2realloc (mbcset->char_classes, wctype_t, - &new_char_class_alloc); + wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t, + new_char_class_alloc); if (BE (new_char_classes == NULL, 0)) return REG_ESPACE; mbcset->char_classes = new_char_classes; @@ -3454,39 +3527,45 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, #endif /* RE_ENABLE_I18N */ #define BUILD_CHARCLASS_LOOP(ctype_func) \ - for (i = 0; i < SBC_MAX; ++i) \ + do { \ + if (BE (trans != NULL, 0)) \ { \ - if (ctype_func (i)) \ - { \ - int ch = trans ? trans[i] : i; \ - bitset_set (sbcset, ch); \ - } \ - } + for (i = 0; i < SBC_MAX; ++i) \ + if (ctype_func (i)) \ + bitset_set (sbcset, trans[i]); \ + } \ + else \ + { \ + for (i = 0; i < SBC_MAX; ++i) \ + if (ctype_func (i)) \ + bitset_set (sbcset, i); \ + } \ + } while (0) if (strcmp (name, "alnum") == 0) - BUILD_CHARCLASS_LOOP (isalnum) + BUILD_CHARCLASS_LOOP (isalnum); else if (strcmp (name, "cntrl") == 0) - BUILD_CHARCLASS_LOOP (iscntrl) + BUILD_CHARCLASS_LOOP (iscntrl); else if (strcmp (name, "lower") == 0) - BUILD_CHARCLASS_LOOP (islower) + BUILD_CHARCLASS_LOOP (islower); else if (strcmp (name, "space") == 0) - BUILD_CHARCLASS_LOOP (isspace) + BUILD_CHARCLASS_LOOP (isspace); else if (strcmp (name, "alpha") == 0) - BUILD_CHARCLASS_LOOP (isalpha) + BUILD_CHARCLASS_LOOP (isalpha); else if (strcmp (name, "digit") == 0) - BUILD_CHARCLASS_LOOP (isdigit) + BUILD_CHARCLASS_LOOP (isdigit); else if (strcmp (name, "print") == 0) - BUILD_CHARCLASS_LOOP (isprint) + BUILD_CHARCLASS_LOOP (isprint); else if (strcmp (name, "upper") == 0) - BUILD_CHARCLASS_LOOP (isupper) + BUILD_CHARCLASS_LOOP (isupper); else if (strcmp (name, "blank") == 0) - BUILD_CHARCLASS_LOOP (isblank) + BUILD_CHARCLASS_LOOP (isblank); else if (strcmp (name, "graph") == 0) - BUILD_CHARCLASS_LOOP (isgraph) + BUILD_CHARCLASS_LOOP (isgraph); else if (strcmp (name, "punct") == 0) - BUILD_CHARCLASS_LOOP (ispunct) + BUILD_CHARCLASS_LOOP (ispunct); else if (strcmp (name, "xdigit") == 0) - BUILD_CHARCLASS_LOOP (isxdigit) + BUILD_CHARCLASS_LOOP (isxdigit); else return REG_ECTYPE; @@ -3494,10 +3573,10 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset, } static bin_tree_t * -build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, +build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans, const unsigned char *class_name, - const unsigned char *extra, - bool non_match, reg_errcode_t *err) + const unsigned char *extra, bool non_match, + reg_errcode_t *err) { re_bitset_ptr_t sbcset; #ifdef RE_ENABLE_I18N @@ -3508,9 +3587,9 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, re_token_t br_token; bin_tree_t *tree; - sbcset = re_calloc (bitset_word, BITSET_WORDS); + sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); #ifdef RE_ENABLE_I18N - mbcset = re_calloc (re_charset_t, 1); + mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); #endif /* RE_ENABLE_I18N */ #ifdef RE_ENABLE_I18N @@ -3527,7 +3606,7 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans, { #ifdef RE_ENABLE_I18N /* - if (syntax & REG_HAT_LISTS_NOT_NEWLINE) + if (syntax & RE_HAT_LISTS_NOT_NEWLINE) bitset_set(cset->sbcset, '\0'); */ mbcset->non_match = 1; @@ -3627,7 +3706,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) || num == REG_ERROR) ? REG_ERROR : ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0')); - num = (num > REG_DUP_MAX) ? REG_ERROR : num; + num = (num > RE_DUP_MAX) ? REG_ERROR : num; } return num; } diff --git a/lib/regex.c b/gl/regex.c similarity index 91% rename from lib/regex.c rename to gl/regex.c index 82e76c0..d4eb726 100644 --- a/lib/regex.c +++ b/gl/regex.c @@ -1,5 +1,5 @@ /* Extended regular expression matching and search library. - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa . @@ -17,8 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include +#include + +/* Make sure noone compiles this code with a C++ compiler. */ +#if defined __cplusplus && defined _LIBC +# error "This is C code, use a C compiler" #endif #ifdef _LIBC diff --git a/lib/regex.h b/gl/regex.h similarity index 58% rename from lib/regex.h rename to gl/regex.h index c06a062..6885ebd 100644 --- a/lib/regex.h +++ b/gl/regex.h @@ -1,6 +1,6 @@ /* Definitions for data structures and routines for the regular expression library. - Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005 + Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -28,19 +28,13 @@ extern "C" { #endif -/* Define _REGEX_SOURCE to get definitions that are incompatible with - POSIX. */ -#if (!defined _REGEX_SOURCE \ - && (defined _GNU_SOURCE \ - || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \ - && !defined _XOPEN_SOURCE))) -# define _REGEX_SOURCE 1 -#endif - -#if defined _REGEX_SOURCE && defined VMS -/* VMS doesn't have `size_t' in , even though POSIX says it - should be there. */ -# include +/* Define __USE_GNU_REGEX to declare GNU extensions that violate the + POSIX name space rules. */ +#undef __USE_GNU_REGEX +#if (defined _GNU_SOURCE \ + || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \ + && !defined _XOPEN_SOURCE)) +# define __USE_GNU_REGEX 1 #endif #ifdef _REGEX_LARGE_OFFSETS @@ -53,11 +47,13 @@ extern "C" { /* The type of the offset of a byte within a string. For historical reasons POSIX 1003.1-2004 requires that regoff_t be - at least as wide as off_t. This is a bit odd (and many common - POSIX platforms set it to the more-sensible ssize_t) but we might - as well conform. We don't know of any hosts where ssize_t is wider - than off_t, so off_t is safe. */ -typedef off_t regoff_t; + at least as wide as off_t. However, many common POSIX platforms set + regoff_t to the more-sensible ssize_t and the Open Group has + signalled its intention to change the requirement to be that + regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN + 60 (2005-08-25). We don't know of any hosts where ssize_t or + ptrdiff_t is wider than ssize_t, so ssize_t is safe. */ +typedef ssize_t regoff_t; /* The type of nonnegative object indexes. Traditionally, GNU regex uses 'int' for these. Code that uses __re_idx_t should work @@ -97,20 +93,22 @@ typedef unsigned long int active_reg_t; add or remove a bit, only one other definition need change. */ typedef unsigned long int reg_syntax_t; +#ifdef __USE_GNU_REGEX + /* If this bit is not set, then \ inside a bracket expression is literal. If set, then such a \ quotes the following character. */ -#define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul +# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) /* If this bit is not set, then + and ? are operators, and \+ and \? are literals. If set, then \+ and \? are operators and + and ? are literals. */ -#define REG_BK_PLUS_QM (1ul << 1) +# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) /* If this bit is set, then character classes are supported. They are: [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. If not set, then character classes are not supported. */ -#define REG_CHAR_CLASSES (1ul << 2) +# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) /* If this bit is set, then ^ and $ are always anchors (outside bracket expressions, of course). @@ -120,11 +118,11 @@ typedef unsigned long int reg_syntax_t; $ is an anchor if it is at the end of a regular expression, or before a close-group or an alternation operator. - This bit could be (re)combined with REG_CONTEXT_INDEP_OPS, because + This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because POSIX draft 11.2 says that * etc. in leading positions is undefined. We already implemented a previous draft which made those constructs invalid, though, so we haven't changed the code back. */ -#define REG_CONTEXT_INDEP_ANCHORS (1ul << 3) +# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) /* If this bit is set, then special characters are always special regardless of where they are in the pattern. @@ -132,70 +130,71 @@ typedef unsigned long int reg_syntax_t; some contexts; otherwise they are ordinary. Specifically, * + ? and intervals are only special when not after the beginning, open-group, or alternation operator. */ -#define REG_CONTEXT_INDEP_OPS (1ul << 4) +# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) /* If this bit is set, then *, +, ?, and { cannot be first in an re or immediately after an alternation or begin-group operator. */ -#define REG_CONTEXT_INVALID_OPS (1ul << 5) +# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) /* If this bit is set, then . matches newline. If not set, then it doesn't. */ -#define REG_DOT_NEWLINE (1ul << 6) +# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) /* If this bit is set, then . doesn't match NUL. If not set, then it does. */ -#define REG_DOT_NOT_NULL (1ul << 7) +# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) /* If this bit is set, nonmatching lists [^...] do not match newline. If not set, they do. */ -#define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8) +# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) /* If this bit is set, either \{...\} or {...} defines an - interval, depending on REG_NO_BK_BRACES. + interval, depending on RE_NO_BK_BRACES. If not set, \{, \}, {, and } are literals. */ -#define REG_INTERVALS (1ul << 9) +# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) /* If this bit is set, +, ? and | aren't recognized as operators. If not set, they are. */ -#define REG_LIMITED_OPS (1ul << 10) +# define RE_LIMITED_OPS (RE_INTERVALS << 1) /* If this bit is set, newline is an alternation operator. If not set, newline is literal. */ -#define REG_NEWLINE_ALT (1ul << 11) +# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) /* If this bit is set, then `{...}' defines an interval, and \{ and \} are literals. If not set, then `\{...\}' defines an interval. */ -#define REG_NO_BK_BRACES (1ul << 12) +# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) /* If this bit is set, (...) defines a group, and \( and \) are literals. If not set, \(...\) defines a group, and ( and ) are literals. */ -#define REG_NO_BK_PARENS (1ul << 13) +# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) /* If this bit is set, then \ matches . If not set, then \ is a back-reference. */ -#define REG_NO_BK_REFS (1ul << 14) +# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) /* If this bit is set, then | is an alternation operator, and \| is literal. If not set, then \| is an alternation operator, and | is literal. */ -#define REG_NO_BK_VBAR (1ul << 15) +# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) /* If this bit is set, then an ending range point collating higher than the starting range point, as in [z-a], is invalid. - If not set, the containing range is empty and does not match any string. */ -#define REG_NO_EMPTY_RANGES (1ul << 16) + If not set, then when ending range point collates higher than the + starting range point, the range is ignored. */ +# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) /* If this bit is set, then an unmatched ) is ordinary. If not set, then an unmatched ) is invalid. */ -#define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17) +# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) /* If this bit is set, succeed as soon as we match the whole pattern, without further backtracking. */ -#define REG_NO_POSIX_BACKTRACKING (1ul << 18) +# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) /* If this bit is set, do not process the GNU regex operators. If not set, then the GNU regex operators are recognized. */ -#define REG_NO_GNU_OPS (1ul << 19) +# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) /* If this bit is set, turn on internal regex debugging. If not set, and debugging was on, turn it off. @@ -203,29 +202,31 @@ typedef unsigned long int reg_syntax_t; We define this bit always, so that all that's needed to turn on debugging is to recompile regex.c; the calling code can always have this bit set, and it won't affect anything in the normal case. */ -#define REG_DEBUG (1ul << 20) +# define RE_DEBUG (RE_NO_GNU_OPS << 1) /* If this bit is set, a syntactically invalid interval is treated as a string of ordinary characters. For example, the ERE 'a{1' is treated as 'a\{1'. */ -#define REG_INVALID_INTERVAL_ORD (1ul << 21) +# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) /* If this bit is set, then ignore case when matching. If not set, then case is significant. */ -#define REG_IGNORE_CASE (1ul << 22) +# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) -/* This bit is used internally like REG_CONTEXT_INDEP_ANCHORS but only +/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only for ^, because it is difficult to scan the regex backwards to find whether ^ should be special. */ -#define REG_CARET_ANCHORS_HERE (1ul << 23) +# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) /* If this bit is set, then \{ cannot be first in an bre or immediately after an alternation or begin-group operator. */ -#define REG_CONTEXT_INVALID_DUP (1ul << 24) +# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) /* If this bit is set, then no_sub will be set to 1 during re_compile_pattern. */ -#define REG_NO_SUB (1ul << 25) +# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) + +#endif /* defined __USE_GNU_REGEX */ /* This global variable defines the particular regexp syntax to use (for some interfaces). When a regexp is compiled, the syntax used is @@ -233,82 +234,99 @@ typedef unsigned long int reg_syntax_t; already-compiled regexps. */ extern reg_syntax_t re_syntax_options; +#ifdef __USE_GNU_REGEX /* Define combinations of the above bits for the standard possibilities. (The [[[ comments delimit what gets put into the Texinfo file, so don't delete them!) */ /* [[[begin syntaxes]]] */ -#define REG_SYNTAX_EMACS 0 - -#define REG_SYNTAX_AWK \ - (REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \ - | REG_NO_BK_PARENS | REG_NO_BK_REFS \ - | REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \ - | REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \ - | REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS) - -#define REG_SYNTAX_GNU_AWK \ - ((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ - | REG_DEBUG) \ - & ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \ - | REG_CONTEXT_INVALID_OPS )) - -#define REG_SYNTAX_POSIX_AWK \ - (REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ - | REG_INTERVALS | REG_NO_GNU_OPS) - -#define REG_SYNTAX_GREP \ - (REG_BK_PLUS_QM | REG_CHAR_CLASSES \ - | REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \ - | REG_NEWLINE_ALT) - -#define REG_SYNTAX_EGREP \ - (REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \ - | REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \ - | REG_NEWLINE_ALT | REG_NO_BK_PARENS \ - | REG_NO_BK_VBAR) - -#define REG_SYNTAX_POSIX_EGREP \ - (REG_SYNTAX_EGREP | REG_INTERVALS | REG_NO_BK_BRACES \ - | REG_INVALID_INTERVAL_ORD) +# define RE_SYNTAX_EMACS 0 + +# define RE_SYNTAX_AWK \ + (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ + | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ + | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) + +# define RE_SYNTAX_GNU_AWK \ + ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ + & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ + | RE_CONTEXT_INVALID_OPS )) + +# define RE_SYNTAX_POSIX_AWK \ + (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INTERVALS | RE_NO_GNU_OPS) + +# define RE_SYNTAX_GREP \ + (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ + | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ + | RE_NEWLINE_ALT) + +# define RE_SYNTAX_EGREP \ + (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ + | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ + | RE_NO_BK_VBAR) + +# define RE_SYNTAX_POSIX_EGREP \ + (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ + | RE_INVALID_INTERVAL_ORD) /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC +# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC -#define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC +# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC /* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _REG_SYNTAX_POSIX_COMMON \ - (REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \ - | REG_INTERVALS | REG_NO_EMPTY_RANGES) +# define _RE_SYNTAX_POSIX_COMMON \ + (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ + | RE_INTERVALS | RE_NO_EMPTY_RANGES) -#define REG_SYNTAX_POSIX_BASIC \ - (_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP) +# define RE_SYNTAX_POSIX_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) -/* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes - REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this +/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes + RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this isn't minimal, since other operators, such as \`, aren't disabled. */ -#define REG_SYNTAX_POSIX_MINIMAL_BASIC \ - (_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS) - -#define REG_SYNTAX_POSIX_EXTENDED \ - (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ - | REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \ - | REG_NO_BK_PARENS | REG_NO_BK_VBAR \ - | REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is - removed and REG_NO_BK_REFS is added. */ -#define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ - | REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \ - | REG_NO_BK_PARENS | REG_NO_BK_REFS \ - | REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD) +# define RE_SYNTAX_POSIX_MINIMAL_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) + +# define RE_SYNTAX_POSIX_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ + | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) + +/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is + removed and RE_NO_BK_REFS is added. */ +# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) /* [[[end syntaxes]]] */ + +#endif /* defined __USE_GNU_REGEX */ -/* Maximum number of duplicates an interval can allow. This is - distinct from RE_DUP_MAX, to conform to POSIX name space rules and - to avoid collisions with . */ -#define REG_DUP_MAX 32767 +#ifdef __USE_GNU_REGEX + +/* Maximum number of duplicates an interval can allow. POSIX-conforming + systems might define this in , but we want our + value, so remove any previous define. */ +# ifdef RE_DUP_MAX +# undef RE_DUP_MAX +# endif + +/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored + the counter as a 2-byte signed integer. This is no longer true, so + RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to + ((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined. + However, there would be a huge performance problem if someone + actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains + its historical value. */ +# define RE_DUP_MAX (0x7fff) + +#endif /* defined __USE_GNU_REGEX */ /* POSIX `cflags' bits (i.e., information for `regcomp'). */ @@ -354,72 +372,55 @@ extern reg_syntax_t re_syntax_options; typedef enum { _REG_ENOSYS = -1, /* This will never happen for this implementation. */ -#define REG_ENOSYS _REG_ENOSYS - - _REG_NOERROR, /* Success. */ -#define REG_NOERROR _REG_NOERROR - + _REG_NOERROR = 0, /* Success. */ _REG_NOMATCH, /* Didn't find a match (for regexec). */ -#define REG_NOMATCH _REG_NOMATCH /* POSIX regcomp return error codes. (In the order listed in the standard.) */ - _REG_BADPAT, /* Invalid pattern. */ -#define REG_BADPAT _REG_BADPAT - - _REG_ECOLLATE, /* Inalid collating element. */ -#define REG_ECOLLATE _REG_ECOLLATE - + _REG_ECOLLATE, /* Invalid collating element. */ _REG_ECTYPE, /* Invalid character class name. */ -#define REG_ECTYPE _REG_ECTYPE - _REG_EESCAPE, /* Trailing backslash. */ -#define REG_EESCAPE _REG_EESCAPE - _REG_ESUBREG, /* Invalid back reference. */ -#define REG_ESUBREG _REG_ESUBREG - _REG_EBRACK, /* Unmatched left bracket. */ -#define REG_EBRACK _REG_EBRACK - _REG_EPAREN, /* Parenthesis imbalance. */ -#define REG_EPAREN _REG_EPAREN - _REG_EBRACE, /* Unmatched \{. */ -#define REG_EBRACE _REG_EBRACE - _REG_BADBR, /* Invalid contents of \{\}. */ -#define REG_BADBR _REG_BADBR - _REG_ERANGE, /* Invalid range end. */ -#define REG_ERANGE _REG_ERANGE - _REG_ESPACE, /* Ran out of memory. */ -#define REG_ESPACE _REG_ESPACE - _REG_BADRPT, /* No preceding re for repetition op. */ -#define REG_BADRPT _REG_BADRPT /* Error codes we've added. */ - _REG_EEND, /* Premature end. */ -#define REG_EEND _REG_EEND - _REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ -#define REG_ESIZE _REG_ESIZE - _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -#define REG_ERPAREN _REG_ERPAREN - } reg_errcode_t; + +#ifdef _XOPEN_SOURCE +# define REG_ENOSYS _REG_ENOSYS +#endif +#define REG_NOERROR _REG_NOERROR +#define REG_NOMATCH _REG_NOMATCH +#define REG_BADPAT _REG_BADPAT +#define REG_ECOLLATE _REG_ECOLLATE +#define REG_ECTYPE _REG_ECTYPE +#define REG_EESCAPE _REG_EESCAPE +#define REG_ESUBREG _REG_ESUBREG +#define REG_EBRACK _REG_EBRACK +#define REG_EPAREN _REG_EPAREN +#define REG_EBRACE _REG_EBRACE +#define REG_BADBR _REG_BADBR +#define REG_ERANGE _REG_ERANGE +#define REG_ESPACE _REG_ESPACE +#define REG_BADRPT _REG_BADRPT +#define REG_EEND _REG_EEND +#define REG_ESIZE _REG_ESIZE +#define REG_ERPAREN _REG_ERPAREN -/* In the traditional GNU implementation, regex.h defined member names - like `buffer' that POSIX does not allow. These members now have - names with leading `re_' (e.g., `re_buffer'). Support the old - names only if _REGEX_SOURCE is defined. New programs should use - the new names. */ -#ifdef _REGEX_SOURCE +/* struct re_pattern_buffer normally uses member names like `buffer' + that POSIX does not allow. In POSIX mode these members have names + with leading `re_' (e.g., `re_buffer'). */ +#ifdef __USE_GNU_REGEX # define _REG_RE_NAME(id) id # define _REG_RM_NAME(id) id #else @@ -428,88 +429,87 @@ typedef enum #endif /* The user can specify the type of the re_translate member by - defining the macro REG_TRANSLATE_TYPE. In the traditional GNU - implementation, this macro was named RE_TRANSLATE_TYPE, but POSIX - does not allow this. Support the old name only if _REGEX_SOURCE - and if the new name is not defined. New programs should use the new - name. */ -#ifndef REG_TRANSLATE_TYPE -# if defined _REGEX_SOURCE && defined RE_TRANSLATE_TYPE -# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE -# else -# define REG_TRANSLATE_TYPE char * + defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned + char *. This pollutes the POSIX name space, so in POSIX mode just + use unsigned char *. */ +#ifdef __USE_GNU_REGEX +# ifndef RE_TRANSLATE_TYPE +# define RE_TRANSLATE_TYPE unsigned char * # endif +# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE +#else +# define REG_TRANSLATE_TYPE unsigned char * #endif /* This data structure represents a compiled pattern. Before calling - the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap', - `re_translate', and `re_no_sub' can be set. After the pattern has been + the pattern compiler, the fields `buffer', `allocated', `fastmap', + `translate', and `no_sub' can be set. After the pattern has been compiled, the `re_nsub' field is available. All other fields are private to the regex routines. */ struct re_pattern_buffer { -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ + /* Space that holds the compiled pattern. It is declared as + `unsigned char *' because its elements are sometimes used as + array indexes. */ unsigned char *_REG_RE_NAME (buffer); - /* Number of bytes to which `re_buffer' points. */ + /* Number of bytes to which `buffer' points. */ __re_long_size_t _REG_RE_NAME (allocated); - /* Number of bytes actually used in `re_buffer'. */ + /* Number of bytes actually used in `buffer'. */ __re_long_size_t _REG_RE_NAME (used); - /* Syntax setting with which the pattern was compiled. */ + /* Syntax setting with which the pattern was compiled. */ reg_syntax_t _REG_RE_NAME (syntax); - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ + /* Pointer to a fastmap, if any, otherwise zero. re_search uses the + fastmap, if there is one, to skip over impossible starting points + for matches. */ char *_REG_RE_NAME (fastmap); - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ + /* Either a translate table to apply to all characters before + comparing them, or zero for no translation. The translation is + applied to a pattern when it is compiled and to a string when it + is matched. */ REG_TRANSLATE_TYPE _REG_RE_NAME (translate); - /* Number of subexpressions found by the compiler. */ + /* Number of subexpressions found by the compiler. */ size_t re_nsub; - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ + /* Zero if this pattern cannot match the empty string, one else. + Well, in truth it's used only in `re_search_2', to see whether or + not we should use the fastmap, so we don't set this absolutely + perfectly; see `re_compile_fastmap' (the `duplicate' case). */ unsigned int _REG_RE_NAME (can_be_null) : 1; - /* If REG_UNALLOCATED, allocate space in the `regs' structure - for `max (REG_NREGS, re_nsub + 1)' groups. - If REG_REALLOCATE, reallocate space if necessary. - If REG_FIXED, use what's there. */ -#define REG_UNALLOCATED 0 -#define REG_REALLOCATE 1 -#define REG_FIXED 2 + /* If REGS_UNALLOCATED, allocate space in the `regs' structure + for `max (RE_NREGS, re_nsub + 1)' groups. + If REGS_REALLOCATE, reallocate space if necessary. + If REGS_FIXED, use what's there. */ +#ifdef __USE_GNU_REGEX +# define REGS_UNALLOCATED 0 +# define REGS_REALLOCATE 1 +# define REGS_FIXED 2 +#endif unsigned int _REG_RE_NAME (regs_allocated) : 2; - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ + /* Set to zero when `regex_compile' compiles a pattern; set to one + by `re_compile_fastmap' if it updates the fastmap. */ unsigned int _REG_RE_NAME (fastmap_accurate) : 1; - /* If set, `re_match_2' does not return information about - subexpressions. */ + /* If set, `re_match_2' does not return information about + subexpressions. */ unsigned int _REG_RE_NAME (no_sub) : 1; - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ + /* If set, a beginning-of-line anchor doesn't match at the beginning + of the string. */ unsigned int _REG_RE_NAME (not_bol) : 1; - /* Similarly for an end-of-line anchor. */ + /* Similarly for an end-of-line anchor. */ unsigned int _REG_RE_NAME (not_eol) : 1; - /* If true, an anchor at a newline matches. */ + /* If true, an anchor at a newline matches. */ unsigned int _REG_RE_NAME (newline_anchor) : 1; /* [[[end pattern_buffer]]] */ @@ -527,11 +527,11 @@ struct re_registers }; -/* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer, +/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, `re_match_2' returns information about at least this many registers the first time a `regs' structure is passed. */ -#ifndef REG_NREGS -# define REG_NREGS 30 +#if !defined RE_NREGS && defined __USE_GNU_REGEX +# define RE_NREGS 30 #endif @@ -567,7 +567,7 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); compiled into BUFFER. Start searching at position START, for RANGE characters. Return the starting position of the match, -1 for no match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */ + information in REGS (if REGS and BUFFER->no_sub are nonzero). */ extern regoff_t re_search (struct re_pattern_buffer *__buffer, const char *__string, __re_idx_t __length, __re_idx_t __start, regoff_t __range, @@ -635,13 +635,17 @@ extern int re_exec (const char *); # endif # endif #endif -/* gcc 3.1 and up support the [restrict] syntax, but g++ doesn't. */ -#ifndef __restrict_arr -# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && !defined __cplusplus -# define __restrict_arr __restrict -# else -# define __restrict_arr -# endif +/* gcc 3.1 and up support the [restrict] syntax. Don't trust + sys/cdefs.h's definition of __restrict_arr, though, as it + mishandles gcc -ansi -pedantic. */ +#undef __restrict_arr +#if ((199901L <= __STDC_VERSION__ \ + || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ + && !__STRICT_ANSI__)) \ + && !defined __GNUG__) +# define __restrict_arr __restrict +#else +# define __restrict_arr #endif /* POSIX compatibility. */ @@ -660,110 +664,8 @@ extern size_t regerror (int __errcode, const regex_t *__restrict __preg, extern void regfree (regex_t *__preg); -#ifdef _REGEX_SOURCE - -/* Define the POSIX-compatible member names in terms of the - incompatible (and deprecated) names established by _REG_RE_NAME. - New programs should use the re_* names. */ - -# define re_allocated allocated -# define re_buffer buffer -# define re_can_be_null can_be_null -# define re_fastmap fastmap -# define re_fastmap_accurate fastmap_accurate -# define re_newline_anchor newline_anchor -# define re_no_sub no_sub -# define re_not_bol not_bol -# define re_not_eol not_eol -# define re_regs_allocated regs_allocated -# define re_syntax syntax -# define re_translate translate -# define re_used used - -/* Similarly for _REG_RM_NAME. */ - -# define rm_end end -# define rm_num_regs num_regs -# define rm_start start - -/* Undef RE_DUP_MAX first, in case the user has already included a - with an incompatible definition. - - On GNU systems, the most common spelling for RE_DUP_MAX's value in - is (0x7ffff), so define RE_DUP_MAX to that, not to - REG_DUP_MAX. This avoid some duplicate-macro-definition warnings - with programs that include after this file. - - New programs should not assume that regex.h defines RE_DUP_MAX; to - get the value of RE_DUP_MAX, they should instead include - and possibly invoke the sysconf function. */ - -# undef RE_DUP_MAX -# define RE_DUP_MAX (0x7fff) - -/* Define the following symbols for backward source compatibility. - These symbols violate the POSIX name space rules, and new programs - should avoid them. */ - -# define REGS_FIXED REG_FIXED -# define REGS_REALLOCATE REG_REALLOCATE -# define REGS_UNALLOCATED REG_UNALLOCATED -# define RE_BACKSLASH_ESCAPE_IN_LISTS REG_BACKSLASH_ESCAPE_IN_LISTS -# define RE_BK_PLUS_QM REG_BK_PLUS_QM -# define RE_CARET_ANCHORS_HERE REG_CARET_ANCHORS_HERE -# define RE_CHAR_CLASSES REG_CHAR_CLASSES -# define RE_CONTEXT_INDEP_ANCHORS REG_CONTEXT_INDEP_ANCHORS -# define RE_CONTEXT_INDEP_OPS REG_CONTEXT_INDEP_OPS -# define RE_CONTEXT_INVALID_DUP REG_CONTEXT_INVALID_DUP -# define RE_CONTEXT_INVALID_OPS REG_CONTEXT_INVALID_OPS -# define RE_DEBUG REG_DEBUG -# define RE_DOT_NEWLINE REG_DOT_NEWLINE -# define RE_DOT_NOT_NULL REG_DOT_NOT_NULL -# define RE_HAT_LISTS_NOT_NEWLINE REG_HAT_LISTS_NOT_NEWLINE -# define RE_ICASE REG_IGNORE_CASE /* avoid collision with REG_ICASE */ -# define RE_INTERVALS REG_INTERVALS -# define RE_INVALID_INTERVAL_ORD REG_INVALID_INTERVAL_ORD -# define RE_LIMITED_OPS REG_LIMITED_OPS -# define RE_NEWLINE_ALT REG_NEWLINE_ALT -# define RE_NO_BK_BRACES REG_NO_BK_BRACES -# define RE_NO_BK_PARENS REG_NO_BK_PARENS -# define RE_NO_BK_REFS REG_NO_BK_REFS -# define RE_NO_BK_VBAR REG_NO_BK_VBAR -# define RE_NO_EMPTY_RANGES REG_NO_EMPTY_RANGES -# define RE_NO_GNU_OPS REG_NO_GNU_OPS -# define RE_NO_POSIX_BACKTRACKING REG_NO_POSIX_BACKTRACKING -# define RE_NO_SUB REG_NO_SUB -# define RE_NREGS REG_NREGS -# define RE_SYNTAX_AWK REG_SYNTAX_AWK -# define RE_SYNTAX_ED REG_SYNTAX_ED -# define RE_SYNTAX_EGREP REG_SYNTAX_EGREP -# define RE_SYNTAX_EMACS REG_SYNTAX_EMACS -# define RE_SYNTAX_GNU_AWK REG_SYNTAX_GNU_AWK -# define RE_SYNTAX_GREP REG_SYNTAX_GREP -# define RE_SYNTAX_POSIX_AWK REG_SYNTAX_POSIX_AWK -# define RE_SYNTAX_POSIX_BASIC REG_SYNTAX_POSIX_BASIC -# define RE_SYNTAX_POSIX_EGREP REG_SYNTAX_POSIX_EGREP -# define RE_SYNTAX_POSIX_EXTENDED REG_SYNTAX_POSIX_EXTENDED -# define RE_SYNTAX_POSIX_MINIMAL_BASIC REG_SYNTAX_POSIX_MINIMAL_BASIC -# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED REG_SYNTAX_POSIX_MINIMAL_EXTENDED -# define RE_SYNTAX_SED REG_SYNTAX_SED -# define RE_UNMATCHED_RIGHT_PAREN_ORD REG_UNMATCHED_RIGHT_PAREN_ORD -# ifndef RE_TRANSLATE_TYPE -# define RE_TRANSLATE_TYPE REG_TRANSLATE_TYPE -# endif - -#endif /* defined _REGEX_SOURCE */ - #ifdef __cplusplus } #endif /* C++ */ #endif /* regex.h */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/lib/regex_internal.c b/gl/regex_internal.c similarity index 84% rename from lib/regex_internal.c rename to gl/regex_internal.c index ad618cf..78e16f3 100644 --- a/lib/regex_internal.c +++ b/gl/regex_internal.c @@ -1,5 +1,5 @@ /* Extended regular expression matching and search library. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa . @@ -19,7 +19,7 @@ static void re_string_construct_common (const char *str, Idx len, re_string_t *pstr, - REG_TRANSLATE_TYPE trans, bool icase, + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) internal_function; static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, @@ -37,7 +37,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, static reg_errcode_t internal_function re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, - REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) { reg_errcode_t ret; Idx init_buf_len; @@ -65,7 +65,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, static reg_errcode_t internal_function re_string_construct (re_string_t *pstr, const char *str, Idx len, - REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) { reg_errcode_t ret; memset (pstr, '\0', sizeof (re_string_t)); @@ -132,13 +132,20 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) #ifdef RE_ENABLE_I18N if (pstr->mb_cur_max > 1) { - wint_t *new_wcs = re_xrealloc (pstr->wcs, wint_t, new_buf_len); + wint_t *new_wcs; + + /* Avoid overflow. */ + size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx)); + if (BE (SIZE_MAX / max_object_size < new_buf_len, 0)) + return REG_ESPACE; + + new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); if (BE (new_wcs == NULL, 0)) return REG_ESPACE; pstr->wcs = new_wcs; if (pstr->offsets != NULL) { - Idx *new_offsets = re_xrealloc (pstr->offsets, Idx, new_buf_len); + Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len); if (BE (new_offsets == NULL, 0)) return REG_ESPACE; pstr->offsets = new_offsets; @@ -161,13 +168,13 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) static void internal_function re_string_construct_common (const char *str, Idx len, re_string_t *pstr, - REG_TRANSLATE_TYPE trans, bool icase, + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) { pstr->raw_mbs = (const unsigned char *) str; pstr->len = len; pstr->raw_len = len; - pstr->trans = (unsigned REG_TRANSLATE_TYPE) trans; + pstr->trans = trans; pstr->icase = icase; pstr->mbs_allocated = (trans != NULL || icase); pstr->mb_cur_max = dfa->mb_cur_max; @@ -301,7 +308,7 @@ build_wcs_upper_buffer (re_string_t *pstr) mbclen = mbrtowc (&wc, ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx), remain_len, &pstr->cur_state); - if (BE ((size_t) (mbclen + 2) > 2, 1)) + if (BE (mbclen < (size_t) -2, 1)) { wchar_t wcu = wc; if (iswlower (wc)) @@ -369,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) else p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state); - if (BE ((size_t) (mbclen + 2) > 2, 1)) + if (BE (mbclen < (size_t) -2, 1)) { wchar_t wcu = wc; if (iswlower (wc)) @@ -392,7 +399,7 @@ build_wcs_upper_buffer (re_string_t *pstr) if (pstr->offsets == NULL) { - pstr->offsets = re_xmalloc (Idx, pstr->bufs_len); + pstr->offsets = re_malloc (Idx, pstr->bufs_len); if (pstr->offsets == NULL) return REG_ESPACE; @@ -481,27 +488,34 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc) mbstate_t prev_st; Idx rawbuf_idx; size_t mbclen; - wchar_t wc = 0; + wint_t wc = WEOF; /* Skip the characters which are not necessary to check. */ for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len; rawbuf_idx < new_raw_idx;) { + wchar_t wc2; Idx remain_len; remain_len = pstr->len - rawbuf_idx; prev_st = pstr->cur_state; - mbclen = mbrtowc (&wc, (const char *) pstr->raw_mbs + rawbuf_idx, + mbclen = mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx, remain_len, &pstr->cur_state); if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) { - /* We treat these cases as a singlebyte character. */ + /* We treat these cases as a single byte character. */ + if (mbclen == 0 || remain_len == 0) + wc = L'\0'; + else + wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx); mbclen = 1; pstr->cur_state = prev_st; } + else + wc = wc2; /* Then proceed the next character. */ rawbuf_idx += mbclen; } - *last_wc = (wint_t) wc; + *last_wc = wc; return rawbuf_idx; } #endif /* RE_ENABLE_I18N */ @@ -583,34 +597,98 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) if (BE (offset != 0, 1)) { - /* Are the characters which are already checked remain? */ - if (BE (offset < pstr->valid_raw_len, 1) -#ifdef RE_ENABLE_I18N - /* Handling this would enlarge the code too much. - Accept a slowdown in that case. */ - && pstr->offsets_needed == 0 -#endif - ) + /* Should the already checked characters be kept? */ + if (BE (offset < pstr->valid_raw_len, 1)) { /* Yes, move them to the front of the buffer. */ - pstr->tip_context = re_string_context_at (pstr, offset - 1, eflags); #ifdef RE_ENABLE_I18N - if (pstr->mb_cur_max > 1) - memmove (pstr->wcs, pstr->wcs + offset, - (pstr->valid_len - offset) * sizeof (wint_t)); + if (BE (pstr->offsets_needed, 0)) + { + Idx low = 0, high = pstr->valid_len, mid; + do + { + mid = (high + low) / 2; + if (pstr->offsets[mid] > offset) + high = mid; + else if (pstr->offsets[mid] < offset) + low = mid + 1; + else + break; + } + while (low < high); + if (pstr->offsets[mid] < offset) + ++mid; + pstr->tip_context = re_string_context_at (pstr, mid - 1, + eflags); + /* This can be quite complicated, so handle specially + only the common and easy case where the character with + different length representation of lower and upper + case is present at or after offset. */ + if (pstr->valid_len > offset + && mid == offset && pstr->offsets[mid] == offset) + { + memmove (pstr->wcs, pstr->wcs + offset, + (pstr->valid_len - offset) * sizeof (wint_t)); + memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); + pstr->valid_len -= offset; + pstr->valid_raw_len -= offset; + for (low = 0; low < pstr->valid_len; low++) + pstr->offsets[low] = pstr->offsets[low + offset] - offset; + } + else + { + /* Otherwise, just find out how long the partial multibyte + character at offset is and fill it with WEOF/255. */ + pstr->len = pstr->raw_len - idx + offset; + pstr->stop = pstr->raw_stop - idx + offset; + pstr->offsets_needed = 0; + while (mid > 0 && pstr->offsets[mid - 1] == offset) + --mid; + while (mid < pstr->valid_len) + if (pstr->wcs[mid] != WEOF) + break; + else + ++mid; + if (mid == pstr->valid_len) + pstr->valid_len = 0; + else + { + pstr->valid_len = pstr->offsets[mid] - offset; + if (pstr->valid_len) + { + for (low = 0; low < pstr->valid_len; ++low) + pstr->wcs[low] = WEOF; + memset (pstr->mbs, 255, pstr->valid_len); + } + } + pstr->valid_raw_len = pstr->valid_len; + } + } + else +#endif + { + pstr->tip_context = re_string_context_at (pstr, offset - 1, + eflags); +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + memmove (pstr->wcs, pstr->wcs + offset, + (pstr->valid_len - offset) * sizeof (wint_t)); #endif /* RE_ENABLE_I18N */ - if (BE (pstr->mbs_allocated, 0)) - memmove (pstr->mbs, pstr->mbs + offset, - pstr->valid_len - offset); - pstr->valid_len -= offset; - pstr->valid_raw_len -= offset; + if (BE (pstr->mbs_allocated, 0)) + memmove (pstr->mbs, pstr->mbs + offset, + pstr->valid_len - offset); + pstr->valid_len -= offset; + pstr->valid_raw_len -= offset; #if DEBUG - assert (pstr->valid_len > 0); + assert (pstr->valid_len > 0); #endif + } } else { /* No, skip all characters until IDX. */ + Idx prev_valid_len = pstr->valid_len; + #ifdef RE_ENABLE_I18N if (BE (pstr->offsets_needed, 0)) { @@ -620,7 +698,6 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) } #endif pstr->valid_len = 0; - pstr->valid_raw_len = 0; #ifdef RE_ENABLE_I18N if (pstr->mb_cur_max > 1) { @@ -635,60 +712,80 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) byte other than 0x80 - 0xbf. */ raw = pstr->raw_mbs + pstr->raw_mbs_idx; end = raw + (offset - pstr->mb_cur_max); - for (p = raw + offset - 1; p >= end; --p) - if ((*p & 0xc0) != 0x80) - { - mbstate_t cur_state; - wchar_t wc2; - Idx mlen = raw + pstr->len - p; - unsigned char buf[6]; - size_t mbclen; - - q = p; - if (BE (pstr->trans != NULL, 0)) - { - int i = mlen < 6 ? mlen : 6; - while (--i >= 0) - buf[i] = pstr->trans[p[i]]; - q = buf; - } - /* XXX Don't use mbrtowc, we know which conversion - to use (UTF-8 -> UCS4). */ - memset (&cur_state, 0, sizeof (cur_state)); - mbclen = mbrtowc (&wc2, (const char *) p, mlen, - &cur_state); - if (raw + offset - p <= mbclen && mbclen < (size_t) -2) - { - memset (&pstr->cur_state, '\0', - sizeof (mbstate_t)); - pstr->valid_len = mbclen - (raw + offset - p); - wc = wc2; - } - break; - } + if (end < pstr->raw_mbs) + end = pstr->raw_mbs; + p = raw + offset - 1; +#ifdef _LIBC + /* We know the wchar_t encoding is UCS4, so for the simple + case, ASCII characters, skip the conversion step. */ + if (isascii (*p) && BE (pstr->trans == NULL, 1)) + { + memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); + /* pstr->valid_len = 0; */ + wc = (wchar_t) *p; + } + else +#endif + for (; p >= end; --p) + if ((*p & 0xc0) != 0x80) + { + mbstate_t cur_state; + wchar_t wc2; + Idx mlen = raw + pstr->len - p; + unsigned char buf[6]; + size_t mbclen; + + q = p; + if (BE (pstr->trans != NULL, 0)) + { + int i = mlen < 6 ? mlen : 6; + while (--i >= 0) + buf[i] = pstr->trans[p[i]]; + q = buf; + } + /* XXX Don't use mbrtowc, we know which conversion + to use (UTF-8 -> UCS4). */ + memset (&cur_state, 0, sizeof (cur_state)); + mbclen = mbrtowc (&wc2, (const char *) p, mlen, + &cur_state); + if (raw + offset - p <= mbclen + && mbclen < (size_t) -2) + { + memset (&pstr->cur_state, '\0', + sizeof (mbstate_t)); + pstr->valid_len = mbclen - (raw + offset - p); + wc = wc2; + } + break; + } } if (wc == WEOF) pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx; + if (wc == WEOF) + pstr->tip_context + = re_string_context_at (pstr, prev_valid_len - 1, eflags); + else + pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) + && IS_WIDE_WORD_CHAR (wc)) + ? CONTEXT_WORD + : ((IS_WIDE_NEWLINE (wc) + && pstr->newline_anchor) + ? CONTEXT_NEWLINE : 0)); if (BE (pstr->valid_len, 0)) { for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) pstr->wcs[wcs_idx] = WEOF; if (pstr->mbs_allocated) - memset (pstr->mbs, -1, pstr->valid_len); + memset (pstr->mbs, 255, pstr->valid_len); } pstr->valid_raw_len = pstr->valid_len; - pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) - && IS_WIDE_WORD_CHAR (wc)) - ? CONTEXT_WORD - : ((IS_WIDE_NEWLINE (wc) - && pstr->newline_anchor) - ? CONTEXT_NEWLINE : 0)); } else #endif /* RE_ENABLE_I18N */ { int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; + pstr->valid_raw_len = 0; if (pstr->trans) c = pstr->trans[c]; pstr->tip_context = (bitset_contain (pstr->word_char, c) @@ -719,15 +816,15 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) } else #endif /* RE_ENABLE_I18N */ - if (BE (pstr->mbs_allocated, 0)) - { - if (pstr->icase) - build_upper_buffer (pstr); - else if (pstr->trans != NULL) - re_string_translate_buffer (pstr); - } - else - pstr->valid_len = pstr->len; + if (BE (pstr->mbs_allocated, 0)) + { + if (pstr->icase) + build_upper_buffer (pstr); + else if (pstr->trans != NULL) + re_string_translate_buffer (pstr); + } + else + pstr->valid_len = pstr->len; pstr->cur_idx = 0; return REG_NOERROR; @@ -873,7 +970,7 @@ re_node_set_alloc (re_node_set *set, Idx size) { set->alloc = size; set->nelem = 0; - set->elems = re_xmalloc (Idx, size); + set->elems = re_malloc (Idx, size); if (BE (set->elems == NULL, 0)) return REG_ESPACE; return REG_NOERROR; @@ -939,7 +1036,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src) dest->alloc = dest->nelem = 0; return REG_ESPACE; } - memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]); + memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); } else re_node_set_init_empty (dest); @@ -964,12 +1061,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, if (src1->nelem + src2->nelem + dest->nelem > dest->alloc) { Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; - Idx *new_elems; - if (sizeof (Idx) < 3 - && (new_alloc < dest->alloc - || ((Idx) (src1->nelem + src2->nelem) < src1->nelem))) - return REG_ESPACE; - new_elems = re_xrealloc (dest->elems, Idx, new_alloc); + Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); if (BE (new_elems == NULL, 0)) return REG_ESPACE; dest->elems = new_elems; @@ -1038,7 +1130,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, } /* Copy remaining SRC elements. */ - memcpy (dest->elems, dest->elems + sbase, delta * sizeof dest->elems[0]); + memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx)); return REG_NOERROR; } @@ -1055,9 +1147,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1, if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0) { dest->alloc = src1->nelem + src2->nelem; - if (sizeof (Idx) < 2 && dest->alloc < src1->nelem) - return REG_ESPACE; - dest->elems = re_xmalloc (Idx, dest->alloc); + dest->elems = re_malloc (Idx, dest->alloc); if (BE (dest->elems == NULL, 0)) return REG_ESPACE; } @@ -1085,13 +1175,13 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1, if (i1 < src1->nelem) { memcpy (dest->elems + id, src1->elems + i1, - (src1->nelem - i1) * sizeof dest->elems[0]); + (src1->nelem - i1) * sizeof (Idx)); id += src1->nelem - i1; } else if (i2 < src2->nelem) { memcpy (dest->elems + id, src2->elems + i2, - (src2->nelem - i2) * sizeof dest->elems[0]); + (src2->nelem - i2) * sizeof (Idx)); id += src2->nelem - i2; } dest->nelem = id; @@ -1108,17 +1198,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) Idx is, id, sbase, delta; if (src == NULL || src->nelem == 0) return REG_NOERROR; - if (sizeof (Idx) < 3 - && ((Idx) (2 * src->nelem) < src->nelem - || (Idx) (2 * src->nelem + dest->nelem) < dest->nelem)) - return REG_ESPACE; if (dest->alloc < 2 * src->nelem + dest->nelem) { - Idx new_alloc = src->nelem + dest->alloc; - Idx *new_buffer; - if (sizeof (Idx) < 4 && new_alloc < dest->alloc) - return REG_ESPACE; - new_buffer = re_x2realloc (dest->elems, Idx, &new_alloc); + Idx new_alloc = 2 * (src->nelem + dest->alloc); + Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc); if (BE (new_buffer == NULL, 0)) return REG_ESPACE; dest->elems = new_buffer; @@ -1128,7 +1211,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) if (BE (dest->nelem == 0, 0)) { dest->nelem = src->nelem; - memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]); + memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); return REG_NOERROR; } @@ -1150,8 +1233,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) { /* If DEST is exhausted, the remaining items of SRC must be unique. */ sbase -= is + 1; - memcpy (dest->elems + sbase, src->elems, - (is + 1) * sizeof dest->elems[0]); + memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx)); } id = dest->nelem - 1; @@ -1180,7 +1262,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) { /* Copy remaining SRC elements. */ memcpy (dest->elems, dest->elems + sbase, - delta * sizeof dest->elems[0]); + delta * sizeof (Idx)); break; } } @@ -1200,7 +1282,7 @@ re_node_set_insert (re_node_set *set, Idx elem) Idx idx; /* In case the set is empty. */ if (set->alloc == 0) - return re_node_set_init_1 (set, elem) == REG_NOERROR; + return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1); if (BE (set->nelem, 0) == 0) { @@ -1213,7 +1295,9 @@ re_node_set_insert (re_node_set *set, Idx elem) /* Realloc if we need. */ if (set->alloc == set->nelem) { - Idx *new_elems = re_x2realloc (set->elems, Idx, &set->alloc); + Idx *new_elems; + set->alloc = set->alloc * 2; + new_elems = re_realloc (set->elems, Idx, set->alloc); if (BE (new_elems == NULL, 0)) return false; set->elems = new_elems; @@ -1251,7 +1335,8 @@ re_node_set_insert_last (re_node_set *set, Idx elem) if (set->alloc == set->nelem) { Idx *new_elems; - new_elems = re_x2realloc (set->elems, Idx, &set->alloc); + set->alloc = (set->alloc + 1) * 2; + new_elems = re_realloc (set->elems, Idx, set->alloc); if (BE (new_elems == NULL, 0)) return false; set->elems = new_elems; @@ -1321,21 +1406,28 @@ static Idx internal_function re_dfa_add_node (re_dfa_t *dfa, re_token_t token) { - int type = token.type; if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) { - Idx new_nodes_alloc = dfa->nodes_alloc; + size_t new_nodes_alloc = dfa->nodes_alloc * 2; Idx *new_nexts, *new_indices; re_node_set *new_edests, *new_eclosures; + re_token_t *new_nodes; + size_t max_object_size = + MAX (sizeof (re_token_t), + MAX (sizeof (re_node_set), + sizeof (Idx))); + + /* Avoid overflows. */ + if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0)) + return REG_MISSING; - re_token_t *new_nodes = re_x2realloc (dfa->nodes, re_token_t, - &new_nodes_alloc); + new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); if (BE (new_nodes == NULL, 0)) return REG_MISSING; dfa->nodes = new_nodes; new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); - new_edests = re_xrealloc (dfa->edests, re_node_set, new_nodes_alloc); + new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); if (BE (new_nexts == NULL || new_indices == NULL || new_edests == NULL || new_eclosures == NULL, 0)) @@ -1349,8 +1441,11 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token) dfa->nodes[dfa->nodes_len] = token; dfa->nodes[dfa->nodes_len].constraint = 0; #ifdef RE_ENABLE_I18N + { + int type = token.type; dfa->nodes[dfa->nodes_len].accept_mb = (type == OP_PERIOD && dfa->mb_cur_max > 1) || type == COMPLEX_BRACKET; + } #endif dfa->nexts[dfa->nodes_len] = REG_MISSING; 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) - We never return non-NULL value in case of any errors, it is for optimization. */ -static re_dfastate_t* +static re_dfastate_t * internal_function -re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) +re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, + const re_node_set *nodes) { re_hashval_t hash; re_dfastate_t *new_state; @@ -1409,13 +1505,10 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) /* There are no appropriate state in the dfa, create the new one. */ new_state = create_ci_newstate (dfa, nodes, hash); - if (BE (new_state != NULL, 1)) - return new_state; - else - { - *err = REG_ESPACE; - return NULL; - } + if (BE (new_state == NULL, 0)) + *err = REG_ESPACE; + + return new_state; } /* Search for the state whose node_set is equivalent to NODES and @@ -1428,9 +1521,9 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes) - We never return non-NULL value in case of any errors, it is for optimization. */ -static re_dfastate_t* +static re_dfastate_t * internal_function -re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, +re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, const re_node_set *nodes, unsigned int context) { re_hashval_t hash; @@ -1459,13 +1552,10 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, } /* There are no appropriate state in `dfa', create the new one. */ new_state = create_cd_newstate (dfa, nodes, context, hash); - if (BE (new_state != NULL, 1)) - return new_state; - else - { - *err = REG_ESPACE; - return NULL; - } + if (BE (new_state == NULL, 0)) + *err = REG_ESPACE; + + return new_state; } /* Finish initialization of the new state NEWSTATE, and using its hash value @@ -1473,8 +1563,8 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa, indicates the error code if failed. */ static reg_errcode_t -internal_function -register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) +register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, + re_hashval_t hash) { struct re_state_table_entry *spot; reg_errcode_t err; @@ -1488,19 +1578,16 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) { Idx elem = newstate->nodes.elems[i]; if (!IS_EPSILON_NODE (dfa->nodes[elem].type)) - { - bool ok = re_node_set_insert_last (&newstate->non_eps_nodes, elem); - if (BE (! ok, 0)) - return REG_ESPACE; - } + if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0)) + return REG_ESPACE; } spot = dfa->state_table + (hash & dfa->state_hash_mask); if (BE (spot->alloc <= spot->num, 0)) { - Idx new_alloc = spot->num; - re_dfastate_t **new_array = re_x2realloc (spot->array, re_dfastate_t *, - &new_alloc); + Idx new_alloc = 2 * spot->num + 2; + re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *, + new_alloc); if (BE (new_array == NULL, 0)) return REG_ESPACE; spot->array = new_array; @@ -1510,6 +1597,22 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash) return REG_NOERROR; } +static void +free_state (re_dfastate_t *state) +{ + re_node_set_free (&state->non_eps_nodes); + re_node_set_free (&state->inveclosure); + if (state->entrance_nodes != &state->nodes) + { + re_node_set_free (state->entrance_nodes); + re_free (state->entrance_nodes); + } + re_node_set_free (&state->nodes); + re_free (state->word_trtable); + re_free (state->trtable); + re_free (state); +} + /* Create the new state which is independ of contexts. Return the new state if succeeded, otherwise return NULL. */ @@ -1522,7 +1625,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, reg_errcode_t err; re_dfastate_t *newstate; - newstate = re_calloc (re_dfastate_t, 1); + newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); if (BE (newstate == NULL, 0)) return NULL; err = re_node_set_init_copy (&newstate->nodes, nodes); @@ -1572,7 +1675,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, reg_errcode_t err; re_dfastate_t *newstate; - newstate = re_calloc (re_dfastate_t, 1); + newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); if (BE (newstate == NULL, 0)) return NULL; err = re_node_set_init_copy (&newstate->nodes, nodes); @@ -1637,20 +1740,3 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, } return newstate; } - -static void -internal_function -free_state (re_dfastate_t *state) -{ - re_node_set_free (&state->non_eps_nodes); - re_node_set_free (&state->inveclosure); - if (state->entrance_nodes != &state->nodes) - { - re_node_set_free (state->entrance_nodes); - re_free (state->entrance_nodes); - } - re_node_set_free (&state->nodes); - re_free (state->word_trtable); - re_free (state->trtable); - re_free (state); -} diff --git a/lib/regex_internal.h b/gl/regex_internal.h similarity index 82% rename from lib/regex_internal.h rename to gl/regex_internal.h index a36ae4c..b0f7e65 100644 --- a/lib/regex_internal.h +++ b/gl/regex_internal.h @@ -1,5 +1,5 @@ /* Extended regular expression matching and search library. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa . @@ -37,23 +37,20 @@ #if defined HAVE_LOCALE_H || defined _LIBC # include #endif -#if defined HAVE_WCHAR_H || defined _LIBC -# include -#endif /* HAVE_WCHAR_H || _LIBC */ -#if defined HAVE_WCTYPE_H || defined _LIBC -# include -#endif /* HAVE_WCTYPE_H || _LIBC */ + +#include +#include +#include #if defined _LIBC # include #else -# define __libc_lock_define(CLASS,NAME) # define __libc_lock_init(NAME) do { } while (0) # define __libc_lock_lock(NAME) do { } while (0) # define __libc_lock_unlock(NAME) do { } while (0) #endif /* In case that the system doesn't have isblank(). */ -#if !defined _LIBC && !defined HAVE_ISBLANK && !defined isblank +#if !defined _LIBC && !HAVE_DECL_ISBLANK && !defined isblank # define isblank(ch) ((ch) == ' ' || (ch) == '\t') #endif @@ -84,7 +81,12 @@ # define gettext_noop(String) String #endif -#if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC +/* For loser systems without the definition. */ +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +#if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC # define RE_ENABLE_I18N #endif @@ -92,10 +94,16 @@ # define BE(expr, val) __builtin_expect (expr, val) #else # define BE(expr, val) (expr) +# ifdef _LIBC +# define inline +# endif #endif -/* Number of single byte character. */ -#define SBC_MAX 256 +/* Number of ASCII characters. */ +#define ASCII_CHARS 0x80 + +/* Number of single byte characters. */ +#define SBC_MAX (UCHAR_MAX + 1) #define COLL_ELEM_LEN_MAX 8 @@ -122,9 +130,6 @@ # define __attribute(arg) #endif -extern const char __re_error_msgid[] attribute_hidden; -extern const size_t __re_error_msgid_idx[] attribute_hidden; - typedef __re_idx_t Idx; /* Special return value for failure to match. */ @@ -152,15 +157,15 @@ typedef __re_size_t re_hashval_t; /* An integer used to represent a set of bits. It must be unsigned, and must be at least as wide as unsigned int. */ -typedef unsigned long int bitset_word; - -/* Maximum value of a bitset word. It must be useful in preprocessor - contexts, and must be consistent with bitset_word. */ +typedef unsigned long int bitset_word_t; +/* All bits set in a bitset_word_t. */ #define BITSET_WORD_MAX ULONG_MAX -/* Number of bits in a bitset word. Avoid greater-than-32-bit - integers and unconditional shifts by more than 31 bits, as they're - not portable. */ +/* Number of bits in a bitset_word_t. For portability to hosts with + padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)'; + instead, deduce it directly from BITSET_WORD_MAX. Avoid + greater-than-32-bit integers and unconditional shifts by more than + 31 bits, as they're not portable. */ #if BITSET_WORD_MAX == 0xffffffff # define BITSET_WORD_BITS 32 #elif BITSET_WORD_MAX >> 31 >> 5 == 1 @@ -182,16 +187,20 @@ typedef unsigned long int bitset_word; # if BITSET_WORD_BITS <= SBC_MAX # error "Invalid SBC_MAX" # endif +#elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff +/* Work around a bug in 64-bit PGC (before version 6.1-2), where the + preprocessor mishandles large unsigned values as if they were signed. */ +# define BITSET_WORD_BITS 64 #else -# error "Add case for new bitset_word size" +# error "Add case for new bitset_word_t size" #endif -/* Number of bitset words in a bitset. */ +/* Number of bitset_word_t values in a bitset_t. */ #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) -typedef bitset_word bitset[BITSET_WORDS]; -typedef bitset_word *re_bitset_ptr_t; -typedef const bitset_word *re_const_bitset_ptr_t; +typedef bitset_word_t bitset_t[BITSET_WORDS]; +typedef bitset_word_t *re_bitset_ptr_t; +typedef const bitset_word_t *re_const_bitset_ptr_t; #define PREV_WORD_CONSTRAINT 0x0001 #define PREV_NOTWORD_CONSTRAINT 0x0002 @@ -336,7 +345,7 @@ typedef struct Idx idx; /* for BACK_REF */ re_context_type ctx_type; /* for ANCHOR */ } opr; -#if __GNUC__ >= 2 +#if __GNUC__ >= 2 && !__STRICT_ANSI__ re_token_type_t type : 8; #else re_token_type_t type; @@ -397,7 +406,7 @@ struct re_string_t the beginning of the input string. */ unsigned int tip_context; /* The translation passed as a part of an argument of re_compile_pattern. */ - unsigned REG_TRANSLATE_TYPE trans; + RE_TRANSLATE_TYPE trans; /* Copy of re_dfa_t's word_char. */ re_const_bitset_ptr_t word_char; /* true if REG_ICASE. */ @@ -434,10 +443,9 @@ static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) #endif /* RE_ENABLE_I18N */ static void build_upper_buffer (re_string_t *pstr) internal_function; static void re_string_translate_buffer (re_string_t *pstr) internal_function; -static unsigned int re_string_context_at (const re_string_t *input, - Idx idx, int eflags) +static unsigned int re_string_context_at (const re_string_t *input, Idx idx, + int eflags) internal_function __attribute ((pure)); - #define re_string_peek_byte(pstr, offset) \ ((pstr)->mbs[(pstr)->cur_idx + offset]) #define re_string_fetch_byte(pstr) \ @@ -470,71 +478,14 @@ static unsigned int re_string_context_at (const re_string_t *input, # endif #endif +#ifndef MAX +# define MAX(a,b) ((a) < (b) ? (b) : (a)) +#endif + #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) -#define re_xmalloc(t,n) ((t *) re_xnmalloc (n, sizeof (t))) -#define re_calloc(t,n) ((t *) calloc (n, sizeof (t))) #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) -#define re_xrealloc(p,t,n) ((t *) re_xnrealloc (p, n, sizeof (t))) -#define re_x2realloc(p,t,pn) ((t *) re_x2nrealloc (p, pn, sizeof (t))) #define re_free(p) free (p) -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - -/* Return true if an array of N objects, each of size S, cannot exist - due to size arithmetic overflow. S must be nonzero. */ -static inline bool -re_alloc_oversized (size_t n, size_t s) -{ - return BE (SIZE_MAX / s < n, 0); -} - -/* Return true if an array of (2 * N + 1) objects, each of size S, - cannot exist due to size arithmetic overflow. S must be nonzero. */ -static inline bool -re_x2alloc_oversized (size_t n, size_t s) -{ - return BE ((SIZE_MAX / s - 1) / 2 < n, 0); -} - -/* Allocate an array of N objects, each with S bytes of memory, - dynamically, with error checking. S must be nonzero. */ -static inline void * -re_xnmalloc (size_t n, size_t s) -{ - return re_alloc_oversized (n, s) ? NULL : malloc (n * s); -} - -/* Change the size of an allocated block of memory P to an array of N - objects each of S bytes, with error checking. S must be nonzero. */ -static inline void * -re_xnrealloc (void *p, size_t n, size_t s) -{ - return re_alloc_oversized (n, s) ? NULL : realloc (p, n * s); -} - -/* Reallocate a block of memory P to an array of (2 * (*PN) + 1) - objects each of S bytes, with error checking. S must be nonzero. - If the allocation is successful, set *PN to the new allocation - count and return the resulting pointer. Otherwise, return - NULL. */ -static inline void * -re_x2nrealloc (void *p, size_t *pn, size_t s) -{ - if (re_x2alloc_oversized (*pn, s)) - return NULL; - else - { - /* Add 1 in case *PN is zero. */ - size_t n1 = 2 * *pn + 1; - p = realloc (p, n1 * s); - if (BE (p != NULL, 1)) - *pn = n1; - return p; - } -} - struct bin_tree_t { struct bin_tree_t *parent; @@ -664,9 +615,9 @@ typedef struct /* The string object corresponding to the input string. */ re_string_t input; #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) - re_dfa_t *const dfa; + const re_dfa_t *const dfa; #else - re_dfa_t *dfa; + const re_dfa_t *dfa; #endif /* EFLAGS of the argument of regexec. */ int eflags; @@ -713,8 +664,8 @@ struct re_fail_stack_t struct re_dfa_t { re_token_t *nodes; - Idx nodes_alloc; - Idx nodes_len; + size_t nodes_alloc; + size_t nodes_len; Idx *nexts; Idx *org_indices; re_node_set *edests; @@ -736,8 +687,8 @@ struct re_dfa_t Idx nbackref; /* The number of backreference in this dfa. */ /* Bitmap expressing which backreference is used. */ - bitset_word used_bkref_map; - bitset_word completed_bkref_map; + bitset_word_t used_bkref_map; + bitset_word_t completed_bkref_map; unsigned int has_plural_match : 1; /* If this dfa has "multibyte node", which is a backreference or @@ -748,13 +699,15 @@ struct re_dfa_t unsigned int map_notascii : 1; unsigned int word_ops_used : 1; int mb_cur_max; - bitset word_char; + bitset_t word_char; reg_syntax_t syntax; Idx *subexp_map; #ifdef DEBUG char* re_str; #endif +#ifdef _LIBC __libc_lock_define (, lock) +#endif }; #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set)) @@ -762,8 +715,6 @@ struct re_dfa_t (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1)) #define re_node_set_empty(p) ((p)->nelem = 0) #define re_node_set_free(set) re_free ((set)->elems) - -static void free_state (re_dfastate_t *state) internal_function; typedef enum @@ -787,76 +738,76 @@ typedef struct } bracket_elem_t; -/* Inline functions for bitset operation. */ +/* Inline functions for bitset_t operation. */ static inline void -bitset_set (bitset set, Idx i) +bitset_set (bitset_t set, Idx i) { - set[i / BITSET_WORD_BITS] |= (bitset_word) 1 << i % BITSET_WORD_BITS; + set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; } static inline void -bitset_clear (bitset set, Idx i) +bitset_clear (bitset_t set, Idx i) { - set[i / BITSET_WORD_BITS] &= ~ ((bitset_word) 1 << i % BITSET_WORD_BITS); + set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); } static inline bool -bitset_contain (const bitset set, Idx i) +bitset_contain (const bitset_t set, Idx i) { return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; } static inline void -bitset_empty (bitset set) +bitset_empty (bitset_t set) { - memset (set, 0, sizeof (bitset)); + memset (set, '\0', sizeof (bitset_t)); } static inline void -bitset_set_all (bitset set) +bitset_set_all (bitset_t set) { - memset (set, -1, sizeof (bitset_word) * (SBC_MAX / BITSET_WORD_BITS)); + memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); if (SBC_MAX % BITSET_WORD_BITS != 0) set[BITSET_WORDS - 1] = - ((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; + ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; } static inline void -bitset_copy (bitset dest, const bitset src) +bitset_copy (bitset_t dest, const bitset_t src) { - memcpy (dest, src, sizeof (bitset)); + memcpy (dest, src, sizeof (bitset_t)); } static inline void -bitset_not (bitset set) +bitset_not (bitset_t set) { - int i; - for (i = 0; i < SBC_MAX / BITSET_WORD_BITS; ++i) - set[i] = ~set[i]; + int bitset_i; + for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i) + set[bitset_i] = ~set[bitset_i]; if (SBC_MAX % BITSET_WORD_BITS != 0) set[BITSET_WORDS - 1] = - ((((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1) + ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1) & ~set[BITSET_WORDS - 1]); } static inline void -bitset_merge (bitset dest, const bitset src) +bitset_merge (bitset_t dest, const bitset_t src) { - int i; - for (i = 0; i < BITSET_WORDS; ++i) - dest[i] |= src[i]; + int bitset_i; + for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) + dest[bitset_i] |= src[bitset_i]; } static inline void -bitset_mask (bitset dest, const bitset src) +bitset_mask (bitset_t dest, const bitset_t src) { - int i; - for (i = 0; i < BITSET_WORDS; ++i) - dest[i] &= src[i]; + int bitset_i; + for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) + dest[bitset_i] &= src[bitset_i]; } -#if defined RE_ENABLE_I18N +#ifdef RE_ENABLE_I18N /* Inline functions for re_string. */ static inline int internal_function __attribute ((pure)) @@ -884,11 +835,11 @@ static int internal_function __attribute ((pure)) re_string_elem_size_at (const re_string_t *pstr, Idx idx) { -#ifdef _LIBC +# ifdef _LIBC const unsigned char *p, *extra; const int32_t *table, *indirect; int32_t tmp; -# include +# include uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); if (nrules != 0) @@ -903,7 +854,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) return p - pstr->mbs - idx; } else -#endif /* _LIBC */ +# endif /* _LIBC */ return 1; } #endif /* RE_ENABLE_I18N */ diff --git a/lib/regexec.c b/gl/regexec.c similarity index 88% rename from lib/regexec.c rename to gl/regexec.c index a85077c..7c186aa 100644 --- a/lib/regexec.c +++ b/gl/regexec.c @@ -1,5 +1,5 @@ /* Extended regular expression matching and search library. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa . @@ -51,68 +51,79 @@ static regoff_t re_search_stub (struct re_pattern_buffer *bufp, regoff_t range, Idx stop, struct re_registers *regs, bool ret_len) internal_function; -static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, - Idx nregs, int regs_allocated) internal_function; +static unsigned int re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, + Idx nregs, int regs_allocated) + internal_function; static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) internal_function; static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match, - Idx *p_match_first) - internal_function; + Idx *p_match_first) internal_function; static Idx check_halt_state_context (const re_match_context_t *mctx, const re_dfastate_t *state, Idx idx) internal_function; -static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch, +static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) internal_function; static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, Idx nregs, regmatch_t *regs, - re_node_set *eps_via_nodes) internal_function; + re_node_set *eps_via_nodes) + internal_function; static reg_errcode_t set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, regmatch_t *pmatch, bool fl_backtrack) internal_function; -static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function; +static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) + internal_function; #ifdef RE_ENABLE_I18N static int sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, - Idx node_idx, Idx str_idx, Idx max_str_idx) internal_function; + Idx node_idx, Idx str_idx, Idx max_str_idx) + internal_function; #endif /* RE_ENABLE_I18N */ -static reg_errcode_t sift_states_backward (re_match_context_t *mctx, - re_sift_context_t *sctx) internal_function; -static reg_errcode_t build_sifted_states (re_match_context_t *mctx, +static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, + re_sift_context_t *sctx) + internal_function; +static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, Idx str_idx, - re_node_set *cur_dest) internal_function; -static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx, + re_node_set *cur_dest) + internal_function; +static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, re_sift_context_t *sctx, Idx str_idx, - re_node_set *dest_nodes) internal_function; -static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa, + re_node_set *dest_nodes) + internal_function; +static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, - const re_node_set *candidates) internal_function; + const re_node_set *candidates) + internal_function; static bool check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) internal_function; static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, Idx subexp_idx, - Idx from_node, Idx bkref_idx) internal_function; + Idx from_node, Idx bkref_idx) + internal_function; static int check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, Idx subexp_idx, Idx node, Idx str_idx, Idx bkref_idx) internal_function; -static reg_errcode_t check_subexp_limits (re_dfa_t *dfa, +static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, const re_node_set *candidates, re_node_set *limits, struct re_backref_cache_entry *bkref_ents, Idx str_idx) internal_function; -static reg_errcode_t sift_states_bkref (re_match_context_t *mctx, +static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, - Idx str_idx, const re_node_set *candidates) internal_function; -static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, - re_dfastate_t **src, Idx num) internal_function; + Idx str_idx, const re_node_set *candidates) + internal_function; +static reg_errcode_t merge_state_array (const re_dfa_t *dfa, + re_dfastate_t **dst, + re_dfastate_t **src, Idx num) + internal_function; static re_dfastate_t *find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) internal_function; static re_dfastate_t *transit_state (reg_errcode_t *err, @@ -120,27 +131,33 @@ static re_dfastate_t *transit_state (reg_errcode_t *err, re_dfastate_t *state) internal_function; static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, - re_dfastate_t *next_state) internal_function; + re_dfastate_t *next_state) + internal_function; static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, Idx str_idx) internal_function; #if 0 static re_dfastate_t *transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, - re_dfastate_t *pstate) internal_function; + re_dfastate_t *pstate) + internal_function; #endif #ifdef RE_ENABLE_I18N static reg_errcode_t transit_state_mb (re_match_context_t *mctx, - re_dfastate_t *pstate) internal_function; + re_dfastate_t *pstate) + internal_function; #endif /* RE_ENABLE_I18N */ static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, - const re_node_set *nodes) internal_function; + const re_node_set *nodes) + internal_function; static reg_errcode_t get_subexp (re_match_context_t *mctx, - Idx bkref_node, Idx bkref_str_idx) internal_function; + Idx bkref_node, Idx bkref_str_idx) + internal_function; static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, re_sub_match_last_t *sub_last, - Idx bkref_node, Idx bkref_str) internal_function; + Idx bkref_node, Idx bkref_str) + internal_function; static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, Idx subexp_idx, int type) internal_function; static reg_errcode_t check_arrival (re_match_context_t *mctx, @@ -150,35 +167,41 @@ static reg_errcode_t check_arrival (re_match_context_t *mctx, static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, re_node_set *cur_nodes, - re_node_set *next_nodes) internal_function; -static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa, + re_node_set *next_nodes) + internal_function; +static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, - Idx ex_subexp, int type) internal_function; -static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa, + Idx ex_subexp, int type) + internal_function; +static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, Idx target, Idx ex_subexp, int type) internal_function; static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, Idx cur_str, - Idx subexp_num, int type) internal_function; -static bool build_trtable (re_dfa_t *dfa, + Idx subexp_num, int type) + internal_function; +static bool build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) internal_function; #ifdef RE_ENABLE_I18N -static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, - const re_string_t *input, Idx idx) internal_function; +static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, + const re_string_t *input, Idx idx) + internal_function; # ifdef _LIBC static unsigned int find_collation_sequence_value (const unsigned char *mbs, - size_t name_len) internal_function; + size_t name_len) + internal_function; # endif /* _LIBC */ #endif /* RE_ENABLE_I18N */ static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, re_node_set *states_node, - bitset *states_ch) internal_function; + bitset_t *states_ch) internal_function; static bool check_node_accept (const re_match_context_t *mctx, const re_token_t *node, Idx idx) internal_function; -static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function; +static reg_errcode_t extend_buffers (re_match_context_t *mctx) + internal_function; /* Entry point for POSIX code. */ @@ -197,13 +220,17 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function We return 0 if we find a match and REG_NOMATCH if not. */ int -regexec (const regex_t *__restrict preg, const char *__restrict string, - size_t nmatch, regmatch_t pmatch[], int eflags) +regexec (preg, string, nmatch, pmatch, eflags) + const regex_t *__restrict preg; + const char *__restrict string; + size_t nmatch; + regmatch_t pmatch[]; + int eflags; { reg_errcode_t err; Idx start, length; #ifdef _LIBC - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) preg->buffer; #endif if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) @@ -221,7 +248,7 @@ regexec (const regex_t *__restrict preg, const char *__restrict string, } __libc_lock_lock (dfa->lock); - if (preg->re_no_sub) + if (preg->no_sub) err = re_search_internal (preg, string, length, start, length, length, 0, NULL, eflags); else @@ -271,8 +298,8 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); the first STOP characters of the concatenation of the strings should be concerned. - If REGS is not NULL, and BUFP->re_no_sub is not set, the offsets of the match - and all groups is stroed in REGS. (For the "_2" variants, the offsets are + If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match + and all groups is stored in REGS. (For the "_2" variants, the offsets are computed relative to the concatenation, not relative to the individual strings.) @@ -281,8 +308,11 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); match was found and -2 indicates an internal error. */ regoff_t -re_match (struct re_pattern_buffer *bufp, const char *string, - Idx length, Idx start, struct re_registers *regs) +re_match (bufp, string, length, start, regs) + struct re_pattern_buffer *bufp; + const char *string; + Idx length, start; + struct re_registers *regs; { return re_search_stub (bufp, string, length, start, 0, length, regs, true); } @@ -291,8 +321,12 @@ weak_alias (__re_match, re_match) #endif regoff_t -re_search (struct re_pattern_buffer *bufp, const char *string, - Idx length, Idx start, regoff_t range, struct re_registers *regs) +re_search (bufp, string, length, start, range, regs) + struct re_pattern_buffer *bufp; + const char *string; + Idx length, start; + regoff_t range; + struct re_registers *regs; { return re_search_stub (bufp, string, length, start, range, length, regs, false); @@ -302,10 +336,11 @@ weak_alias (__re_search, re_search) #endif regoff_t -re_match_2 (struct re_pattern_buffer *bufp, - const char *string1, Idx length1, - const char *string2, Idx length2, - Idx start, struct re_registers *regs, Idx stop) +re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) + struct re_pattern_buffer *bufp; + const char *string1, *string2; + Idx length1, length2, start, stop; + struct re_registers *regs; { return re_search_2_stub (bufp, string1, length1, string2, length2, start, 0, regs, stop, true); @@ -315,10 +350,12 @@ weak_alias (__re_match_2, re_match_2) #endif regoff_t -re_search_2 (struct re_pattern_buffer *bufp, - const char *string1, Idx length1, - const char *string2, Idx length2, - Idx start, regoff_t range, struct re_registers *regs, Idx stop) +re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) + struct re_pattern_buffer *bufp; + const char *string1, *string2; + Idx length1, length2, start, stop; + regoff_t range; + struct re_registers *regs; { return re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs, stop, false); @@ -351,8 +388,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp, if (BE (s == NULL, 0)) return -2; +#ifdef _LIBC + memcpy (__mempcpy (s, string1, length1), string2, length2); +#else memcpy (s, string1, length1); memcpy (s + length1, string2, length2); +#endif str = s; } else @@ -384,59 +425,37 @@ re_search_stub (struct re_pattern_buffer *bufp, regoff_t rval; int eflags = 0; #ifdef _LIBC - re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; + re_dfa_t *dfa = (re_dfa_t *) bufp->buffer; #endif Idx last_start = start + range; /* Check for out-of-range. */ if (BE (start < 0 || start > length, 0)) return -1; - if (sizeof start < sizeof range) - { - regoff_t length_offset = length; - regoff_t start_offset = start; - if (BE (length_offset - start_offset < range, 0)) - last_start = length; - else if (BE (range < - start_offset, 0)) - last_start = 0; - } - else - { - if (BE ((last_start < start) != (range < 0), 0)) - { - /* Overflow occurred when computing last_start; substitute - the extreme value. */ - last_start = range < 0 ? 0 : length; - } - else - { - if (BE (length < last_start, 0)) - last_start = length; - else if (BE (last_start < 0, 0)) - last_start = 0; - } - } + if (BE (length < last_start || (0 <= range && last_start < start), 0)) + last_start = length; + else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) + last_start = 0; __libc_lock_lock (dfa->lock); - eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0; - eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0; + eflags |= (bufp->not_bol) ? REG_NOTBOL : 0; + eflags |= (bufp->not_eol) ? REG_NOTEOL : 0; /* Compile fastmap if we haven't yet. */ - if (start < last_start && bufp->re_fastmap != NULL - && !bufp->re_fastmap_accurate) + if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) re_compile_fastmap (bufp); - if (BE (bufp->re_no_sub, 0)) + if (BE (bufp->no_sub, 0)) regs = NULL; /* We need at least 1 register. */ if (regs == NULL) nregs = 1; - else if (BE (bufp->re_regs_allocated == REG_FIXED - && regs->rm_num_regs <= bufp->re_nsub, 0)) + else if (BE (bufp->regs_allocated == REGS_FIXED + && regs->num_regs <= bufp->re_nsub, 0)) { - nregs = regs->rm_num_regs; + nregs = regs->num_regs; if (BE (nregs < 1, 0)) { /* Nothing can be copied to regs. */ @@ -446,7 +465,7 @@ re_search_stub (struct re_pattern_buffer *bufp, } else nregs = bufp->re_nsub + 1; - pmatch = re_xmalloc (regmatch_t, nregs); + pmatch = re_malloc (regmatch_t, nregs); if (BE (pmatch == NULL, 0)) { rval = -2; @@ -464,9 +483,9 @@ re_search_stub (struct re_pattern_buffer *bufp, else if (regs != NULL) { /* If caller wants register contents data back, copy them. */ - bufp->re_regs_allocated = re_copy_regs (regs, pmatch, nregs, - bufp->re_regs_allocated); - if (BE (bufp->re_regs_allocated == REG_UNALLOCATED, 0)) + bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, + bufp->regs_allocated); + if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) rval = -2; } @@ -486,58 +505,68 @@ re_search_stub (struct re_pattern_buffer *bufp, return rval; } -static unsigned +static unsigned int internal_function re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, int regs_allocated) { - int rval = REG_REALLOCATE; + int rval = REGS_REALLOCATE; Idx i; Idx need_regs = nregs + 1; - /* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code + /* We need one extra element beyond `num_regs' for the `-1' marker GNU code uses. */ /* Have the register data arrays been allocated? */ - if (regs_allocated == REG_UNALLOCATED) + if (regs_allocated == REGS_UNALLOCATED) { /* No. So allocate them with malloc. */ - regs->rm_start = re_xmalloc (regoff_t, need_regs); - regs->rm_end = re_malloc (regoff_t, need_regs); - if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0)) - return REG_UNALLOCATED; - regs->rm_num_regs = need_regs; + regs->start = re_malloc (regoff_t, need_regs); + if (BE (regs->start == NULL, 0)) + return REGS_UNALLOCATED; + regs->end = re_malloc (regoff_t, need_regs); + if (BE (regs->end == NULL, 0)) + { + re_free (regs->start); + return REGS_UNALLOCATED; + } + regs->num_regs = need_regs; } - else if (regs_allocated == REG_REALLOCATE) + else if (regs_allocated == REGS_REALLOCATE) { /* Yes. If we need more elements than were already allocated, reallocate them. If we need fewer, just leave it alone. */ - if (BE (need_regs > regs->rm_num_regs, 0)) + if (BE (need_regs > regs->num_regs, 0)) { - regoff_t *new_start = - re_xrealloc (regs->rm_start, regoff_t, need_regs); - regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs); - if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0)) - return REG_UNALLOCATED; - regs->rm_start = new_start; - regs->rm_end = new_end; - regs->rm_num_regs = need_regs; + regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); + regoff_t *new_end; + if (BE (new_start == NULL, 0)) + return REGS_UNALLOCATED; + new_end = re_realloc (regs->end, regoff_t, need_regs); + if (BE (new_end == NULL, 0)) + { + re_free (new_start); + return REGS_UNALLOCATED; + } + regs->start = new_start; + regs->end = new_end; + regs->num_regs = need_regs; } } else { - assert (regs_allocated == REG_FIXED); - /* This function may not be called with REG_FIXED and nregs too big. */ - assert (regs->rm_num_regs >= nregs); - rval = REG_FIXED; + assert (regs_allocated == REGS_FIXED); + /* This function may not be called with REGS_FIXED and nregs too big. */ + assert (regs->num_regs >= nregs); + rval = REGS_FIXED; } /* Copy the regs. */ for (i = 0; i < nregs; ++i) { - regs->rm_start[i] = pmatch[i].rm_so; - regs->rm_end[i] = pmatch[i].rm_eo; + regs->start[i] = pmatch[i].rm_so; + regs->end[i] = pmatch[i].rm_eo; } - for ( ; i < regs->rm_num_regs; ++i) - regs->rm_start[i] = regs->rm_end[i] = -1; + for ( ; i < regs->num_regs; ++i) + regs->start[i] = regs->end[i] = -1; return rval; } @@ -556,21 +585,24 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, freeing the old data. */ void -re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, - __re_size_t num_regs, regoff_t *starts, regoff_t *ends) +re_set_registers (bufp, regs, num_regs, starts, ends) + struct re_pattern_buffer *bufp; + struct re_registers *regs; + __re_size_t num_regs; + regoff_t *starts, *ends; { if (num_regs) { - bufp->re_regs_allocated = REG_REALLOCATE; - regs->rm_num_regs = num_regs; - regs->rm_start = starts; - regs->rm_end = ends; + bufp->regs_allocated = REGS_REALLOCATE; + regs->num_regs = num_regs; + regs->start = starts; + regs->end = ends; } else { - bufp->re_regs_allocated = REG_UNALLOCATED; - regs->rm_num_regs = 0; - regs->rm_start = regs->rm_end = NULL; + bufp->regs_allocated = REGS_UNALLOCATED; + regs->num_regs = 0; + regs->start = regs->end = NULL; } } #ifdef _LIBC @@ -585,7 +617,8 @@ int # ifdef _LIBC weak_function # endif -re_exec (const char *s) +re_exec (s) + const char *s; { return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); } @@ -611,12 +644,13 @@ re_search_internal (const regex_t *preg, int eflags) { reg_errcode_t err; - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; Idx left_lim, right_lim; int incr; bool fl_longest_match; int match_kind; - Idx match_first, match_last = REG_MISSING; + Idx match_first; + Idx match_last = REG_MISSING; Idx extra_nmatch; bool sb; int ch; @@ -625,11 +659,10 @@ re_search_internal (const regex_t *preg, #else re_match_context_t mctx; #endif - char *fastmap = ((preg->re_fastmap != NULL && preg->re_fastmap_accurate - && start != last_start && !preg->re_can_be_null) - ? preg->re_fastmap : NULL); - unsigned REG_TRANSLATE_TYPE t = - (unsigned REG_TRANSLATE_TYPE) preg->re_translate; + char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate + && start != last_start && !preg->can_be_null) + ? preg->fastmap : NULL); + RE_TRANSLATE_TYPE t = preg->translate; #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) memset (&mctx, '\0', sizeof (re_match_context_t)); @@ -640,7 +673,7 @@ re_search_internal (const regex_t *preg, nmatch -= extra_nmatch; /* Check if the DFA haven't been compiled. */ - if (BE (preg->re_used == 0 || dfa->init_state == NULL + if (BE (preg->used == 0 || dfa->init_state == NULL || dfa->init_state_word == NULL || dfa->init_state_nl == NULL || dfa->init_state_begbuf == NULL, 0)) return REG_NOMATCH; @@ -651,12 +684,12 @@ re_search_internal (const regex_t *preg, #endif /* If initial states with non-begbuf contexts have no elements, - the regex must be anchored. If preg->re_newline_anchor is set, + the regex must be anchored. If preg->newline_anchor is set, we'll never use init_state_nl, so do not check it. */ if (dfa->init_state->nodes.nelem == 0 && dfa->init_state_word->nodes.nelem == 0 && (dfa->init_state_nl->nodes.nelem == 0 - || !preg->re_newline_anchor)) + || !preg->newline_anchor)) { if (start != 0 && last_start != 0) return REG_NOMATCH; @@ -667,13 +700,12 @@ re_search_internal (const regex_t *preg, fl_longest_match = (nmatch != 0 || dfa->nbackref); err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, - preg->re_translate, - preg->re_syntax & REG_IGNORE_CASE, dfa); + preg->translate, preg->syntax & RE_ICASE, dfa); if (BE (err != REG_NOERROR, 0)) goto free_return; mctx.input.stop = stop; mctx.input.raw_stop = stop; - mctx.input.newline_anchor = preg->re_newline_anchor; + mctx.input.newline_anchor = preg->newline_anchor; err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); if (BE (err != REG_NOERROR, 0)) @@ -685,7 +717,14 @@ re_search_internal (const regex_t *preg, multi character collating element. */ if (nmatch > 1 || dfa->has_mb_node) { - mctx.state_log = re_xmalloc (re_dfastate_t *, mctx.input.bufs_len + 1); + /* Avoid overflow. */ + if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0)) + { + err = REG_ESPACE; + goto free_return; + } + + mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); if (BE (mctx.state_log == NULL, 0)) { err = REG_ESPACE; @@ -706,7 +745,7 @@ re_search_internal (const regex_t *preg, sb = dfa->mb_cur_max == 1; match_kind = (fastmap - ? ((sb || !(preg->re_syntax & REG_IGNORE_CASE || t) ? 4 : 0) + ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0) | (start <= last_start ? 2 : 0) | (t != NULL ? 1 : 0)) : 8); @@ -828,13 +867,13 @@ re_search_internal (const regex_t *preg, else { mctx.match_last = match_last; - if ((!preg->re_no_sub && nmatch > 1) || dfa->nbackref) + if ((!preg->no_sub && nmatch > 1) || dfa->nbackref) { re_dfastate_t *pstate = mctx.state_log[match_last]; mctx.last_node = check_halt_state_context (&mctx, pstate, match_last); } - if ((!preg->re_no_sub && nmatch > 1 && dfa->has_plural_match) + if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match) || dfa->nbackref) { err = prune_impossible_nodes (&mctx); @@ -873,7 +912,7 @@ re_search_internal (const regex_t *preg, the maximum possible regoff_t value. We need a new error code REG_OVERFLOW. */ - if (!preg->re_no_sub && nmatch > 1) + if (!preg->no_sub && nmatch > 1) { err = set_regs (preg, &mctx, nmatch, pmatch, dfa->has_plural_match && dfa->nbackref > 0); @@ -934,7 +973,7 @@ static reg_errcode_t internal_function prune_impossible_nodes (re_match_context_t *mctx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx halt_node, match_last; reg_errcode_t ret; re_dfastate_t **sifted_states; @@ -945,7 +984,12 @@ prune_impossible_nodes (re_match_context_t *mctx) #endif match_last = mctx->match_last; halt_node = mctx->last_node; - sifted_states = re_xmalloc (re_dfastate_t *, match_last + 1); + + /* Avoid overflow. */ + if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0)) + return REG_ESPACE; + + sifted_states = re_malloc (re_dfastate_t *, match_last + 1); if (BE (sifted_states == NULL, 0)) { ret = REG_ESPACE; @@ -953,7 +997,7 @@ prune_impossible_nodes (re_match_context_t *mctx) } if (dfa->nbackref) { - lim_states = re_xmalloc (re_dfastate_t *, match_last + 1); + lim_states = re_malloc (re_dfastate_t *, match_last + 1); if (BE (lim_states == NULL, 0)) { ret = REG_ESPACE; @@ -1021,7 +1065,7 @@ __attribute ((always_inline)) internal_function acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, Idx idx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; if (dfa->init_state->has_constraint) { unsigned int context; @@ -1063,7 +1107,7 @@ internal_function check_matching (re_match_context_t *mctx, bool fl_longest_match, Idx *p_match_first) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; Idx match = 0; Idx match_last = REG_MISSING; @@ -1233,11 +1277,11 @@ check_halt_state_context (const re_match_context_t *mctx, static Idx internal_function -proceed_next_node (const re_match_context_t *mctx, - Idx nregs, regmatch_t *regs, Idx *pidx, Idx node, - re_node_set *eps_via_nodes, struct re_fail_stack_t *fs) +proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, + Idx *pidx, Idx node, re_node_set *eps_via_nodes, + struct re_fail_stack_t *fs) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx i; bool ok; if (IS_EPSILON_NODE (dfa->nodes[node].type)) @@ -1342,15 +1386,17 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, Idx num = fs->num++; if (fs->num == fs->alloc) { - struct re_fail_stack_ent_t *new_array = - re_x2realloc (fs->stack, struct re_fail_stack_ent_t, &fs->alloc); + struct re_fail_stack_ent_t *new_array; + new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) + * fs->alloc * 2)); if (new_array == NULL) return REG_ESPACE; + fs->alloc *= 2; fs->stack = new_array; } fs->stack[num].idx = str_idx; fs->stack[num].node = dest_node; - fs->stack[num].regs = re_xmalloc (regmatch_t, nregs); + fs->stack[num].regs = re_malloc (regmatch_t, nregs); if (fs->stack[num].regs == NULL) return REG_ESPACE; memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); @@ -1360,8 +1406,8 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, static Idx internal_function -pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, - Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes) +pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, + regmatch_t *regs, re_node_set *eps_via_nodes) { Idx num = --fs->num; assert (REG_VALID_INDEX (num)); @@ -1380,10 +1426,10 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, static reg_errcode_t internal_function -set_regs (const regex_t *preg, const re_match_context_t *mctx, - size_t nmatch, regmatch_t *pmatch, bool fl_backtrack) +set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, + regmatch_t *pmatch, bool fl_backtrack) { - re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; + const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; Idx idx, cur_node; re_node_set eps_via_nodes; struct re_fail_stack_t *fs; @@ -1398,7 +1444,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, if (fl_backtrack) { fs = &fs_body; - fs->stack = re_xmalloc (struct re_fail_stack_ent_t, fs->alloc); + fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc); if (fs->stack == NULL) return REG_ESPACE; } @@ -1408,11 +1454,6 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, cur_node = dfa->init_node; re_node_set_init_empty (&eps_via_nodes); - if (re_alloc_oversized (nmatch, sizeof (regmatch_t))) - { - free_fail_stack_return (fs); - return REG_ESPACE; - } if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); else @@ -1509,8 +1550,8 @@ free_fail_stack_return (struct re_fail_stack_t *fs) static void internal_function -update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, - Idx cur_node, Idx cur_idx, Idx nmatch) +update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, + regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) { int type = dfa->nodes[cur_node].type; if (type == OP_OPEN_SUBEXP) @@ -1581,7 +1622,7 @@ update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, static reg_errcode_t internal_function -sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx) +sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) { reg_errcode_t err; int null_cnt = 0; @@ -1639,11 +1680,11 @@ sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx) static reg_errcode_t internal_function -build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx, +build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, Idx str_idx, re_node_set *cur_dest) { - re_dfa_t *const dfa = mctx->dfa; - re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; + const re_dfa_t *const dfa = mctx->dfa; + const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; Idx i; /* Then build the next sifted state. @@ -1726,8 +1767,8 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) static reg_errcode_t internal_function -merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, - Idx num) +merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, + re_dfastate_t **src, Idx num) { Idx st_idx; reg_errcode_t err; @@ -1753,11 +1794,12 @@ merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, static reg_errcode_t internal_function -update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx, - Idx str_idx, re_node_set *dest_nodes) +update_cur_sifted_state (const re_match_context_t *mctx, + re_sift_context_t *sctx, Idx str_idx, + re_node_set *dest_nodes) { - re_dfa_t *const dfa = mctx->dfa; - reg_errcode_t err; + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err = REG_NOERROR; const re_node_set *candidates; candidates = ((mctx->state_log[str_idx] == NULL) ? NULL : &mctx->state_log[str_idx]->nodes); @@ -1800,7 +1842,7 @@ update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx, static reg_errcode_t internal_function -add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes, +add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, const re_node_set *candidates) { reg_errcode_t err = REG_NOERROR; @@ -1825,7 +1867,7 @@ add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes, static reg_errcode_t internal_function -sub_epsilon_src_nodes (re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, +sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, const re_node_set *candidates) { Idx ecl_idx; @@ -1877,7 +1919,7 @@ internal_function check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx lim_idx, src_pos, dst_pos; Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx); @@ -1913,8 +1955,8 @@ internal_function check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, Idx subexp_idx, Idx from_node, Idx bkref_idx) { - re_dfa_t *const dfa = mctx->dfa; - re_node_set *eclosures = dfa->eclosures + from_node; + const re_dfa_t *const dfa = mctx->dfa; + const re_node_set *eclosures = dfa->eclosures + from_node; Idx node_idx; /* Else, we are on the boundary: examine the nodes on the epsilon @@ -1938,7 +1980,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, if (subexp_idx < BITSET_WORD_BITS && !(ent->eps_reachable_subexps_map - & ((bitset_word) 1 << subexp_idx))) + & ((bitset_word_t) 1 << subexp_idx))) continue; /* Recurse trying to reach the OP_OPEN_SUBEXP and @@ -1965,8 +2007,8 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, return 0; if (subexp_idx < BITSET_WORD_BITS) - ent->eps_reachable_subexps_map &= - ~ ((bitset_word) 1 << subexp_idx); + ent->eps_reachable_subexps_map + &= ~((bitset_word_t) 1 << subexp_idx); } while (ent++->more); } @@ -1992,9 +2034,9 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, static int internal_function -check_dst_limits_calc_pos (const re_match_context_t *mctx, - Idx limit, Idx subexp_idx, - Idx from_node, Idx str_idx, Idx bkref_idx) +check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, + Idx subexp_idx, Idx from_node, Idx str_idx, + Idx bkref_idx) { struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; int boundaries; @@ -2022,7 +2064,7 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx, static reg_errcode_t internal_function -check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes, +check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, const re_node_set *candidates, re_node_set *limits, struct re_backref_cache_entry *bkref_ents, Idx str_idx) { @@ -2110,10 +2152,10 @@ check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes, static reg_errcode_t internal_function -sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, +sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, Idx str_idx, const re_node_set *candidates) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; Idx node_idx, node; re_sift_context_t local_sctx; @@ -2141,8 +2183,10 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, enabled_idx = first_idx; do { + Idx subexp_len; + Idx to_idx; + Idx dst_node; bool ok; - Idx subexp_len, to_idx, dst_node; re_dfastate_t *cur_state; if (entry->node != node) @@ -2211,7 +2255,7 @@ internal_function sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, Idx node_idx, Idx str_idx, Idx max_str_idx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; int naccepted; /* Check the node can accept `multi byte'. */ naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); @@ -2299,7 +2343,7 @@ internal_function merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, re_dfastate_t *next_state) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx cur_idx = re_string_cur_idx (&mctx->input); if (cur_idx > mctx->state_log_top) @@ -2377,7 +2421,7 @@ static re_dfastate_t * internal_function find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) { - re_dfastate_t *cur_state = NULL; + re_dfastate_t *cur_state; do { Idx max = mctx->state_log_top; @@ -2409,7 +2453,7 @@ internal_function check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, Idx str_idx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx node_idx; reg_errcode_t err; @@ -2424,7 +2468,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, if (dfa->nodes[node].type == OP_OPEN_SUBEXP && dfa->nodes[node].opr.idx < BITSET_WORD_BITS && (dfa->used_bkref_map - & ((bitset_word) 1 << dfa->nodes[node].opr.idx))) + & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) { err = match_ctx_add_subtop (mctx, node, str_idx); if (BE (err != REG_NOERROR, 0)) @@ -2442,7 +2486,7 @@ static re_dfastate_t * transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, re_dfastate_t *state) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; re_node_set next_nodes; re_dfastate_t *next_state; Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input); @@ -2481,7 +2525,7 @@ static reg_errcode_t internal_function transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; Idx i; @@ -2535,7 +2579,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) if (BE (err != REG_NOERROR, 0)) return err; } - context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags); + context = re_string_context_at (&mctx->input, dest_idx - 1, + mctx->eflags); mctx->state_log[dest_idx] = re_acquire_state_context (&err, dfa, &dest_nodes, context); if (dest_state != NULL) @@ -2551,7 +2596,7 @@ static reg_errcode_t internal_function transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; Idx i; Idx cur_str_idx = re_string_cur_idx (&mctx->input); @@ -2665,14 +2710,15 @@ static reg_errcode_t internal_function get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; Idx subexp_num, sub_top_idx; const char *buf = (const char *) re_string_get_buffer (&mctx->input); /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); if (cache_idx != REG_MISSING) { - const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx; + const struct re_backref_cache_entry *entry + = mctx->bkref_ents + cache_idx; do if (entry->node == bkref_node) return REG_NOERROR; /* We already checked it. */ @@ -2719,7 +2765,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) buf = (const char *) re_string_get_buffer (&mctx->input); } if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0) - break; /* We don't need to search this sub expression any more. */ + /* We don't need to search this sub expression any more. */ + break; } bkref_str_off += sl_str_diff; sl_str += sl_str_diff; @@ -2771,20 +2818,22 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) continue; /* Does this state have a ')' of the sub expression? */ nodes = &mctx->state_log[sl_str]->nodes; - cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP); + cls_node = find_subexp_node (dfa, nodes, subexp_num, + OP_CLOSE_SUBEXP); if (cls_node == REG_MISSING) continue; /* No. */ if (sub_top->path == NULL) { - sub_top->path = re_calloc (state_array_t, - sl_str - sub_top->str_idx + 1); + sub_top->path = calloc (sizeof (state_array_t), + sl_str - sub_top->str_idx + 1); if (sub_top->path == NULL) return REG_ESPACE; } /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node in the current context? */ err = check_arrival (mctx, sub_top->path, sub_top->node, - sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP); + sub_top->str_idx, cls_node, sl_str, + OP_CLOSE_SUBEXP); if (err == REG_NOMATCH) continue; if (BE (err != REG_NOERROR, 0)) @@ -2816,7 +2865,8 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, Idx to_idx; /* Can the subexpression arrive the back reference? */ err = check_arrival (mctx, &sub_last->path, sub_last->node, - sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP); + sub_last->str_idx, bkref_node, bkref_str, + OP_OPEN_SUBEXP); if (err != REG_NOERROR) return err; err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, @@ -2859,12 +2909,11 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, static reg_errcode_t internal_function -check_arrival (re_match_context_t *mctx, state_array_t *path, - Idx top_node, Idx top_str, Idx last_node, Idx last_str, - int type) +check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, + Idx top_str, Idx last_node, Idx last_str, int type) { - re_dfa_t *const dfa = mctx->dfa; - reg_errcode_t err; + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err = REG_NOERROR; Idx subexp_num, backup_cur_idx, str_idx, null_cnt; re_dfastate_t *cur_state = NULL; re_node_set *cur_nodes, next_nodes; @@ -2878,18 +2927,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, re_dfastate_t **new_array; Idx old_alloc = path->alloc; Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1; - if (BE (new_alloc < old_alloc, 0)) + if (BE (new_alloc < old_alloc, 0) + || BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) return REG_ESPACE; - new_array = re_xrealloc (path->array, re_dfastate_t *, new_alloc); + new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); if (BE (new_array == NULL, 0)) return REG_ESPACE; path->array = new_array; path->alloc = new_alloc; memset (new_array + old_alloc, '\0', - sizeof (re_dfastate_t *) * (new_alloc - old_alloc)); + sizeof (re_dfastate_t *) * (path->alloc - old_alloc)); } - str_idx = path->next_idx == 0 ? top_str : path->next_idx; + str_idx = path->next_idx ? path->next_idx : top_str; /* Temporary modify MCTX. */ backup_state_log = mctx->state_log; @@ -2917,7 +2967,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, if (cur_state && cur_state->has_backref) { err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); - if (BE ( err != REG_NOERROR, 0)) + if (BE (err != REG_NOERROR, 0)) return err; } else @@ -2929,7 +2979,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, { err = expand_bkref_cache (mctx, &next_nodes, str_idx, subexp_num, type); - if (BE ( err != REG_NOERROR, 0)) + if (BE (err != REG_NOERROR, 0)) { re_node_set_free (&next_nodes); return err; @@ -2960,7 +3010,8 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, if (cur_state) { err = check_arrival_add_next_nodes (mctx, str_idx, - &cur_state->non_eps_nodes, &next_nodes); + &cur_state->non_eps_nodes, + &next_nodes); if (BE (err != REG_NOERROR, 0)) { re_node_set_free (&next_nodes); @@ -2978,7 +3029,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, } err = expand_bkref_cache (mctx, &next_nodes, str_idx, subexp_num, type); - if (BE ( err != REG_NOERROR, 0)) + if (BE (err != REG_NOERROR, 0)) { re_node_set_free (&next_nodes); return err; @@ -3021,13 +3072,12 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, static reg_errcode_t internal_function check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, - re_node_set *cur_nodes, - re_node_set *next_nodes) + re_node_set *cur_nodes, re_node_set *next_nodes) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; bool ok; Idx cur_idx; - reg_errcode_t err; + reg_errcode_t err = REG_NOERROR; re_node_set union_set; re_node_set_init_empty (&union_set); for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx) @@ -3100,7 +3150,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, static reg_errcode_t internal_function -check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, +check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, Idx ex_subexp, int type) { reg_errcode_t err; @@ -3118,7 +3168,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, for (idx = 0; idx < cur_nodes->nelem; ++idx) { Idx cur_node = cur_nodes->elems[idx]; - re_node_set *eclosure = dfa->eclosures + cur_node; + const re_node_set *eclosure = dfa->eclosures + cur_node; outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); if (outside_node == REG_MISSING) { @@ -3153,7 +3203,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, static reg_errcode_t internal_function -check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, +check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, Idx target, Idx ex_subexp, int type) { Idx cur_node; @@ -3179,12 +3229,12 @@ check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, break; if (dfa->edests[cur_node].nelem == 2) { - reg_errcode_t ret = - check_arrival_expand_ecl_sub (dfa, dst_nodes, - dfa->edests[cur_node].elems[1], - ex_subexp, type); - if (BE (ret != REG_NOERROR, 0)) - return ret; + reg_errcode_t err; + err = check_arrival_expand_ecl_sub (dfa, dst_nodes, + dfa->edests[cur_node].elems[1], + ex_subexp, type); + if (BE (err != REG_NOERROR, 0)) + return err; } cur_node = dfa->edests[cur_node].elems[0]; } @@ -3201,7 +3251,7 @@ internal_function expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, Idx cur_str, Idx subexp_num, int type) { - re_dfa_t *const dfa = mctx->dfa; + const re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); struct re_backref_cache_entry *ent; @@ -3287,25 +3337,26 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, static bool internal_function -build_trtable (re_dfa_t *dfa, re_dfastate_t *state) +build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) { reg_errcode_t err; Idx i, j; int ch; bool need_word_trtable = false; - bitset_word elem, mask; - bool dests_node_malloced = false, dest_states_malloced = false; + bitset_word_t elem, mask; + bool dests_node_malloced = false; + bool dest_states_malloced = false; Idx ndests; /* Number of the destination states from `state'. */ re_dfastate_t **trtable; re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; re_node_set follows, *dests_node; - bitset *dests_ch; - bitset acceptable; + bitset_t *dests_ch; + bitset_t acceptable; struct dests_alloc { re_node_set dests_node[SBC_MAX]; - bitset dests_ch[SBC_MAX]; + bitset_t dests_ch[SBC_MAX]; } *dests_alloc; /* We build DFA states which corresponds to the destination nodes @@ -3313,7 +3364,7 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) destination state contains, and `dests_ch[i]' represents the characters which i-th destination state accepts. */ if (__libc_use_alloca (sizeof (struct dests_alloc))) - dests_alloc = (struct dests_alloc *) alloca (sizeof dests_alloc[0]); + dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); else { dests_alloc = re_malloc (struct dests_alloc, 1); @@ -3336,7 +3387,8 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) free (dests_alloc); if (ndests == 0) { - state->trtable = re_calloc (re_dfastate_t *, SBC_MAX); + state->trtable = (re_dfastate_t **) + calloc (sizeof (re_dfastate_t *), SBC_MAX); return true; } return false; @@ -3347,12 +3399,13 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state) goto out_free; /* Avoid arithmetic overflow in size calculation. */ - if (BE (((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX) - / (3 * sizeof (re_dfastate_t *))) - < ndests, 0)) + if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) + / (3 * sizeof (re_dfastate_t *))) + < ndests), + 0)) goto out_free; - if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX + if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX + ndests * 3 * sizeof (re_dfastate_t *))) dest_states = (re_dfastate_t **) alloca (ndests * 3 * sizeof (re_dfastate_t *)); @@ -3428,7 +3481,8 @@ out_free: character, or we are in a single-byte character set so we can discern by looking at the character code: allocate a 256-entry transition table. */ - trtable = state->trtable = re_calloc (re_dfastate_t *, SBC_MAX); + trtable = state->trtable = + (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); if (BE (trtable == NULL, 0)) goto out_free; @@ -3458,7 +3512,8 @@ out_free: by looking at the character code: build two 256-entry transition tables, one starting at trtable[0] and one starting at trtable[SBC_MAX]. */ - trtable = state->word_trtable = re_calloc (re_dfastate_t *, 2 * SBC_MAX); + trtable = state->word_trtable = + (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); if (BE (trtable == NULL, 0)) goto out_free; @@ -3518,13 +3573,13 @@ out_free: static Idx internal_function group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, - re_node_set *dests_node, bitset *dests_ch) + re_node_set *dests_node, bitset_t *dests_ch) { reg_errcode_t err; bool ok; Idx i, j, k; Idx ndests; /* Number of the destinations from `state'. */ - bitset accepts; /* Characters a node can accept. */ + bitset_t accepts; /* Characters a node can accept. */ const re_node_set *cur_nodes = &state->nodes; bitset_empty (accepts); ndests = 0; @@ -3551,21 +3606,21 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, else #endif bitset_set_all (accepts); - if (!(dfa->syntax & REG_DOT_NEWLINE)) + if (!(dfa->syntax & RE_DOT_NEWLINE)) bitset_clear (accepts, '\n'); - if (dfa->syntax & REG_DOT_NOT_NULL) + if (dfa->syntax & RE_DOT_NOT_NULL) bitset_clear (accepts, '\0'); } #ifdef RE_ENABLE_I18N else if (type == OP_UTF8_PERIOD) { - if (SBC_MAX / 2 % BITSET_WORD_BITS == 0) - memset (accepts, -1, sizeof accepts / 2); + if (ASCII_CHARS % BITSET_WORD_BITS == 0) + memset (accepts, -1, ASCII_CHARS / CHAR_BIT); else bitset_merge (accepts, utf8_sb_map); - if (!(dfa->syntax & REG_DOT_NEWLINE)) + if (!(dfa->syntax & RE_DOT_NEWLINE)) bitset_clear (accepts, '\n'); - if (dfa->syntax & REG_DOT_NOT_NULL) + if (dfa->syntax & RE_DOT_NOT_NULL) bitset_clear (accepts, '\0'); } #endif @@ -3593,7 +3648,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, if (constraint & NEXT_WORD_CONSTRAINT) { - bitset_word any_set = 0; + bitset_word_t any_set = 0; if (type == CHARACTER && !node->word_char) { bitset_empty (accepts); @@ -3612,7 +3667,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, } if (constraint & NEXT_NOTWORD_CONSTRAINT) { - bitset_word any_set = 0; + bitset_word_t any_set = 0; if (type == CHARACTER && node->word_char) { bitset_empty (accepts); @@ -3635,10 +3690,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, state. Above, we make sure that accepts is not empty. */ for (j = 0; j < ndests; ++j) { - bitset intersec; /* Intersection sets, see below. */ - bitset remains; + bitset_t intersec; /* Intersection sets, see below. */ + bitset_t remains; /* Flags, see below. */ - bitset_word has_intersec, not_subset, not_consumed; + bitset_word_t has_intersec, not_subset, not_consumed; /* Optimization, skip if this state doesn't accept the character. */ if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c)) @@ -3710,7 +3765,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, static int internal_function -check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, +check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, const re_string_t *input, Idx str_idx) { const re_token_t *node = dfa->nodes + node_idx; @@ -3776,9 +3831,9 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, /* FIXME: I don't think this if is needed, as both '\n' and '\0' are char_len == 1. */ /* '.' accepts any one character except the following two cases. */ - if ((!(dfa->syntax & REG_DOT_NEWLINE) && + if ((!(dfa->syntax & RE_DOT_NEWLINE) && re_string_byte_at (input, str_idx) == '\n') || - ((dfa->syntax & REG_DOT_NOT_NULL) && + ((dfa->syntax & RE_DOT_NOT_NULL) && re_string_byte_at (input, str_idx) == '\0')) return 0; return char_len; @@ -3911,7 +3966,7 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx, # endif /* _LIBC */ { /* match with range expression? */ -#if __GNUC__ >= 2 +#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && __STRICT_ANSI__) wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'}; #else 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, # ifdef _LIBC static unsigned int +internal_function find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) { uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); @@ -4028,13 +4084,13 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, #ifdef RE_ENABLE_I18N case OP_UTF8_PERIOD: - if (ch >= 0x80) + if (ch >= ASCII_CHARS) return false; /* FALLTHROUGH */ #endif case OP_PERIOD: - if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE)) - || (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL))) + if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) + || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) return false; break; @@ -4064,6 +4120,10 @@ extend_buffers (re_match_context_t *mctx) reg_errcode_t ret; re_string_t *pstr = &mctx->input; + /* Avoid overflow. */ + if (BE (SIZE_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0)) + return REG_ESPACE; + /* Double the lengthes of the buffers. */ ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); if (BE (ret != REG_NOERROR, 0)) @@ -4075,8 +4135,8 @@ extend_buffers (re_match_context_t *mctx) /* XXX We have no indication of the size of this buffer. If this allocation fail we have no indication that the state_log array does not have the right size. */ - re_dfastate_t **new_array = re_xrealloc (mctx->state_log, re_dfastate_t *, - pstr->bufs_len + 1); + re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, + pstr->bufs_len + 1); if (BE (new_array == NULL, 0)) return REG_ESPACE; mctx->state_log = new_array; @@ -4124,8 +4184,15 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) mctx->match_last = REG_MISSING; if (n > 0) { - mctx->bkref_ents = re_xmalloc (struct re_backref_cache_entry, n); - mctx->sub_tops = re_xmalloc (re_sub_match_top_t *, n); + /* Avoid overflow. */ + size_t max_object_size = + MAX (sizeof (struct re_backref_cache_entry), + sizeof (re_sub_match_top_t *)); + if (BE (SIZE_MAX / max_object_size < n, 0)) + return REG_ESPACE; + + mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); + mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) return REG_ESPACE; } @@ -4191,14 +4258,14 @@ match_ctx_free (re_match_context_t *mctx) static reg_errcode_t internal_function -match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, - Idx from, Idx to) +match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, + Idx to) { if (mctx->nbkref_ents >= mctx->abkref_ents) { struct re_backref_cache_entry* new_entry; - new_entry = re_x2realloc (mctx->bkref_ents, struct re_backref_cache_entry, - &mctx->abkref_ents); + new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, + mctx->abkref_ents * 2); if (BE (new_entry == NULL, 0)) { re_free (mctx->bkref_ents); @@ -4206,8 +4273,8 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, } mctx->bkref_ents = new_entry; memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', - (sizeof (struct re_backref_cache_entry) - * (mctx->abkref_ents - mctx->nbkref_ents))); + sizeof (struct re_backref_cache_entry) * mctx->abkref_ents); + mctx->abkref_ents *= 2; } if (mctx->nbkref_ents > 0 && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx) @@ -4271,16 +4338,16 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) #endif if (BE (mctx->nsub_tops == mctx->asub_tops, 0)) { - Idx new_asub_tops = mctx->asub_tops; - re_sub_match_top_t **new_array = re_x2realloc (mctx->sub_tops, - re_sub_match_top_t *, - &new_asub_tops); + Idx new_asub_tops = mctx->asub_tops * 2; + re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, + re_sub_match_top_t *, + new_asub_tops); if (BE (new_array == NULL, 0)) return REG_ESPACE; mctx->sub_tops = new_array; mctx->asub_tops = new_asub_tops; } - mctx->sub_tops[mctx->nsub_tops] = re_calloc (re_sub_match_top_t, 1); + mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) return REG_ESPACE; mctx->sub_tops[mctx->nsub_tops]->node = node; @@ -4298,16 +4365,16 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) re_sub_match_last_t *new_entry; if (BE (subtop->nlasts == subtop->alasts, 0)) { - Idx new_alasts = subtop->alasts; - re_sub_match_last_t **new_array = re_x2realloc (subtop->lasts, - re_sub_match_last_t *, - &new_alasts); + Idx new_alasts = 2 * subtop->alasts + 1; + re_sub_match_last_t **new_array = re_realloc (subtop->lasts, + re_sub_match_last_t *, + new_alasts); if (BE (new_array == NULL, 0)) return NULL; subtop->lasts = new_array; subtop->alasts = new_alasts; } - new_entry = re_calloc (re_sub_match_last_t, 1); + new_entry = calloc (1, sizeof (re_sub_match_last_t)); if (BE (new_entry != NULL, 1)) { subtop->lasts[subtop->nlasts] = new_entry; @@ -4320,10 +4387,8 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) static void internal_function -sift_ctx_init (re_sift_context_t *sctx, - re_dfastate_t **sifted_sts, - re_dfastate_t **limited_sts, - Idx last_node, Idx last_str_idx) +sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, + re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx) { sctx->sifted_states = sifted_sts; sctx->limited_states = limited_sts; diff --git a/lib/safe-read.c b/gl/safe-read.c similarity index 93% rename from lib/safe-read.c rename to gl/safe-read.c index 9caf846..b7bf1d5 100644 --- a/lib/safe-read.c +++ b/gl/safe-read.c @@ -1,7 +1,7 @@ /* An interface to read and write that retries after interrupts. - Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005 Free Software - Foundation, Inc. + Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include /* Specification. */ #ifdef SAFE_WRITE diff --git a/lib/safe-read.h b/gl/safe-read.h similarity index 89% rename from lib/safe-read.h rename to gl/safe-read.h index 9f8a59b..3451955 100644 --- a/lib/safe-read.h +++ b/gl/safe-read.h @@ -1,5 +1,5 @@ /* An interface to read() that retries after interrupts. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +17,19 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + + #define SAFE_READ_ERROR ((size_t) -1) /* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted. Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR upon error. */ extern size_t safe_read (int fd, void *buf, size_t count); + + +#ifdef __cplusplus +} +#endif diff --git a/lib/safe-write.c b/gl/safe-write.c similarity index 100% rename from lib/safe-write.c rename to gl/safe-write.c diff --git a/lib/safe-write.h b/gl/safe-write.h similarity index 100% rename from lib/safe-write.h rename to 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 @@ +/* size_max.h -- declare SIZE_MAX through system headers + Copyright (C) 2005-2006 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef GNULIB_SIZE_MAX_H +#define GNULIB_SIZE_MAX_H + +/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */ +# include +/* Get SIZE_MAX declaration on systems like glibc 2. */ +# if HAVE_STDINT_H +# include +# endif +/* On systems where these include files don't define it, SIZE_MAX is defined + in config.h. */ + +#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 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Written by Simon Josefsson and Paul Eggert. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "snprintf.h" + +#include +#include +#include +#include +#include + +#include "vasnprintf.h" + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +/* Print formatted output to string STR. Similar to sprintf, but + additional length SIZE limit how much is written into STR. Returns + string length of formatted string (which may be larger than SIZE). + STR may be NULL, in which case nothing will be written. On error, + return a negative value. */ +int +snprintf (char *str, size_t size, const char *format, ...) +{ + char *output; + size_t len; + size_t lenbuf = size; + va_list args; + + va_start (args, format); + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + va_end (args); + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (INT_MAX < len) + { + errno = EOVERFLOW; + return -1; + } + + return len; +} 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 @@ +/* Formatted output to strings. + Copyright (C) 2004 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef SNPRINTF_H +#define SNPRINTF_H + +/* Get snprintf declaration, if available. */ +#include + +#if defined HAVE_DECL_SNPRINTF && !HAVE_DECL_SNPRINTF +int snprintf (char *str, size_t size, const char *format, ...); +#endif + +#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 @@ +/* Provide a sys/socket header file for systems lacking it (read: MinGW). + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _SYS_SOCKET_H +#define _SYS_SOCKET_H + +/* This file is supposed to be used on platforms that lack + sys/socket.h. It is intended to provide definitions and prototypes + needed by an application. + + Currently only MinGW is supported. See the gnulib manual regarding + Windows sockets. MinGW has the header files winsock2.h and + ws2tcpip.h that declare the sys/socket.h definitions we need. Note + that you can influence which definitions you get by setting the + WINVER symbol before including these two files. For example, + getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that + symbol is set indiriectly through WINVER). You can set this by + adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your + code may not run on older Windows releases then. My Windows 2000 + box was not able to run the code, for example. The situation is + slightly confusing because: + http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp + suggests that getaddrinfo should be available on all Windows + releases. */ + + +#if HAVE_WINSOCK2_H +# include +#endif +#if HAVE_WS2TCPIP_H +# include +#endif + +/* For shutdown(). */ +#if !defined SHUT_RD && defined SD_RECEIVE +# define SHUT_RD SD_RECEIVE +#endif +#if !defined SHUT_WR && defined SD_SEND +# define SHUT_WR SD_SEND +#endif +#if !defined SHUT_RDWR && defined SD_BOTH +# define SHUT_RDWR SD_BOTH +#endif + +#if defined _WIN32 || defined __WIN32__ +# define ENOTSOCK WSAENOTSOCK +# define EADDRINUSE WSAEADDRINUSE +# define ENETRESET WSAENETRESET +# define ECONNABORTED WSAECONNABORTED +# define ECONNRESET WSAECONNRESET +# define ENOTCONN WSAENOTCONN +# define ESHUTDOWN WSAESHUTDOWN +#endif + +#endif /* _SYS_SOCKET_H */ diff --git a/lib/stdbool_.h b/gl/stdbool_.h similarity index 56% rename from lib/stdbool_.h rename to gl/stdbool_.h index 7cd2da8..efa80ba 100644 --- a/lib/stdbool_.h +++ b/gl/stdbool_.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -54,47 +54,57 @@ /* 7.16. Boolean type and values */ /* BeOS already #defines false 0, true 1. We use the same - definitions below, which is OK. */ + definitions below, but temporarily we have to #undef them. */ #ifdef __BEOS__ # include /* defines bool but not _Bool */ +# undef false +# undef true #endif -/* C++ and BeOS have a reliable bool (and _Bool, if it exists). - Otherwise, since this file is being compiled, the system - is not reliable so assume that the system _Bool is not - reliable either. Under that assumption, it is tempting to write - - typedef enum { false, true } _Bool; - - so that gdb prints values of type 'bool' symbolically. But if we do +/* For the sake of symbolic names in gdb, we define true and false as + enum constants, not only as macros. + It is tempting to write + typedef enum { false = 0, true = 1 } _Bool; + so that gdb prints values of type 'bool' symbolically. But if we do this, values of type '_Bool' may promote to 'int' or 'unsigned int' (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' - (see ISO C 99 6.3.1.1.(2)). We could instead try this: - - typedef enum { _Bool_dummy = -1, false, true } _Bool; - - as the negative value ensures that '_Bool' promotes to 'int'. - However, this runs into some other problems. First, Sun's C - compiler when (__SUNPRO_C < 0x550 || __STDC__ == 1) issues a stupid - "warning: _Bool is a keyword in ISO C99". Second, IBM's AIX cc - compiler 6.0.0.0 (and presumably other versions) mishandles - subscripts involving _Bool (effectively, _Bool promotes to unsigned - int in this case), and we need to redefine _Bool in that case. - Third, HP-UX 10.20's C compiler lacks but has _Bool and - mishandles comparisons of _Bool to int (it promotes _Bool to - unsigned int). - - The simplest way to work around these problems is to ignore any - existing definition of _Bool and use our own. */ - + (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the + enum; this ensures that '_Bool' promotes to 'int'. */ #if defined __cplusplus || defined __BEOS__ + /* A compiler known to have 'bool'. */ + /* If the compiler already has both 'bool' and '_Bool', we can assume they + are the same types. */ # if !@HAVE__BOOL@ typedef bool _Bool; # endif #else -# define _Bool signed char +# if !defined __GNUC__ + /* If @HAVE__BOOL@: + Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when + the built-in _Bool type is used. See + http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html + Similar bugs are likely with other compilers as well; this file + wouldn't be used if was working. + So we override the _Bool type. + If !@HAVE__BOOL@: + Need to define _Bool ourselves. As 'signed char' or as an enum type? + Use of a typedef, with SunPRO C, leads to a stupid + "warning: _Bool is a keyword in ISO C99". + Use of an enum type, with IRIX cc, leads to a stupid + "warning(1185): enumerated type mixed with another type". + The only benefit of the enum type, debuggability, is not important + with these compilers. So use 'signed char' and no typedef. */ +# define _Bool signed char +enum { false = 0, true = 1 }; +# else + /* With this compiler, trust the _Bool type if the compiler has it. */ +# if !@HAVE__BOOL@ +typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; +# endif +# endif #endif - #define bool _Bool /* 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 @@ +/* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. + Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. + This file is part of gnulib. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _GL_STDINT_H +#define _GL_STDINT_H + +/* + * ISO C 99 for platforms that lack it. + * + */ + +/* Get those types that are already defined in other system include + files, so that we can "#define int8_t signed char" below without + worrying about a later system include file containing a "typedef + signed char int8_t;" that will get messed up by our macro. Our + macros should all be consistent with the system versions, except + for the "fast" types and macros, which we recommend against using + in public interfaces due to compiler differences. */ + +#if @HAVE_STDINT_H@ +# if defined __sgi && ! defined __c99 + /* Bypass IRIX's if in C89 mode, since it merely annoys users + with "This header file is to be used only for c99 mode compilations" + diagnostics. */ +# define __STDINT_H__ +# endif + /* Other systems may have an incomplete or buggy . + Include it before , since any "#include " + in would reinclude us, skipping our contents because + _GL_STDINT_H is defined. */ +# include @ABSOLUTE_STDINT_H@ +#endif + +/* defines some of the stdint.h types as well, on glibc, + IRIX 6.5, and OpenBSD 3.8 (via ). + AIX 5.2 isn't needed and causes troubles. + MacOS X 10.4.6 includes (which is us), but + relies on the system definitions, so include + after @ABSOLUTE_STDINT_H@. */ +#if @HAVE_SYS_TYPES_H@ && ! defined _AIX +# include +#endif + +/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */ +#include + +#if @HAVE_INTTYPES_H@ + /* In OpenBSD 3.8, includes , which defines + int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. + also defines intptr_t and uintptr_t. */ +# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H +# include +# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H +#elif @HAVE_SYS_INTTYPES_H@ + /* Solaris 7 has the types except the *_fast*_t types, and + the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ +# include +#endif + +#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ + /* Linux libc4 >= 4.6.7 and libc5 have a that defines + int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is + included by . */ +# include +#endif + +#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS + +/* Get WCHAR_MIN, WCHAR_MAX. */ +# if ! (defined WCHAR_MIN && defined WCHAR_MAX) +# include +# endif + +#endif + +/* Minimum and maximum values for a integer type under the usual assumption. + Return an unspecified value if BITS == 0, adding a check to pacify + picky compilers. */ + +#define _STDINT_MIN(signed, bits, zero) \ + ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) + +#define _STDINT_MAX(signed, bits, zero) \ + ((signed) \ + ? ~ _STDINT_MIN (signed, bits, zero) \ + : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) + +/* 7.18.1.1. Exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef int8_t +#undef uint8_t +#define int8_t signed char +#define uint8_t unsigned char + +#undef int16_t +#undef uint16_t +#define int16_t short int +#define uint16_t unsigned short int + +#undef int32_t +#undef uint32_t +#define int32_t int +#define uint32_t unsigned int + +#undef int64_t +#if LONG_MAX >> 31 >> 31 == 1 +# define int64_t long int +#elif defined _MSC_VER +# define int64_t __int64 +#elif @HAVE_LONG_LONG_INT@ +# define int64_t long long int +#endif + +#undef uint64_t +#if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# define uint64_t unsigned long int +#elif defined _MSC_VER +# define uint64_t unsigned __int64 +#elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# define uint64_t unsigned long long int +#endif + +/* Avoid collision with Solaris 2.5.1 etc. */ +#define _UINT8_T +#define _UINT32_T +#define _UINT64_T + + +/* 7.18.1.2. Minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef int_least8_t +#undef uint_least8_t +#undef int_least16_t +#undef uint_least16_t +#undef int_least32_t +#undef uint_least32_t +#undef int_least64_t +#undef uint_least64_t +#define int_least8_t int8_t +#define uint_least8_t uint8_t +#define int_least16_t int16_t +#define uint_least16_t uint16_t +#define int_least32_t int32_t +#define uint_least32_t uint32_t +#ifdef int64_t +# define int_least64_t int64_t +#endif +#ifdef uint64_t +# define uint_least64_t uint64_t +#endif + +/* 7.18.1.3. Fastest minimum-width integer types */ + +/* Note: Other substitutes may define these types differently. + It is not recommended to use these types in public header files. */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. Assume that 'long int' + is fast enough for all narrower integers. */ + +#undef int_fast8_t +#undef uint_fast8_t +#undef int_fast16_t +#undef uint_fast16_t +#undef int_fast32_t +#undef uint_fast32_t +#undef int_fast64_t +#undef uint_fast64_t +#define int_fast8_t long int +#define uint_fast8_t unsigned int_fast8_t +#define int_fast16_t long int +#define uint_fast16_t unsigned int_fast16_t +#define int_fast32_t long int +#define uint_fast32_t unsigned int_fast32_t +#ifdef int64_t +# define int_fast64_t int64_t +#endif +#ifdef uint64_t +# define uint_fast64_t uint64_t +#endif + +/* 7.18.1.4. Integer types capable of holding object pointers */ + +#undef intptr_t +#undef uintptr_t +#define intptr_t long int +#define uintptr_t unsigned long int + +/* 7.18.1.5. Greatest-width integer types */ + +/* Note: These types are compiler dependent. It may be unwise to use them in + public header files. */ + +#undef intmax_t +#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +# define intmax_t long long int +#elif defined int64_t +# define intmax_t int64_t +#else +# define intmax_t long int +#endif + +#undef uintmax_t +#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +# define uintmax_t unsigned long long int +#elif defined uint64_t +# define uintmax_t uint64_t +#else +# define uintmax_t unsigned long int +#endif + +/* 7.18.2. Limits of specified-width integer types */ + +#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS + +/* 7.18.2.1. Limits of exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef INT8_MIN +#undef INT8_MAX +#undef UINT8_MAX +#define INT8_MIN (~ INT8_MAX) +#define INT8_MAX 127 +#define UINT8_MAX 255 + +#undef INT16_MIN +#undef INT16_MAX +#undef UINT16_MAX +#define INT16_MIN (~ INT16_MAX) +#define INT16_MAX 32767 +#define UINT16_MAX 65535 + +#undef INT32_MIN +#undef INT32_MAX +#undef UINT32_MAX +#define INT32_MIN (~ INT32_MAX) +#define INT32_MAX 2147483647 +#define UINT32_MAX 4294967295U + +#undef INT64_MIN +#undef INT64_MAX +#ifdef int64_t +# define INT64_MIN (~ INT64_MAX) +# define INT64_MAX INTMAX_C (9223372036854775807) +#endif + +#undef UINT64_MAX +#ifdef uint64_t +# define UINT64_MAX UINTMAX_C (18446744073709551615) +#endif + +/* 7.18.2.2. Limits of minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef INT_LEAST8_MIN +#undef INT_LEAST8_MAX +#undef UINT_LEAST8_MAX +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#undef INT_LEAST16_MIN +#undef INT_LEAST16_MAX +#undef UINT_LEAST16_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#undef INT_LEAST32_MIN +#undef INT_LEAST32_MAX +#undef UINT_LEAST32_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#undef INT_LEAST64_MIN +#undef INT_LEAST64_MAX +#ifdef int64_t +# define INT_LEAST64_MIN INT64_MIN +# define INT_LEAST64_MAX INT64_MAX +#endif + +#undef UINT_LEAST64_MAX +#ifdef uint64_t +# define UINT_LEAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.3. Limits of fastest minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. */ + +#undef INT_FAST8_MIN +#undef INT_FAST8_MAX +#undef UINT_FAST8_MAX +#define INT_FAST8_MIN LONG_MIN +#define INT_FAST8_MAX LONG_MAX +#define UINT_FAST8_MAX ULONG_MAX + +#undef INT_FAST16_MIN +#undef INT_FAST16_MAX +#undef UINT_FAST16_MAX +#define INT_FAST16_MIN LONG_MIN +#define INT_FAST16_MAX LONG_MAX +#define UINT_FAST16_MAX ULONG_MAX + +#undef INT_FAST32_MIN +#undef INT_FAST32_MAX +#undef UINT_FAST32_MAX +#define INT_FAST32_MIN LONG_MIN +#define INT_FAST32_MAX LONG_MAX +#define UINT_FAST32_MAX ULONG_MAX + +#undef INT_FAST64_MIN +#undef INT_FAST64_MAX +#ifdef int64_t +# define INT_FAST64_MIN INT64_MIN +# define INT_FAST64_MAX INT64_MAX +#endif + +#undef UINT_FAST64_MAX +#ifdef uint64_t +# define UINT_FAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.4. Limits of integer types capable of holding object pointers */ + +#undef INTPTR_MIN +#undef INTPTR_MAX +#undef UINTPTR_MAX +#define INTPTR_MIN LONG_MIN +#define INTPTR_MAX LONG_MAX +#define UINTPTR_MAX ULONG_MAX + +/* 7.18.2.5. Limits of greatest-width integer types */ + +#undef INTMAX_MIN +#undef INTMAX_MAX +#define INTMAX_MIN (~ INTMAX_MAX) +#ifdef INT64_MAX +# define INTMAX_MAX INT64_MAX +#else +# define INTMAX_MAX INT32_MAX +#endif + +#undef UINTMAX_MAX +#ifdef UINT64_MAX +# define UINTMAX_MAX UINT64_MAX +#else +# define UINTMAX_MAX UINT32_MAX +#endif + +/* 7.18.3. Limits of other integer types */ + +/* ptrdiff_t limits */ +#undef PTRDIFF_MIN +#undef PTRDIFF_MAX +#define PTRDIFF_MIN \ + _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) +#define PTRDIFF_MAX \ + _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) + +/* sig_atomic_t limits */ +#undef SIG_ATOMIC_MIN +#undef SIG_ATOMIC_MAX +#define SIG_ATOMIC_MIN \ + _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) +#define SIG_ATOMIC_MAX \ + _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) + + +/* size_t limit */ +#undef SIZE_MAX +#define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) + +/* wchar_t limits */ +#undef WCHAR_MIN +#undef WCHAR_MAX +#define WCHAR_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) +#define WCHAR_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) + +/* wint_t limits */ +#undef WINT_MIN +#undef WINT_MAX +#define WINT_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) +#define WINT_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) + +#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */ + +/* 7.18.4. Macros for integer constants */ + +#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS + +/* 7.18.4.1. Macros for minimum-width integer constants */ +/* According to ISO C 99 Technical Corrigendum 1 */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ + +#undef INT8_C +#undef UINT8_C +#define INT8_C(x) x +#define UINT8_C(x) x + +#undef INT16_C +#undef UINT16_C +#define INT16_C(x) x +#define UINT16_C(x) x + +#undef INT32_C +#undef UINT32_C +#define INT32_C(x) x +#define UINT32_C(x) x ## U + +#undef INT64_C +#undef UINT64_C +#if LONG_MAX >> 31 >> 31 == 1 +# define INT64_C(x) x##L +#elif defined _MSC_VER +# define INT64_C(x) x##i64 +#elif @HAVE_LONG_LONG_INT@ +# define INT64_C(x) x##LL +#endif +#if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# define UINT64_C(x) x##UL +#elif defined _MSC_VER +# define UINT64_C(x) x##ui64 +#elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# define UINT64_C(x) x##ULL +#endif + +/* 7.18.4.2. Macros for greatest-width integer constants */ + +#undef INTMAX_C +#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +# define INTMAX_C(x) x##LL +#elif defined int64_t +# define INTMAX_C(x) INT64_C(x) +#else +# define INTMAX_C(x) x##L +#endif + +#undef UINTMAX_C +#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +# define UINTMAX_C(x) x##ULL +#elif defined uint64_t +# define UINTMAX_C(x) UINT64_C(x) +#else +# define UINTMAX_C(x) x##UL +#endif + +#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ + +#endif /* _GL_STDINT_H */ diff --git a/lib/strcase.h b/gl/strcase.h similarity index 75% rename from lib/strcase.h rename to gl/strcase.h index e420798..07d4c9a 100644 --- a/lib/strcase.h +++ b/gl/strcase.h @@ -1,5 +1,5 @@ /* Case-insensitive string comparison functions. - Copyright (C) 1995-1996, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001, 2003, 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,13 +19,19 @@ #define _STRCASE_H #include - +/* Include header files with a possibly conflicting declarations of strcasecmp + before we define it as a macro, so that they will be no-ops if included + after strcasecmp is defined as a macro. */ +#include #ifdef __cplusplus extern "C" { #endif +/* No known system has a strcasecmp() function that works correctly in + multibyte locales. Therefore we use our version always. */ +#define strcasecmp rpl_strcasecmp /* Compare strings S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. @@ -37,7 +43,9 @@ extern int strcasecmp (const char *s1, const char *s2); returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. Note: This function can not work correctly in multibyte locales. */ +#if ! HAVE_DECL_STRNCASECMP extern int strncasecmp (const char *s1, const char *s2, size_t n); +#endif #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 @@ +/* Case-insensitive string comparison function. + Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. + Written by Bruno Haible , 2005, + based on earlier glibc code. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "strcase.h" + +#include +#include + +#if HAVE_MBRTOWC +# include "mbuiter.h" +#endif + +#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) + +/* Compare strings S1 and S2, ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less than, equal to or greater + than S2. + Note: This function may, in multibyte locales, return 0 for strings of + different lengths! */ +int +strcasecmp (const char *s1, const char *s2) +{ + if (s1 == s2) + return 0; + + /* Be careful not to look at the entire extent of s1 or s2 until needed. + This is useful because when two strings differ, the difference is + most often already in the very few first characters. */ +#if HAVE_MBRTOWC + if (MB_CUR_MAX > 1) + { + mbui_iterator_t iter1; + mbui_iterator_t iter2; + + mbui_init (iter1, s1); + mbui_init (iter2, s2); + + while (mbui_avail (iter1) && mbui_avail (iter2)) + { + int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); + + if (cmp != 0) + return cmp; + + mbui_advance (iter1); + mbui_advance (iter2); + } + if (mbui_avail (iter1)) + /* s2 terminated before s1. */ + return 1; + if (mbui_avail (iter2)) + /* s1 terminated before s2. */ + return -1; + return 0; + } + else +#endif + { + const unsigned char *p1 = (const unsigned char *) s1; + const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + do + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); + + if (c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); + } +} 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 @@ +/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006 Free + Software Foundation, Inc. + + This file is part of the GNU C Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _LIBC +# include +/* Get specification. */ +# include "strdup.h" +#endif + +#include +#include + +#undef __strdup +#ifdef _LIBC +# undef strdup +#endif + +#ifndef weak_alias +# define __strdup strdup +#endif + +/* Duplicate S, returning an identical malloc'd string. */ +char * +__strdup (const char *s) +{ + size_t len = strlen (s) + 1; + void *new = malloc (len); + + if (new == NULL) + return NULL; + + return (char *) memcpy (new, s, len); +} +#ifdef libc_hidden_def +libc_hidden_def (__strdup) +#endif +#ifdef weak_alias +weak_alias (__strdup, strdup) +#endif diff --git a/gl/strdup.h b/gl/strdup.h new file mode 100644 index 0000000..73e66e3 --- /dev/null +++ b/gl/strdup.h @@ -0,0 +1,39 @@ +/* strdup.h -- duplicate a string + Copyright (C) 2004, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef STRDUP_H_ +#define STRDUP_H_ + +/* Get strdup declaration, if available. */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined HAVE_DECL_STRDUP && !HAVE_DECL_STRDUP && !defined strdup +/* Duplicate S, returning an identical malloc'd string. */ +extern char *strdup (const char *s); +#endif + + +#ifdef __cplusplus +} +#endif + +#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 @@ +/* stripslash.c -- remove redundant trailing slashes from a file name + + Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "dirname.h" + +/* Remove trailing slashes from FILE. Return true if a trailing slash + was removed. This is useful when using file name completion from a + shell that adds a "/" after directory names (such as tcsh and + bash), because on symlinks to directories, several system calls + have different semantics according to whether a trailing slash is + present. */ + +bool +strip_trailing_slashes (char *file) +{ + char *base = last_component (file); + char *base_lim; + bool had_slash; + + /* last_component returns "" for file system roots, but we need to turn + `///' into `/'. */ + if (! *base) + base = file; + base_lim = base + base_len (base); + had_slash = (*base_lim != '\0'); + *base_lim = '\0'; + return had_slash; +} diff --git a/gl/strncasecmp.c b/gl/strncasecmp.c new file mode 100644 index 0000000..f59b953 --- /dev/null +++ b/gl/strncasecmp.c @@ -0,0 +1,63 @@ +/* strncasecmp.c -- case insensitive string comparator + Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "strcase.h" + +#include +#include + +#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) + +/* Compare no more than N bytes of strings S1 and S2, + ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less + than, equal to or greater than S2. */ + +int +strncasecmp (const char *s1, const char *s2, size_t n) +{ + register const unsigned char *p1 = (const unsigned char *) s1; + register const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2 || n == 0) + return 0; + + do + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); + + if (--n == 0 || c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); +} 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 @@ +/* A replacement function, for systems that lack strndup. + + Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free + Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include +#include "strndup.h" + +#include +#include + +#include "strnlen.h" + +char * +strndup (char const *s, size_t n) +{ + size_t len = strnlen (s, n); + char *new = malloc (len + 1); + + if (new == NULL) + return NULL; + + new[len] = '\0'; + return memcpy (new, s, len); +} 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 @@ +/* Duplicate a size-bounded string. + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Get size_t. */ +#include +/* If HAVE_STRNDUP, get the strndup declaration. + If !HAVE_STRNDUP, include now so that it doesn't cause + trouble if included later. */ +#include + +#if !HAVE_STRNDUP +# undef strndup +# define strndup rpl_strndup +# if !HAVE_DECL_STRNDUP /* Don't risk conflicting declarations. */ +/* Return a newly allocated copy of at most N bytes of STRING. */ +extern char *strndup (const char *string, size_t n); +# endif +#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 @@ +/* Find the length of STRING, but scan at most MAXLEN characters. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "strnlen.h" + +/* Find the length of STRING, but scan at most MAXLEN characters. + If no '\0' terminator is found in that many characters, return MAXLEN. */ + +size_t +strnlen (const char *string, size_t maxlen) +{ + const char *end = memchr (string, '\0', maxlen); + return end ? (size_t) (end - string) : maxlen; +} 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 @@ +/* Find the length of STRING, but scan at most MAXLEN characters. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef STRNLEN_H +#define STRNLEN_H + +/* Get strnlen declaration, if available. */ +#include + +#if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN +/* Find the length (number of bytes) of STRING, but scan at most + MAXLEN bytes. If no '\0' terminator is found in that many bytes, + return MAXLEN. */ +extern size_t strnlen(const char *string, size_t maxlen); +#endif + +#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 @@ +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + Copyright (C) 2005-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "strnlen1.h" + +#include + +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +/* This is the same as strnlen (string, maxlen - 1) + 1. */ +size_t +strnlen1 (const char *string, size_t maxlen) +{ + const char *end = (const char *) memchr (string, '\0', maxlen); + if (end != NULL) + return end - string + 1; + else + return maxlen; +} 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 @@ +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _STRNLEN1_H +#define _STRNLEN1_H + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +/* This is the same as strnlen (string, maxlen - 1) + 1. */ +extern size_t strnlen1 (const char *string, size_t maxlen); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _STRNLEN1_H */ diff --git a/lib/unistd--.h b/gl/unistd--.h similarity index 100% rename from lib/unistd--.h rename to gl/unistd--.h diff --git a/lib/unistd-safer.h b/gl/unistd-safer.h similarity index 100% rename from lib/unistd-safer.h rename to 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 @@ +/* Substitute for and wrapper around . + Copyright (C) 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _GL_UNISTD_H +#define _GL_UNISTD_H + +#if HAVE_UNISTD_H +# include @ABSOLUTE_UNISTD_H@ +#endif + + +/* Declare overridden functions. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef FCHDIR_REPLACEMENT + +/* Change the process' current working directory to the directory on which + the given file descriptor is open. */ +extern int fchdir (int /*fd*/); + +# define close rpl_close +extern int close (int); +# define dup rpl_dup +extern int dup (int); +# define dup2 rpl_dup2 +extern int dup2 (int, int); + +#endif + +#ifdef __cplusplus +} +#endif + + +#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 @@ +/* vsprintf with automatic memory allocation. + Copyright (C) 1999, 2002-2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#ifndef IN_LIBINTL +# include +#endif + +/* Specification. */ +#if WIDE_CHAR_VERSION +# include "vasnwprintf.h" +#else +# include "vasnprintf.h" +#endif + +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#if WIDE_CHAR_VERSION +# include "wprintf-parse.h" +#else +# include "printf-parse.h" +#endif + +/* Checked size_t computations. */ +#include "xsize.h" + +#ifdef HAVE_WCHAR_T +# ifdef HAVE_WCSLEN +# define local_wcslen wcslen +# else + /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid + a dependency towards this library, here is a local substitute. + Define this substitute only once, even if this file is included + twice in the same compilation unit. */ +# ifndef local_wcslen_defined +# define local_wcslen_defined 1 +static size_t +local_wcslen (const wchar_t *s) +{ + const wchar_t *ptr; + + for (ptr = s; *ptr != (wchar_t) 0; ptr++) + ; + return ptr - s; +} +# endif +# endif +#endif + +#if WIDE_CHAR_VERSION +# define VASNPRINTF vasnwprintf +# define CHAR_T wchar_t +# define DIRECTIVE wchar_t_directive +# define DIRECTIVES wchar_t_directives +# define PRINTF_PARSE wprintf_parse +# define USE_SNPRINTF 1 +# if HAVE_DECL__SNWPRINTF + /* On Windows, the function swprintf() has a different signature than + on Unix; we use the _snwprintf() function instead. */ +# define SNPRINTF _snwprintf +# else + /* Unix. */ +# define SNPRINTF swprintf +# endif +#else +# define VASNPRINTF vasnprintf +# define CHAR_T char +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +# define PRINTF_PARSE printf_parse +# define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) +# if HAVE_DECL__SNPRINTF + /* Windows. */ +# define SNPRINTF _snprintf +# else + /* Unix. */ +# define SNPRINTF snprintf +# endif +#endif + +CHAR_T * +VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) +{ + DIRECTIVES d; + arguments a; + + if (PRINTF_PARSE (format, &d, &a) < 0) + { + errno = EINVAL; + return NULL; + } + +#define CLEANUP() \ + free (d.dir); \ + if (a.arg) \ + free (a.arg); + + if (printf_fetchargs (args, &a) < 0) + { + CLEANUP (); + errno = EINVAL; + return NULL; + } + + { + size_t buf_neededlength; + CHAR_T *buf; + CHAR_T *buf_malloced; + const CHAR_T *cp; + size_t i; + DIRECTIVE *dp; + /* Output string accumulator. */ + CHAR_T *result; + size_t allocated; + size_t length; + + /* Allocate a small buffer that will hold a directive passed to + sprintf or snprintf. */ + buf_neededlength = + xsum4 (7, d.max_width_length, d.max_precision_length, 6); +#if HAVE_ALLOCA + if (buf_neededlength < 4000 / sizeof (CHAR_T)) + { + buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); + buf_malloced = NULL; + } + else +#endif + { + size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T)); + if (size_overflow_p (buf_memsize)) + goto out_of_memory_1; + buf = (CHAR_T *) malloc (buf_memsize); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; + } + + if (resultbuf != NULL) + { + result = resultbuf; + allocated = *lengthp; + } + else + { + result = NULL; + allocated = 0; + } + length = 0; + /* Invariants: + result is either == resultbuf or == NULL or malloc-allocated. + If length > 0, then result != NULL. */ + + /* Ensures that allocated >= needed. Aborts through a jump to + out_of_memory if needed is SIZE_MAX or otherwise too big. */ +#define ENSURE_ALLOCATION(needed) \ + if ((needed) > allocated) \ + { \ + size_t memory_size; \ + CHAR_T *memory; \ + \ + allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ + if ((needed) > allocated) \ + allocated = (needed); \ + memory_size = xtimes (allocated, sizeof (CHAR_T)); \ + if (size_overflow_p (memory_size)) \ + goto out_of_memory; \ + if (result == resultbuf || result == NULL) \ + memory = (CHAR_T *) malloc (memory_size); \ + else \ + memory = (CHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + memcpy (memory, result, length * sizeof (CHAR_T)); \ + result = memory; \ + } + + for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) + { + if (cp != dp->dir_start) + { + size_t n = dp->dir_start - cp; + size_t augmented_length = xsum (length, n); + + ENSURE_ALLOCATION (augmented_length); + memcpy (result + length, cp, n * sizeof (CHAR_T)); + length = augmented_length; + } + if (i == d.count) + break; + + /* Execute a single directive. */ + if (dp->conversion == '%') + { + size_t augmented_length; + + if (!(dp->arg_index == ARG_NONE)) + abort (); + augmented_length = xsum (length, 1); + ENSURE_ALLOCATION (augmented_length); + result[length] = '%'; + length = augmented_length; + } + else + { + if (!(dp->arg_index != ARG_NONE)) + abort (); + + if (dp->conversion == 'n') + { + switch (a.arg[dp->arg_index].type) + { + case TYPE_COUNT_SCHAR_POINTER: + *a.arg[dp->arg_index].a.a_count_schar_pointer = length; + break; + case TYPE_COUNT_SHORT_POINTER: + *a.arg[dp->arg_index].a.a_count_short_pointer = length; + break; + case TYPE_COUNT_INT_POINTER: + *a.arg[dp->arg_index].a.a_count_int_pointer = length; + break; + case TYPE_COUNT_LONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longint_pointer = length; + break; +#ifdef HAVE_LONG_LONG_INT + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; +#endif + default: + abort (); + } + } + else + { + arg_type type = a.arg[dp->arg_index].type; + CHAR_T *p; + unsigned int prefix_count; + int prefixes[2]; +#if !USE_SNPRINTF + size_t tmp_length; + CHAR_T tmpbuf[700]; + CHAR_T *tmp; + + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + { + size_t width; + size_t precision; + + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + width = (arg < 0 ? (unsigned int) (-arg) : arg); + } + else + { + const CHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + } + + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + precision = (arg < 0 ? 0 : arg); + } + else + { + const CHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + } + } + + switch (dp->conversion) + { + + case 'd': case 'i': case 'u': +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Multiply by 2, as an estimate for FLAG_GROUP. */ + tmp_length = xsum (tmp_length, tmp_length); + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'o': +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'x': case 'X': +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 2, to account for a leading sign or alternate form. */ + tmp_length = xsum (tmp_length, 2); + break; + + case 'f': case 'F': +# ifdef HAVE_LONG_DOUBLE + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + else +# endif + tmp_length = + (unsigned int) (DBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': + tmp_length = + 12; /* sign, decimal point, exponent etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'c': +# if defined HAVE_WINT_T && !WIDE_CHAR_VERSION + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else +# endif + tmp_length = 1; + break; + + case 's': +# ifdef HAVE_WCHAR_T + if (type == TYPE_WIDE_STRING) + { + tmp_length = + local_wcslen (a.arg[dp->arg_index].a.a_wide_string); + +# if !WIDE_CHAR_VERSION + tmp_length = xtimes (tmp_length, MB_CUR_MAX); +# endif + } + else +# endif + tmp_length = strlen (a.arg[dp->arg_index].a.a_string); + break; + + case 'p': + tmp_length = + (unsigned int) (sizeof (void *) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1 /* turn floor into ceil */ + + 2; /* account for leading 0x */ + break; + + default: + abort (); + } + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + } + + if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (CHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } +#endif + + /* Construct the format string for calling snprintf or + sprintf. */ + p = buf; + *p++ = '%'; + if (dp->flags & FLAG_GROUP) + *p++ = '\''; + if (dp->flags & FLAG_LEFT) + *p++ = '-'; + if (dp->flags & FLAG_SHOWSIGN) + *p++ = '+'; + if (dp->flags & FLAG_SPACE) + *p++ = ' '; + if (dp->flags & FLAG_ALT) + *p++ = '#'; + if (dp->flags & FLAG_ZERO) + *p++ = '0'; + if (dp->width_start != dp->width_end) + { + size_t n = dp->width_end - dp->width_start; + memcpy (p, dp->width_start, n * sizeof (CHAR_T)); + p += n; + } + if (dp->precision_start != dp->precision_end) + { + size_t n = dp->precision_end - dp->precision_start; + memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); + p += n; + } + + switch (type) + { +#ifdef HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: + *p++ = 'l'; + /*FALLTHROUGH*/ +#endif + case TYPE_LONGINT: + case TYPE_ULONGINT: +#ifdef HAVE_WINT_T + case TYPE_WIDE_CHAR: +#endif +#ifdef HAVE_WCHAR_T + case TYPE_WIDE_STRING: +#endif + *p++ = 'l'; + break; +#ifdef HAVE_LONG_DOUBLE + case TYPE_LONGDOUBLE: + *p++ = 'L'; + break; +#endif + default: + break; + } + *p = dp->conversion; +#if USE_SNPRINTF + p[1] = '%'; + p[2] = 'n'; + p[3] = '\0'; +#else + p[1] = '\0'; +#endif + + /* Construct the arguments for calling snprintf or sprintf. */ + prefix_count = 0; + if (dp->width_arg_index != ARG_NONE) + { + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; + } + if (dp->precision_arg_index != ARG_NONE) + { + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; + } + +#if USE_SNPRINTF + /* Prepare checking whether snprintf returns the count + via %n. */ + ENSURE_ALLOCATION (xsum (length, 1)); + result[length] = '\0'; +#endif + + for (;;) + { + size_t maxlen; + int count; + int retcount; + + maxlen = allocated - length; + count = -1; + retcount = 0; + +#if USE_SNPRINTF +# define SNPRINTF_BUF(arg) \ + switch (prefix_count) \ + { \ + case 0: \ + retcount = SNPRINTF (result + length, maxlen, buf, \ + arg, &count); \ + break; \ + case 1: \ + retcount = SNPRINTF (result + length, maxlen, buf, \ + prefixes[0], arg, &count); \ + break; \ + case 2: \ + retcount = SNPRINTF (result + length, maxlen, buf, \ + prefixes[0], prefixes[1], arg, \ + &count); \ + break; \ + default: \ + abort (); \ + } +#else +# define SNPRINTF_BUF(arg) \ + switch (prefix_count) \ + { \ + case 0: \ + count = sprintf (tmp, buf, arg); \ + break; \ + case 1: \ + count = sprintf (tmp, buf, prefixes[0], arg); \ + break; \ + case 2: \ + count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ + arg); \ + break; \ + default: \ + abort (); \ + } +#endif + + switch (type) + { + case TYPE_SCHAR: + { + int arg = a.arg[dp->arg_index].a.a_schar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UCHAR: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uchar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_SHORT: + { + int arg = a.arg[dp->arg_index].a.a_short; + SNPRINTF_BUF (arg); + } + break; + case TYPE_USHORT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_ushort; + SNPRINTF_BUF (arg); + } + break; + case TYPE_INT: + { + int arg = a.arg[dp->arg_index].a.a_int; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UINT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGINT: + { + long int arg = a.arg[dp->arg_index].a.a_longint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGINT: + { + unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; + SNPRINTF_BUF (arg); + } + break; +#ifdef HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + { + long long int arg = a.arg[dp->arg_index].a.a_longlongint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGLONGINT: + { + unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_DOUBLE: + { + double arg = a.arg[dp->arg_index].a.a_double; + SNPRINTF_BUF (arg); + } + break; +#ifdef HAVE_LONG_DOUBLE + case TYPE_LONGDOUBLE: + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_CHAR: + { + int arg = a.arg[dp->arg_index].a.a_char; + SNPRINTF_BUF (arg); + } + break; +#ifdef HAVE_WINT_T + case TYPE_WIDE_CHAR: + { + wint_t arg = a.arg[dp->arg_index].a.a_wide_char; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_STRING: + { + const char *arg = a.arg[dp->arg_index].a.a_string; + SNPRINTF_BUF (arg); + } + break; +#ifdef HAVE_WCHAR_T + case TYPE_WIDE_STRING: + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_POINTER: + { + void *arg = a.arg[dp->arg_index].a.a_pointer; + SNPRINTF_BUF (arg); + } + break; + default: + abort (); + } + +#if USE_SNPRINTF + /* Portability: Not all implementations of snprintf() + are ISO C 99 compliant. Determine the number of + bytes that snprintf() has produced or would have + produced. */ + if (count >= 0) + { + /* Verify that snprintf() has NUL-terminated its + result. */ + if (count < maxlen && result[length + count] != '\0') + abort (); + /* Portability hack. */ + if (retcount > count) + count = retcount; + } + else + { + /* snprintf() doesn't understand the '%n' + directive. */ + if (p[1] != '\0') + { + /* Don't use the '%n' directive; instead, look + at the snprintf() return value. */ + p[1] = '\0'; + continue; + } + else + { + /* Look at the snprintf() return value. */ + if (retcount < 0) + { + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. */ + size_t bigger_need = + xsum (xtimes (allocated, 2), 12); + ENSURE_ALLOCATION (bigger_need); + continue; + } + else + count = retcount; + } + } +#endif + + /* Attempt to handle failure. */ + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EINVAL; + return NULL; + } + +#if !USE_SNPRINTF + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); +#endif + + /* Make room for the result. */ + if (count >= maxlen) + { + /* Need at least count bytes. But allocate + proportionally, to avoid looping eternally if + snprintf() reports a too small count. */ + size_t n = + xmax (xsum (length, count), xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); +#if USE_SNPRINTF + continue; +#endif + } + +#if USE_SNPRINTF + /* The snprintf() result did fit. */ +#else + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (CHAR_T)); + if (tmp != tmpbuf) + free (tmp); +#endif + + length += count; + break; + } + } + } + } + + /* Add the final NUL. */ + ENSURE_ALLOCATION (xsum (length, 1)); + result[length] = '\0'; + + if (result != resultbuf && length + 1 < allocated) + { + /* Shrink the allocated memory if possible. */ + CHAR_T *memory; + + memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); + if (memory != NULL) + result = memory; + } + + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + *lengthp = length; + /* Note that we can produce a big string of a length > INT_MAX. POSIX + says that snprintf() fails with errno = EOVERFLOW in this case, but + that's only because snprintf() returns an 'int'. This function does + not have this limitation. */ + return result; + + out_of_memory: + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + out_of_memory_1: + CLEANUP (); + errno = ENOMEM; + return NULL; + } +} + +#undef SNPRINTF +#undef USE_SNPRINTF +#undef PRINTF_PARSE +#undef DIRECTIVES +#undef DIRECTIVE +#undef CHAR_T +#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 @@ +/* vsprintf with automatic memory allocation. + Copyright (C) 2002-2004 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _VASNPRINTF_H +#define _VASNPRINTF_H + +/* Get va_list. */ +#include + +/* Get size_t. */ +#include + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Write formatted output to a string dynamically allocated with malloc(). + You can pass a preallocated buffer for the result in RESULTBUF and its + size in *LENGTHP; otherwise you pass RESULTBUF = NULL. + If successful, return the address of the string (this may be = RESULTBUF + if no dynamic memory allocation was necessary) and set *LENGTHP to the + number of resulting bytes, excluding the trailing NUL. Upon error, set + errno and return NULL. + + When dynamic memory allocation occurs, the preallocated buffer is left + alone (with possibly modified contents). This makes it possible to use + a statically allocated or stack-allocated buffer, like this: + + char buf[100]; + size_t len = sizeof (buf); + char *output = vasnprintf (buf, &len, format, args); + if (output == NULL) + ... error handling ...; + else + { + ... use the output string ...; + if (output != buf) + free (output); + } + */ +extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) + __attribute__ ((__format__ (__printf__, 3, 4))); +extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) + __attribute__ ((__format__ (__printf__, 3, 0))); + +#ifdef __cplusplus +} +#endif + +#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 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "vasprintf.h" + +#include +#include +#include + +#include "vasnprintf.h" + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +int +vasprintf (char **resultp, const char *format, va_list args) +{ + size_t length; + char *result = vasnprintf (NULL, &length, format, args); + if (result == NULL) + return -1; + + if (length > INT_MAX) + { + free (result); + errno = EOVERFLOW; + return -1; + } + + *resultp = result; + /* Return the number of resulting bytes, excluding the trailing NUL. */ + return length; +} 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 @@ +/* vsprintf with automatic memory allocation. + Copyright (C) 2002-2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _VASPRINTF_H +#define _VASPRINTF_H + +#if HAVE_VASPRINTF + +/* Get asprintf(), vasprintf() declarations. */ +#include + +#else + +/* Get va_list. */ +#include + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Write formatted output to a string dynamically allocated with malloc(). + If the memory allocation succeeds, store the address of the string in + *RESULT and return the number of resulting bytes, excluding the trailing + NUL. Upon memory allocation error, or some other error, return -1. */ +extern int asprintf (char **result, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); +extern int vasprintf (char **result, const char *format, va_list args) + __attribute__ ((__format__ (__printf__, 2, 0))); + +#ifdef __cplusplus +} +#endif + +#endif + +#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 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Written by Simon Josefsson and Yoann Vandoorselaere . + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include "vsnprintf.h" + +#include +#include +#include +#include +#include +#include + +#include "vasnprintf.h" + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +/* Print formatted output to string STR. Similar to vsprintf, but + additional length SIZE limit how much is written into STR. Returns + string length of formatted string (which may be larger than SIZE). + STR may be NULL, in which case nothing will be written. On error, + return a negative value. */ +int +vsnprintf (char *str, size_t size, const char *format, va_list args) +{ + char *output; + size_t len; + size_t lenbuf = size; + + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > INT_MAX) + { + errno = EOVERFLOW; + return -1; + } + + return len; +} 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 @@ +/* Formatted output to strings. + Copyright (C) 2004 Free Software Foundation, Inc. + Written by Simon Josefsson and Yoann Vandoorselaere . + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef VSNPRINTF_H +#define VSNPRINTF_H + +#include + +/* Get vsnprintf declaration, if available. */ +#include + +#if defined HAVE_DECL_VSNPRINTF && !HAVE_DECL_VSNPRINTF +int vsnprintf (char *str, size_t size, const char *format, va_list args); +#endif + +#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 @@ +/* A substitute for ISO C99 , for platforms that have issues. + + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Eric Blake. */ + +/* + * ISO C 99 for platforms that have issues. + * + * + * For now, this just ensures proper prerequisite inclusion order. + */ + +#ifndef _GL_WCHAR_H +#define _GL_WCHAR_H + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include + +/* Include the original . */ +#include @ABSOLUTE_WCHAR_H@ + +#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 @@ +/* A substitute for ISO C99 , for platforms that lack it. + + Copyright (C) 2006, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible and Paul Eggert. */ + +/* + * ISO C 99 for platforms that lack it. + * + * + * iswctype, towctrans, towlower, towupper, wctrans, wctype, + * wctrans_t, and wctype_t are not yet implemented. + */ + +#ifndef _GL_WCTYPE_H +#define _GL_WCTYPE_H + +#if @HAVE_WINT_T@ +/* Solaris 2.5 has a bug: must be included before . + Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +# include +# include +# include +# include +typedef wint_t __wctype_wint_t; +#else +typedef int __wctype_wint_t; +#endif + +/* Include the original if it exists. + BeOS 5 has the functions but no . */ +#if @HAVE_WCTYPE_H@ +# include @ABSOLUTE_WCTYPE_H@ +#endif + +/* FreeBSD 4.4 to 4.11 has but lacks the functions. + Assume all 12 functions are implemented the same way, or not at all. */ +#if ! HAVE_ISWCNTRL + +/* IRIX 5.3 has macros but no functions, its isw* macros refer to an + undefined variable _ctmp_ and to macros like _P, and they + refer to system functions like _iswctype that are not in the + standard C library. Rather than try to get ancient buggy + implementations like this to work, just disable them. */ +# undef iswalnum +# undef iswalpha +# undef iswblank +# undef iswcntrl +# undef iswdigit +# undef iswgraph +# undef iswlower +# undef iswprint +# undef iswpunct +# undef iswspace +# undef iswupper +# undef iswxdigit + +static inline int +iswalnum (__wctype_wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); +} + +static inline int +iswalpha (__wctype_wint_t wc) +{ + return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; +} + +static inline int +iswblank (__wctype_wint_t wc) +{ + return wc == ' ' || wc == '\t'; +} + +static inline int +iswcntrl (__wctype_wint_t wc) +{ + return (wc & ~0x1f) == 0 || wc == 0x7f; +} + +static inline int +iswdigit (__wctype_wint_t wc) +{ + return wc >= '0' && wc <= '9'; +} + +static inline int +iswgraph (__wctype_wint_t wc) +{ + return wc >= '!' && wc <= '~'; +} + +static inline int +iswlower (__wctype_wint_t wc) +{ + return wc >= 'a' && wc <= 'z'; +} + +static inline int +iswprint (__wctype_wint_t wc) +{ + return wc >= ' ' && wc <= '~'; +} + +static inline int +iswpunct (__wctype_wint_t wc) +{ + return (wc >= '!' && wc <= '~' + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); +} + +static inline int +iswspace (__wctype_wint_t wc) +{ + return (wc == ' ' || wc == '\t' + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); +} + +static inline int +iswupper (__wctype_wint_t wc) +{ + return wc >= 'A' && wc <= 'Z'; +} + +static inline int +iswxdigit (__wctype_wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); +} + +# endif /* ! HAVE_ISWCNTRL */ + +#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 @@ +/* Determine the number of screen columns needed for a character. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _gl_WCWIDTH_H +#define _gl_WCWIDTH_H + +#if HAVE_WCHAR_T + +/* Get wcwidth if available, along with wchar_t. */ +# include + +/* Get iswprint. */ +# include + +# ifndef HAVE_DECL_WCWIDTH +"this configure-time declaration test was not run" +# endif +# ifndef wcwidth +# if !HAVE_WCWIDTH + +/* wcwidth doesn't exist, so assume all printable characters have + width 1. */ +static inline int +wcwidth (wchar_t wc) +{ + return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; +} + +# elif !HAVE_DECL_WCWIDTH + +/* wcwidth exists but is not declared. */ +extern +# ifdef __cplusplus +"C" +# endif +int wcwidth (int /* actually wchar_t */); + +# endif +# endif + +#endif /* HAVE_WCHAR_T */ + +#endif /* _gl_WCWIDTH_H */ diff --git a/lib/xalloc-die.c b/gl/xalloc-die.c similarity index 90% rename from lib/xalloc-die.c rename to gl/xalloc-die.c index ff5ac9e..090f060 100644 --- a/lib/xalloc-die.c +++ b/gl/xalloc-die.c @@ -1,6 +1,6 @@ /* Report a memory allocation failure and exit. - Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free + Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -17,9 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "xalloc.h" @@ -30,7 +28,6 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -#define N_(msgid) msgid void 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 @@ +/* xalloc.h -- malloc with out-of-memory checking + + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef XALLOC_H_ +# define XALLOC_H_ + +# include + + +# ifdef __cplusplus +extern "C" { +# endif + + +# ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ +# define __attribute__(x) +# endif +# endif + +# ifndef ATTRIBUTE_NORETURN +# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) +# endif + +/* This function is always triggered when memory is exhausted. + It must be defined by the application, either explicitly + or by using gnulib's xalloc-die module. This is the + function to call when one wants the program to die because of a + memory allocation failure. */ +extern void xalloc_die (void) ATTRIBUTE_NORETURN; + +void *xmalloc (size_t s); +void *xzalloc (size_t s); +void *xcalloc (size_t n, size_t s); +void *xrealloc (void *p, size_t s); +void *x2realloc (void *p, size_t *pn); +void *xmemdup (void const *p, size_t s); +char *xstrdup (char const *str); + +/* Return 1 if an array of N objects, each of size S, cannot exist due + to size arithmetic overflow. S must be positive and N must be + nonnegative. This is a macro, not an inline function, so that it + works correctly even when SIZE_MAX < N. + + By gnulib convention, SIZE_MAX represents overflow in size + calculations, so the conservative dividend to use here is + SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. + However, malloc (SIZE_MAX) fails on all known hosts where + sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for + exactly-SIZE_MAX allocations on such hosts; this avoids a test and + branch when S is known to be 1. */ +# define xalloc_oversized(n, s) \ + ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) + + +/* In the following macros, T must be an elementary or structure/union or + typedef'ed type, or a pointer to such a type. To apply one of the + following macros to a function pointer or array type, you need to typedef + it first and use the typedef name. */ + +/* Allocate an object of type T dynamically, with error checking. */ +/* extern t *XMALLOC (typename t); */ +# define XMALLOC(t) ((t *) xmalloc (sizeof (t))) + +/* Allocate memory for N elements of type T, with error checking. */ +/* extern t *XNMALLOC (size_t n, typename t); */ +# define XNMALLOC(n, t) \ + ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) + +/* Allocate an object of type T dynamically, with error checking, + and zero it. */ +/* extern t *XZALLOC (typename t); */ +# define XZALLOC(t) ((t *) xzalloc (sizeof (t))) + +/* Allocate memory for N elements of type T, with error checking, + and zero it. */ +/* extern t *XCALLOC (size_t n, typename t); */ +# define XCALLOC(n, t) \ + ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) + + +# if HAVE_INLINE +# define static_inline static inline +# else + void *xnmalloc (size_t n, size_t s); + void *xnrealloc (void *p, size_t n, size_t s); + void *x2nrealloc (void *p, size_t *pn, size_t s); + char *xcharalloc (size_t n); +# endif + +# ifdef static_inline + +/* Allocate an array of N objects, each with S bytes of memory, + dynamically, with error checking. S must be nonzero. */ + +static_inline void * +xnmalloc (size_t n, size_t s) +{ + if (xalloc_oversized (n, s)) + xalloc_die (); + return xmalloc (n * s); +} + +/* Change the size of an allocated block of memory P to an array of N + objects each of S bytes, with error checking. S must be nonzero. */ + +static_inline void * +xnrealloc (void *p, size_t n, size_t s) +{ + if (xalloc_oversized (n, s)) + xalloc_die (); + return xrealloc (p, n * s); +} + +/* If P is null, allocate a block of at least *PN such objects; + otherwise, reallocate P so that it contains more than *PN objects + each of S bytes. *PN must be nonzero unless P is null, and S must + be nonzero. Set *PN to the new number of objects, and return the + pointer to the new block. *PN is never set to zero, and the + returned pointer is never null. + + Repeated reallocations are guaranteed to make progress, either by + allocating an initial block with a nonzero size, or by allocating a + larger block. + + In the following implementation, nonzero sizes are doubled so that + repeated reallocations have O(N log N) overall cost rather than + O(N**2) cost, but the specification for this function does not + guarantee that sizes are doubled. + + Here is an example of use: + + int *p = NULL; + size_t used = 0; + size_t allocated = 0; + + void + append_int (int value) + { + if (used == allocated) + p = x2nrealloc (p, &allocated, sizeof *p); + p[used++] = value; + } + + This causes x2nrealloc to allocate a block of some nonzero size the + first time it is called. + + To have finer-grained control over the initial size, set *PN to a + nonzero value before calling this function with P == NULL. For + example: + + int *p = NULL; + size_t used = 0; + size_t allocated = 0; + size_t allocated1 = 1000; + + void + append_int (int value) + { + if (used == allocated) + { + p = x2nrealloc (p, &allocated1, sizeof *p); + allocated = allocated1; + } + p[used++] = value; + } + + */ + +static_inline void * +x2nrealloc (void *p, size_t *pn, size_t s) +{ + size_t n = *pn; + + if (! p) + { + if (! n) + { + /* The approximate size to use for initial small allocation + requests, when the invoking code specifies an old size of + zero. 64 bytes is the largest "small" request for the + GNU C library malloc. */ + enum { DEFAULT_MXFAST = 64 }; + + n = DEFAULT_MXFAST / s; + n += !n; + } + } + else + { + if (((size_t) -1) / 2 / s < n) + xalloc_die (); + n *= 2; + } + + *pn = n; + return xrealloc (p, n * s); +} + +/* Return a pointer to a new buffer of N bytes. This is like xmalloc, + except it returns char *. */ + +static_inline char * +xcharalloc (size_t n) +{ + return XNMALLOC (n, char); +} + +# endif + +# ifdef __cplusplus +} + +/* C++ does not allow conversions from void * to other pointer types + without a cast. Use templates to work around the problem when + possible. */ + +template inline T * +xrealloc (T *p, size_t s) +{ + return (T *) xrealloc ((void *) p, s); +} + +template inline T * +xnrealloc (T *p, size_t n, size_t s) +{ + return (T *) xnrealloc ((void *) p, n, s); +} + +template inline T * +x2realloc (T *p, size_t *pn) +{ + return (T *) x2realloc ((void *) p, pn); +} + +template inline T * +x2nrealloc (T *p, size_t *pn, size_t s) +{ + return (T *) x2nrealloc ((void *) p, pn, s); +} + +template inline T * +xmemdup (T const *p, size_t s) +{ + return (T *) xmemdup ((void const *) p, s); +} + +# endif + + +#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 @@ +/* xmalloc.c -- malloc with out of memory checking + + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, + Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#if ! HAVE_INLINE +# define static_inline +#endif +#include "xalloc.h" +#undef static_inline + +#include +#include + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +/* 1 if calloc is known to be compatible with GNU calloc. This + matters if we are not also using the calloc module, which defines + HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ +#if defined HAVE_CALLOC || defined __GLIBC__ +enum { HAVE_GNU_CALLOC = 1 }; +#else +enum { HAVE_GNU_CALLOC = 0 }; +#endif + +/* Allocate N bytes of memory dynamically, with error checking. */ + +void * +xmalloc (size_t n) +{ + void *p = malloc (n); + if (!p && n != 0) + xalloc_die (); + return p; +} + +/* Change the size of an allocated block of memory P to N bytes, + with error checking. */ + +void * +xrealloc (void *p, size_t n) +{ + p = realloc (p, n); + if (!p && n != 0) + xalloc_die (); + return p; +} + +/* If P is null, allocate a block of at least *PN bytes; otherwise, + reallocate P so that it contains more than *PN bytes. *PN must be + nonzero unless P is null. Set *PN to the new block's size, and + return the pointer to the new block. *PN is never set to zero, and + the returned pointer is never null. */ + +void * +x2realloc (void *p, size_t *pn) +{ + return x2nrealloc (p, pn, 1); +} + +/* Allocate S bytes of zeroed memory dynamically, with error checking. + There's no need for xnzalloc (N, S), since it would be equivalent + to xcalloc (N, S). */ + +void * +xzalloc (size_t s) +{ + return memset (xmalloc (s), 0, s); +} + +/* Allocate zeroed memory for N elements of S bytes, with error + checking. S must be nonzero. */ + +void * +xcalloc (size_t n, size_t s) +{ + void *p; + /* Test for overflow, since some calloc implementations don't have + proper overflow checks. But omit overflow and size-zero tests if + HAVE_GNU_CALLOC, since GNU calloc catches overflow and never + returns NULL if successful. */ + if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) + || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) + xalloc_die (); + return p; +} + +/* Clone an object P of size S, with error checking. There's no need + for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any + need for an arithmetic overflow check. */ + +void * +xmemdup (void const *p, size_t s) +{ + return memcpy (xmalloc (s), p, s); +} + +/* Clone STRING. */ + +char * +xstrdup (char const *string) +{ + return xmemdup (string, strlen (string) + 1); +} 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 @@ +/* xsize.h -- Checked size_t computations. + + Copyright (C) 2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _XSIZE_H +#define _XSIZE_H + +/* Get size_t. */ +#include + +/* Get SIZE_MAX. */ +#include +#if HAVE_STDINT_H +# include +#endif + +/* The size of memory objects is often computed through expressions of + type size_t. Example: + void* p = malloc (header_size + n * element_size). + These computations can lead to overflow. When this happens, malloc() + returns a piece of memory that is way too small, and the program then + crashes while attempting to fill the memory. + To avoid this, the functions and macros in this file check for overflow. + The convention is that SIZE_MAX represents overflow. + malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc + implementation that uses mmap --, it's recommended to use size_overflow_p() + or size_in_bounds_p() before invoking malloc(). + The example thus becomes: + size_t size = xsum (header_size, xtimes (n, element_size)); + void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); +*/ + +/* Convert an arbitrary value >= 0 to type size_t. */ +#define xcast_size_t(N) \ + ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) + +/* Sum of two sizes, with overflow check. */ +static inline size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum (size_t size1, size_t size2) +{ + size_t sum = size1 + size2; + return (sum >= size1 ? sum : SIZE_MAX); +} + +/* Sum of three sizes, with overflow check. */ +static inline size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum3 (size_t size1, size_t size2, size_t size3) +{ + return xsum (xsum (size1, size2), size3); +} + +/* Sum of four sizes, with overflow check. */ +static inline size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) +{ + return xsum (xsum (xsum (size1, size2), size3), size4); +} + +/* Maximum of two sizes, with overflow check. */ +static inline size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xmax (size_t size1, size_t size2) +{ + /* No explicit check is needed here, because for any n: + max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ + return (size1 >= size2 ? size1 : size2); +} + +/* Multiplication of a count with an element size, with overflow check. + The count must be >= 0 and the element size must be > 0. + This is a macro, not an inline function, so that it works correctly even + when N is of a wider tupe and N > SIZE_MAX. */ +#define xtimes(N, ELSIZE) \ + ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) + +/* Check for overflow. */ +#define size_overflow_p(SIZE) \ + ((SIZE) == SIZE_MAX) +/* Check against overflow. */ +#define size_in_bounds_p(SIZE) \ + ((SIZE) != SIZE_MAX) + +#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 @@ +/* Duplicate a bounded initial segment of a string, with out-of-memory + checking. + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "xstrndup.h" + +#include "strndup.h" +#include "xalloc.h" + +/* Return a newly allocated copy of at most N bytes of STRING. + In other words, return a copy of the initial segment of length N of + STRING. */ +char * +xstrndup (const char *string, size_t n) +{ + char *s = strndup (string, n); + if (! s) + xalloc_die (); + return s; +} 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 @@ +/* Duplicate a bounded initial segment of a string, with out-of-memory + checking. + Copyright (C) 2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Return a newly allocated copy of at most N bytes of STRING. + In other words, return a copy of the initial segment of length N of + STRING. */ +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 @@ SUBDIRS = tests -noinst_LIBRARIES = libcoreutils.a libnagiosplug.a +noinst_LIBRARIES = libnagiosplug.a -# Will auto pick up fsusage.c mountlist.c -libcoreutils_a_SOURCES = \ - cloexec.c cloexec.h \ - exit.h \ - full-read.c full-read.h \ - full-write.c full-write.h \ - gettext.h \ - safe-read.c safe-read.h \ - safe-write.c safe-write.h strcase.h xalloc-die.c -# intprops.h required for getloadavg.c -# This needs to be an EXTRA_DIST because the m4s -# that have AC_LIBSOURCES for intprops.h are not necessary and -# the getloadavg m4 is an autoconf one, so doesn't -# know about intprops.h. Confused? You will be! -EXTRA_DIST = intprops.h +libnagiosplug_a_SOURCES = utils_base.c utils_disk.c +EXTRA_DIST = utils_base.h utils_disk.h -other_coreutils_files = \ - error.c error.h \ - fsusage.c \ - getloadavg.c \ - malloc.c \ - mountlist.c \ - realloc.c \ - strtod.c \ - exitfail.c exitfail.h \ - fsusage.h \ - getopt.c getopt1.c \ - mountlist.h \ - unlocked-io.h \ - xalloc.h \ - xmalloc.c - - -libcoreutils_a_LIBADD = $(LIBOBJS) $(ALLOCA) -libcoreutils_a_DEPENDENCIES = $(libcoreutils_a_LIBADD) -lib_OBJECTS = $(libcoreutils_a_OBJECTS) - -libnagiosplug_a_SOURCES = snprintf.c utils_base.c utils_disk.c -EXTRA_DIST += utils_base.h utils_disk.h - -INCLUDES = -I$(srcdir) -I$(top_srcdir)/intl -I$(top_srcdir)/plugins - -print_coreutil_files: - @echo $(libcoreutils_a_SOURCES) $(other_coreutils_files) $(EXTRA_DIST) +INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins test: cd tests && make test -# Below are from coreutil's lib/Makefile.am -BUILT_SOURCES = $(STDBOOL_H) -EXTRA_DIST += stdbool_.h -MOSTLYCLEANFILES = stdbool.h stdbool.ht -# Create stdbool.h on systems that lack a working one. -stdbool.h: stdbool_.h - sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' $(srcdir)/stdbool_.h > $@t - mv $@t $@ - -BUILT_SOURCES += $(ALLOCA_H) -EXTRA_DIST += alloca_.h - -# We need the following in order to create an when the system -# doesn't have one that works with the given compiler -all-local $(lib_OBJECTS): $(ALLOCA_H) -alloca.h: alloca_.h - cp $(srcdir)/alloca_.h $@-t - mv $@-t $@ -MOSTLYCLEANFILES += alloca.h alloca.h-t - -BUILT_SOURCES += $(GETOPT_H) -EXTRA_DIST += getopt_.h getopt_int.h - -# We need the following in order to create an when the system -# doesn't have one that works with the given compiler. -all-local $(lib_OBJECTS): $(GETOPT_H) -getopt.h: getopt_.h - cp $(srcdir)/getopt_.h $@-t - mv $@-t $@ -MOSTLYCLEANFILES += getopt.h getopt.h-t - 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 @@ -/* basename.c -- return the last element in a file name - - Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free - Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "dirname.h" -#include - -/* In general, we can't use the builtin `basename' function if available, - since it has different meanings in different environments. - In some environments the builtin `basename' modifies its argument. - - Return the address of the last file name component of NAME. If - NAME has no file name components because it is all slashes, return - NAME if it is empty, the address of its last slash otherwise. */ - -char * -base_name (char const *name) -{ - char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); - char const *p; - - for (p = base; *p; p++) - { - if (ISSLASH (*p)) - { - /* Treat multiple adjacent slashes like a single slash. */ - do p++; - while (ISSLASH (*p)); - - /* If the file name ends in slash, use the trailing slash as - the basename if no non-slashes have been found. */ - if (! *p) - { - if (ISSLASH (*base)) - base = p - 1; - break; - } - - /* *P is a non-slash preceded by a slash. */ - base = p; - } - } - - return (char *) base; -} - -/* Return the length of of the basename NAME. Typically NAME is the - value returned by base_name. Act like strlen (NAME), except omit - redundant trailing slashes. */ - -size_t -base_len (char const *name) -{ - size_t len; - - for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) - continue; - - return len; -} 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 @@ -#define LONG 1 -#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 @@ -/* Convenience header for conditional use of GNU . - Copyright (C) 1995-1998, 2000-2002, 2004 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _LIBGETTEXT_H -#define _LIBGETTEXT_H 1 - -/* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS - -/* Get declarations of GNU message catalog functions. */ -# include - -#else - -/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which - chokes if dcgettext is defined as a macro. So include it now, to make - later inclusions of a NOP. We don't include - as well because people using "gettext.h" will not include , - and also including would fail on SunOS 4, whereas - is OK. */ -#if defined(__sun) -# include -#endif - -/* Many header files from the libstdc++ coming with g++ 3.3 or newer include - , which chokes if dcgettext is defined as a macro. So include - it now, to make later inclusions of a NOP. */ -#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) -# include -# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H -# include -# endif -#endif - -/* Disabled NLS. - The casts to 'const char *' serve the purpose of producing warnings - for invalid uses of the value returned from these functions. - On pre-ANSI systems without 'const', the config.h file is supposed to - contain "#define const". */ -# define gettext(Msgid) ((const char *) (Msgid)) -# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) -# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) -# define ngettext(Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define textdomain(Domainname) ((const char *) (Domainname)) -# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) -# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) - -#endif - -/* A pseudo function call that serves as a marker for the automated - extraction of messages, but does not call gettext(). The run-time - translation is done at a different place in the code. - The argument, String, should be a literal string. Concatenated strings - and other string expressions won't work. - The macro's expansion is not parenthesized, so that it is suitable as - initializer for static 'char[]' or 'const char[]' variables. */ -#define gettext_noop(String) String - -#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 @@ -/* realloc() function that is glibc compatible. - Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* written by Jim Meyering */ - -#ifdef HAVE_CONFIG_H -# include -#endif -#undef realloc - -#include - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. If N is zero, change it to 1. If P is NULL, - use malloc. */ - -void * -rpl_realloc (void *p, size_t n) -{ - if (n == 0) - { - n = 1; - - /* In theory realloc might fail, so don't rely on it to free. */ - free (p); - p = NULL; - } - - if (p == NULL) - return malloc (n); - return realloc (p, n); -} 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 @@ -/* - * NOTE: If you change this file, please merge it into rsync, samba, etc. - */ - -/* - * Copyright Patrick Powell 1995 - * This code is based on code written by Patrick Powell (papowell@astart.com) - * It may be used for any purpose as long as this notice remains intact - * on all source code distributions - */ - -/************************************************************** - * Original: - * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 - * A bombproof version of doprnt (dopr) included. - * Sigh. This sort of thing is always nasty do deal with. Note that - * the version here does not include floating point... - * - * snprintf() is used instead of sprintf() as it does limit checks - * for string length. This covers a nasty loophole. - * - * The other functions are there to prevent NULL pointers from - * causing nast effects. - * - * More Recently: - * Brandon Long 9/15/96 for mutt 0.43 - * This was ugly. It is still ugly. I opted out of floating point - * numbers, but the formatter understands just about everything - * from the normal C string format, at least as far as I can tell from - * the Solaris 2.5 printf(3S) man page. - * - * Brandon Long 10/22/97 for mutt 0.87.1 - * Ok, added some minimal floating point support, which means this - * probably requires libm on most operating systems. Don't yet - * support the exponent (e,E) and sigfig (g,G). Also, fmtint() - * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code - * to mutt conventions, and removed dead code left over from the - * original. Also, there is now a builtin-test, just compile with: - * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm - * and run snprintf for results. - * - * Thomas Roessler 01/27/98 for mutt 0.89i - * The PGP code was using unsigned hexadecimal formats. - * Unfortunately, unsigned formats simply didn't work. - * - * Michael Elkins 03/05/98 for mutt 0.90.8 - * The original code assumed that both snprintf() and vsnprintf() were - * missing. Some systems only have snprintf() but not vsnprintf(), so - * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. - * - * Andrew Tridgell (tridge@samba.org) Oct 1998 - * fixed handling of %.0f - * added test for HAVE_LONG_DOUBLE - * - * tridge@samba.org, idra@samba.org, April 2001 - * got rid of fcvt code (twas buggy and made testing harder) - * added C99 semantics - * - * date: 2002/12/19 19:56:31; author: herb; state: Exp; lines: +2 -0 - * actually print args for %g and %e - * - * date: 2002/06/03 13:37:52; author: jmcd; state: Exp; lines: +8 -0 - * Since includes.h isn't included here, VA_COPY has to be defined here. I don't - * see any include file that is guaranteed to be here, so I'm defining it - * locally. Fixes AIX and Solaris builds. - * - * date: 2002/06/03 03:07:24; author: tridge; state: Exp; lines: +5 -13 - * put the ifdef for HAVE_VA_COPY in one place rather than in lots of - * functions - * - * date: 2002/05/17 14:51:22; author: jmcd; state: Exp; lines: +21 -4 - * Fix usage of va_list passed as an arg. Use __va_copy before using it - * when it exists. - * - * date: 2002/04/16 22:38:04; author: idra; state: Exp; lines: +20 -14 - * Fix incorrect zpadlen handling in fmtfp. - * Thanks to Ollie Oldham for spotting it. - * few mods to make it easier to compile the tests. - * addedd the "Ollie" test to the floating point ones. - * - * Martin Pool (mbp@samba.org) April 2003 - * Remove NO_CONFIG_H so that the test case can be built within a source - * tree with less trouble. - * Remove unnecessary SAFE_FREE() definition. - * - * Martin Pool (mbp@samba.org) May 2003 - * Put in a prototype for dummy_snprintf() to quiet compiler warnings. - * - * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even - * if the C library has some snprintf functions already. - **************************************************************/ - -#ifndef NO_CONFIG_H -#include "config.h" -#else -#define NULL 0 -#endif - -#ifdef TEST_SNPRINTF /* need math library headers for testing */ - -/* In test mode, we pretend that this system doesn't have any snprintf - * functions, regardless of what config.h says. */ -# undef HAVE_SNPRINTF -# undef HAVE_VSNPRINTF -# undef HAVE_C99_VSNPRINTF -# undef HAVE_ASPRINTF -# undef HAVE_VASPRINTF -# include -#endif /* TEST_SNPRINTF */ - -#ifdef HAVE_STRING_H -#include -#endif - -#ifdef HAVE_STRINGS_H -#include -#endif -#ifdef HAVE_CTYPE_H -#include -#endif -#include -#include -#ifdef HAVE_STDLIB_H -#include -#endif - -#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF) -/* only include stdio.h if we are not re-defining snprintf or vsnprintf */ -#include - /* make the compiler happy with an empty file */ - void dummy_snprintf(void); - void dummy_snprintf(void) {} -#endif /* HAVE_SNPRINTF, etc */ - -#ifdef HAVE_LONG_DOUBLE -#define LDOUBLE long double -#else -#define LDOUBLE double -#endif - -#ifdef HAVE_LONG_LONG -#define LLONG long long -#else -#define LLONG long -#endif - -#ifndef VA_COPY -#ifdef HAVE_VA_COPY -#define VA_COPY(dest, src) va_copy(dest, src) -#else -#ifdef HAVE___VA_COPY -#define VA_COPY(dest, src) __va_copy(dest, src) -#else -#define VA_COPY(dest, src) (dest) = (src) -#endif -#endif - -/* - * dopr(): poor man's version of doprintf - */ - -/* format read states */ -#define DP_S_DEFAULT 0 -#define DP_S_FLAGS 1 -#define DP_S_MIN 2 -#define DP_S_DOT 3 -#define DP_S_MAX 4 -#define DP_S_MOD 5 -#define DP_S_CONV 6 -#define DP_S_DONE 7 - -/* format flags - Bits */ -#define DP_F_MINUS (1 << 0) -#define DP_F_PLUS (1 << 1) -#define DP_F_SPACE (1 << 2) -#define DP_F_NUM (1 << 3) -#define DP_F_ZERO (1 << 4) -#define DP_F_UP (1 << 5) -#define DP_F_UNSIGNED (1 << 6) - -/* Conversion Flags */ -#define DP_C_SHORT 1 -#define DP_C_LONG 2 -#define DP_C_LDOUBLE 3 -#define DP_C_LLONG 4 - -#define char_to_int(p) ((p)- '0') -#ifndef MAX -#define MAX(p,q) (((p) >= (q)) ? (p) : (q)) -#endif - -/* yes this really must be a ||. Don't muck with this (tridge) */ -#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - -static size_t dopr(char *buffer, size_t maxlen, const char *format, - va_list args_in); -static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max); -static void fmtint(char *buffer, size_t *currlen, size_t maxlen, - long value, int base, int min, int max, int flags); -static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, - LDOUBLE fvalue, int min, int max, int flags); -static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); - -static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) -{ - char ch; - LLONG value; - LDOUBLE fvalue; - char *strvalue; - int min; - int max; - int state; - int flags; - int cflags; - size_t currlen; - va_list args; - - VA_COPY(args, args_in); - - state = DP_S_DEFAULT; - currlen = flags = cflags = min = 0; - max = -1; - ch = *format++; - - while (state != DP_S_DONE) { - if (ch == '\0') - state = DP_S_DONE; - - switch(state) { - case DP_S_DEFAULT: - if (ch == '%') - state = DP_S_FLAGS; - else - dopr_outch (buffer, &currlen, maxlen, ch); - ch = *format++; - break; - case DP_S_FLAGS: - switch (ch) { - case '-': - flags |= DP_F_MINUS; - ch = *format++; - break; - case '+': - flags |= DP_F_PLUS; - ch = *format++; - break; - case ' ': - flags |= DP_F_SPACE; - ch = *format++; - break; - case '#': - flags |= DP_F_NUM; - ch = *format++; - break; - case '0': - flags |= DP_F_ZERO; - ch = *format++; - break; - default: - state = DP_S_MIN; - break; - } - break; - case DP_S_MIN: - if (isdigit((unsigned char)ch)) { - min = 10*min + char_to_int (ch); - ch = *format++; - } else if (ch == '*') { - min = va_arg (args, int); - ch = *format++; - state = DP_S_DOT; - } else { - state = DP_S_DOT; - } - break; - case DP_S_DOT: - if (ch == '.') { - state = DP_S_MAX; - ch = *format++; - } else { - state = DP_S_MOD; - } - break; - case DP_S_MAX: - if (isdigit((unsigned char)ch)) { - if (max < 0) - max = 0; - max = 10*max + char_to_int (ch); - ch = *format++; - } else if (ch == '*') { - max = va_arg (args, int); - ch = *format++; - state = DP_S_MOD; - } else { - state = DP_S_MOD; - } - break; - case DP_S_MOD: - switch (ch) { - case 'h': - cflags = DP_C_SHORT; - ch = *format++; - break; - case 'l': - cflags = DP_C_LONG; - ch = *format++; - if (ch == 'l') { /* It's a long long */ - cflags = DP_C_LLONG; - ch = *format++; - } - break; - case 'L': - cflags = DP_C_LDOUBLE; - ch = *format++; - break; - default: - break; - } - state = DP_S_CONV; - break; - case DP_S_CONV: - switch (ch) { - case 'd': - case 'i': - if (cflags == DP_C_SHORT) - value = va_arg (args, int); - else if (cflags == DP_C_LONG) - value = va_arg (args, long int); - else if (cflags == DP_C_LLONG) - value = va_arg (args, LLONG); - else - value = va_arg (args, int); - fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); - break; - case 'o': - flags |= DP_F_UNSIGNED; - if (cflags == DP_C_SHORT) - value = va_arg (args, unsigned int); - else if (cflags == DP_C_LONG) - value = (long)va_arg (args, unsigned long int); - else if (cflags == DP_C_LLONG) - value = (long)va_arg (args, unsigned LLONG); - else - value = (long)va_arg (args, unsigned int); - fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags); - break; - case 'u': - flags |= DP_F_UNSIGNED; - if (cflags == DP_C_SHORT) - value = va_arg (args, unsigned int); - else if (cflags == DP_C_LONG) - value = (long)va_arg (args, unsigned long int); - else if (cflags == DP_C_LLONG) - value = (LLONG)va_arg (args, unsigned LLONG); - else - value = (long)va_arg (args, unsigned int); - fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); - break; - case 'X': - flags |= DP_F_UP; - case 'x': - flags |= DP_F_UNSIGNED; - if (cflags == DP_C_SHORT) - value = va_arg (args, unsigned int); - else if (cflags == DP_C_LONG) - value = (long)va_arg (args, unsigned long int); - else if (cflags == DP_C_LLONG) - value = (LLONG)va_arg (args, unsigned LLONG); - else - value = (long)va_arg (args, unsigned int); - fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags); - break; - case 'f': - if (cflags == DP_C_LDOUBLE) - fvalue = va_arg (args, LDOUBLE); - else - fvalue = va_arg (args, double); - /* um, floating point? */ - fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); - break; - case 'E': - flags |= DP_F_UP; - case 'e': - if (cflags == DP_C_LDOUBLE) - fvalue = va_arg (args, LDOUBLE); - else - fvalue = va_arg (args, double); - fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); - break; - case 'G': - flags |= DP_F_UP; - case 'g': - if (cflags == DP_C_LDOUBLE) - fvalue = va_arg (args, LDOUBLE); - else - fvalue = va_arg (args, double); - fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); - break; - case 'c': - dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); - break; - case 's': - strvalue = va_arg (args, char *); - if (!strvalue) strvalue = "(NULL)"; - if (max == -1) { - max = strlen(strvalue); - } - if (min > 0 && max >= 0 && min > max) max = min; - fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max); - break; - case 'p': - strvalue = va_arg (args, void *); - fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags); - break; - case 'n': - if (cflags == DP_C_SHORT) { - short int *num; - num = va_arg (args, short int *); - *num = currlen; - } else if (cflags == DP_C_LONG) { - long int *num; - num = va_arg (args, long int *); - *num = (long int)currlen; - } else if (cflags == DP_C_LLONG) { - LLONG *num; - num = va_arg (args, LLONG *); - *num = (LLONG)currlen; - } else { - int *num; - num = va_arg (args, int *); - *num = currlen; - } - break; - case '%': - dopr_outch (buffer, &currlen, maxlen, ch); - break; - case 'w': - /* not supported yet, treat as next char */ - ch = *format++; - break; - default: - /* Unknown, skip */ - break; - } - ch = *format++; - state = DP_S_DEFAULT; - flags = cflags = min = 0; - max = -1; - break; - case DP_S_DONE: - break; - default: - /* hmm? */ - break; /* some picky compilers need this */ - } - } - if (maxlen != 0) { - if (currlen < maxlen - 1) - buffer[currlen] = '\0'; - else if (maxlen > 0) - buffer[maxlen - 1] = '\0'; - } - - return currlen; -} - -static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max) -{ - int padlen, strln; /* amount to pad */ - int cnt = 0; - -#ifdef DEBUG_SNPRINTF - printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value); -#endif - if (value == 0) { - value = ""; - } - - for (strln = 0; value[strln]; ++strln); /* strlen */ - padlen = min - strln; - if (padlen < 0) - padlen = 0; - if (flags & DP_F_MINUS) - padlen = -padlen; /* Left Justify */ - - while ((padlen > 0) && (cnt < max)) { - dopr_outch (buffer, currlen, maxlen, ' '); - --padlen; - ++cnt; - } - while (*value && (cnt < max)) { - dopr_outch (buffer, currlen, maxlen, *value++); - ++cnt; - } - while ((padlen < 0) && (cnt < max)) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++padlen; - ++cnt; - } -} - -/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ - -static void fmtint(char *buffer, size_t *currlen, size_t maxlen, - long value, int base, int min, int max, int flags) -{ - int signvalue = 0; - unsigned long uvalue; - char convert[20]; - int place = 0; - int spadlen = 0; /* amount to space pad */ - int zpadlen = 0; /* amount to zero pad */ - int caps = 0; - - if (max < 0) - max = 0; - - uvalue = value; - - if(!(flags & DP_F_UNSIGNED)) { - if( value < 0 ) { - signvalue = '-'; - uvalue = -value; - } else { - if (flags & DP_F_PLUS) /* Do a sign (+/i) */ - signvalue = '+'; - else if (flags & DP_F_SPACE) - signvalue = ' '; - } - } - - if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ - - do { - convert[place++] = - (caps? "0123456789ABCDEF":"0123456789abcdef") - [uvalue % (unsigned)base ]; - uvalue = (uvalue / (unsigned)base ); - } while(uvalue && (place < 20)); - if (place == 20) place--; - convert[place] = 0; - - zpadlen = max - place; - spadlen = min - MAX (max, place) - (signvalue ? 1 : 0); - if (zpadlen < 0) zpadlen = 0; - if (spadlen < 0) spadlen = 0; - if (flags & DP_F_ZERO) { - zpadlen = MAX(zpadlen, spadlen); - spadlen = 0; - } - if (flags & DP_F_MINUS) - spadlen = -spadlen; /* Left Justifty */ - -#ifdef DEBUG_SNPRINTF - printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", - zpadlen, spadlen, min, max, place); -#endif - - /* Spaces */ - while (spadlen > 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - --spadlen; - } - - /* Sign */ - if (signvalue) - dopr_outch (buffer, currlen, maxlen, signvalue); - - /* Zeros */ - if (zpadlen > 0) { - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } - } - - /* Digits */ - while (place > 0) - dopr_outch (buffer, currlen, maxlen, convert[--place]); - - /* Left Justified spaces */ - while (spadlen < 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++spadlen; - } -} - -static LDOUBLE abs_val(LDOUBLE value) -{ - LDOUBLE result = value; - - if (value < 0) - result = -value; - - return result; -} - -static LDOUBLE POW10(int exp) -{ - LDOUBLE result = 1; - - while (exp) { - result *= 10; - exp--; - } - - return result; -} - -static LLONG ROUND(LDOUBLE value) -{ - LLONG intpart; - - intpart = (LLONG)value; - value = value - intpart; - if (value >= 0.5) intpart++; - - return intpart; -} - -/* a replacement for modf that doesn't need the math library. Should - be portable, but slow */ -static double my_modf(double x0, double *iptr) -{ - int i; - long l; - double x = x0; - double f = 1.0; - - for (i=0;i<100;i++) { - l = (long)x; - if (l <= (x+1) && l >= (x-1)) break; - x *= 0.1; - f *= 10.0; - } - - if (i == 100) { - /* yikes! the number is beyond what we can handle. What do we do? */ - (*iptr) = 0; - return 0; - } - - if (i != 0) { - double i2; - double ret; - - ret = my_modf(x0-l*f, &i2); - (*iptr) = l*f + i2; - return ret; - } - - (*iptr) = l; - return x - (*iptr); -} - - -static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, - LDOUBLE fvalue, int min, int max, int flags) -{ - int signvalue = 0; - double ufvalue; - char iconvert[311]; - char fconvert[311]; - int iplace = 0; - int fplace = 0; - int padlen = 0; /* amount to pad */ - int zpadlen = 0; - int caps = 0; - int idx; - double intpart; - double fracpart; - double temp; - - /* - * AIX manpage says the default is 0, but Solaris says the default - * is 6, and sprintf on AIX defaults to 6 - */ - if (max < 0) - max = 6; - - ufvalue = abs_val (fvalue); - - if (fvalue < 0) { - signvalue = '-'; - } else { - if (flags & DP_F_PLUS) { /* Do a sign (+/i) */ - signvalue = '+'; - } else { - if (flags & DP_F_SPACE) - signvalue = ' '; - } - } - -#if 0 - if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ -#endif - -#if 0 - if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */ -#endif - - /* - * Sorry, we only support 16 digits past the decimal because of our - * conversion method - */ - if (max > 16) - max = 16; - - /* We "cheat" by converting the fractional part to integer by - * multiplying by a factor of 10 - */ - - temp = ufvalue; - my_modf(temp, &intpart); - - fracpart = ROUND((POW10(max)) * (ufvalue - intpart)); - - if (fracpart >= POW10(max)) { - intpart++; - fracpart -= POW10(max); - } - - - /* Convert integer part */ - do { - temp = intpart*0.1; - my_modf(temp, &intpart); - idx = (int) ((temp -intpart +0.05)* 10.0); - /* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ - /* printf ("%llf, %f, %x\n", temp, intpart, idx); */ - iconvert[iplace++] = - (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; - } while (intpart && (iplace < 311)); - if (iplace == 311) iplace--; - iconvert[iplace] = 0; - - /* Convert fractional part */ - if (fracpart) - { - do { - temp = fracpart*0.1; - my_modf(temp, &fracpart); - idx = (int) ((temp -fracpart +0.05)* 10.0); - /* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */ - /* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */ - fconvert[fplace++] = - (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; - } while(fracpart && (fplace < 311)); - if (fplace == 311) fplace--; - } - fconvert[fplace] = 0; - - /* -1 for decimal point, another -1 if we are printing a sign */ - padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); - zpadlen = max - fplace; - if (zpadlen < 0) zpadlen = 0; - if (padlen < 0) - padlen = 0; - if (flags & DP_F_MINUS) - padlen = -padlen; /* Left Justifty */ - - if ((flags & DP_F_ZERO) && (padlen > 0)) { - if (signvalue) { - dopr_outch (buffer, currlen, maxlen, signvalue); - --padlen; - signvalue = 0; - } - while (padlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --padlen; - } - } - while (padlen > 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - --padlen; - } - if (signvalue) - dopr_outch (buffer, currlen, maxlen, signvalue); - - while (iplace > 0) - dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]); - -#ifdef DEBUG_SNPRINTF - printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); -#endif - - /* - * Decimal point. This should probably use locale to find the correct - * char to print out. - */ - if (max > 0) { - dopr_outch (buffer, currlen, maxlen, '.'); - - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } - - while (fplace > 0) - dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); - } - - while (padlen < 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++padlen; - } -} - -static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) -{ - if (*currlen < maxlen) { - buffer[(*currlen)] = c; - } - (*currlen)++; -} - - int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args) -{ - return dopr(str, count, fmt, args); -} -#define vsnprintf smb_vsnprintf -#endif - -/* yes this really must be a ||. Don't muck with this (tridge) - * - * The logic for these two is that we need our own definition if the - * OS *either* has no definition of *sprintf, or if it does have one - * that doesn't work properly according to the autoconf test. - */ -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) -int smb_snprintf(char *str,size_t count,const char *fmt,...) -{ - size_t ret; - va_list ap; - - va_start(ap, fmt); - ret = vsnprintf(str, count, fmt, ap); - va_end(ap); - return ret; -} -#define snprintf smb_snprintf -#endif - -#endif - -#ifndef HAVE_VASPRINTF - int vasprintf(char **ptr, const char *format, va_list ap) -{ - int ret; - va_list ap2; - - VA_COPY(ap2, ap); - - ret = vsnprintf(NULL, 0, format, ap2); - if (ret <= 0) return ret; - - (*ptr) = (char *)malloc(ret+1); - if (!*ptr) return -1; - - VA_COPY(ap2, ap); - - ret = vsnprintf(*ptr, ret+1, format, ap2); - - return ret; -} -#endif - - -#ifndef HAVE_ASPRINTF - int asprintf(char **ptr, const char *format, ...) -{ - va_list ap; - int ret; - - *ptr = NULL; - va_start(ap, format); - ret = vasprintf(ptr, format, ap); - va_end(ap); - - return ret; -} -#endif - -#ifdef TEST_SNPRINTF - - int sprintf(char *str,const char *fmt,...); - - int main (void) -{ - char buf1[1024]; - char buf2[1024]; - char *fp_fmt[] = { - "%1.1f", - "%-1.5f", - "%1.5f", - "%123.9f", - "%10.5f", - "% 10.5f", - "%+22.9f", - "%+4.9f", - "%01.3f", - "%4f", - "%3.1f", - "%3.2f", - "%.0f", - "%f", - "-16.16f", - NULL - }; - double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, - 0.9996, 1.996, 4.136, 5.030201, 0.00205, - /* END LIST */ 0}; - char *int_fmt[] = { - "%-1.5d", - "%1.5d", - "%123.9d", - "%5.5d", - "%10.5d", - "% 10.5d", - "%+22.33d", - "%01.3d", - "%4d", - "%d", - NULL - }; - long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; - char *str_fmt[] = { - "10.5s", - "5.10s", - "10.1s", - "0.10s", - "10.0s", - "1.10s", - "%s", - "%.1s", - "%.10s", - "%10s", - NULL - }; - char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; - int x, y; - int fail = 0; - int num = 0; - - printf ("Testing snprintf format codes against system sprintf...\n"); - - for (x = 0; fp_fmt[x] ; x++) { - for (y = 0; fp_nums[y] != 0 ; y++) { - int l1 = snprintf(NULL, 0, fp_fmt[x], fp_nums[y]); - int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); - sprintf (buf2, fp_fmt[x], fp_nums[y]); - if (strcmp (buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", - fp_fmt[x], buf1, buf2); - fail++; - } - if (l1 != l2) { - printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, fp_fmt[x]); - fail++; - } - num++; - } - } - - for (x = 0; int_fmt[x] ; x++) { - for (y = 0; int_nums[y] != 0 ; y++) { - int l1 = snprintf(NULL, 0, int_fmt[x], int_nums[y]); - int l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]); - sprintf (buf2, int_fmt[x], int_nums[y]); - if (strcmp (buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", - int_fmt[x], buf1, buf2); - fail++; - } - if (l1 != l2) { - printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, int_fmt[x]); - fail++; - } - num++; - } - } - - for (x = 0; str_fmt[x] ; x++) { - for (y = 0; str_vals[y] != 0 ; y++) { - int l1 = snprintf(NULL, 0, str_fmt[x], str_vals[y]); - int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]); - sprintf (buf2, str_fmt[x], str_vals[y]); - if (strcmp (buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n", - str_fmt[x], buf1, buf2); - fail++; - } - if (l1 != l2) { - printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, str_fmt[x]); - fail++; - } - num++; - } - } - - printf ("%d tests failed out of %d.\n", fail, num); - - printf("seeing how many digits we support\n"); - { - double v0 = 0.12345678901234567890123456789012345678901; - for (x=0; x<100; x++) { - double p = pow(10, x); - double r = v0*p; - snprintf(buf1, sizeof(buf1), "%1.1f", r); - sprintf(buf2, "%1.1f", r); - if (strcmp(buf1, buf2)) { - printf("we seem to support %d digits\n", x-1); - break; - } - } - } - - return 0; -} -#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 @@ -/* Copyright (C) 1991, 1992, 1997, 1999, 2003 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#ifndef errno -extern int errno; -#endif - -#include - -#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) -# define IN_CTYPE_DOMAIN(c) 1 -#else -# define IN_CTYPE_DOMAIN(c) isascii(c) -#endif - -#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) -#define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) -#define TOLOWER(c) (IN_CTYPE_DOMAIN (c) ? tolower(c) : (c)) - -#include - -#include -#include -#include - -/* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the - character after the last one used in the number is put in *ENDPTR. */ -double -strtod (const char *nptr, char **endptr) -{ - register const char *s; - short int sign; - - /* The number so far. */ - double num; - - int got_dot; /* Found a decimal point. */ - int got_digit; /* Seen any digits. */ - - /* The exponent of the number. */ - long int exponent; - - if (nptr == NULL) - { - errno = EINVAL; - goto noconv; - } - - s = nptr; - - /* Eat whitespace. */ - while (ISSPACE (*s)) - ++s; - - /* Get the sign. */ - sign = *s == '-' ? -1 : 1; - if (*s == '-' || *s == '+') - ++s; - - num = 0.0; - got_dot = 0; - got_digit = 0; - exponent = 0; - for (;; ++s) - { - if (ISDIGIT (*s)) - { - got_digit = 1; - - /* Make sure that multiplication by 10 will not overflow. */ - if (num > DBL_MAX * 0.1) - /* The value of the digit doesn't matter, since we have already - gotten as many digits as can be represented in a `double'. - This doesn't necessarily mean the result will overflow. - The exponent may reduce it to within range. - - We just need to record that there was another - digit so that we can multiply by 10 later. */ - ++exponent; - else - num = (num * 10.0) + (*s - '0'); - - /* Keep track of the number of digits after the decimal point. - If we just divided by 10 here, we would lose precision. */ - if (got_dot) - --exponent; - } - else if (!got_dot && *s == '.') - /* Record that we have found the decimal point. */ - got_dot = 1; - else - /* Any other character terminates the number. */ - break; - } - - if (!got_digit) - goto noconv; - - if (TOLOWER (*s) == 'e') - { - /* Get the exponent specified after the `e' or `E'. */ - int save = errno; - char *end; - long int exp; - - errno = 0; - ++s; - exp = strtol (s, &end, 10); - if (errno == ERANGE) - { - /* The exponent overflowed a `long int'. It is probably a safe - assumption that an exponent that cannot be represented by - a `long int' exceeds the limits of a `double'. */ - if (endptr != NULL) - *endptr = end; - if (exp < 0) - goto underflow; - else - goto overflow; - } - else if (end == s) - /* There was no exponent. Reset END to point to - the 'e' or 'E', so *ENDPTR will be set there. */ - end = (char *) s - 1; - errno = save; - s = end; - exponent += exp; - } - - if (endptr != NULL) - *endptr = (char *) s; - - if (num == 0.0) - return 0.0; - - /* Multiply NUM by 10 to the EXPONENT power, - checking for overflow and underflow. */ - - if (exponent < 0) - { - if (num < DBL_MIN * pow (10.0, (double) -exponent)) - goto underflow; - } - else if (exponent > 0) - { - if (num > DBL_MAX * pow (10.0, (double) -exponent)) - goto overflow; - } - - num *= pow (10.0, (double) exponent); - - return num * sign; - -overflow: - /* Return an overflow error. */ - errno = ERANGE; - return HUGE_VAL * sign; - -underflow: - /* Return an underflow error. */ - if (endptr != NULL) - *endptr = (char *) nptr; - errno = ERANGE; - return 0.0; - -noconv: - /* There was no number. */ - if (endptr != NULL) - *endptr = (char *) nptr; - return 0.0; -} 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@ TESTS = @EXTRA_TEST@ check_PROGRAMS = @EXTRA_TEST@ -INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl -I$(top_srcdir)/plugins +INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins EXTRA_PROGRAMS = test_utils test_disk 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 @@ -/* Prefer faster, non-thread-safe stdio functions if available. - - Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Written by Jim Meyering. */ - -#ifndef UNLOCKED_IO_H -# define UNLOCKED_IO_H 1 - -/* These are wrappers for functions/macros from the GNU C library, and - from other C libraries supporting POSIX's optional thread-safe functions. - - The standard I/O functions are thread-safe. These *_unlocked ones are - more efficient but not thread-safe. That they're not thread-safe is - fine since all of the applications in this package are single threaded. - - Also, some code that is shared with the GNU C library may invoke - the *_unlocked functions directly. On hosts that lack those - functions, invoke the non-thread-safe versions instead. */ - -# include - -# if HAVE_DECL_CLEARERR_UNLOCKED -# undef clearerr -# define clearerr(x) clearerr_unlocked (x) -# else -# define clearerr_unlocked(x) clearerr (x) -# endif - -# if HAVE_DECL_FEOF_UNLOCKED -# undef feof -# define feof(x) feof_unlocked (x) -# else -# define feof_unlocked(x) feof (x) -# endif - -# if HAVE_DECL_FERROR_UNLOCKED -# undef ferror -# define ferror(x) ferror_unlocked (x) -# else -# define ferror_unlocked(x) ferror (x) -# endif - -# if HAVE_DECL_FFLUSH_UNLOCKED -# undef fflush -# define fflush(x) fflush_unlocked (x) -# else -# define fflush_unlocked(x) fflush (x) -# endif - -# if HAVE_DECL_FGETS_UNLOCKED -# undef fgets -# define fgets(x,y,z) fgets_unlocked (x,y,z) -# else -# define fgets_unlocked(x,y,z) fgets (x,y,z) -# endif - -# if HAVE_DECL_FPUTC_UNLOCKED -# undef fputc -# define fputc(x,y) fputc_unlocked (x,y) -# else -# define fputc_unlocked(x,y) fputc (x,y) -# endif - -# if HAVE_DECL_FPUTS_UNLOCKED -# undef fputs -# define fputs(x,y) fputs_unlocked (x,y) -# else -# define fputs_unlocked(x,y) fputs (x,y) -# endif - -# if HAVE_DECL_FREAD_UNLOCKED -# undef fread -# define fread(w,x,y,z) fread_unlocked (w,x,y,z) -# else -# define fread_unlocked(w,x,y,z) fread (w,x,y,z) -# endif - -# if HAVE_DECL_FWRITE_UNLOCKED -# undef fwrite -# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) -# else -# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) -# endif - -# if HAVE_DECL_GETC_UNLOCKED -# undef getc -# define getc(x) getc_unlocked (x) -# else -# define getc_unlocked(x) getc (x) -# endif - -# if HAVE_DECL_GETCHAR_UNLOCKED -# undef getchar -# define getchar() getchar_unlocked () -# else -# define getchar_unlocked() getchar () -# endif - -# if HAVE_DECL_PUTC_UNLOCKED -# undef putc -# define putc(x,y) putc_unlocked (x,y) -# else -# define putc_unlocked(x,y) putc (x,y) -# endif - -# if HAVE_DECL_PUTCHAR_UNLOCKED -# undef putchar -# define putchar(x) putchar_unlocked (x) -# else -# define putchar_unlocked(x) putchar (x) -# endif - -# undef flockfile -# define flockfile(x) ((void) 0) - -# undef ftrylockfile -# define ftrylockfile(x) 0 - -# undef funlockfile -# define funlockfile(x) ((void) 0) - -#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 @@ -/* xalloc.h -- malloc with out-of-memory checking - - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003, 2004 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef XALLOC_H_ -# define XALLOC_H_ - -# include - - -# ifdef __cplusplus -extern "C" { -# endif - - -# ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ -# define __attribute__(x) -# endif -# endif - -# ifndef ATTRIBUTE_NORETURN -# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) -# endif - -/* This function is always triggered when memory is exhausted. - It must be defined by the application, either explicitly - or by using gnulib's xalloc-die module. This is the - function to call when one wants the program to die because of a - memory allocation failure. */ -extern void xalloc_die (void) ATTRIBUTE_NORETURN; - -void *xmalloc (size_t s); -void *xnmalloc (size_t n, size_t s); -void *xzalloc (size_t s); -void *xcalloc (size_t n, size_t s); -void *xrealloc (void *p, size_t s); -void *xnrealloc (void *p, size_t n, size_t s); -void *x2realloc (void *p, size_t *pn); -void *x2nrealloc (void *p, size_t *pn, size_t s); -void *xmemdup (void const *p, size_t s); -char *xstrdup (char const *str); - -/* Return 1 if an array of N objects, each of size S, cannot exist due - to size arithmetic overflow. S must be positive and N must be - nonnegative. This is a macro, not an inline function, so that it - works correctly even when SIZE_MAX < N. - - By gnulib convention, SIZE_MAX represents overflow in size - calculations, so the conservative dividend to use here is - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. - However, malloc (SIZE_MAX) fails on all known hosts where - sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for - exactly-SIZE_MAX allocations on such hosts; this avoids a test and - branch when S is known to be 1. */ -# define xalloc_oversized(n, s) \ - ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) - -# ifdef __cplusplus -} -# endif - - -#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 @@ -/* xmalloc.c -- malloc with out of memory checking - - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "xalloc.h" - -#include -#include - -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - -/* 1 if calloc is known to be compatible with GNU calloc. This - matters if we are not also using the calloc module, which defines - HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ -#if defined HAVE_CALLOC || defined __GLIBC__ -enum { HAVE_GNU_CALLOC = 1 }; -#else -enum { HAVE_GNU_CALLOC = 0 }; -#endif - -/* Allocate an array of N objects, each with S bytes of memory, - dynamically, with error checking. S must be nonzero. */ - -static inline void * -xnmalloc_inline (size_t n, size_t s) -{ - void *p; - if (xalloc_oversized (n, s) || (! (p = malloc (n * s)) && n != 0)) - xalloc_die (); - return p; -} - -void * -xnmalloc (size_t n, size_t s) -{ - return xnmalloc_inline (n, s); -} - -/* Allocate N bytes of memory dynamically, with error checking. */ - -void * -xmalloc (size_t n) -{ - return xnmalloc_inline (n, 1); -} - -/* Change the size of an allocated block of memory P to an array of N - objects each of S bytes, with error checking. S must be nonzero. */ - -static inline void * -xnrealloc_inline (void *p, size_t n, size_t s) -{ - if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0)) - xalloc_die (); - return p; -} - -void * -xnrealloc (void *p, size_t n, size_t s) -{ - return xnrealloc_inline (p, n, s); -} - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. */ - -void * -xrealloc (void *p, size_t n) -{ - return xnrealloc_inline (p, n, 1); -} - - -/* If P is null, allocate a block of at least *PN such objects; - otherwise, reallocate P so that it contains more than *PN objects - each of S bytes. *PN must be nonzero unless P is null, and S must - be nonzero. Set *PN to the new number of objects, and return the - pointer to the new block. *PN is never set to zero, and the - returned pointer is never null. - - Repeated reallocations are guaranteed to make progress, either by - allocating an initial block with a nonzero size, or by allocating a - larger block. - - In the following implementation, nonzero sizes are doubled so that - repeated reallocations have O(N log N) overall cost rather than - O(N**2) cost, but the specification for this function does not - guarantee that sizes are doubled. - - Here is an example of use: - - int *p = NULL; - size_t used = 0; - size_t allocated = 0; - - void - append_int (int value) - { - if (used == allocated) - p = x2nrealloc (p, &allocated, sizeof *p); - p[used++] = value; - } - - This causes x2nrealloc to allocate a block of some nonzero size the - first time it is called. - - To have finer-grained control over the initial size, set *PN to a - nonzero value before calling this function with P == NULL. For - example: - - int *p = NULL; - size_t used = 0; - size_t allocated = 0; - size_t allocated1 = 1000; - - void - append_int (int value) - { - if (used == allocated) - { - p = x2nrealloc (p, &allocated1, sizeof *p); - allocated = allocated1; - } - p[used++] = value; - } - - */ - -static inline void * -x2nrealloc_inline (void *p, size_t *pn, size_t s) -{ - size_t n = *pn; - - if (! p) - { - if (! n) - { - /* The approximate size to use for initial small allocation - requests, when the invoking code specifies an old size of - zero. 64 bytes is the largest "small" request for the - GNU C library malloc. */ - enum { DEFAULT_MXFAST = 64 }; - - n = DEFAULT_MXFAST / s; - n += !n; - } - } - else - { - if (SIZE_MAX / 2 / s < n) - xalloc_die (); - n *= 2; - } - - *pn = n; - return xrealloc (p, n * s); -} - -void * -x2nrealloc (void *p, size_t *pn, size_t s) -{ - return x2nrealloc_inline (p, pn, s); -} - -/* If P is null, allocate a block of at least *PN bytes; otherwise, - reallocate P so that it contains more than *PN bytes. *PN must be - nonzero unless P is null. Set *PN to the new block's size, and - return the pointer to the new block. *PN is never set to zero, and - the returned pointer is never null. */ - -void * -x2realloc (void *p, size_t *pn) -{ - return x2nrealloc_inline (p, pn, 1); -} - -/* Allocate S bytes of zeroed memory dynamically, with error checking. - There's no need for xnzalloc (N, S), since it would be equivalent - to xcalloc (N, S). */ - -void * -xzalloc (size_t s) -{ - return memset (xmalloc (s), 0, s); -} - -/* Allocate zeroed memory for N elements of S bytes, with error - checking. S must be nonzero. */ - -void * -xcalloc (size_t n, size_t s) -{ - void *p; - /* Test for overflow, since some calloc implementations don't have - proper overflow checks. But omit overflow and size-zero tests if - HAVE_GNU_CALLOC, since GNU calloc catches overflow and never - returns NULL if successful. */ - if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) - || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) - xalloc_die (); - return p; -} - -/* Clone an object P of size S, with error checking. There's no need - for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any - need for an arithmetic overflow check. */ - -void * -xmemdup (void const *p, size_t s) -{ - return memcpy (xmalloc (s), p, s); -} - -/* Clone STRING. */ - -char * -xstrdup (char const *string) -{ - return xmemdup (string, strlen (string) + 1); -} 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 @@ -## This is a template from which Makefile.am is generated. -*-Makefile-*- - -Makefile.am: Makefile.am.in - rm -f $@ $@t - (echo "## Process this file with automake to produce Makefile.in."; \ - echo EXTRA_DIST =; \ - echo "EXTRA_DIST += Makefile.am.in"; \ - ls -1 *.m4 | sed 's/^/EXTRA_DIST += /'; echo ) \ - >> $@t - sed -n '/^Makefile\.am:/,$$p' $@.in >> $@t - chmod a-w $@t - mv $@t $@ - -print_coreutil_files: - @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 @@ -#serial 8 - -# Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_AFS], - [ - AC_ARG_WITH(afs, - AC_HELP_STRING([--with-afs], - [support for the Andrew File System [[default=no]]]), - test "$withval" = no || with_afs=yes, with_afs=no) - if test "$with_afs" = yes; then - AC_DEFINE(AFS, 1, [Define if you have the Andrew File System.]) - fi - ]) 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 @@ -# basename.m4 serial 1 -dnl Copyright (C) 2005 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_BASENAME], -[ - AC_LIBSOURCES([basename.c, dirname.h]) - AC_LIBOBJ([basename]) - - dnl Prerequisites of lib/basename.c. - AC_REQUIRE([gl_AC_DOS]) -]) 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 @@ -# Enable extensions on systems that normally disable them. - -# Copyright (C) 2003 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# gl_USE_SYSTEM_EXTENSIONS -# ------------------------ -# Enable extensions on systems that normally disable them, -# typically due to standards-conformance issues. -AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [ - AC_BEFORE([$0], [AC_COMPILE_IFELSE]) - AC_BEFORE([$0], [AC_RUN_IFELSE]) - - AC_REQUIRE([AC_GNU_SOURCE]) - AC_REQUIRE([AC_AIX]) - AC_REQUIRE([AC_MINIX]) - - AH_VERBATIM([__EXTENSIONS__], -[/* Enable extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif]) - AC_DEFINE([__EXTENSIONS__]) - AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) -]) 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 @@ -#serial 5 - -dnl From Jim Meyering. -dnl -dnl See if struct statfs has the f_fstypename member. -dnl If so, define HAVE_F_FSTYPENAME_IN_STATFS. -dnl - -# Copyright (C) 1998, 1999, 2001, 2004 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FSTYPENAME], - [ - AC_CACHE_CHECK([for f_fstypename in struct statfs], - fu_cv_sys_f_fstypename_in_statfs, - [ - AC_TRY_COMPILE( - [ -#include -#include -#include - ], - [struct statfs s; int i = sizeof s.f_fstypename;], - fu_cv_sys_f_fstypename_in_statfs=yes, - fu_cv_sys_f_fstypename_in_statfs=no - ) - ] - ) - - if test $fu_cv_sys_f_fstypename_in_statfs = yes; then - AC_DEFINE(HAVE_F_FSTYPENAME_IN_STATFS, 1, - [Define if struct statfs has the f_fstypename member.]) - fi - ] -) 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 @@ -# inttypes.m4 serial 1 (gettext-0.11.4) -dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_INTTYPES_H if exists and doesn't clash with -# . - -AC_DEFUN([gt_HEADER_INTTYPES_H], -[ - AC_CACHE_CHECK([for inttypes.h], gt_cv_header_inttypes_h, - [ - AC_TRY_COMPILE( - [#include -#include ], - [], gt_cv_header_inttypes_h=yes, gt_cv_header_inttypes_h=no) - ]) - if test $gt_cv_header_inttypes_h = yes; then - AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1, - [Define if exists and doesn't clash with .]) - fi -]) 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 @@ -# longlong.m4 serial 5 -dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_LONG_LONG if 'long long' works. - -AC_DEFUN([gl_AC_TYPE_LONG_LONG], -[ - AC_CACHE_CHECK([for long long], ac_cv_type_long_long, - [AC_TRY_LINK([long long ll = 1LL; int i = 63;], - [long long llmax = (long long) -1; - return ll << i | ll >> i | llmax / ll | llmax % ll;], - ac_cv_type_long_long=yes, - ac_cv_type_long_long=no)]) - if test $ac_cv_type_long_long = yes; then - AC_DEFINE(HAVE_LONG_LONG, 1, - [Define if you have the 'long long' type.]) - fi -]) 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 @@ -dnl These are for the libs and macros from coreutils -dnl Currently utilising v5.2.1 - -dnl We use jm_ for non Autoconf macros. -m4_pattern_forbid([^np_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl -m4_pattern_forbid([^jm_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl -m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl - -dnl These are all m4 things that need to be called -dnl Usually in coreutils' prereq.m4, but this is a subset that we need -AC_DEFUN([np_COREUTILS], -[ - AC_REQUIRE([AM_STDBOOL_H]) - AC_REQUIRE([gl_BASENAME]) - AC_REQUIRE([gl_C_STRTOLD]) - AC_REQUIRE([gl_EXITFAIL]) - AC_REQUIRE([gl_FCNTL_SAFER]) - AC_REQUIRE([gl_FSUSAGE]) - AC_REQUIRE([gl_FUNC_ALLOCA]) - AC_REQUIRE([gl_GETOPT]) - AC_REQUIRE([gl_MOUNTLIST]) - AC_REQUIRE([gl_REGEX]) - AC_REQUIRE([gl_UNISTD_SAFER]) - AC_REQUIRE([gl_XALLOC]) - AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) - -dnl This is in jm-macros.m4, which calls prereq.m4, and then calls this afterwards - AC_REQUIRE([gl_AFS]) -]) 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 @@ -dnl These are for the libs and macros from curl -dnl Currently utilising v7.12.3 - -dnl We use jm_ for non Autoconf macros. -dnl m4_pattern_forbid([^np_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl -dnl m4_pattern_forbid([^jm_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl -dnl m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl - -dnl These are all m4 things that need to be called -dnl Usually in coreutils' prereq.m4, but this is a subset that we need -AC_DEFUN([np_CURL], -[ - AC_REQUIRE([TYPE_SOCKLEN_T]) -]) - -dnl Check for socklen_t: historically on BSD it is an int, and in -dnl POSIX 1g it is a type of its own, but some platforms use different -dnl types for the argument to getsockopt, getpeername, etc. So we -dnl have to test to find something that will work. -AC_DEFUN([TYPE_SOCKLEN_T], -[ - AC_CHECK_TYPE([socklen_t], ,[ - AC_MSG_CHECKING([for socklen_t equivalent]) - AC_CACHE_VAL([curl_cv_socklen_t_equiv], - [ - # Systems have either "struct sockaddr *" or - # "void *" as the second argument to getpeername - curl_cv_socklen_t_equiv= - for arg2 in "struct sockaddr" void; do - for t in int size_t unsigned long "unsigned long"; do - AC_TRY_COMPILE([ - #ifdef HAVE_SYS_TYPES_H - #include - #endif - #ifdef HAVE_SYS_SOCKET_H - #include - #endif - - int getpeername (int, $arg2 *, $t *); - ],[ - $t len; - getpeername(0,0,&len); - ],[ - curl_cv_socklen_t_equiv="$t" - break - ]) - done - done - - if test "x$curl_cv_socklen_t_equiv" = x; then - AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) - fi - ]) - AC_MSG_RESULT($curl_cv_socklen_t_equiv) - AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, - [type to use in place of socklen_t if not defined])], - [#include -#include ]) -]) - 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 @@ -#serial 1003 -dnl Copyright (C) 2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# This macro can be removed once we can rely on Autoconf 2.57a or later, -# since we can then use its AC_C_RESTRICT. - -# gl_C_RESTRICT -# -------------- -# Determine whether the C/C++ compiler supports the "restrict" keyword -# introduced in ANSI C99, or an equivalent. Do nothing if the compiler -# accepts it. Otherwise, if the compiler supports an equivalent, -# define "restrict" to be that. Here are some variants: -# - GCC supports both __restrict and __restrict__ -# - older DEC Alpha C compilers support only __restrict -# - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C -# Otherwise, define "restrict" to be empty. -AC_DEFUN([gl_C_RESTRICT], -[AC_CACHE_CHECK([for C/C++ restrict keyword], gl_cv_c_restrict, - [gl_cv_c_restrict=no - # Try the official restrict keyword, then gcc's __restrict, and - # the less common variants. - for ac_kw in restrict __restrict __restrict__ _Restrict; do - AC_COMPILE_IFELSE([AC_LANG_SOURCE( - [float * $ac_kw x;])], - [gl_cv_c_restrict=$ac_kw; break]) - done - ]) - case $gl_cv_c_restrict in - restrict) ;; - no) AC_DEFINE(restrict,, - [Define to equivalent of C99 restrict keyword, or to nothing if this - is not supported. Do not define if restrict is supported directly.]) ;; - *) AC_DEFINE_UNQUOTED(restrict, $gl_cv_c_restrict) ;; - esac -]) 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 @@ -# signed.m4 serial 1 (gettext-0.10.40) -dnl Copyright (C) 2001-2002 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -AC_DEFUN([bh_C_SIGNED], -[ - AC_CACHE_CHECK([for signed], bh_cv_c_signed, - [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)]) - if test $bh_cv_c_signed = no; then - AC_DEFINE(signed, , - [Define to empty if the C compiler doesn't support this keyword.]) - fi -]) 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 @@ -# ulonglong.m4 serial 4 -dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works. - -AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], -[ - AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long, - [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;], - [unsigned long long ullmax = (unsigned long long) -1; - return ull << i | ull >> i | ullmax / ull | ullmax % ull;], - ac_cv_type_unsigned_long_long=yes, - ac_cv_type_unsigned_long_long=no)]) - if test $ac_cv_type_unsigned_long_long = yes; then - AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, - [Define if you have the 'unsigned long long' type.]) - fi -]) 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 @@ -# unlocked-io.m4 serial 12 - -# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software -# Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -dnl From Jim Meyering. -dnl -dnl See if the glibc *_unlocked I/O macros or functions are available. -dnl Use only those *_unlocked macros or functions that are declared -dnl (because some of them were declared in Solaris 2.5.1 but were removed -dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run -dnl on Solaris 2.6). - -AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO], -[ - AC_LIBSOURCES([unlocked-io.h]) - - AC_DEFINE([USE_UNLOCKED_IO], 1, - [Define to 1 if you want getc etc. to use unlocked I/O if available. - Unlocked I/O can improve performance in unithreaded apps, - but it is not safe for multithreaded apps.]) - - dnl Persuade glibc and Solaris to declare - dnl fgets_unlocked(), fputs_unlocked() etc. - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - - AC_CHECK_DECLS_ONCE( - [clearerr_unlocked feof_unlocked ferror_unlocked - fflush_unlocked fgets_unlocked fputc_unlocked fputs_unlocked - fread_unlocked fwrite_unlocked getc_unlocked - getchar_unlocked putc_unlocked putchar_unlocked]) -]) 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 @@ VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t -INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl -I$(top_srcdir)/plugins @SSLINCLUDE@ +INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins @SSLINCLUDE@ datadir = @datadir@ localedir = $(datadir)/locale @@ -15,7 +15,7 @@ EXTRA_PROGRAMS = pst3 EXTRA_DIST = pst3.c -BASEOBJS = ../plugins/utils.o ../lib/libnagiosplug.a ../lib/libcoreutils.a +BASEOBJS = ../plugins/utils.o ../lib/libnagiosplug.a ../gl/libgnu.a NETOBJS = ../plugins/netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) NETLIBS = $(NETOBJS) $(SOCKETLIBS) 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 @@ VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t -INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ +INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ datadir = @datadir@ localedir = $(datadir)/locale @@ -33,7 +33,7 @@ EXTRA_DIST = t utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ PLUGINHDRS = common.h -BASEOBJS = utils.o ../lib/libnagiosplug.a ../lib/libcoreutils.a +BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) SSLOBJS = sslutils.o 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) char *helocmd = NULL; char *error_msg = NULL; struct timeval tv; - struct hostent *hp; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -191,9 +190,6 @@ main (int argc, char **argv) printf(_("gethostname() failed!\n")); return STATE_CRITICAL; } - hp = gethostbyname(localhostname); - if(!hp) helocmd = localhostname; - else helocmd = hp->h_name; } else { helocmd = localhostname; } @@ -202,6 +198,9 @@ main (int argc, char **argv) else asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n"); + if (verbose) + printf("HELOCMD: %s", helocmd); + /* initialize the MAIL command with optional FROM command */ asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n"); 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 @@ #include #endif +/* GNU Libraries */ #include -#include - -#ifdef HAVE_LWRES_NETDB_H -#include -#else -# if !HAVE_GETADDRINFO -# include "getaddrinfo.h" -# else -# include -# endif -#endif +#include "vasprintf.h" +#include "snprintf.h" +#include "vsnprintf.h" #ifdef HAVE_LOCALE_H #include @@ -138,22 +131,6 @@ # define strtoul(a,b,c) (unsigned long)atol((a)) #endif -#ifndef HAVE_ASPRINTF -int asprintf(char **strp, const char *fmt, ...); -#endif - -#ifndef HAVE_VASPRINTF -/* int vasprintf(char **strp, const char *fmt, va_list ap); */ -#endif - -#ifndef HAVE_SNPRINTF -int snprintf(char *str, size_t size, const char *format, ...); -#endif - -#ifndef HAVE_VSNPRINTF -int vsnprintf(char *str, size_t size, const char *format, va_list ap); -#endif - /* SSL implementations */ #ifdef HAVE_GNUTLS_OPENSSL_H # include 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 @@ -/* - * This file is part of libESMTP, a library for submission of RFC 2822 - * formatted electronic mail messages using the SMTP protocol described - * in RFC 2821. - * Modified by Jeremy T. Bouse for use in Nagios plugins - * - * Copyright (C) 2001,2002 Brian Stafford - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -/* Need to turn off Posix features in glibc to build this */ -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "gethostbyname.h" -#include "getaddrinfo.h" - -static struct addrinfo * -dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) -{ - struct addrinfo *ret; - - ret = malloc (sizeof (struct addrinfo)); - if (ret == NULL) - return NULL; - memcpy (ret, info, sizeof (struct addrinfo)); - ret->ai_addr = malloc (addrlen); - if (ret->ai_addr == NULL) - { - free (ret); - return NULL; - } - memcpy (ret->ai_addr, addr, addrlen); - ret->ai_addrlen = addrlen; - return ret; -} - -int -getaddrinfo (const char *nodename, const char *servname, - const struct addrinfo *hints, struct addrinfo **res) -{ - struct hostent *hp; - struct servent *servent; - const char *socktype; - int port; - struct addrinfo hint, result; - struct addrinfo *ai, *sai, *eai; - struct ghbnctx ghbnctx; - char **addrs; - int code; - - memset (&result, 0, sizeof result); - - /* default for hints */ - if (hints == NULL) - { - memset (&hint, 0, sizeof hint); - hint.ai_family = PF_UNSPEC; - hints = &hint; - } - - result.ai_socktype = hints->ai_socktype; - - /* Note: maintain port in host byte order to make debugging easier */ - if (servname != NULL) { - if (isdigit (*servname)) - port = strtol (servname, NULL, 10); - else if ((servent = getservbyname (servname, socktype)) != NULL) - port = ntohs (servent->s_port); - else - return EAI_NONAME; - } - - /* if nodename == NULL refer to the local host for a client or any - for a server */ - if (nodename == NULL) - { - struct sockaddr_in sin; - - /* check protocol family is PF_UNSPEC or PF_INET - could try harder - for IPv6 but that's more code than I'm prepared to write */ - if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET) - result.ai_family = AF_INET; - else - return EAI_FAMILY; - - sin.sin_family = result.ai_family; - sin.sin_port = htons (port); - if (hints->ai_flags & AI_PASSIVE) - sin.sin_addr.s_addr = htonl (INADDR_ANY); - else - sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - /* Duplicate result and addr and return */ - *res = dup_addrinfo (&result, &sin, sizeof sin); - return (*res == NULL) ? EAI_MEMORY : 0; - } - - /* If AI_NUMERIC is specified, use inet_addr to translate numbers and - dots notation. */ - if (hints->ai_flags & AI_NUMERICHOST) - { - struct sockaddr_in sin; - - /* check protocol family is PF_UNSPEC or PF_INET */ - if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET) - result.ai_family = AF_INET; - else - return EAI_FAMILY; - - sin.sin_family = result.ai_family; - sin.sin_port = htons (port); - sin.sin_addr.s_addr = inet_addr (nodename); - /* Duplicate result and addr and return */ - *res = dup_addrinfo (&result, &sin, sizeof sin); - return (*res == NULL) ? EAI_MEMORY : 0; - } - - errno = 0; - hp = gethostbyname_ctx (nodename, &ghbnctx); - if (hp == NULL) - { - if (errno != 0) - { - free_ghbnctx (&ghbnctx); - return EAI_SYSTEM; - } - code = h_error_ctx (&ghbnctx); - switch (code) - { - case HOST_NOT_FOUND: code = EAI_NODATA; break; - case NO_DATA: code = EAI_NODATA; break; -#if defined(NO_ADDRESS) && NO_ADDRESS != NO_DATA - case NO_ADDRESS: code = EAI_NODATA; break; -#endif - case NO_RECOVERY: code = EAI_FAIL; break; - case TRY_AGAIN: code = EAI_AGAIN; break; - default: code = EAI_FAIL; break; - } - free_ghbnctx (&ghbnctx); - return code; - } - - /* Check that the address family is acceptable. - */ - switch (hp->h_addrtype) - { - case AF_INET: - if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)) - goto eai_family; - break; -#ifdef USE_IPV6 - case AF_INET6: - if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6)) - goto eai_family; - break; -#endif - default: - eai_family: - free_ghbnctx (&ghbnctx); - return EAI_FAMILY; - } - - /* For each element pointed to by hp, create an element in the - result linked list. */ - sai = eai = NULL; - for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) - { - struct sockaddr sa; - size_t addrlen; - - sa.sa_family = hp->h_addrtype; - switch (hp->h_addrtype) - { - case AF_INET: - ((struct sockaddr_in *) &sa)->sin_port = htons (port); - memcpy (&((struct sockaddr_in *) &sa)->sin_addr, - *addrs, hp->h_length); - addrlen = sizeof (struct sockaddr_in); - break; -#ifdef USE_IPV6 - case AF_INET6: -# if SIN6_LEN - ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length; -# endif - ((struct sockaddr_in6 *) &sa)->sin6_port = htons (port); - memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr, - *addrs, hp->h_length); - addrlen = sizeof (struct sockaddr_in6); - break; -#endif - default: - continue; - } - - result.ai_family = hp->h_addrtype; - ai = dup_addrinfo (&result, &sa, addrlen); - if (ai == NULL) - { - free_ghbnctx (&ghbnctx); - freeaddrinfo (sai); - return EAI_MEMORY; - } - if (sai == NULL) - sai = ai; - else - eai->ai_next = ai; - eai = ai; - } - - if (sai == NULL) - { - free_ghbnctx (&ghbnctx); - return EAI_NODATA; - } - - if (hints->ai_flags & AI_CANONNAME) - { - sai->ai_canonname = malloc (strlen (hp->h_name) + 1); - if (sai->ai_canonname == NULL) - { - free_ghbnctx (&ghbnctx); - freeaddrinfo (sai); - return EAI_MEMORY; - } - strcpy (sai->ai_canonname, hp->h_name); - } - - free_ghbnctx (&ghbnctx); - *res = sai; - return 0; -} - -void -freeaddrinfo (struct addrinfo *ai) -{ - struct addrinfo *next; - - while (ai != NULL) - { - next = ai->ai_next; - if (ai->ai_canonname != NULL) - free (ai->ai_canonname); - if (ai->ai_addr != NULL) - free (ai->ai_addr); - free (ai); - ai = next; - } -} - -const char * -gai_strerror (int ecode) -{ - static const char *eai_descr[] = - { - "no error", - "address family for nodename not supported", /* EAI_ADDRFAMILY */ - "temporary failure in name resolution", /* EAI_AGAIN */ - "invalid value for ai_flags", /* EAI_BADFLAGS */ - "non-recoverable failure in name resolution", /* EAI_FAIL */ - "ai_family not supported", /* EAI_FAMILY */ - "memory allocation failure", /* EAI_MEMORY */ - "no address associated with nodename", /* EAI_NODATA */ - "nodename nor servname provided, or not known", /* EAI_NONAME */ - "servname not supported for ai_socktype", /* EAI_SERVICE */ - "ai_socktype not supported", /* EAI_SOCKTYPE */ - "system error returned in errno", /* EAI_SYSTEM */ - }; - - if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0])) - return "unknown error"; - return eai_descr[ecode]; -} 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 @@ -#ifndef _getaddrinfo_h -#define _getaddrinfo_h -/* - * This file is part of libESMTP, a library for submission of RFC 2822 - * formatted electronic mail messages using the SMTP protocol described - * in RFC 2821. - * Modified by Jeremy T. Bouse for use in Nagios plugins - * - * Copyright (C) 2001,2002 Brian Stafford - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* Structure and prototypes aken from RFC 2553 - * - * $Id$ - */ - -struct addrinfo - { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ - size_t ai_addrlen; /* length of ai_addr */ - char *ai_canonname; /* canonical name for nodename */ - struct sockaddr *ai_addr; /* binary address */ - struct addrinfo *ai_next; /* next structure in linked list */ - }; - -/* Supposed to be defined in */ -#define AI_PASSIVE 1 /* Socket address is intended for `bind'. */ -#define AI_CANONNAME 2 /* Request for canonical name. */ -#define AI_NUMERICHOST 4 /* Don't use name resolution. */ - -/* Supposed to be defined in */ -#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */ -#define EAI_AGAIN 2 /* temporary failure in name resolution */ -#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ -#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ -#define EAI_FAMILY 5 /* ai_family not supported */ -#define EAI_MEMORY 6 /* memory allocation failure */ -#define EAI_NODATA 7 /* no address associated with nodename */ -#define EAI_NONAME 8 /* nodename nor servname provided, or not known */ -#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ -#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ -#define EAI_SYSTEM 11 /* system error returned in errno */ - -/* RFC 2553 / Posix resolver */ -int getaddrinfo (const char *nodename, const char *servname, - const struct addrinfo *hints, struct addrinfo **res); - -/* Free addrinfo structure and associated storage */ -void freeaddrinfo (struct addrinfo *ai); - -/* Convert error return from getaddrinfo() to string */ -const char *gai_strerror (int code); - -#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 @@ -/****************************************************************************** -* -* Nagios gethostbyname_r()'s prototype. -* -* License: GPL -* Copyright (C) 2001,2002 Brian Stafford -* -* Last Modified: $Date$ -* -* Description: -* -* This file is a ghastly hack because nobody can agree on -* gethostbyname_r()'s prototype. -* -* License Information: -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -* -* $Id$ -* -*****************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#define _SVID_SOURCE 1 /* Need this to get gethostbyname_r() */ - -#include - -#include -#include -#include -#include - -#include "gethostbyname.h" - -#if HAVE_GETIPNODEBYNAME - -void -free_ghbnctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - if (ctx->hostent != NULL) - freehostent (ctx->hostent); -} - -struct hostent * -gethostbyname_ctx (const char *host, struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - memset (ctx, 0, sizeof (struct ghbnctx)); - ctx->hostent = getipnodebyname (host, AF_UNSPEC, AI_ADDRCONFIG, &ctx->h_err); - return ctx->hostent; -} - -int -h_error_ctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - return ctx->h_err; -} - -#elif HAVE_GETHOSTBYNAME_R == 6 - -void -free_ghbnctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - if (ctx->hostbuf != NULL) - free (ctx->hostbuf); -} - -struct hostent * -gethostbyname_ctx (const char *host, struct ghbnctx *ctx) -{ - struct hostent *hp; - char *tmp; - int err; - - assert (ctx != NULL); - - memset (ctx, 0, sizeof (struct ghbnctx)); - ctx->hostbuf_len = 2048; - if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL) - { - errno = ENOMEM; - return NULL; - } - while ((err = gethostbyname_r (host, - &ctx->hostent, ctx->hostbuf, ctx->hostbuf_len, - &hp, &ctx->h_err)) == ERANGE) - { - ctx->hostbuf_len += 1024; - if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL) - { - errno = ENOMEM; - return NULL; - } - ctx->hostbuf = tmp; - } - if (err != 0) - { - errno = err; - return NULL; - } - return hp; -} - -int -h_error_ctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - return ctx->h_err; -} - -#elif HAVE_GETHOSTBYNAME_R == 5 - -void -free_ghbnctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - if (ctx->hostbuf != NULL) - free (ctx->hostbuf); -} - -struct hostent * -gethostbyname_ctx (const char *host, struct ghbnctx *ctx) -{ - struct hostent *hp; - char *tmp; - - assert (ctx != NULL); - - memset (ctx, 0, sizeof (struct ghbnctx)); - ctx->hostbuf_len = 2048; - if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL) - { - errno = ENOMEM; - return NULL; - } - while ((hp = gethostbyname_r (host, &ctx->hostent, - ctx->hostbuf, ctx->hostbuf_len, - &ctx->h_err)) == NULL && errno == ERANGE) - { - ctx->hostbuf_len += 1024; - if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL) - { - errno = ENOMEM; - return NULL; - } - ctx->hostbuf = tmp; - } - return hp; -} - -int -h_error_ctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - return ctx->h_err; -} - -#elif HAVE_GETHOSTBYNAME_R == 3 - -void -free_ghbnctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - /* FIXME: does this need to do anything? */ -} - -struct hostent * -gethostbyname_ctx (const char *host, struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - if (!gethostbyname_r (host, &ctx->hostent, &ctx->hostent_data)) - { - ctx->h_err = h_errno; /* FIXME: is this correct? */ - return NULL; - } - return &ctx->hostent; -} - -int -h_error_ctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - return ctx->h_err; -} - -#else - -void -free_ghbnctx (struct ghbnctx *ctx __attribute__ ((unused))) -{ - assert (ctx != NULL); -} - -struct hostent * -gethostbyname_ctx (const char *host, struct ghbnctx *ctx) -{ - struct hostent *hp; - - hp = gethostbyname (host); - if (hp == NULL) - ctx->h_err = h_errno; - return hp; -} - -int -h_error_ctx (struct ghbnctx *ctx) -{ - assert (ctx != NULL); - - return ctx->h_err; -} - -#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 @@ -/****************************************************************************** -* -* Nagios gethostbyname_r()'s prototype. -* -* License: GPL -* Copyright (C) 2001,2002 Brian Stafford -* -* Last Modified: $Date$ -* -* Description: -* -* This file is a ghastly hack because nobody can agree on -* gethostbyname_r()'s prototype. -* -* License Information: -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -* -* $Id$ -*****************************************************************************/ - -/************************************************************************* - Usage: - - #include - #include "gethostbyname.h" - - f () - { - struct ghbnctx ctx; - - errno = 0; - hp = gethostbyname_ctx (host, &ctx); - if (hp == NULL) - { - if (errno != 0) - handle_value_of_errno (errno); - else - handle_value_of_h_errno (h_error_ctx (&ctx)); - } - else - { - ... - } - free_ghbnctx (&ctx); - } - *************************************************************************/ - -#ifndef _gethostbyname_h -#define _gethostbyname_h - -#if HAVE_GETIPNODEBYNAME - -struct ghbnctx - { - int h_err; - struct hostent *hostent; - }; - -#elif HAVE_GETHOSTBYNAME_R == 6 - -struct ghbnctx - { - int h_err; - struct hostent hostent; - char *hostbuf; - size_t hostbuf_len; - }; - -#elif HAVE_GETHOSTBYNAME_R == 5 - -struct ghbnctx - { - int h_err; - struct hostent hostent; - char *hostbuf; - int hostbuf_len; - }; - -#elif HAVE_GETHOSTBYNAME_R == 3 - -struct ghbnctx - { - int h_err; - struct hostent_data hostent_data; - struct hostent hostent; - }; - -#else - -struct ghbnctx - { - int h_err; - }; - -#endif - -struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx); -int h_error_ctx (struct ghbnctx *ctx); -void free_ghbnctx (struct ghbnctx *ctx); - -#endif - 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 @@ #include "utils.h" #include #include +#include "getaddrinfo.h" #ifdef HAVE_SYS_UN_H # include diff --git a/tools/setup b/tools/setup index 94bd077..7fdb980 100755 --- a/tools/setup +++ b/tools/setup @@ -18,17 +18,13 @@ else echo Found GNU Make at $MAKE ... good. fi -( cd m4 && $MAKE -f Makefile.am.in Makefile.am ) - # This bit is to fix SF's compile server as libtool not installed by default extra="" if test -d $HOME/share/aclocal ; then extra="-I $HOME/share/aclocal" fi -# I think gettext no longer necessary, as all necessary files imported from coreutils -#autopoint --force -aclocal -I m4 $extra +aclocal -I gl/m4 -I m4 $extra #libtoolize --force --copy autoheader 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 @@ -#!/bin/bash -# Quick script to copy coreutil files into Nagios area -# Pass $1 as top level of coreutils source dir -# Expects to be run in the lib directory - -function die { echo $1; exit 1; } - -function copy_if_newer { [[ $1 -nt $2 ]] && cp $1 $2; } - -coreutils_dir=$1 - -[[ -z $coreutils_dir ]] && die "Please specify coreutils directory" - -cwd=`pwd` - -[[ ${cwd##*/} != "lib" ]] && die "Must be run in lib directory" - -# Get list of files from EXTRA_DIST in Makefile.am -# Need \\\ because the perl needs \\ but one is escaped -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`" - -for i in $files ; do - if [[ -e $coreutils_dir/lib/$i ]] ; then - copy_if_newer $coreutils_dir/lib/$i ./$i - elif [[ -e $coreutils_dir/m4/$i ]] ; then - copy_if_newer $coreutils_dir/m4/$i ./$i - else - echo "Not found: $i" - fi -done - -- 2.30.2