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.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-08 13:45:44 +01:00 committed by Jan (janneke) Nieuwenhuizen
parent 7799f3688e
commit 85153b6fa8
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
6 changed files with 62 additions and 7 deletions

View File

@ -250,6 +250,7 @@ lib/stdio/fclose.c
lib/stdio/fdopen.c lib/stdio/fdopen.c
lib/stdio/ferror.c lib/stdio/ferror.c
lib/stdio/fflush.c lib/stdio/fflush.c
lib/stdio/fileno.c
lib/stdio/fopen.c lib/stdio/fopen.c
lib/stdio/fprintf.c lib/stdio/fprintf.c
lib/stdio/fread.c lib/stdio/fread.c
@ -334,7 +335,6 @@ lib/posix/unsetenv.c
lib/stdio/clearerr.c lib/stdio/clearerr.c
lib/stdio/feof.c lib/stdio/feof.c
lib/stdio/fgets.c lib/stdio/fgets.c
lib/stdio/fileno.c
lib/stdio/freopen.c lib/stdio/freopen.c
lib/stdio/fscanf.c lib/stdio/fscanf.c
lib/stdio/perror.c lib/stdio/perror.c

View File

@ -65,6 +65,7 @@ int ferror (FILE * stream);
int fflush (FILE * stream); int fflush (FILE * stream);
int fgetc (FILE * stream); int fgetc (FILE * stream);
char *fgets (char *s, int size, FILE * stream); char *fgets (char *s, int size, FILE * stream);
int fileno (FILE *);
int fpurge (FILE * stream); int fpurge (FILE * stream);
int fputc (int c, FILE * stream); int fputc (int c, FILE * stream);
int fputs (char const *s, FILE * stream); int fputs (char const *s, FILE * stream);

View File

@ -26,7 +26,7 @@
int int
vfprintf (FILE * f, char const *format, va_list ap) vfprintf (FILE * f, char const *format, va_list ap)
{ {
int fd = (long) f; int fd = fileno (f);
char const *p = format; char const *p = format;
int count = 0; int count = 0;
while (*p) while (*p)
@ -41,6 +41,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
char c = *p; char c = *p;
int left_p = 0; int left_p = 0;
int precision = -1; int precision = -1;
int prefix_p = 0;
int width = -1; int width = -1;
if (c == '-') if (c == '-')
{ {
@ -51,12 +52,17 @@ vfprintf (FILE * f, char const *format, va_list ap)
if (c == ' ') if (c == ' ')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
} }
if (c == '0') if (c == '0')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
} }
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
{ {
@ -134,6 +140,18 @@ vfprintf (FILE * f, char const *format, va_list ap)
count++; count++;
} }
} }
if (prefix_p && *s && c == 'o')
{
fputc ('0', f);
width--;
}
if (prefix_p && *s && (c == 'x' || c == 'X'))
{
fputc ('0', f);
width--;
fputc ('x', f);
width--;
}
while (*s) while (*s)
{ {
if (precision-- <= 0) if (precision-- <= 0)
@ -194,6 +212,9 @@ vfprintf (FILE * f, char const *format, va_list ap)
case 'G': case 'G':
{ {
double d = va_arg8 (ap, double); double d = va_arg8 (ap, double);
#if 1
fputs ("0.0", f);
#else
char *s = dtoab (d, 10, 1); char *s = dtoab (d, 10, 1);
if (c == 'E' || c == 'G') if (c == 'E' || c == 'G')
strupr (s); strupr (s);
@ -229,6 +250,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
fputc (pad, f); fputc (pad, f);
count++; count++;
} }
#endif
break; break;
} }
case 'n': case 'n':
@ -241,6 +263,8 @@ vfprintf (FILE * f, char const *format, va_list ap)
{ {
eputs ("vfprintf: not supported: %:"); eputs ("vfprintf: not supported: %:");
eputc (c); eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n"); eputs ("\n");
p++; p++;
} }
@ -248,5 +272,5 @@ vfprintf (FILE * f, char const *format, va_list ap)
p++; p++;
} }
va_end (ap); va_end (ap);
return 0; return count;
} }

View File

@ -110,6 +110,8 @@ vfscanf (FILE * stream, char const *template, va_list ap)
{ {
eputs ("vsscanf: not supported: %:"); eputs ("vsscanf: not supported: %:");
eputc (c); eputc (c);
eputs (", in template: ");
eputs (template);
eputs ("\n"); eputs ("\n");
t++; t++;
p = fgetc (stream); p = fgetc (stream);

View File

@ -43,6 +43,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
c = *p; c = *p;
int left_p = 0; int left_p = 0;
int precision = -1; int precision = -1;
int prefix_p = 0;
int width = -1; int width = -1;
if (c == '-') if (c == '-')
{ {
@ -53,12 +54,17 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
if (c == ' ') if (c == ' ')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
} }
if (c == '0') if (c == '0')
{ {
pad = c; pad = c;
c = *p++; c = *++p;
} }
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
{ {
@ -142,6 +148,18 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
count++; count++;
} }
} }
if (prefix_p && *s && c == 'o')
{
*s++ = '0';
width--;
}
if (prefix_p && *s && (c == 'x' || c == 'X'))
{
*s++ = '0';
width--;
*s++ = 'x';
width--;
}
while (*s) while (*s)
{ {
if (precision-- <= 0) if (precision-- <= 0)
@ -210,6 +228,11 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
case 'G': case 'G':
{ {
double d = va_arg8 (ap, double); double d = va_arg8 (ap, double);
#if 1
*str++ = '0';
*str++ = '.';
*str++ = '0';
#else
char *s = dtoab (d, 10, 1); char *s = dtoab (d, 10, 1);
if (c == 'E' || c == 'G') if (c == 'E' || c == 'G')
strupr (s); strupr (s);
@ -250,6 +273,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
*str++ = pad; *str++ = pad;
count++; count++;
} }
#endif
break; break;
} }
case 'n': case 'n':
@ -262,6 +286,8 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
{ {
eputs ("vsnprintf: not supported: %:"); eputs ("vsnprintf: not supported: %:");
eputc (c); eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n"); eputs ("\n");
p++; p++;
} }

View File

@ -81,6 +81,8 @@ vsscanf (char const *s, char const *template, va_list ap)
{ {
eputs ("vsscanf: not supported: %:"); eputs ("vsscanf: not supported: %:");
eputc (c); eputc (c);
eputs (", in template: ");
eputs (template);
eputs ("\n"); eputs ("\n");
t++; t++;
p++; p++;