#include #include #include #include #include #include #include #include extern "C" { int putchar(int ch) { write(0, &ch, 1); return (byte)ch; } static void sys_putch(char*&, char ch) { putchar(ch); } int printf(const char* fmt, ...) { va_list ap; va_start(ap, fmt); int ret = printfInternal(sys_putch, nullptr, fmt, ap); va_end(ap); return ret; } static void buffer_putch(char*& bufptr, char ch) { *bufptr++ = ch; } int sprintf(char* buffer, const char* fmt, ...) { va_list ap; va_start(ap, fmt); int ret = printfInternal(buffer_putch, buffer, fmt, ap); buffer[ret] = '\0'; va_end(ap); return ret; } void perror(const char* s) { printf("%s: %s\n", s, strerror(errno)); } }