#define _LUNA_SYSTEM_ERROR_EXTENSIONS #include #include #include #include #include #include FILE* stderr = nullptr; extern "C" { int console_write(const char* str, size_t size) { long rc = syscall(SYS_console_write, str, size); __errno_return(rc, int); } int vsnprintf(char* buf, size_t max, const char* format, va_list ap) { return (int)vstring_format(buf, max, format, ap); } int snprintf(char* buf, size_t max, const char* format, ...) { va_list ap; va_start(ap, format); int rc = vsnprintf(buf, max, format, ap); va_end(ap); return rc; } int vsprintf(char* buf, const char* format, va_list ap) { return vsnprintf(buf, (size_t)-1, format, ap); } int sprintf(char* buf, const char* format, ...) { va_list ap; va_start(ap, format); int rc = vsnprintf(buf, (size_t)-1, format, ap); va_end(ap); return rc; } int printf(const char* format, ...) { va_list ap; va_start(ap, format); int rc = (int)pure_cstyle_format( format, [](char c, void*) { console_write(&c, 1); }, nullptr, ap); va_end(ap); return rc; } int puts(const char* s) { if (console_write(s, strlen(s)) < 0) return -1; if (console_write("\n", 1) < 0) return -1; return 0; } void perror(const char* s) { // FIXME: Output to stderr when available. int err = errno; if (s && *s) printf("%s: ", s); printf("%s\n", strerror(err)); } } void debug_log_impl(const char* format, va_list ap) { pure_cstyle_format( format, [](char c, void*) { console_write(&c, 1); }, nullptr, ap); console_write("\n", 1); }