diff options
Diffstat (limited to 'stdlib/strfrom-skeleton.c')
-rw-r--r-- | stdlib/strfrom-skeleton.c | 38 |
1 files changed, 7 insertions, 31 deletions
diff --git a/stdlib/strfrom-skeleton.c b/stdlib/strfrom-skeleton.c index 36e9adcad5..810eb315d0 100644 --- a/stdlib/strfrom-skeleton.c +++ b/stdlib/strfrom-skeleton.c @@ -28,6 +28,7 @@ #include <string.h> #include <locale/localeinfo.h> #include <fix-float-double-convert-nan.h> +#include <printf_buffer.h> #define UCHAR_T char #define L_(Str) Str @@ -37,12 +38,7 @@ int STRFROM (char *dest, size_t size, const char *format, FLOAT f) { - _IO_strnfile sfile; -#ifdef _IO_MTSAFE_IO - sfile.f._sbf._f._lock = NULL; -#endif - - int done; + struct __printf_buffer_snprintf buf; /* Single-precision values need to be stored in a double type, because __printf_fp_l and __printf_fphex do not accept the float type. */ @@ -106,23 +102,8 @@ STRFROM (char *dest, size_t size, const char *format, FLOAT f) abort (); } - /* The following code to prepare the virtual file has been adapted from the - function __vsnprintf_internal from libio. */ - - if (size == 0) - { - /* When size is zero, nothing is written and dest may be a null pointer. - This is specified for snprintf in ISO/IEC 9899:2011, Section 7.21.6.5, - in the second paragraph. Thus, if size is zero, prepare to use the - overflow buffer right from the start. */ - dest = sfile.overflow_buf; - size = sizeof (sfile.overflow_buf); - } - - /* Prepare the virtual string file. */ - _IO_no_init (&sfile.f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL); - _IO_JUMPS (&sfile.f._sbf) = &_IO_strn_jumps; - _IO_str_init_static_internal (&sfile.f, dest, size - 1, dest); + /* Prepare the string buffer. */ + __printf_buffer_snprintf_init (&buf, dest, size); /* Prepare the format specification for printf_fp. */ memset (&info, '\0', sizeof (info)); @@ -144,13 +125,8 @@ STRFROM (char *dest, size_t size, const char *format, FLOAT f) info.spec = specifier; if (info.spec != 'a' && info.spec != 'A') - done = __printf_fp_l (&sfile.f._sbf._f, _NL_CURRENT_LOCALE, &info, &fpptr); + __printf_fp_l_buffer (&buf.base, _NL_CURRENT_LOCALE, &info, &fpptr); else - done = __printf_fphex (&sfile.f._sbf._f, &info, &fpptr); - - /* Terminate the string. */ - if (sfile.f._sbf._f._IO_buf_base != sfile.overflow_buf) - *sfile.f._sbf._f._IO_write_ptr = '\0'; - - return done; + __printf_fphex_l_buffer (&buf.base, _NL_CURRENT_LOCALE, &info, &fpptr); + return __printf_buffer_snprintf_done (&buf); } |