mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Add all auto-generated files
The auto-generated files are created by running ./build-aux/bootstrap with Gnulib as at commit d72683055ea46253d8eb8f89341eff5414ae6ca0 (with a date stamp of Sun Jul 24 23:37:17 2011 +0200), Autoconf 2.68 and Automake 1.11.1.
This commit is contained in:
parent
e0b75aa783
commit
c7f2343052
15
.gitignore
vendored
15
.gitignore
vendored
@ -2,26 +2,11 @@
|
||||
*.a
|
||||
.deps/
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
||||
/aclocal.m4
|
||||
/autom4te.cache
|
||||
/config.h
|
||||
/config.h.in
|
||||
/config.log
|
||||
/config.status
|
||||
/configure
|
||||
/stamp-h1
|
||||
|
||||
/build-aux/config.guess
|
||||
/build-aux/config.sub
|
||||
/build-aux/depcomp
|
||||
/build-aux/install-sh
|
||||
/build-aux/missing
|
||||
|
||||
/build-aux/snippet/arg-nonnull.h
|
||||
/build-aux/snippet/c++defs.h
|
||||
/build-aux/snippet/warn-on-use.h
|
||||
/build-aux/snippet/_Noreturn.h
|
||||
|
||||
/src/trader
|
||||
|
1440
Makefile.in
Normal file
1440
Makefile.in
Normal file
File diff suppressed because it is too large
Load Diff
1023
aclocal.m4
vendored
Normal file
1023
aclocal.m4
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1517
build-aux/config.guess
vendored
Executable file
1517
build-aux/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1760
build-aux/config.sub
vendored
Executable file
1760
build-aux/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
630
build-aux/depcomp
Executable file
630
build-aux/depcomp
Executable file
@ -0,0 +1,630 @@
|
||||
#! /bin/sh
|
||||
# depcomp - compile a program generating dependencies as side-effects
|
||||
|
||||
scriptversion=2009-04-28.21; # UTC
|
||||
|
||||
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# 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.
|
||||
|
||||
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||
as side-effects.
|
||||
|
||||
Environment variables:
|
||||
depmode Dependency tracking mode.
|
||||
source Source file read by `PROGRAMS ARGS'.
|
||||
object Object file output by `PROGRAMS ARGS'.
|
||||
DEPDIR directory where to store dependencies.
|
||||
depfile Dependency file to output.
|
||||
tmpdepfile Temporary file to use when outputing dependencies.
|
||||
libtool Whether libtool is used (yes/no).
|
||||
|
||||
Report bugs to <bug-automake@gnu.org>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "depcomp $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||
depfile=${depfile-`echo "$object" |
|
||||
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||
|
||||
rm -f "$tmpdepfile"
|
||||
|
||||
# Some modes work just like other modes, but use different flags. We
|
||||
# parameterize here, but still list the modes in the big case below,
|
||||
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||
# here, because this file can only contain one case statement.
|
||||
if test "$depmode" = hp; then
|
||||
# HP compiler uses -M and no extra arg.
|
||||
gccflag=-M
|
||||
depmode=gcc
|
||||
fi
|
||||
|
||||
if test "$depmode" = dashXmstdout; then
|
||||
# This is just like dashmstdout with a different argument.
|
||||
dashmflag=-xM
|
||||
depmode=dashmstdout
|
||||
fi
|
||||
|
||||
cygpath_u="cygpath -u -f -"
|
||||
if test "$depmode" = msvcmsys; then
|
||||
# This is just like msvisualcpp but w/o cygpath translation.
|
||||
# Just convert the backslash-escaped backslashes to single forward
|
||||
# slashes to satisfy depend.m4
|
||||
cygpath_u="sed s,\\\\\\\\,/,g"
|
||||
depmode=msvisualcpp
|
||||
fi
|
||||
|
||||
case "$depmode" in
|
||||
gcc3)
|
||||
## gcc 3 implements dependency tracking that does exactly what
|
||||
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||
## the command line argument order; so add the flags where they
|
||||
## appear in depend2.am. Note that the slowdown incurred here
|
||||
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||
*) set fnord "$@" "$arg" ;;
|
||||
esac
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
done
|
||||
"$@"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
mv "$tmpdepfile" "$depfile"
|
||||
;;
|
||||
|
||||
gcc)
|
||||
## There are various ways to get dependency output from gcc. Here's
|
||||
## why we pick this rather obscure method:
|
||||
## - Don't want to use -MD because we'd like the dependencies to end
|
||||
## up in a subdir. Having to rename by hand is ugly.
|
||||
## (We might end up doing this anyway to support other compilers.)
|
||||
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||
## -MM, not -M (despite what the docs say).
|
||||
## - Using -M directly means running the compiler twice (even worse
|
||||
## than renaming).
|
||||
if test -z "$gccflag"; then
|
||||
gccflag=-MD,
|
||||
fi
|
||||
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
## The second -e expression handles DOS-style file names with drive letters.
|
||||
sed -e 's/^[^:]*: / /' \
|
||||
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||
## This next piece of magic avoids the `deleted header file' problem.
|
||||
## The problem is that when a header file which appears in a .P file
|
||||
## is deleted, the dependency causes make to die (because there is
|
||||
## typically no way to rebuild the header). We avoid this by adding
|
||||
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||
## this for us directly.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" |
|
||||
## Some versions of gcc put a space before the `:'. On the theory
|
||||
## that the space means something, we add a space to the output as
|
||||
## well.
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
sgi)
|
||||
if test "$libtool" = yes; then
|
||||
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||
else
|
||||
"$@" -MDupdate "$tmpdepfile"
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
|
||||
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||
echo "$object : \\" > "$depfile"
|
||||
|
||||
# Clip off the initial element (the dependent). Don't try to be
|
||||
# clever and replace this with sed code, as IRIX sed won't handle
|
||||
# lines with more than a fixed number of characters (4096 in
|
||||
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||
# the IRIX cc adds comments like `#:fec' to the end of the
|
||||
# dependency line.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
|
||||
tr '
|
||||
' ' ' >> "$depfile"
|
||||
echo >> "$depfile"
|
||||
|
||||
# The second pass generates a dummy entry for each header file.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||
>> "$depfile"
|
||||
else
|
||||
# The sourcefile does not contain any dependencies, so just
|
||||
# store a dummy comment line, to avoid errors with the Makefile
|
||||
# "include basename.Plo" scheme.
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
aix)
|
||||
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||
# in a .u file. In older versions, this file always lives in the
|
||||
# current directory. Also, the AIX compiler puts `$object:' at the
|
||||
# start of each line; $object doesn't have directory information.
|
||||
# Version 6 uses the directory in both cases.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$base.u
|
||||
tmpdepfile3=$dir.libs/$base.u
|
||||
"$@" -Wc,-M
|
||||
else
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$dir$base.u
|
||||
tmpdepfile3=$dir$base.u
|
||||
"$@" -M
|
||||
fi
|
||||
stat=$?
|
||||
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
# Each line is of the form `foo.o: dependent.h'.
|
||||
# Do two passes, one to just change these to
|
||||
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||
# That's a tab and a space in the [].
|
||||
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
# The sourcefile does not contain any dependencies, so just
|
||||
# store a dummy comment line, to avoid errors with the Makefile
|
||||
# "include basename.Plo" scheme.
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
icc)
|
||||
# Intel's C compiler understands `-MD -MF file'. However on
|
||||
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
|
||||
# ICC 7.0 will fill foo.d with something like
|
||||
# foo.o: sub/foo.c
|
||||
# foo.o: sub/foo.h
|
||||
# which is wrong. We want:
|
||||
# sub/foo.o: sub/foo.c
|
||||
# sub/foo.o: sub/foo.h
|
||||
# sub/foo.c:
|
||||
# sub/foo.h:
|
||||
# ICC 7.1 will output
|
||||
# foo.o: sub/foo.c sub/foo.h
|
||||
# and will wrap long lines using \ :
|
||||
# foo.o: sub/foo.c ... \
|
||||
# sub/foo.h ... \
|
||||
# ...
|
||||
|
||||
"$@" -MD -MF "$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
# Each line is of the form `foo.o: dependent.h',
|
||||
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||
# Do two passes, one to just change these to
|
||||
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
# correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
|
||||
sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp2)
|
||||
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||
# compilers, which have integrated preprocessors. The correct option
|
||||
# to use with these is +Maked; it writes dependencies to a file named
|
||||
# 'foo.d', which lands next to the object file, wherever that
|
||||
# happens to be.
|
||||
# Much of this is similar to the tru64 case; see comments there.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir.libs/$base.d
|
||||
"$@" -Wc,+Maked
|
||||
else
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
"$@" +Maked
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||
# Add `dependent.h:' lines.
|
||||
sed -ne '2,${
|
||||
s/^ *//
|
||||
s/ \\*$//
|
||||
s/$/:/
|
||||
p
|
||||
}' "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||
;;
|
||||
|
||||
tru64)
|
||||
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
|
||||
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||
# dependencies in `foo.d' instead, so we check for that too.
|
||||
# Subdirectories are respected.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
|
||||
if test "$libtool" = yes; then
|
||||
# With Tru64 cc, shared objects can also be used to make a
|
||||
# static library. This mechanism is used in libtool 1.4 series to
|
||||
# handle both shared and static libraries in a single compilation.
|
||||
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
|
||||
#
|
||||
# With libtool 1.5 this exception was removed, and libtool now
|
||||
# generates 2 separate objects for the 2 libraries. These two
|
||||
# compilations output dependencies in $dir.libs/$base.o.d and
|
||||
# in $dir$base.o.d. We have to check for both files, because
|
||||
# one of the two compilations can be disabled. We should prefer
|
||||
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||
# the former would cause a distcleancheck panic.
|
||||
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
|
||||
tmpdepfile2=$dir$base.o.d # libtool 1.5
|
||||
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
|
||||
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||
"$@" -Wc,-MD
|
||||
else
|
||||
tmpdepfile1=$dir$base.o.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
tmpdepfile3=$dir$base.d
|
||||
tmpdepfile4=$dir$base.d
|
||||
"$@" -MD
|
||||
fi
|
||||
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||
# That's a tab and a space in the [].
|
||||
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
#nosideeffect)
|
||||
# This comment above is used by automake to tell side-effect
|
||||
# dependency tracking mechanisms from slower ones.
|
||||
|
||||
dashmstdout)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout, regardless of -o.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove `-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
test -z "$dashmflag" && dashmflag=-M
|
||||
# Require at least two characters before searching for `:'
|
||||
# in the target name. This is to cope with DOS-style filenames:
|
||||
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
|
||||
"$@" $dashmflag |
|
||||
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
cat < "$tmpdepfile" > "$depfile"
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" | \
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
dashXmstdout)
|
||||
# This case only exists to satisfy depend.m4. It is never actually
|
||||
# run, as this mode is specially recognized in the preamble.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
makedepend)
|
||||
"$@" || exit $?
|
||||
# Remove any Libtool call
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
# X makedepend
|
||||
shift
|
||||
cleared=no eat=no
|
||||
for arg
|
||||
do
|
||||
case $cleared in
|
||||
no)
|
||||
set ""; shift
|
||||
cleared=yes ;;
|
||||
esac
|
||||
if test $eat = yes; then
|
||||
eat=no
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-D*|-I*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
# Strip any option that makedepend may not understand. Remove
|
||||
# the object too, otherwise makedepend will parse it as a source file.
|
||||
-arch)
|
||||
eat=yes ;;
|
||||
-*|$object)
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
esac
|
||||
done
|
||||
obj_suffix=`echo "$object" | sed 's/^.*\././'`
|
||||
touch "$tmpdepfile"
|
||||
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||
rm -f "$depfile"
|
||||
cat < "$tmpdepfile" > "$depfile"
|
||||
sed '1,2d' "$tmpdepfile" | tr ' ' '
|
||||
' | \
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||
;;
|
||||
|
||||
cpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove `-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
"$@" -E |
|
||||
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
|
||||
sed '$ s: \\$::' > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
cat < "$tmpdepfile" >> "$depfile"
|
||||
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvisualcpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case "$arg" in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||
set fnord "$@"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
"$@" -E 2>/dev/null |
|
||||
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
|
||||
echo " " >> "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvcmsys)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
none)
|
||||
exec "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown depmode $depmode" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
520
build-aux/install-sh
Executable file
520
build-aux/install-sh
Executable file
@ -0,0 +1,520 @@
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
|
||||
scriptversion=2009-04-28.21; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
# following copyright and license.
|
||||
#
|
||||
# Copyright (C) 1994 X Consortium
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
# Except as contained in this notice, the name of the X Consortium shall not
|
||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
# ings in this Software without prior written authorization from the X Consor-
|
||||
# tium.
|
||||
#
|
||||
#
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
|
||||
nl='
|
||||
'
|
||||
IFS=" "" $nl"
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit=${DOITPROG-}
|
||||
if test -z "$doit"; then
|
||||
doit_exec=exec
|
||||
else
|
||||
doit_exec=$doit
|
||||
fi
|
||||
|
||||
# Put in absolute file names if you don't have them in your path;
|
||||
# or use environment vars.
|
||||
|
||||
chgrpprog=${CHGRPPROG-chgrp}
|
||||
chmodprog=${CHMODPROG-chmod}
|
||||
chownprog=${CHOWNPROG-chown}
|
||||
cmpprog=${CMPPROG-cmp}
|
||||
cpprog=${CPPROG-cp}
|
||||
mkdirprog=${MKDIRPROG-mkdir}
|
||||
mvprog=${MVPROG-mv}
|
||||
rmprog=${RMPROG-rm}
|
||||
stripprog=${STRIPPROG-strip}
|
||||
|
||||
posix_glob='?'
|
||||
initialize_posix_glob='
|
||||
test "$posix_glob" != "?" || {
|
||||
if (set -f) 2>/dev/null; then
|
||||
posix_glob=
|
||||
else
|
||||
posix_glob=:
|
||||
fi
|
||||
}
|
||||
'
|
||||
|
||||
posix_mkdir=
|
||||
|
||||
# Desired mode of installed file.
|
||||
mode=0755
|
||||
|
||||
chgrpcmd=
|
||||
chmodcmd=$chmodprog
|
||||
chowncmd=
|
||||
mvcmd=$mvprog
|
||||
rmcmd="$rmprog -f"
|
||||
stripcmd=
|
||||
|
||||
src=
|
||||
dst=
|
||||
dir_arg=
|
||||
dst_arg=
|
||||
|
||||
copy_on_change=false
|
||||
no_target_directory=
|
||||
|
||||
usage="\
|
||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||
or: $0 [OPTION]... -d DIRECTORIES...
|
||||
|
||||
In the 1st form, copy SRCFILE to DSTFILE.
|
||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||
In the 4th, create DIRECTORIES.
|
||||
|
||||
Options:
|
||||
--help display this help and exit.
|
||||
--version display version info and exit.
|
||||
|
||||
-c (ignored)
|
||||
-C install only if different (preserve the last data modification time)
|
||||
-d create directories instead of installing files.
|
||||
-g GROUP $chgrpprog installed files to GROUP.
|
||||
-m MODE $chmodprog installed files to MODE.
|
||||
-o USER $chownprog installed files to USER.
|
||||
-s $stripprog installed files.
|
||||
-t DIRECTORY install into DIRECTORY.
|
||||
-T report an error if DSTFILE is a directory.
|
||||
|
||||
Environment variables override the default commands:
|
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||
RMPROG STRIPPROG
|
||||
"
|
||||
|
||||
while test $# -ne 0; do
|
||||
case $1 in
|
||||
-c) ;;
|
||||
|
||||
-C) copy_on_change=true;;
|
||||
|
||||
-d) dir_arg=true;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift;;
|
||||
|
||||
--help) echo "$usage"; exit $?;;
|
||||
|
||||
-m) mode=$2
|
||||
case $mode in
|
||||
*' '* | *' '* | *'
|
||||
'* | *'*'* | *'?'* | *'['*)
|
||||
echo "$0: invalid mode: $mode" >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift;;
|
||||
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-t) dst_arg=$2
|
||||
shift;;
|
||||
|
||||
-T) no_target_directory=true;;
|
||||
|
||||
--version) echo "$0 $scriptversion"; exit $?;;
|
||||
|
||||
--) shift
|
||||
break;;
|
||||
|
||||
-*) echo "$0: invalid option: $1" >&2
|
||||
exit 1;;
|
||||
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||
# When -d is used, all remaining arguments are directories to create.
|
||||
# When -t is used, the destination is already specified.
|
||||
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||
for arg
|
||||
do
|
||||
if test -n "$dst_arg"; then
|
||||
# $@ is not empty: it contains at least $arg.
|
||||
set fnord "$@" "$dst_arg"
|
||||
shift # fnord
|
||||
fi
|
||||
shift # arg
|
||||
dst_arg=$arg
|
||||
done
|
||||
fi
|
||||
|
||||
if test $# -eq 0; then
|
||||
if test -z "$dir_arg"; then
|
||||
echo "$0: no input file specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
# It's OK to call `install-sh -d' without argument.
|
||||
# This can happen when creating conditional directories.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "$dir_arg"; then
|
||||
trap '(exit $?); exit' 1 2 13 15
|
||||
|
||||
# Set umask so as not to create temps with too-generous modes.
|
||||
# However, 'strip' requires both read and write access to temps.
|
||||
case $mode in
|
||||
# Optimize common cases.
|
||||
*644) cp_umask=133;;
|
||||
*755) cp_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw='% 200'
|
||||
fi
|
||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||
*)
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw=,u+rw
|
||||
fi
|
||||
cp_umask=$mode$u_plus_rw;;
|
||||
esac
|
||||
fi
|
||||
|
||||
for src
|
||||
do
|
||||
# Protect names starting with `-'.
|
||||
case $src in
|
||||
-*) src=./$src;;
|
||||
esac
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
dst=$src
|
||||
dstdir=$dst
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
if test ! -f "$src" && test ! -d "$src"; then
|
||||
echo "$0: $src does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$dst_arg"; then
|
||||
echo "$0: no destination specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dst=$dst_arg
|
||||
# Protect names starting with `-'.
|
||||
case $dst in
|
||||
-*) dst=./$dst;;
|
||||
esac
|
||||
|
||||
# If destination is a directory, append the input filename; won't work
|
||||
# if double slashes aren't ignored.
|
||||
if test -d "$dst"; then
|
||||
if test -n "$no_target_directory"; then
|
||||
echo "$0: $dst_arg: Is a directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
dstdir=$dst
|
||||
dst=$dstdir/`basename "$src"`
|
||||
dstdir_status=0
|
||||
else
|
||||
# Prefer dirname, but fall back on a substitute if dirname fails.
|
||||
dstdir=`
|
||||
(dirname "$dst") 2>/dev/null ||
|
||||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
||||
X"$dst" : 'X\(//\)[^/]' \| \
|
||||
X"$dst" : 'X\(//\)$' \| \
|
||||
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
|
||||
echo X"$dst" |
|
||||
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\/\)[^/].*/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\/\)$/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\).*/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
s/.*/./; q'
|
||||
`
|
||||
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
obsolete_mkdir_used=false
|
||||
|
||||
if test $dstdir_status != 0; then
|
||||
case $posix_mkdir in
|
||||
'')
|
||||
# Create intermediate dirs using mode 755 as modified by the umask.
|
||||
# This is like FreeBSD 'install' as of 1997-10-28.
|
||||
umask=`umask`
|
||||
case $stripcmd.$umask in
|
||||
# Optimize common cases.
|
||||
*[2367][2367]) mkdir_umask=$umask;;
|
||||
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
mkdir_umask=`expr $umask + 22 \
|
||||
- $umask % 100 % 40 + $umask % 20 \
|
||||
- $umask % 10 % 4 + $umask % 2
|
||||
`;;
|
||||
*) mkdir_umask=$umask,go-w;;
|
||||
esac
|
||||
|
||||
# With -d, create the new directory with the user-specified mode.
|
||||
# Otherwise, rely on $mkdir_umask.
|
||||
if test -n "$dir_arg"; then
|
||||
mkdir_mode=-m$mode
|
||||
else
|
||||
mkdir_mode=
|
||||
fi
|
||||
|
||||
posix_mkdir=false
|
||||
case $umask in
|
||||
*[123567][0-7][0-7])
|
||||
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
||||
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
||||
;;
|
||||
*)
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
|
||||
|
||||
if (umask $mkdir_umask &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
|
||||
then
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writeable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/d" "$tmpdir"
|
||||
else
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac;;
|
||||
esac
|
||||
|
||||
if
|
||||
$posix_mkdir && (
|
||||
umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||
)
|
||||
then :
|
||||
else
|
||||
|
||||
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
||||
# or it failed possibly due to a race condition. Create the
|
||||
# directory the slow way, step by step, checking for races as we go.
|
||||
|
||||
case $dstdir in
|
||||
/*) prefix='/';;
|
||||
-*) prefix='./';;
|
||||
*) prefix='';;
|
||||
esac
|
||||
|
||||
eval "$initialize_posix_glob"
|
||||
|
||||
oIFS=$IFS
|
||||
IFS=/
|
||||
$posix_glob set -f
|
||||
set fnord $dstdir
|
||||
shift
|
||||
$posix_glob set +f
|
||||
IFS=$oIFS
|
||||
|
||||
prefixes=
|
||||
|
||||
for d
|
||||
do
|
||||
test -z "$d" && continue
|
||||
|
||||
prefix=$prefix$d
|
||||
if test -d "$prefix"; then
|
||||
prefixes=
|
||||
else
|
||||
if $posix_mkdir; then
|
||||
(umask=$mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||
# Don't fail if two instances are running concurrently.
|
||||
test -d "$prefix" || exit 1
|
||||
else
|
||||
case $prefix in
|
||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||
*) qprefix=$prefix;;
|
||||
esac
|
||||
prefixes="$prefixes '$qprefix'"
|
||||
fi
|
||||
fi
|
||||
prefix=$prefix/
|
||||
done
|
||||
|
||||
if test -n "$prefixes"; then
|
||||
# Don't fail if two instances are running concurrently.
|
||||
(umask $mkdir_umask &&
|
||||
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||
test -d "$dstdir" || exit 1
|
||||
obsolete_mkdir_used=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||
else
|
||||
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
dsttmp=$dstdir/_inst.$$_
|
||||
rmtmp=$dstdir/_rm.$$_
|
||||
|
||||
# Trap to clean up those temp files at exit.
|
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||
|
||||
# Copy the file name to the temp name.
|
||||
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits.
|
||||
#
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||
#
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||
|
||||
# If -C, don't bother to copy if it wouldn't change the file.
|
||||
if $copy_on_change &&
|
||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||
|
||||
eval "$initialize_posix_glob" &&
|
||||
$posix_glob set -f &&
|
||||
set X $old && old=:$2:$4:$5:$6 &&
|
||||
set X $new && new=:$2:$4:$5:$6 &&
|
||||
$posix_glob set +f &&
|
||||
|
||||
test "$old" = "$new" &&
|
||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||
then
|
||||
rm -f "$dsttmp"
|
||||
else
|
||||
# Rename the file to the real destination.
|
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||
|
||||
# The rename failed, perhaps because mv can't rename something else
|
||||
# to itself, or perhaps because mv is so ancient that it does not
|
||||
# support -f.
|
||||
{
|
||||
# Now remove or move aside any old file at destination location.
|
||||
# We try this two ways since rm can't unlink itself on some
|
||||
# systems and the destination file might be busy for other
|
||||
# reasons. In this case, the final cleanup might fail but the new
|
||||
# file should still install successfully.
|
||||
{
|
||||
test ! -f "$dst" ||
|
||||
$doit $rmcmd -f "$dst" 2>/dev/null ||
|
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
|
||||
} ||
|
||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||
(exit 1); exit 1
|
||||
}
|
||||
} &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
$doit $mvcmd "$dsttmp" "$dst"
|
||||
}
|
||||
fi || exit 1
|
||||
|
||||
trap '' 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
376
build-aux/missing
Executable file
376
build-aux/missing
Executable file
@ -0,0 +1,376 @@
|
||||
#! /bin/sh
|
||||
# Common stub for a few missing GNU programs while installing.
|
||||
|
||||
scriptversion=2009-04-28.21; # UTC
|
||||
|
||||
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
|
||||
# 2008, 2009 Free Software Foundation, Inc.
|
||||
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 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, 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# 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.
|
||||
|
||||
if test $# -eq 0; then
|
||||
echo 1>&2 "Try \`$0 --help' for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
run=:
|
||||
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
|
||||
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
|
||||
|
||||
# In the cases where this matters, `missing' is being run in the
|
||||
# srcdir already.
|
||||
if test -f configure.ac; then
|
||||
configure_ac=configure.ac
|
||||
else
|
||||
configure_ac=configure.in
|
||||
fi
|
||||
|
||||
msg="missing on your system"
|
||||
|
||||
case $1 in
|
||||
--run)
|
||||
# Try to run requested program, and just exit if it succeeds.
|
||||
run=
|
||||
shift
|
||||
"$@" && exit 0
|
||||
# Exit code 63 means version mismatch. This often happens
|
||||
# when the user try to use an ancient version of a tool on
|
||||
# a file that requires a minimum version. In this case we
|
||||
# we should proceed has if the program had been absent, or
|
||||
# if --run hadn't been passed.
|
||||
if test $? = 63; then
|
||||
run=:
|
||||
msg="probably too old"
|
||||
fi
|
||||
;;
|
||||
|
||||
-h|--h|--he|--hel|--help)
|
||||
echo "\
|
||||
$0 [OPTION]... PROGRAM [ARGUMENT]...
|
||||
|
||||
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
|
||||
error status if there is no known handling for PROGRAM.
|
||||
|
||||
Options:
|
||||
-h, --help display this help and exit
|
||||
-v, --version output version information and exit
|
||||
--run try to run the given command, and emulate it if it fails
|
||||
|
||||
Supported PROGRAM values:
|
||||
aclocal touch file \`aclocal.m4'
|
||||
autoconf touch file \`configure'
|
||||
autoheader touch file \`config.h.in'
|
||||
autom4te touch the output file, or create a stub one
|
||||
automake touch all \`Makefile.in' files
|
||||
bison create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||
flex create \`lex.yy.c', if possible, from existing .c
|
||||
help2man touch the output file
|
||||
lex create \`lex.yy.c', if possible, from existing .c
|
||||
makeinfo touch the output file
|
||||
tar try tar, gnutar, gtar, then tar without non-portable flags
|
||||
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||
|
||||
Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
|
||||
\`g' are ignored when checking the name.
|
||||
|
||||
Send bug reports to <bug-automake@gnu.org>."
|
||||
exit $?
|
||||
;;
|
||||
|
||||
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
|
||||
echo "missing $scriptversion (GNU Automake)"
|
||||
exit $?
|
||||
;;
|
||||
|
||||
-*)
|
||||
echo 1>&2 "$0: Unknown \`$1' option"
|
||||
echo 1>&2 "Try \`$0 --help' for more information"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
# normalize program name to check for.
|
||||
program=`echo "$1" | sed '
|
||||
s/^gnu-//; t
|
||||
s/^gnu//; t
|
||||
s/^g//; t'`
|
||||
|
||||
# Now exit if we have it, but it failed. Also exit now if we
|
||||
# don't have it and --version was passed (most likely to detect
|
||||
# the program). This is about non-GNU programs, so use $1 not
|
||||
# $program.
|
||||
case $1 in
|
||||
lex*|yacc*)
|
||||
# Not GNU programs, they don't have --version.
|
||||
;;
|
||||
|
||||
tar*)
|
||||
if test -n "$run"; then
|
||||
echo 1>&2 "ERROR: \`tar' requires --run"
|
||||
exit 1
|
||||
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
|
||||
# We have it, but it failed.
|
||||
exit 1
|
||||
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||
# Could not run --version or --help. This is probably someone
|
||||
# running `$TOOL --version' or `$TOOL --help' to check whether
|
||||
# $TOOL exists and not knowing $TOOL uses missing.
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# If it does not exist, or fails to run (possibly an outdated version),
|
||||
# try to emulate it.
|
||||
case $program in
|
||||
aclocal*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
|
||||
to install the \`Automake' and \`Perl' packages. Grab them from
|
||||
any GNU archive site."
|
||||
touch aclocal.m4
|
||||
;;
|
||||
|
||||
autoconf*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified \`${configure_ac}'. You might want to install the
|
||||
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
|
||||
archive site."
|
||||
touch configure
|
||||
;;
|
||||
|
||||
autoheader*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified \`acconfig.h' or \`${configure_ac}'. You might want
|
||||
to install the \`Autoconf' and \`GNU m4' packages. Grab them
|
||||
from any GNU archive site."
|
||||
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
|
||||
test -z "$files" && files="config.h"
|
||||
touch_files=
|
||||
for f in $files; do
|
||||
case $f in
|
||||
*:*) touch_files="$touch_files "`echo "$f" |
|
||||
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
|
||||
*) touch_files="$touch_files $f.in";;
|
||||
esac
|
||||
done
|
||||
touch $touch_files
|
||||
;;
|
||||
|
||||
automake*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
|
||||
You might want to install the \`Automake' and \`Perl' packages.
|
||||
Grab them from any GNU archive site."
|
||||
find . -type f -name Makefile.am -print |
|
||||
sed 's/\.am$/.in/' |
|
||||
while read f; do touch "$f"; done
|
||||
;;
|
||||
|
||||
autom4te*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is needed, but is $msg.
|
||||
You might have modified some files without having the
|
||||
proper tools for further handling them.
|
||||
You can get \`$1' as part of \`Autoconf' from any GNU
|
||||
archive site."
|
||||
|
||||
file=`echo "$*" | sed -n "$sed_output"`
|
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||
if test -f "$file"; then
|
||||
touch $file
|
||||
else
|
||||
test -z "$file" || exec >$file
|
||||
echo "#! /bin/sh"
|
||||
echo "# Created by GNU Automake missing as a replacement of"
|
||||
echo "# $ $@"
|
||||
echo "exit 0"
|
||||
chmod +x $file
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
bison*|yacc*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' $msg. You should only need it if
|
||||
you modified a \`.y' file. You may need the \`Bison' package
|
||||
in order for those modifications to take effect. You can get
|
||||
\`Bison' from any GNU archive site."
|
||||
rm -f y.tab.c y.tab.h
|
||||
if test $# -ne 1; then
|
||||
eval LASTARG="\${$#}"
|
||||
case $LASTARG in
|
||||
*.y)
|
||||
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
|
||||
if test -f "$SRCFILE"; then
|
||||
cp "$SRCFILE" y.tab.c
|
||||
fi
|
||||
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
|
||||
if test -f "$SRCFILE"; then
|
||||
cp "$SRCFILE" y.tab.h
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if test ! -f y.tab.h; then
|
||||
echo >y.tab.h
|
||||
fi
|
||||
if test ! -f y.tab.c; then
|
||||
echo 'main() { return 0; }' >y.tab.c
|
||||
fi
|
||||
;;
|
||||
|
||||
lex*|flex*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified a \`.l' file. You may need the \`Flex' package
|
||||
in order for those modifications to take effect. You can get
|
||||
\`Flex' from any GNU archive site."
|
||||
rm -f lex.yy.c
|
||||
if test $# -ne 1; then
|
||||
eval LASTARG="\${$#}"
|
||||
case $LASTARG in
|
||||
*.l)
|
||||
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
|
||||
if test -f "$SRCFILE"; then
|
||||
cp "$SRCFILE" lex.yy.c
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if test ! -f lex.yy.c; then
|
||||
echo 'main() { return 0; }' >lex.yy.c
|
||||
fi
|
||||
;;
|
||||
|
||||
help2man*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified a dependency of a manual page. You may need the
|
||||
\`Help2man' package in order for those modifications to take
|
||||
effect. You can get \`Help2man' from any GNU archive site."
|
||||
|
||||
file=`echo "$*" | sed -n "$sed_output"`
|
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||
if test -f "$file"; then
|
||||
touch $file
|
||||
else
|
||||
test -z "$file" || exec >$file
|
||||
echo ".ab help2man is required to generate this page"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
|
||||
makeinfo*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is $msg. You should only need it if
|
||||
you modified a \`.texi' or \`.texinfo' file, or any other file
|
||||
indirectly affecting the aspect of the manual. The spurious
|
||||
call might also be the consequence of using a buggy \`make' (AIX,
|
||||
DU, IRIX). You might want to install the \`Texinfo' package or
|
||||
the \`GNU make' package. Grab either from any GNU archive site."
|
||||
# The file to touch is that specified with -o ...
|
||||
file=`echo "$*" | sed -n "$sed_output"`
|
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||
if test -z "$file"; then
|
||||
# ... or it is the one specified with @setfilename ...
|
||||
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
|
||||
file=`sed -n '
|
||||
/^@setfilename/{
|
||||
s/.* \([^ ]*\) *$/\1/
|
||||
p
|
||||
q
|
||||
}' $infile`
|
||||
# ... or it is derived from the source name (dir/f.texi becomes f.info)
|
||||
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
|
||||
fi
|
||||
# If the file does not exist, the user really needs makeinfo;
|
||||
# let's fail without touching anything.
|
||||
test -f $file || exit 1
|
||||
touch $file
|
||||
;;
|
||||
|
||||
tar*)
|
||||
shift
|
||||
|
||||
# We have already tried tar in the generic part.
|
||||
# Look for gnutar/gtar before invocation to avoid ugly error
|
||||
# messages.
|
||||
if (gnutar --version > /dev/null 2>&1); then
|
||||
gnutar "$@" && exit 0
|
||||
fi
|
||||
if (gtar --version > /dev/null 2>&1); then
|
||||
gtar "$@" && exit 0
|
||||
fi
|
||||
firstarg="$1"
|
||||
if shift; then
|
||||
case $firstarg in
|
||||
*o*)
|
||||
firstarg=`echo "$firstarg" | sed s/o//`
|
||||
tar "$firstarg" "$@" && exit 0
|
||||
;;
|
||||
esac
|
||||
case $firstarg in
|
||||
*h*)
|
||||
firstarg=`echo "$firstarg" | sed s/h//`
|
||||
tar "$firstarg" "$@" && exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo 1>&2 "\
|
||||
WARNING: I can't seem to be able to run \`tar' with the given arguments.
|
||||
You may want to install GNU tar or Free paxutils, or check the
|
||||
command line arguments."
|
||||
exit 1
|
||||
;;
|
||||
|
||||
*)
|
||||
echo 1>&2 "\
|
||||
WARNING: \`$1' is needed, and is $msg.
|
||||
You might have modified some files without having the
|
||||
proper tools for further handling them. Check the \`README' file,
|
||||
it often tells you about the needed prerequisites for installing
|
||||
this package. You may also peek at any GNU archive site, in case
|
||||
some other package would contain this missing \`$1' program."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
10
build-aux/snippet/_Noreturn.h
Normal file
10
build-aux/snippet/_Noreturn.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _Noreturn
|
||||
# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
|
||||
|| 0x5110 <= __SUNPRO_C)
|
||||
# define _Noreturn __attribute__ ((__noreturn__))
|
||||
# elif 1200 <= _MSC_VER
|
||||
# define _Noreturn __declspec (noreturn)
|
||||
# else
|
||||
# define _Noreturn
|
||||
# endif
|
||||
#endif
|
26
build-aux/snippet/arg-nonnull.h
Normal file
26
build-aux/snippet/arg-nonnull.h
Normal file
@ -0,0 +1,26 @@
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
271
build-aux/snippet/c++defs.h
Normal file
271
build-aux/snippet/c++defs.h
Normal file
@ -0,0 +1,271 @@
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
rettype (*const func) parameters = ::rpl_func; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
rettype (*const func) parameters = \
|
||||
reinterpret_cast<rettype(*)parameters>(::rpl_func); \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* If we were to write
|
||||
rettype (*const func) parameters = ::func;
|
||||
like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
|
||||
better (remove an indirection through a 'static' pointer variable),
|
||||
but then the _GL_CXXALIASWARN macro below would cause a warning not only
|
||||
for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static rettype (*func) parameters = ::func; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static rettype (*func) parameters = \
|
||||
reinterpret_cast<rettype(*)parameters>(::func); \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static rettype (*func) parameters = \
|
||||
reinterpret_cast<rettype(*)parameters>( \
|
||||
(rettype2(*)parameters2)(::func)); \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !__OPTIMIZE__
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !__OPTIMIZE__
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
109
build-aux/snippet/warn-on-use.h
Normal file
109
build-aux/snippet/warn-on-use.h
Normal file
@ -0,0 +1,109 @@
|
||||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
This macro is useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead. However, one of the reasons that a function is a
|
||||
portability trap is if it has the wrong signature. Declaring
|
||||
FUNCTION with a different signature in C is a compilation error, so
|
||||
this macro must use the same type as any existing declaration so
|
||||
that programs that avoid the problematic FUNCTION do not fail to
|
||||
compile merely because they included a header that poisoned the
|
||||
function. But this implies that _GL_WARN_ON_USE is only safe to
|
||||
use if FUNCTION is known to already have a declaration. Use of
|
||||
this macro implies that there must not be any other macro hiding
|
||||
the declaration of FUNCTION; but undefining FUNCTION first is part
|
||||
of the poisoning process anyway (although for symbols that are
|
||||
provided only via a macro, the result is a compilation error rather
|
||||
than a warning containing "literal string"). Also note that in
|
||||
C++, it is only safe to use if FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static inline char ***rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
extern __typeof__ (function) function
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
|
||||
is like _GL_WARN_ON_USE (function, "string"), except that the function is
|
||||
declared with the given prototype, consisting of return type, parameters,
|
||||
and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
extern rettype function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
extern rettype function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
1195
config.h.in
Normal file
1195
config.h.in
Normal file
File diff suppressed because it is too large
Load Diff
1153
doc/Makefile.in
Normal file
1153
doc/Makefile.in
Normal file
File diff suppressed because it is too large
Load Diff
87
lib/.gitignore
vendored
87
lib/.gitignore
vendored
@ -1,87 +0,0 @@
|
||||
Makefile.am
|
||||
alloca.in.h
|
||||
asnprintf.c
|
||||
ctype.in.h
|
||||
dosname.h
|
||||
errno.in.h
|
||||
float.c
|
||||
float.in.h
|
||||
float+.h
|
||||
fprintf.c
|
||||
fpucw.h
|
||||
frexp.c
|
||||
frexpl.c
|
||||
fseterr.c
|
||||
fseterr.h
|
||||
getopt.c
|
||||
getopt.in.h
|
||||
getopt1.c
|
||||
getopt_int.h
|
||||
gettext.h
|
||||
gettimeofday.c
|
||||
isnan.c
|
||||
isnand.c
|
||||
isnand-nolibm.h
|
||||
isnanf.c
|
||||
isnanf-nolibm.h
|
||||
isnanl.c
|
||||
isnanl-nolibm.h
|
||||
locale.in.h
|
||||
malloc.c
|
||||
math.in.h
|
||||
memchr.c
|
||||
memchr.valgrind
|
||||
printf.c
|
||||
printf-args.c
|
||||
printf-args.h
|
||||
printf-frexp.c
|
||||
printf-frexp.h
|
||||
printf-frexpl.c
|
||||
printf-frexpl.h
|
||||
printf-parse.c
|
||||
printf-parse.h
|
||||
signbitd.c
|
||||
signbitf.c
|
||||
signbitl.c
|
||||
size_max.h
|
||||
snprintf.c
|
||||
stat.c
|
||||
stdarg.in.h
|
||||
stdbool.in.h
|
||||
stddef.in.h
|
||||
stdint.in.h
|
||||
stdio.in.h
|
||||
stdio-impl.h
|
||||
stdlib.in.h
|
||||
strdup.c
|
||||
string.in.h
|
||||
strncat.c
|
||||
strstr.c
|
||||
str-two-way.h
|
||||
sys_stat.in.h
|
||||
sys_time.in.h
|
||||
time.in.h
|
||||
unistd.in.h
|
||||
vasnprintf.c
|
||||
vasnprintf.h
|
||||
verify.h
|
||||
vfprintf.c
|
||||
vsnprintf.c
|
||||
wchar.in.h
|
||||
xsize.h
|
||||
|
||||
alloca.h
|
||||
arg-nonnull.h
|
||||
c++defs.h
|
||||
ctype.h
|
||||
getopt.h
|
||||
locale.h
|
||||
math.h
|
||||
stdio.h
|
||||
stdlib.h
|
||||
string.h
|
||||
sys
|
||||
time.h
|
||||
unistd.h
|
||||
warn-on-use.h
|
||||
wchar.h
|
1491
lib/Makefile.am
Normal file
1491
lib/Makefile.am
Normal file
File diff suppressed because it is too large
Load Diff
2402
lib/Makefile.in
Normal file
2402
lib/Makefile.in
Normal file
File diff suppressed because it is too large
Load Diff
56
lib/alloca.in.h
Normal file
56
lib/alloca.in.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* Memory allocation on the stack.
|
||||
|
||||
Copyright (C) 1995, 1999, 2001-2004, 2006-2011 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 3, 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. */
|
||||
|
||||
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
||||
means there is a real alloca function. */
|
||||
#ifndef _GL_ALLOCA_H
|
||||
#define _GL_ALLOCA_H
|
||||
|
||||
/* alloca (N) returns a pointer to N bytes of memory
|
||||
allocated on the stack, which will last until the function returns.
|
||||
Use of alloca should be avoided:
|
||||
- inside arguments of function calls - undefined behaviour,
|
||||
- in inline functions - the allocation may actually last until the
|
||||
calling function returns,
|
||||
- for huge N (say, N >= 65536) - you never know how large (or small)
|
||||
the stack is, and when the stack cannot fulfill the memory allocation
|
||||
request, the program just crashes.
|
||||
*/
|
||||
|
||||
#ifndef alloca
|
||||
# ifdef __GNUC__
|
||||
# define alloca __builtin_alloca
|
||||
# elif defined _AIX
|
||||
# define alloca __alloca
|
||||
# elif defined _MSC_VER
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
# elif defined __DECC && defined __VMS
|
||||
# define alloca __ALLOCA
|
||||
# else
|
||||
# include <stddef.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void *alloca (size_t);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _GL_ALLOCA_H */
|
35
lib/asnprintf.c
Normal file
35
lib/asnprintf.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* Formatted output to strings.
|
||||
Copyright (C) 1999, 2002, 2006, 2009-2011 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 3, 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 <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "vasnprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
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;
|
||||
}
|
58
lib/ctype.in.h
Normal file
58
lib/ctype.in.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* A substitute for ISO C99 <ctype.h>, for platforms on which it is incomplete.
|
||||
|
||||
Copyright (C) 2009-2011 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 3, 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. */
|
||||
|
||||
/*
|
||||
* ISO C 99 <ctype.h> for platforms on which it is incomplete.
|
||||
* <http://www.opengroup.org/onlinepubs/9699919799/basedefs/ctype.h.html>
|
||||
*/
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_CTYPE_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* Include the original <ctype.h>. */
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_CTYPE_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_CTYPE_H
|
||||
#define _@GUARD_PREFIX@_CTYPE_H
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
/* Return non-zero if c is a blank, i.e. a space or tab character. */
|
||||
#if @GNULIB_ISBLANK@
|
||||
# if !@HAVE_ISBLANK@
|
||||
_GL_EXTERN_C int isblank (int c);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef isblank
|
||||
# if HAVE_RAW_DECL_ISBLANK
|
||||
_GL_WARN_ON_USE (isblank, "isblank is unportable - "
|
||||
"use gnulib module isblank for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_CTYPE_H */
|
||||
#endif /* _@GUARD_PREFIX@_CTYPE_H */
|
53
lib/dosname.h
Normal file
53
lib/dosname.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* File names on MS-DOS/Windows systems.
|
||||
|
||||
Copyright (C) 2000-2001, 2004-2006, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
From Paul Eggert and Jim Meyering. */
|
||||
|
||||
#ifndef _DOSNAME_H
|
||||
#define _DOSNAME_H
|
||||
|
||||
#if (defined _WIN32 || defined __WIN32__ || \
|
||||
defined __MSDOS__ || defined __CYGWIN__ || \
|
||||
defined __EMX__ || defined __DJGPP__)
|
||||
/* 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)
|
||||
# ifndef __CYGWIN__
|
||||
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
|
||||
# endif
|
||||
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
|
||||
#else
|
||||
# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
#endif
|
||||
|
||||
#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
|
||||
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 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]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
|
||||
#endif
|
||||
#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
|
||||
|
||||
#endif /* DOSNAME_H_ */
|
167
lib/errno.in.h
Normal file
167
lib/errno.in.h
Normal file
@ -0,0 +1,167 @@
|
||||
/* A POSIX-like <errno.h>.
|
||||
|
||||
Copyright (C) 2008-2011 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 3, 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 _@GUARD_PREFIX@_ERRNO_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_ERRNO_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_ERRNO_H
|
||||
#define _@GUARD_PREFIX@_ERRNO_H
|
||||
|
||||
|
||||
/* On native Windows platforms, many macros are not defined. */
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
/* POSIX says that EAGAIN and EWOULDBLOCK may have the same value. */
|
||||
# define EWOULDBLOCK EAGAIN
|
||||
|
||||
/* Values >= 100 seem safe to use. */
|
||||
# define ETXTBSY 100
|
||||
# define GNULIB_defined_ETXTBSY 1
|
||||
|
||||
/* These are intentionally the same values as the WSA* error numbers, defined
|
||||
in <winsock2.h>. */
|
||||
# define EINPROGRESS 10036
|
||||
# define EALREADY 10037
|
||||
# define ENOTSOCK 10038
|
||||
# define EDESTADDRREQ 10039
|
||||
# define EMSGSIZE 10040
|
||||
# define EPROTOTYPE 10041
|
||||
# define ENOPROTOOPT 10042
|
||||
# define EPROTONOSUPPORT 10043
|
||||
# define ESOCKTNOSUPPORT 10044 /* not required by POSIX */
|
||||
# define EOPNOTSUPP 10045
|
||||
# define EPFNOSUPPORT 10046 /* not required by POSIX */
|
||||
# define EAFNOSUPPORT 10047
|
||||
# define EADDRINUSE 10048
|
||||
# define EADDRNOTAVAIL 10049
|
||||
# define ENETDOWN 10050
|
||||
# define ENETUNREACH 10051
|
||||
# define ENETRESET 10052
|
||||
# define ECONNABORTED 10053
|
||||
# define ECONNRESET 10054
|
||||
# define ENOBUFS 10055
|
||||
# define EISCONN 10056
|
||||
# define ENOTCONN 10057
|
||||
# define ESHUTDOWN 10058 /* not required by POSIX */
|
||||
# define ETOOMANYREFS 10059 /* not required by POSIX */
|
||||
# define ETIMEDOUT 10060
|
||||
# define ECONNREFUSED 10061
|
||||
# define ELOOP 10062
|
||||
# define EHOSTDOWN 10064 /* not required by POSIX */
|
||||
# define EHOSTUNREACH 10065
|
||||
# define EPROCLIM 10067 /* not required by POSIX */
|
||||
# define EUSERS 10068 /* not required by POSIX */
|
||||
# define EDQUOT 10069
|
||||
# define ESTALE 10070
|
||||
# define EREMOTE 10071 /* not required by POSIX */
|
||||
# define GNULIB_defined_ESOCK 1
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
/* On OSF/1 5.1, when _XOPEN_SOURCE_EXTENDED is not defined, the macros
|
||||
EMULTIHOP, ENOLINK, EOVERFLOW are not defined. */
|
||||
# if @EMULTIHOP_HIDDEN@
|
||||
# define EMULTIHOP @EMULTIHOP_VALUE@
|
||||
# define GNULIB_defined_EMULTIHOP 1
|
||||
# endif
|
||||
# if @ENOLINK_HIDDEN@
|
||||
# define ENOLINK @ENOLINK_VALUE@
|
||||
# define GNULIB_defined_ENOLINK 1
|
||||
# endif
|
||||
# if @EOVERFLOW_HIDDEN@
|
||||
# define EOVERFLOW @EOVERFLOW_VALUE@
|
||||
# define GNULIB_defined_EOVERFLOW 1
|
||||
# endif
|
||||
|
||||
|
||||
/* On OpenBSD 4.0 and on native Windows, the macros ENOMSG, EIDRM, ENOLINK,
|
||||
EPROTO, EMULTIHOP, EBADMSG, EOVERFLOW, ENOTSUP, ECANCELED are not defined.
|
||||
Likewise, on NonStop Kernel, EDQUOT is not defined.
|
||||
Define them here. Values >= 2000 seem safe to use: Solaris ESTALE = 151,
|
||||
HP-UX EWOULDBLOCK = 246, IRIX EDQUOT = 1133.
|
||||
|
||||
Note: When one of these systems defines some of these macros some day,
|
||||
binaries will have to be recompiled so that they recognizes the new
|
||||
errno values from the system. */
|
||||
|
||||
# ifndef ENOMSG
|
||||
# define ENOMSG 2000
|
||||
# define GNULIB_defined_ENOMSG 1
|
||||
# endif
|
||||
|
||||
# ifndef EIDRM
|
||||
# define EIDRM 2001
|
||||
# define GNULIB_defined_EIDRM 1
|
||||
# endif
|
||||
|
||||
# ifndef ENOLINK
|
||||
# define ENOLINK 2002
|
||||
# define GNULIB_defined_ENOLINK 1
|
||||
# endif
|
||||
|
||||
# ifndef EPROTO
|
||||
# define EPROTO 2003
|
||||
# define GNULIB_defined_EPROTO 1
|
||||
# endif
|
||||
|
||||
# ifndef EMULTIHOP
|
||||
# define EMULTIHOP 2004
|
||||
# define GNULIB_defined_EMULTIHOP 1
|
||||
# endif
|
||||
|
||||
# ifndef EBADMSG
|
||||
# define EBADMSG 2005
|
||||
# define GNULIB_defined_EBADMSG 1
|
||||
# endif
|
||||
|
||||
# ifndef EOVERFLOW
|
||||
# define EOVERFLOW 2006
|
||||
# define GNULIB_defined_EOVERFLOW 1
|
||||
# endif
|
||||
|
||||
# ifndef ENOTSUP
|
||||
# define ENOTSUP 2007
|
||||
# define GNULIB_defined_ENOTSUP 1
|
||||
# endif
|
||||
|
||||
# ifndef ESTALE
|
||||
# define ESTALE 2009
|
||||
# define GNULIB_defined_ESTALE 1
|
||||
# endif
|
||||
|
||||
# ifndef EDQUOT
|
||||
# define EDQUOT 2010
|
||||
# define GNULIB_defined_EDQUOT 1
|
||||
# endif
|
||||
|
||||
# ifndef ECANCELED
|
||||
# define ECANCELED 2008
|
||||
# define GNULIB_defined_ECANCELED 1
|
||||
# endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_ERRNO_H */
|
||||
#endif /* _@GUARD_PREFIX@_ERRNO_H */
|
148
lib/float+.h
Normal file
148
lib/float+.h
Normal file
@ -0,0 +1,148 @@
|
||||
/* Supplemental information about the floating-point formats.
|
||||
Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2007.
|
||||
|
||||
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 3, 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 _FLOATPLUS_H
|
||||
#define _FLOATPLUS_H
|
||||
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Number of bits in the mantissa of a floating-point number, including the
|
||||
"hidden bit". */
|
||||
#if FLT_RADIX == 2
|
||||
# define FLT_MANT_BIT FLT_MANT_DIG
|
||||
# define DBL_MANT_BIT DBL_MANT_DIG
|
||||
# define LDBL_MANT_BIT LDBL_MANT_DIG
|
||||
#elif FLT_RADIX == 4
|
||||
# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
|
||||
# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
|
||||
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
|
||||
#elif FLT_RADIX == 16
|
||||
# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
|
||||
# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
|
||||
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
|
||||
#endif
|
||||
|
||||
/* Bit mask that can be used to mask the exponent, as an unsigned number. */
|
||||
#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
|
||||
#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
|
||||
#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
|
||||
|
||||
/* Number of bits used for the exponent of a floating-point number, including
|
||||
the exponent's sign. */
|
||||
#define FLT_EXP_BIT \
|
||||
(FLT_EXP_MASK < 0x100 ? 8 : \
|
||||
FLT_EXP_MASK < 0x200 ? 9 : \
|
||||
FLT_EXP_MASK < 0x400 ? 10 : \
|
||||
FLT_EXP_MASK < 0x800 ? 11 : \
|
||||
FLT_EXP_MASK < 0x1000 ? 12 : \
|
||||
FLT_EXP_MASK < 0x2000 ? 13 : \
|
||||
FLT_EXP_MASK < 0x4000 ? 14 : \
|
||||
FLT_EXP_MASK < 0x8000 ? 15 : \
|
||||
FLT_EXP_MASK < 0x10000 ? 16 : \
|
||||
FLT_EXP_MASK < 0x20000 ? 17 : \
|
||||
FLT_EXP_MASK < 0x40000 ? 18 : \
|
||||
FLT_EXP_MASK < 0x80000 ? 19 : \
|
||||
FLT_EXP_MASK < 0x100000 ? 20 : \
|
||||
FLT_EXP_MASK < 0x200000 ? 21 : \
|
||||
FLT_EXP_MASK < 0x400000 ? 22 : \
|
||||
FLT_EXP_MASK < 0x800000 ? 23 : \
|
||||
FLT_EXP_MASK < 0x1000000 ? 24 : \
|
||||
FLT_EXP_MASK < 0x2000000 ? 25 : \
|
||||
FLT_EXP_MASK < 0x4000000 ? 26 : \
|
||||
FLT_EXP_MASK < 0x8000000 ? 27 : \
|
||||
FLT_EXP_MASK < 0x10000000 ? 28 : \
|
||||
FLT_EXP_MASK < 0x20000000 ? 29 : \
|
||||
FLT_EXP_MASK < 0x40000000 ? 30 : \
|
||||
FLT_EXP_MASK <= 0x7fffffff ? 31 : \
|
||||
32)
|
||||
#define DBL_EXP_BIT \
|
||||
(DBL_EXP_MASK < 0x100 ? 8 : \
|
||||
DBL_EXP_MASK < 0x200 ? 9 : \
|
||||
DBL_EXP_MASK < 0x400 ? 10 : \
|
||||
DBL_EXP_MASK < 0x800 ? 11 : \
|
||||
DBL_EXP_MASK < 0x1000 ? 12 : \
|
||||
DBL_EXP_MASK < 0x2000 ? 13 : \
|
||||
DBL_EXP_MASK < 0x4000 ? 14 : \
|
||||
DBL_EXP_MASK < 0x8000 ? 15 : \
|
||||
DBL_EXP_MASK < 0x10000 ? 16 : \
|
||||
DBL_EXP_MASK < 0x20000 ? 17 : \
|
||||
DBL_EXP_MASK < 0x40000 ? 18 : \
|
||||
DBL_EXP_MASK < 0x80000 ? 19 : \
|
||||
DBL_EXP_MASK < 0x100000 ? 20 : \
|
||||
DBL_EXP_MASK < 0x200000 ? 21 : \
|
||||
DBL_EXP_MASK < 0x400000 ? 22 : \
|
||||
DBL_EXP_MASK < 0x800000 ? 23 : \
|
||||
DBL_EXP_MASK < 0x1000000 ? 24 : \
|
||||
DBL_EXP_MASK < 0x2000000 ? 25 : \
|
||||
DBL_EXP_MASK < 0x4000000 ? 26 : \
|
||||
DBL_EXP_MASK < 0x8000000 ? 27 : \
|
||||
DBL_EXP_MASK < 0x10000000 ? 28 : \
|
||||
DBL_EXP_MASK < 0x20000000 ? 29 : \
|
||||
DBL_EXP_MASK < 0x40000000 ? 30 : \
|
||||
DBL_EXP_MASK <= 0x7fffffff ? 31 : \
|
||||
32)
|
||||
#define LDBL_EXP_BIT \
|
||||
(LDBL_EXP_MASK < 0x100 ? 8 : \
|
||||
LDBL_EXP_MASK < 0x200 ? 9 : \
|
||||
LDBL_EXP_MASK < 0x400 ? 10 : \
|
||||
LDBL_EXP_MASK < 0x800 ? 11 : \
|
||||
LDBL_EXP_MASK < 0x1000 ? 12 : \
|
||||
LDBL_EXP_MASK < 0x2000 ? 13 : \
|
||||
LDBL_EXP_MASK < 0x4000 ? 14 : \
|
||||
LDBL_EXP_MASK < 0x8000 ? 15 : \
|
||||
LDBL_EXP_MASK < 0x10000 ? 16 : \
|
||||
LDBL_EXP_MASK < 0x20000 ? 17 : \
|
||||
LDBL_EXP_MASK < 0x40000 ? 18 : \
|
||||
LDBL_EXP_MASK < 0x80000 ? 19 : \
|
||||
LDBL_EXP_MASK < 0x100000 ? 20 : \
|
||||
LDBL_EXP_MASK < 0x200000 ? 21 : \
|
||||
LDBL_EXP_MASK < 0x400000 ? 22 : \
|
||||
LDBL_EXP_MASK < 0x800000 ? 23 : \
|
||||
LDBL_EXP_MASK < 0x1000000 ? 24 : \
|
||||
LDBL_EXP_MASK < 0x2000000 ? 25 : \
|
||||
LDBL_EXP_MASK < 0x4000000 ? 26 : \
|
||||
LDBL_EXP_MASK < 0x8000000 ? 27 : \
|
||||
LDBL_EXP_MASK < 0x10000000 ? 28 : \
|
||||
LDBL_EXP_MASK < 0x20000000 ? 29 : \
|
||||
LDBL_EXP_MASK < 0x40000000 ? 30 : \
|
||||
LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
|
||||
32)
|
||||
|
||||
/* Number of bits used for a floating-point number: the mantissa (not
|
||||
counting the "hidden bit", since it may or may not be explicit), the
|
||||
exponent, and the sign. */
|
||||
#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
|
||||
#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
|
||||
#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
|
||||
|
||||
/* Number of bytes used for a floating-point number.
|
||||
This can be smaller than the 'sizeof'. For example, on i386 systems,
|
||||
'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
|
||||
LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
|
||||
sizeof (long double) = 12 or = 16. */
|
||||
#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
|
||||
#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
|
||||
#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
|
||||
|
||||
/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
|
||||
typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1];
|
||||
typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1];
|
||||
typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1];
|
||||
|
||||
#endif /* _FLOATPLUS_H */
|
33
lib/float.c
Normal file
33
lib/float.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* Auxiliary definitions for <float.h>.
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2011.
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <float.h>
|
||||
|
||||
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
|
||||
const union gl_long_double_union gl_LDBL_MAX =
|
||||
{ { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
|
||||
#elif defined __i386__
|
||||
const union gl_long_double_union gl_LDBL_MAX =
|
||||
{ { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
|
||||
#else
|
||||
/* This declaration is solely to ensure that after preprocessing
|
||||
this file is never empty. */
|
||||
typedef int dummy;
|
||||
#endif
|
174
lib/float.in.h
Normal file
174
lib/float.in.h
Normal file
@ -0,0 +1,174 @@
|
||||
/* A correct <float.h>.
|
||||
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_FLOAT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_FLOAT_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_FLOAT_H
|
||||
#define _@GUARD_PREFIX@_FLOAT_H
|
||||
|
||||
/* 'long double' properties. */
|
||||
|
||||
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
|
||||
/* Number of mantissa units, in base FLT_RADIX. */
|
||||
# undef LDBL_MANT_DIG
|
||||
# define LDBL_MANT_DIG 64
|
||||
/* Number of decimal digits that is sufficient for representing a number. */
|
||||
# undef LDBL_DIG
|
||||
# define LDBL_DIG 18
|
||||
/* x-1 where x is the smallest representable number > 1. */
|
||||
# undef LDBL_EPSILON
|
||||
# define LDBL_EPSILON 1.0842021724855044340E-19L
|
||||
/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
|
||||
# undef LDBL_MIN_EXP
|
||||
# define LDBL_MIN_EXP (-16381)
|
||||
/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
|
||||
# undef LDBL_MAX_EXP
|
||||
# define LDBL_MAX_EXP 16384
|
||||
/* Minimum positive normalized number. */
|
||||
# undef LDBL_MIN
|
||||
# define LDBL_MIN 3.3621031431120935063E-4932L
|
||||
/* Maximum representable finite number. */
|
||||
# undef LDBL_MAX
|
||||
# define LDBL_MAX 1.1897314953572317650E+4932L
|
||||
/* Minimum e such that 10^e is in the range of normalized numbers. */
|
||||
# undef LDBL_MIN_10_EXP
|
||||
# define LDBL_MIN_10_EXP (-4931)
|
||||
/* Maximum e such that 10^e is in the range of representable finite numbers. */
|
||||
# undef LDBL_MAX_10_EXP
|
||||
# define LDBL_MAX_10_EXP 4932
|
||||
#endif
|
||||
|
||||
/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
|
||||
precision in the compiler but 64 bits of precision at runtime. See
|
||||
<http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. */
|
||||
#if defined __i386__ && defined __FreeBSD__
|
||||
/* Number of mantissa units, in base FLT_RADIX. */
|
||||
# undef LDBL_MANT_DIG
|
||||
# define LDBL_MANT_DIG 64
|
||||
/* Number of decimal digits that is sufficient for representing a number. */
|
||||
# undef LDBL_DIG
|
||||
# define LDBL_DIG 18
|
||||
/* x-1 where x is the smallest representable number > 1. */
|
||||
# undef LDBL_EPSILON
|
||||
# define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 */
|
||||
/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
|
||||
# undef LDBL_MIN_EXP
|
||||
# define LDBL_MIN_EXP (-16381)
|
||||
/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
|
||||
# undef LDBL_MAX_EXP
|
||||
# define LDBL_MAX_EXP 16384
|
||||
/* Minimum positive normalized number. */
|
||||
# undef LDBL_MIN
|
||||
# define LDBL_MIN 3.3621031431120935E-4932L /* = 0x1p-16382L */
|
||||
/* Maximum representable finite number. */
|
||||
# undef LDBL_MAX
|
||||
/* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
|
||||
But the largest literal that GCC allows us to write is
|
||||
0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }.
|
||||
So, define it like this through a reference to an external variable
|
||||
|
||||
const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 };
|
||||
extern const long double LDBL_MAX;
|
||||
|
||||
Unfortunately, this is not a constant expression. */
|
||||
union gl_long_double_union
|
||||
{
|
||||
struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
|
||||
long double ld;
|
||||
};
|
||||
extern const union gl_long_double_union gl_LDBL_MAX;
|
||||
# define LDBL_MAX (gl_LDBL_MAX.ld)
|
||||
/* Minimum e such that 10^e is in the range of normalized numbers. */
|
||||
# undef LDBL_MIN_10_EXP
|
||||
# define LDBL_MIN_10_EXP (-4931)
|
||||
/* Maximum e such that 10^e is in the range of representable finite numbers. */
|
||||
# undef LDBL_MAX_10_EXP
|
||||
# define LDBL_MAX_10_EXP 4932
|
||||
#endif
|
||||
|
||||
/* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
|
||||
wrong. */
|
||||
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
|
||||
# undef LDBL_MIN_EXP
|
||||
# define LDBL_MIN_EXP DBL_MIN_EXP
|
||||
# undef LDBL_MIN_10_EXP
|
||||
# define LDBL_MIN_10_EXP DBL_MIN_10_EXP
|
||||
# undef LDBL_MIN
|
||||
# define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
|
||||
# undef LDBL_MAX
|
||||
/* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }.
|
||||
It is not easy to define:
|
||||
#define LDBL_MAX 1.79769313486231580793728971405302307166e308L
|
||||
is too small, whereas
|
||||
#define LDBL_MAX 1.79769313486231580793728971405302307167e308L
|
||||
is too large. Apparently a bug in GCC decimal-to-binary conversion.
|
||||
Also, I can't get values larger than
|
||||
#define LDBL63 ((long double) (1ULL << 63))
|
||||
#define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
||||
#define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
||||
#define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
||||
#define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
|
||||
which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
|
||||
So, define it like this through a reference to an external variable
|
||||
|
||||
const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL };
|
||||
extern const long double LDBL_MAX;
|
||||
|
||||
or through a pointer cast
|
||||
|
||||
#define LDBL_MAX \
|
||||
(*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL })
|
||||
|
||||
Unfortunately, this is not a constant expression, and the latter expression
|
||||
does not work well when GCC is optimizing.. */
|
||||
union gl_long_double_union
|
||||
{
|
||||
struct { double hi; double lo; } dd;
|
||||
long double ld;
|
||||
};
|
||||
extern const union gl_long_double_union gl_LDBL_MAX;
|
||||
# define LDBL_MAX (gl_LDBL_MAX.ld)
|
||||
#endif
|
||||
|
||||
/* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
|
||||
On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON
|
||||
are wrong. */
|
||||
#if defined __sgi && (LDBL_MANT_DIG >= 106)
|
||||
# undef LDBL_MANT_DIG
|
||||
# define LDBL_MANT_DIG 106
|
||||
# if defined __GNUC__
|
||||
# undef LDBL_MIN_EXP
|
||||
# define LDBL_MIN_EXP DBL_MIN_EXP
|
||||
# undef LDBL_MIN_10_EXP
|
||||
# define LDBL_MIN_10_EXP DBL_MIN_10_EXP
|
||||
# undef LDBL_MIN
|
||||
# define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
|
||||
# undef LDBL_EPSILON
|
||||
# define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_FLOAT_H */
|
||||
#endif /* _@GUARD_PREFIX@_FLOAT_H */
|
77
lib/fprintf.c
Normal file
77
lib/fprintf.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* Formatted output to a stream.
|
||||
Copyright (C) 2004, 2006-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if 1
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "fseterr.h"
|
||||
#include "vasnprintf.h"
|
||||
|
||||
/* Print formatted output to the stream FP.
|
||||
Return string length of formatted string. On error, return a negative
|
||||
value. */
|
||||
int
|
||||
fprintf (FILE *fp, const char *format, ...)
|
||||
{
|
||||
char buf[2000];
|
||||
char *output;
|
||||
size_t len;
|
||||
size_t lenbuf = sizeof (buf);
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
output = vasnprintf (buf, &lenbuf, format, args);
|
||||
len = lenbuf;
|
||||
va_end (args);
|
||||
|
||||
if (!output)
|
||||
{
|
||||
fseterr (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fwrite (output, 1, len, fp) < len)
|
||||
{
|
||||
if (output != buf)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (output);
|
||||
errno = saved_errno;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (output != buf)
|
||||
free (output);
|
||||
|
||||
if (len > INT_MAX)
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
fseterr (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
107
lib/fpucw.h
Normal file
107
lib/fpucw.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* Manipulating the FPU control word.
|
||||
Copyright (C) 2007-2011 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2007.
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _FPUCW_H
|
||||
#define _FPUCW_H
|
||||
|
||||
/* The i386 floating point hardware (the 387 compatible FPU, not the modern
|
||||
SSE/SSE2 hardware) has a controllable rounding precision. It is specified
|
||||
through the 'PC' bits in the FPU control word ('fctrl' register). (See
|
||||
the GNU libc i386 <fpu_control.h> header for details.)
|
||||
|
||||
On some platforms, such as Linux or Solaris, the default precision setting
|
||||
is set to "extended precision". This means that 'long double' instructions
|
||||
operate correctly, but 'double' computations often produce slightly
|
||||
different results as on strictly IEEE 754 conforming systems.
|
||||
|
||||
On some platforms, such as NetBSD, the default precision is set to
|
||||
"double precision". This means that 'long double' instructions will operate
|
||||
only as 'double', i.e. lead wrong results.
|
||||
|
||||
The FPU control word is under control of the application, i.e. it is
|
||||
not required to be set either way by the ABI. (In fact, the i386 ABI
|
||||
http://refspecs.freestandards.org/elf/abi386-4.pdf page 3-12 = page 38
|
||||
is not clear about it. But in any case, gcc treats the control word
|
||||
like a "preserved" register: it emits code that assumes that the control
|
||||
word is preserved across calls, and it restores the control word at the
|
||||
end of functions that modify it.)
|
||||
|
||||
See Vincent Lefèvre's page http://www.vinc17.org/research/extended.en.html
|
||||
for a good explanation.
|
||||
See http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html for
|
||||
some argumentation which setting should be the default. */
|
||||
|
||||
/* This header file provides the following facilities:
|
||||
fpucw_t integral type holding the value of 'fctrl'
|
||||
FPU_PC_MASK bit mask denoting the precision control
|
||||
FPU_PC_DOUBLE precision control for 53 bits mantissa
|
||||
FPU_PC_EXTENDED precision control for 64 bits mantissa
|
||||
GET_FPUCW () yields the current FPU control word
|
||||
SET_FPUCW (word) sets the FPU control word
|
||||
DECL_LONG_DOUBLE_ROUNDING variable declaration for
|
||||
BEGIN/END_LONG_DOUBLE_ROUNDING
|
||||
BEGIN_LONG_DOUBLE_ROUNDING () starts a sequence of instructions with
|
||||
'long double' safe operation precision
|
||||
END_LONG_DOUBLE_ROUNDING () ends a sequence of instructions with
|
||||
'long double' safe operation precision
|
||||
*/
|
||||
|
||||
/* Inline assembler like this works only with GNU C. */
|
||||
#if (defined __i386__ || defined __x86_64__) && defined __GNUC__
|
||||
|
||||
typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */
|
||||
|
||||
# define FPU_PC_MASK 0x0300
|
||||
# define FPU_PC_DOUBLE 0x200 /* glibc calls this _FPU_DOUBLE */
|
||||
# define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */
|
||||
|
||||
# define GET_FPUCW() \
|
||||
({ fpucw_t _cw; \
|
||||
__asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \
|
||||
_cw; \
|
||||
})
|
||||
# define SET_FPUCW(word) \
|
||||
(void)({ fpucw_t _ncw = (word); \
|
||||
__asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \
|
||||
})
|
||||
|
||||
# define DECL_LONG_DOUBLE_ROUNDING \
|
||||
fpucw_t oldcw;
|
||||
# define BEGIN_LONG_DOUBLE_ROUNDING() \
|
||||
(void)(oldcw = GET_FPUCW (), \
|
||||
SET_FPUCW ((oldcw & ~FPU_PC_MASK) | FPU_PC_EXTENDED))
|
||||
# define END_LONG_DOUBLE_ROUNDING() \
|
||||
SET_FPUCW (oldcw)
|
||||
|
||||
#else
|
||||
|
||||
typedef unsigned int fpucw_t;
|
||||
|
||||
# define FPU_PC_MASK 0
|
||||
# define FPU_PC_DOUBLE 0
|
||||
# define FPU_PC_EXTENDED 0
|
||||
|
||||
# define GET_FPUCW() 0
|
||||
# define SET_FPUCW(word) (void)(word)
|
||||
|
||||
# define DECL_LONG_DOUBLE_ROUNDING
|
||||
# define BEGIN_LONG_DOUBLE_ROUNDING()
|
||||
# define END_LONG_DOUBLE_ROUNDING()
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _FPUCW_H */
|
166
lib/frexp.c
Normal file
166
lib/frexp.c
Normal file
@ -0,0 +1,166 @@
|
||||
/* Split a double into fraction and mantissa.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paolo Bonzini <bonzini@gnu.org>, 2003, and
|
||||
Bruno Haible <bruno@clisp.org>, 2007. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <math.h>
|
||||
|
||||
#include <float.h>
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# include "isnanl-nolibm.h"
|
||||
# include "fpucw.h"
|
||||
#else
|
||||
# include "isnand-nolibm.h"
|
||||
#endif
|
||||
|
||||
/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
|
||||
than 2, or not even a power of 2, some rounding errors can occur, so that
|
||||
then the returned mantissa is only guaranteed to be <= 1.0, not < 1.0. */
|
||||
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# define FUNC frexpl
|
||||
# define DOUBLE long double
|
||||
# define ISNAN isnanl
|
||||
# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
|
||||
# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
|
||||
# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
|
||||
# define L_(literal) literal##L
|
||||
#else
|
||||
# define FUNC frexp
|
||||
# define DOUBLE double
|
||||
# define ISNAN isnand
|
||||
# define DECL_ROUNDING
|
||||
# define BEGIN_ROUNDING()
|
||||
# define END_ROUNDING()
|
||||
# define L_(literal) literal
|
||||
#endif
|
||||
|
||||
DOUBLE
|
||||
FUNC (DOUBLE x, int *expptr)
|
||||
{
|
||||
int sign;
|
||||
int exponent;
|
||||
DECL_ROUNDING
|
||||
|
||||
/* Test for NaN, infinity, and zero. */
|
||||
if (ISNAN (x) || x + x == x)
|
||||
{
|
||||
*expptr = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
sign = 0;
|
||||
if (x < 0)
|
||||
{
|
||||
x = - x;
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
BEGIN_ROUNDING ();
|
||||
|
||||
{
|
||||
/* Since the exponent is an 'int', it fits in 64 bits. Therefore the
|
||||
loops are executed no more than 64 times. */
|
||||
DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
|
||||
DOUBLE powh[64]; /* powh[i] = 2^-2^i */
|
||||
int i;
|
||||
|
||||
exponent = 0;
|
||||
if (x >= L_(1.0))
|
||||
{
|
||||
/* A positive exponent. */
|
||||
DOUBLE pow2_i; /* = pow2[i] */
|
||||
DOUBLE powh_i; /* = powh[i] */
|
||||
|
||||
/* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
|
||||
x * 2^exponent = argument, x >= 1.0. */
|
||||
for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
|
||||
;
|
||||
i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
|
||||
{
|
||||
if (x >= pow2_i)
|
||||
{
|
||||
exponent += (1 << i);
|
||||
x *= powh_i;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
pow2[i] = pow2_i;
|
||||
powh[i] = powh_i;
|
||||
}
|
||||
/* Avoid making x too small, as it could become a denormalized
|
||||
number and thus lose precision. */
|
||||
while (i > 0 && x < pow2[i - 1])
|
||||
{
|
||||
i--;
|
||||
powh_i = powh[i];
|
||||
}
|
||||
exponent += (1 << i);
|
||||
x *= powh_i;
|
||||
/* Here 2^-2^i <= x < 1.0. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A negative or zero exponent. */
|
||||
DOUBLE pow2_i; /* = pow2[i] */
|
||||
DOUBLE powh_i; /* = powh[i] */
|
||||
|
||||
/* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
|
||||
x * 2^exponent = argument, x < 1.0. */
|
||||
for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
|
||||
;
|
||||
i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
|
||||
{
|
||||
if (x < powh_i)
|
||||
{
|
||||
exponent -= (1 << i);
|
||||
x *= pow2_i;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
pow2[i] = pow2_i;
|
||||
powh[i] = powh_i;
|
||||
}
|
||||
/* Here 2^-2^i <= x < 1.0. */
|
||||
}
|
||||
|
||||
/* Invariants: x * 2^exponent = argument, and 2^-2^i <= x < 1.0. */
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
if (x < powh[i])
|
||||
{
|
||||
exponent -= (1 << i);
|
||||
x *= pow2[i];
|
||||
}
|
||||
}
|
||||
/* Here 0.5 <= x < 1.0. */
|
||||
}
|
||||
|
||||
if (sign < 0)
|
||||
x = - x;
|
||||
|
||||
END_ROUNDING ();
|
||||
|
||||
*expptr = exponent;
|
||||
return x;
|
||||
}
|
18
lib/frexpl.c
Normal file
18
lib/frexpl.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* Split a 'long double' into fraction and mantissa.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define USE_LONG_DOUBLE
|
||||
#include "frexp.c"
|
74
lib/fseterr.c
Normal file
74
lib/fseterr.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* Set the error indicator of a stream.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "fseterr.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "stdio-impl.h"
|
||||
|
||||
void
|
||||
fseterr (FILE *fp)
|
||||
{
|
||||
/* Most systems provide FILE as a struct and the necessary bitmask in
|
||||
<stdio.h>, because they need it for implementing getc() and putc() as
|
||||
fast macros. */
|
||||
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
|
||||
fp->_flags |= _IO_ERR_SEEN;
|
||||
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
|
||||
fp_->_flags |= __SERR;
|
||||
#elif defined __EMX__ /* emx+gcc */
|
||||
fp->_flags |= _IOERR;
|
||||
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
|
||||
fp_->_flag |= _IOERR;
|
||||
#elif defined __UCLIBC__ /* uClibc */
|
||||
fp->__modeflags |= __FLAG_ERROR;
|
||||
#elif defined __QNX__ /* QNX */
|
||||
fp->_Mode |= 0x200 /* _MERR */;
|
||||
#elif defined __MINT__ /* Atari FreeMiNT */
|
||||
fp->__error = 1;
|
||||
#elif 0 /* unknown */
|
||||
/* Portable fallback, based on an idea by Rich Felker.
|
||||
Wow! 6 system calls for something that is just a bit operation!
|
||||
Not activated on any system, because there is no way to repair FP when
|
||||
the sequence of system calls fails, and library code should not call
|
||||
abort(). */
|
||||
int saved_errno;
|
||||
int fd;
|
||||
int fd2;
|
||||
|
||||
saved_errno = errno;
|
||||
fflush (fp);
|
||||
fd = fileno (fp);
|
||||
fd2 = dup (fd);
|
||||
if (fd2 >= 0)
|
||||
{
|
||||
close (fd);
|
||||
fputc ('\0', fp); /* This should set the error indicator. */
|
||||
fflush (fp); /* Or this. */
|
||||
if (dup2 (fd2, fd) < 0)
|
||||
/* Whee... we botched the stream and now cannot restore it! */
|
||||
abort ();
|
||||
close (fd2);
|
||||
}
|
||||
errno = saved_errno;
|
||||
#else
|
||||
#error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
|
||||
#endif
|
||||
}
|
37
lib/fseterr.h
Normal file
37
lib/fseterr.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* Set the error indicator of a stream.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _FSETERR_H
|
||||
#define _FSETERR_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Set the error indicator of the stream FP.
|
||||
The "error indicator" is set when an I/O operation on the stream fails, and
|
||||
is cleared (together with the "end-of-file" indicator) by clearerr (FP). */
|
||||
extern void fseterr (FILE *fp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FSETERR_H */
|
1245
lib/getopt.c
Normal file
1245
lib/getopt.c
Normal file
File diff suppressed because it is too large
Load Diff
253
lib/getopt.in.h
Normal file
253
lib/getopt.in.h
Normal file
@ -0,0 +1,253 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_GETOPT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. We must
|
||||
also inform the replacement unistd.h to not recursively use
|
||||
<getopt.h>; our definitions will be present soon enough. */
|
||||
#if @HAVE_GETOPT_H@
|
||||
# define _GL_SYSTEM_GETOPT
|
||||
# @INCLUDE_NEXT@ @NEXT_GETOPT_H@
|
||||
# undef _GL_SYSTEM_GETOPT
|
||||
#endif
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _@GUARD_PREFIX@_GETOPT_H 1
|
||||
#endif
|
||||
|
||||
/* Standalone applications should #define __GETOPT_PREFIX to an
|
||||
identifier that prefixes the external functions and variables
|
||||
defined in this header. When this happens, include the
|
||||
headers that might declare getopt so that they will not cause
|
||||
confusion if included after this file (if the system had <getopt.h>,
|
||||
we have already included it). Then systematically rename
|
||||
identifiers so that they do not collide with the system functions
|
||||
and variables. Renaming avoids problems with some compilers and
|
||||
linkers. */
|
||||
#if defined __GETOPT_PREFIX && !defined __need_getopt
|
||||
# if !@HAVE_GETOPT_H@
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# undef __need_getopt
|
||||
# undef getopt
|
||||
# undef getopt_long
|
||||
# undef getopt_long_only
|
||||
# undef optarg
|
||||
# undef opterr
|
||||
# undef optind
|
||||
# undef optopt
|
||||
# undef option
|
||||
# define __GETOPT_CONCAT(x, y) x ## y
|
||||
# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
|
||||
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
|
||||
# define getopt __GETOPT_ID (getopt)
|
||||
# define getopt_long __GETOPT_ID (getopt_long)
|
||||
# define getopt_long_only __GETOPT_ID (getopt_long_only)
|
||||
# define optarg __GETOPT_ID (optarg)
|
||||
# define opterr __GETOPT_ID (opterr)
|
||||
# define optind __GETOPT_ID (optind)
|
||||
# define optopt __GETOPT_ID (optopt)
|
||||
# define option __GETOPT_ID (option)
|
||||
# define _getopt_internal __GETOPT_ID (getopt_internal)
|
||||
#endif
|
||||
|
||||
/* Standalone applications get correct prototypes for getopt_long and
|
||||
getopt_long_only; they declare "char **argv". libc uses prototypes
|
||||
with "char *const *argv" that are incorrect because getopt_long and
|
||||
getopt_long_only can permute argv; this is required for backward
|
||||
compatibility (e.g., for LSB 2.0.1).
|
||||
|
||||
This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
|
||||
but it caused redefinition warnings if both unistd.h and getopt.h were
|
||||
included, since unistd.h includes getopt.h having previously defined
|
||||
__need_getopt.
|
||||
|
||||
The only place where __getopt_argv_const is used is in definitions
|
||||
of getopt_long and getopt_long_only below, but these are visible
|
||||
only if __need_getopt is not defined, so it is quite safe to rewrite
|
||||
the conditional as follows:
|
||||
*/
|
||||
#if !defined __need_getopt
|
||||
# if defined __GETOPT_PREFIX
|
||||
# define __getopt_argv_const /* empty */
|
||||
# else
|
||||
# define __getopt_argv_const const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If __GNU_LIBRARY__ is not already defined, either we are being used
|
||||
standalone, or this is the first header included in the source file.
|
||||
If we are being used with glibc, we need to include <features.h>, but
|
||||
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
|
||||
not defined, include <ctype.h>, which will pull in <features.h> for us
|
||||
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
|
||||
doesn't flood the namespace with stuff the way some other headers do.) */
|
||||
#if !defined __GNU_LIBRARY__
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifndef __THROW
|
||||
# ifndef __GNUC_PREREQ
|
||||
# define __GNUC_PREREQ(maj, min) (0)
|
||||
# endif
|
||||
# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
||||
# define __THROW throw ()
|
||||
# else
|
||||
# define __THROW
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
# if !GNULIB_defined_struct_option
|
||||
struct option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
# define GNULIB_defined_struct_option 1
|
||||
# endif
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, `optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in `optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU `getopt'.
|
||||
|
||||
The argument `--' causes premature termination of argument
|
||||
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 '\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 _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
#ifndef __need_getopt
|
||||
extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW _GL_ARG_NONNULL ((2, 3));
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_GETOPT_H */
|
||||
#endif /* _@GUARD_PREFIX@_GETOPT_H */
|
170
lib/getopt1.c
Normal file
170
lib/getopt1.c
Normal file
@ -0,0 +1,170 @@
|
||||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||
Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <getopt.h>
|
||||
#else
|
||||
# include <config.h>
|
||||
# include "getopt.h"
|
||||
#endif
|
||||
#include "getopt_int.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* This needs to come after some library #include
|
||||
to get __GNU_LIBRARY__ defined. */
|
||||
#ifdef __GNU_LIBRARY__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
int
|
||||
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, (char **) argv, options, long_options,
|
||||
opt_index, 0, 0);
|
||||
}
|
||||
|
||||
int
|
||||
_getopt_long_r (int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
{
|
||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||
0, d, 0);
|
||||
}
|
||||
|
||||
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||
If an option that starts with '-' (not '--') doesn't match a long option,
|
||||
but does match a short option, it is parsed as a short option
|
||||
instead. */
|
||||
|
||||
int
|
||||
getopt_long_only (int argc, char *__getopt_argv_const *argv,
|
||||
const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, (char **) argv, options, long_options,
|
||||
opt_index, 1, 0);
|
||||
}
|
||||
|
||||
int
|
||||
_getopt_long_only_r (int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index,
|
||||
struct _getopt_data *d)
|
||||
{
|
||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||
1, d, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
static const struct option long_options[] =
|
||||
{
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
printf ("option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (" with arg %s", optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printf ("option d with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
135
lib/getopt_int.h
Normal file
135
lib/getopt_int.h
Normal file
@ -0,0 +1,135 @@
|
||||
/* Internal declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GETOPT_INT_H
|
||||
#define _GETOPT_INT_H 1
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
extern int _getopt_internal (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, int __posixly_correct);
|
||||
|
||||
|
||||
/* Reentrant versions which can handle parsing multiple argument
|
||||
vectors at the same time. */
|
||||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
If the caller did not specify anything,
|
||||
the default is REQUIRE_ORDER if the environment variable
|
||||
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options;
|
||||
stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
This mode of operation is selected by either setting the environment
|
||||
variable POSIXLY_CORRECT, or using `+' as the first character
|
||||
of the list of option characters, or by calling getopt.
|
||||
|
||||
PERMUTE is the default. We permute the contents of ARGV as we
|
||||
scan, so that eventually all the non-options are at the end.
|
||||
This allows options to be given in any order, even with programs
|
||||
that were not written to expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were
|
||||
written to expect options and other ARGV-elements in any order
|
||||
and that care about the ordering of the two. We describe each
|
||||
non-option ARGV-element as if it were the argument of an option
|
||||
with character code 1. Using `-' as the first character of the
|
||||
list of option characters selects this mode of operation.
|
||||
|
||||
The special argument `--' forces an end of option-scanning regardless
|
||||
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
|
||||
|
||||
enum __ord
|
||||
{
|
||||
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
|
||||
};
|
||||
|
||||
/* Data type for reentrant functions. */
|
||||
struct _getopt_data
|
||||
{
|
||||
/* These have exactly the same meaning as the corresponding global
|
||||
variables, except that they are used for the reentrant
|
||||
versions of getopt. */
|
||||
int optind;
|
||||
int opterr;
|
||||
int optopt;
|
||||
char *optarg;
|
||||
|
||||
/* Internal members. */
|
||||
|
||||
/* True if the internal members have been initialized. */
|
||||
int __initialized;
|
||||
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
char *__nextchar;
|
||||
|
||||
/* See __ord above. */
|
||||
enum __ord __ordering;
|
||||
|
||||
/* If the POSIXLY_CORRECT environment variable is set
|
||||
or getopt was called. */
|
||||
int __posixly_correct;
|
||||
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
been skipped. `first_nonopt' is the index in ARGV of the first
|
||||
of them; `last_nonopt' is the index after the last of them. */
|
||||
|
||||
int __first_nonopt;
|
||||
int __last_nonopt;
|
||||
|
||||
#if defined _LIBC && defined USE_NONOPTION_FLAGS
|
||||
int __nonoption_flags_max_len;
|
||||
int __nonoption_flags_len;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* The initializer is necessary to set OPTIND and OPTERR to their
|
||||
default values and to clear the initialization flag. */
|
||||
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
|
||||
|
||||
extern int _getopt_internal_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, struct _getopt_data *__data,
|
||||
int __posixly_correct);
|
||||
|
||||
extern int _getopt_long_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
extern int _getopt_long_only_r (int ___argc, char **___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts,
|
||||
int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
#endif /* getopt_int.h */
|
286
lib/gettext.h
Normal file
286
lib/gettext.h
Normal file
@ -0,0 +1,286 @@
|
||||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2011 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 3, 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 <libintl.h>
|
||||
|
||||
/* 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 <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
|
||||
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
|
||||
it now, to make later inclusions of <libintl.h> a NOP. */
|
||||
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
|
||||
# include <cstdlib>
|
||||
# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# 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". */
|
||||
# undef gettext
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# undef dgettext
|
||||
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
|
||||
# undef dcgettext
|
||||
# define dcgettext(Domainname, Msgid, Category) \
|
||||
((void) (Category), dgettext (Domainname, Msgid))
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 \
|
||||
? ((void) (Msgid2), (const char *) (Msgid1)) \
|
||||
: ((void) (Msgid1), (const char *) (Msgid2)))
|
||||
# undef dngettext
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
|
||||
# undef dcngettext
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) \
|
||||
((void) (Domainname), (const char *) (Dirname))
|
||||
# undef bind_textdomain_codeset
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) \
|
||||
((void) (Domainname), (const char *) (Codeset))
|
||||
|
||||
#endif
|
||||
|
||||
/* Prefer gnulib's setlocale override over libintl's setlocale override. */
|
||||
#ifdef GNULIB_defined_setlocale
|
||||
# undef setlocale
|
||||
# define setlocale rpl_setlocale
|
||||
#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 <string.h>
|
||||
|
||||
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
|
||||
(((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
|
||||
/* || __STDC_VERSION__ >= 199901L */ )
|
||||
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
#include <stdlib.h>
|
||||
#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 */
|
144
lib/gettimeofday.c
Normal file
144
lib/gettimeofday.c
Normal file
@ -0,0 +1,144 @@
|
||||
/* Provide gettimeofday for systems that don't have it or for which it's broken.
|
||||
|
||||
Copyright (C) 2001-2003, 2005-2007, 2009-2011 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 3, 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 */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if HAVE_SYS_TIMEB_H
|
||||
# include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
|
||||
|
||||
/* Work around the bug in some systems whereby gettimeofday clobbers
|
||||
the static buffer that localtime uses for its return value. The
|
||||
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
|
||||
this problem. The tzset replacement is necessary for at least
|
||||
Solaris 2.5, 2.5.1, and 2.6. */
|
||||
|
||||
static struct tm tm_zero_buffer;
|
||||
static struct tm *localtime_buffer_addr = &tm_zero_buffer;
|
||||
|
||||
# undef localtime
|
||||
extern struct tm *localtime (time_t const *);
|
||||
|
||||
# undef gmtime
|
||||
extern struct tm *gmtime (time_t const *);
|
||||
|
||||
/* This is a wrapper for localtime. It is used only on systems for which
|
||||
gettimeofday clobbers the static buffer used for localtime's result.
|
||||
|
||||
On the first call, record the address of the static buffer that
|
||||
localtime uses for its result. */
|
||||
|
||||
struct tm *
|
||||
rpl_localtime (time_t const *timep)
|
||||
{
|
||||
struct tm *tm = localtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* Same as above, since gmtime and localtime use the same buffer. */
|
||||
struct tm *
|
||||
rpl_gmtime (time_t const *timep)
|
||||
{
|
||||
struct tm *tm = gmtime (timep);
|
||||
|
||||
if (localtime_buffer_addr == &tm_zero_buffer)
|
||||
localtime_buffer_addr = tm;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
|
||||
|
||||
#if TZSET_CLOBBERS_LOCALTIME
|
||||
|
||||
# undef tzset
|
||||
extern void tzset (void);
|
||||
|
||||
/* This is a wrapper for tzset, for systems on which tzset may clobber
|
||||
the static buffer used for localtime's result. */
|
||||
void
|
||||
rpl_tzset (void)
|
||||
{
|
||||
/* Save and restore the contents of the buffer used for localtime's
|
||||
result around the call to tzset. */
|
||||
struct tm save = *localtime_buffer_addr;
|
||||
tzset ();
|
||||
*localtime_buffer_addr = save;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This is a wrapper for gettimeofday. It is used only on systems
|
||||
that lack this function, or whose implementation of this function
|
||||
causes problems. */
|
||||
|
||||
int
|
||||
gettimeofday (struct timeval *restrict tv, void *restrict tz)
|
||||
{
|
||||
#undef gettimeofday
|
||||
#if HAVE_GETTIMEOFDAY
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
/* Save and restore the contents of the buffer used for localtime's
|
||||
result around the call to gettimeofday. */
|
||||
struct tm save = *localtime_buffer_addr;
|
||||
# endif
|
||||
|
||||
int result = gettimeofday (tv, (struct timezone *) tz);
|
||||
|
||||
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
|
||||
*localtime_buffer_addr = save;
|
||||
# endif
|
||||
|
||||
return result;
|
||||
|
||||
#else
|
||||
|
||||
# if HAVE__FTIME
|
||||
|
||||
struct _timeb timebuf;
|
||||
_ftime (&timebuf);
|
||||
tv->tv_sec = timebuf.time;
|
||||
tv->tv_usec = timebuf.millitm * 1000;
|
||||
|
||||
# else
|
||||
|
||||
# if !defined OK_TO_USE_1S_CLOCK
|
||||
# error "Only 1-second nominal clock resolution found. Is that intended?" \
|
||||
"If so, compile with the -DOK_TO_USE_1S_CLOCK option."
|
||||
# endif
|
||||
tv->tv_sec = time (NULL);
|
||||
tv->tv_usec = 0;
|
||||
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
174
lib/isnan.c
Normal file
174
lib/isnan.c
Normal file
@ -0,0 +1,174 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
/* Specification found in math.h or isnanl-nolibm.h. */
|
||||
extern int rpl_isnanl (long double x);
|
||||
#elif ! defined USE_FLOAT
|
||||
/* Specification found in math.h or isnand-nolibm.h. */
|
||||
extern int rpl_isnand (double x);
|
||||
#else /* defined USE_FLOAT */
|
||||
/* Specification found in math.h or isnanf-nolibm.h. */
|
||||
extern int rpl_isnanf (float x);
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "float+.h"
|
||||
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# define FUNC rpl_isnanl
|
||||
# define DOUBLE long double
|
||||
# define MAX_EXP LDBL_MAX_EXP
|
||||
# define MIN_EXP LDBL_MIN_EXP
|
||||
# if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
|
||||
# define KNOWN_EXPBIT0_LOCATION
|
||||
# define EXPBIT0_WORD LDBL_EXPBIT0_WORD
|
||||
# define EXPBIT0_BIT LDBL_EXPBIT0_BIT
|
||||
# endif
|
||||
# define SIZE SIZEOF_LDBL
|
||||
# define L_(literal) literal##L
|
||||
#elif ! defined USE_FLOAT
|
||||
# define FUNC rpl_isnand
|
||||
# define DOUBLE double
|
||||
# define MAX_EXP DBL_MAX_EXP
|
||||
# define MIN_EXP DBL_MIN_EXP
|
||||
# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
|
||||
# define KNOWN_EXPBIT0_LOCATION
|
||||
# define EXPBIT0_WORD DBL_EXPBIT0_WORD
|
||||
# define EXPBIT0_BIT DBL_EXPBIT0_BIT
|
||||
# endif
|
||||
# define SIZE SIZEOF_DBL
|
||||
# define L_(literal) literal
|
||||
#else /* defined USE_FLOAT */
|
||||
# define FUNC rpl_isnanf
|
||||
# define DOUBLE float
|
||||
# define MAX_EXP FLT_MAX_EXP
|
||||
# define MIN_EXP FLT_MIN_EXP
|
||||
# if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
|
||||
# define KNOWN_EXPBIT0_LOCATION
|
||||
# define EXPBIT0_WORD FLT_EXPBIT0_WORD
|
||||
# define EXPBIT0_BIT FLT_EXPBIT0_BIT
|
||||
# endif
|
||||
# define SIZE SIZEOF_FLT
|
||||
# define L_(literal) literal##f
|
||||
#endif
|
||||
|
||||
#define EXP_MASK ((MAX_EXP - MIN_EXP) | 7)
|
||||
|
||||
#define NWORDS \
|
||||
((sizeof (DOUBLE) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
typedef union { DOUBLE value; unsigned int word[NWORDS]; } memory_double;
|
||||
|
||||
int
|
||||
FUNC (DOUBLE x)
|
||||
{
|
||||
#ifdef KNOWN_EXPBIT0_LOCATION
|
||||
# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
|
||||
/* Special CPU dependent code is needed to treat bit patterns outside the
|
||||
IEEE 754 specification (such as Pseudo-NaNs, Pseudo-Infinities,
|
||||
Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals) as NaNs.
|
||||
These bit patterns are:
|
||||
- exponent = 0x0001..0x7FFF, mantissa bit 63 = 0,
|
||||
- exponent = 0x0000, mantissa bit 63 = 1.
|
||||
The NaN bit pattern is:
|
||||
- exponent = 0x7FFF, mantissa >= 0x8000000000000001. */
|
||||
memory_double m;
|
||||
unsigned int exponent;
|
||||
|
||||
m.value = x;
|
||||
exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
/* Big endian: EXPBIT0_WORD = 0, EXPBIT0_BIT = 16. */
|
||||
if (exponent == 0)
|
||||
return 1 & (m.word[0] >> 15);
|
||||
else if (exponent == EXP_MASK)
|
||||
return (((m.word[0] ^ 0x8000U) << 16) | m.word[1] | (m.word[2] >> 16)) != 0;
|
||||
else
|
||||
return 1 & ~(m.word[0] >> 15);
|
||||
# else
|
||||
/* Little endian: EXPBIT0_WORD = 2, EXPBIT0_BIT = 0. */
|
||||
if (exponent == 0)
|
||||
return (m.word[1] >> 31);
|
||||
else if (exponent == EXP_MASK)
|
||||
return ((m.word[1] ^ 0x80000000U) | m.word[0]) != 0;
|
||||
else
|
||||
return (m.word[1] >> 31) ^ 1;
|
||||
# endif
|
||||
# else
|
||||
/* Be careful to not do any floating-point operation on x, such as x == x,
|
||||
because x may be a signaling NaN. */
|
||||
# if defined __TINYC__ || defined __SUNPRO_C || defined __DECC \
|
||||
|| (defined __sgi && !defined __GNUC__) || defined __ICC
|
||||
/* The Sun C 5.0, Intel ICC 10.0, and Compaq (ex-DEC) 6.4 compilers don't
|
||||
recognize the initializers as constant expressions. The latter compiler
|
||||
also fails when constant-folding 0.0 / 0.0 even when constant-folding is
|
||||
not required. The SGI MIPSpro C compiler complains about "floating-point
|
||||
operation result is out of range". */
|
||||
static DOUBLE zero = L_(0.0);
|
||||
memory_double nan;
|
||||
DOUBLE plus_inf = L_(1.0) / L_(0.0);
|
||||
DOUBLE minus_inf = -L_(1.0) / L_(0.0);
|
||||
nan.value = zero / zero;
|
||||
# else
|
||||
static memory_double nan = { L_(0.0) / L_(0.0) };
|
||||
static DOUBLE plus_inf = L_(1.0) / L_(0.0);
|
||||
static DOUBLE minus_inf = -L_(1.0) / L_(0.0);
|
||||
# endif
|
||||
{
|
||||
memory_double m;
|
||||
|
||||
/* A NaN can be recognized through its exponent. But exclude +Infinity and
|
||||
-Infinity, which have the same exponent. */
|
||||
m.value = x;
|
||||
if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
|
||||
& (EXP_MASK << EXPBIT0_BIT))
|
||||
== 0)
|
||||
return (memcmp (&m.value, &plus_inf, SIZE) != 0
|
||||
&& memcmp (&m.value, &minus_inf, SIZE) != 0);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
/* The configuration did not find sufficient information. Give up about
|
||||
the signaling NaNs, handle only the quiet NaNs. */
|
||||
if (x == x)
|
||||
{
|
||||
# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
|
||||
/* Detect any special bit patterns that pass ==; see comment above. */
|
||||
memory_double m1;
|
||||
memory_double m2;
|
||||
|
||||
memset (&m1.value, 0, SIZE);
|
||||
memset (&m2.value, 0, SIZE);
|
||||
m1.value = x;
|
||||
m2.value = x + (x ? 0.0L : -0.0L);
|
||||
if (memcmp (&m1.value, &m2.value, SIZE) != 0)
|
||||
return 1;
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
33
lib/isnand-nolibm.h
Normal file
33
lib/isnand-nolibm.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if HAVE_ISNAND_IN_LIBC
|
||||
/* Get declaration of isnan macro. */
|
||||
# include <math.h>
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnand
|
||||
# define isnand(x) __builtin_isnan ((double)(x))
|
||||
# else
|
||||
# undef isnand
|
||||
# define isnand(x) isnan ((double)(x))
|
||||
# endif
|
||||
#else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnand
|
||||
# define isnand rpl_isnand
|
||||
extern int isnand (double x);
|
||||
#endif
|
19
lib/isnand.c
Normal file
19
lib/isnand.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2008-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
|
||||
|
||||
#include "isnan.c"
|
33
lib/isnanf-nolibm.h
Normal file
33
lib/isnanf-nolibm.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if HAVE_ISNANF_IN_LIBC
|
||||
/* Get declaration of isnan macro or (older) isnanf function. */
|
||||
# include <math.h>
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnanf
|
||||
# define isnanf(x) __builtin_isnanf ((float)(x))
|
||||
# elif defined isnan
|
||||
# undef isnanf
|
||||
# define isnanf(x) isnan ((float)(x))
|
||||
# endif
|
||||
#else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnanf
|
||||
# define isnanf rpl_isnanf
|
||||
extern int isnanf (float x);
|
||||
#endif
|
20
lib/isnanf.c
Normal file
20
lib/isnanf.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
||||
|
||||
#define USE_FLOAT
|
||||
#include "isnan.c"
|
33
lib/isnanl-nolibm.h
Normal file
33
lib/isnanl-nolibm.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if HAVE_ISNANL_IN_LIBC
|
||||
/* Get declaration of isnan macro or (older) isnanl function. */
|
||||
# include <math.h>
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnanl
|
||||
# define isnanl(x) __builtin_isnanl ((long double)(x))
|
||||
# elif defined isnan
|
||||
# undef isnanl
|
||||
# define isnanl(x) isnan ((long double)(x))
|
||||
# endif
|
||||
#else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnanl
|
||||
# define isnanl rpl_isnanl
|
||||
extern int isnanl (long double x);
|
||||
#endif
|
20
lib/isnanl.c
Normal file
20
lib/isnanl.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* Test for NaN that does not need libm.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
||||
|
||||
#define USE_LONG_DOUBLE
|
||||
#include "isnan.c"
|
96
lib/locale.in.h
Normal file
96
lib/locale.in.h
Normal file
@ -0,0 +1,96 @@
|
||||
/* A POSIX <locale.h>.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_LOCALE_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_LOCALE_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_LOCALE_H
|
||||
#define _@GUARD_PREFIX@_LOCALE_H
|
||||
|
||||
/* NetBSD 5.0 mis-defines NULL. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* MacOS X 10.5 defines the locale_t type in <xlocale.h>. */
|
||||
#if @HAVE_XLOCALE_H@
|
||||
# include <xlocale.h>
|
||||
#endif
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
|
||||
On systems that don't define it, use the same value as GNU libintl. */
|
||||
#if !defined LC_MESSAGES
|
||||
# define LC_MESSAGES 1729
|
||||
#endif
|
||||
|
||||
#if @GNULIB_SETLOCALE@
|
||||
# if @REPLACE_SETLOCALE@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef setlocale
|
||||
# define setlocale rpl_setlocale
|
||||
# define GNULIB_defined_setlocale 1
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale));
|
||||
_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (setlocale);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef setlocale
|
||||
# if HAVE_RAW_DECL_SETLOCALE
|
||||
_GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
|
||||
"use gnulib module setlocale for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_DUPLOCALE@
|
||||
# if @REPLACE_DUPLOCALE@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef duplocale
|
||||
# define duplocale rpl_duplocale
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
|
||||
# else
|
||||
# if @HAVE_DUPLOCALE@
|
||||
_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
|
||||
# endif
|
||||
# endif
|
||||
# if @HAVE_DUPLOCALE@
|
||||
_GL_CXXALIASWARN (duplocale);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef duplocale
|
||||
# if HAVE_RAW_DECL_DUPLOCALE
|
||||
_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
|
||||
"use gnulib module duplocale for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_LOCALE_H */
|
||||
#endif /* _@GUARD_PREFIX@_LOCALE_H */
|
57
lib/malloc.c
Normal file
57
lib/malloc.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* malloc() function that is glibc compatible.
|
||||
|
||||
Copyright (C) 1997-1998, 2006-2007, 2009-2011 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 3, 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 and Bruno Haible */
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
|
||||
#ifdef malloc
|
||||
# define NEED_MALLOC_GNU 1
|
||||
# undef malloc
|
||||
/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
|
||||
#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
|
||||
# define NEED_MALLOC_GNU 1
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* Allocate an N-byte block of memory from the heap.
|
||||
If N is zero, allocate a 1-byte block. */
|
||||
|
||||
void *
|
||||
rpl_malloc (size_t n)
|
||||
{
|
||||
void *result;
|
||||
|
||||
#if NEED_MALLOC_GNU
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
#endif
|
||||
|
||||
result = malloc (n);
|
||||
|
||||
#if !HAVE_MALLOC_POSIX
|
||||
if (result == NULL)
|
||||
errno = ENOMEM;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
810
lib/math.in.h
Normal file
810
lib/math.in.h
Normal file
@ -0,0 +1,810 @@
|
||||
/* A GNU-like <math.h>.
|
||||
|
||||
Copyright (C) 2002-2003, 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_MATH_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_MATH_H
|
||||
#define _@GUARD_PREFIX@_MATH_H
|
||||
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
/* Helper macros to define a portability warning for the
|
||||
classification macro FUNC called with VALUE. POSIX declares the
|
||||
classification macros with an argument of real-floating (that is,
|
||||
one of float, double, or long double). */
|
||||
#define _GL_WARN_REAL_FLOATING_DECL(func) \
|
||||
static inline int \
|
||||
rpl_ ## func ## f (float f) \
|
||||
{ \
|
||||
return func (f); \
|
||||
} \
|
||||
static inline int \
|
||||
rpl_ ## func ## d (double d) \
|
||||
{ \
|
||||
return func (d); \
|
||||
} \
|
||||
static inline int \
|
||||
rpl_ ## func ## l (long double l) \
|
||||
{ \
|
||||
return func (l); \
|
||||
} \
|
||||
_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \
|
||||
"use gnulib module " #func " for portability"); \
|
||||
_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \
|
||||
"use gnulib module " #func " for portability"); \
|
||||
_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \
|
||||
"use gnulib module " #func " for portability")
|
||||
#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
|
||||
(sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
|
||||
: sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
|
||||
: rpl_ ## func ## l (value))
|
||||
|
||||
|
||||
/* POSIX allows platforms that don't support NAN. But all major
|
||||
machines in the past 15 years have supported something close to
|
||||
IEEE NaN, so we define this unconditionally. We also must define
|
||||
it on platforms like Solaris 10, where NAN is present but defined
|
||||
as a function pointer rather than a floating point constant. */
|
||||
#if !defined NAN || @REPLACE_NAN@
|
||||
# if !GNULIB_defined_NAN
|
||||
# undef NAN
|
||||
/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
|
||||
# ifdef __DECC
|
||||
static float
|
||||
_NaN ()
|
||||
{
|
||||
static float zero = 0.0f;
|
||||
return zero / zero;
|
||||
}
|
||||
# define NAN (_NaN())
|
||||
# else
|
||||
# define NAN (0.0f / 0.0f)
|
||||
# endif
|
||||
# define GNULIB_defined_NAN 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Solaris 10 defines HUGE_VAL, but as a function pointer rather
|
||||
than a floating point constant. */
|
||||
#if @REPLACE_HUGE_VAL@
|
||||
# undef HUGE_VAL
|
||||
# define HUGE_VAL (1.0 / 0.0)
|
||||
#endif
|
||||
|
||||
|
||||
/* Write x as
|
||||
x = mantissa * 2^exp
|
||||
where
|
||||
If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
|
||||
If x is zero: mantissa = x, exp = 0.
|
||||
If x is infinite or NaN: mantissa = x, exp unspecified.
|
||||
Store exp in *EXPPTR and return mantissa. */
|
||||
#if @GNULIB_FREXP@
|
||||
# if @REPLACE_FREXP@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define frexp rpl_frexp
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (frexp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef frexp
|
||||
/* Assume frexp is always declared. */
|
||||
_GL_WARN_ON_USE (frexp, "frexp is unportable - "
|
||||
"use gnulib module frexp for portability");
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_LOGB@
|
||||
# if !@HAVE_DECL_LOGB@
|
||||
_GL_EXTERN_C double logb (double x);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef logb
|
||||
# if HAVE_RAW_DECL_LOGB
|
||||
_GL_WARN_ON_USE (logb, "logb is unportable - "
|
||||
"use gnulib module logb for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ACOSL@
|
||||
# if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@
|
||||
_GL_FUNCDECL_SYS (acosl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (acosl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (acosl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef acosl
|
||||
# if HAVE_RAW_DECL_ACOSL
|
||||
_GL_WARN_ON_USE (acosl, "acosl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ASINL@
|
||||
# if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@
|
||||
_GL_FUNCDECL_SYS (asinl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (asinl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (asinl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef asinl
|
||||
# if HAVE_RAW_DECL_ASINL
|
||||
_GL_WARN_ON_USE (asinl, "asinl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ATANL@
|
||||
# if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@
|
||||
_GL_FUNCDECL_SYS (atanl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (atanl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (atanl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef atanl
|
||||
# if HAVE_RAW_DECL_ATANL
|
||||
_GL_WARN_ON_USE (atanl, "atanl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_CEILF@
|
||||
# if @REPLACE_CEILF@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ceilf rpl_ceilf
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ceilf, float, (float x));
|
||||
_GL_CXXALIAS_RPL (ceilf, float, (float x));
|
||||
# else
|
||||
# if !@HAVE_DECL_CEILF@
|
||||
_GL_FUNCDECL_SYS (ceilf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (ceilf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (ceilf);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef ceilf
|
||||
# if HAVE_RAW_DECL_CEILF
|
||||
_GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
|
||||
"use gnulib module ceilf for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_CEIL@
|
||||
# if @REPLACE_CEIL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ceil rpl_ceil
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ceil, double, (double x));
|
||||
_GL_CXXALIAS_RPL (ceil, double, (double x));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (ceil, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (ceil);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_CEILL@
|
||||
# if @REPLACE_CEILL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ceill rpl_ceill
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ceill, long double, (long double x));
|
||||
_GL_CXXALIAS_RPL (ceill, long double, (long double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_CEILL@
|
||||
_GL_FUNCDECL_SYS (ceill, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (ceill, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (ceill);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef ceill
|
||||
# if HAVE_RAW_DECL_CEILL
|
||||
_GL_WARN_ON_USE (ceill, "ceill is unportable - "
|
||||
"use gnulib module ceill for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_COSL@
|
||||
# if !@HAVE_COSL@ || !@HAVE_DECL_COSL@
|
||||
_GL_FUNCDECL_SYS (cosl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (cosl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (cosl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef cosl
|
||||
# if HAVE_RAW_DECL_COSL
|
||||
_GL_WARN_ON_USE (cosl, "cosl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_EXPL@
|
||||
# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
|
||||
_GL_FUNCDECL_SYS (expl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (expl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (expl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef expl
|
||||
# if HAVE_RAW_DECL_EXPL
|
||||
_GL_WARN_ON_USE (expl, "expl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_FLOORF@
|
||||
# if @REPLACE_FLOORF@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define floorf rpl_floorf
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (floorf, float, (float x));
|
||||
_GL_CXXALIAS_RPL (floorf, float, (float x));
|
||||
# else
|
||||
# if !@HAVE_DECL_FLOORF@
|
||||
_GL_FUNCDECL_SYS (floorf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (floorf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (floorf);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef floorf
|
||||
# if HAVE_RAW_DECL_FLOORF
|
||||
_GL_WARN_ON_USE (floorf, "floorf is unportable - "
|
||||
"use gnulib module floorf for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FLOOR@
|
||||
# if @REPLACE_FLOOR@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define floor rpl_floor
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (floor, double, (double x));
|
||||
_GL_CXXALIAS_RPL (floor, double, (double x));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (floor, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (floor);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FLOORL@
|
||||
# if @REPLACE_FLOORL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define floorl rpl_floorl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (floorl, long double, (long double x));
|
||||
_GL_CXXALIAS_RPL (floorl, long double, (long double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_FLOORL@
|
||||
_GL_FUNCDECL_SYS (floorl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (floorl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (floorl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef floorl
|
||||
# if HAVE_RAW_DECL_FLOORL
|
||||
_GL_WARN_ON_USE (floorl, "floorl is unportable - "
|
||||
"use gnulib module floorl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Write x as
|
||||
x = mantissa * 2^exp
|
||||
where
|
||||
If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
|
||||
If x is zero: mantissa = x, exp = 0.
|
||||
If x is infinite or NaN: mantissa = x, exp unspecified.
|
||||
Store exp in *EXPPTR and return mantissa. */
|
||||
#if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define frexpl rpl_frexpl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (frexpl, long double,
|
||||
(long double x, int *expptr) _GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
|
||||
#else
|
||||
# if !@HAVE_DECL_FREXPL@
|
||||
_GL_FUNCDECL_SYS (frexpl, long double,
|
||||
(long double x, int *expptr) _GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
# if @GNULIB_FREXPL@
|
||||
_GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
|
||||
# endif
|
||||
#endif
|
||||
#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
|
||||
_GL_CXXALIASWARN (frexpl);
|
||||
#endif
|
||||
#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
|
||||
# undef frexpl
|
||||
# if HAVE_RAW_DECL_FREXPL
|
||||
_GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
|
||||
"use gnulib module frexpl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return x * 2^exp. */
|
||||
#if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ldexpl rpl_ldexpl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
|
||||
_GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
|
||||
#else
|
||||
# if !@HAVE_DECL_LDEXPL@
|
||||
_GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
|
||||
# endif
|
||||
# if @GNULIB_LDEXPL@
|
||||
_GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
|
||||
# endif
|
||||
#endif
|
||||
#if @GNULIB_LDEXPL@
|
||||
_GL_CXXALIASWARN (ldexpl);
|
||||
#endif
|
||||
#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
|
||||
# undef ldexpl
|
||||
# if HAVE_RAW_DECL_LDEXPL
|
||||
_GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
|
||||
"use gnulib module ldexpl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_LOGL@
|
||||
# if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@
|
||||
_GL_FUNCDECL_SYS (logl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (logl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (logl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef logl
|
||||
# if HAVE_RAW_DECL_LOGL
|
||||
_GL_WARN_ON_USE (logl, "logl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ROUNDF@
|
||||
# if @REPLACE_ROUNDF@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef roundf
|
||||
# define roundf rpl_roundf
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (roundf, float, (float x));
|
||||
_GL_CXXALIAS_RPL (roundf, float, (float x));
|
||||
# else
|
||||
# if !@HAVE_DECL_ROUNDF@
|
||||
_GL_FUNCDECL_SYS (roundf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (roundf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (roundf);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef roundf
|
||||
# if HAVE_RAW_DECL_ROUNDF
|
||||
_GL_WARN_ON_USE (roundf, "roundf is unportable - "
|
||||
"use gnulib module roundf for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ROUND@
|
||||
# if @REPLACE_ROUND@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef round
|
||||
# define round rpl_round
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (round, double, (double x));
|
||||
_GL_CXXALIAS_RPL (round, double, (double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_ROUND@
|
||||
_GL_FUNCDECL_SYS (round, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (round, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (round);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef round
|
||||
# if HAVE_RAW_DECL_ROUND
|
||||
_GL_WARN_ON_USE (round, "round is unportable - "
|
||||
"use gnulib module round for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ROUNDL@
|
||||
# if @REPLACE_ROUNDL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef roundl
|
||||
# define roundl rpl_roundl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (roundl, long double, (long double x));
|
||||
_GL_CXXALIAS_RPL (roundl, long double, (long double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_ROUNDL@
|
||||
_GL_FUNCDECL_SYS (roundl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (roundl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (roundl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef roundl
|
||||
# if HAVE_RAW_DECL_ROUNDL
|
||||
_GL_WARN_ON_USE (roundl, "roundl is unportable - "
|
||||
"use gnulib module roundl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_SINL@
|
||||
# if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
|
||||
_GL_FUNCDECL_SYS (sinl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sinl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (sinl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef sinl
|
||||
# if HAVE_RAW_DECL_SINL
|
||||
_GL_WARN_ON_USE (sinl, "sinl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_SQRTL@
|
||||
# if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@
|
||||
_GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (sqrtl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef sqrtl
|
||||
# if HAVE_RAW_DECL_SQRTL
|
||||
_GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_TANL@
|
||||
# if !@HAVE_TANL@ || !@HAVE_DECL_TANL@
|
||||
_GL_FUNCDECL_SYS (tanl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (tanl, long double, (long double x));
|
||||
_GL_CXXALIASWARN (tanl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef tanl
|
||||
# if HAVE_RAW_DECL_TANL
|
||||
_GL_WARN_ON_USE (tanl, "tanl is unportable - "
|
||||
"use gnulib module mathl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_TRUNCF@
|
||||
# if @REPLACE_TRUNCF@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define truncf rpl_truncf
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (truncf, float, (float x));
|
||||
_GL_CXXALIAS_RPL (truncf, float, (float x));
|
||||
# else
|
||||
# if !@HAVE_DECL_TRUNCF@
|
||||
_GL_FUNCDECL_SYS (truncf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (truncf, float, (float x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (truncf);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef truncf
|
||||
# if HAVE_RAW_DECL_TRUNCF
|
||||
_GL_WARN_ON_USE (truncf, "truncf is unportable - "
|
||||
"use gnulib module truncf for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_TRUNC@
|
||||
# if @REPLACE_TRUNC@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define trunc rpl_trunc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (trunc, double, (double x));
|
||||
_GL_CXXALIAS_RPL (trunc, double, (double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_TRUNC@
|
||||
_GL_FUNCDECL_SYS (trunc, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (trunc, double, (double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (trunc);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef trunc
|
||||
# if HAVE_RAW_DECL_TRUNC
|
||||
_GL_WARN_ON_USE (trunc, "trunc is unportable - "
|
||||
"use gnulib module trunc for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_TRUNCL@
|
||||
# if @REPLACE_TRUNCL@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef truncl
|
||||
# define truncl rpl_truncl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (truncl, long double, (long double x));
|
||||
_GL_CXXALIAS_RPL (truncl, long double, (long double x));
|
||||
# else
|
||||
# if !@HAVE_DECL_TRUNCL@
|
||||
_GL_FUNCDECL_SYS (truncl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (truncl, long double, (long double x));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (truncl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef truncl
|
||||
# if HAVE_RAW_DECL_TRUNCL
|
||||
_GL_WARN_ON_USE (truncl, "truncl is unportable - "
|
||||
"use gnulib module truncl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ISFINITE@
|
||||
# if @REPLACE_ISFINITE@
|
||||
_GL_EXTERN_C int gl_isfinitef (float x);
|
||||
_GL_EXTERN_C int gl_isfinited (double x);
|
||||
_GL_EXTERN_C int gl_isfinitel (long double x);
|
||||
# undef isfinite
|
||||
# define isfinite(x) \
|
||||
(sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
|
||||
sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
|
||||
gl_isfinitef (x))
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# if defined isfinite
|
||||
_GL_WARN_REAL_FLOATING_DECL (isfinite);
|
||||
# undef isfinite
|
||||
# define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ISINF@
|
||||
# if @REPLACE_ISINF@
|
||||
_GL_EXTERN_C int gl_isinff (float x);
|
||||
_GL_EXTERN_C int gl_isinfd (double x);
|
||||
_GL_EXTERN_C int gl_isinfl (long double x);
|
||||
# undef isinf
|
||||
# define isinf(x) \
|
||||
(sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
|
||||
sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
|
||||
gl_isinff (x))
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# if defined isinf
|
||||
_GL_WARN_REAL_FLOATING_DECL (isinf);
|
||||
# undef isinf
|
||||
# define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ISNANF@
|
||||
/* Test for NaN for 'float' numbers. */
|
||||
# if @HAVE_ISNANF@
|
||||
/* The original <math.h> included above provides a declaration of isnan macro
|
||||
or (older) isnanf function. */
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnanf
|
||||
# define isnanf(x) __builtin_isnanf ((float)(x))
|
||||
# elif defined isnan
|
||||
# undef isnanf
|
||||
# define isnanf(x) isnan ((float)(x))
|
||||
# endif
|
||||
# else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnanf
|
||||
# define isnanf rpl_isnanf
|
||||
_GL_EXTERN_C int isnanf (float x);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ISNAND@
|
||||
/* Test for NaN for 'double' numbers.
|
||||
This function is a gnulib extension, unlike isnan() which applied only
|
||||
to 'double' numbers earlier but now is a type-generic macro. */
|
||||
# if @HAVE_ISNAND@
|
||||
/* The original <math.h> included above provides a declaration of isnan
|
||||
macro. */
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnand
|
||||
# define isnand(x) __builtin_isnan ((double)(x))
|
||||
# else
|
||||
# undef isnand
|
||||
# define isnand(x) isnan ((double)(x))
|
||||
# endif
|
||||
# else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnand
|
||||
# define isnand rpl_isnand
|
||||
_GL_EXTERN_C int isnand (double x);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_ISNANL@
|
||||
/* Test for NaN for 'long double' numbers. */
|
||||
# if @HAVE_ISNANL@
|
||||
/* The original <math.h> included above provides a declaration of isnan
|
||||
macro or (older) isnanl function. */
|
||||
# if __GNUC__ >= 4
|
||||
/* GCC 4.0 and newer provides three built-ins for isnan. */
|
||||
# undef isnanl
|
||||
# define isnanl(x) __builtin_isnanl ((long double)(x))
|
||||
# elif defined isnan
|
||||
# undef isnanl
|
||||
# define isnanl(x) isnan ((long double)(x))
|
||||
# endif
|
||||
# else
|
||||
/* Test whether X is a NaN. */
|
||||
# undef isnanl
|
||||
# define isnanl rpl_isnanl
|
||||
_GL_EXTERN_C int isnanl (long double x);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */
|
||||
#if @GNULIB_ISNAN@
|
||||
# if @REPLACE_ISNAN@
|
||||
/* We can't just use the isnanf macro (e.g.) as exposed by
|
||||
isnanf.h (e.g.) here, because those may end up being macros
|
||||
that recursively expand back to isnan. So use the gnulib
|
||||
replacements for them directly. */
|
||||
# if @HAVE_ISNANF@ && __GNUC__ >= 4
|
||||
# define gl_isnan_f(x) __builtin_isnanf ((float)(x))
|
||||
# else
|
||||
_GL_EXTERN_C int rpl_isnanf (float x);
|
||||
# define gl_isnan_f(x) rpl_isnanf (x)
|
||||
# endif
|
||||
# if @HAVE_ISNAND@ && __GNUC__ >= 4
|
||||
# define gl_isnan_d(x) __builtin_isnan ((double)(x))
|
||||
# else
|
||||
_GL_EXTERN_C int rpl_isnand (double x);
|
||||
# define gl_isnan_d(x) rpl_isnand (x)
|
||||
# endif
|
||||
# if @HAVE_ISNANL@ && __GNUC__ >= 4
|
||||
# define gl_isnan_l(x) __builtin_isnanl ((long double)(x))
|
||||
# else
|
||||
_GL_EXTERN_C int rpl_isnanl (long double x);
|
||||
# define gl_isnan_l(x) rpl_isnanl (x)
|
||||
# endif
|
||||
# undef isnan
|
||||
# define isnan(x) \
|
||||
(sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
|
||||
sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
|
||||
gl_isnan_f (x))
|
||||
# elif __GNUC__ >= 4
|
||||
# undef isnan
|
||||
# define isnan(x) \
|
||||
(sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \
|
||||
sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
|
||||
__builtin_isnanf ((float)(x)))
|
||||
# endif
|
||||
/* Ensure isnan is a macro. */
|
||||
# ifndef isnan
|
||||
# define isnan isnan
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# if defined isnan
|
||||
_GL_WARN_REAL_FLOATING_DECL (isnan);
|
||||
# undef isnan
|
||||
# define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_SIGNBIT@
|
||||
# if @REPLACE_SIGNBIT_USING_GCC@
|
||||
# undef signbit
|
||||
/* GCC 4.0 and newer provides three built-ins for signbit. */
|
||||
# define signbit(x) \
|
||||
(sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
|
||||
sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
|
||||
__builtin_signbitf (x))
|
||||
# endif
|
||||
# if @REPLACE_SIGNBIT@
|
||||
# undef signbit
|
||||
_GL_EXTERN_C int gl_signbitf (float arg);
|
||||
_GL_EXTERN_C int gl_signbitd (double arg);
|
||||
_GL_EXTERN_C int gl_signbitl (long double arg);
|
||||
# if __GNUC__ >= 2 && !__STRICT_ANSI__
|
||||
# define _GL_NUM_UINT_WORDS(type) \
|
||||
((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
|
||||
# define gl_signbitf_OPTIMIZED_MACRO
|
||||
# define gl_signbitf(arg) \
|
||||
({ union { float _value; \
|
||||
unsigned int _word[_GL_NUM_UINT_WORDS (float)]; \
|
||||
} _m; \
|
||||
_m._value = (arg); \
|
||||
(_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
|
||||
})
|
||||
# endif
|
||||
# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
|
||||
# define gl_signbitd_OPTIMIZED_MACRO
|
||||
# define gl_signbitd(arg) \
|
||||
({ union { double _value; \
|
||||
unsigned int _word[_GL_NUM_UINT_WORDS (double)]; \
|
||||
} _m; \
|
||||
_m._value = (arg); \
|
||||
(_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
|
||||
})
|
||||
# endif
|
||||
# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
|
||||
# define gl_signbitl_OPTIMIZED_MACRO
|
||||
# define gl_signbitl(arg) \
|
||||
({ union { long double _value; \
|
||||
unsigned int _word[_GL_NUM_UINT_WORDS (long double)]; \
|
||||
} _m; \
|
||||
_m._value = (arg); \
|
||||
(_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
|
||||
})
|
||||
# endif
|
||||
# endif
|
||||
# define signbit(x) \
|
||||
(sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
|
||||
sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
|
||||
gl_signbitf (x))
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# if defined signbit
|
||||
_GL_WARN_REAL_FLOATING_DECL (signbit);
|
||||
# undef signbit
|
||||
# define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_MATH_H */
|
||||
#endif /* _@GUARD_PREFIX@_MATH_H */
|
172
lib/memchr.c
Normal file
172
lib/memchr.c
Normal file
@ -0,0 +1,172 @@
|
||||
/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2011
|
||||
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 3 of the License, or 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined _LIBC
|
||||
# include <memcopy.h>
|
||||
#else
|
||||
# define reg_char char
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if HAVE_BP_SYM_H || defined _LIBC
|
||||
# include <bp-sym.h>
|
||||
#else
|
||||
# define BP_SYM(sym) sym
|
||||
#endif
|
||||
|
||||
#undef __memchr
|
||||
#ifdef _LIBC
|
||||
# undef memchr
|
||||
#endif
|
||||
|
||||
#ifndef weak_alias
|
||||
# define __memchr memchr
|
||||
#endif
|
||||
|
||||
/* Search no more than N bytes of S for C. */
|
||||
void *
|
||||
__memchr (void const *s, int c_in, size_t n)
|
||||
{
|
||||
/* On 32-bit hardware, choosing longword to be a 32-bit unsigned
|
||||
long instead of a 64-bit uintmax_t tends to give better
|
||||
performance. On 64-bit hardware, unsigned long is generally 64
|
||||
bits already. Change this typedef to experiment with
|
||||
performance. */
|
||||
typedef unsigned long int longword;
|
||||
|
||||
const unsigned char *char_ptr;
|
||||
const longword *longword_ptr;
|
||||
longword repeated_one;
|
||||
longword repeated_c;
|
||||
unsigned reg_char c;
|
||||
|
||||
c = (unsigned char) c_in;
|
||||
|
||||
/* Handle the first few bytes by reading one byte 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;
|
||||
|
||||
longword_ptr = (const longword *) char_ptr;
|
||||
|
||||
/* All these elucidatory comments refer to 4-byte longwords,
|
||||
but the theory applies equally well to any size longwords. */
|
||||
|
||||
/* Compute auxiliary longword values:
|
||||
repeated_one is a value which has a 1 in every byte.
|
||||
repeated_c has c in every byte. */
|
||||
repeated_one = 0x01010101;
|
||||
repeated_c = c | (c << 8);
|
||||
repeated_c |= repeated_c << 16;
|
||||
if (0xffffffffU < (longword) -1)
|
||||
{
|
||||
repeated_one |= repeated_one << 31 << 1;
|
||||
repeated_c |= repeated_c << 31 << 1;
|
||||
if (8 < sizeof (longword))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 64; i < sizeof (longword) * 8; i *= 2)
|
||||
{
|
||||
repeated_one |= repeated_one << i;
|
||||
repeated_c |= repeated_c << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Instead of the traditional loop which tests each byte, 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 equal to c. We first use an xor
|
||||
with repeated_c. This reduces the task to testing whether *any of the
|
||||
four* bytes in longword1 is zero.
|
||||
|
||||
We compute tmp =
|
||||
((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
|
||||
That is, we perform the following operations:
|
||||
1. Subtract repeated_one.
|
||||
2. & ~longword1.
|
||||
3. & a mask consisting of 0x80 in every byte.
|
||||
Consider what happens in each byte:
|
||||
- If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
|
||||
and step 3 transforms it into 0x80. A carry can also be propagated
|
||||
to more significant bytes.
|
||||
- If a byte of longword1 is nonzero, let its lowest 1 bit be at
|
||||
position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
|
||||
the byte ends in a single bit of value 0 and k bits of value 1.
|
||||
After step 2, the result is just k bits of value 1: 2^k - 1. After
|
||||
step 3, the result is 0. And no carry is produced.
|
||||
So, if longword1 has only non-zero bytes, tmp is zero.
|
||||
Whereas if longword1 has a zero byte, call j the position of the least
|
||||
significant zero byte. Then the result has a zero at positions 0, ...,
|
||||
j-1 and a 0x80 at position j. We cannot predict the result at the more
|
||||
significant bytes (positions j+1..3), but it does not matter since we
|
||||
already have a non-zero bit at position 8*j+7.
|
||||
|
||||
So, the test whether any byte in longword1 is zero is equivalent to
|
||||
testing whether tmp is nonzero. */
|
||||
|
||||
while (n >= sizeof (longword))
|
||||
{
|
||||
longword longword1 = *longword_ptr ^ repeated_c;
|
||||
|
||||
if ((((longword1 - repeated_one) & ~longword1)
|
||||
& (repeated_one << 7)) != 0)
|
||||
break;
|
||||
longword_ptr++;
|
||||
n -= sizeof (longword);
|
||||
}
|
||||
|
||||
char_ptr = (const unsigned char *) longword_ptr;
|
||||
|
||||
/* At this point, we know that either n < sizeof (longword), or one of the
|
||||
sizeof (longword) bytes starting at char_ptr is == c. On little-endian
|
||||
machines, we could determine the first such byte without any further
|
||||
memory accesses, just by looking at the tmp result from the last loop
|
||||
iteration. But this does not work on big-endian machines. Choose code
|
||||
that works in both cases. */
|
||||
|
||||
for (; n > 0; --n, ++char_ptr)
|
||||
{
|
||||
if (*char_ptr == c)
|
||||
return (void *) char_ptr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__memchr, BP_SYM (memchr))
|
||||
#endif
|
14
lib/memchr.valgrind
Normal file
14
lib/memchr.valgrind
Normal file
@ -0,0 +1,14 @@
|
||||
# Suppress a valgrind message about use of uninitialized memory in memchr().
|
||||
# POSIX states that when the character is found, memchr must not read extra
|
||||
# bytes in an overestimated length (for example, where memchr is used to
|
||||
# implement strnlen). However, we use a safe word read to provide a speedup.
|
||||
{
|
||||
memchr-value4
|
||||
Memcheck:Value4
|
||||
fun:rpl_memchr
|
||||
}
|
||||
{
|
||||
memchr-value8
|
||||
Memcheck:Value8
|
||||
fun:rpl_memchr
|
||||
}
|
188
lib/printf-args.c
Normal file
188
lib/printf-args.c
Normal file
@ -0,0 +1,188 @@
|
||||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2011 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 3, 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. */
|
||||
|
||||
/* This file can be parametrized with the following macros:
|
||||
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||
PRINTF_FETCHARGS Name of the function to be defined.
|
||||
STATIC Set to 'static' to declare the function static. */
|
||||
|
||||
#ifndef PRINTF_FETCHARGS
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#ifndef PRINTF_FETCHARGS
|
||||
# include "printf-args.h"
|
||||
#endif
|
||||
|
||||
#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;
|
||||
#if 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;
|
||||
case TYPE_LONGDOUBLE:
|
||||
ap->a.a_longdouble = va_arg (args, long double);
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
ap->a.a_char = va_arg (args, int);
|
||||
break;
|
||||
#if 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)
|
||||
? (wint_t) 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;
|
||||
#if 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;
|
||||
#if HAVE_LONG_LONG_INT
|
||||
case TYPE_COUNT_LONGLONGINT_POINTER:
|
||||
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
|
||||
break;
|
||||
#endif
|
||||
#if ENABLE_UNISTDIO
|
||||
/* The unistdio extensions. */
|
||||
case TYPE_U8_STRING:
|
||||
ap->a.a_u8_string = va_arg (args, const uint8_t *);
|
||||
/* A null pointer is an invalid argument for "%U", but in practice
|
||||
it occurs quite frequently in printf statements that produce
|
||||
debug output. Use a fallback in this case. */
|
||||
if (ap->a.a_u8_string == NULL)
|
||||
{
|
||||
static const uint8_t u8_null_string[] =
|
||||
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||
ap->a.a_u8_string = u8_null_string;
|
||||
}
|
||||
break;
|
||||
case TYPE_U16_STRING:
|
||||
ap->a.a_u16_string = va_arg (args, const uint16_t *);
|
||||
/* A null pointer is an invalid argument for "%lU", but in practice
|
||||
it occurs quite frequently in printf statements that produce
|
||||
debug output. Use a fallback in this case. */
|
||||
if (ap->a.a_u16_string == NULL)
|
||||
{
|
||||
static const uint16_t u16_null_string[] =
|
||||
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||
ap->a.a_u16_string = u16_null_string;
|
||||
}
|
||||
break;
|
||||
case TYPE_U32_STRING:
|
||||
ap->a.a_u32_string = va_arg (args, const uint32_t *);
|
||||
/* A null pointer is an invalid argument for "%llU", but in practice
|
||||
it occurs quite frequently in printf statements that produce
|
||||
debug output. Use a fallback in this case. */
|
||||
if (ap->a.a_u32_string == NULL)
|
||||
{
|
||||
static const uint32_t u32_null_string[] =
|
||||
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||
ap->a.a_u32_string = u32_null_string;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* Unknown type. */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
159
lib/printf-args.h
Normal file
159
lib/printf-args.h
Normal file
@ -0,0 +1,159 @@
|
||||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003, 2006-2007, 2011 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 3, 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
|
||||
|
||||
/* This file can be parametrized with the following macros:
|
||||
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||
PRINTF_FETCHARGS Name of the function to be declared.
|
||||
STATIC Set to 'static' to declare the function static. */
|
||||
|
||||
/* Default parameters. */
|
||||
#ifndef PRINTF_FETCHARGS
|
||||
# define PRINTF_FETCHARGS printf_fetchargs
|
||||
#endif
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get wchar_t. */
|
||||
#if HAVE_WCHAR_T
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
/* Get wint_t. */
|
||||
#if HAVE_WINT_T
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/* Argument types */
|
||||
typedef enum
|
||||
{
|
||||
TYPE_NONE,
|
||||
TYPE_SCHAR,
|
||||
TYPE_UCHAR,
|
||||
TYPE_SHORT,
|
||||
TYPE_USHORT,
|
||||
TYPE_INT,
|
||||
TYPE_UINT,
|
||||
TYPE_LONGINT,
|
||||
TYPE_ULONGINT,
|
||||
#if HAVE_LONG_LONG_INT
|
||||
TYPE_LONGLONGINT,
|
||||
TYPE_ULONGLONGINT,
|
||||
#endif
|
||||
TYPE_DOUBLE,
|
||||
TYPE_LONGDOUBLE,
|
||||
TYPE_CHAR,
|
||||
#if HAVE_WINT_T
|
||||
TYPE_WIDE_CHAR,
|
||||
#endif
|
||||
TYPE_STRING,
|
||||
#if 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
|
||||
#if HAVE_LONG_LONG_INT
|
||||
, TYPE_COUNT_LONGLONGINT_POINTER
|
||||
#endif
|
||||
#if ENABLE_UNISTDIO
|
||||
/* The unistdio extensions. */
|
||||
, TYPE_U8_STRING
|
||||
, TYPE_U16_STRING
|
||||
, TYPE_U32_STRING
|
||||
#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;
|
||||
#if HAVE_LONG_LONG_INT
|
||||
long long int a_longlongint;
|
||||
unsigned long long int a_ulonglongint;
|
||||
#endif
|
||||
float a_float;
|
||||
double a_double;
|
||||
long double a_longdouble;
|
||||
int a_char;
|
||||
#if HAVE_WINT_T
|
||||
wint_t a_wide_char;
|
||||
#endif
|
||||
const char* a_string;
|
||||
#if 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;
|
||||
#if HAVE_LONG_LONG_INT
|
||||
long long int * a_count_longlongint_pointer;
|
||||
#endif
|
||||
#if ENABLE_UNISTDIO
|
||||
/* The unistdio extensions. */
|
||||
const uint8_t * a_u8_string;
|
||||
const uint16_t * a_u16_string;
|
||||
const uint32_t * a_u32_string;
|
||||
#endif
|
||||
}
|
||||
a;
|
||||
}
|
||||
argument;
|
||||
|
||||
/* Number of directly allocated arguments (no malloc() needed). */
|
||||
#define N_DIRECT_ALLOC_ARGUMENTS 7
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t count;
|
||||
argument *arg;
|
||||
argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
|
||||
}
|
||||
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 */
|
188
lib/printf-frexp.c
Normal file
188
lib/printf-frexp.c
Normal file
@ -0,0 +1,188 @@
|
||||
/* Split a double into fraction and mantissa, for hexadecimal printf.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# include "printf-frexpl.h"
|
||||
#else
|
||||
# include "printf-frexp.h"
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# include "fpucw.h"
|
||||
#endif
|
||||
|
||||
/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
|
||||
than 2, or not even a power of 2, some rounding errors can occur, so that
|
||||
then the returned mantissa is only guaranteed to be <= 2.0, not < 2.0. */
|
||||
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
# define FUNC printf_frexpl
|
||||
# define DOUBLE long double
|
||||
# define MIN_EXP LDBL_MIN_EXP
|
||||
# if HAVE_FREXPL_IN_LIBC && HAVE_LDEXPL_IN_LIBC
|
||||
# define USE_FREXP_LDEXP
|
||||
# define FREXP frexpl
|
||||
# define LDEXP ldexpl
|
||||
# endif
|
||||
# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
|
||||
# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
|
||||
# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
|
||||
# define L_(literal) literal##L
|
||||
#else
|
||||
# define FUNC printf_frexp
|
||||
# define DOUBLE double
|
||||
# define MIN_EXP DBL_MIN_EXP
|
||||
# if HAVE_FREXP_IN_LIBC && HAVE_LDEXP_IN_LIBC
|
||||
# define USE_FREXP_LDEXP
|
||||
# define FREXP frexp
|
||||
# define LDEXP ldexp
|
||||
# endif
|
||||
# define DECL_ROUNDING
|
||||
# define BEGIN_ROUNDING()
|
||||
# define END_ROUNDING()
|
||||
# define L_(literal) literal
|
||||
#endif
|
||||
|
||||
DOUBLE
|
||||
FUNC (DOUBLE x, int *expptr)
|
||||
{
|
||||
int exponent;
|
||||
DECL_ROUNDING
|
||||
|
||||
BEGIN_ROUNDING ();
|
||||
|
||||
#ifdef USE_FREXP_LDEXP
|
||||
/* frexp and ldexp are usually faster than the loop below. */
|
||||
x = FREXP (x, &exponent);
|
||||
|
||||
x = x + x;
|
||||
exponent -= 1;
|
||||
|
||||
if (exponent < MIN_EXP - 1)
|
||||
{
|
||||
x = LDEXP (x, exponent - (MIN_EXP - 1));
|
||||
exponent = MIN_EXP - 1;
|
||||
}
|
||||
#else
|
||||
{
|
||||
/* Since the exponent is an 'int', it fits in 64 bits. Therefore the
|
||||
loops are executed no more than 64 times. */
|
||||
DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
|
||||
DOUBLE powh[64]; /* powh[i] = 2^-2^i */
|
||||
int i;
|
||||
|
||||
exponent = 0;
|
||||
if (x >= L_(1.0))
|
||||
{
|
||||
/* A nonnegative exponent. */
|
||||
{
|
||||
DOUBLE pow2_i; /* = pow2[i] */
|
||||
DOUBLE powh_i; /* = powh[i] */
|
||||
|
||||
/* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
|
||||
x * 2^exponent = argument, x >= 1.0. */
|
||||
for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
|
||||
;
|
||||
i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
|
||||
{
|
||||
if (x >= pow2_i)
|
||||
{
|
||||
exponent += (1 << i);
|
||||
x *= powh_i;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
pow2[i] = pow2_i;
|
||||
powh[i] = powh_i;
|
||||
}
|
||||
}
|
||||
/* Here 1.0 <= x < 2^2^i. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A negative exponent. */
|
||||
{
|
||||
DOUBLE pow2_i; /* = pow2[i] */
|
||||
DOUBLE powh_i; /* = powh[i] */
|
||||
|
||||
/* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
|
||||
x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */
|
||||
for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
|
||||
;
|
||||
i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
|
||||
{
|
||||
if (exponent - (1 << i) < MIN_EXP - 1)
|
||||
break;
|
||||
|
||||
exponent -= (1 << i);
|
||||
x *= pow2_i;
|
||||
if (x >= L_(1.0))
|
||||
break;
|
||||
|
||||
pow2[i] = pow2_i;
|
||||
powh[i] = powh_i;
|
||||
}
|
||||
}
|
||||
/* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent,
|
||||
or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
|
||||
|
||||
if (x < L_(1.0))
|
||||
/* Invariants: x * 2^exponent = argument, x < 1.0 and
|
||||
exponent - 2^i < MIN_EXP - 1 <= exponent. */
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
if (exponent - (1 << i) >= MIN_EXP - 1)
|
||||
{
|
||||
exponent -= (1 << i);
|
||||
x *= pow2[i];
|
||||
if (x >= L_(1.0))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here either x < 1.0 and exponent = MIN_EXP - 1,
|
||||
or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
|
||||
}
|
||||
|
||||
/* Invariants: x * 2^exponent = argument, and
|
||||
either x < 1.0 and exponent = MIN_EXP - 1,
|
||||
or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
if (x >= pow2[i])
|
||||
{
|
||||
exponent += (1 << i);
|
||||
x *= powh[i];
|
||||
}
|
||||
}
|
||||
/* Here either x < 1.0 and exponent = MIN_EXP - 1,
|
||||
or 1.0 <= x < 2.0 and exponent >= MIN_EXP - 1. */
|
||||
}
|
||||
#endif
|
||||
|
||||
END_ROUNDING ();
|
||||
|
||||
*expptr = exponent;
|
||||
return x;
|
||||
}
|
23
lib/printf-frexp.h
Normal file
23
lib/printf-frexp.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* Split a double into fraction and mantissa, for hexadecimal printf.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Write a finite, positive number x as
|
||||
x = mantissa * 2^exp
|
||||
where exp >= DBL_MIN_EXP - 1,
|
||||
mantissa < 2.0,
|
||||
if x is not a denormalized number then mantissa >= 1.0.
|
||||
Store exp in *EXPPTR and return mantissa. */
|
||||
extern double printf_frexp (double x, int *expptr);
|
18
lib/printf-frexpl.c
Normal file
18
lib/printf-frexpl.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define USE_LONG_DOUBLE
|
||||
#include "printf-frexp.c"
|
23
lib/printf-frexpl.h
Normal file
23
lib/printf-frexpl.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Write a finite, positive number x as
|
||||
x = mantissa * 2^exp
|
||||
where exp >= LDBL_MIN_EXP - 1,
|
||||
mantissa < 2.0,
|
||||
if x is not a denormalized number then mantissa >= 1.0.
|
||||
Store exp in *EXPPTR and return mantissa. */
|
||||
extern long double printf_frexpl (long double x, int *expptr);
|
639
lib/printf-parse.c
Normal file
639
lib/printf-parse.c
Normal file
@ -0,0 +1,639 @@
|
||||
/* Formatted output to strings.
|
||||
Copyright (C) 1999-2000, 2002-2003, 2006-2011 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 3, 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. */
|
||||
|
||||
/* This file can be parametrized with the following macros:
|
||||
CHAR_T The element type of the format string.
|
||||
CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
|
||||
in the format string are ASCII.
|
||||
DIRECTIVE Structure denoting a format directive.
|
||||
Depends on CHAR_T.
|
||||
DIRECTIVES Structure denoting the set of format directives of a
|
||||
format string. Depends on CHAR_T.
|
||||
PRINTF_PARSE Function that parses a format string.
|
||||
Depends on CHAR_T.
|
||||
STATIC Set to 'static' to declare the function static.
|
||||
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
|
||||
|
||||
#ifndef PRINTF_PARSE
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#ifndef PRINTF_PARSE
|
||||
# include "printf-parse.h"
|
||||
#endif
|
||||
|
||||
/* Default parameters. */
|
||||
#ifndef PRINTF_PARSE
|
||||
# define PRINTF_PARSE printf_parse
|
||||
# define CHAR_T char
|
||||
# define DIRECTIVE char_directive
|
||||
# define DIRECTIVES char_directives
|
||||
#endif
|
||||
|
||||
/* Get size_t, NULL. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get intmax_t. */
|
||||
#if defined IN_LIBINTL || defined IN_LIBASPRINTF
|
||||
# if HAVE_STDINT_H_WITH_UINTMAX
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
# if HAVE_INTTYPES_H_WITH_UINTMAX
|
||||
# include <inttypes.h>
|
||||
# endif
|
||||
#else
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* malloc(), realloc(), free(). */
|
||||
#include <stdlib.h>
|
||||
|
||||
/* memcpy(). */
|
||||
#include <string.h>
|
||||
|
||||
/* errno. */
|
||||
#include <errno.h>
|
||||
|
||||
/* Checked size_t computations. */
|
||||
#include "xsize.h"
|
||||
|
||||
#if CHAR_T_ONLY_ASCII
|
||||
/* c_isascii(). */
|
||||
# include "c-ctype.h"
|
||||
#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 = N_DIRECT_ALLOC_DIRECTIVES;
|
||||
d->dir = d->direct_alloc_dir;
|
||||
|
||||
a->count = 0;
|
||||
a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
|
||||
a->arg = a->direct_alloc_arg;
|
||||
|
||||
#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 out_of_memory; \
|
||||
memory = (argument *) (a->arg != a->direct_alloc_arg \
|
||||
? realloc (a->arg, memory_size) \
|
||||
: malloc (memory_size)); \
|
||||
if (memory == NULL) \
|
||||
/* Out of memory. */ \
|
||||
goto out_of_memory; \
|
||||
if (a->arg == a->direct_alloc_arg) \
|
||||
memcpy (memory, a->arg, a->count * sizeof (argument)); \
|
||||
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++;
|
||||
}
|
||||
#if __GLIBC__ >= 2 && !defined __UCLIBC__
|
||||
else if (*cp == 'I')
|
||||
{
|
||||
dp->flags |= FLAG_LOCALIZED;
|
||||
cp++;
|
||||
}
|
||||
#endif
|
||||
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++;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
#if defined __APPLE__ && defined __MACH__
|
||||
/* On MacOS X 10.3, PRIdMAX is defined as "qd".
|
||||
We cannot change it to "lld" because PRIdMAX must also
|
||||
be understood by the system's printf routines. */
|
||||
else if (*cp == 'q')
|
||||
{
|
||||
if (64 / 8 > sizeof (long))
|
||||
{
|
||||
/* int64_t = long long */
|
||||
flags += 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* int64_t = long */
|
||||
flags += 8;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
#endif
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
/* On native Win32, PRIdMAX is defined as "I64d".
|
||||
We cannot change it to "lld" because PRIdMAX must also
|
||||
be understood by the system's printf routines. */
|
||||
else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
|
||||
{
|
||||
if (64 / 8 > sizeof (long))
|
||||
{
|
||||
/* __int64 = long long */
|
||||
flags += 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* __int64 = long */
|
||||
flags += 8;
|
||||
}
|
||||
cp += 3;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read the conversion character. */
|
||||
c = *cp++;
|
||||
switch (c)
|
||||
{
|
||||
case 'd': case 'i':
|
||||
#if 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':
|
||||
#if 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':
|
||||
if (flags >= 16 || (flags & 4))
|
||||
type = TYPE_LONGDOUBLE;
|
||||
else
|
||||
type = TYPE_DOUBLE;
|
||||
break;
|
||||
case 'c':
|
||||
if (flags >= 8)
|
||||
#if HAVE_WINT_T
|
||||
type = TYPE_WIDE_CHAR;
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
else
|
||||
type = TYPE_CHAR;
|
||||
break;
|
||||
#if HAVE_WINT_T
|
||||
case 'C':
|
||||
type = TYPE_WIDE_CHAR;
|
||||
c = 'c';
|
||||
break;
|
||||
#endif
|
||||
case 's':
|
||||
if (flags >= 8)
|
||||
#if HAVE_WCHAR_T
|
||||
type = TYPE_WIDE_STRING;
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
else
|
||||
type = TYPE_STRING;
|
||||
break;
|
||||
#if HAVE_WCHAR_T
|
||||
case 'S':
|
||||
type = TYPE_WIDE_STRING;
|
||||
c = 's';
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
type = TYPE_POINTER;
|
||||
break;
|
||||
case 'n':
|
||||
#if 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;
|
||||
#if ENABLE_UNISTDIO
|
||||
/* The unistdio extensions. */
|
||||
case 'U':
|
||||
if (flags >= 16)
|
||||
type = TYPE_U32_STRING;
|
||||
else if (flags >= 8)
|
||||
type = TYPE_U16_STRING;
|
||||
else
|
||||
type = TYPE_U8_STRING;
|
||||
break;
|
||||
#endif
|
||||
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 out_of_memory;
|
||||
memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
|
||||
? realloc (d->dir, memory_size)
|
||||
: malloc (memory_size));
|
||||
if (memory == NULL)
|
||||
/* Out of memory. */
|
||||
goto out_of_memory;
|
||||
if (d->dir == d->direct_alloc_dir)
|
||||
memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
|
||||
d->dir = memory;
|
||||
}
|
||||
}
|
||||
#if CHAR_T_ONLY_ASCII
|
||||
else if (!c_isascii (c))
|
||||
{
|
||||
/* Non-ASCII character. Not supported. */
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
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 != a->direct_alloc_arg)
|
||||
free (a->arg);
|
||||
if (d->dir != d->direct_alloc_dir)
|
||||
free (d->dir);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
||||
out_of_memory:
|
||||
if (a->arg != a->direct_alloc_arg)
|
||||
free (a->arg);
|
||||
if (d->dir != d->direct_alloc_dir)
|
||||
free (d->dir);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#undef PRINTF_PARSE
|
||||
#undef DIRECTIVES
|
||||
#undef DIRECTIVE
|
||||
#undef CHAR_T_ONLY_ASCII
|
||||
#undef CHAR_T
|
194
lib/printf-parse.h
Normal file
194
lib/printf-parse.h
Normal file
@ -0,0 +1,194 @@
|
||||
/* Parse printf format string.
|
||||
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 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 3, 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
|
||||
|
||||
/* This file can be parametrized with the following macros:
|
||||
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||
STATIC Set to 'static' to declare the function static. */
|
||||
|
||||
#if HAVE_FEATURES_H
|
||||
# include <features.h> /* for __GLIBC__, __UCLIBC__ */
|
||||
#endif
|
||||
|
||||
#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
|
||||
#if __GLIBC__ >= 2 && !defined __UCLIBC__
|
||||
# define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
|
||||
#endif
|
||||
|
||||
/* arg_index value indicating that no argument is consumed. */
|
||||
#define ARG_NONE (~(size_t)0)
|
||||
|
||||
/* xxx_directive: A parsed directive.
|
||||
xxx_directives: A parsed format string. */
|
||||
|
||||
/* Number of directly allocated directives (no malloc() needed). */
|
||||
#define N_DIRECT_ALLOC_DIRECTIVES 7
|
||||
|
||||
/* 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 F e E g G a A 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_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||
}
|
||||
char_directives;
|
||||
|
||||
#if ENABLE_UNISTDIO
|
||||
|
||||
/* A parsed directive. */
|
||||
typedef struct
|
||||
{
|
||||
const uint8_t* dir_start;
|
||||
const uint8_t* dir_end;
|
||||
int flags;
|
||||
const uint8_t* width_start;
|
||||
const uint8_t* width_end;
|
||||
size_t width_arg_index;
|
||||
const uint8_t* precision_start;
|
||||
const uint8_t* precision_end;
|
||||
size_t precision_arg_index;
|
||||
uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
|
||||
size_t arg_index;
|
||||
}
|
||||
u8_directive;
|
||||
|
||||
/* A parsed format string. */
|
||||
typedef struct
|
||||
{
|
||||
size_t count;
|
||||
u8_directive *dir;
|
||||
size_t max_width_length;
|
||||
size_t max_precision_length;
|
||||
u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||
}
|
||||
u8_directives;
|
||||
|
||||
/* A parsed directive. */
|
||||
typedef struct
|
||||
{
|
||||
const uint16_t* dir_start;
|
||||
const uint16_t* dir_end;
|
||||
int flags;
|
||||
const uint16_t* width_start;
|
||||
const uint16_t* width_end;
|
||||
size_t width_arg_index;
|
||||
const uint16_t* precision_start;
|
||||
const uint16_t* precision_end;
|
||||
size_t precision_arg_index;
|
||||
uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
|
||||
size_t arg_index;
|
||||
}
|
||||
u16_directive;
|
||||
|
||||
/* A parsed format string. */
|
||||
typedef struct
|
||||
{
|
||||
size_t count;
|
||||
u16_directive *dir;
|
||||
size_t max_width_length;
|
||||
size_t max_precision_length;
|
||||
u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||
}
|
||||
u16_directives;
|
||||
|
||||
/* A parsed directive. */
|
||||
typedef struct
|
||||
{
|
||||
const uint32_t* dir_start;
|
||||
const uint32_t* dir_end;
|
||||
int flags;
|
||||
const uint32_t* width_start;
|
||||
const uint32_t* width_end;
|
||||
size_t width_arg_index;
|
||||
const uint32_t* precision_start;
|
||||
const uint32_t* precision_end;
|
||||
size_t precision_arg_index;
|
||||
uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
|
||||
size_t arg_index;
|
||||
}
|
||||
u32_directive;
|
||||
|
||||
/* A parsed format string. */
|
||||
typedef struct
|
||||
{
|
||||
size_t count;
|
||||
u32_directive *dir;
|
||||
size_t max_width_length;
|
||||
size_t max_precision_length;
|
||||
u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||
}
|
||||
u32_directives;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* 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. */
|
||||
#if ENABLE_UNISTDIO
|
||||
extern int
|
||||
ulc_printf_parse (const char *format, char_directives *d, arguments *a);
|
||||
extern int
|
||||
u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
|
||||
extern int
|
||||
u16_printf_parse (const uint16_t *format, u16_directives *d,
|
||||
arguments *a);
|
||||
extern int
|
||||
u32_printf_parse (const uint32_t *format, u32_directives *d,
|
||||
arguments *a);
|
||||
#else
|
||||
# ifdef STATIC
|
||||
STATIC
|
||||
# else
|
||||
extern
|
||||
# endif
|
||||
int printf_parse (const char *format, char_directives *d, arguments *a);
|
||||
#endif
|
||||
|
||||
#endif /* _PRINTF_PARSE_H */
|
40
lib/printf.c
Normal file
40
lib/printf.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* Formatted output to a stream.
|
||||
Copyright (C) 2007, 2010-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if 1
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Print formatted output to standard output.
|
||||
Return string length of formatted string. On error, return a negative
|
||||
value. */
|
||||
int
|
||||
printf (const char *format, ...)
|
||||
{
|
||||
int retval;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
retval = vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
64
lib/signbitd.c
Normal file
64
lib/signbitd.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* signbit() macro: Determine the sign bit of a floating-point number.
|
||||
Copyright (C) 2007-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <math.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "isnand-nolibm.h"
|
||||
#include "float+.h"
|
||||
|
||||
#ifdef gl_signbitd_OPTIMIZED_MACRO
|
||||
# undef gl_signbitd
|
||||
#endif
|
||||
|
||||
int
|
||||
gl_signbitd (double arg)
|
||||
{
|
||||
#if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
|
||||
/* The use of a union to extract the bits of the representation of a
|
||||
'long double' is safe in practice, despite of the "aliasing rules" of
|
||||
C99, because the GCC docs say
|
||||
"Even with '-fstrict-aliasing', type-punning is allowed, provided the
|
||||
memory is accessed through the union type."
|
||||
and similarly for other compilers. */
|
||||
# define NWORDS \
|
||||
((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
union { double value; unsigned int word[NWORDS]; } m;
|
||||
m.value = arg;
|
||||
return (m.word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;
|
||||
#elif HAVE_COPYSIGN_IN_LIBC
|
||||
return copysign (1.0, arg) < 0;
|
||||
#else
|
||||
/* This does not do the right thing for NaN, but this is irrelevant for
|
||||
most use cases. */
|
||||
if (isnand (arg))
|
||||
return 0;
|
||||
if (arg < 0.0)
|
||||
return 1;
|
||||
else if (arg == 0.0)
|
||||
{
|
||||
/* Distinguish 0.0 and -0.0. */
|
||||
static double plus_zero = 0.0;
|
||||
double arg_mem = arg;
|
||||
return (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
64
lib/signbitf.c
Normal file
64
lib/signbitf.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* signbit() macro: Determine the sign bit of a floating-point number.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <math.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "isnanf-nolibm.h"
|
||||
#include "float+.h"
|
||||
|
||||
#ifdef gl_signbitf_OPTIMIZED_MACRO
|
||||
# undef gl_signbitf
|
||||
#endif
|
||||
|
||||
int
|
||||
gl_signbitf (float arg)
|
||||
{
|
||||
#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
|
||||
/* The use of a union to extract the bits of the representation of a
|
||||
'long double' is safe in practice, despite of the "aliasing rules" of
|
||||
C99, because the GCC docs say
|
||||
"Even with '-fstrict-aliasing', type-punning is allowed, provided the
|
||||
memory is accessed through the union type."
|
||||
and similarly for other compilers. */
|
||||
# define NWORDS \
|
||||
((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
union { float value; unsigned int word[NWORDS]; } m;
|
||||
m.value = arg;
|
||||
return (m.word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;
|
||||
#elif HAVE_COPYSIGNF_IN_LIBC
|
||||
return copysignf (1.0f, arg) < 0;
|
||||
#else
|
||||
/* This does not do the right thing for NaN, but this is irrelevant for
|
||||
most use cases. */
|
||||
if (isnanf (arg))
|
||||
return 0;
|
||||
if (arg < 0.0f)
|
||||
return 1;
|
||||
else if (arg == 0.0f)
|
||||
{
|
||||
/* Distinguish 0.0f and -0.0f. */
|
||||
static float plus_zero = 0.0f;
|
||||
float arg_mem = arg;
|
||||
return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
64
lib/signbitl.c
Normal file
64
lib/signbitl.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* signbit() macro: Determine the sign bit of a floating-point number.
|
||||
Copyright (C) 2007, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <math.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "isnanl-nolibm.h"
|
||||
#include "float+.h"
|
||||
|
||||
#ifdef gl_signbitl_OPTIMIZED_MACRO
|
||||
# undef gl_signbitl
|
||||
#endif
|
||||
|
||||
int
|
||||
gl_signbitl (long double arg)
|
||||
{
|
||||
#if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
|
||||
/* The use of a union to extract the bits of the representation of a
|
||||
'long double' is safe in practice, despite of the "aliasing rules" of
|
||||
C99, because the GCC docs say
|
||||
"Even with '-fstrict-aliasing', type-punning is allowed, provided the
|
||||
memory is accessed through the union type."
|
||||
and similarly for other compilers. */
|
||||
# define NWORDS \
|
||||
((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
union { long double value; unsigned int word[NWORDS]; } m;
|
||||
m.value = arg;
|
||||
return (m.word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;
|
||||
#elif HAVE_COPYSIGNL_IN_LIBC
|
||||
return copysignl (1.0L, arg) < 0;
|
||||
#else
|
||||
/* This does not do the right thing for NaN, but this is irrelevant for
|
||||
most use cases. */
|
||||
if (isnanl (arg))
|
||||
return 0;
|
||||
if (arg < 0.0L)
|
||||
return 1;
|
||||
else if (arg == 0.0L)
|
||||
{
|
||||
/* Distinguish 0.0L and -0.0L. */
|
||||
static long double plus_zero = 0.0L;
|
||||
long double arg_mem = arg;
|
||||
return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
31
lib/size_max.h
Normal file
31
lib/size_max.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* size_max.h -- declare SIZE_MAX through system headers
|
||||
Copyright (C) 2005-2006, 2009-2011 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 3, 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 <limits.h>
|
||||
/* Get SIZE_MAX declaration on systems like glibc 2. */
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
/* On systems where these include files don't define it, SIZE_MAX is defined
|
||||
in config.h. */
|
||||
|
||||
#endif /* GNULIB_SIZE_MAX_H */
|
72
lib/snprintf.c
Normal file
72
lib/snprintf.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* Formatted output to strings.
|
||||
Copyright (C) 2004, 2006-2011 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 3, 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 <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vasnprintf.h"
|
||||
|
||||
/* 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;
|
||||
}
|
113
lib/stat.c
Normal file
113
lib/stat.c
Normal file
@ -0,0 +1,113 @@
|
||||
/* Work around platform bugs in stat.
|
||||
Copyright (C) 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Eric Blake */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Get the original definition of stat. It might be defined as a macro. */
|
||||
#define __need_system_sys_stat_h
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#undef __need_system_sys_stat_h
|
||||
|
||||
static inline int
|
||||
orig_stat (const char *filename, struct stat *buf)
|
||||
{
|
||||
return stat (filename, buf);
|
||||
}
|
||||
|
||||
/* Specification. */
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "dosname.h"
|
||||
#include "verify.h"
|
||||
|
||||
/* Store information about NAME into ST. Work around bugs with
|
||||
trailing slashes. Mingw has other bugs (such as st_ino always
|
||||
being 0 on success) which this wrapper does not work around. But
|
||||
at least this implementation provides the ability to emulate fchdir
|
||||
correctly. */
|
||||
|
||||
int
|
||||
rpl_stat (char const *name, struct stat *st)
|
||||
{
|
||||
int result = orig_stat (name, st);
|
||||
#if REPLACE_FUNC_STAT_FILE
|
||||
/* Solaris 9 mistakenly succeeds when given a non-directory with a
|
||||
trailing slash. */
|
||||
if (result == 0 && !S_ISDIR (st->st_mode))
|
||||
{
|
||||
size_t len = strlen (name);
|
||||
if (ISSLASH (name[len - 1]))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif /* REPLACE_FUNC_STAT_FILE */
|
||||
#if REPLACE_FUNC_STAT_DIR
|
||||
/* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
|
||||
have a constant PATH_MAX. */
|
||||
# ifndef PATH_MAX
|
||||
# error "Please port this replacement to your platform"
|
||||
# endif
|
||||
|
||||
if (result == -1 && errno == ENOENT)
|
||||
{
|
||||
/* Due to mingw's oddities, there are some directories (like
|
||||
c:\) where stat() only succeeds with a trailing slash, and
|
||||
other directories (like c:\windows) where stat() only
|
||||
succeeds without a trailing slash. But we want the two to be
|
||||
synonymous, since chdir() manages either style. Likewise, Mingw also
|
||||
reports ENOENT for names longer than PATH_MAX, when we want
|
||||
ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
|
||||
Fortunately, mingw PATH_MAX is small enough for stack
|
||||
allocation. */
|
||||
char fixed_name[PATH_MAX + 1] = {0};
|
||||
size_t len = strlen (name);
|
||||
bool check_dir = false;
|
||||
verify (PATH_MAX <= 4096);
|
||||
if (PATH_MAX <= len)
|
||||
errno = ENAMETOOLONG;
|
||||
else if (len)
|
||||
{
|
||||
strcpy (fixed_name, name);
|
||||
if (ISSLASH (fixed_name[len - 1]))
|
||||
{
|
||||
check_dir = true;
|
||||
while (len && ISSLASH (fixed_name[len - 1]))
|
||||
fixed_name[--len] = '\0';
|
||||
if (!len)
|
||||
fixed_name[0] = '/';
|
||||
}
|
||||
else
|
||||
fixed_name[len++] = '/';
|
||||
result = orig_stat (fixed_name, st);
|
||||
if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
|
||||
{
|
||||
result = -1;
|
||||
errno = ENOTDIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* REPLACE_FUNC_STAT_DIR */
|
||||
return result;
|
||||
}
|
36
lib/stdarg.in.h
Normal file
36
lib/stdarg.in.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* Substitute for and wrapper around <stdarg.h>.
|
||||
Copyright (C) 2008-2011 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 3, 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 _@GUARD_PREFIX@_STDARG_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_STDARG_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_STDARG_H
|
||||
#define _@GUARD_PREFIX@_STDARG_H
|
||||
|
||||
#ifndef va_copy
|
||||
# define va_copy(a,b) ((a) = (b))
|
||||
#endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_STDARG_H */
|
||||
#endif /* _@GUARD_PREFIX@_STDARG_H */
|
122
lib/stdbool.in.h
Normal file
122
lib/stdbool.in.h
Normal file
@ -0,0 +1,122 @@
|
||||
/* Copyright (C) 2001-2003, 2006-2011 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
|
||||
|
||||
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 3, 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_STDBOOL_H
|
||||
#define _GL_STDBOOL_H
|
||||
|
||||
/* ISO C 99 <stdbool.h> for platforms that lack it. */
|
||||
|
||||
/* Usage suggestions:
|
||||
|
||||
Programs that use <stdbool.h> should be aware of some limitations
|
||||
and standards compliance issues.
|
||||
|
||||
Standards compliance:
|
||||
|
||||
- <stdbool.h> must be #included before 'bool', 'false', 'true'
|
||||
can be used.
|
||||
|
||||
- You cannot assume that sizeof (bool) == 1.
|
||||
|
||||
- Programs should not undefine the macros bool, true, and false,
|
||||
as C99 lists that as an "obsolescent feature".
|
||||
|
||||
Limitations of this substitute, when used in a C89 environment:
|
||||
|
||||
- <stdbool.h> must be #included before the '_Bool' type can be used.
|
||||
|
||||
- You cannot assume that _Bool is a typedef; it might be a macro.
|
||||
|
||||
- Bit-fields of type 'bool' are not supported. Portable code
|
||||
should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
|
||||
|
||||
- In C99, casts and automatic conversions to '_Bool' or 'bool' are
|
||||
performed in such a way that every nonzero value gets converted
|
||||
to 'true', and zero gets converted to 'false'. This doesn't work
|
||||
with this substitute. With this substitute, only the values 0 and 1
|
||||
give the expected result when converted to _Bool' or 'bool'.
|
||||
|
||||
- C99 allows the use of (_Bool)0.0 in constant expressions, but
|
||||
this substitute cannot always provide this property.
|
||||
|
||||
Also, it is suggested that programs use 'bool' rather than '_Bool';
|
||||
this isn't required, but 'bool' is more common. */
|
||||
|
||||
|
||||
/* 7.16. Boolean type and values */
|
||||
|
||||
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
|
||||
definitions below, but temporarily we have to #undef them. */
|
||||
#if defined __BEOS__ && !defined __HAIKU__
|
||||
# include <OS.h> /* defines bool but not _Bool */
|
||||
# undef false
|
||||
# undef true
|
||||
#endif
|
||||
|
||||
/* 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)). So we add a negative value to the
|
||||
enum; this ensures that '_Bool' promotes to 'int'. */
|
||||
#if defined __cplusplus || (defined __BEOS__ && !defined __HAIKU__)
|
||||
/* 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
|
||||
# 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 <stdbool.h> 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".
|
||||
Even the existence of an enum type, without a typedef,
|
||||
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
|
||||
The only benefit of the enum, debuggability, is not important
|
||||
with these compilers. So use 'signed char' and no enum. */
|
||||
# define _Bool signed char
|
||||
# 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. */
|
||||
#define false 0
|
||||
#define true 1
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#endif /* _GL_STDBOOL_H */
|
87
lib/stddef.in.h
Normal file
87
lib/stddef.in.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
|
||||
|
||||
Copyright (C) 2009-2011 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 3, 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. */
|
||||
|
||||
/*
|
||||
* POSIX 2008 <stddef.h> for platforms that have issues.
|
||||
* <http://www.opengroup.org/susv3xbd/stddef.h.html>
|
||||
*/
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_wchar_t || defined __need_size_t \
|
||||
|| defined __need_ptrdiff_t || defined __need_NULL \
|
||||
|| defined __need_wint_t
|
||||
/* Special invocation convention inside gcc header files. In
|
||||
particular, gcc provides a version of <stddef.h> that blindly
|
||||
redefines NULL even when __need_wint_t was defined, even though
|
||||
wint_t is not normally provided by <stddef.h>. Hence, we must
|
||||
remember if special invocation has ever been used to obtain wint_t,
|
||||
in which case we need to clean up NULL yet again. */
|
||||
|
||||
# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
|
||||
# ifdef __need_wint_t
|
||||
# undef _@GUARD_PREFIX@_STDDEF_H
|
||||
# define _GL_STDDEF_WINT_T
|
||||
# endif
|
||||
# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
# ifndef _@GUARD_PREFIX@_STDDEF_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
|
||||
# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
|
||||
|
||||
# ifndef _@GUARD_PREFIX@_STDDEF_H
|
||||
# define _@GUARD_PREFIX@_STDDEF_H
|
||||
|
||||
/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
|
||||
#if @REPLACE_NULL@
|
||||
# undef NULL
|
||||
# ifdef __cplusplus
|
||||
/* ISO C++ says that the macro NULL must expand to an integer constant
|
||||
expression, hence '((void *) 0)' is not allowed in C++. */
|
||||
# if __GNUG__ >= 3
|
||||
/* GNU C++ has a __null macro that behaves like an integer ('int' or
|
||||
'long') but has the same size as a pointer. Use that, to avoid
|
||||
warnings. */
|
||||
# define NULL __null
|
||||
# else
|
||||
# define NULL 0L
|
||||
# endif
|
||||
# else
|
||||
# define NULL ((void *) 0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some platforms lack wchar_t. */
|
||||
#if !@HAVE_WCHAR_T@
|
||||
# define wchar_t int
|
||||
#endif
|
||||
|
||||
# endif /* _@GUARD_PREFIX@_STDDEF_H */
|
||||
# endif /* _@GUARD_PREFIX@_STDDEF_H */
|
||||
#endif /* __need_XXX */
|
606
lib/stdint.in.h
Normal file
606
lib/stdint.in.h
Normal file
@ -0,0 +1,606 @@
|
||||
/* Copyright (C) 2001-2002, 2004-2011 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 3, 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. */
|
||||
|
||||
/*
|
||||
* ISO C 99 <stdint.h> for platforms that lack it.
|
||||
* <http://www.opengroup.org/susv3xbd/stdint.h.html>
|
||||
*/
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_STDINT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* When including a system file that in turn includes <inttypes.h>,
|
||||
use the system <inttypes.h>, not our substitute. This avoids
|
||||
problems with (for example) VMS, whose <sys/bitypes.h> includes
|
||||
<inttypes.h>. */
|
||||
#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* Get those types that are already defined in other system include
|
||||
files, so that we can "#define int8_t signed char" below without
|
||||
worrying about a later system include file containing a "typedef
|
||||
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 <stdint.h> 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 <stdint.h>.
|
||||
Include it before <inttypes.h>, since any "#include <stdint.h>"
|
||||
in <inttypes.h> would reinclude us, skipping our contents because
|
||||
_@GUARD_PREFIX@_STDINT_H is defined.
|
||||
The include_next requires a split double-inclusion guard. */
|
||||
# @INCLUDE_NEXT@ @NEXT_STDINT_H@
|
||||
#endif
|
||||
|
||||
#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
|
||||
#define _@GUARD_PREFIX@_STDINT_H
|
||||
|
||||
/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
|
||||
IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
|
||||
AIX 5.2 <sys/types.h> isn't needed and causes troubles.
|
||||
MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
|
||||
relies on the system <stdint.h> definitions, so include
|
||||
<sys/types.h> after @NEXT_STDINT_H@. */
|
||||
#if @HAVE_SYS_TYPES_H@ && ! defined _AIX
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
|
||||
#include <limits.h>
|
||||
|
||||
#if @HAVE_INTTYPES_H@
|
||||
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
|
||||
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
|
||||
<inttypes.h> also defines intptr_t and uintptr_t. */
|
||||
# include <inttypes.h>
|
||||
#elif @HAVE_SYS_INTTYPES_H@
|
||||
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
|
||||
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
|
||||
# include <sys/inttypes.h>
|
||||
#endif
|
||||
|
||||
#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
|
||||
/* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
|
||||
int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
|
||||
included by <sys/types.h>. */
|
||||
# include <sys/bitypes.h>
|
||||
#endif
|
||||
|
||||
#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* Minimum and maximum values for an 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) \
|
||||
: /* The expression for the unsigned case. The subtraction of (signed) \
|
||||
is a nop in the unsigned case and avoids "signed integer overflow" \
|
||||
warnings in the signed case. */ \
|
||||
((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
|
||||
|
||||
#if !GNULIB_defined_stdint_types
|
||||
|
||||
/* 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
|
||||
typedef signed char gl_int8_t;
|
||||
typedef unsigned char gl_uint8_t;
|
||||
#define int8_t gl_int8_t
|
||||
#define uint8_t gl_uint8_t
|
||||
|
||||
#undef int16_t
|
||||
#undef uint16_t
|
||||
typedef short int gl_int16_t;
|
||||
typedef unsigned short int gl_uint16_t;
|
||||
#define int16_t gl_int16_t
|
||||
#define uint16_t gl_uint16_t
|
||||
|
||||
#undef int32_t
|
||||
#undef uint32_t
|
||||
typedef int gl_int32_t;
|
||||
typedef unsigned int gl_uint32_t;
|
||||
#define int32_t gl_int32_t
|
||||
#define uint32_t gl_uint32_t
|
||||
|
||||
/* If the system defines INT64_MAX, assume int64_t works. That way,
|
||||
if the underlying platform defines int64_t to be a 64-bit long long
|
||||
int, the code below won't mistakenly define it to be a 64-bit long
|
||||
int, which would mess up C++ name mangling. We must use #ifdef
|
||||
rather than #if, to avoid an error with HP-UX 10.20 cc. */
|
||||
|
||||
#ifdef INT64_MAX
|
||||
# define GL_INT64_T
|
||||
#else
|
||||
/* Do not undefine int64_t if gnulib is not being used with 64-bit
|
||||
types, since otherwise it breaks platforms like Tandem/NSK. */
|
||||
# if LONG_MAX >> 31 >> 31 == 1
|
||||
# undef int64_t
|
||||
typedef long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef int64_t
|
||||
typedef __int64 gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# elif @HAVE_LONG_LONG_INT@
|
||||
# undef int64_t
|
||||
typedef long long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef UINT64_MAX
|
||||
# define GL_UINT64_T
|
||||
#else
|
||||
# if ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
# undef uint64_t
|
||||
typedef unsigned long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef uint64_t
|
||||
typedef unsigned __int64 gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# elif @HAVE_UNSIGNED_LONG_LONG_INT@
|
||||
# undef uint64_t
|
||||
typedef unsigned long long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Avoid collision with Solaris 2.5.1 <pthread.h> 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 GL_INT64_T
|
||||
# define int_least64_t int64_t
|
||||
#endif
|
||||
#ifdef GL_UINT64_T
|
||||
# define uint_least64_t uint64_t
|
||||
#endif
|
||||
|
||||
/* 7.18.1.3. Fastest minimum-width integer types */
|
||||
|
||||
/* Note: Other <stdint.h> 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
|
||||
typedef long int gl_int_fast8_t;
|
||||
typedef unsigned long int gl_uint_fast8_t;
|
||||
typedef long int gl_int_fast16_t;
|
||||
typedef unsigned long int gl_uint_fast16_t;
|
||||
typedef long int gl_int_fast32_t;
|
||||
typedef unsigned long int gl_uint_fast32_t;
|
||||
#define int_fast8_t gl_int_fast8_t
|
||||
#define uint_fast8_t gl_uint_fast8_t
|
||||
#define int_fast16_t gl_int_fast16_t
|
||||
#define uint_fast16_t gl_uint_fast16_t
|
||||
#define int_fast32_t gl_int_fast32_t
|
||||
#define uint_fast32_t gl_uint_fast32_t
|
||||
#ifdef GL_INT64_T
|
||||
# define int_fast64_t int64_t
|
||||
#endif
|
||||
#ifdef GL_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
|
||||
typedef long int gl_intptr_t;
|
||||
typedef unsigned long int gl_uintptr_t;
|
||||
#define intptr_t gl_intptr_t
|
||||
#define uintptr_t gl_uintptr_t
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* If the system defines INTMAX_MAX, assume that intmax_t works, and
|
||||
similarly for UINTMAX_MAX and uintmax_t. This avoids problems with
|
||||
assuming one type where another is used by the system. */
|
||||
|
||||
#ifndef INTMAX_MAX
|
||||
# undef INTMAX_C
|
||||
# undef intmax_t
|
||||
# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
|
||||
typedef long long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# elif defined GL_INT64_T
|
||||
# define intmax_t int64_t
|
||||
# else
|
||||
typedef long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_MAX
|
||||
# undef UINTMAX_C
|
||||
# undef uintmax_t
|
||||
# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
|
||||
typedef unsigned long long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# elif defined GL_UINT64_T
|
||||
# define uintmax_t uint64_t
|
||||
# else
|
||||
typedef unsigned long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Verify that intmax_t and uintmax_t have the same size. Too much code
|
||||
breaks if this is not the case. If this check fails, the reason is likely
|
||||
to be found in the autoconf macros. */
|
||||
typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
||||
? 1 : -1];
|
||||
|
||||
#define GNULIB_defined_stdint_types 1
|
||||
#endif /* !GNULIB_defined_stdint_types */
|
||||
|
||||
/* 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
|
||||
|
||||
#if defined GL_INT64_T && ! defined INT64_MAX
|
||||
/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
|
||||
evaluates the latter incorrectly in preprocessor expressions. */
|
||||
# define INT64_MIN (- INTMAX_C (1) << 63)
|
||||
# define INT64_MAX INTMAX_C (9223372036854775807)
|
||||
#endif
|
||||
|
||||
#if defined GL_UINT64_T && ! defined UINT64_MAX
|
||||
# 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 GL_INT64_T
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
#endif
|
||||
|
||||
#undef UINT_LEAST64_MAX
|
||||
#ifdef GL_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 GL_INT64_T
|
||||
# define INT_FAST64_MIN INT64_MIN
|
||||
# define INT_FAST64_MAX INT64_MAX
|
||||
#endif
|
||||
|
||||
#undef UINT_FAST64_MAX
|
||||
#ifdef GL_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 */
|
||||
|
||||
#ifndef INTMAX_MAX
|
||||
# undef INTMAX_MIN
|
||||
# ifdef INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# else
|
||||
# define INTMAX_MIN INT32_MIN
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_MAX
|
||||
# ifdef UINT64_MAX
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# else
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* 7.18.3. Limits of other integer types */
|
||||
|
||||
/* ptrdiff_t limits */
|
||||
#undef PTRDIFF_MIN
|
||||
#undef PTRDIFF_MAX
|
||||
#if @APPLE_UNIVERSAL_BUILD@
|
||||
# ifdef _LP64
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
|
||||
# else
|
||||
# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
|
||||
# endif
|
||||
#else
|
||||
# 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@)
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
#if @APPLE_UNIVERSAL_BUILD@
|
||||
# ifdef _LP64
|
||||
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
|
||||
# else
|
||||
# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
|
||||
# endif
|
||||
#else
|
||||
# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
|
||||
#endif
|
||||
|
||||
/* wchar_t limits */
|
||||
/* Get WCHAR_MIN, WCHAR_MAX.
|
||||
This include is not on the top, above, because on OSF/1 4.0 we have a
|
||||
sequence of nested includes
|
||||
<wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
|
||||
<stdint.h> and assumes its types are already defined. */
|
||||
#if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
|
||||
/* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
||||
included before <wchar.h>. */
|
||||
# include <stddef.h>
|
||||
# include <stdio.h>
|
||||
# include <time.h>
|
||||
# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
# include <wchar.h>
|
||||
# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
#endif
|
||||
#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 */
|
||||
|
||||
#ifndef INTMAX_C
|
||||
# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
|
||||
# define INTMAX_C(x) x##LL
|
||||
# elif defined GL_INT64_T
|
||||
# define INTMAX_C(x) INT64_C(x)
|
||||
# else
|
||||
# define INTMAX_C(x) x##L
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_C
|
||||
# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
|
||||
# define UINTMAX_C(x) x##ULL
|
||||
# elif defined GL_UINT64_T
|
||||
# define UINTMAX_C(x) UINT64_C(x)
|
||||
# else
|
||||
# define UINTMAX_C(x) x##UL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_STDINT_H */
|
||||
#endif /* !defined _@GUARD_PREFIX@_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
|
110
lib/stdio-impl.h
Normal file
110
lib/stdio-impl.h
Normal file
@ -0,0 +1,110 @@
|
||||
/* Implementation details of FILE streams.
|
||||
Copyright (C) 2007-2008, 2010-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Many stdio implementations have the same logic and therefore can share
|
||||
the same implementation of stdio extension API, except that some fields
|
||||
have different naming conventions, or their access requires some casts. */
|
||||
|
||||
|
||||
/* BSD stdio derived implementations. */
|
||||
|
||||
#if defined __NetBSD__ /* NetBSD */
|
||||
/* Get __NetBSD_Version__. */
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
|
||||
|
||||
# if defined __DragonFly__ /* DragonFly */
|
||||
/* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
|
||||
# define fp_ ((struct { struct __FILE_public pub; \
|
||||
struct { unsigned char *_base; int _size; } _bf; \
|
||||
void *cookie; \
|
||||
void *_close; \
|
||||
void *_read; \
|
||||
void *_seek; \
|
||||
void *_write; \
|
||||
struct { unsigned char *_base; int _size; } _ub; \
|
||||
int _ur; \
|
||||
unsigned char _ubuf[3]; \
|
||||
unsigned char _nbuf[1]; \
|
||||
struct { unsigned char *_base; int _size; } _lb; \
|
||||
int _blksize; \
|
||||
fpos_t _offset; \
|
||||
/* More fields, not relevant here. */ \
|
||||
} *) fp)
|
||||
/* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
|
||||
# define _p pub._p
|
||||
# define _flags pub._flags
|
||||
# define _r pub._r
|
||||
# define _w pub._w
|
||||
# else
|
||||
# define fp_ fp
|
||||
# endif
|
||||
|
||||
# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */
|
||||
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
|
||||
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
|
||||
struct __sfileext
|
||||
{
|
||||
struct __sbuf _ub; /* ungetc buffer */
|
||||
/* More fields, not relevant here. */
|
||||
};
|
||||
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
|
||||
# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, MacOS X, Cygwin */
|
||||
# define fp_ub fp_->_ub
|
||||
# endif
|
||||
|
||||
# define HASUB(fp) (fp_ub._base != NULL)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* SystemV derived implementations. */
|
||||
|
||||
#ifdef __TANDEM /* NonStop Kernel */
|
||||
# ifndef _IOERR
|
||||
/* These values were determined by the program 'stdioext-flags' at
|
||||
<http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
|
||||
# define _IOERR 0x40
|
||||
# define _IOREAD 0x80
|
||||
# define _IOWRT 0x4
|
||||
# define _IORW 0x100
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined _IOERR
|
||||
|
||||
# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
|
||||
# define fp_ ((struct { unsigned char *_ptr; \
|
||||
unsigned char *_base; \
|
||||
unsigned char *_end; \
|
||||
long _cnt; \
|
||||
int _file; \
|
||||
unsigned int _flag; \
|
||||
} *) fp)
|
||||
# else
|
||||
# define fp_ fp
|
||||
# endif
|
||||
|
||||
# if defined _SCO_DS /* OpenServer */
|
||||
# define _cnt __cnt
|
||||
# define _ptr __ptr
|
||||
# define _base __base
|
||||
# define _flag __flag
|
||||
# endif
|
||||
|
||||
#endif
|
1312
lib/stdio.in.h
Normal file
1312
lib/stdio.in.h
Normal file
File diff suppressed because it is too large
Load Diff
762
lib/stdlib.in.h
Normal file
762
lib/stdlib.in.h
Normal file
@ -0,0 +1,762 @@
|
||||
/* A GNU-like <stdlib.h>.
|
||||
|
||||
Copyright (C) 1995, 2001-2004, 2006-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_malloc_and_calloc
|
||||
/* Special invocation convention inside glibc header files. */
|
||||
|
||||
#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_STDLIB_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_STDLIB_H
|
||||
#define _@GUARD_PREFIX@_STDLIB_H
|
||||
|
||||
/* NetBSD 5.0 mis-defines NULL. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* MirBSD 10 defines WEXITSTATUS in <sys/wait.h>, not in <stdlib.h>. */
|
||||
#if @GNULIB_SYSTEM_POSIX@ && !defined WEXITSTATUS
|
||||
# include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
/* Solaris declares getloadavg() in <sys/loadavg.h>. */
|
||||
#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
|
||||
# include <sys/loadavg.h>
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
|
||||
/* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
|
||||
from <stdlib.h> if _REENTRANT is defined. Include it whenever we need
|
||||
'struct random_data'. */
|
||||
# if @HAVE_RANDOM_H@
|
||||
# include <random.h>
|
||||
# endif
|
||||
|
||||
# if !@HAVE_STRUCT_RANDOM_DATA@ || !@HAVE_RANDOM_R@
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
|
||||
# if !@HAVE_STRUCT_RANDOM_DATA@
|
||||
/* Define 'struct random_data'.
|
||||
But allow multiple gnulib generated <stdlib.h> replacements to coexist. */
|
||||
# if !GNULIB_defined_struct_random_data
|
||||
struct random_data
|
||||
{
|
||||
int32_t *fptr; /* Front pointer. */
|
||||
int32_t *rptr; /* Rear pointer. */
|
||||
int32_t *state; /* Array of state values. */
|
||||
int rand_type; /* Type of random number generator. */
|
||||
int rand_deg; /* Degree of random number generator. */
|
||||
int rand_sep; /* Distance between front and rear. */
|
||||
int32_t *end_ptr; /* Pointer behind state table. */
|
||||
};
|
||||
# define GNULIB_defined_struct_random_data 1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
|
||||
/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
|
||||
/* On MacOS X 10.5, only <unistd.h> declares mkstemps. */
|
||||
/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
|
||||
/* But avoid namespace pollution on glibc systems and native Windows. */
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* The definition of _Noreturn is copied here. */
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
|
||||
#ifndef EXIT_SUCCESS
|
||||
# define EXIT_SUCCESS 0
|
||||
#endif
|
||||
/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
|
||||
with proper operation of xargs. */
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#elif EXIT_FAILURE != 1
|
||||
# undef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB__EXIT@
|
||||
/* Terminate the current process with the given return code, without running
|
||||
the 'atexit' handlers. */
|
||||
# if !@HAVE__EXIT@
|
||||
_GL_FUNCDECL_SYS (_Exit, _Noreturn void, (int status));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (_Exit, void, (int status));
|
||||
_GL_CXXALIASWARN (_Exit);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef _Exit
|
||||
# if HAVE_RAW_DECL__EXIT
|
||||
_GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
|
||||
"use gnulib module _Exit for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_ATOLL@
|
||||
/* Parse a signed decimal integer.
|
||||
Returns the value of the integer. Errors are not detected. */
|
||||
# if !@HAVE_ATOLL@
|
||||
_GL_FUNCDECL_SYS (atoll, long long, (const char *string) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (atoll, long long, (const char *string));
|
||||
_GL_CXXALIASWARN (atoll);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef atoll
|
||||
# if HAVE_RAW_DECL_ATOLL
|
||||
_GL_WARN_ON_USE (atoll, "atoll is unportable - "
|
||||
"use gnulib module atoll for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_CALLOC_POSIX@
|
||||
# if @REPLACE_CALLOC@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef calloc
|
||||
# define calloc rpl_calloc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size));
|
||||
_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (calloc);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef calloc
|
||||
/* Assume calloc is always declared. */
|
||||
_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
|
||||
"use gnulib module calloc-posix for portability");
|
||||
#endif
|
||||
|
||||
#if @GNULIB_CANONICALIZE_FILE_NAME@
|
||||
# if @REPLACE_CANONICALIZE_FILE_NAME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define canonicalize_file_name rpl_canonicalize_file_name
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
|
||||
# else
|
||||
# if !@HAVE_CANONICALIZE_FILE_NAME@
|
||||
_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (canonicalize_file_name);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef canonicalize_file_name
|
||||
# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
|
||||
_GL_WARN_ON_USE (canonicalize_file_name,
|
||||
"canonicalize_file_name is unportable - "
|
||||
"use gnulib module canonicalize-lgpl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_GETLOADAVG@
|
||||
/* Store max(NELEM,3) load average numbers in LOADAVG[].
|
||||
The three numbers are the load average of the last 1 minute, the last 5
|
||||
minutes, and the last 15 minutes, respectively.
|
||||
LOADAVG is an array of NELEM numbers. */
|
||||
# if !@HAVE_DECL_GETLOADAVG@
|
||||
_GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem));
|
||||
_GL_CXXALIASWARN (getloadavg);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef getloadavg
|
||||
# if HAVE_RAW_DECL_GETLOADAVG
|
||||
_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
|
||||
"use gnulib module getloadavg for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_GETSUBOPT@
|
||||
/* Assuming *OPTIONP is a comma separated list of elements of the form
|
||||
"token" or "token=value", getsubopt parses the first of these elements.
|
||||
If the first element refers to a "token" that is member of the given
|
||||
NULL-terminated array of tokens:
|
||||
- It replaces the comma with a NUL byte, updates *OPTIONP to point past
|
||||
the first option and the comma, sets *VALUEP to the value of the
|
||||
element (or NULL if it doesn't contain an "=" sign),
|
||||
- It returns the index of the "token" in the given array of tokens.
|
||||
Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
|
||||
For more details see the POSIX:2001 specification.
|
||||
http://www.opengroup.org/susv3xsh/getsubopt.html */
|
||||
# if !@HAVE_GETSUBOPT@
|
||||
_GL_FUNCDECL_SYS (getsubopt, int,
|
||||
(char **optionp, char *const *tokens, char **valuep)
|
||||
_GL_ARG_NONNULL ((1, 2, 3)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (getsubopt, int,
|
||||
(char **optionp, char *const *tokens, char **valuep));
|
||||
_GL_CXXALIASWARN (getsubopt);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef getsubopt
|
||||
# if HAVE_RAW_DECL_GETSUBOPT
|
||||
_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - "
|
||||
"use gnulib module getsubopt for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_GRANTPT@
|
||||
/* Change the ownership and access permission of the slave side of the
|
||||
pseudo-terminal whose master side is specified by FD. */
|
||||
# if !@HAVE_GRANTPT@
|
||||
_GL_FUNCDECL_SYS (grantpt, int, (int fd));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (grantpt, int, (int fd));
|
||||
_GL_CXXALIASWARN (grantpt);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef grantpt
|
||||
# if HAVE_RAW_DECL_GRANTPT
|
||||
_GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
|
||||
"use gnulib module grantpt for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
|
||||
rely on GNU or POSIX semantics for malloc and realloc (for example,
|
||||
by never specifying a zero size), so it does not need malloc or
|
||||
realloc to be redefined. */
|
||||
#if @GNULIB_MALLOC_POSIX@
|
||||
# if @REPLACE_MALLOC@
|
||||
# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
|
||||
|| _GL_USE_STDLIB_ALLOC)
|
||||
# undef malloc
|
||||
# define malloc rpl_malloc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (malloc, void *, (size_t size));
|
||||
_GL_CXXALIAS_RPL (malloc, void *, (size_t size));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (malloc);
|
||||
#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
|
||||
# undef malloc
|
||||
/* Assume malloc is always declared. */
|
||||
_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
|
||||
"use gnulib module malloc-posix for portability");
|
||||
#endif
|
||||
|
||||
/* Convert a multibyte character to a wide character. */
|
||||
#if @GNULIB_MBTOWC@
|
||||
# if @REPLACE_MBTOWC@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbtowc
|
||||
# define mbtowc rpl_mbtowc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
|
||||
_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbtowc);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_MKDTEMP@
|
||||
/* Create a unique temporary directory from TEMPLATE.
|
||||
The last six characters of TEMPLATE must be "XXXXXX";
|
||||
they are replaced with a string that makes the directory name unique.
|
||||
Returns TEMPLATE, or a null pointer if it cannot get a unique name.
|
||||
The directory is created mode 700. */
|
||||
# if !@HAVE_MKDTEMP@
|
||||
_GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/));
|
||||
_GL_CXXALIASWARN (mkdtemp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkdtemp
|
||||
# if HAVE_RAW_DECL_MKDTEMP
|
||||
_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - "
|
||||
"use gnulib module mkdtemp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_MKOSTEMP@
|
||||
/* Create a unique temporary file from TEMPLATE.
|
||||
The last six characters of TEMPLATE must be "XXXXXX";
|
||||
they are replaced with a string that makes the file name unique.
|
||||
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
|
||||
and O_TEXT, O_BINARY (defined in "binary-io.h").
|
||||
The file is then created, with the specified flags, ensuring it didn't exist
|
||||
before.
|
||||
The file is created read-write (mask at least 0600 & ~umask), but it may be
|
||||
world-readable and world-writable (mask 0666 & ~umask), depending on the
|
||||
implementation.
|
||||
Returns the open file descriptor if successful, otherwise -1 and errno
|
||||
set. */
|
||||
# if !@HAVE_MKOSTEMP@
|
||||
_GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/));
|
||||
_GL_CXXALIASWARN (mkostemp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkostemp
|
||||
# if HAVE_RAW_DECL_MKOSTEMP
|
||||
_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - "
|
||||
"use gnulib module mkostemp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_MKOSTEMPS@
|
||||
/* Create a unique temporary file from TEMPLATE.
|
||||
The last six characters of TEMPLATE before a suffix of length
|
||||
SUFFIXLEN must be "XXXXXX";
|
||||
they are replaced with a string that makes the file name unique.
|
||||
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
|
||||
and O_TEXT, O_BINARY (defined in "binary-io.h").
|
||||
The file is then created, with the specified flags, ensuring it didn't exist
|
||||
before.
|
||||
The file is created read-write (mask at least 0600 & ~umask), but it may be
|
||||
world-readable and world-writable (mask 0666 & ~umask), depending on the
|
||||
implementation.
|
||||
Returns the open file descriptor if successful, otherwise -1 and errno
|
||||
set. */
|
||||
# if !@HAVE_MKOSTEMPS@
|
||||
_GL_FUNCDECL_SYS (mkostemps, int,
|
||||
(char * /*template*/, int /*suffixlen*/, int /*flags*/)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkostemps, int,
|
||||
(char * /*template*/, int /*suffixlen*/, int /*flags*/));
|
||||
_GL_CXXALIASWARN (mkostemps);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkostemps
|
||||
# if HAVE_RAW_DECL_MKOSTEMPS
|
||||
_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - "
|
||||
"use gnulib module mkostemps for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_MKSTEMP@
|
||||
/* Create a unique temporary file from TEMPLATE.
|
||||
The last six characters of TEMPLATE must be "XXXXXX";
|
||||
they are replaced with a string that makes the file name unique.
|
||||
The file is then created, ensuring it didn't exist before.
|
||||
The file is created read-write (mask at least 0600 & ~umask), but it may be
|
||||
world-readable and world-writable (mask 0666 & ~umask), depending on the
|
||||
implementation.
|
||||
Returns the open file descriptor if successful, otherwise -1 and errno
|
||||
set. */
|
||||
# if @REPLACE_MKSTEMP@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define mkstemp rpl_mkstemp
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/));
|
||||
# else
|
||||
# if ! @HAVE_MKSTEMP@
|
||||
_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mkstemp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkstemp
|
||||
# if HAVE_RAW_DECL_MKSTEMP
|
||||
_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - "
|
||||
"use gnulib module mkstemp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_MKSTEMPS@
|
||||
/* Create a unique temporary file from TEMPLATE.
|
||||
The last six characters of TEMPLATE prior to a suffix of length
|
||||
SUFFIXLEN must be "XXXXXX";
|
||||
they are replaced with a string that makes the file name unique.
|
||||
The file is then created, ensuring it didn't exist before.
|
||||
The file is created read-write (mask at least 0600 & ~umask), but it may be
|
||||
world-readable and world-writable (mask 0666 & ~umask), depending on the
|
||||
implementation.
|
||||
Returns the open file descriptor if successful, otherwise -1 and errno
|
||||
set. */
|
||||
# if !@HAVE_MKSTEMPS@
|
||||
_GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/));
|
||||
_GL_CXXALIASWARN (mkstemps);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkstemps
|
||||
# if HAVE_RAW_DECL_MKSTEMPS
|
||||
_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
|
||||
"use gnulib module mkstemps for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PTSNAME@
|
||||
/* Return the pathname of the pseudo-terminal slave associated with
|
||||
the master FD is open on, or NULL on errors. */
|
||||
# if !@HAVE_PTSNAME@
|
||||
_GL_FUNCDECL_SYS (ptsname, char *, (int fd));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (ptsname, char *, (int fd));
|
||||
_GL_CXXALIASWARN (ptsname);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef ptsname
|
||||
# if HAVE_RAW_DECL_PTSNAME
|
||||
_GL_WARN_ON_USE (ptsname, "ptsname is not portable - "
|
||||
"use gnulib module ptsname for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PUTENV@
|
||||
# if @REPLACE_PUTENV@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef putenv
|
||||
# define putenv rpl_putenv
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (putenv, int, (char *string));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (putenv, int, (char *string));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (putenv);
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
# if !@HAVE_RANDOM_R@
|
||||
# ifndef RAND_MAX
|
||||
# define RAND_MAX 2147483647
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
# if !@HAVE_RANDOM_R@
|
||||
_GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result));
|
||||
_GL_CXXALIASWARN (random_r);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef random_r
|
||||
# if HAVE_RAW_DECL_RANDOM_R
|
||||
_GL_WARN_ON_USE (random_r, "random_r is unportable - "
|
||||
"use gnulib module random_r for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
# if !@HAVE_RANDOM_R@
|
||||
_GL_FUNCDECL_SYS (srandom_r, int,
|
||||
(unsigned int seed, struct random_data *rand_state)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (srandom_r, int,
|
||||
(unsigned int seed, struct random_data *rand_state));
|
||||
_GL_CXXALIASWARN (srandom_r);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef srandom_r
|
||||
# if HAVE_RAW_DECL_SRANDOM_R
|
||||
_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - "
|
||||
"use gnulib module random_r for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
# if !@HAVE_RANDOM_R@
|
||||
_GL_FUNCDECL_SYS (initstate_r, int,
|
||||
(unsigned int seed, char *buf, size_t buf_size,
|
||||
struct random_data *rand_state)
|
||||
_GL_ARG_NONNULL ((2, 4)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (initstate_r, int,
|
||||
(unsigned int seed, char *buf, size_t buf_size,
|
||||
struct random_data *rand_state));
|
||||
_GL_CXXALIASWARN (initstate_r);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef initstate_r
|
||||
# if HAVE_RAW_DECL_INITSTATE_R
|
||||
_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - "
|
||||
"use gnulib module random_r for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RANDOM_R@
|
||||
# if !@HAVE_RANDOM_R@
|
||||
_GL_FUNCDECL_SYS (setstate_r, int,
|
||||
(char *arg_state, struct random_data *rand_state)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (setstate_r, int,
|
||||
(char *arg_state, struct random_data *rand_state));
|
||||
_GL_CXXALIASWARN (setstate_r);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef setstate_r
|
||||
# if HAVE_RAW_DECL_SETSTATE_R
|
||||
_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
|
||||
"use gnulib module random_r for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_REALLOC_POSIX@
|
||||
# if @REPLACE_REALLOC@
|
||||
# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
|
||||
|| _GL_USE_STDLIB_ALLOC)
|
||||
# undef realloc
|
||||
# define realloc rpl_realloc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size));
|
||||
_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (realloc);
|
||||
#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
|
||||
# undef realloc
|
||||
/* Assume realloc is always declared. */
|
||||
_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
|
||||
"use gnulib module realloc-posix for portability");
|
||||
#endif
|
||||
|
||||
#if @GNULIB_REALPATH@
|
||||
# if @REPLACE_REALPATH@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define realpath rpl_realpath
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved));
|
||||
# else
|
||||
# if !@HAVE_REALPATH@
|
||||
_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (realpath);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef realpath
|
||||
# if HAVE_RAW_DECL_REALPATH
|
||||
_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module "
|
||||
"canonicalize or canonicalize-lgpl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_RPMATCH@
|
||||
/* Test a user response to a question.
|
||||
Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
|
||||
# if !@HAVE_RPMATCH@
|
||||
_GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (rpmatch, int, (const char *response));
|
||||
_GL_CXXALIASWARN (rpmatch);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef rpmatch
|
||||
# if HAVE_RAW_DECL_RPMATCH
|
||||
_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - "
|
||||
"use gnulib module rpmatch for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_SETENV@
|
||||
/* Set NAME to VALUE in the environment.
|
||||
If REPLACE is nonzero, overwrite an existing value. */
|
||||
# if @REPLACE_SETENV@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef setenv
|
||||
# define setenv rpl_setenv
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (setenv, int,
|
||||
(const char *name, const char *value, int replace)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (setenv, int,
|
||||
(const char *name, const char *value, int replace));
|
||||
# else
|
||||
# if !@HAVE_DECL_SETENV@
|
||||
_GL_FUNCDECL_SYS (setenv, int,
|
||||
(const char *name, const char *value, int replace)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (setenv, int,
|
||||
(const char *name, const char *value, int replace));
|
||||
# endif
|
||||
# if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
|
||||
_GL_CXXALIASWARN (setenv);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef setenv
|
||||
# if HAVE_RAW_DECL_SETENV
|
||||
_GL_WARN_ON_USE (setenv, "setenv is unportable - "
|
||||
"use gnulib module setenv for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_STRTOD@
|
||||
/* Parse a double from STRING, updating ENDP if appropriate. */
|
||||
# if @REPLACE_STRTOD@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define strtod rpl_strtod
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp));
|
||||
# else
|
||||
# if !@HAVE_STRTOD@
|
||||
_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (strtod);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef strtod
|
||||
# if HAVE_RAW_DECL_STRTOD
|
||||
_GL_WARN_ON_USE (strtod, "strtod is unportable - "
|
||||
"use gnulib module strtod for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_STRTOLL@
|
||||
/* Parse a signed integer whose textual representation starts at STRING.
|
||||
The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
|
||||
it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
|
||||
"0x").
|
||||
If ENDPTR is not NULL, the address of the first byte after the integer is
|
||||
stored in *ENDPTR.
|
||||
Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
|
||||
to ERANGE. */
|
||||
# if !@HAVE_STRTOLL@
|
||||
_GL_FUNCDECL_SYS (strtoll, long long,
|
||||
(const char *string, char **endptr, int base)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (strtoll, long long,
|
||||
(const char *string, char **endptr, int base));
|
||||
_GL_CXXALIASWARN (strtoll);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef strtoll
|
||||
# if HAVE_RAW_DECL_STRTOLL
|
||||
_GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
|
||||
"use gnulib module strtoll for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_STRTOULL@
|
||||
/* Parse an unsigned integer whose textual representation starts at STRING.
|
||||
The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
|
||||
it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
|
||||
"0x").
|
||||
If ENDPTR is not NULL, the address of the first byte after the integer is
|
||||
stored in *ENDPTR.
|
||||
Upon overflow, the return value is ULLONG_MAX, and errno is set to
|
||||
ERANGE. */
|
||||
# if !@HAVE_STRTOULL@
|
||||
_GL_FUNCDECL_SYS (strtoull, unsigned long long,
|
||||
(const char *string, char **endptr, int base)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (strtoull, unsigned long long,
|
||||
(const char *string, char **endptr, int base));
|
||||
_GL_CXXALIASWARN (strtoull);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef strtoull
|
||||
# if HAVE_RAW_DECL_STRTOULL
|
||||
_GL_WARN_ON_USE (strtoull, "strtoull is unportable - "
|
||||
"use gnulib module strtoull for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_UNLOCKPT@
|
||||
/* Unlock the slave side of the pseudo-terminal whose master side is specified
|
||||
by FD, so that it can be opened. */
|
||||
# if !@HAVE_UNLOCKPT@
|
||||
_GL_FUNCDECL_SYS (unlockpt, int, (int fd));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (unlockpt, int, (int fd));
|
||||
_GL_CXXALIASWARN (unlockpt);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef unlockpt
|
||||
# if HAVE_RAW_DECL_UNLOCKPT
|
||||
_GL_WARN_ON_USE (unlockpt, "unlockpt is not portable - "
|
||||
"use gnulib module unlockpt for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_UNSETENV@
|
||||
/* Remove the variable NAME from the environment. */
|
||||
# if @REPLACE_UNSETENV@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef unsetenv
|
||||
# define unsetenv rpl_unsetenv
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (unsetenv, int, (const char *name));
|
||||
# else
|
||||
# if !@HAVE_DECL_UNSETENV@
|
||||
_GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (unsetenv, int, (const char *name));
|
||||
# endif
|
||||
# if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
|
||||
_GL_CXXALIASWARN (unsetenv);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef unsetenv
|
||||
# if HAVE_RAW_DECL_UNSETENV
|
||||
_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
|
||||
"use gnulib module unsetenv for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Convert a wide character to a multibyte character. */
|
||||
#if @GNULIB_WCTOMB@
|
||||
# if @REPLACE_WCTOMB@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wctomb
|
||||
# define wctomb rpl_wctomb
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc));
|
||||
_GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wctomb);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_STDLIB_H */
|
||||
#endif /* _@GUARD_PREFIX@_STDLIB_H */
|
||||
#endif
|
453
lib/str-two-way.h
Normal file
453
lib/str-two-way.h
Normal file
@ -0,0 +1,453 @@
|
||||
/* Byte-wise substring search, using the Two-Way algorithm.
|
||||
Copyright (C) 2008-2011 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Eric Blake <ebb9@byu.net>, 2008.
|
||||
|
||||
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 3, 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. */
|
||||
|
||||
/* Before including this file, you need to include <config.h> and
|
||||
<string.h>, and define:
|
||||
RESULT_TYPE A macro that expands to the return type.
|
||||
AVAILABLE(h, h_l, j, n_l)
|
||||
A macro that returns nonzero if there are
|
||||
at least N_L bytes left starting at H[J].
|
||||
H is 'unsigned char *', H_L, J, and N_L
|
||||
are 'size_t'; H_L is an lvalue. For
|
||||
NUL-terminated searches, H_L can be
|
||||
modified each iteration to avoid having
|
||||
to compute the end of H up front.
|
||||
|
||||
For case-insensitivity, you may optionally define:
|
||||
CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
|
||||
characters of P1 and P2 are equal.
|
||||
CANON_ELEMENT(c) A macro that canonicalizes an element right after
|
||||
it has been fetched from one of the two strings.
|
||||
The argument is an 'unsigned char'; the result
|
||||
must be an 'unsigned char' as well.
|
||||
|
||||
This file undefines the macros documented above, and defines
|
||||
LONG_NEEDLE_THRESHOLD.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* We use the Two-Way string matching algorithm (also known as
|
||||
Chrochemore-Perrin), which guarantees linear complexity with
|
||||
constant space. Additionally, for long needles, we also use a bad
|
||||
character shift table similar to the Boyer-Moore algorithm to
|
||||
achieve improved (potentially sub-linear) performance.
|
||||
|
||||
See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260,
|
||||
http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm,
|
||||
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.6641&rep=rep1&type=pdf
|
||||
*/
|
||||
|
||||
/* Point at which computing a bad-byte shift table is likely to be
|
||||
worthwhile. Small needles should not compute a table, since it
|
||||
adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
|
||||
speedup no greater than a factor of NEEDLE_LEN. The larger the
|
||||
needle, the better the potential performance gain. On the other
|
||||
hand, on non-POSIX systems with CHAR_BIT larger than eight, the
|
||||
memory required for the table is prohibitive. */
|
||||
#if CHAR_BIT < 10
|
||||
# define LONG_NEEDLE_THRESHOLD 32U
|
||||
#else
|
||||
# define LONG_NEEDLE_THRESHOLD SIZE_MAX
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) ((a < b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#ifndef CANON_ELEMENT
|
||||
# define CANON_ELEMENT(c) c
|
||||
#endif
|
||||
#ifndef CMP_FUNC
|
||||
# define CMP_FUNC memcmp
|
||||
#endif
|
||||
|
||||
/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
|
||||
Return the index of the first byte in the right half, and set
|
||||
*PERIOD to the global period of the right half.
|
||||
|
||||
The global period of a string is the smallest index (possibly its
|
||||
length) at which all remaining bytes in the string are repetitions
|
||||
of the prefix (the last repetition may be a subset of the prefix).
|
||||
|
||||
When NEEDLE is factored into two halves, a local period is the
|
||||
length of the smallest word that shares a suffix with the left half
|
||||
and shares a prefix with the right half. All factorizations of a
|
||||
non-empty NEEDLE have a local period of at least 1 and no greater
|
||||
than NEEDLE_LEN.
|
||||
|
||||
A critical factorization has the property that the local period
|
||||
equals the global period. All strings have at least one critical
|
||||
factorization with the left half smaller than the global period.
|
||||
And while some strings have more than one critical factorization,
|
||||
it is provable that with an ordered alphabet, at least one of the
|
||||
critical factorizations corresponds to a maximal suffix.
|
||||
|
||||
Given an ordered alphabet, a critical factorization can be computed
|
||||
in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
|
||||
shorter of two ordered maximal suffixes. The ordered maximal
|
||||
suffixes are determined by lexicographic comparison while tracking
|
||||
periodicity. */
|
||||
static size_t
|
||||
critical_factorization (const unsigned char *needle, size_t needle_len,
|
||||
size_t *period)
|
||||
{
|
||||
/* Index of last byte of left half, or SIZE_MAX. */
|
||||
size_t max_suffix, max_suffix_rev;
|
||||
size_t j; /* Index into NEEDLE for current candidate suffix. */
|
||||
size_t k; /* Offset into current period. */
|
||||
size_t p; /* Intermediate period. */
|
||||
unsigned char a, b; /* Current comparison bytes. */
|
||||
|
||||
/* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
|
||||
out 0-length needles. */
|
||||
if (needle_len < 3)
|
||||
{
|
||||
*period = 1;
|
||||
return needle_len - 1;
|
||||
}
|
||||
|
||||
/* Invariants:
|
||||
0 <= j < NEEDLE_LEN - 1
|
||||
-1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
|
||||
min(max_suffix, max_suffix_rev) < global period of NEEDLE
|
||||
1 <= p <= global period of NEEDLE
|
||||
p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
|
||||
1 <= k <= p
|
||||
*/
|
||||
|
||||
/* Perform lexicographic search. */
|
||||
max_suffix = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[max_suffix + k]);
|
||||
if (a < b)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* b < a */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
*period = p;
|
||||
|
||||
/* Perform reverse lexicographic search. */
|
||||
max_suffix_rev = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[max_suffix_rev + k]);
|
||||
if (b < a)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix_rev;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* a < b */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix_rev = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Choose the shorter suffix. Return the index of the first byte of
|
||||
the right half, rather than the last byte of the left half.
|
||||
|
||||
For some examples, 'banana' has two critical factorizations, both
|
||||
exposed by the two lexicographic extreme suffixes of 'anana' and
|
||||
'nana', where both suffixes have a period of 2. On the other
|
||||
hand, with 'aab' and 'bba', both strings have a single critical
|
||||
factorization of the last byte, with the suffix having a period
|
||||
of 1. While the maximal lexicographic suffix of 'aab' is 'b',
|
||||
the maximal lexicographic suffix of 'bba' is 'ba', which is not a
|
||||
critical factorization. Conversely, the maximal reverse
|
||||
lexicographic suffix of 'a' works for 'bba', but not 'ab' for
|
||||
'aab'. The shorter suffix of the two will always be a critical
|
||||
factorization. */
|
||||
if (max_suffix_rev + 1 < max_suffix + 1)
|
||||
return max_suffix + 1;
|
||||
*period = p;
|
||||
return max_suffix_rev + 1;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 2 * NEEDLE_LEN comparisons.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
|
||||
static RETURN_TYPE
|
||||
two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch in the left half can
|
||||
only advance by the period, so use memory to avoid rescanning
|
||||
known occurrences of the period in the right half. */
|
||||
size_t memory = 0;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = suffix;
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
|
||||
and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
|
||||
sublinear performance is not possible. */
|
||||
static RETURN_TYPE
|
||||
two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
size_t shift_table[1U << CHAR_BIT]; /* See below. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Populate shift_table. For each possible byte value c,
|
||||
shift_table[c] is the distance from the last occurrence of c to
|
||||
the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
|
||||
shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
|
||||
for (i = 0; i < 1U << CHAR_BIT; i++)
|
||||
shift_table[i] = needle_len;
|
||||
for (i = 0; i < needle_len; i++)
|
||||
shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch in the left half can
|
||||
only advance by the period, so use memory to avoid rescanning
|
||||
known occurrences of the period in the right half. */
|
||||
size_t memory = 0;
|
||||
size_t shift;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
if (memory && shift < period)
|
||||
{
|
||||
/* Since needle is periodic, but the last period has
|
||||
a byte out of place, there can be no match until
|
||||
after the mismatch. */
|
||||
shift = needle_len - period;
|
||||
}
|
||||
memory = 0;
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
size_t shift;
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = suffix;
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef AVAILABLE
|
||||
#undef CANON_ELEMENT
|
||||
#undef CMP_FUNC
|
||||
#undef MAX
|
||||
#undef RETURN_TYPE
|
55
lib/strdup.c
Normal file
55
lib/strdup.c
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2011 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 3, 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 <config.h>
|
||||
#endif
|
||||
|
||||
/* Get specification. */
|
||||
#include <string.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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
|
1011
lib/string.in.h
Normal file
1011
lib/string.in.h
Normal file
File diff suppressed because it is too large
Load Diff
33
lib/strncat.c
Normal file
33
lib/strncat.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* Concatenate strings.
|
||||
Copyright (C) 1999, 2002, 2006, 2010-2011 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strncat (char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *destptr = dest + strlen (dest);
|
||||
|
||||
for (; n > 0 && (*destptr = *src) != '\0'; src++, destptr++, n--)
|
||||
;
|
||||
if (n == 0)
|
||||
*destptr = '\0';
|
||||
return dest;
|
||||
}
|
83
lib/strstr.c
Normal file
83
lib/strstr.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2011 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 3, 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. */
|
||||
|
||||
/* This particular implementation was written by Eric Blake, 2008. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification of strstr. */
|
||||
#include <string.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef _LIBC
|
||||
# define __builtin_expect(expr, val) (expr)
|
||||
#endif
|
||||
|
||||
#define RETURN_TYPE char *
|
||||
#define AVAILABLE(h, h_l, j, n_l) \
|
||||
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
|
||||
&& ((h_l) = (j) + (n_l)))
|
||||
#include "str-two-way.h"
|
||||
|
||||
/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
|
||||
if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
|
||||
HAYSTACK. */
|
||||
char *
|
||||
strstr (const char *haystack_start, const char *needle_start)
|
||||
{
|
||||
const char *haystack = haystack_start;
|
||||
const char *needle = needle_start;
|
||||
size_t needle_len; /* Length of NEEDLE. */
|
||||
size_t haystack_len; /* Known minimum length of HAYSTACK. */
|
||||
bool ok = true; /* True if NEEDLE is prefix of HAYSTACK. */
|
||||
|
||||
/* Determine length of NEEDLE, and in the process, make sure
|
||||
HAYSTACK is at least as long (no point processing all of a long
|
||||
NEEDLE if HAYSTACK is too short). */
|
||||
while (*haystack && *needle)
|
||||
ok &= *haystack++ == *needle++;
|
||||
if (*needle)
|
||||
return NULL;
|
||||
if (ok)
|
||||
return (char *) haystack_start;
|
||||
|
||||
/* Reduce the size of haystack using strchr, since it has a smaller
|
||||
linear coefficient than the Two-Way algorithm. */
|
||||
needle_len = needle - needle_start;
|
||||
haystack = strchr (haystack_start + 1, *needle_start);
|
||||
if (!haystack || __builtin_expect (needle_len == 1, 0))
|
||||
return (char *) haystack;
|
||||
needle -= needle_len;
|
||||
haystack_len = (haystack > haystack_start + needle_len ? 1
|
||||
: needle_len + haystack_start - haystack);
|
||||
|
||||
/* Perform the search. Abstract memory is considered to be an array
|
||||
of 'unsigned char' values, not an array of 'char' values. See
|
||||
ISO C 99 section 6.2.6.1. */
|
||||
if (needle_len < LONG_NEEDLE_THRESHOLD)
|
||||
return two_way_short_needle ((const unsigned char *) haystack,
|
||||
haystack_len,
|
||||
(const unsigned char *) needle, needle_len);
|
||||
return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
|
||||
(const unsigned char *) needle, needle_len);
|
||||
}
|
||||
|
||||
#undef LONG_NEEDLE_THRESHOLD
|
658
lib/sys_stat.in.h
Normal file
658
lib/sys_stat.in.h
Normal file
@ -0,0 +1,658 @@
|
||||
/* Provide a more complete sys/stat header file.
|
||||
Copyright (C) 2005-2011 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 3, 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, Paul Eggert, and Jim Meyering. */
|
||||
|
||||
/* This file is supposed to be used on platforms where <sys/stat.h> is
|
||||
incomplete. It is intended to provide definitions and prototypes
|
||||
needed by an application. Start with what the system provides. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_system_sys_stat_h
|
||||
/* Special invocation convention. */
|
||||
|
||||
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_STAT_H
|
||||
|
||||
/* Get nlink_t. */
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Get struct timespec. */
|
||||
#include <time.h>
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_SYS_STAT_H
|
||||
#define _@GUARD_PREFIX@_SYS_STAT_H
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
|
||||
headers that may declare mkdir(). */
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
# include <io.h> /* mingw32, mingw64 */
|
||||
# include <direct.h> /* mingw64 */
|
||||
#endif
|
||||
|
||||
#ifndef S_IFMT
|
||||
# define S_IFMT 0170000
|
||||
#endif
|
||||
|
||||
#if STAT_MACROS_BROKEN
|
||||
# undef S_ISBLK
|
||||
# undef S_ISCHR
|
||||
# undef S_ISDIR
|
||||
# undef S_ISFIFO
|
||||
# undef S_ISLNK
|
||||
# undef S_ISNAM
|
||||
# undef S_ISMPB
|
||||
# undef S_ISMPC
|
||||
# undef S_ISNWK
|
||||
# undef S_ISREG
|
||||
# undef S_ISSOCK
|
||||
#endif
|
||||
|
||||
#ifndef S_ISBLK
|
||||
# ifdef S_IFBLK
|
||||
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
# else
|
||||
# define S_ISBLK(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISCHR
|
||||
# ifdef S_IFCHR
|
||||
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
# else
|
||||
# define S_ISCHR(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISDIR
|
||||
# ifdef S_IFDIR
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
# else
|
||||
# define S_ISDIR(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISDOOR /* Solaris 2.5 and up */
|
||||
# define S_ISDOOR(m) 0
|
||||
#endif
|
||||
|
||||
#ifndef S_ISFIFO
|
||||
# ifdef S_IFIFO
|
||||
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
# else
|
||||
# define S_ISFIFO(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISLNK
|
||||
# ifdef S_IFLNK
|
||||
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
# else
|
||||
# define S_ISLNK(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISMPB /* V7 */
|
||||
# ifdef S_IFMPB
|
||||
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
# else
|
||||
# define S_ISMPB(m) 0
|
||||
# define S_ISMPC(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISNAM /* Xenix */
|
||||
# ifdef S_IFNAM
|
||||
# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
|
||||
# else
|
||||
# define S_ISNAM(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISNWK /* HP/UX */
|
||||
# ifdef S_IFNWK
|
||||
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
# else
|
||||
# define S_ISNWK(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISPORT /* Solaris 10 and up */
|
||||
# define S_ISPORT(m) 0
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
# ifdef S_IFREG
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
# else
|
||||
# define S_ISREG(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISSOCK
|
||||
# ifdef S_IFSOCK
|
||||
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
# else
|
||||
# define S_ISSOCK(m) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef S_TYPEISMQ
|
||||
# define S_TYPEISMQ(p) 0
|
||||
#endif
|
||||
|
||||
#ifndef S_TYPEISTMO
|
||||
# define S_TYPEISTMO(p) 0
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef S_TYPEISSEM
|
||||
# ifdef S_INSEM
|
||||
# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
|
||||
# else
|
||||
# define S_TYPEISSEM(p) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef S_TYPEISSHM
|
||||
# ifdef S_INSHD
|
||||
# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
|
||||
# else
|
||||
# define S_TYPEISSHM(p) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* high performance ("contiguous data") */
|
||||
#ifndef S_ISCTG
|
||||
# define S_ISCTG(p) 0
|
||||
#endif
|
||||
|
||||
/* Cray DMF (data migration facility): off line, with data */
|
||||
#ifndef S_ISOFD
|
||||
# define S_ISOFD(p) 0
|
||||
#endif
|
||||
|
||||
/* Cray DMF (data migration facility): off line, with no data */
|
||||
#ifndef S_ISOFL
|
||||
# define S_ISOFL(p) 0
|
||||
#endif
|
||||
|
||||
/* 4.4BSD whiteout */
|
||||
#ifndef S_ISWHT
|
||||
# define S_ISWHT(m) 0
|
||||
#endif
|
||||
|
||||
/* If any of the following are undefined,
|
||||
define them to their de facto standard values. */
|
||||
#if !S_ISUID
|
||||
# define S_ISUID 04000
|
||||
#endif
|
||||
#if !S_ISGID
|
||||
# define S_ISGID 02000
|
||||
#endif
|
||||
|
||||
/* S_ISVTX is a common extension to POSIX. */
|
||||
#ifndef S_ISVTX
|
||||
# define S_ISVTX 01000
|
||||
#endif
|
||||
|
||||
#if !S_IRUSR && S_IREAD
|
||||
# define S_IRUSR S_IREAD
|
||||
#endif
|
||||
#if !S_IRUSR
|
||||
# define S_IRUSR 00400
|
||||
#endif
|
||||
#if !S_IRGRP
|
||||
# define S_IRGRP (S_IRUSR >> 3)
|
||||
#endif
|
||||
#if !S_IROTH
|
||||
# define S_IROTH (S_IRUSR >> 6)
|
||||
#endif
|
||||
|
||||
#if !S_IWUSR && S_IWRITE
|
||||
# define S_IWUSR S_IWRITE
|
||||
#endif
|
||||
#if !S_IWUSR
|
||||
# define S_IWUSR 00200
|
||||
#endif
|
||||
#if !S_IWGRP
|
||||
# define S_IWGRP (S_IWUSR >> 3)
|
||||
#endif
|
||||
#if !S_IWOTH
|
||||
# define S_IWOTH (S_IWUSR >> 6)
|
||||
#endif
|
||||
|
||||
#if !S_IXUSR && S_IEXEC
|
||||
# define S_IXUSR S_IEXEC
|
||||
#endif
|
||||
#if !S_IXUSR
|
||||
# define S_IXUSR 00100
|
||||
#endif
|
||||
#if !S_IXGRP
|
||||
# define S_IXGRP (S_IXUSR >> 3)
|
||||
#endif
|
||||
#if !S_IXOTH
|
||||
# define S_IXOTH (S_IXUSR >> 6)
|
||||
#endif
|
||||
|
||||
#if !S_IRWXU
|
||||
# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
|
||||
#endif
|
||||
#if !S_IRWXG
|
||||
# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
|
||||
#endif
|
||||
#if !S_IRWXO
|
||||
# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
|
||||
#endif
|
||||
|
||||
/* S_IXUGO is a common extension to POSIX. */
|
||||
#if !S_IXUGO
|
||||
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
|
||||
#endif
|
||||
|
||||
#ifndef S_IRWXUGO
|
||||
# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
#endif
|
||||
|
||||
/* Macros for futimens and utimensat. */
|
||||
#ifndef UTIME_NOW
|
||||
# define UTIME_NOW (-1)
|
||||
# define UTIME_OMIT (-2)
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_FCHMODAT@
|
||||
# if !@HAVE_FCHMODAT@
|
||||
_GL_FUNCDECL_SYS (fchmodat, int,
|
||||
(int fd, char const *file, mode_t mode, int flag)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (fchmodat, int,
|
||||
(int fd, char const *file, mode_t mode, int flag));
|
||||
_GL_CXXALIASWARN (fchmodat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fchmodat
|
||||
# if HAVE_RAW_DECL_FCHMODAT
|
||||
_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
|
||||
"use gnulib module openat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @REPLACE_FSTAT@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define fstat rpl_fstat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
|
||||
#else
|
||||
_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
|
||||
#endif
|
||||
_GL_CXXALIASWARN (fstat);
|
||||
|
||||
|
||||
#if @GNULIB_FSTATAT@
|
||||
# if @REPLACE_FSTATAT@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef fstatat
|
||||
# define fstatat rpl_fstatat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (fstatat, int,
|
||||
(int fd, char const *name, struct stat *st, int flags)
|
||||
_GL_ARG_NONNULL ((2, 3)));
|
||||
_GL_CXXALIAS_RPL (fstatat, int,
|
||||
(int fd, char const *name, struct stat *st, int flags));
|
||||
# else
|
||||
# if !@HAVE_FSTATAT@
|
||||
_GL_FUNCDECL_SYS (fstatat, int,
|
||||
(int fd, char const *name, struct stat *st, int flags)
|
||||
_GL_ARG_NONNULL ((2, 3)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (fstatat, int,
|
||||
(int fd, char const *name, struct stat *st, int flags));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (fstatat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fstatat
|
||||
# if HAVE_RAW_DECL_FSTATAT
|
||||
_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
|
||||
"use gnulib module openat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_FUTIMENS@
|
||||
/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
|
||||
implementation relies on futimesat, which on Solaris 10 makes an invocation
|
||||
to futimens that is meant to invoke the libc's futimens(), not gnulib's
|
||||
futimens(). */
|
||||
# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef futimens
|
||||
# define futimens rpl_futimens
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
|
||||
_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
|
||||
# else
|
||||
# if !@HAVE_FUTIMENS@
|
||||
_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
|
||||
# endif
|
||||
# if @HAVE_FUTIMENS@
|
||||
_GL_CXXALIASWARN (futimens);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef futimens
|
||||
# if HAVE_RAW_DECL_FUTIMENS
|
||||
_GL_WARN_ON_USE (futimens, "futimens is not portable - "
|
||||
"use gnulib module futimens for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_LCHMOD@
|
||||
/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
|
||||
denotes a symbolic link. */
|
||||
# if !@HAVE_LCHMOD@
|
||||
/* The lchmod replacement follows symbolic links. Callers should take
|
||||
this into account; lchmod should be applied only to arguments that
|
||||
are known to not be symbolic links. On hosts that lack lchmod,
|
||||
this can lead to race conditions between the check and the
|
||||
invocation of lchmod, but we know of no workarounds that are
|
||||
reliable in general. You might try requesting support for lchmod
|
||||
from your operating system supplier. */
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define lchmod chmod
|
||||
# endif
|
||||
/* Need to cast, because on mingw, the second parameter of chmod is
|
||||
int mode. */
|
||||
_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
|
||||
(const char *filename, mode_t mode));
|
||||
# else
|
||||
# if 0 /* assume already declared */
|
||||
_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
|
||||
# endif
|
||||
# if @HAVE_LCHMOD@
|
||||
_GL_CXXALIASWARN (lchmod);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef lchmod
|
||||
# if HAVE_RAW_DECL_LCHMOD
|
||||
_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
|
||||
"use gnulib module lchmod for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_LSTAT@
|
||||
# if ! @HAVE_LSTAT@
|
||||
/* mingw does not support symlinks, therefore it does not have lstat. But
|
||||
without links, stat does just fine. */
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define lstat stat
|
||||
# endif
|
||||
_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
|
||||
# elif @REPLACE_LSTAT@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef lstat
|
||||
# define lstat rpl_lstat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
|
||||
# endif
|
||||
# if @HAVE_LSTAT@
|
||||
_GL_CXXALIASWARN (lstat);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef lstat
|
||||
# if HAVE_RAW_DECL_LSTAT
|
||||
_GL_WARN_ON_USE (lstat, "lstat is unportable - "
|
||||
"use gnulib module lstat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @REPLACE_MKDIR@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mkdir
|
||||
# define mkdir rpl_mkdir
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
|
||||
#else
|
||||
/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
|
||||
Additionally, it declares _mkdir (and depending on compile flags, an
|
||||
alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
|
||||
which are included above. */
|
||||
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
# if !GNULIB_defined_rpl_mkdir
|
||||
static inline int
|
||||
rpl_mkdir (char const *name, mode_t mode)
|
||||
{
|
||||
return _mkdir (name);
|
||||
}
|
||||
# define GNULIB_defined_rpl_mkdir 1
|
||||
# endif
|
||||
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define mkdir rpl_mkdir
|
||||
# endif
|
||||
_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
|
||||
# endif
|
||||
#endif
|
||||
_GL_CXXALIASWARN (mkdir);
|
||||
|
||||
|
||||
#if @GNULIB_MKDIRAT@
|
||||
# if !@HAVE_MKDIRAT@
|
||||
_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
|
||||
_GL_CXXALIASWARN (mkdirat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkdirat
|
||||
# if HAVE_RAW_DECL_MKDIRAT
|
||||
_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
|
||||
"use gnulib module openat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_MKFIFO@
|
||||
# if @REPLACE_MKFIFO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mkfifo
|
||||
# define mkfifo rpl_mkfifo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
|
||||
# else
|
||||
# if !@HAVE_MKFIFO@
|
||||
_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mkfifo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkfifo
|
||||
# if HAVE_RAW_DECL_MKFIFO
|
||||
_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
|
||||
"use gnulib module mkfifo for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_MKFIFOAT@
|
||||
# if !@HAVE_MKFIFOAT@
|
||||
_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
|
||||
_GL_CXXALIASWARN (mkfifoat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mkfifoat
|
||||
# if HAVE_RAW_DECL_MKFIFOAT
|
||||
_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
|
||||
"use gnulib module mkfifoat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_MKNOD@
|
||||
# if @REPLACE_MKNOD@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mknod
|
||||
# define mknod rpl_mknod
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
|
||||
# else
|
||||
# if !@HAVE_MKNOD@
|
||||
_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
|
||||
_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mknod);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mknod
|
||||
# if HAVE_RAW_DECL_MKNOD
|
||||
_GL_WARN_ON_USE (mknod, "mknod is not portable - "
|
||||
"use gnulib module mknod for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_MKNODAT@
|
||||
# if !@HAVE_MKNODAT@
|
||||
_GL_FUNCDECL_SYS (mknodat, int,
|
||||
(int fd, char const *file, mode_t mode, dev_t dev)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mknodat, int,
|
||||
(int fd, char const *file, mode_t mode, dev_t dev));
|
||||
_GL_CXXALIASWARN (mknodat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mknodat
|
||||
# if HAVE_RAW_DECL_MKNODAT
|
||||
_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
|
||||
"use gnulib module mkfifoat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_STAT@
|
||||
# if @REPLACE_STAT@
|
||||
/* We can't use the object-like #define stat rpl_stat, because of
|
||||
struct stat. This means that rpl_stat will not be used if the user
|
||||
does (stat)(a,b). Oh well. */
|
||||
# undef stat
|
||||
# ifdef _LARGE_FILES
|
||||
/* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
|
||||
so we have to replace stat64() instead of stat(). */
|
||||
# define stat stat64
|
||||
# undef stat64
|
||||
# define stat64(name, st) rpl_stat (name, st)
|
||||
# else /* !_LARGE_FILES */
|
||||
# define stat(name, st) rpl_stat (name, st)
|
||||
# endif /* !_LARGE_FILES */
|
||||
_GL_EXTERN_C int stat (const char *name, struct stat *buf)
|
||||
_GL_ARG_NONNULL ((1, 2));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef stat
|
||||
# if HAVE_RAW_DECL_STAT
|
||||
_GL_WARN_ON_USE (stat, "stat is unportable - "
|
||||
"use gnulib module stat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_UTIMENSAT@
|
||||
/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
|
||||
implementation relies on futimesat, which on Solaris 10 makes an invocation
|
||||
to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
|
||||
utimensat(). */
|
||||
# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef utimensat
|
||||
# define utimensat rpl_utimensat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
|
||||
struct timespec const times[2], int flag)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
|
||||
struct timespec const times[2], int flag));
|
||||
# else
|
||||
# if !@HAVE_UTIMENSAT@
|
||||
_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
|
||||
struct timespec const times[2], int flag)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
|
||||
struct timespec const times[2], int flag));
|
||||
# endif
|
||||
# if @HAVE_UTIMENSAT@
|
||||
_GL_CXXALIASWARN (utimensat);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef utimensat
|
||||
# if HAVE_RAW_DECL_UTIMENSAT
|
||||
_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
|
||||
"use gnulib module utimensat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
|
||||
#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
|
||||
#endif
|
101
lib/sys_time.in.h
Normal file
101
lib/sys_time.in.h
Normal file
@ -0,0 +1,101 @@
|
||||
/* Provide a more complete sys/time.h.
|
||||
|
||||
Copyright (C) 2007-2011 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 3, 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 Paul Eggert. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined _@GUARD_PREFIX@_SYS_TIME_H
|
||||
|
||||
/* Simply delegate to the system's header, without adding anything. */
|
||||
# if @HAVE_SYS_TIME_H@
|
||||
# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
# define _@GUARD_PREFIX@_SYS_TIME_H
|
||||
|
||||
# if @HAVE_SYS_TIME_H@
|
||||
# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# if ! @HAVE_STRUCT_TIMEVAL@
|
||||
|
||||
# if !GNULIB_defined_struct_timeval
|
||||
struct timeval
|
||||
{
|
||||
time_t tv_sec;
|
||||
long int tv_usec;
|
||||
};
|
||||
# define GNULIB_defined_struct_timeval 1
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# if @GNULIB_GETTIMEOFDAY@
|
||||
# if @REPLACE_GETTIMEOFDAY@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef gettimeofday
|
||||
# define gettimeofday rpl_gettimeofday
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (gettimeofday, int,
|
||||
(struct timeval *restrict, void *restrict)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (gettimeofday, int,
|
||||
(struct timeval *restrict, void *restrict));
|
||||
# else
|
||||
# if !@HAVE_GETTIMEOFDAY@
|
||||
_GL_FUNCDECL_SYS (gettimeofday, int,
|
||||
(struct timeval *restrict, void *restrict)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
/* Need to cast, because on glibc systems, by default, the second argument is
|
||||
struct timezone *. */
|
||||
_GL_CXXALIAS_SYS_CAST (gettimeofday, int,
|
||||
(struct timeval *restrict, void *restrict));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (gettimeofday);
|
||||
# elif defined GNULIB_POSIXCHECK
|
||||
# undef gettimeofday
|
||||
# if HAVE_RAW_DECL_GETTIMEOFDAY
|
||||
_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
|
||||
"use gnulib module gettimeofday for portability");
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_SYS_TIME_H */
|
249
lib/time.in.h
Normal file
249
lib/time.in.h
Normal file
@ -0,0 +1,249 @@
|
||||
/* A more-standard <time.h>.
|
||||
|
||||
Copyright (C) 2007-2011 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 3, 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. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
/* Don't get in the way of glibc when it includes time.h merely to
|
||||
declare a few standard symbols, rather than to declare all the
|
||||
symbols. Also, Solaris 8 <time.h> eventually includes itself
|
||||
recursively; if that is happening, just include the system <time.h>
|
||||
without adding our own declarations. */
|
||||
#if (defined __need_time_t || defined __need_clock_t \
|
||||
|| defined __need_timespec \
|
||||
|| defined _@GUARD_PREFIX@_TIME_H)
|
||||
|
||||
# @INCLUDE_NEXT@ @NEXT_TIME_H@
|
||||
|
||||
#else
|
||||
|
||||
# define _@GUARD_PREFIX@_TIME_H
|
||||
|
||||
# @INCLUDE_NEXT@ @NEXT_TIME_H@
|
||||
|
||||
/* NetBSD 5.0 mis-defines NULL. */
|
||||
# include <stddef.h>
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
|
||||
Or they define it with the wrong member names or define it in <sys/time.h>
|
||||
(e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
|
||||
pthreads-win32 library defines it in <pthread.h>. */
|
||||
# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
|
||||
# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
|
||||
# include <sys/time.h>
|
||||
# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
|
||||
# include <pthread.h>
|
||||
/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
|
||||
# undef asctime_r
|
||||
# undef ctime_r
|
||||
# undef gmtime_r
|
||||
# undef localtime_r
|
||||
# undef rand_r
|
||||
# undef strtok_r
|
||||
# else
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# if !GNULIB_defined_struct_timespec
|
||||
# undef timespec
|
||||
# define timespec rpl_timespec
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec;
|
||||
long int tv_nsec;
|
||||
};
|
||||
# define GNULIB_defined_struct_timespec 1
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if !GNULIB_defined_struct_time_t_must_be_integral
|
||||
/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
|
||||
time_t to be an integer type, even though C99 permits floating
|
||||
point. We don't know of any implementation that uses floating
|
||||
point, and it is much easier to write code that doesn't have to
|
||||
worry about that corner case, so we force the issue. */
|
||||
struct __time_t_must_be_integral {
|
||||
unsigned int __floating_time_t_unsupported : (time_t) 1;
|
||||
};
|
||||
# define GNULIB_defined_struct_time_t_must_be_integral 1
|
||||
# endif
|
||||
|
||||
/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
|
||||
return -1 and store the remaining time into RMTP. See
|
||||
<http://www.opengroup.org/susv3xsh/nanosleep.html>. */
|
||||
# if @GNULIB_NANOSLEEP@
|
||||
# if @REPLACE_NANOSLEEP@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define nanosleep rpl_nanosleep
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp));
|
||||
# else
|
||||
# if ! @HAVE_NANOSLEEP@
|
||||
_GL_FUNCDECL_SYS (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (nanosleep);
|
||||
# endif
|
||||
|
||||
/* Return the 'time_t' representation of TP and normalize TP. */
|
||||
# if @GNULIB_MKTIME@
|
||||
# if @REPLACE_MKTIME@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define mktime rpl_mktime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mktime);
|
||||
# endif
|
||||
|
||||
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
|
||||
<http://www.opengroup.org/susv3xsh/localtime_r.html> and
|
||||
<http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
|
||||
# if @GNULIB_TIME_R@
|
||||
# if @REPLACE_LOCALTIME_R@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef localtime_r
|
||||
# define localtime_r rpl_localtime_r
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# else
|
||||
# if ! @HAVE_DECL_LOCALTIME_R@
|
||||
_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# endif
|
||||
# if @HAVE_DECL_LOCALTIME_R@
|
||||
_GL_CXXALIASWARN (localtime_r);
|
||||
# endif
|
||||
# if @REPLACE_LOCALTIME_R@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef gmtime_r
|
||||
# define gmtime_r rpl_gmtime_r
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# else
|
||||
# if ! @HAVE_DECL_LOCALTIME_R@
|
||||
_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# endif
|
||||
# if @HAVE_DECL_LOCALTIME_R@
|
||||
_GL_CXXALIASWARN (gmtime_r);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
|
||||
the resulting broken-down time into TM. See
|
||||
<http://www.opengroup.org/susv3xsh/strptime.html>. */
|
||||
# if @GNULIB_STRPTIME@
|
||||
# if ! @HAVE_STRPTIME@
|
||||
_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
|
||||
char const *restrict __format,
|
||||
struct tm *restrict __tm)
|
||||
_GL_ARG_NONNULL ((1, 2, 3)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
|
||||
char const *restrict __format,
|
||||
struct tm *restrict __tm));
|
||||
_GL_CXXALIASWARN (strptime);
|
||||
# endif
|
||||
|
||||
/* Convert TM to a time_t value, assuming UTC. */
|
||||
# if @GNULIB_TIMEGM@
|
||||
# if @REPLACE_TIMEGM@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef timegm
|
||||
# define timegm rpl_timegm
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
|
||||
# else
|
||||
# if ! @HAVE_TIMEGM@
|
||||
_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (timegm);
|
||||
# endif
|
||||
|
||||
/* Encourage applications to avoid unsafe functions that can overrun
|
||||
buffers when given outlandish struct tm values. Portable
|
||||
applications should use strftime (or even sprintf) instead. */
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef asctime
|
||||
_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef asctime_r
|
||||
_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef ctime
|
||||
_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef ctime_r
|
||||
_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
|
||||
#endif
|
1421
lib/unistd.in.h
Normal file
1421
lib/unistd.in.h
Normal file
File diff suppressed because it is too large
Load Diff
5578
lib/vasnprintf.c
Normal file
5578
lib/vasnprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
80
lib/vasnprintf.h
Normal file
80
lib/vasnprintf.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* vsprintf with automatic memory allocation.
|
||||
Copyright (C) 2002-2004, 2007-2011 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 3, 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 <stdarg.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* The __attribute__ feature is available in gcc versions 2.5 and later.
|
||||
The __-protected variants of the attributes 'format' and 'printf' are
|
||||
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
|
||||
We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
|
||||
gnulib and libintl do '#define printf __printf__' when they override
|
||||
the 'printf' function. */
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
|
||||
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
|
||||
#else
|
||||
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
|
||||
#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);
|
||||
}
|
||||
*/
|
||||
#if REPLACE_VASNPRINTF
|
||||
# define asnprintf rpl_asnprintf
|
||||
# define vasnprintf rpl_vasnprintf
|
||||
#endif
|
||||
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
|
||||
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VASNPRINTF_H */
|
243
lib/verify.h
Normal file
243
lib/verify.h
Normal file
@ -0,0 +1,243 @@
|
||||
/* Compile-time assert-like macros.
|
||||
|
||||
Copyright (C) 2005-2006, 2009-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||
|
||||
#ifndef _GL_VERIFY_H
|
||||
# define _GL_VERIFY_H
|
||||
|
||||
|
||||
/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per the
|
||||
C1X draft N1548 section 6.7.10. This is supported by GCC 4.6.0 and
|
||||
later, in C mode, and its use here generates easier-to-read diagnostics
|
||||
when verify (R) fails.
|
||||
|
||||
Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per the
|
||||
C++0X draft N3242 section 7.(4).
|
||||
This will likely be supported by future GCC versions, in C++ mode.
|
||||
|
||||
Use this only with GCC. If we were willing to slow 'configure'
|
||||
down we could also use it with other compilers, but since this
|
||||
affects only the quality of diagnostics, why bother? */
|
||||
# if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined __cplusplus
|
||||
# define _GL_HAVE__STATIC_ASSERT 1
|
||||
# endif
|
||||
/* The condition (99 < __GNUC__) is temporary, until we know about the
|
||||
first G++ release that supports static_assert. */
|
||||
# if (99 < __GNUC__) && defined __cplusplus
|
||||
# define _GL_HAVE_STATIC_ASSERT 1
|
||||
# endif
|
||||
|
||||
/* Each of these macros verifies that its argument R is nonzero. To
|
||||
be portable, R should be an integer constant expression. Unlike
|
||||
assert (R), there is no run-time overhead.
|
||||
|
||||
If _Static_assert works, verify (R) uses it directly. Similarly,
|
||||
_GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
|
||||
that is an operand of sizeof.
|
||||
|
||||
The code below uses several ideas for C++ compilers, and for C
|
||||
compilers that do not support _Static_assert:
|
||||
|
||||
* The first step is ((R) ? 1 : -1). Given an expression R, of
|
||||
integral or boolean or floating-point type, this yields an
|
||||
expression of integral type, whose value is later verified to be
|
||||
constant and nonnegative.
|
||||
|
||||
* Next this expression W is wrapped in a type
|
||||
struct _gl_verify_type {
|
||||
unsigned int _gl_verify_error_if_negative: W;
|
||||
}.
|
||||
If W is negative, this yields a compile-time error. No compiler can
|
||||
deal with a bit-field of negative size.
|
||||
|
||||
One might think that an array size check would have the same
|
||||
effect, that is, that the type struct { unsigned int dummy[W]; }
|
||||
would work as well. However, inside a function, some compilers
|
||||
(such as C++ compilers and GNU C) allow local parameters and
|
||||
variables inside array size expressions. With these compilers,
|
||||
an array size check would not properly diagnose this misuse of
|
||||
the verify macro:
|
||||
|
||||
void function (int n) { verify (n < 0); }
|
||||
|
||||
* For the verify macro, the struct _gl_verify_type will need to
|
||||
somehow be embedded into a declaration. To be portable, this
|
||||
declaration must declare an object, a constant, a function, or a
|
||||
typedef name. If the declared entity uses the type directly,
|
||||
such as in
|
||||
|
||||
struct dummy {...};
|
||||
typedef struct {...} dummy;
|
||||
extern struct {...} *dummy;
|
||||
extern void dummy (struct {...} *);
|
||||
extern struct {...} *dummy (void);
|
||||
|
||||
two uses of the verify macro would yield colliding declarations
|
||||
if the entity names are not disambiguated. A workaround is to
|
||||
attach the current line number to the entity name:
|
||||
|
||||
#define _GL_CONCAT0(x, y) x##y
|
||||
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||
extern struct {...} * _GL_CONCAT (dummy, __LINE__);
|
||||
|
||||
But this has the problem that two invocations of verify from
|
||||
within the same macro would collide, since the __LINE__ value
|
||||
would be the same for both invocations. (The GCC __COUNTER__
|
||||
macro solves this problem, but is not portable.)
|
||||
|
||||
A solution is to use the sizeof operator. It yields a number,
|
||||
getting rid of the identity of the type. Declarations like
|
||||
|
||||
extern int dummy [sizeof (struct {...})];
|
||||
extern void dummy (int [sizeof (struct {...})]);
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
|
||||
can be repeated.
|
||||
|
||||
* Should the implementation use a named struct or an unnamed struct?
|
||||
Which of the following alternatives can be used?
|
||||
|
||||
extern int dummy [sizeof (struct {...})];
|
||||
extern int dummy [sizeof (struct _gl_verify_type {...})];
|
||||
extern void dummy (int [sizeof (struct {...})]);
|
||||
extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
|
||||
|
||||
In the second and sixth case, the struct type is exported to the
|
||||
outer scope; two such declarations therefore collide. GCC warns
|
||||
about the first, third, and fourth cases. So the only remaining
|
||||
possibility is the fifth case:
|
||||
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
|
||||
* GCC warns about duplicate declarations of the dummy function if
|
||||
-Wredundant_decls is used. GCC 4.3 and later have a builtin
|
||||
__COUNTER__ macro that can let us generate unique identifiers for
|
||||
each dummy function, to suppress this warning.
|
||||
|
||||
* This implementation exploits the fact that older versions of GCC,
|
||||
which do not support _Static_assert, also do not warn about the
|
||||
last declaration mentioned above.
|
||||
|
||||
* In C++, any struct definition inside sizeof is invalid.
|
||||
Use a template type to work around the problem. */
|
||||
|
||||
/* Concatenate two preprocessor tokens. */
|
||||
# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||
# define _GL_CONCAT0(x, y) x##y
|
||||
|
||||
/* _GL_COUNTER is an integer, preferably one that changes each time we
|
||||
use it. Use __COUNTER__ if it works, falling back on __LINE__
|
||||
otherwise. __LINE__ isn't perfect, but it's better than a
|
||||
constant. */
|
||||
# if defined __COUNTER__ && __COUNTER__ != __COUNTER__
|
||||
# define _GL_COUNTER __COUNTER__
|
||||
# else
|
||||
# define _GL_COUNTER __LINE__
|
||||
# endif
|
||||
|
||||
/* Generate a symbol with the given prefix, making it unique if
|
||||
possible. */
|
||||
# define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
|
||||
|
||||
/* Verify requirement R at compile-time, as an integer constant expression
|
||||
that returns 1. If R is false, fail at compile-time, preferably
|
||||
with a diagnostic that includes the string-literal DIAGNOSTIC. */
|
||||
|
||||
# define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
|
||||
(!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
|
||||
|
||||
# ifdef __cplusplus
|
||||
# if !GNULIB_defined_struct__gl_verify_type
|
||||
template <int w>
|
||||
struct _gl_verify_type {
|
||||
unsigned int _gl_verify_error_if_negative: w;
|
||||
};
|
||||
# define GNULIB_defined_struct__gl_verify_type 1
|
||||
# endif
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
_gl_verify_type<(R) ? 1 : -1>
|
||||
# elif defined _GL_HAVE__STATIC_ASSERT
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
struct { \
|
||||
_Static_assert (R, DIAGNOSTIC); \
|
||||
int _gl_dummy; \
|
||||
}
|
||||
# else
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
|
||||
# endif
|
||||
|
||||
/* Verify requirement R at compile-time, as a declaration without a
|
||||
trailing ';'. If R is false, fail at compile-time, preferably
|
||||
with a diagnostic that includes the string-literal DIAGNOSTIC.
|
||||
|
||||
Unfortunately, unlike C1X, this implementation must appear as an
|
||||
ordinary declaration, and cannot appear inside struct { ... }. */
|
||||
|
||||
# ifdef _GL_HAVE__STATIC_ASSERT
|
||||
# define _GL_VERIFY _Static_assert
|
||||
# else
|
||||
# define _GL_VERIFY(R, DIAGNOSTIC) \
|
||||
extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
|
||||
[_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
|
||||
# endif
|
||||
|
||||
/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
|
||||
# ifdef _GL_STATIC_ASSERT_H
|
||||
# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
|
||||
# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
|
||||
# endif
|
||||
# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
|
||||
# define static_assert _Static_assert /* Draft C1X requires this #define. */
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* @assert.h omit start@ */
|
||||
|
||||
/* Each of these macros verifies that its argument R is nonzero. To
|
||||
be portable, R should be an integer constant expression. Unlike
|
||||
assert (R), there is no run-time overhead.
|
||||
|
||||
There are two macros, since no single macro can be used in all
|
||||
contexts in C. verify_true (R) is for scalar contexts, including
|
||||
integer constant expression contexts. verify (R) is for declaration
|
||||
contexts, e.g., the top level. */
|
||||
|
||||
/* Verify requirement R at compile-time, as an integer constant expression.
|
||||
Return 1. This is equivalent to verify_expr (R, 1).
|
||||
|
||||
verify_true is obsolescent; please use verify_expr instead. */
|
||||
|
||||
# define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
|
||||
|
||||
/* Verify requirement R at compile-time. Return the value of the
|
||||
expression E. */
|
||||
|
||||
# define verify_expr(R, E) \
|
||||
(_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
|
||||
|
||||
/* Verify requirement R at compile-time, as a declaration without a
|
||||
trailing ';'. */
|
||||
|
||||
# define verify(R) _GL_VERIFY (R, "verify (" #R ")")
|
||||
|
||||
/* @assert.h omit end@ */
|
||||
|
||||
#endif
|
74
lib/vfprintf.c
Normal file
74
lib/vfprintf.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* Formatted output to a stream.
|
||||
Copyright (C) 2004, 2006-2011 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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#if 1
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "fseterr.h"
|
||||
#include "vasnprintf.h"
|
||||
|
||||
/* Print formatted output to the stream FP.
|
||||
Return string length of formatted string. On error, return a negative
|
||||
value. */
|
||||
int
|
||||
vfprintf (FILE *fp, const char *format, va_list args)
|
||||
{
|
||||
char buf[2000];
|
||||
char *output;
|
||||
size_t len;
|
||||
size_t lenbuf = sizeof (buf);
|
||||
|
||||
output = vasnprintf (buf, &lenbuf, format, args);
|
||||
len = lenbuf;
|
||||
|
||||
if (!output)
|
||||
{
|
||||
fseterr (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fwrite (output, 1, len, fp) < len)
|
||||
{
|
||||
if (output != buf)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (output);
|
||||
errno = saved_errno;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (output != buf)
|
||||
free (output);
|
||||
|
||||
if (len > INT_MAX)
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
fseterr (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
71
lib/vsnprintf.c
Normal file
71
lib/vsnprintf.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* Formatted output to strings.
|
||||
Copyright (C) 2004, 2006-2011 Free Software Foundation, Inc.
|
||||
Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>.
|
||||
|
||||
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 3, 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. */
|
||||
|
||||
#if 1
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vasnprintf.h"
|
||||
|
||||
/* 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;
|
||||
}
|
994
lib/wchar.in.h
Normal file
994
lib/wchar.in.h
Normal file
@ -0,0 +1,994 @@
|
||||
/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
|
||||
|
||||
Copyright (C) 2007-2011 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 3, 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 <wchar.h> for platforms that have issues.
|
||||
* <http://www.opengroup.org/susv3xbd/wchar.h.html>
|
||||
*
|
||||
* For now, this just ensures proper prerequisite inclusion order and
|
||||
* the declaration of wcwidth().
|
||||
*/
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
@PRAGMA_COLUMNS@
|
||||
|
||||
#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
|
||||
/* Special invocation convention:
|
||||
- Inside glibc and uClibc header files.
|
||||
- On HP-UX 11.00 we have a sequence of nested includes
|
||||
<wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
|
||||
once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
|
||||
and once directly. In both situations 'wint_t' is not yet defined,
|
||||
therefore we cannot provide the function overrides; instead include only
|
||||
the system's <wchar.h>.
|
||||
- On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
|
||||
the latter includes <wchar.h>. But here, we have no way to detect whether
|
||||
<wctype.h> is completely included or is still being included. */
|
||||
|
||||
#@INCLUDE_NEXT@ @NEXT_WCHAR_H@
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_WCHAR_H
|
||||
|
||||
#define _GL_ALREADY_INCLUDING_WCHAR_H
|
||||
|
||||
#if @HAVE_FEATURES_H@
|
||||
# include <features.h> /* for __GLIBC__ */
|
||||
#endif
|
||||
|
||||
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
|
||||
<wchar.h>.
|
||||
BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|
||||
included before <wchar.h>.
|
||||
In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
|
||||
by <stddef.h>.
|
||||
But avoid namespace pollution on glibc systems. */
|
||||
#if !(defined __GLIBC__ && !defined __UCLIBC__)
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
#ifndef __GLIBC__
|
||||
# include <stdio.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
/* Include the original <wchar.h> if it exists.
|
||||
Some builds of uClibc lack it. */
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#if @HAVE_WCHAR_H@
|
||||
# @INCLUDE_NEXT@ @NEXT_WCHAR_H@
|
||||
#endif
|
||||
|
||||
#undef _GL_ALREADY_INCLUDING_WCHAR_H
|
||||
|
||||
#ifndef _@GUARD_PREFIX@_WCHAR_H
|
||||
#define _@GUARD_PREFIX@_WCHAR_H
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
|
||||
|
||||
/* Define wint_t and WEOF. (Also done in wctype.in.h.) */
|
||||
#if !@HAVE_WINT_T@ && !defined wint_t
|
||||
# define wint_t int
|
||||
# ifndef WEOF
|
||||
# define WEOF -1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WEOF
|
||||
# define WEOF ((wint_t) -1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Override mbstate_t if it is too small.
|
||||
On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
|
||||
implementing mbrtowc for encodings like UTF-8. */
|
||||
#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
|
||||
# if !GNULIB_defined_mbstate_t
|
||||
typedef int rpl_mbstate_t;
|
||||
# undef mbstate_t
|
||||
# define mbstate_t rpl_mbstate_t
|
||||
# define GNULIB_defined_mbstate_t 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a single-byte character to a wide character. */
|
||||
#if @GNULIB_BTOWC@
|
||||
# if @REPLACE_BTOWC@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef btowc
|
||||
# define btowc rpl_btowc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (btowc, wint_t, (int c));
|
||||
_GL_CXXALIAS_RPL (btowc, wint_t, (int c));
|
||||
# else
|
||||
# if !@HAVE_BTOWC@
|
||||
_GL_FUNCDECL_SYS (btowc, wint_t, (int c));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (btowc);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef btowc
|
||||
# if HAVE_RAW_DECL_BTOWC
|
||||
_GL_WARN_ON_USE (btowc, "btowc is unportable - "
|
||||
"use gnulib module btowc for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a wide character to a single-byte character. */
|
||||
#if @GNULIB_WCTOB@
|
||||
# if @REPLACE_WCTOB@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wctob
|
||||
# define wctob rpl_wctob
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
|
||||
_GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
|
||||
# else
|
||||
# if !defined wctob && !@HAVE_DECL_WCTOB@
|
||||
/* wctob is provided by gnulib, or wctob exists but is not declared. */
|
||||
_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wctob);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wctob
|
||||
# if HAVE_RAW_DECL_WCTOB
|
||||
_GL_WARN_ON_USE (wctob, "wctob is unportable - "
|
||||
"use gnulib module wctob for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Test whether *PS is in the initial state. */
|
||||
#if @GNULIB_MBSINIT@
|
||||
# if @REPLACE_MBSINIT@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbsinit
|
||||
# define mbsinit rpl_mbsinit
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
|
||||
_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_MBSINIT@
|
||||
_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbsinit);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mbsinit
|
||||
# if HAVE_RAW_DECL_MBSINIT
|
||||
_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
|
||||
"use gnulib module mbsinit for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a multibyte character to a wide character. */
|
||||
#if @GNULIB_MBRTOWC@
|
||||
# if @REPLACE_MBRTOWC@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbrtowc
|
||||
# define mbrtowc rpl_mbrtowc
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbrtowc, size_t,
|
||||
(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
|
||||
_GL_CXXALIAS_RPL (mbrtowc, size_t,
|
||||
(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_MBRTOWC@
|
||||
_GL_FUNCDECL_SYS (mbrtowc, size_t,
|
||||
(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mbrtowc, size_t,
|
||||
(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbrtowc);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mbrtowc
|
||||
# if HAVE_RAW_DECL_MBRTOWC
|
||||
_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
|
||||
"use gnulib module mbrtowc for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Recognize a multibyte character. */
|
||||
#if @GNULIB_MBRLEN@
|
||||
# if @REPLACE_MBRLEN@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbrlen
|
||||
# define mbrlen rpl_mbrlen
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
|
||||
_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_MBRLEN@
|
||||
_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbrlen);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mbrlen
|
||||
# if HAVE_RAW_DECL_MBRLEN
|
||||
_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
|
||||
"use gnulib module mbrlen for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a string to a wide string. */
|
||||
#if @GNULIB_MBSRTOWCS@
|
||||
# if @REPLACE_MBSRTOWCS@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbsrtowcs
|
||||
# define mbsrtowcs rpl_mbsrtowcs
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t len,
|
||||
mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_MBSRTOWCS@
|
||||
_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t len,
|
||||
mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbsrtowcs);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mbsrtowcs
|
||||
# if HAVE_RAW_DECL_MBSRTOWCS
|
||||
_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
|
||||
"use gnulib module mbsrtowcs for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a string to a wide string. */
|
||||
#if @GNULIB_MBSNRTOWCS@
|
||||
# if @REPLACE_MBSNRTOWCS@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef mbsnrtowcs
|
||||
# define mbsnrtowcs rpl_mbsnrtowcs
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_MBSNRTOWCS@
|
||||
_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
|
||||
(wchar_t *dest, const char **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (mbsnrtowcs);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef mbsnrtowcs
|
||||
# if HAVE_RAW_DECL_MBSNRTOWCS
|
||||
_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
|
||||
"use gnulib module mbsnrtowcs for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a wide character to a multibyte character. */
|
||||
#if @GNULIB_WCRTOMB@
|
||||
# if @REPLACE_WCRTOMB@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcrtomb
|
||||
# define wcrtomb rpl_wcrtomb
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
|
||||
_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_WCRTOMB@
|
||||
_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcrtomb);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcrtomb
|
||||
# if HAVE_RAW_DECL_WCRTOMB
|
||||
_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
|
||||
"use gnulib module wcrtomb for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a wide string to a string. */
|
||||
#if @GNULIB_WCSRTOMBS@
|
||||
# if @REPLACE_WCSRTOMBS@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcsrtombs
|
||||
# define wcsrtombs rpl_wcsrtombs
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcsrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (wcsrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t len,
|
||||
mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_WCSRTOMBS@
|
||||
_GL_FUNCDECL_SYS (wcsrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t len,
|
||||
mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcsrtombs);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsrtombs
|
||||
# if HAVE_RAW_DECL_WCSRTOMBS
|
||||
_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
|
||||
"use gnulib module wcsrtombs for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert a wide string to a string. */
|
||||
#if @GNULIB_WCSNRTOMBS@
|
||||
# if @REPLACE_WCSNRTOMBS@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcsnrtombs
|
||||
# define wcsnrtombs rpl_wcsnrtombs
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps));
|
||||
# else
|
||||
# if !@HAVE_WCSNRTOMBS@
|
||||
_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
|
||||
(char *dest, const wchar_t **srcp, size_t srclen, size_t len,
|
||||
mbstate_t *ps));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcsnrtombs);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsnrtombs
|
||||
# if HAVE_RAW_DECL_WCSNRTOMBS
|
||||
_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
|
||||
"use gnulib module wcsnrtombs for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the number of screen columns needed for WC. */
|
||||
#if @GNULIB_WCWIDTH@
|
||||
# if @REPLACE_WCWIDTH@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcwidth
|
||||
# define wcwidth rpl_wcwidth
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
|
||||
_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
|
||||
# else
|
||||
# if !@HAVE_DECL_WCWIDTH@
|
||||
/* wcwidth exists but is not declared. */
|
||||
_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcwidth);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcwidth
|
||||
# if HAVE_RAW_DECL_WCWIDTH
|
||||
_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
|
||||
"use gnulib module wcwidth for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Search N wide characters of S for C. */
|
||||
#if @GNULIB_WMEMCHR@
|
||||
# if !@HAVE_WMEMCHR@
|
||||
_GL_FUNCDECL_SYS (wmemchr, wchar_t *, (const wchar_t *s, wchar_t c, size_t n));
|
||||
# endif
|
||||
/* On some systems, this function is defined as an overloaded function:
|
||||
extern "C++" {
|
||||
const wchar_t * std::wmemchr (const wchar_t *, wchar_t, size_t);
|
||||
wchar_t * std::wmemchr (wchar_t *, wchar_t, size_t);
|
||||
} */
|
||||
_GL_CXXALIAS_SYS_CAST2 (wmemchr,
|
||||
wchar_t *, (const wchar_t *, wchar_t, size_t),
|
||||
const wchar_t *, (const wchar_t *, wchar_t, size_t));
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
|
||||
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||
_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
|
||||
_GL_CXXALIASWARN1 (wmemchr, const wchar_t *,
|
||||
(const wchar_t *s, wchar_t c, size_t n));
|
||||
# else
|
||||
_GL_CXXALIASWARN (wmemchr);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wmemchr
|
||||
# if HAVE_RAW_DECL_WMEMCHR
|
||||
_GL_WARN_ON_USE (wmemchr, "wmemchr is unportable - "
|
||||
"use gnulib module wmemchr for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare N wide characters of S1 and S2. */
|
||||
#if @GNULIB_WMEMCMP@
|
||||
# if !@HAVE_WMEMCMP@
|
||||
_GL_FUNCDECL_SYS (wmemcmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wmemcmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
_GL_CXXALIASWARN (wmemcmp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wmemcmp
|
||||
# if HAVE_RAW_DECL_WMEMCMP
|
||||
_GL_WARN_ON_USE (wmemcmp, "wmemcmp is unportable - "
|
||||
"use gnulib module wmemcmp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy N wide characters of SRC to DEST. */
|
||||
#if @GNULIB_WMEMCPY@
|
||||
# if !@HAVE_WMEMCPY@
|
||||
_GL_FUNCDECL_SYS (wmemcpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wmemcpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
_GL_CXXALIASWARN (wmemcpy);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wmemcpy
|
||||
# if HAVE_RAW_DECL_WMEMCPY
|
||||
_GL_WARN_ON_USE (wmemcpy, "wmemcpy is unportable - "
|
||||
"use gnulib module wmemcpy for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for
|
||||
overlapping memory areas. */
|
||||
#if @GNULIB_WMEMMOVE@
|
||||
# if !@HAVE_WMEMMOVE@
|
||||
_GL_FUNCDECL_SYS (wmemmove, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wmemmove, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
_GL_CXXALIASWARN (wmemmove);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wmemmove
|
||||
# if HAVE_RAW_DECL_WMEMMOVE
|
||||
_GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - "
|
||||
"use gnulib module wmemmove for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Set N wide characters of S to C. */
|
||||
#if @GNULIB_WMEMSET@
|
||||
# if !@HAVE_WMEMSET@
|
||||
_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
|
||||
_GL_CXXALIASWARN (wmemset);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wmemset
|
||||
# if HAVE_RAW_DECL_WMEMSET
|
||||
_GL_WARN_ON_USE (wmemset, "wmemset is unportable - "
|
||||
"use gnulib module wmemset for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the number of wide characters in S. */
|
||||
#if @GNULIB_WCSLEN@
|
||||
# if !@HAVE_WCSLEN@
|
||||
_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s));
|
||||
_GL_CXXALIASWARN (wcslen);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcslen
|
||||
# if HAVE_RAW_DECL_WCSLEN
|
||||
_GL_WARN_ON_USE (wcslen, "wcslen is unportable - "
|
||||
"use gnulib module wcslen for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the number of wide characters in S, but at most MAXLEN. */
|
||||
#if @GNULIB_WCSNLEN@
|
||||
# if !@HAVE_WCSNLEN@
|
||||
_GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen));
|
||||
_GL_CXXALIASWARN (wcsnlen);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsnlen
|
||||
# if HAVE_RAW_DECL_WCSNLEN
|
||||
_GL_WARN_ON_USE (wcsnlen, "wcsnlen is unportable - "
|
||||
"use gnulib module wcsnlen for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy SRC to DEST. */
|
||||
#if @GNULIB_WCSCPY@
|
||||
# if !@HAVE_WCSCPY@
|
||||
_GL_FUNCDECL_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
_GL_CXXALIASWARN (wcscpy);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscpy
|
||||
# if HAVE_RAW_DECL_WCSCPY
|
||||
_GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - "
|
||||
"use gnulib module wcscpy for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */
|
||||
#if @GNULIB_WCPCPY@
|
||||
# if !@HAVE_WCPCPY@
|
||||
_GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
_GL_CXXALIASWARN (wcpcpy);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcpcpy
|
||||
# if HAVE_RAW_DECL_WCPCPY
|
||||
_GL_WARN_ON_USE (wcpcpy, "wcpcpy is unportable - "
|
||||
"use gnulib module wcpcpy for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy no more than N wide characters of SRC to DEST. */
|
||||
#if @GNULIB_WCSNCPY@
|
||||
# if !@HAVE_WCSNCPY@
|
||||
_GL_FUNCDECL_SYS (wcsncpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsncpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
_GL_CXXALIASWARN (wcsncpy);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsncpy
|
||||
# if HAVE_RAW_DECL_WCSNCPY
|
||||
_GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - "
|
||||
"use gnulib module wcsncpy for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy no more than N characters of SRC to DEST, returning the address of
|
||||
the last character written into DEST. */
|
||||
#if @GNULIB_WCPNCPY@
|
||||
# if !@HAVE_WCPNCPY@
|
||||
_GL_FUNCDECL_SYS (wcpncpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcpncpy, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
_GL_CXXALIASWARN (wcpncpy);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcpncpy
|
||||
# if HAVE_RAW_DECL_WCPNCPY
|
||||
_GL_WARN_ON_USE (wcpncpy, "wcpncpy is unportable - "
|
||||
"use gnulib module wcpncpy for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Append SRC onto DEST. */
|
||||
#if @GNULIB_WCSCAT@
|
||||
# if !@HAVE_WCSCAT@
|
||||
_GL_FUNCDECL_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src));
|
||||
_GL_CXXALIASWARN (wcscat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscat
|
||||
# if HAVE_RAW_DECL_WCSCAT
|
||||
_GL_WARN_ON_USE (wcscat, "wcscat is unportable - "
|
||||
"use gnulib module wcscat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Append no more than N wide characters of SRC onto DEST. */
|
||||
#if @GNULIB_WCSNCAT@
|
||||
# if !@HAVE_WCSNCAT@
|
||||
_GL_FUNCDECL_SYS (wcsncat, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsncat, wchar_t *,
|
||||
(wchar_t *dest, const wchar_t *src, size_t n));
|
||||
_GL_CXXALIASWARN (wcsncat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsncat
|
||||
# if HAVE_RAW_DECL_WCSNCAT
|
||||
_GL_WARN_ON_USE (wcsncat, "wcsncat is unportable - "
|
||||
"use gnulib module wcsncat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare S1 and S2. */
|
||||
#if @GNULIB_WCSCMP@
|
||||
# if !@HAVE_WCSCMP@
|
||||
_GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
_GL_CXXALIASWARN (wcscmp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscmp
|
||||
# if HAVE_RAW_DECL_WCSCMP
|
||||
_GL_WARN_ON_USE (wcscmp, "wcscmp is unportable - "
|
||||
"use gnulib module wcscmp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare no more than N wide characters of S1 and S2. */
|
||||
#if @GNULIB_WCSNCMP@
|
||||
# if !@HAVE_WCSNCMP@
|
||||
_GL_FUNCDECL_SYS (wcsncmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsncmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
_GL_CXXALIASWARN (wcsncmp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsncmp
|
||||
# if HAVE_RAW_DECL_WCSNCMP
|
||||
_GL_WARN_ON_USE (wcsncmp, "wcsncmp is unportable - "
|
||||
"use gnulib module wcsncmp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare S1 and S2, ignoring case. */
|
||||
#if @GNULIB_WCSCASECMP@
|
||||
# if !@HAVE_WCSCASECMP@
|
||||
_GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
_GL_CXXALIASWARN (wcscasecmp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscasecmp
|
||||
# if HAVE_RAW_DECL_WCSCASECMP
|
||||
_GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - "
|
||||
"use gnulib module wcscasecmp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare no more than N chars of S1 and S2, ignoring case. */
|
||||
#if @GNULIB_WCSNCASECMP@
|
||||
# if !@HAVE_WCSNCASECMP@
|
||||
_GL_FUNCDECL_SYS (wcsncasecmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsncasecmp, int,
|
||||
(const wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
_GL_CXXALIASWARN (wcsncasecmp);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsncasecmp
|
||||
# if HAVE_RAW_DECL_WCSNCASECMP
|
||||
_GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - "
|
||||
"use gnulib module wcsncasecmp for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE
|
||||
category of the current locale. */
|
||||
#if @GNULIB_WCSCOLL@
|
||||
# if !@HAVE_WCSCOLL@
|
||||
_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
|
||||
_GL_CXXALIASWARN (wcscoll);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscoll
|
||||
# if HAVE_RAW_DECL_WCSCOLL
|
||||
_GL_WARN_ON_USE (wcscoll, "wcscoll is unportable - "
|
||||
"use gnulib module wcscoll for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Transform S2 into array pointed to by S1 such that if wcscmp is applied
|
||||
to two transformed strings the result is the as applying 'wcscoll' to the
|
||||
original strings. */
|
||||
#if @GNULIB_WCSXFRM@
|
||||
# if !@HAVE_WCSXFRM@
|
||||
_GL_FUNCDECL_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n));
|
||||
_GL_CXXALIASWARN (wcsxfrm);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsxfrm
|
||||
# if HAVE_RAW_DECL_WCSXFRM
|
||||
_GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - "
|
||||
"use gnulib module wcsxfrm for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Duplicate S, returning an identical malloc'd string. */
|
||||
#if @GNULIB_WCSDUP@
|
||||
# if !@HAVE_WCSDUP@
|
||||
_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
|
||||
_GL_CXXALIASWARN (wcsdup);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsdup
|
||||
# if HAVE_RAW_DECL_WCSDUP
|
||||
_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - "
|
||||
"use gnulib module wcsdup for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Find the first occurrence of WC in WCS. */
|
||||
#if @GNULIB_WCSCHR@
|
||||
# if !@HAVE_WCSCHR@
|
||||
_GL_FUNCDECL_SYS (wcschr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
|
||||
# endif
|
||||
/* On some systems, this function is defined as an overloaded function:
|
||||
extern "C++" {
|
||||
const wchar_t * std::wcschr (const wchar_t *, wchar_t);
|
||||
wchar_t * std::wcschr (wchar_t *, wchar_t);
|
||||
} */
|
||||
_GL_CXXALIAS_SYS_CAST2 (wcschr,
|
||||
wchar_t *, (const wchar_t *, wchar_t),
|
||||
const wchar_t *, (const wchar_t *, wchar_t));
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
|
||||
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||
_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc));
|
||||
_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
|
||||
# else
|
||||
_GL_CXXALIASWARN (wcschr);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcschr
|
||||
# if HAVE_RAW_DECL_WCSCHR
|
||||
_GL_WARN_ON_USE (wcschr, "wcschr is unportable - "
|
||||
"use gnulib module wcschr for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Find the last occurrence of WC in WCS. */
|
||||
#if @GNULIB_WCSRCHR@
|
||||
# if !@HAVE_WCSRCHR@
|
||||
_GL_FUNCDECL_SYS (wcsrchr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
|
||||
# endif
|
||||
/* On some systems, this function is defined as an overloaded function:
|
||||
extern "C++" {
|
||||
const wchar_t * std::wcsrchr (const wchar_t *, wchar_t);
|
||||
wchar_t * std::wcsrchr (wchar_t *, wchar_t);
|
||||
} */
|
||||
_GL_CXXALIAS_SYS_CAST2 (wcsrchr,
|
||||
wchar_t *, (const wchar_t *, wchar_t),
|
||||
const wchar_t *, (const wchar_t *, wchar_t));
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
|
||||
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||
_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc));
|
||||
_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
|
||||
# else
|
||||
_GL_CXXALIASWARN (wcsrchr);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsrchr
|
||||
# if HAVE_RAW_DECL_WCSRCHR
|
||||
_GL_WARN_ON_USE (wcsrchr, "wcsrchr is unportable - "
|
||||
"use gnulib module wcsrchr for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the length of the initial segmet of WCS which consists entirely
|
||||
of wide characters not in REJECT. */
|
||||
#if @GNULIB_WCSCSPN@
|
||||
# if !@HAVE_WCSCSPN@
|
||||
_GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
|
||||
_GL_CXXALIASWARN (wcscspn);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcscspn
|
||||
# if HAVE_RAW_DECL_WCSCSPN
|
||||
_GL_WARN_ON_USE (wcscspn, "wcscspn is unportable - "
|
||||
"use gnulib module wcscspn for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the length of the initial segmet of WCS which consists entirely
|
||||
of wide characters in ACCEPT. */
|
||||
#if @GNULIB_WCSSPN@
|
||||
# if !@HAVE_WCSSPN@
|
||||
_GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
|
||||
_GL_CXXALIASWARN (wcsspn);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsspn
|
||||
# if HAVE_RAW_DECL_WCSSPN
|
||||
_GL_WARN_ON_USE (wcsspn, "wcsspn is unportable - "
|
||||
"use gnulib module wcsspn for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Find the first occurrence in WCS of any character in ACCEPT. */
|
||||
#if @GNULIB_WCSPBRK@
|
||||
# if !@HAVE_WCSPBRK@
|
||||
_GL_FUNCDECL_SYS (wcspbrk, wchar_t *,
|
||||
(const wchar_t *wcs, const wchar_t *accept));
|
||||
# endif
|
||||
/* On some systems, this function is defined as an overloaded function:
|
||||
extern "C++" {
|
||||
const wchar_t * std::wcspbrk (const wchar_t *, const wchar_t *);
|
||||
wchar_t * std::wcspbrk (wchar_t *, const wchar_t *);
|
||||
} */
|
||||
_GL_CXXALIAS_SYS_CAST2 (wcspbrk,
|
||||
wchar_t *, (const wchar_t *, const wchar_t *),
|
||||
const wchar_t *, (const wchar_t *, const wchar_t *));
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
|
||||
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||
_GL_CXXALIASWARN1 (wcspbrk, wchar_t *,
|
||||
(wchar_t *wcs, const wchar_t *accept));
|
||||
_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *,
|
||||
(const wchar_t *wcs, const wchar_t *accept));
|
||||
# else
|
||||
_GL_CXXALIASWARN (wcspbrk);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcspbrk
|
||||
# if HAVE_RAW_DECL_WCSPBRK
|
||||
_GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - "
|
||||
"use gnulib module wcspbrk for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Find the first occurrence of NEEDLE in HAYSTACK. */
|
||||
#if @GNULIB_WCSSTR@
|
||||
# if !@HAVE_WCSSTR@
|
||||
_GL_FUNCDECL_SYS (wcsstr, wchar_t *,
|
||||
(const wchar_t *haystack, const wchar_t *needle));
|
||||
# endif
|
||||
/* On some systems, this function is defined as an overloaded function:
|
||||
extern "C++" {
|
||||
const wchar_t * std::wcsstr (const wchar_t *, const wchar_t *);
|
||||
wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
|
||||
} */
|
||||
_GL_CXXALIAS_SYS_CAST2 (wcsstr,
|
||||
wchar_t *, (const wchar_t *, const wchar_t *),
|
||||
const wchar_t *, (const wchar_t *, const wchar_t *));
|
||||
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
|
||||
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||
_GL_CXXALIASWARN1 (wcsstr, wchar_t *,
|
||||
(wchar_t *haystack, const wchar_t *needle));
|
||||
_GL_CXXALIASWARN1 (wcsstr, const wchar_t *,
|
||||
(const wchar_t *haystack, const wchar_t *needle));
|
||||
# else
|
||||
_GL_CXXALIASWARN (wcsstr);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcsstr
|
||||
# if HAVE_RAW_DECL_WCSSTR
|
||||
_GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
|
||||
"use gnulib module wcsstr for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Divide WCS into tokens separated by characters in DELIM. */
|
||||
#if @GNULIB_WCSTOK@
|
||||
# if !@HAVE_WCSTOK@
|
||||
_GL_FUNCDECL_SYS (wcstok, wchar_t *,
|
||||
(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcstok, wchar_t *,
|
||||
(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
|
||||
_GL_CXXALIASWARN (wcstok);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcstok
|
||||
# if HAVE_RAW_DECL_WCSTOK
|
||||
_GL_WARN_ON_USE (wcstok, "wcstok is unportable - "
|
||||
"use gnulib module wcstok for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine number of column positions required for first N wide
|
||||
characters (or fewer if S ends before this) in S. */
|
||||
#if @GNULIB_WCSWIDTH@
|
||||
# if @REPLACE_WCSWIDTH@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef wcswidth
|
||||
# define wcswidth rpl_wcswidth
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (wcswidth, int, (const wchar_t *s, size_t n));
|
||||
_GL_CXXALIAS_RPL (wcswidth, int, (const wchar_t *s, size_t n));
|
||||
# else
|
||||
# if !@HAVE_WCSWIDTH@
|
||||
_GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (wcswidth);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef wcswidth
|
||||
# if HAVE_RAW_DECL_WCSWIDTH
|
||||
_GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
|
||||
"use gnulib module wcswidth for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _@GUARD_PREFIX@_WCHAR_H */
|
||||
#endif /* _@GUARD_PREFIX@_WCHAR_H */
|
||||
#endif
|
108
lib/xsize.h
Normal file
108
lib/xsize.h
Normal file
@ -0,0 +1,108 @@
|
||||
/* xsize.h -- Checked size_t computations.
|
||||
|
||||
Copyright (C) 2003, 2008-2011 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 3, 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 <stddef.h>
|
||||
|
||||
/* Get SIZE_MAX. */
|
||||
#include <limits.h>
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#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 type 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 */
|
69
m4/.gitignore
vendored
69
m4/.gitignore
vendored
@ -1,69 +0,0 @@
|
||||
00gnulib.m4
|
||||
alloca.m4
|
||||
asm-underscore.m4
|
||||
assert.m4
|
||||
config-h.m4
|
||||
ctype.m4
|
||||
errno_h.m4
|
||||
exponentd.m4
|
||||
exponentf.m4
|
||||
exponentl.m4
|
||||
extensions.m4
|
||||
float_h.m4
|
||||
fpieee.m4
|
||||
fprintf-posix.m4
|
||||
frexp.m4
|
||||
frexpl.m4
|
||||
getopt.m4
|
||||
gettimeofday.m4
|
||||
gnulib-common.m4
|
||||
gnulib-comp.m4
|
||||
gnulib-tool.m4
|
||||
include_next.m4
|
||||
intmax_t.m4
|
||||
inttypes_h.m4
|
||||
isnand.m4
|
||||
isnanf.m4
|
||||
isnanl.m4
|
||||
ldexpl.m4
|
||||
locale_h.m4
|
||||
longlong.m4
|
||||
malloc.m4
|
||||
math_h.m4
|
||||
memchr.m4
|
||||
mmap-anon.m4
|
||||
multiarch.m4
|
||||
nocrash.m4
|
||||
printf.m4
|
||||
printf-frexp.m4
|
||||
printf-frexpl.m4
|
||||
printf-posix-rpl.m4
|
||||
signbit.m4
|
||||
size_max.m4
|
||||
snprintf.m4
|
||||
snprintf-posix.m4
|
||||
stat.m4
|
||||
stdarg.m4
|
||||
stdbool.m4
|
||||
stddef_h.m4
|
||||
stdint.m4
|
||||
stdint_h.m4
|
||||
stdio_h.m4
|
||||
stdlib_h.m4
|
||||
strdup.m4
|
||||
string_h.m4
|
||||
strncat.m4
|
||||
strstr.m4
|
||||
sys_stat_h.m4
|
||||
sys_time_h.m4
|
||||
time_h.m4
|
||||
unistd_h.m4
|
||||
vasnprintf.m4
|
||||
vfprintf-posix.m4
|
||||
vsnprintf.m4
|
||||
vsnprintf-posix.m4
|
||||
warn-on-use.m4
|
||||
wchar_h.m4
|
||||
wchar_t.m4
|
||||
wint_t.m4
|
||||
xsize.m4
|
30
m4/00gnulib.m4
Normal file
30
m4/00gnulib.m4
Normal file
@ -0,0 +1,30 @@
|
||||
# 00gnulib.m4 serial 2
|
||||
dnl Copyright (C) 2009-2011 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 This file must be named something that sorts before all other
|
||||
dnl gnulib-provided .m4 files. It is needed until such time as we can
|
||||
dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics.
|
||||
|
||||
# AC_DEFUN_ONCE([NAME], VALUE)
|
||||
# ----------------------------
|
||||
# Define NAME to expand to VALUE on the first use (whether by direct
|
||||
# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses.
|
||||
# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This
|
||||
# definition is slower than the version in Autoconf 2.64, because it
|
||||
# can only use interfaces that existed since 2.59; but it achieves the
|
||||
# same effect. Quoting is necessary to avoid confusing Automake.
|
||||
m4_version_prereq([2.63.263], [],
|
||||
[m4_define([AC][_DEFUN_ONCE],
|
||||
[AC][_DEFUN([$1],
|
||||
[AC_REQUIRE([_gl_DEFUN_ONCE([$1])],
|
||||
[m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl
|
||||
[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])])
|
||||
|
||||
# gl_00GNULIB
|
||||
# -----------
|
||||
# Witness macro that this file has been included. Needed to force
|
||||
# Automake to include this file prior to all other gnulib .m4 files.
|
||||
AC_DEFUN([gl_00GNULIB])
|
1079
m4/Makefile.in
Normal file
1079
m4/Makefile.in
Normal file
File diff suppressed because it is too large
Load Diff
121
m4/alloca.m4
Normal file
121
m4/alloca.m4
Normal file
@ -0,0 +1,121 @@
|
||||
# alloca.m4 serial 13
|
||||
dnl Copyright (C) 2002-2004, 2006-2007, 2009-2011 Free Software Foundation,
|
||||
dnl 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_ALLOCA],
|
||||
[
|
||||
AC_REQUIRE([AC_FUNC_ALLOCA])
|
||||
if test $ac_cv_func_alloca_works = no; then
|
||||
gl_PREREQ_ALLOCA
|
||||
fi
|
||||
|
||||
# Define an additional variable used in the Makefile substitution.
|
||||
if test $ac_cv_working_alloca_h = yes; then
|
||||
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
|
||||
#endif
|
||||
], [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 <alloca.h>,
|
||||
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
|
||||
AC_SUBST([ALLOCA_H])
|
||||
AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"])
|
||||
])
|
||||
|
||||
# Prerequisites of lib/alloca.c.
|
||||
# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
|
||||
AC_DEFUN([gl_PREREQ_ALLOCA], [:])
|
||||
|
||||
# This works around a bug in autoconf <= 2.68.
|
||||
# See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>.
|
||||
|
||||
m4_version_prereq([2.69], [] ,[
|
||||
|
||||
# This is taken from the following Autoconf patch:
|
||||
# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
|
||||
|
||||
# _AC_LIBOBJ_ALLOCA
|
||||
# -----------------
|
||||
# Set up the LIBOBJ replacement of `alloca'. Well, not exactly
|
||||
# AC_LIBOBJ since we actually set the output variable `ALLOCA'.
|
||||
# Nevertheless, for Automake, AC_LIBSOURCES it.
|
||||
m4_define([_AC_LIBOBJ_ALLOCA],
|
||||
[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
|
||||
# that cause trouble. Some versions do not even contain alloca or
|
||||
# contain a buggy version. If you still want to use their alloca,
|
||||
# use ar to extract alloca.o from them instead of compiling alloca.c.
|
||||
AC_LIBSOURCES(alloca.c)
|
||||
AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
|
||||
AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.])
|
||||
|
||||
AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray,
|
||||
[AC_EGREP_CPP(webecray,
|
||||
[#if defined CRAY && ! defined CRAY2
|
||||
webecray
|
||||
#else
|
||||
wenotbecray
|
||||
#endif
|
||||
], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
|
||||
if test $ac_cv_os_cray = yes; then
|
||||
for ac_func in _getb67 GETB67 getb67; do
|
||||
AC_CHECK_FUNC($ac_func,
|
||||
[AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
|
||||
[Define to one of `_getb67', `GETB67',
|
||||
`getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for
|
||||
`alloca.c' support on those systems.])
|
||||
break])
|
||||
done
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([stack direction for C alloca],
|
||||
[ac_cv_c_stack_direction],
|
||||
[AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[AC_INCLUDES_DEFAULT
|
||||
int
|
||||
find_stack_direction (int *addr, int depth)
|
||||
{
|
||||
int dir, dummy = 0;
|
||||
if (! addr)
|
||||
addr = &dummy;
|
||||
*addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
|
||||
dir = depth ? find_stack_direction (addr, depth - 1) : 0;
|
||||
return dir + dummy;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
return find_stack_direction (0, argc + !argv + 20) < 0;
|
||||
}])],
|
||||
[ac_cv_c_stack_direction=1],
|
||||
[ac_cv_c_stack_direction=-1],
|
||||
[ac_cv_c_stack_direction=0])])
|
||||
AH_VERBATIM([STACK_DIRECTION],
|
||||
[/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at runtime.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
@%:@undef STACK_DIRECTION])dnl
|
||||
AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
|
||||
])# _AC_LIBOBJ_ALLOCA
|
||||
])
|
48
m4/asm-underscore.m4
Normal file
48
m4/asm-underscore.m4
Normal file
@ -0,0 +1,48 @@
|
||||
# asm-underscore.m4 serial 1
|
||||
dnl Copyright (C) 2010-2011 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. Based on as-underscore.m4 in GNU clisp.
|
||||
|
||||
# gl_ASM_SYMBOL_PREFIX
|
||||
# Tests for the prefix of C symbols at the assembly language level and the
|
||||
# linker level. This prefix is either an underscore or empty. Defines the
|
||||
# C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to
|
||||
# a stringified variant of this prefix.
|
||||
|
||||
AC_DEFUN([gl_ASM_SYMBOL_PREFIX],
|
||||
[
|
||||
dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because
|
||||
dnl 1. It works only for GCC.
|
||||
dnl 2. It is incorrectly defined on some platforms, in some GCC versions.
|
||||
AC_CACHE_CHECK(
|
||||
[whether C symbols are prefixed with underscore at the linker level],
|
||||
[gl_cv_prog_as_underscore],
|
||||
[cat > conftest.c <<EOF
|
||||
#ifdef __cplusplus
|
||||
extern "C" int foo (void);
|
||||
#endif
|
||||
int foo(void) { return 0; }
|
||||
EOF
|
||||
# Look for the assembly language name in the .s file.
|
||||
AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -S conftest.c) >/dev/null 2>&1
|
||||
if grep _foo conftest.s >/dev/null ; then
|
||||
gl_cv_prog_as_underscore=yes
|
||||
else
|
||||
gl_cv_prog_as_underscore=no
|
||||
fi
|
||||
rm -f conftest*
|
||||
])
|
||||
if test $gl_cv_prog_as_underscore = yes; then
|
||||
USER_LABEL_PREFIX=_
|
||||
else
|
||||
USER_LABEL_PREFIX=
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX],
|
||||
[Define to the prefix of C symbols at the assembler and linker level,
|
||||
either an underscore or empty.])
|
||||
ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
|
||||
AC_SUBST([ASM_SYMBOL_PREFIX])
|
||||
])
|
24
m4/assert.m4
Normal file
24
m4/assert.m4
Normal file
@ -0,0 +1,24 @@
|
||||
#serial 7
|
||||
|
||||
# Copyright (C) 1998-1999, 2001, 2004, 2008-2011 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 based on code from Eleftherios Gkioulekas
|
||||
dnl Autoconf 2.60 provides AC_HEADER_ASSERT for the same purpose, but
|
||||
dnl it has broken semantics for --enable-assert until 2.64.
|
||||
AC_DEFUN([gl_ASSERT],
|
||||
[
|
||||
AC_MSG_CHECKING([whether to enable assertions])
|
||||
AC_ARG_ENABLE([assert],
|
||||
[AS_HELP_STRING([--disable-assert], [turn off assertions])],
|
||||
[AS_IF([test "x$enableval" = xno],
|
||||
[AC_DEFINE([NDEBUG], [1],
|
||||
[Define to 1 if assertions should be disabled.])],
|
||||
[test "x$enableval" != xyes],
|
||||
[AC_MSG_WARN([invalid argument supplied to --enable-assert])
|
||||
enable_assert=yes])],
|
||||
[enable_assert=yes])
|
||||
AC_MSG_RESULT([$enable_assert])
|
||||
])
|
13
m4/config-h.m4
Normal file
13
m4/config-h.m4
Normal file
@ -0,0 +1,13 @@
|
||||
# Say that -DHAVE_CONFIG_H is not needed.
|
||||
|
||||
dnl Copyright (C) 2006, 2009-2011 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.
|
||||
|
||||
# This package's source files all include config.h unconditionally,
|
||||
# so there's no need to pass -DHAVE_CONFIG_H to the compiler.
|
||||
AC_DEFUN([gl_CONFIG_H],
|
||||
[AC_CONFIG_COMMANDS_PRE([test "X$DEFS" = X-DHAVE_CONFIG_H && DEFS=])])
|
32
m4/ctype.m4
Normal file
32
m4/ctype.m4
Normal file
@ -0,0 +1,32 @@
|
||||
# ctype_h.m4 serial 6
|
||||
dnl Copyright (C) 2009-2011 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_CTYPE_H],
|
||||
[
|
||||
AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
|
||||
|
||||
dnl <ctype.h> is always overridden, because of GNULIB_POSIXCHECK.
|
||||
gl_NEXT_HEADERS([ctype.h])
|
||||
|
||||
dnl Check for declarations of anything we want to poison if the
|
||||
dnl corresponding gnulib module is not in use.
|
||||
gl_WARN_ON_USE_PREPARE([[#include <ctype.h>
|
||||
]], [isblank])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_CTYPE_MODULE_INDICATOR],
|
||||
[
|
||||
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
|
||||
AC_REQUIRE([gl_CTYPE_H_DEFAULTS])
|
||||
gl_MODULE_INDICATOR_SET_VARIABLE([$1])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_CTYPE_H_DEFAULTS],
|
||||
[
|
||||
GNULIB_ISBLANK=0; AC_SUBST([GNULIB_ISBLANK])
|
||||
dnl Assume proper GNU behavior unless another module says otherwise.
|
||||
HAVE_ISBLANK=1; AC_SUBST([HAVE_ISBLANK])
|
||||
])
|
119
m4/errno_h.m4
Normal file
119
m4/errno_h.m4
Normal file
@ -0,0 +1,119 @@
|
||||
# errno_h.m4 serial 9
|
||||
dnl Copyright (C) 2004, 2006, 2008-2011 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_ONCE([gl_HEADER_ERRNO_H],
|
||||
[
|
||||
AC_REQUIRE([AC_PROG_CC])
|
||||
AC_CACHE_CHECK([for complete errno.h], [gl_cv_header_errno_h_complete], [
|
||||
AC_EGREP_CPP([booboo],[
|
||||
#include <errno.h>
|
||||
#if !defined ENOMSG
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EIDRM
|
||||
booboo
|
||||
#endif
|
||||
#if !defined ENOLINK
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EPROTO
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EMULTIHOP
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EBADMSG
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EOVERFLOW
|
||||
booboo
|
||||
#endif
|
||||
#if !defined ENOTSUP
|
||||
booboo
|
||||
#endif
|
||||
#if !defined ESTALE
|
||||
booboo
|
||||
#endif
|
||||
#if !defined EDQUOT
|
||||
booboo
|
||||
#endif
|
||||
#if !defined ECANCELED
|
||||
booboo
|
||||
#endif
|
||||
],
|
||||
[gl_cv_header_errno_h_complete=no],
|
||||
[gl_cv_header_errno_h_complete=yes])
|
||||
])
|
||||
if test $gl_cv_header_errno_h_complete = yes; then
|
||||
ERRNO_H=''
|
||||
else
|
||||
gl_NEXT_HEADERS([errno.h])
|
||||
ERRNO_H='errno.h'
|
||||
fi
|
||||
AC_SUBST([ERRNO_H])
|
||||
AM_CONDITIONAL([GL_GENERATE_ERRNO_H], [test -n "$ERRNO_H"])
|
||||
gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
|
||||
gl_REPLACE_ERRNO_VALUE([ENOLINK])
|
||||
gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
|
||||
])
|
||||
|
||||
# Assuming $1 = EOVERFLOW.
|
||||
# The EOVERFLOW errno value ought to be defined in <errno.h>, according to
|
||||
# POSIX. But some systems (like OpenBSD 4.0 or AIX 3) don't define it, and
|
||||
# some systems (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined.
|
||||
# Check for the value of EOVERFLOW.
|
||||
# Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE.
|
||||
AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
|
||||
[
|
||||
if test -n "$ERRNO_H"; then
|
||||
AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
|
||||
AC_EGREP_CPP([yes],[
|
||||
#include <errno.h>
|
||||
#ifdef ]$1[
|
||||
yes
|
||||
#endif
|
||||
],
|
||||
[gl_cv_header_errno_h_]$1[=yes],
|
||||
[gl_cv_header_errno_h_]$1[=no])
|
||||
if test $gl_cv_header_errno_h_]$1[ = no; then
|
||||
AC_EGREP_CPP([yes],[
|
||||
#define _XOPEN_SOURCE_EXTENDED 1
|
||||
#include <errno.h>
|
||||
#ifdef ]$1[
|
||||
yes
|
||||
#endif
|
||||
], [gl_cv_header_errno_h_]$1[=hidden])
|
||||
if test $gl_cv_header_errno_h_]$1[ = hidden; then
|
||||
dnl The macro exists but is hidden.
|
||||
dnl Define it to the same value.
|
||||
AC_COMPUTE_INT([gl_cv_header_errno_h_]$1, $1, [
|
||||
#define _XOPEN_SOURCE_EXTENDED 1
|
||||
#include <errno.h>
|
||||
/* The following two lines are a workaround against an autoconf-2.52 bug. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
])
|
||||
fi
|
||||
fi
|
||||
])
|
||||
case $gl_cv_header_errno_h_]$1[ in
|
||||
yes | no)
|
||||
]$1[_HIDDEN=0; ]$1[_VALUE=
|
||||
;;
|
||||
*)
|
||||
]$1[_HIDDEN=1; ]$1[_VALUE="$gl_cv_header_errno_h_]$1["
|
||||
;;
|
||||
esac
|
||||
AC_SUBST($1[_HIDDEN])
|
||||
AC_SUBST($1[_VALUE])
|
||||
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])])
|
||||
])
|
115
m4/exponentd.m4
Normal file
115
m4/exponentd.m4
Normal file
@ -0,0 +1,115 @@
|
||||
# exponentd.m4 serial 2
|
||||
dnl Copyright (C) 2007-2008, 2010-2011 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_EXPONENT_LOCATION],
|
||||
[
|
||||
AC_CACHE_CHECK([where to find the exponent in a 'double'],
|
||||
[gl_cv_cc_double_expbit0],
|
||||
[
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE([[
|
||||
#include <float.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define NWORDS \
|
||||
((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
typedef union { double value; unsigned int word[NWORDS]; } memory_double;
|
||||
static unsigned int ored_words[NWORDS];
|
||||
static unsigned int anded_words[NWORDS];
|
||||
static void add_to_ored_words (double x)
|
||||
{
|
||||
memory_double m;
|
||||
size_t i;
|
||||
/* Clear it first, in case sizeof (double) < sizeof (memory_double). */
|
||||
memset (&m, 0, sizeof (memory_double));
|
||||
m.value = x;
|
||||
for (i = 0; i < NWORDS; i++)
|
||||
{
|
||||
ored_words[i] |= m.word[i];
|
||||
anded_words[i] &= m.word[i];
|
||||
}
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
size_t j;
|
||||
FILE *fp = fopen ("conftest.out", "w");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
anded_words[j] = ~ (unsigned int) 0;
|
||||
add_to_ored_words (0.25);
|
||||
add_to_ored_words (0.5);
|
||||
add_to_ored_words (1.0);
|
||||
add_to_ored_words (2.0);
|
||||
add_to_ored_words (4.0);
|
||||
/* Remove bits that are common (e.g. if representation of the first mantissa
|
||||
bit is explicit). */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
ored_words[j] &= ~anded_words[j];
|
||||
/* Now find the nonzero word. */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
if (ored_words[j] != 0)
|
||||
break;
|
||||
if (j < NWORDS)
|
||||
{
|
||||
size_t i;
|
||||
for (i = j + 1; i < NWORDS; i++)
|
||||
if (ored_words[i] != 0)
|
||||
{
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
for (i = 0; ; i++)
|
||||
if ((ored_words[j] >> i) & 1)
|
||||
{
|
||||
fprintf (fp, "word %d bit %d", (int) j, (int) i);
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
}
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
]])],
|
||||
[gl_cv_cc_double_expbit0=`cat conftest.out`],
|
||||
[gl_cv_cc_double_expbit0="unknown"],
|
||||
[
|
||||
dnl On ARM, there are two 'double' floating-point formats, used by
|
||||
dnl different sets of instructions: The older FPA instructions assume
|
||||
dnl that they are stored in big-endian word order, while the words
|
||||
dnl (like integer types) are stored in little-endian byte order.
|
||||
dnl The newer VFP instructions assume little-endian order consistenly.
|
||||
AC_EGREP_CPP([mixed_endianness], [
|
||||
#if defined arm || defined __arm || defined __arm__
|
||||
mixed_endianness
|
||||
#endif
|
||||
],
|
||||
[gl_cv_cc_double_expbit0="unknown"],
|
||||
[
|
||||
pushdef([AC_MSG_CHECKING],[:])dnl
|
||||
pushdef([AC_MSG_RESULT],[:])dnl
|
||||
pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
|
||||
AC_C_BIGENDIAN(
|
||||
[gl_cv_cc_double_expbit0="word 0 bit 20"],
|
||||
[gl_cv_cc_double_expbit0="word 1 bit 20"],
|
||||
[gl_cv_cc_double_expbit0="unknown"])
|
||||
popdef([AC_MSG_RESULT_UNQUOTED])dnl
|
||||
popdef([AC_MSG_RESULT])dnl
|
||||
popdef([AC_MSG_CHECKING])dnl
|
||||
])
|
||||
])
|
||||
rm -f conftest.out
|
||||
])
|
||||
case "$gl_cv_cc_double_expbit0" in
|
||||
word*bit*)
|
||||
word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
|
||||
bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
|
||||
AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
|
||||
[Define as the word index where to find the exponent of 'double'.])
|
||||
AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
|
||||
[Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])
|
||||
;;
|
||||
esac
|
||||
])
|
92
m4/exponentf.m4
Normal file
92
m4/exponentf.m4
Normal file
@ -0,0 +1,92 @@
|
||||
# exponentf.m4 serial 2
|
||||
dnl Copyright (C) 2007-2008, 2010-2011 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_FLOAT_EXPONENT_LOCATION],
|
||||
[
|
||||
AC_CACHE_CHECK([where to find the exponent in a 'float'],
|
||||
[gl_cv_cc_float_expbit0],
|
||||
[
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE([[
|
||||
#include <float.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define NWORDS \
|
||||
((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
typedef union { float value; unsigned int word[NWORDS]; } memory_float;
|
||||
static unsigned int ored_words[NWORDS];
|
||||
static unsigned int anded_words[NWORDS];
|
||||
static void add_to_ored_words (float x)
|
||||
{
|
||||
memory_float m;
|
||||
size_t i;
|
||||
/* Clear it first, in case
|
||||
sizeof (float) < sizeof (memory_float). */
|
||||
memset (&m, 0, sizeof (memory_float));
|
||||
m.value = x;
|
||||
for (i = 0; i < NWORDS; i++)
|
||||
{
|
||||
ored_words[i] |= m.word[i];
|
||||
anded_words[i] &= m.word[i];
|
||||
}
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
size_t j;
|
||||
FILE *fp = fopen ("conftest.out", "w");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
anded_words[j] = ~ (unsigned int) 0;
|
||||
add_to_ored_words (0.25f);
|
||||
add_to_ored_words (0.5f);
|
||||
add_to_ored_words (1.0f);
|
||||
add_to_ored_words (2.0f);
|
||||
add_to_ored_words (4.0f);
|
||||
/* Remove bits that are common (e.g. if representation of the first mantissa
|
||||
bit is explicit). */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
ored_words[j] &= ~anded_words[j];
|
||||
/* Now find the nonzero word. */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
if (ored_words[j] != 0)
|
||||
break;
|
||||
if (j < NWORDS)
|
||||
{
|
||||
size_t i;
|
||||
for (i = j + 1; i < NWORDS; i++)
|
||||
if (ored_words[i] != 0)
|
||||
{
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
for (i = 0; ; i++)
|
||||
if ((ored_words[j] >> i) & 1)
|
||||
{
|
||||
fprintf (fp, "word %d bit %d", (int) j, (int) i);
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
}
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
]])],
|
||||
[gl_cv_cc_float_expbit0=`cat conftest.out`],
|
||||
[gl_cv_cc_float_expbit0="unknown"],
|
||||
[gl_cv_cc_float_expbit0="word 0 bit 23"])
|
||||
rm -f conftest.out
|
||||
])
|
||||
case "$gl_cv_cc_float_expbit0" in
|
||||
word*bit*)
|
||||
word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
|
||||
bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
|
||||
AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
|
||||
[Define as the word index where to find the exponent of 'float'.])
|
||||
AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
|
||||
[Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])
|
||||
;;
|
||||
esac
|
||||
])
|
98
m4/exponentl.m4
Normal file
98
m4/exponentl.m4
Normal file
@ -0,0 +1,98 @@
|
||||
# exponentl.m4 serial 3
|
||||
dnl Copyright (C) 2007-2011 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_LONG_DOUBLE_EXPONENT_LOCATION],
|
||||
[
|
||||
AC_REQUIRE([gl_BIGENDIAN])
|
||||
AC_CACHE_CHECK([where to find the exponent in a 'long double'],
|
||||
[gl_cv_cc_long_double_expbit0],
|
||||
[
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE([[
|
||||
#include <float.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define NWORDS \
|
||||
((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
|
||||
typedef union { long double value; unsigned int word[NWORDS]; }
|
||||
memory_long_double;
|
||||
static unsigned int ored_words[NWORDS];
|
||||
static unsigned int anded_words[NWORDS];
|
||||
static void add_to_ored_words (long double x)
|
||||
{
|
||||
memory_long_double m;
|
||||
size_t i;
|
||||
/* Clear it first, in case
|
||||
sizeof (long double) < sizeof (memory_long_double). */
|
||||
memset (&m, 0, sizeof (memory_long_double));
|
||||
m.value = x;
|
||||
for (i = 0; i < NWORDS; i++)
|
||||
{
|
||||
ored_words[i] |= m.word[i];
|
||||
anded_words[i] &= m.word[i];
|
||||
}
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
size_t j;
|
||||
FILE *fp = fopen ("conftest.out", "w");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
anded_words[j] = ~ (unsigned int) 0;
|
||||
add_to_ored_words (0.25L);
|
||||
add_to_ored_words (0.5L);
|
||||
add_to_ored_words (1.0L);
|
||||
add_to_ored_words (2.0L);
|
||||
add_to_ored_words (4.0L);
|
||||
/* Remove bits that are common (e.g. if representation of the first mantissa
|
||||
bit is explicit). */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
ored_words[j] &= ~anded_words[j];
|
||||
/* Now find the nonzero word. */
|
||||
for (j = 0; j < NWORDS; j++)
|
||||
if (ored_words[j] != 0)
|
||||
break;
|
||||
if (j < NWORDS)
|
||||
{
|
||||
size_t i;
|
||||
for (i = j + 1; i < NWORDS; i++)
|
||||
if (ored_words[i] != 0)
|
||||
{
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
for (i = 0; ; i++)
|
||||
if ((ored_words[j] >> i) & 1)
|
||||
{
|
||||
fprintf (fp, "word %d bit %d", (int) j, (int) i);
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
}
|
||||
fprintf (fp, "unknown");
|
||||
return (fclose (fp) != 0);
|
||||
}
|
||||
]])],
|
||||
[gl_cv_cc_long_double_expbit0=`cat conftest.out`],
|
||||
[gl_cv_cc_long_double_expbit0="unknown"],
|
||||
[
|
||||
dnl When cross-compiling, we don't know. It depends on the
|
||||
dnl ABI and compiler version. There are too many cases.
|
||||
gl_cv_cc_long_double_expbit0="unknown"
|
||||
])
|
||||
rm -f conftest.out
|
||||
])
|
||||
case "$gl_cv_cc_long_double_expbit0" in
|
||||
word*bit*)
|
||||
word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
|
||||
bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
|
||||
AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
|
||||
[Define as the word index where to find the exponent of 'long double'.])
|
||||
AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
|
||||
[Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])
|
||||
;;
|
||||
esac
|
||||
])
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user