From 139c6f197bd332729785ef2aabd73aba942e59d5 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 8 Feb 2019 13:45:44 +0100 Subject: [PATCH] lib: vfprintf, vsnprintf: Support gcc-4.6.4: #-type. * lib/stdio/vfscanf.c (vfscanf): Show whole template upon error. * lib/stdio/vsscanf.c (vsscanf): Likewise. * lib/stdio/vsnprintf.c (vsnprintf): Likewise. Support #-type prefix. * lib/stdio/vfprintf.c (vfprintf): Likewise. Use fileno. Return count. * build-aux/configure-lib.sh (libc_gnu_SOURCES): Move fileno... (libc_tcc_SOURCES): ...here. --- build-aux/configure-lib.sh | 2 +- include/stdio.h | 1 + lib/stdio/vfprintf.c | 8 ++++++-- lib/stdio/vsnprintf.c | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index ab3a580f..df39f3ae 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -250,6 +250,7 @@ lib/stdio/fclose.c lib/stdio/fdopen.c lib/stdio/ferror.c lib/stdio/fflush.c +lib/stdio/fileno.c lib/stdio/fopen.c lib/stdio/fprintf.c lib/stdio/fread.c @@ -335,7 +336,6 @@ lib/posix/unsetenv.c lib/stdio/clearerr.c lib/stdio/feof.c lib/stdio/fgets.c -lib/stdio/fileno.c lib/stdio/freopen.c lib/stdio/fscanf.c lib/stdio/perror.c diff --git a/include/stdio.h b/include/stdio.h index 82a9e4df..de11d350 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -65,6 +65,7 @@ int ferror (FILE * stream); int fflush (FILE * stream); int fgetc (FILE * stream); char *fgets (char *s, int size, FILE * stream); +int fileno (FILE *); int fpurge (FILE * stream); int fputc (int c, FILE * stream); int fputs (char const *s, FILE * stream); diff --git a/lib/stdio/vfprintf.c b/lib/stdio/vfprintf.c index 7f2c55ee..b87479ba 100644 --- a/lib/stdio/vfprintf.c +++ b/lib/stdio/vfprintf.c @@ -26,7 +26,7 @@ int vfprintf (FILE * f, char const *format, va_list ap) { - int fd = (long) f; + int fd = fileno (f); char const *p = format; int count = 0; while (*p) @@ -212,6 +212,9 @@ vfprintf (FILE * f, char const *format, va_list ap) case 'G': { double d = va_arg8 (ap, double); +#if 1 + fputs ("0.0", f); +#else char *s = dtoab (d, 10, 1); if (c == 'E' || c == 'G') strupr (s); @@ -247,6 +250,7 @@ vfprintf (FILE * f, char const *format, va_list ap) fputc (pad, f); count++; } +#endif break; } case 'n': @@ -268,5 +272,5 @@ vfprintf (FILE * f, char const *format, va_list ap) p++; } va_end (ap); - return 0; + return count; } diff --git a/lib/stdio/vsnprintf.c b/lib/stdio/vsnprintf.c index c1b56840..c524d223 100644 --- a/lib/stdio/vsnprintf.c +++ b/lib/stdio/vsnprintf.c @@ -228,6 +228,11 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap) case 'G': { double d = va_arg8 (ap, double); +#if 1 + *str++ = '0'; + *str++ = '.'; + *str++ = '0'; +#else char *s = dtoab (d, 10, 1); if (c == 'E' || c == 'G') strupr (s); @@ -268,6 +273,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap) *str++ = pad; count++; } +#endif break; } case 'n':