mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-14 23:50:19 +02:00
Use Gnulib's `vsnprintf' module.
* m4/gnulib-cache.m4: Use `vsnprintf', needed by `deprecation.c'.
This commit is contained in:
parent
5374ec9c28
commit
c4b681fdac
38 changed files with 10886 additions and 5 deletions
191
lib/Makefile.am
191
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 --libtool --macro-prefix=gl --no-vc-files alloca-opt autobuild byteswap canonicalize-lgpl count-one-bits environ extensions flock fpieee full-read full-write havelib iconv_open-utf lib-symbol-visibility libunistring putenv stdlib strcase strftime striconveh string
|
||||
# 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 --libtool --macro-prefix=gl --no-vc-files alloca-opt autobuild byteswap canonicalize-lgpl count-one-bits environ extensions flock fpieee full-read full-write havelib iconv_open-utf lib-symbol-visibility libunistring putenv stdlib strcase strftime striconveh string vsnprintf
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
|
||||
|
||||
|
@ -167,6 +167,54 @@ EXTRA_DIST += count-one-bits.h
|
|||
|
||||
## end gnulib module count-one-bits
|
||||
|
||||
## begin gnulib module errno
|
||||
|
||||
BUILT_SOURCES += $(ERRNO_H)
|
||||
|
||||
# We need the following in order to create <errno.h> when the system
|
||||
# doesn't have one that is POSIX compliant.
|
||||
errno.h: errno.in.h
|
||||
rm -f $@-t $@
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
|
||||
sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''NEXT_ERRNO_H''@|$(NEXT_ERRNO_H)|g' \
|
||||
-e 's|@''EMULTIHOP_HIDDEN''@|$(EMULTIHOP_HIDDEN)|g' \
|
||||
-e 's|@''EMULTIHOP_VALUE''@|$(EMULTIHOP_VALUE)|g' \
|
||||
-e 's|@''ENOLINK_HIDDEN''@|$(ENOLINK_HIDDEN)|g' \
|
||||
-e 's|@''ENOLINK_VALUE''@|$(ENOLINK_VALUE)|g' \
|
||||
-e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \
|
||||
-e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \
|
||||
< $(srcdir)/errno.in.h; \
|
||||
} > $@-t
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += errno.h errno.h-t
|
||||
|
||||
EXTRA_DIST += errno.in.h
|
||||
|
||||
## end gnulib module errno
|
||||
|
||||
## begin gnulib module float
|
||||
|
||||
BUILT_SOURCES += $(FLOAT_H)
|
||||
|
||||
# We need the following in order to create <float.h> when the system
|
||||
# doesn't have one that works with the given compiler.
|
||||
float.h: float.in.h
|
||||
rm -f $@-t $@
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
|
||||
sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
|
||||
< $(srcdir)/float.in.h; \
|
||||
} > $@-t
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += float.h float.h-t
|
||||
|
||||
EXTRA_DIST += float.in.h
|
||||
|
||||
## end gnulib module float
|
||||
|
||||
## begin gnulib module flock
|
||||
|
||||
|
||||
|
@ -188,6 +236,15 @@ libgnu_la_SOURCES += full-write.h full-write.c
|
|||
|
||||
## end gnulib module full-write
|
||||
|
||||
## begin gnulib module getpagesize
|
||||
|
||||
|
||||
EXTRA_DIST += getpagesize.c
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += getpagesize.c
|
||||
|
||||
## end gnulib module getpagesize
|
||||
|
||||
## begin gnulib module gperf
|
||||
|
||||
GPERF = gperf
|
||||
|
@ -390,6 +447,15 @@ EXTRA_libgnu_la_SOURCES += mbsinit.c
|
|||
|
||||
## end gnulib module mbsinit
|
||||
|
||||
## begin gnulib module memchr
|
||||
|
||||
|
||||
EXTRA_DIST += memchr.c memchr.valgrind
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += memchr.c
|
||||
|
||||
## end gnulib module memchr
|
||||
|
||||
## begin gnulib module pathmax
|
||||
|
||||
|
||||
|
@ -433,6 +499,12 @@ EXTRA_libgnu_la_SOURCES += safe-write.c
|
|||
|
||||
## end gnulib module safe-write
|
||||
|
||||
## begin gnulib module size_max
|
||||
|
||||
libgnu_la_SOURCES += size_max.h
|
||||
|
||||
## end gnulib module size_max
|
||||
|
||||
## begin gnulib module stdbool
|
||||
|
||||
BUILT_SOURCES += $(STDBOOL_H)
|
||||
|
@ -493,6 +565,99 @@ EXTRA_DIST += stdint.in.h
|
|||
|
||||
## end gnulib module stdint
|
||||
|
||||
## begin gnulib module stdio
|
||||
|
||||
BUILT_SOURCES += stdio.h
|
||||
|
||||
# We need the following in order to create <stdio.h> when the system
|
||||
# doesn't have one that works with the given compiler.
|
||||
stdio.h: stdio.in.h
|
||||
rm -f $@-t $@
|
||||
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
|
||||
sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
|
||||
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
|
||||
-e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
|
||||
-e 's|@''GNULIB_FPRINTF''@|$(GNULIB_FPRINTF)|g' \
|
||||
-e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_PRINTF''@|$(GNULIB_PRINTF)|g' \
|
||||
-e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
|
||||
-e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
|
||||
-e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_VPRINTF''@|$(GNULIB_VPRINTF)|g' \
|
||||
-e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
|
||||
-e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_DPRINTF''@|$(GNULIB_DPRINTF)|g' \
|
||||
-e 's|@''GNULIB_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \
|
||||
-e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
|
||||
-e 's|@''GNULIB_OBSTACK_PRINTF''@|$(GNULIB_OBSTACK_PRINTF)|g' \
|
||||
-e 's|@''GNULIB_OBSTACK_PRINTF_POSIX''@|$(GNULIB_OBSTACK_PRINTF_POSIX)|g' \
|
||||
-e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \
|
||||
-e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \
|
||||
-e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
|
||||
-e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
|
||||
-e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
|
||||
-e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
|
||||
-e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
|
||||
-e 's|@''GNULIB_FPURGE''@|$(GNULIB_FPURGE)|g' \
|
||||
-e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
|
||||
-e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
|
||||
-e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
|
||||
-e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
|
||||
-e 's|@''GNULIB_FPUTS''@|$(GNULIB_FPUTS)|g' \
|
||||
-e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \
|
||||
-e 's|@''GNULIB_FWRITE''@|$(GNULIB_FWRITE)|g' \
|
||||
-e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
|
||||
-e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
|
||||
-e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \
|
||||
-e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \
|
||||
-e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \
|
||||
-e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
|
||||
-e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
|
||||
-e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
|
||||
-e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \
|
||||
-e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
|
||||
-e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
|
||||
-e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
|
||||
-e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
|
||||
-e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
|
||||
-e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
|
||||
-e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
|
||||
-e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
|
||||
-e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
|
||||
-e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \
|
||||
-e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
|
||||
-e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
|
||||
-e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \
|
||||
-e 's|@''REPLACE_OBSTACK_PRINTF''@|$(REPLACE_OBSTACK_PRINTF)|g' \
|
||||
-e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
|
||||
-e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \
|
||||
-e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
|
||||
-e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
|
||||
-e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
|
||||
-e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
|
||||
-e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
|
||||
-e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \
|
||||
-e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
|
||||
-e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
|
||||
-e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
|
||||
-e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
|
||||
-e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \
|
||||
-e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \
|
||||
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
|
||||
< $(srcdir)/stdio.in.h; \
|
||||
} > $@-t
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += stdio.h stdio.h-t
|
||||
|
||||
EXTRA_DIST += stdio-write.c stdio.in.h
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += stdio-write.c
|
||||
|
||||
## end gnulib module stdio
|
||||
|
||||
## begin gnulib module stdlib
|
||||
|
||||
BUILT_SOURCES += stdlib.h
|
||||
|
@ -868,12 +1033,30 @@ EXTRA_DIST += unitypes.h
|
|||
|
||||
## end gnulib module unitypes
|
||||
|
||||
## begin gnulib module vasnprintf
|
||||
|
||||
|
||||
EXTRA_DIST += asnprintf.c float+.h printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c
|
||||
|
||||
## end gnulib module vasnprintf
|
||||
|
||||
## begin gnulib module verify
|
||||
|
||||
libgnu_la_SOURCES += verify.h
|
||||
|
||||
## end gnulib module verify
|
||||
|
||||
## begin gnulib module vsnprintf
|
||||
|
||||
|
||||
EXTRA_DIST += vsnprintf.c
|
||||
|
||||
EXTRA_libgnu_la_SOURCES += vsnprintf.c
|
||||
|
||||
## end gnulib module vsnprintf
|
||||
|
||||
## begin gnulib module wchar
|
||||
|
||||
BUILT_SOURCES += $(WCHAR_H)
|
||||
|
@ -941,6 +1124,12 @@ EXTRA_libgnu_la_SOURCES += write.c
|
|||
|
||||
## end gnulib module write
|
||||
|
||||
## begin gnulib module xsize
|
||||
|
||||
libgnu_la_SOURCES += xsize.h
|
||||
|
||||
## end gnulib module xsize
|
||||
|
||||
|
||||
mostlyclean-local: mostlyclean-generic
|
||||
@for dir in '' $(MOSTLYCLEANDIRS); do \
|
||||
|
|
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 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. */
|
||||
|
||||
#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;
|
||||
}
|
160
lib/errno.in.h
Normal file
160
lib/errno.in.h
Normal file
|
@ -0,0 +1,160 @@
|
|||
/* A POSIX-like <errno.h>.
|
||||
|
||||
Copyright (C) 2008-2009 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. */
|
||||
|
||||
#ifndef _GL_ERRNO_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_ERRNO_H@
|
||||
|
||||
#ifndef _GL_ERRNO_H
|
||||
#define _GL_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.
|
||||
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 ECANCELED
|
||||
# define ECANCELED 2008
|
||||
# define GNULIB_defined_ECANCELED 1
|
||||
# endif
|
||||
|
||||
|
||||
#endif /* _GL_ERRNO_H */
|
||||
#endif /* _GL_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 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 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. */
|
||||
|
||||
#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[2 * (SIZEOF_FLT <= sizeof (float)) - 1];
|
||||
typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1];
|
||||
typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1];
|
||||
|
||||
#endif /* _FLOATPLUS_H */
|
62
lib/float.in.h
Normal file
62
lib/float.in.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* A correct <float.h>.
|
||||
|
||||
Copyright (C) 2007-2008 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/>. */
|
||||
|
||||
#ifndef _GL_FLOAT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_FLOAT_H@
|
||||
|
||||
#ifndef _GL_FLOAT_H
|
||||
#define _GL_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
|
||||
|
||||
#endif /* _GL_FLOAT_H */
|
||||
#endif /* _GL_FLOAT_H */
|
39
lib/getpagesize.c
Normal file
39
lib/getpagesize.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* getpagesize emulation for systems where it cannot be done in a C macro.
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 and Martin Lambers. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
/* This implementation is only for native Win32 systems. */
|
||||
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
int
|
||||
getpagesize (void)
|
||||
{
|
||||
SYSTEM_INFO system_info;
|
||||
GetSystemInfo (&system_info);
|
||||
return system_info.dwPageSize;
|
||||
}
|
||||
|
||||
#endif
|
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
|
||||
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 Lesser 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 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/>. */
|
||||
|
||||
#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
|
||||
}
|
187
lib/printf-args.c
Normal file
187
lib/printf-args.c
Normal file
|
@ -0,0 +1,187 @@
|
|||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003, 2005-2007 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. */
|
||||
|
||||
/* 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)
|
||||
? 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;
|
||||
}
|
154
lib/printf-args.h
Normal file
154
lib/printf-args.h
Normal file
|
@ -0,0 +1,154 @@
|
|||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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. */
|
||||
|
||||
#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;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t count;
|
||||
argument *arg;
|
||||
}
|
||||
arguments;
|
||||
|
||||
|
||||
/* Fetch the arguments, putting them into a. */
|
||||
#ifdef STATIC
|
||||
STATIC
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int PRINTF_FETCHARGS (va_list args, arguments *a);
|
||||
|
||||
#endif /* _PRINTF_ARGS_H */
|
627
lib/printf-parse.c
Normal file
627
lib/printf-parse.c
Normal file
|
@ -0,0 +1,627 @@
|
|||
/* Formatted output to strings.
|
||||
Copyright (C) 1999-2000, 2002-2003, 2006-2008 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. */
|
||||
|
||||
/* 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>
|
||||
|
||||
/* 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 = 1;
|
||||
d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
|
||||
if (d->dir == NULL)
|
||||
/* Out of memory. */
|
||||
goto out_of_memory_1;
|
||||
|
||||
a->count = 0;
|
||||
a_allocated = 0;
|
||||
a->arg = NULL;
|
||||
|
||||
#define REGISTER_ARG(_index_,_type_) \
|
||||
{ \
|
||||
size_t n = (_index_); \
|
||||
if (n >= a_allocated) \
|
||||
{ \
|
||||
size_t memory_size; \
|
||||
argument *memory; \
|
||||
\
|
||||
a_allocated = xtimes (a_allocated, 2); \
|
||||
if (a_allocated <= n) \
|
||||
a_allocated = xsum (n, 1); \
|
||||
memory_size = xtimes (a_allocated, sizeof (argument)); \
|
||||
if (size_overflow_p (memory_size)) \
|
||||
/* Overflow, would lead to out of memory. */ \
|
||||
goto out_of_memory; \
|
||||
memory = (argument *) (a->arg \
|
||||
? realloc (a->arg, memory_size) \
|
||||
: malloc (memory_size)); \
|
||||
if (memory == NULL) \
|
||||
/* Out of memory. */ \
|
||||
goto out_of_memory; \
|
||||
a->arg = memory; \
|
||||
} \
|
||||
while (a->count <= n) \
|
||||
a->arg[a->count++].type = TYPE_NONE; \
|
||||
if (a->arg[n].type == TYPE_NONE) \
|
||||
a->arg[n].type = (_type_); \
|
||||
else if (a->arg[n].type != (_type_)) \
|
||||
/* Ambiguous type for positional argument. */ \
|
||||
goto error; \
|
||||
}
|
||||
|
||||
while (*cp != '\0')
|
||||
{
|
||||
CHAR_T c = *cp++;
|
||||
if (c == '%')
|
||||
{
|
||||
size_t arg_index = ARG_NONE;
|
||||
DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
|
||||
|
||||
/* Initialize the next directive. */
|
||||
dp->dir_start = cp - 1;
|
||||
dp->flags = 0;
|
||||
dp->width_start = NULL;
|
||||
dp->width_end = NULL;
|
||||
dp->width_arg_index = ARG_NONE;
|
||||
dp->precision_start = NULL;
|
||||
dp->precision_end = NULL;
|
||||
dp->precision_arg_index = ARG_NONE;
|
||||
dp->arg_index = ARG_NONE;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const CHAR_T *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = xsum (xtimes (n, 10), *np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
if (size_overflow_p (n))
|
||||
/* n too large, would lead to out of memory later. */
|
||||
goto error;
|
||||
arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the flags. */
|
||||
for (;;)
|
||||
{
|
||||
if (*cp == '\'')
|
||||
{
|
||||
dp->flags |= FLAG_GROUP;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '-')
|
||||
{
|
||||
dp->flags |= FLAG_LEFT;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '+')
|
||||
{
|
||||
dp->flags |= FLAG_SHOWSIGN;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == ' ')
|
||||
{
|
||||
dp->flags |= FLAG_SPACE;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '#')
|
||||
{
|
||||
dp->flags |= FLAG_ALT;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '0')
|
||||
{
|
||||
dp->flags |= FLAG_ZERO;
|
||||
cp++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Parse the field width. */
|
||||
if (*cp == '*')
|
||||
{
|
||||
dp->width_start = cp;
|
||||
cp++;
|
||||
dp->width_end = cp;
|
||||
if (max_width_length < 1)
|
||||
max_width_length = 1;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const CHAR_T *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = xsum (xtimes (n, 10), *np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
if (size_overflow_p (n))
|
||||
/* n too large, would lead to out of memory later. */
|
||||
goto error;
|
||||
dp->width_arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
if (dp->width_arg_index == ARG_NONE)
|
||||
{
|
||||
dp->width_arg_index = arg_posn++;
|
||||
if (dp->width_arg_index == ARG_NONE)
|
||||
/* arg_posn wrapped around. */
|
||||
goto error;
|
||||
}
|
||||
REGISTER_ARG (dp->width_arg_index, TYPE_INT);
|
||||
}
|
||||
else if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
size_t width_length;
|
||||
|
||||
dp->width_start = cp;
|
||||
for (; *cp >= '0' && *cp <= '9'; cp++)
|
||||
;
|
||||
dp->width_end = cp;
|
||||
width_length = dp->width_end - dp->width_start;
|
||||
if (max_width_length < width_length)
|
||||
max_width_length = width_length;
|
||||
}
|
||||
|
||||
/* Parse the precision. */
|
||||
if (*cp == '.')
|
||||
{
|
||||
cp++;
|
||||
if (*cp == '*')
|
||||
{
|
||||
dp->precision_start = cp - 1;
|
||||
cp++;
|
||||
dp->precision_end = cp;
|
||||
if (max_precision_length < 2)
|
||||
max_precision_length = 2;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const CHAR_T *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = xsum (xtimes (n, 10), *np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
if (size_overflow_p (n))
|
||||
/* n too large, would lead to out of memory
|
||||
later. */
|
||||
goto error;
|
||||
dp->precision_arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
if (dp->precision_arg_index == ARG_NONE)
|
||||
{
|
||||
dp->precision_arg_index = arg_posn++;
|
||||
if (dp->precision_arg_index == ARG_NONE)
|
||||
/* arg_posn wrapped around. */
|
||||
goto error;
|
||||
}
|
||||
REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t precision_length;
|
||||
|
||||
dp->precision_start = cp - 1;
|
||||
for (; *cp >= '0' && *cp <= '9'; cp++)
|
||||
;
|
||||
dp->precision_end = cp;
|
||||
precision_length = dp->precision_end - dp->precision_start;
|
||||
if (max_precision_length < precision_length)
|
||||
max_precision_length = precision_length;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
arg_type type;
|
||||
|
||||
/* Parse argument type/size specifiers. */
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (*cp == 'h')
|
||||
{
|
||||
flags |= (1 << (flags & 1));
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == 'L')
|
||||
{
|
||||
flags |= 4;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == 'l')
|
||||
{
|
||||
flags += 8;
|
||||
cp++;
|
||||
}
|
||||
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 *) realloc (d->dir, memory_size);
|
||||
if (memory == NULL)
|
||||
/* Out of memory. */
|
||||
goto out_of_memory;
|
||||
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)
|
||||
free (a->arg);
|
||||
if (d->dir)
|
||||
free (d->dir);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
||||
out_of_memory:
|
||||
if (a->arg)
|
||||
free (a->arg);
|
||||
if (d->dir)
|
||||
free (d->dir);
|
||||
out_of_memory_1:
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#undef PRINTF_PARSE
|
||||
#undef DIRECTIVES
|
||||
#undef DIRECTIVE
|
||||
#undef CHAR_T_ONLY_ASCII
|
||||
#undef CHAR_T
|
179
lib/printf-parse.h
Normal file
179
lib/printf-parse.h
Normal file
|
@ -0,0 +1,179 @@
|
|||
/* Parse printf format string.
|
||||
Copyright (C) 1999, 2002-2003, 2005, 2007 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. */
|
||||
|
||||
#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. */
|
||||
|
||||
#include "printf-args.h"
|
||||
|
||||
|
||||
/* Flags */
|
||||
#define FLAG_GROUP 1 /* ' flag */
|
||||
#define FLAG_LEFT 2 /* - flag */
|
||||
#define FLAG_SHOWSIGN 4 /* + flag */
|
||||
#define FLAG_SPACE 8 /* space flag */
|
||||
#define FLAG_ALT 16 /* # flag */
|
||||
#define FLAG_ZERO 32
|
||||
|
||||
/* arg_index value indicating that no argument is consumed. */
|
||||
#define ARG_NONE (~(size_t)0)
|
||||
|
||||
/* xxx_directive: A parsed directive.
|
||||
xxx_directives: A parsed format string. */
|
||||
|
||||
/* 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_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_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_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_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 */
|
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 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 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. */
|
||||
|
||||
#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 */
|
148
lib/stdio-write.c
Normal file
148
lib/stdio-write.c
Normal file
|
@ -0,0 +1,148 @@
|
|||
/* POSIX compatible FILE stream write function.
|
||||
Copyright (C) 2008 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_VFPRINTF_POSIX /* avoid collision with vprintf.c */
|
||||
int
|
||||
vprintf (const char *format, va_list args)
|
||||
{
|
||||
return vfprintf (stdout, format, args);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if !REPLACE_VPRINTF_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
|
542
lib/stdio.in.h
Normal file
542
lib/stdio.in.h
Normal file
|
@ -0,0 +1,542 @@
|
|||
/* A GNU-like <stdio.h>.
|
||||
|
||||
Copyright (C) 2004, 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 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. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
@PRAGMA_SYSTEM_HEADER@
|
||||
#endif
|
||||
|
||||
#if defined __need_FILE || defined __need___FILE
|
||||
/* Special invocation convention inside glibc header files. */
|
||||
|
||||
#@INCLUDE_NEXT@ @NEXT_STDIO_H@
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _GL_STDIO_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#@INCLUDE_NEXT@ @NEXT_STDIO_H@
|
||||
|
||||
#ifndef _GL_STDIO_H
|
||||
#define _GL_STDIO_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
|
||||
|| (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
|
||||
|| (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
|
||||
|| (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
|
||||
/* Get off_t and ssize_t. */
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef __attribute__
|
||||
/* This feature is available in gcc versions 2.5 and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
/* The __-protected variants of `format' and `printf' attributes
|
||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __format__ format
|
||||
# define __printf__ printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* The definition of GL_LINK_WARNING is copied here. */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if @GNULIB_FPRINTF_POSIX@
|
||||
# if @REPLACE_FPRINTF@
|
||||
# define fprintf rpl_fprintf
|
||||
extern int fprintf (FILE *fp, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
# endif
|
||||
#elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# define fprintf rpl_fprintf
|
||||
extern int fprintf (FILE *fp, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fprintf
|
||||
# define fprintf \
|
||||
(GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
|
||||
"use gnulib module fprintf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
fprintf)
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VFPRINTF_POSIX@
|
||||
# if @REPLACE_VFPRINTF@
|
||||
# define vfprintf rpl_vfprintf
|
||||
extern int vfprintf (FILE *fp, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
# endif
|
||||
#elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# define vfprintf rpl_vfprintf
|
||||
extern int vfprintf (FILE *fp, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef vfprintf
|
||||
# define vfprintf(s,f,a) \
|
||||
(GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
|
||||
"use gnulib module vfprintf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
vfprintf (s, f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PRINTF_POSIX@
|
||||
# if @REPLACE_PRINTF@
|
||||
/* Don't break __attribute__((format(printf,M,N))). */
|
||||
# define printf __printf__
|
||||
extern int printf (const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
# endif
|
||||
#elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
/* Don't break __attribute__((format(printf,M,N))). */
|
||||
# define printf __printf__
|
||||
extern int printf (const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef printf
|
||||
# define printf \
|
||||
(GL_LINK_WARNING ("printf is not always POSIX compliant - " \
|
||||
"use gnulib module printf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
printf)
|
||||
/* Don't break __attribute__((format(printf,M,N))). */
|
||||
# define format(kind,m,n) format (__##kind##__, m, n)
|
||||
# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
|
||||
# define ____printf____ __printf__
|
||||
# define ____scanf____ __scanf__
|
||||
# define ____strftime____ __strftime__
|
||||
# define ____strfmon____ __strfmon__
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VPRINTF_POSIX@
|
||||
# if @REPLACE_VPRINTF@
|
||||
# define vprintf rpl_vprintf
|
||||
extern int vprintf (const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 1, 0)));
|
||||
# endif
|
||||
#elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# define vprintf rpl_vprintf
|
||||
extern int vprintf (const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 1, 0)));
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef vprintf
|
||||
# define vprintf(f,a) \
|
||||
(GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
|
||||
"use gnulib module vprintf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
vprintf (f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_SNPRINTF@
|
||||
# if @REPLACE_SNPRINTF@
|
||||
# define snprintf rpl_snprintf
|
||||
# endif
|
||||
# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
|
||||
extern int snprintf (char *str, size_t size, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef snprintf
|
||||
# define snprintf \
|
||||
(GL_LINK_WARNING ("snprintf is unportable - " \
|
||||
"use gnulib module snprintf for portability"), \
|
||||
snprintf)
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VSNPRINTF@
|
||||
# if @REPLACE_VSNPRINTF@
|
||||
# define vsnprintf rpl_vsnprintf
|
||||
# endif
|
||||
# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
|
||||
extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef vsnprintf
|
||||
# define vsnprintf(b,s,f,a) \
|
||||
(GL_LINK_WARNING ("vsnprintf is unportable - " \
|
||||
"use gnulib module vsnprintf for portability"), \
|
||||
vsnprintf (b, s, f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_SPRINTF_POSIX@
|
||||
# if @REPLACE_SPRINTF@
|
||||
# define sprintf rpl_sprintf
|
||||
extern int sprintf (char *str, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef sprintf
|
||||
# define sprintf \
|
||||
(GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
|
||||
"use gnulib module sprintf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
sprintf)
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VSPRINTF_POSIX@
|
||||
# if @REPLACE_VSPRINTF@
|
||||
# define vsprintf rpl_vsprintf
|
||||
extern int vsprintf (char *str, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef vsprintf
|
||||
# define vsprintf(b,f,a) \
|
||||
(GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
|
||||
"use gnulib module vsprintf-posix for portable " \
|
||||
"POSIX compliance"), \
|
||||
vsprintf (b, f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_DPRINTF@
|
||||
# if @REPLACE_DPRINTF@
|
||||
# define dprintf rpl_dprintf
|
||||
# endif
|
||||
# if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
|
||||
extern int dprintf (int fd, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef dprintf
|
||||
# define dprintf(d,f,a) \
|
||||
(GL_LINK_WARNING ("dprintf is unportable - " \
|
||||
"use gnulib module dprintf for portability"), \
|
||||
dprintf (d, f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VDPRINTF@
|
||||
# if @REPLACE_VDPRINTF@
|
||||
# define vdprintf rpl_vdprintf
|
||||
# endif
|
||||
# if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
|
||||
extern int vdprintf (int fd, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef vdprintf
|
||||
# define vdprintf(d,f,a) \
|
||||
(GL_LINK_WARNING ("vdprintf is unportable - " \
|
||||
"use gnulib module vdprintf for portability"), \
|
||||
vdprintf (d, f, a))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_VASPRINTF@
|
||||
# if @REPLACE_VASPRINTF@
|
||||
# define asprintf rpl_asprintf
|
||||
# define vasprintf rpl_vasprintf
|
||||
# endif
|
||||
# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
|
||||
/* Write formatted output to a string dynamically allocated with malloc().
|
||||
If the memory allocation succeeds, store the address of the string in
|
||||
*RESULT and return the number of resulting bytes, excluding the trailing
|
||||
NUL. Upon memory allocation error, or some other error, return -1. */
|
||||
extern int asprintf (char **result, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
extern int vasprintf (char **result, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_OBSTACK_PRINTF@
|
||||
# if @REPLACE_OBSTACK_PRINTF@
|
||||
# define obstack_printf rpl_osbtack_printf
|
||||
# define obstack_vprintf rpl_obstack_vprintf
|
||||
# endif
|
||||
# if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
|
||||
struct obstack;
|
||||
/* Grow an obstack with formatted output. Return the number of
|
||||
bytes added to OBS. No trailing nul byte is added, and the
|
||||
object should be closed with obstack_finish before use. Upon
|
||||
memory allocation error, call obstack_alloc_failed_handler. Upon
|
||||
other error, return -1. */
|
||||
extern int obstack_printf (struct obstack *obs, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
extern int obstack_vprintf (struct obstack *obs, const char *format,
|
||||
va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FOPEN@
|
||||
# if @REPLACE_FOPEN@
|
||||
# undef fopen
|
||||
# define fopen rpl_fopen
|
||||
extern FILE * fopen (const char *filename, const char *mode);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fopen
|
||||
# define fopen(f,m) \
|
||||
(GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
|
||||
"use gnulib module fopen for portability"), \
|
||||
fopen (f, m))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FREOPEN@
|
||||
# if @REPLACE_FREOPEN@
|
||||
# undef freopen
|
||||
# define freopen rpl_freopen
|
||||
extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef freopen
|
||||
# define freopen(f,m,s) \
|
||||
(GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
|
||||
"use gnulib module freopen for portability"), \
|
||||
freopen (f, m, s))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FSEEKO@
|
||||
# if @REPLACE_FSEEKO@
|
||||
/* Provide fseek, fseeko functions that are aware of a preceding
|
||||
fflush(), and which detect pipes. */
|
||||
# define fseeko rpl_fseeko
|
||||
extern int fseeko (FILE *fp, off_t offset, int whence);
|
||||
# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fseeko
|
||||
# define fseeko(f,o,w) \
|
||||
(GL_LINK_WARNING ("fseeko is unportable - " \
|
||||
"use gnulib module fseeko for portability"), \
|
||||
fseeko (f, o, w))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
|
||||
extern int rpl_fseek (FILE *fp, long offset, int whence);
|
||||
# undef fseek
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# define fseek(f,o,w) \
|
||||
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
|
||||
"on 32-bit platforms - " \
|
||||
"use fseeko function for handling of large files"), \
|
||||
rpl_fseek (f, o, w))
|
||||
# else
|
||||
# define fseek rpl_fseek
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# ifndef fseek
|
||||
# define fseek(f,o,w) \
|
||||
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
|
||||
"on 32-bit platforms - " \
|
||||
"use fseeko function for handling of large files"), \
|
||||
fseek (f, o, w))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FTELLO@
|
||||
# if @REPLACE_FTELLO@
|
||||
# define ftello rpl_ftello
|
||||
extern off_t ftello (FILE *fp);
|
||||
# define ftell(fp) ftello (fp)
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef ftello
|
||||
# define ftello(f) \
|
||||
(GL_LINK_WARNING ("ftello is unportable - " \
|
||||
"use gnulib module ftello for portability"), \
|
||||
ftello (f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FTELL@ && @REPLACE_FTELL@
|
||||
extern long rpl_ftell (FILE *fp);
|
||||
# undef ftell
|
||||
# if GNULIB_POSIXCHECK
|
||||
# define ftell(f) \
|
||||
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
|
||||
"on 32-bit platforms - " \
|
||||
"use ftello function for handling of large files"), \
|
||||
rpl_ftell (f))
|
||||
# else
|
||||
# define ftell rpl_ftell
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# ifndef ftell
|
||||
# define ftell(f) \
|
||||
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
|
||||
"on 32-bit platforms - " \
|
||||
"use ftello function for handling of large files"), \
|
||||
ftell (f))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FFLUSH@
|
||||
# if @REPLACE_FFLUSH@
|
||||
# define fflush rpl_fflush
|
||||
/* Flush all pending data on STREAM according to POSIX rules. Both
|
||||
output and seekable input streams are supported.
|
||||
Note! LOSS OF DATA can occur if fflush is applied on an input stream
|
||||
that is _not_seekable_ or on an update stream that is _not_seekable_
|
||||
and in which the most recent operation was input. Seekability can
|
||||
be tested with lseek(fileno(fp),0,SEEK_CUR). */
|
||||
extern int fflush (FILE *gl_stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fflush
|
||||
# define fflush(f) \
|
||||
(GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
|
||||
"use gnulib module fflush for portable " \
|
||||
"POSIX compliance"), \
|
||||
fflush (f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FPURGE@
|
||||
# if @REPLACE_FPURGE@
|
||||
# define fpurge rpl_fpurge
|
||||
# endif
|
||||
# if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
|
||||
/* Discard all pending buffered I/O data on STREAM.
|
||||
STREAM must not be wide-character oriented.
|
||||
Return 0 if successful. Upon error, return -1 and set errno. */
|
||||
extern int fpurge (FILE *gl_stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fpurge
|
||||
# define fpurge(f) \
|
||||
(GL_LINK_WARNING ("fpurge is not always present - " \
|
||||
"use gnulib module fpurge for portability"), \
|
||||
fpurge (f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FCLOSE@
|
||||
# if @REPLACE_FCLOSE@
|
||||
# define fclose rpl_fclose
|
||||
/* Close STREAM and its underlying file descriptor. */
|
||||
extern int fclose (FILE *stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fclose
|
||||
# define fclose(f) \
|
||||
(GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
|
||||
"use gnulib module fclose for portable " \
|
||||
"POSIX compliance"), \
|
||||
fclose (f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef fputc
|
||||
# define fputc rpl_fputc
|
||||
extern int fputc (int c, FILE *stream);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef putc
|
||||
# define putc rpl_fputc
|
||||
extern int putc (int c, FILE *stream);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef putchar
|
||||
# define putchar rpl_putchar
|
||||
extern int putchar (int c);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef fputs
|
||||
# define fputs rpl_fputs
|
||||
extern int fputs (const char *string, FILE *stream);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef puts
|
||||
# define puts rpl_puts
|
||||
extern int puts (const char *string);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
|
||||
# undef fwrite
|
||||
# define fwrite rpl_fwrite
|
||||
extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
|
||||
#endif
|
||||
|
||||
#if @GNULIB_GETDELIM@
|
||||
# if !@HAVE_DECL_GETDELIM@
|
||||
/* Read input, up to (and including) the next occurrence of DELIMITER, from
|
||||
STREAM, store it in *LINEPTR (and NUL-terminate it).
|
||||
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
|
||||
bytes of space. It is realloc'd as necessary.
|
||||
Return the number of bytes read and stored at *LINEPTR (not including the
|
||||
NUL terminator), or -1 on error or EOF. */
|
||||
extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
|
||||
FILE *stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef getdelim
|
||||
# define getdelim(l, s, d, f) \
|
||||
(GL_LINK_WARNING ("getdelim is unportable - " \
|
||||
"use gnulib module getdelim for portability"), \
|
||||
getdelim (l, s, d, f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_GETLINE@
|
||||
# if @REPLACE_GETLINE@
|
||||
# undef getline
|
||||
# define getline rpl_getline
|
||||
# endif
|
||||
# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
|
||||
/* Read a line, up to (and including) the next newline, from STREAM, store it
|
||||
in *LINEPTR (and NUL-terminate it).
|
||||
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
|
||||
bytes of space. It is realloc'd as necessary.
|
||||
Return the number of bytes read and stored at *LINEPTR (not including the
|
||||
NUL terminator), or -1 on error or EOF. */
|
||||
extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef getline
|
||||
# define getline(l, s, f) \
|
||||
(GL_LINK_WARNING ("getline is unportable - " \
|
||||
"use gnulib module getline for portability"), \
|
||||
getline (l, s, f))
|
||||
#endif
|
||||
|
||||
#if @GNULIB_PERROR@
|
||||
# if @REPLACE_PERROR@
|
||||
# define perror rpl_perror
|
||||
/* Print a message to standard error, describing the value of ERRNO,
|
||||
(if STRING is not NULL and not empty) prefixed with STRING and ": ",
|
||||
and terminated with a newline. */
|
||||
extern void perror (const char *string);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef perror
|
||||
# define perror(s) \
|
||||
(GL_LINK_WARNING ("perror is not always POSIX compliant - " \
|
||||
"use gnulib module perror for portability"), \
|
||||
perror (s))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GL_STDIO_H */
|
||||
#endif /* _GL_STDIO_H */
|
||||
#endif
|
5487
lib/vasnprintf.c
Normal file
5487
lib/vasnprintf.c
Normal file
File diff suppressed because it is too large
Load diff
81
lib/vasnprintf.h
Normal file
81
lib/vasnprintf.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* vsprintf with automatic memory allocation.
|
||||
Copyright (C) 2002-2004, 2007-2008 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. */
|
||||
|
||||
#ifndef _VASNPRINTF_H
|
||||
#define _VASNPRINTF_H
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __attribute__
|
||||
/* This feature is available in gcc versions 2.5 and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
/* The __-protected variants of `format' and `printf' attributes
|
||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __format__ format
|
||||
# define __printf__ printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Write formatted output to a string dynamically allocated with malloc().
|
||||
You can pass a preallocated buffer for the result in RESULTBUF and its
|
||||
size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
|
||||
If successful, return the address of the string (this may be = RESULTBUF
|
||||
if no dynamic memory allocation was necessary) and set *LENGTHP to the
|
||||
number of resulting bytes, excluding the trailing NUL. Upon error, set
|
||||
errno and return NULL.
|
||||
|
||||
When dynamic memory allocation occurs, the preallocated buffer is left
|
||||
alone (with possibly modified contents). This makes it possible to use
|
||||
a statically allocated or stack-allocated buffer, like this:
|
||||
|
||||
char buf[100];
|
||||
size_t len = sizeof (buf);
|
||||
char *output = vasnprintf (buf, &len, format, args);
|
||||
if (output == NULL)
|
||||
... error handling ...;
|
||||
else
|
||||
{
|
||||
... use the output string ...;
|
||||
if (output != buf)
|
||||
free (output);
|
||||
}
|
||||
*/
|
||||
#if REPLACE_VASNPRINTF
|
||||
# define asnprintf rpl_asnprintf
|
||||
# define vasnprintf rpl_vasnprintf
|
||||
#endif
|
||||
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VASNPRINTF_H */
|
71
lib/vsnprintf.c
Normal file
71
lib/vsnprintf.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* Formatted output to strings.
|
||||
Copyright (C) 2004, 2006-2008 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 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. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# 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;
|
||||
}
|
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 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. */
|
||||
|
||||
#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 */
|
115
m4/errno_h.m4
Normal file
115
m4/errno_h.m4
Normal file
|
@ -0,0 +1,115 @@
|
|||
# errno_h.m4 serial 6
|
||||
dnl Copyright (C) 2004, 2006, 2008, 2009 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 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_CHECK_NEXT_HEADERS([errno.h])
|
||||
ERRNO_H='errno.h'
|
||||
fi
|
||||
AC_SUBST([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])])
|
||||
])
|
19
m4/float_h.m4
Normal file
19
m4/float_h.m4
Normal file
|
@ -0,0 +1,19 @@
|
|||
# float_h.m4 serial 3
|
||||
dnl Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FLOAT_H],
|
||||
[
|
||||
AC_REQUIRE([AC_PROG_CC])
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
FLOAT_H=
|
||||
case "$host_os" in
|
||||
beos* | openbsd*)
|
||||
FLOAT_H=float.h
|
||||
gl_CHECK_NEXT_HEADERS([float.h])
|
||||
;;
|
||||
esac
|
||||
AC_SUBST([FLOAT_H])
|
||||
])
|
29
m4/getpagesize.m4
Normal file
29
m4/getpagesize.m4
Normal file
|
@ -0,0 +1,29 @@
|
|||
# getpagesize.m4 serial 7
|
||||
dnl Copyright (C) 2002, 2004-2005, 2007 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_GETPAGESIZE],
|
||||
[
|
||||
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_CHECK_FUNCS([getpagesize])
|
||||
if test $ac_cv_func_getpagesize = no; then
|
||||
HAVE_GETPAGESIZE=0
|
||||
AC_CHECK_HEADERS([OS.h])
|
||||
if test $ac_cv_header_OS_h = yes; then
|
||||
HAVE_OS_H=1
|
||||
fi
|
||||
AC_CHECK_HEADERS([sys/param.h])
|
||||
if test $ac_cv_header_sys_param_h = yes; then
|
||||
HAVE_SYS_PARAM_H=1
|
||||
fi
|
||||
fi
|
||||
case "$host_os" in
|
||||
mingw*)
|
||||
REPLACE_GETPAGESIZE=1
|
||||
AC_LIBOBJ([getpagesize])
|
||||
;;
|
||||
esac
|
||||
])
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
|
||||
# Specification in the form of a command-line invocation:
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl --libtool --macro-prefix=gl --no-vc-files alloca-opt autobuild byteswap canonicalize-lgpl count-one-bits environ extensions flock fpieee full-read full-write havelib iconv_open-utf lib-symbol-visibility libunistring putenv stdlib strcase strftime striconveh string
|
||||
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl --libtool --macro-prefix=gl --no-vc-files alloca-opt autobuild byteswap canonicalize-lgpl count-one-bits environ extensions flock fpieee full-read full-write havelib iconv_open-utf lib-symbol-visibility libunistring putenv stdlib strcase strftime striconveh string vsnprintf
|
||||
|
||||
# Specification in the form of a few gnulib-tool.m4 macro invocations:
|
||||
gl_LOCAL_DIR([])
|
||||
|
@ -41,6 +41,7 @@ gl_MODULES([
|
|||
strftime
|
||||
striconveh
|
||||
string
|
||||
vsnprintf
|
||||
])
|
||||
gl_AVOID([])
|
||||
gl_SOURCE_BASE([lib])
|
||||
|
|
|
@ -51,8 +51,12 @@ AC_DEFUN([gl_INIT],
|
|||
gl_COUNT_ONE_BITS
|
||||
gl_ENVIRON
|
||||
gl_UNISTD_MODULE_INDICATOR([environ])
|
||||
gl_HEADER_ERRNO_H
|
||||
gl_FLOAT_H
|
||||
gl_FUNC_FLOCK
|
||||
gl_HEADER_SYS_FILE_MODULE_INDICATOR([flock])
|
||||
gl_FUNC_GETPAGESIZE
|
||||
gl_UNISTD_MODULE_INDICATOR([getpagesize])
|
||||
AM_ICONV
|
||||
gl_ICONV_H
|
||||
gl_FUNC_ICONV_OPEN
|
||||
|
@ -72,6 +76,8 @@ AC_DEFUN([gl_INIT],
|
|||
gl_WCHAR_MODULE_INDICATOR([mbrtowc])
|
||||
gl_FUNC_MBSINIT
|
||||
gl_WCHAR_MODULE_INDICATOR([mbsinit])
|
||||
gl_FUNC_MEMCHR
|
||||
gl_STRING_MODULE_INDICATOR([memchr])
|
||||
gl_MULTIARCH
|
||||
gl_PATHMAX
|
||||
gl_FUNC_PUTENV
|
||||
|
@ -80,9 +86,11 @@ AC_DEFUN([gl_INIT],
|
|||
gl_UNISTD_MODULE_INDICATOR([readlink])
|
||||
gl_SAFE_READ
|
||||
gl_SAFE_WRITE
|
||||
gl_SIZE_MAX
|
||||
gt_TYPE_SSIZE_T
|
||||
AM_STDBOOL_H
|
||||
gl_STDINT_H
|
||||
gl_STDIO_H
|
||||
gl_STDLIB_H
|
||||
gl_STRCASE
|
||||
gl_FUNC_GNU_STRFTIME
|
||||
|
@ -101,9 +109,13 @@ AC_DEFUN([gl_INIT],
|
|||
gl_MODULE_INDICATOR([unistr/u8-mbtouc-unsafe])
|
||||
gl_MODULE_INDICATOR([unistr/u8-mbtoucr])
|
||||
gl_MODULE_INDICATOR([unistr/u8-uctomb])
|
||||
gl_FUNC_VASNPRINTF
|
||||
gl_FUNC_VSNPRINTF
|
||||
gl_STDIO_MODULE_INDICATOR([vsnprintf])
|
||||
gl_WCHAR_H
|
||||
gl_FUNC_WRITE
|
||||
gl_UNISTD_MODULE_INDICATOR([write])
|
||||
gl_XSIZE
|
||||
m4_ifval(gl_LIBSOURCES_LIST, [
|
||||
m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
|
||||
for gl_file in ]gl_LIBSOURCES_LIST[ ; do
|
||||
|
@ -235,6 +247,7 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
build-aux/config.rpath
|
||||
build-aux/link-warning.h
|
||||
lib/alloca.in.h
|
||||
lib/asnprintf.c
|
||||
lib/byteswap.in.h
|
||||
lib/c-ctype.c
|
||||
lib/c-ctype.h
|
||||
|
@ -246,11 +259,15 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/canonicalize.h
|
||||
lib/config.charset
|
||||
lib/count-one-bits.h
|
||||
lib/errno.in.h
|
||||
lib/float+.h
|
||||
lib/float.in.h
|
||||
lib/flock.c
|
||||
lib/full-read.c
|
||||
lib/full-read.h
|
||||
lib/full-write.c
|
||||
lib/full-write.h
|
||||
lib/getpagesize.c
|
||||
lib/iconv.c
|
||||
lib/iconv.in.h
|
||||
lib/iconv_close.c
|
||||
|
@ -269,7 +286,13 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/mbrlen.c
|
||||
lib/mbrtowc.c
|
||||
lib/mbsinit.c
|
||||
lib/memchr.c
|
||||
lib/memchr.valgrind
|
||||
lib/pathmax.h
|
||||
lib/printf-args.c
|
||||
lib/printf-args.h
|
||||
lib/printf-parse.c
|
||||
lib/printf-parse.h
|
||||
lib/putenv.c
|
||||
lib/readlink.c
|
||||
lib/ref-add.sin
|
||||
|
@ -278,8 +301,11 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/safe-read.h
|
||||
lib/safe-write.c
|
||||
lib/safe-write.h
|
||||
lib/size_max.h
|
||||
lib/stdbool.in.h
|
||||
lib/stdint.in.h
|
||||
lib/stdio-write.c
|
||||
lib/stdio.in.h
|
||||
lib/stdlib.in.h
|
||||
lib/strcasecmp.c
|
||||
lib/streq.h
|
||||
|
@ -304,9 +330,13 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
lib/unistr/u8-uctomb-aux.c
|
||||
lib/unistr/u8-uctomb.c
|
||||
lib/unitypes.h
|
||||
lib/vasnprintf.c
|
||||
lib/vasnprintf.h
|
||||
lib/verify.h
|
||||
lib/vsnprintf.c
|
||||
lib/wchar.in.h
|
||||
lib/write.c
|
||||
lib/xsize.h
|
||||
m4/00gnulib.m4
|
||||
m4/alloca.m4
|
||||
m4/autobuild.m4
|
||||
|
@ -316,9 +346,12 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/count-one-bits.m4
|
||||
m4/eealloc.m4
|
||||
m4/environ.m4
|
||||
m4/errno_h.m4
|
||||
m4/extensions.m4
|
||||
m4/float_h.m4
|
||||
m4/flock.m4
|
||||
m4/fpieee.m4
|
||||
m4/getpagesize.m4
|
||||
m4/glibc21.m4
|
||||
m4/gnulib-common.m4
|
||||
m4/iconv.m4
|
||||
|
@ -326,6 +359,8 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/iconv_open.m4
|
||||
m4/include_next.m4
|
||||
m4/inline.m4
|
||||
m4/intmax_t.m4
|
||||
m4/inttypes_h.m4
|
||||
m4/lib-ld.m4
|
||||
m4/lib-link.m4
|
||||
m4/lib-prefix.m4
|
||||
|
@ -341,15 +376,21 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/mbrtowc.m4
|
||||
m4/mbsinit.m4
|
||||
m4/mbstate_t.m4
|
||||
m4/memchr.m4
|
||||
m4/mmap-anon.m4
|
||||
m4/multiarch.m4
|
||||
m4/pathmax.m4
|
||||
m4/printf.m4
|
||||
m4/putenv.m4
|
||||
m4/readlink.m4
|
||||
m4/safe-read.m4
|
||||
m4/safe-write.m4
|
||||
m4/size_max.m4
|
||||
m4/ssize_t.m4
|
||||
m4/stdbool.m4
|
||||
m4/stdint.m4
|
||||
m4/stdint_h.m4
|
||||
m4/stdio_h.m4
|
||||
m4/stdlib_h.m4
|
||||
m4/strcase.m4
|
||||
m4/strftime.m4
|
||||
|
@ -360,8 +401,12 @@ AC_DEFUN([gl_FILE_LIST], [
|
|||
m4/time_r.m4
|
||||
m4/tm_gmtoff.m4
|
||||
m4/unistd_h.m4
|
||||
m4/vasnprintf.m4
|
||||
m4/visibility.m4
|
||||
m4/vsnprintf.m4
|
||||
m4/wchar.m4
|
||||
m4/wchar_t.m4
|
||||
m4/wint_t.m4
|
||||
m4/write.m4
|
||||
m4/xsize.m4
|
||||
])
|
||||
|
|
61
m4/intmax_t.m4
Normal file
61
m4/intmax_t.m4
Normal file
|
@ -0,0 +1,61 @@
|
|||
# intmax_t.m4 serial 7
|
||||
dnl Copyright (C) 1997-2004, 2006-2007, 2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Paul Eggert.
|
||||
|
||||
AC_PREREQ([2.13])
|
||||
|
||||
# Define intmax_t to 'long' or 'long long'
|
||||
# if it is not already defined in <stdint.h> or <inttypes.h>.
|
||||
|
||||
AC_DEFUN([gl_AC_TYPE_INTMAX_T],
|
||||
[
|
||||
dnl For simplicity, we assume that a header file defines 'intmax_t' if and
|
||||
dnl only if it defines 'uintmax_t'.
|
||||
AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
|
||||
AC_REQUIRE([gl_AC_HEADER_STDINT_H])
|
||||
if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
|
||||
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
|
||||
test $ac_cv_type_long_long_int = yes \
|
||||
&& ac_type='long long' \
|
||||
|| ac_type='long'
|
||||
AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
|
||||
[Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
|
||||
else
|
||||
AC_DEFINE([HAVE_INTMAX_T], [1],
|
||||
[Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
|
||||
fi
|
||||
])
|
||||
|
||||
dnl An alternative would be to explicitly test for 'intmax_t'.
|
||||
|
||||
AC_DEFUN([gt_AC_TYPE_INTMAX_T],
|
||||
[
|
||||
AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
|
||||
AC_REQUIRE([gl_AC_HEADER_STDINT_H])
|
||||
AC_CACHE_CHECK([for intmax_t], [gt_cv_c_intmax_t],
|
||||
[AC_TRY_COMPILE([
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_STDINT_H_WITH_UINTMAX
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#if HAVE_INTTYPES_H_WITH_UINTMAX
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
|
||||
if test $gt_cv_c_intmax_t = yes; then
|
||||
AC_DEFINE([HAVE_INTMAX_T], [1],
|
||||
[Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
|
||||
else
|
||||
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
|
||||
test $ac_cv_type_long_long_int = yes \
|
||||
&& ac_type='long long' \
|
||||
|| ac_type='long'
|
||||
AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
|
||||
[Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
|
||||
fi
|
||||
])
|
26
m4/inttypes_h.m4
Normal file
26
m4/inttypes_h.m4
Normal file
|
@ -0,0 +1,26 @@
|
|||
# inttypes_h.m4 serial 9
|
||||
dnl Copyright (C) 1997-2004, 2006, 2008, 2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Paul Eggert.
|
||||
|
||||
# Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
|
||||
# doesn't clash with <sys/types.h>, and declares uintmax_t.
|
||||
|
||||
AC_DEFUN([gl_AC_HEADER_INTTYPES_H],
|
||||
[
|
||||
AC_CACHE_CHECK([for inttypes.h], [gl_cv_header_inttypes_h],
|
||||
[AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>
|
||||
#include <inttypes.h>],
|
||||
[uintmax_t i = (uintmax_t) -1; return !i;],
|
||||
[gl_cv_header_inttypes_h=yes],
|
||||
[gl_cv_header_inttypes_h=no])])
|
||||
if test $gl_cv_header_inttypes_h = yes; then
|
||||
AC_DEFINE_UNQUOTED([HAVE_INTTYPES_H_WITH_UINTMAX], [1],
|
||||
[Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
|
||||
and declares uintmax_t. ])
|
||||
fi
|
||||
])
|
|
@ -1,4 +1,4 @@
|
|||
# lib-link.m4 serial 19 (gettext-0.18)
|
||||
# lib-link.m4 serial 20 (gettext-0.18)
|
||||
dnl Copyright (C) 2001-2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
|
@ -82,7 +82,7 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
|
|||
])
|
||||
if test "$ac_cv_lib[]Name" = yes; then
|
||||
HAVE_LIB[]NAME=yes
|
||||
AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib[]$1 library.])
|
||||
AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
|
||||
AC_MSG_CHECKING([how to link with lib[]$1])
|
||||
AC_MSG_RESULT([$LIB[]NAME])
|
||||
else
|
||||
|
@ -210,6 +210,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
|
|||
LTLIB[]NAME=
|
||||
INC[]NAME=
|
||||
LIB[]NAME[]_PREFIX=
|
||||
dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
|
||||
dnl computed. So it has to be reset here.
|
||||
HAVE_LIB[]NAME=
|
||||
rpathdirs=
|
||||
ltrpathdirs=
|
||||
names_already_handled=
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# mbrtowc.m4 serial 15
|
||||
# mbrtowc.m4 serial 16
|
||||
dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
|
@ -156,6 +156,7 @@ changequote([,])dnl
|
|||
if test $LOCALE_ZH_CN != none; then
|
||||
AC_TRY_RUN([
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
int main ()
|
||||
|
|
86
m4/memchr.m4
Normal file
86
m4/memchr.m4
Normal file
|
@ -0,0 +1,86 @@
|
|||
# memchr.m4 serial 7
|
||||
dnl Copyright (C) 2002, 2003, 2004, 2009 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_FUNC_MEMCHR],
|
||||
[
|
||||
dnl Check for prerequisites for memory fence checks.
|
||||
gl_FUNC_MMAP_ANON
|
||||
AC_CHECK_HEADERS_ONCE([sys/mman.h])
|
||||
AC_CHECK_FUNCS_ONCE([mprotect])
|
||||
|
||||
dnl These days, we assume memchr is present. But just in case...
|
||||
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
|
||||
AC_REPLACE_FUNCS([memchr])
|
||||
if test $ac_cv_func_memchr = no; then
|
||||
gl_PREREQ_MEMCHR
|
||||
REPLACE_MEMCHR=1
|
||||
fi
|
||||
|
||||
if test $ac_cv_func_memchr = yes; then
|
||||
# Detect platform-specific bugs in some versions of glibc:
|
||||
# memchr should not dereference anything with length 0
|
||||
# http://bugzilla.redhat.com/499689
|
||||
# memchr should not dereference overestimated length after a match
|
||||
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
|
||||
# http://sourceware.org/bugzilla/show_bug.cgi?id=10162
|
||||
# Assume that memchr works on platforms that lack mprotect.
|
||||
AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
|
||||
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <string.h>
|
||||
#if HAVE_SYS_MMAN_H
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/mman.h>
|
||||
# ifndef MAP_FILE
|
||||
# define MAP_FILE 0
|
||||
# endif
|
||||
#endif
|
||||
]], [[
|
||||
char *fence = NULL;
|
||||
#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
|
||||
# if HAVE_MAP_ANONYMOUS
|
||||
const int flags = MAP_ANONYMOUS | MAP_PRIVATE;
|
||||
const int fd = -1;
|
||||
# else /* !HAVE_MAP_ANONYMOUS */
|
||||
const int flags = MAP_FILE | MAP_PRIVATE;
|
||||
int fd = open ("/dev/zero", O_RDONLY, 0666);
|
||||
if (fd >= 0)
|
||||
# endif
|
||||
{
|
||||
int pagesize = getpagesize ();
|
||||
char *two_pages =
|
||||
(char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
|
||||
flags, fd, 0);
|
||||
if (two_pages != (char *)(-1)
|
||||
&& mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
|
||||
fence = two_pages + pagesize;
|
||||
}
|
||||
#endif
|
||||
if (fence)
|
||||
{
|
||||
if (memchr (fence, 0, 0))
|
||||
return 1;
|
||||
strcpy (fence - 9, "12345678");
|
||||
if (memchr (fence - 9, 0, 79) != fence - 1)
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no],
|
||||
[dnl Be pessimistic for now.
|
||||
gl_cv_func_memchr_works="guessing no"])])
|
||||
if test "$gl_cv_func_memchr_works" != yes; then
|
||||
gl_PREREQ_MEMCHR
|
||||
REPLACE_MEMCHR=1
|
||||
AC_LIBOBJ([memchr])
|
||||
fi
|
||||
fi
|
||||
])
|
||||
|
||||
# Prerequisites of lib/memchr.c.
|
||||
AC_DEFUN([gl_PREREQ_MEMCHR], [
|
||||
AC_CHECK_HEADERS([bp-sym.h])
|
||||
])
|
59
m4/mmap-anon.m4
Normal file
59
m4/mmap-anon.m4
Normal file
|
@ -0,0 +1,59 @@
|
|||
# mmap-anon.m4 serial 8
|
||||
dnl Copyright (C) 2005, 2007, 2009 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.
|
||||
|
||||
# Detect how mmap can be used to create anonymous (not file-backed) memory
|
||||
# mappings.
|
||||
# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
|
||||
# and MAP_ANON exist and have the same value.
|
||||
# - On HP-UX, only MAP_ANONYMOUS exists.
|
||||
# - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
|
||||
# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
|
||||
# used.
|
||||
|
||||
AC_DEFUN([gl_FUNC_MMAP_ANON],
|
||||
[
|
||||
dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
|
||||
AC_REQUIRE([AC_PROG_CPP])
|
||||
AC_REQUIRE([AC_PROG_EGREP])
|
||||
|
||||
dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
|
||||
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
|
||||
|
||||
# Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
|
||||
# fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
|
||||
# irrelevant for anonymous mappings.
|
||||
AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
|
||||
|
||||
# Try to allow MAP_ANONYMOUS.
|
||||
gl_have_mmap_anonymous=no
|
||||
if test $gl_have_mmap = yes; then
|
||||
AC_MSG_CHECKING([for MAP_ANONYMOUS])
|
||||
AC_EGREP_CPP([I cant identify this map.], [
|
||||
#include <sys/mman.h>
|
||||
#ifdef MAP_ANONYMOUS
|
||||
I cant identify this map.
|
||||
#endif
|
||||
],
|
||||
[gl_have_mmap_anonymous=yes])
|
||||
if test $gl_have_mmap_anonymous != yes; then
|
||||
AC_EGREP_CPP([I cant identify this map.], [
|
||||
#include <sys/mman.h>
|
||||
#ifdef MAP_ANON
|
||||
I cant identify this map.
|
||||
#endif
|
||||
],
|
||||
[AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
|
||||
[Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
|
||||
gl_have_mmap_anonymous=yes])
|
||||
fi
|
||||
AC_MSG_RESULT([$gl_have_mmap_anonymous])
|
||||
if test $gl_have_mmap_anonymous = yes; then
|
||||
AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
|
||||
[Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
|
||||
config.h and <sys/mman.h>.])
|
||||
fi
|
||||
fi
|
||||
])
|
1416
m4/printf.m4
Normal file
1416
m4/printf.m4
Normal file
File diff suppressed because it is too large
Load diff
75
m4/size_max.m4
Normal file
75
m4/size_max.m4
Normal file
|
@ -0,0 +1,75 @@
|
|||
# size_max.m4 serial 9
|
||||
dnl Copyright (C) 2003, 2005-2006, 2008-2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Bruno Haible.
|
||||
|
||||
AC_DEFUN([gl_SIZE_MAX],
|
||||
[
|
||||
AC_CHECK_HEADERS([stdint.h])
|
||||
dnl First test whether the system already has SIZE_MAX.
|
||||
AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
|
||||
gl_cv_size_max=
|
||||
AC_EGREP_CPP([Found it], [
|
||||
#include <limits.h>
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef SIZE_MAX
|
||||
Found it
|
||||
#endif
|
||||
], [gl_cv_size_max=yes])
|
||||
if test -z "$gl_cv_size_max"; then
|
||||
dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
|
||||
dnl than the type 'unsigned long'. Try hard to find a definition that can
|
||||
dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
|
||||
AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1],
|
||||
[#include <stddef.h>
|
||||
#include <limits.h>], [size_t_bits_minus_1=])
|
||||
AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)],
|
||||
[#include <stddef.h>], [fits_in_uint=])
|
||||
if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
|
||||
if test $fits_in_uint = 1; then
|
||||
dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
|
||||
dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
|
||||
AC_TRY_COMPILE([#include <stddef.h>
|
||||
extern size_t foo;
|
||||
extern unsigned long foo;
|
||||
], [], [fits_in_uint=0])
|
||||
fi
|
||||
dnl We cannot use 'expr' to simplify this expression, because 'expr'
|
||||
dnl works only with 'long' integers in the host environment, while we
|
||||
dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
|
||||
if test $fits_in_uint = 1; then
|
||||
gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
|
||||
else
|
||||
gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
|
||||
fi
|
||||
else
|
||||
dnl Shouldn't happen, but who knows...
|
||||
gl_cv_size_max='((size_t)~(size_t)0)'
|
||||
fi
|
||||
fi
|
||||
])
|
||||
if test "$gl_cv_size_max" != yes; then
|
||||
AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
|
||||
[Define as the maximum value of type 'size_t', if the system doesn't define it.])
|
||||
fi
|
||||
dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after
|
||||
dnl <stdint.h>. Remember that the #undef in AH_VERBATIM gets replaced with
|
||||
dnl #define by AC_DEFINE_UNQUOTED.
|
||||
AH_VERBATIM([SIZE_MAX],
|
||||
[/* Define as the maximum value of type 'size_t', if the system doesn't define
|
||||
it. */
|
||||
#ifndef SIZE_MAX
|
||||
# undef SIZE_MAX
|
||||
#endif])
|
||||
])
|
||||
|
||||
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])])
|
||||
])
|
26
m4/stdint_h.m4
Normal file
26
m4/stdint_h.m4
Normal file
|
@ -0,0 +1,26 @@
|
|||
# stdint_h.m4 serial 8
|
||||
dnl Copyright (C) 1997-2004, 2006, 2008, 2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Paul Eggert.
|
||||
|
||||
# Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
|
||||
# doesn't clash with <sys/types.h>, and declares uintmax_t.
|
||||
|
||||
AC_DEFUN([gl_AC_HEADER_STDINT_H],
|
||||
[
|
||||
AC_CACHE_CHECK([for stdint.h], [gl_cv_header_stdint_h],
|
||||
[AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>
|
||||
#include <stdint.h>],
|
||||
[uintmax_t i = (uintmax_t) -1; return !i;],
|
||||
[gl_cv_header_stdint_h=yes],
|
||||
[gl_cv_header_stdint_h=no])])
|
||||
if test $gl_cv_header_stdint_h = yes; then
|
||||
AC_DEFINE_UNQUOTED([HAVE_STDINT_H_WITH_UINTMAX], [1],
|
||||
[Define if <stdint.h> exists, doesn't clash with <sys/types.h>,
|
||||
and declares uintmax_t. ])
|
||||
fi
|
||||
])
|
136
m4/stdio_h.m4
Normal file
136
m4/stdio_h.m4
Normal file
|
@ -0,0 +1,136 @@
|
|||
# stdio_h.m4 serial 16
|
||||
dnl Copyright (C) 2007-2009 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_STDIO_H],
|
||||
[
|
||||
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
|
||||
gl_CHECK_NEXT_HEADERS([stdio.h])
|
||||
dnl No need to create extra modules for these functions. Everyone who uses
|
||||
dnl <stdio.h> likely needs them.
|
||||
GNULIB_FPRINTF=1
|
||||
GNULIB_PRINTF=1
|
||||
GNULIB_VFPRINTF=1
|
||||
GNULIB_VPRINTF=1
|
||||
GNULIB_FPUTC=1
|
||||
GNULIB_PUTC=1
|
||||
GNULIB_PUTCHAR=1
|
||||
GNULIB_FPUTS=1
|
||||
GNULIB_PUTS=1
|
||||
GNULIB_FWRITE=1
|
||||
dnl This ifdef is just an optimization, to avoid performing a configure
|
||||
dnl check whose result is not used. It does not make the test of
|
||||
dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
|
||||
m4_ifdef([gl_SIGNAL_SIGPIPE], [
|
||||
gl_SIGNAL_SIGPIPE
|
||||
if test $gl_cv_header_signal_h_SIGPIPE != yes; then
|
||||
REPLACE_STDIO_WRITE_FUNCS=1
|
||||
AC_LIBOBJ([stdio-write])
|
||||
fi
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
|
||||
[
|
||||
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
|
||||
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
|
||||
GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_STDIO_H_DEFAULTS],
|
||||
[
|
||||
GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF])
|
||||
GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
|
||||
GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF])
|
||||
GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
|
||||
GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
|
||||
GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
|
||||
GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
|
||||
GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
|
||||
GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF])
|
||||
GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
|
||||
GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
|
||||
GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
|
||||
GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF])
|
||||
GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF])
|
||||
GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
|
||||
GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF])
|
||||
GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
|
||||
GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN])
|
||||
GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN])
|
||||
GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
|
||||
GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
|
||||
GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
|
||||
GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
|
||||
GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
|
||||
GNULIB_FPURGE=0; AC_SUBST([GNULIB_FPURGE])
|
||||
GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
|
||||
GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
|
||||
GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
|
||||
GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
|
||||
GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS])
|
||||
GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS])
|
||||
GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE])
|
||||
GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM])
|
||||
GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE])
|
||||
GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR])
|
||||
GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
|
||||
dnl Assume proper GNU behavior unless another module says otherwise.
|
||||
REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
|
||||
REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
|
||||
REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
|
||||
REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
|
||||
REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
|
||||
REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
|
||||
HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
|
||||
REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
|
||||
HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
|
||||
REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
|
||||
REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])
|
||||
HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF])
|
||||
REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF])
|
||||
HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
|
||||
REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF])
|
||||
HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
|
||||
REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
|
||||
HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
|
||||
REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF])
|
||||
REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
|
||||
REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
|
||||
HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
|
||||
REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
|
||||
REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
|
||||
HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
|
||||
REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
|
||||
REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
|
||||
REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
|
||||
REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
|
||||
HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
|
||||
REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
|
||||
HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
|
||||
HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
|
||||
REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
|
||||
REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR])
|
||||
])
|
||||
|
||||
dnl Code shared by fseeko and ftello. Determine if large files are supported,
|
||||
dnl but stdin does not start as a large file by default.
|
||||
AC_DEFUN([gl_STDIN_LARGE_OFFSET],
|
||||
[
|
||||
AC_CACHE_CHECK([whether stdin defaults to large file offsets],
|
||||
[gl_cv_var_stdin_large_offset],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
|
||||
[[#if defined __SL64 && defined __SCLE /* cygwin */
|
||||
/* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
|
||||
fseeko/ftello needlessly fail. This bug was fixed in 1.5.25, and
|
||||
it is easier to do a version check than building a runtime test. */
|
||||
# include <cygwin/version.h>
|
||||
# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
|
||||
choke me
|
||||
# endif
|
||||
#endif]])],
|
||||
[gl_cv_var_stdin_large_offset=yes],
|
||||
[gl_cv_var_stdin_large_offset=no])])
|
||||
])
|
276
m4/vasnprintf.m4
Normal file
276
m4/vasnprintf.m4
Normal file
|
@ -0,0 +1,276 @@
|
|||
# vasnprintf.m4 serial 29
|
||||
dnl Copyright (C) 2002-2004, 2006-2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_VASNPRINTF],
|
||||
[
|
||||
AC_CHECK_FUNCS_ONCE([vasnprintf])
|
||||
if test $ac_cv_func_vasnprintf = no; then
|
||||
gl_REPLACE_VASNPRINTF
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_REPLACE_VASNPRINTF],
|
||||
[
|
||||
AC_CHECK_FUNCS_ONCE([vasnprintf])
|
||||
AC_LIBOBJ([vasnprintf])
|
||||
AC_LIBOBJ([printf-args])
|
||||
AC_LIBOBJ([printf-parse])
|
||||
AC_LIBOBJ([asnprintf])
|
||||
if test $ac_cv_func_vasnprintf = yes; then
|
||||
AC_DEFINE([REPLACE_VASNPRINTF], [1],
|
||||
[Define if vasnprintf exists but is overridden by gnulib.])
|
||||
fi
|
||||
gl_PREREQ_PRINTF_ARGS
|
||||
gl_PREREQ_PRINTF_PARSE
|
||||
gl_PREREQ_VASNPRINTF
|
||||
gl_PREREQ_ASNPRINTF
|
||||
])
|
||||
|
||||
# Prequisites of lib/printf-args.h, lib/printf-args.c.
|
||||
AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
|
||||
[
|
||||
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
|
||||
AC_REQUIRE([gt_TYPE_WCHAR_T])
|
||||
AC_REQUIRE([gt_TYPE_WINT_T])
|
||||
])
|
||||
|
||||
# Prequisites of lib/printf-parse.h, lib/printf-parse.c.
|
||||
AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
|
||||
[
|
||||
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
|
||||
AC_REQUIRE([gt_TYPE_WCHAR_T])
|
||||
AC_REQUIRE([gt_TYPE_WINT_T])
|
||||
AC_REQUIRE([AC_TYPE_SIZE_T])
|
||||
AC_CHECK_TYPE([ptrdiff_t], ,
|
||||
[AC_DEFINE([ptrdiff_t], [long],
|
||||
[Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
|
||||
])
|
||||
AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
|
||||
])
|
||||
|
||||
# Prerequisites of lib/vasnprintf.c.
|
||||
AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
|
||||
[
|
||||
AC_REQUIRE([AC_FUNC_ALLOCA])
|
||||
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
|
||||
AC_REQUIRE([gt_TYPE_WCHAR_T])
|
||||
AC_REQUIRE([gt_TYPE_WINT_T])
|
||||
AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
|
||||
dnl Use the _snprintf function only if it is declared (because on NetBSD it
|
||||
dnl is defined as a weak alias of snprintf; we prefer to use the latter).
|
||||
AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>])
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
|
||||
# arguments.
|
||||
AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
|
||||
case "$gl_cv_func_printf_long_double" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
'long double' arguments.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
|
||||
# arguments.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_INFINITE])
|
||||
case "$gl_cv_func_printf_infinite" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
infinite 'double' arguments.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
|
||||
# arguments.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
|
||||
dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
|
||||
dnl NEED_PRINTF_LONG_DOUBLE is already set.
|
||||
AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
|
||||
case "$gl_cv_func_printf_long_double" in
|
||||
*yes)
|
||||
case "$gl_cv_func_printf_infinite_long_double" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
infinite 'long double' arguments.])
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
|
||||
case "$gl_cv_func_printf_directive_a" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
the 'a' and 'A' directives.])
|
||||
AC_CHECK_FUNCS([nl_langinfo])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
|
||||
case "$gl_cv_func_printf_directive_f" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
the 'F' directive.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
|
||||
case "$gl_cv_func_printf_directive_ls" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
the 'ls' directive.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
|
||||
case "$gl_cv_func_printf_flag_grouping" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
|
||||
[Define if the vasnprintf implementation needs special code for the
|
||||
' flag.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
|
||||
case "$gl_cv_func_printf_flag_leftadjust" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1],
|
||||
[Define if the vasnprintf implementation needs special code for the
|
||||
'-' flag.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
|
||||
case "$gl_cv_func_printf_flag_zero" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1],
|
||||
[Define if the vasnprintf implementation needs special code for the
|
||||
0 flag.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_PRECISION])
|
||||
case "$gl_cv_func_printf_precision" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
supporting large precisions without arbitrary bounds.])
|
||||
AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
'double' arguments.])
|
||||
AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
'long double' arguments.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory
|
||||
# conditions.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
|
||||
[
|
||||
AC_REQUIRE([gl_PRINTF_ENOMEM])
|
||||
case "$gl_cv_func_printf_enomem" in
|
||||
*yes)
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE([NEED_PRINTF_ENOMEM], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
surviving out-of-memory conditions.])
|
||||
AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
'double' arguments.])
|
||||
AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
|
||||
[Define if the vasnprintf implementation needs special code for
|
||||
'long double' arguments.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
|
||||
AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
|
||||
[
|
||||
AC_REQUIRE([gl_PREREQ_VASNPRINTF])
|
||||
gl_PREREQ_VASNPRINTF_LONG_DOUBLE
|
||||
gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
|
||||
gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
|
||||
gl_PREREQ_VASNPRINTF_DIRECTIVE_A
|
||||
gl_PREREQ_VASNPRINTF_DIRECTIVE_F
|
||||
gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
|
||||
gl_PREREQ_VASNPRINTF_FLAG_GROUPING
|
||||
gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
|
||||
gl_PREREQ_VASNPRINTF_FLAG_ZERO
|
||||
gl_PREREQ_VASNPRINTF_PRECISION
|
||||
gl_PREREQ_VASNPRINTF_ENOMEM
|
||||
])
|
||||
|
||||
# Prerequisites of lib/asnprintf.c.
|
||||
AC_DEFUN([gl_PREREQ_ASNPRINTF],
|
||||
[
|
||||
])
|
40
m4/vsnprintf.m4
Normal file
40
m4/vsnprintf.m4
Normal file
|
@ -0,0 +1,40 @@
|
|||
# vsnprintf.m4 serial 5
|
||||
dnl Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_FUNC_VSNPRINTF],
|
||||
[
|
||||
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
|
||||
gl_cv_func_vsnprintf_usable=no
|
||||
AC_CHECK_FUNCS([vsnprintf])
|
||||
if test $ac_cv_func_vsnprintf = yes; then
|
||||
gl_SNPRINTF_SIZE1
|
||||
case "$gl_cv_func_snprintf_size1" in
|
||||
*yes)
|
||||
gl_cv_func_vsnprintf_usable=yes
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if test $gl_cv_func_vsnprintf_usable = no; then
|
||||
gl_REPLACE_VSNPRINTF
|
||||
fi
|
||||
AC_CHECK_DECLS_ONCE([vsnprintf])
|
||||
if test $ac_cv_have_decl_vsnprintf = no; then
|
||||
HAVE_DECL_VSNPRINTF=0
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([gl_REPLACE_VSNPRINTF],
|
||||
[
|
||||
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
|
||||
AC_LIBOBJ([vsnprintf])
|
||||
if test $ac_cv_func_vsnprintf = yes; then
|
||||
REPLACE_VSNPRINTF=1
|
||||
fi
|
||||
gl_PREREQ_VSNPRINTF
|
||||
])
|
||||
|
||||
# Prerequisites of lib/vsnprintf.c.
|
||||
AC_DEFUN([gl_PREREQ_VSNPRINTF], [:])
|
20
m4/wchar_t.m4
Normal file
20
m4/wchar_t.m4
Normal file
|
@ -0,0 +1,20 @@
|
|||
# wchar_t.m4 serial 3 (gettext-0.18)
|
||||
dnl Copyright (C) 2002-2003, 2008, 2009 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Bruno Haible.
|
||||
dnl Test whether <stddef.h> has the 'wchar_t' type.
|
||||
dnl Prerequisite: AC_PROG_CC
|
||||
|
||||
AC_DEFUN([gt_TYPE_WCHAR_T],
|
||||
[
|
||||
AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t],
|
||||
[AC_TRY_COMPILE([#include <stddef.h>
|
||||
wchar_t foo = (wchar_t)'\0';], ,
|
||||
[gt_cv_c_wchar_t=yes], [gt_cv_c_wchar_t=no])])
|
||||
if test $gt_cv_c_wchar_t = yes; then
|
||||
AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.])
|
||||
fi
|
||||
])
|
13
m4/xsize.m4
Normal file
13
m4/xsize.m4
Normal file
|
@ -0,0 +1,13 @@
|
|||
# xsize.m4 serial 4
|
||||
dnl Copyright (C) 2003-2004, 2008 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_XSIZE],
|
||||
[
|
||||
dnl Prerequisites of lib/xsize.h.
|
||||
AC_REQUIRE([gl_SIZE_MAX])
|
||||
AC_REQUIRE([AC_C_INLINE])
|
||||
AC_CHECK_HEADERS([stdint.h])
|
||||
])
|
Loading…
Add table
Add a link
Reference in a new issue