diff options
Diffstat (limited to 'Build/source/libs/mpfr/mpfr-src/src/printf.c')
-rw-r--r-- | Build/source/libs/mpfr/mpfr-src/src/printf.c | 69 |
1 files changed, 29 insertions, 40 deletions
diff --git a/Build/source/libs/mpfr/mpfr-src/src/printf.c b/Build/source/libs/mpfr/mpfr-src/src/printf.c index 3a554e70457..0888c1d02ae 100644 --- a/Build/source/libs/mpfr/mpfr-src/src/printf.c +++ b/Build/source/libs/mpfr/mpfr-src/src/printf.c @@ -1,4 +1,4 @@ -/* mpfr_printf -- printf function and friends. +/* Formatted output functions (printf functions family). Copyright 2007-2017 Free Software Foundation, Inc. Contributed by the AriC and Caramba projects, INRIA. @@ -21,11 +21,12 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif -/* The mpfr_printf-like functions are defined only if <stdarg.h> exists */ -#ifdef HAVE_STDARG +/* The mpfr_printf-like functions are defined only if <stdarg.h> exists. + Since they use mpf_t, they cannot be defined with mini-gmp. */ +#if defined(HAVE_STDARG) && !defined(MPFR_USE_MINI_GMP) #include <stdarg.h> @@ -44,12 +45,12 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #ifdef _MPFR_H_HAVE_FILE -/* Each printf-like function calls mpfr_vasprintf which - - returns the number of characters in the returned string excluding the - terminating null - - returns -1 and sets the erange flag if the number of produced characters - exceeds INT_MAX (in that case, also sets errno to EOVERFLOW in POSIX - systems) */ +/* Each printf-like function calls mpfr_vasnprintf_aux (directly or + via mpfr_vasprintf), which + - returns the number of characters to be written excluding the + terminating null character (disregarding the size argument); + - returns -1 and sets the erange flag if this number exceeds INT_MAX + (in that case, also sets errno to EOVERFLOW on POSIX systems). */ #define GET_STR_VA(sz, str, fmt, ap) \ do \ @@ -130,6 +131,7 @@ mpfr_vfprintf (FILE *fp, const char *fmt, va_list ap) mpfr_free_str (str); return ret; } + #endif /* _MPFR_H_HAVE_FILE */ int @@ -161,45 +163,20 @@ mpfr_vsprintf (char *buf, const char *fmt, va_list ap) int mpfr_snprintf (char *buf, size_t size, const char *fmt, ...) { - char *str; int ret; - size_t min_size; + va_list ap; - GET_STR (ret, str, fmt); + va_start(ap, fmt); + ret = mpfr_vasnprintf_aux (NULL, buf, size, fmt, ap); + va_end (ap); - /* C99 allows SIZE to be zero */ - if (size != 0) - { - MPFR_ASSERTN (buf != NULL); - min_size = (size_t)ret < size ? (size_t)ret : size - 1; - strncpy (buf, str, min_size); - buf[min_size] = '\0'; - } - - mpfr_free_str (str); return ret; } int mpfr_vsnprintf (char *buf, size_t size, const char *fmt, va_list ap) { - char *str; - int ret; - int min_size; - - GET_STR_VA (ret, str, fmt, ap); - - /* C99 allows SIZE to be zero */ - if (size != 0) - { - MPFR_ASSERTN (buf != NULL); - min_size = (size_t)ret < size ? (size_t)ret : size - 1; - strncpy (buf, str, min_size); - buf[min_size] = '\0'; - } - - mpfr_free_str (str); - return ret; + return mpfr_vasnprintf_aux (NULL, buf, size, fmt, ap); } int @@ -211,4 +188,16 @@ mpfr_asprintf (char **pp, const char *fmt, ...) return ret; } + +int +mpfr_vasprintf (char **ptr, const char *fmt, va_list ap) +{ + return mpfr_vasnprintf_aux (ptr, NULL, 0, fmt, ap); +} + +#else /* HAVE_STDARG */ + +/* Avoid an empty translation unit (see ISO C99, 6.9) */ +typedef int foo; + #endif /* HAVE_STDARG */ |