lib: vfprintf, vsnprintf: Support gcc-4.6.4: #-type.

* lib/stdio/vfprintf.c (vfprintf): Support #-type prefix.  Show whole
format upon error.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
* lib/stdio/vfscanf.c (vfscanf): Show whole template upon error.
* lib/stdio/vsscanf.c (vsscanf): Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-08 13:45:44 +01:00 committed by Jan (janneke) Nieuwenhuizen
parent 6f71f2da02
commit 95ba472302
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 48 additions and 4 deletions

View File

@ -41,6 +41,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
char c = *p;
int left_p = 0;
int precision = -1;
int prefix_p = 0;
int width = -1;
if (c == '-')
{
@ -51,12 +52,17 @@ vfprintf (FILE * f, char const *format, va_list ap)
if (c == ' ')
{
pad = c;
c = *p++;
c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
}
if (c == '0')
{
pad = c;
c = *p++;
c = *++p;
}
if (c >= '0' && c <= '9')
{
@ -134,6 +140,18 @@ vfprintf (FILE * f, char const *format, va_list ap)
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)
{
if (precision-- <= 0)
@ -241,6 +259,8 @@ vfprintf (FILE * f, char const *format, va_list ap)
{
eputs ("vfprintf: not supported: %:");
eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n");
p++;
}

View File

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

View File

@ -43,6 +43,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
c = *p;
int left_p = 0;
int precision = -1;
int prefix_p = 0;
int width = -1;
if (c == '-')
{
@ -53,12 +54,17 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
if (c == ' ')
{
pad = c;
c = *p++;
c = *++p;
}
if (c == '#')
{
prefix_p = 1;
c = *++p;
}
if (c == '0')
{
pad = c;
c = *p++;
c = *++p;
}
if (c >= '0' && c <= '9')
{
@ -142,6 +148,18 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
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)
{
if (precision-- <= 0)
@ -262,6 +280,8 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
{
eputs ("vsnprintf: not supported: %:");
eputc (c);
eputs (", in format: ");
eputs (format);
eputs ("\n");
p++;
}

View File

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