mescc: Tinycc support: vsnprintf.

* module/language/c99/compiler.mes (ast-type->type): Support *p++ in test.
* mlibc/libc-mes+tcc.c (vsnprintf): Implement.
This commit is contained in:
Jan Nieuwenhuizen 2017-08-01 13:24:23 +02:00
parent 0b60a58809
commit 4fbd16aaac
2 changed files with 23 additions and 2 deletions

View file

@ -335,8 +335,27 @@ time_t time (time_t *tloc)
int int
vsnprintf (char *str, size_t size, char const *format, va_list ap) vsnprintf (char *str, size_t size, char const *format, va_list ap)
{ {
eputs ("vsnprintf stub\n"); char const *p = format;
return 0; 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);
} }
void * void *

View file

@ -1283,6 +1283,8 @@
(define (ast-type->type info o) (define (ast-type->type info o)
(pmatch o (pmatch o
((p-expr ,expr) (ast-type->type info (p-expr->type info o))) ((p-expr ,expr) (ast-type->type info (p-expr->type info o)))
((pre-inc ,expr) (ast-type->type info expr))
((post-inc ,expr) (ast-type->type info expr))
((decl-spec-list ,type-spec) ((decl-spec-list ,type-spec)
(ast-type->type info type-spec)) (ast-type->type info type-spec))
((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type))) ((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type)))