Luna/libc/src/stdio.cpp
apio 80f5c790f8
All checks were successful
continuous-integration/drone/push Build is passing
Implement string formatting into libc :)
Of course, using <luna/Format.h> makes it so simple. No need for duplicate code!
2023-01-06 20:15:43 +01:00

52 lines
1.0 KiB
C++

#define _LUNA_SYSTEM_ERROR_EXTENSIONS
#include <bits/errno-return.h>
#include <luna/Format.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
FILE* stderr = nullptr;
extern "C"
{
int console_print(const char* str)
{
long rc = syscall(SYS_console_print, str);
__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;
}
}