mescc: Tinycc support: snprintf.
* mlibc/include/stdarg.h (vsprintf): Declare. * mlibc/libc-gcc.c (vsprintf): New function. (sprintf): Use it. * mlibc/libc-mes+tcc.c (snprintf): Implement. * mlibc/libc-mes.c (vsprintf): New function (sprintf): Use it.
This commit is contained in:
parent
3392f7241a
commit
70e3e83581
|
@ -43,6 +43,7 @@ typedef int va_list;
|
|||
#define va_copy(dest, src) dest = src
|
||||
|
||||
int vprintf (char const* format, va_list ap);
|
||||
int vsprintf (char *str, char const *format, va_list ap);
|
||||
int vsnprintf (char *str, size_t size, char const *format, va_list ap);
|
||||
|
||||
#endif // ! (__GNUC__ && POSIX)
|
||||
|
|
|
@ -389,10 +389,8 @@ printf (char const* format, ...)
|
|||
}
|
||||
|
||||
int
|
||||
sprintf (char *str, char const* format, ...)
|
||||
vsprintf (char *str, char const* format, va_list ap)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
char const *p = format;
|
||||
while (*p)
|
||||
if (*p != '%')
|
||||
|
@ -411,8 +409,19 @@ sprintf (char *str, char const* format, ...)
|
|||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
*str = 0;
|
||||
return strlen (str);
|
||||
}
|
||||
|
||||
int
|
||||
sprintf (char *str, char const* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
int r = vsprintf (str, format, ap);
|
||||
va_end (ap);
|
||||
return 0;
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -248,8 +248,11 @@ sigemptyset (sigset_t *set)
|
|||
int
|
||||
snprintf(char *str, size_t size, char const *format, ...)
|
||||
{
|
||||
eputs ("snprintf stub\n");
|
||||
return 0;
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
int r = vsprintf (str, format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -337,27 +340,7 @@ time_t time (time_t *tloc)
|
|||
int
|
||||
vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
||||
{
|
||||
char const *p = format;
|
||||
while (*p)
|
||||
if (*p != '%')
|
||||
*str++ = *p++;
|
||||
else
|
||||
{
|
||||
p++;
|
||||
char c = *p;
|
||||
switch (c)
|
||||
{
|
||||
case '%': {*str++ = *p; break;}
|
||||
case 'c': {char c; c = va_arg (ap, char); *str++=c; break;}
|
||||
case 'd': {int d; d = va_arg (ap, int); strcpy (str, itoa (d)); break;}
|
||||
case 's': {char *s; s = va_arg (ap, char *); strcpy (str, s); break;}
|
||||
default: {*str++ = *p; break;}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
va_end (ap);
|
||||
*str = 0;
|
||||
return strlen (str);
|
||||
return vsprintf (str, format, ap);
|
||||
}
|
||||
|
||||
void *
|
||||
|
|
|
@ -416,10 +416,8 @@ printf (char const* format, ...)
|
|||
}
|
||||
|
||||
int
|
||||
sprintf (char *str, char const* format, ...)
|
||||
vsprintf (char *str, char const* format, va_list ap)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
char const *p = format;
|
||||
while (*p)
|
||||
if (*p != '%')
|
||||
|
@ -439,5 +437,16 @@ sprintf (char *str, char const* format, ...)
|
|||
p++;
|
||||
}
|
||||
va_end (ap);
|
||||
return 0;
|
||||
*str = 0;
|
||||
return strlen (str);
|
||||
}
|
||||
|
||||
int
|
||||
sprintf (char *str, char const* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
int r = vsprintf (str, format, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue