#include #include static char buffer[3 * sizeof(int) + 2]; int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list params) { int written = 0; int i; int s = 0; int l = 0; for (i = 0; format[i] != '\0'; ++i) { if (format[i] == '%') { written += stream->puts(stream, &format[s], l); s = i + 2; ++i; switch (format[i]) { case 's': { const char *arg = va_arg(params, const char *); written += stream->puts(stream, arg, -1); } break; case 'c': { const char arg = (char)va_arg(params, int); stream->putc(stream, arg); ++written; } break; case 'd': { const char *arg = itoa(buffer, va_arg(params, int), 10); written += stream->puts(stream, arg, -1); } break; case 'u': { const char *arg = utoa(buffer, va_arg(params, unsigned int), 10); written += stream->puts(stream, arg, -1); } break; case 'x': { const char *arg = utoa(buffer, va_arg(params, unsigned int), 16); written += stream->puts(stream, arg, -1); } break; } l = 0; } else ++l; } if (l > 0) { written += stream->puts(stream, &format[s], l); } stream->flush(stream); return written; }