summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am58
-rw-r--r--lib/ceil.c109
-rw-r--r--lib/dosname.h53
-rw-r--r--lib/flock.c34
-rw-r--r--lib/frexp.c166
-rw-r--r--lib/isnand-nolibm.h33
-rw-r--r--lib/round.c168
-rw-r--r--lib/stat.c1
-rw-r--r--lib/stdint.in.h7
-rw-r--r--lib/stdio-write.c148
-rw-r--r--lib/stdlib.in.h30
-rw-r--r--lib/vasnprintf.c6
-rw-r--r--lib/vasnprintf.h14
-rw-r--r--lib/version-etc.h8
14 files changed, 473 insertions, 362 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 50c374239..5d0c22971 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -9,7 +9,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl close connect duplocale environ extensions flock fpieee full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan lib-symbol-versions lib-symbol-visibility libunistring listen locale log1p maintainer-makefile malloc-gnu malloca nproc putenv recv recvfrom round send sendto setsockopt shutdown socket stat-time stdlib strcase strftime striconveh string sys_stat trunc verify version-etc-fsf vsnprintf warnings
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen locale log1p maintainer-makefile malloc-gnu malloca nproc putenv recv recvfrom send sendto setsockopt shutdown socket stat-time stdlib strcase strftime striconveh string sys_stat trunc verify version-etc-fsf vsnprintf warnings wchar
AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
@@ -37,7 +37,9 @@ libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS)
EXTRA_libgnu_la_SOURCES =
libgnu_la_LDFLAGS = $(AM_LDFLAGS)
libgnu_la_LDFLAGS += -no-undefined
+libgnu_la_LDFLAGS += $(CEIL_LIBM)
libgnu_la_LDFLAGS += $(FLOOR_LIBM)
+libgnu_la_LDFLAGS += $(FREXP_LIBM)
libgnu_la_LDFLAGS += $(GETADDRINFO_LIB)
libgnu_la_LDFLAGS += $(HOSTENT_LIB)
libgnu_la_LDFLAGS += $(INET_NTOP_LIB)
@@ -45,12 +47,12 @@ libgnu_la_LDFLAGS += $(INET_PTON_LIB)
libgnu_la_LDFLAGS += $(ISNAND_LIBM)
libgnu_la_LDFLAGS += $(ISNANF_LIBM)
libgnu_la_LDFLAGS += $(ISNANL_LIBM)
+libgnu_la_LDFLAGS += $(LDEXP_LIBM)
libgnu_la_LDFLAGS += $(LIBSOCKET)
libgnu_la_LDFLAGS += $(LOG1P_LIBM)
libgnu_la_LDFLAGS += $(LTLIBICONV)
libgnu_la_LDFLAGS += $(LTLIBINTL)
libgnu_la_LDFLAGS += $(LTLIBUNISTRING)
-libgnu_la_LDFLAGS += $(ROUND_LIBM)
libgnu_la_LDFLAGS += $(SERVENT_LIB)
libgnu_la_LDFLAGS += $(TRUNC_LIBM)
@@ -231,6 +233,15 @@ EXTRA_libgnu_la_SOURCES += canonicalize-lgpl.c
## end gnulib module canonicalize-lgpl
+## begin gnulib module ceil
+
+
+EXTRA_DIST += ceil.c
+
+EXTRA_libgnu_la_SOURCES += ceil.c
+
+## end gnulib module ceil
+
## begin gnulib module close
@@ -257,6 +268,13 @@ EXTRA_libgnu_la_SOURCES += connect.c
## end gnulib module connect
+## begin gnulib module dosname
+
+
+EXTRA_DIST += dosname.h
+
+## end gnulib module dosname
+
## begin gnulib module duplocale
@@ -343,6 +361,15 @@ EXTRA_libgnu_la_SOURCES += floor.c
## end gnulib module floor
+## begin gnulib module frexp
+
+
+EXTRA_DIST += frexp.c
+
+EXTRA_libgnu_la_SOURCES += frexp.c
+
+## end gnulib module frexp
+
## begin gnulib module full-read
libgnu_la_SOURCES += full-read.h full-read.c
@@ -558,6 +585,15 @@ EXTRA_libgnu_la_SOURCES += isnan.c isnand.c
## end gnulib module isnand
+## begin gnulib module isnand-nolibm
+
+
+EXTRA_DIST += float+.h isnan.c isnand-nolibm.h isnand.c
+
+EXTRA_libgnu_la_SOURCES += isnan.c isnand.c
+
+## end gnulib module isnand-nolibm
+
## begin gnulib module isnanf
@@ -904,15 +940,6 @@ EXTRA_libgnu_la_SOURCES += recvfrom.c
## end gnulib module recvfrom
-## begin gnulib module round
-
-
-EXTRA_DIST += round.c
-
-EXTRA_libgnu_la_SOURCES += round.c
-
-## end gnulib module round
-
## begin gnulib module safe-read
@@ -1097,6 +1124,7 @@ stdint.h: stdint.in.h
-e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
+ -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
-e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \
-e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \
-e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
@@ -1229,9 +1257,7 @@ stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
mv $@-t $@
MOSTLYCLEANFILES += stdio.h stdio.h-t
-EXTRA_DIST += stdio-write.c stdio.in.h
-
-EXTRA_libgnu_la_SOURCES += stdio-write.c
+EXTRA_DIST += stdio.in.h
## end gnulib module stdio
@@ -1256,6 +1282,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
-e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
-e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
+ -e 's|@''GNULIB_MBTOWC''@|$(GNULIB_MBTOWC)|g' \
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
-e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
@@ -1274,6 +1301,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
-e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
-e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+ -e 's|@''GNULIB_WCTOMB''@|$(GNULIB_WCTOMB)|g' \
< $(srcdir)/stdlib.in.h | \
sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
-e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
@@ -1302,6 +1330,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
-e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
-e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
+ -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
-e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
@@ -1309,6 +1338,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
-e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
-e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
+ -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
-e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
diff --git a/lib/ceil.c b/lib/ceil.c
new file mode 100644
index 000000000..e5367636d
--- /dev/null
+++ b/lib/ceil.c
@@ -0,0 +1,109 @@
+/* Round towards positive infinity.
+ 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 Lesser 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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. */
+#include <math.h>
+
+#include <float.h>
+
+#undef MIN
+
+#ifdef USE_LONG_DOUBLE
+# define FUNC ceill
+# define DOUBLE long double
+# define MANT_DIG LDBL_MANT_DIG
+# define MIN LDBL_MIN
+# define L_(literal) literal##L
+#elif ! defined USE_FLOAT
+# define FUNC ceil
+# define DOUBLE double
+# define MANT_DIG DBL_MANT_DIG
+# define MIN DBL_MIN
+# define L_(literal) literal
+#else /* defined USE_FLOAT */
+# define FUNC ceilf
+# define DOUBLE float
+# define MANT_DIG FLT_MANT_DIG
+# define MIN FLT_MIN
+# define L_(literal) literal##f
+#endif
+
+/* -0.0. See minus-zero.h. */
+#if defined __hpux || defined __sgi || defined __ICC
+# define MINUS_ZERO (-MIN * MIN)
+#else
+# define MINUS_ZERO L_(-0.0)
+#endif
+
+/* 2^(MANT_DIG-1). */
+static const DOUBLE TWO_MANT_DIG =
+ /* Assume MANT_DIG <= 5 * 31.
+ Use the identity
+ n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
+ (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
+ * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
+ * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
+ * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
+ * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
+
+DOUBLE
+FUNC (DOUBLE x)
+{
+ /* The use of 'volatile' guarantees that excess precision bits are dropped
+ at each addition step and before the following comparison at the caller's
+ site. It is necessary on x86 systems where double-floats are not IEEE
+ compliant by default, to avoid that the results become platform and compiler
+ option dependent. 'volatile' is a portable alternative to gcc's
+ -ffloat-store option. */
+ volatile DOUBLE y = x;
+ volatile DOUBLE z = y;
+
+ if (z > L_(0.0))
+ {
+ /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
+ if (z < TWO_MANT_DIG)
+ {
+ /* Round to the next integer (nearest or up or down, doesn't matter). */
+ z += TWO_MANT_DIG;
+ z -= TWO_MANT_DIG;
+ /* Enforce rounding up. */
+ if (z < y)
+ z += L_(1.0);
+ }
+ }
+ else if (z < L_(0.0))
+ {
+ /* For -1 < x < 0, return -0.0 regardless of the current rounding
+ mode. */
+ if (z > L_(-1.0))
+ z = MINUS_ZERO;
+ /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
+ else if (z > - TWO_MANT_DIG)
+ {
+ /* Round to the next integer (nearest or up or down, doesn't matter). */
+ z -= TWO_MANT_DIG;
+ z += TWO_MANT_DIG;
+ /* Enforce rounding up. */
+ if (z < y)
+ z += L_(1.0);
+ }
+ }
+ return z;
+}
diff --git a/lib/dosname.h b/lib/dosname.h
new file mode 100644
index 000000000..3087d39dc
--- /dev/null
+++ b/lib/dosname.h
@@ -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 Lesser 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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_ */
diff --git a/lib/flock.c b/lib/flock.c
index bdec6d48e..8f018e50c 100644
--- a/lib/flock.c
+++ b/lib/flock.c
@@ -27,13 +27,13 @@
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* _get_osfhandle */
-#include <io.h>
+# include <io.h>
/* LockFileEx */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
-#include <errno.h>
+# include <errno.h>
/* Determine the current size of a file. Because the other braindead
* APIs we'll call need lower/upper 32 bit pairs, keep the file size
@@ -47,9 +47,9 @@ file_size (HANDLE h, DWORD * lower, DWORD * upper)
}
/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
-#ifndef LOCKFILE_FAIL_IMMEDIATELY
-# define LOCKFILE_FAIL_IMMEDIATELY 1
-#endif
+# ifndef LOCKFILE_FAIL_IMMEDIATELY
+# define LOCKFILE_FAIL_IMMEDIATELY 1
+# endif
/* Acquire a lock. */
static BOOL
@@ -160,17 +160,17 @@ flock (int fd, int operation)
#else /* !Windows */
-#ifdef HAVE_STRUCT_FLOCK_L_TYPE
+# ifdef HAVE_STRUCT_FLOCK_L_TYPE
/* We know how to implement flock in terms of fcntl. */
-#include <fcntl.h>
+# include <fcntl.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
-#include <errno.h>
-#include <string.h>
+# include <errno.h>
+# include <string.h>
int
flock (int fd, int operation)
@@ -211,10 +211,10 @@ flock (int fd, int operation)
return r;
}
-#else /* !HAVE_STRUCT_FLOCK_L_TYPE */
+# else /* !HAVE_STRUCT_FLOCK_L_TYPE */
-#error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
+# error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
-#endif /* !HAVE_STRUCT_FLOCK_L_TYPE */
+# endif /* !HAVE_STRUCT_FLOCK_L_TYPE */
#endif /* !Windows */
diff --git a/lib/frexp.c b/lib/frexp.c
new file mode 100644
index 000000000..c7687e0df
--- /dev/null
+++ b/lib/frexp.c
@@ -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 Lesser 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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;
+}
diff --git a/lib/isnand-nolibm.h b/lib/isnand-nolibm.h
new file mode 100644
index 000000000..e434a7bd0
--- /dev/null
+++ b/lib/isnand-nolibm.h
@@ -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 Lesser 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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
diff --git a/lib/round.c b/lib/round.c
deleted file mode 100644
index 1630a6d79..000000000
--- a/lib/round.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/* Round toward nearest, breaking ties away from zero.
- 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 Lesser 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 Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser 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 Ben Pfaff <blp@gnu.org>, 2007.
- Based heavily on code by Bruno Haible. */
-
-#include <config.h>
-
-/* Specification. */
-#include <math.h>
-
-#include <float.h>
-
-#undef MIN
-
-#ifdef USE_LONG_DOUBLE
-# define ROUND roundl
-# define FLOOR floorl
-# define CEIL ceill
-# define DOUBLE long double
-# define MANT_DIG LDBL_MANT_DIG
-# define MIN LDBL_MIN
-# define L_(literal) literal##L
-# define HAVE_FLOOR_AND_CEIL HAVE_FLOORL_AND_CEILL
-#elif ! defined USE_FLOAT
-# define ROUND round
-# define FLOOR floor
-# define CEIL ceil
-# define DOUBLE double
-# define MANT_DIG DBL_MANT_DIG
-# define MIN DBL_MIN
-# define L_(literal) literal
-# define HAVE_FLOOR_AND_CEIL 1
-#else /* defined USE_FLOAT */
-# define ROUND roundf
-# define FLOOR floorf
-# define CEIL ceilf
-# define DOUBLE float
-# define MANT_DIG FLT_MANT_DIG
-# define MIN FLT_MIN
-# define L_(literal) literal##f
-# define HAVE_FLOOR_AND_CEIL HAVE_FLOORF_AND_CEILF
-#endif
-
-/* -0.0. See minus-zero.h. */
-#if defined __hpux || defined __sgi || defined __ICC
-# define MINUS_ZERO (-MIN * MIN)
-#else
-# define MINUS_ZERO L_(-0.0)
-#endif
-
-/* If we're being included from test-round2[f].c, it already defined names for
- our round implementations. Otherwise, pick the preferred implementation for
- this machine. */
-#if !defined FLOOR_BASED_ROUND && !defined FLOOR_FREE_ROUND
-# if HAVE_FLOOR_AND_CEIL
-# define FLOOR_BASED_ROUND ROUND
-# else
-# define FLOOR_FREE_ROUND ROUND
-# endif
-#endif
-
-#ifdef FLOOR_BASED_ROUND
-/* An implementation of the C99 round function based on floor and ceil. We use
- this when floor and ceil are available, on the assumption that they are
- faster than the open-coded versions below. */
-DOUBLE
-FLOOR_BASED_ROUND (DOUBLE x)
-{
- if (x >= L_(0.0))
- {
- DOUBLE y = FLOOR (x);
- if (x - y >= L_(0.5))
- y += L_(1.0);
- return y;
- }
- else
- {
- DOUBLE y = CEIL (x);
- if (y - x >= L_(0.5))
- y -= L_(1.0);
- return y;
- }
-}
-#endif /* FLOOR_BASED_ROUND */
-
-#ifdef FLOOR_FREE_ROUND
-/* An implementation of the C99 round function without floor or ceil.
- We use this when floor or ceil is missing. */
-DOUBLE
-FLOOR_FREE_ROUND (DOUBLE x)
-{
- /* 2^(MANT_DIG-1). */
- static const DOUBLE TWO_MANT_DIG =
- /* Assume MANT_DIG <= 5 * 31.
- Use the identity
- n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
- (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
- * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
- * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
- * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
- * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
-
- /* The use of 'volatile' guarantees that excess precision bits are dropped at
- each addition step and before the following comparison at the caller's
- site. It is necessary on x86 systems where double-floats are not IEEE
- compliant by default, to avoid that the results become platform and
- compiler option dependent. 'volatile' is a portable alternative to gcc's
- -ffloat-store option. */
- volatile DOUBLE y = x;
- volatile DOUBLE z = y;
-
- if (z > L_(0.0))
- {
- /* Avoid rounding error for x = 0.5 - 2^(-MANT_DIG-1). */
- if (z < L_(0.5))
- z = L_(0.0);
- /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
- else if (z < TWO_MANT_DIG)
- {
- /* Add 0.5 to the absolute value. */
- y = z += L_(0.5);
- /* Round to the next integer (nearest or up or down, doesn't
- matter). */
- z += TWO_MANT_DIG;
- z -= TWO_MANT_DIG;
- /* Enforce rounding down. */
- if (z > y)
- z -= L_(1.0);
- }
- }
- else if (z < L_(0.0))
- {
- /* Avoid rounding error for x = -(0.5 - 2^(-MANT_DIG-1)). */
- if (z > - L_(0.5))
- z = MINUS_ZERO;
- /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
- else if (z > -TWO_MANT_DIG)
- {
- /* Add 0.5 to the absolute value. */
- y = z -= L_(0.5);
- /* Round to the next integer (nearest or up or down, doesn't
- matter). */
- z -= TWO_MANT_DIG;
- z += TWO_MANT_DIG;
- /* Enforce rounding up. */
- if (z < y)
- z += L_(1.0);
- }
- }
- return z;
-}
-#endif /* FLOOR_FREE_ROUND */
-
diff --git a/lib/stat.c b/lib/stat.c
index d154a18b0..aa369d0f2 100644
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -37,6 +37,7 @@ orig_stat (const char *filename, struct stat *buf)
#include <limits.h>
#include <stdbool.h>
#include <string.h>
+#include "dosname.h"
/* Store information about NAME into ST. Work around bugs with
trailing slashes. Mingw has other bugs (such as st_ino always
diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index 319b8aa15..b60e9cc0b 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -497,7 +497,12 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
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 ! (defined WCHAR_MIN && defined WCHAR_MAX)
+#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
diff --git a/lib/stdio-write.c b/lib/stdio-write.c
deleted file mode 100644
index 252d9bce8..000000000
--- a/lib/stdio-write.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* POSIX compatible FILE stream write function.
- Copyright (C) 2008-2011 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 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 Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-/* Replace these functions only if module 'sigpipe' is requested. */
-#if GNULIB_SIGPIPE
-
-/* On native Windows platforms, SIGPIPE does not exist. When write() is
- called on a pipe with no readers, WriteFile() fails with error
- GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
- error EINVAL. This write() function is at the basis of the function
- which flushes the buffer of a FILE stream. */
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-# include <errno.h>
-# include <signal.h>
-# include <io.h>
-
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-
-# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
- if (ferror (stream)) \
- return (EXPRESSION); \
- else \
- { \
- RETTYPE ret; \
- SetLastError (0); \
- ret = (EXPRESSION); \
- if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream)) \
- { \
- int fd = fileno (stream); \
- if (fd >= 0 \
- && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
- { \
- /* Try to raise signal SIGPIPE. */ \
- raise (SIGPIPE); \
- /* If it is currently blocked or ignored, change errno from \
- EINVAL to EPIPE. */ \
- errno = EPIPE; \
- } \
- } \
- return ret; \
- }
-
-# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
-int
-printf (const char *format, ...)
-{
- int retval;
- va_list args;
-
- va_start (args, format);
- retval = vfprintf (stdout, format, args);
- va_end (args);
-
- return retval;
-}
-# endif
-
-# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
-int
-fprintf (FILE *stream, const char *format, ...)
-{
- int retval;
- va_list args;
-
- va_start (args, format);
- retval = vfprintf (stream, format, args);
- va_end (args);
-
- return retval;
-}
-# endif
-
-# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
-int
-vprintf (const char *format, va_list args)
-{
- return vfprintf (stdout, format, args);
-}
-# endif
-
-# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
-int
-vfprintf (FILE *stream, const char *format, va_list args)
-#undef vfprintf
-{
- CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
-}
-# endif
-
-int
-putchar (int c)
-{
- return fputc (c, stdout);
-}
-
-int
-fputc (int c, FILE *stream)
-#undef fputc
-{
- CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
-}
-
-int
-fputs (const char *string, FILE *stream)
-#undef fputs
-{
- CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
-}
-
-int
-puts (const char *string)
-#undef puts
-{
- FILE *stream = stdout;
- CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
-}
-
-size_t
-fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
-#undef fwrite
-{
- CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
-}
-
-# endif
-#endif
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index e2d945767..980b909af 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -274,6 +274,21 @@ _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";
@@ -723,6 +738,21 @@ _GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
# 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 /* _GL_STDLIB_H */
#endif /* _GL_STDLIB_H */
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index cad862f9d..fec68c825 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -935,11 +935,11 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
abort ();
m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
}
-#if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
- precision. */
+# if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
+ precision. */
if (!(y == 0.0L))
abort ();
-#endif
+# endif
/* Normalise. */
while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
m.nlimbs--;
diff --git a/lib/vasnprintf.h b/lib/vasnprintf.h
index 7ae03da8e..e2de468aa 100644
--- a/lib/vasnprintf.h
+++ b/lib/vasnprintf.h
@@ -24,16 +24,16 @@
/* Get size_t. */
#include <stddef.h>
-#ifndef __attribute__
/* 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 __attribute__ only if these are supported too, because
+ 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 __attribute__(Spec) /* empty */
-# endif
+#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
@@ -69,9 +69,9 @@ extern "C" {
# define vasnprintf rpl_vasnprintf
#endif
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
- __attribute__ ((__format__ (__printf__, 3, 4)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
- __attribute__ ((__format__ (__printf__, 3, 0)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
#ifdef __cplusplus
}
diff --git a/lib/version-etc.h b/lib/version-etc.h
index 9446dec14..b197ad11f 100644
--- a/lib/version-etc.h
+++ b/lib/version-etc.h
@@ -23,11 +23,11 @@
# include <stdio.h>
/* The `sentinel' attribute was added in gcc 4.0. */
-#ifndef ATTRIBUTE_SENTINEL
+#ifndef _GL_ATTRIBUTE_SENTINEL
# if 4 <= __GNUC__
-# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
+# define _GL_ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
# else
-# define ATTRIBUTE_SENTINEL /* empty */
+# define _GL_ATTRIBUTE_SENTINEL /* empty */
# endif
#endif
@@ -70,7 +70,7 @@ extern void version_etc (FILE *stream,
const char *command_name, const char *package,
const char *version,
/* const char *author1, ..., NULL */ ...)
- ATTRIBUTE_SENTINEL;
+ _GL_ATTRIBUTE_SENTINEL;
/* Display the usual `Report bugs to' stanza */
extern void emit_bug_reporting_address (void);