diff options
Diffstat (limited to 'src/libc/stdio')
-rw-r--r-- | src/libc/stdio/fprintf.c | 32 | ||||
-rw-r--r-- | src/libc/stdio/sprintf.c | 28 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/libc/stdio/fprintf.c b/src/libc/stdio/fprintf.c new file mode 100644 index 0000000..cd2851c --- /dev/null +++ b/src/libc/stdio/fprintf.c @@ -0,0 +1,32 @@ +#include <shared/printf.h> +#include <stdio.h> + +static void backend_file(void *arg, const char *buf, size_t len) { + fwrite(buf, 1, len, arg); +} + +int fprintf(FILE *restrict f, const char *restrict fmt, ...) { + int ret; + va_list argp; + va_start(argp, fmt); + ret = vfprintf(f, fmt, argp); + va_end(argp); + return ret; +} + +int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) { + return __printf_internal(fmt, ap, backend_file, f); +} + +int printf(const char *restrict fmt, ...) { + int ret; + va_list argp; + va_start(argp, fmt); + ret = vprintf(fmt, argp); + va_end(argp); + return ret; +} + +int vprintf(const char *restrict fmt, va_list ap) { + return vfprintf(stdout, fmt, ap); +} diff --git a/src/libc/stdio/sprintf.c b/src/libc/stdio/sprintf.c new file mode 100644 index 0000000..0bfbb17 --- /dev/null +++ b/src/libc/stdio/sprintf.c @@ -0,0 +1,28 @@ +#include <camellia/syscalls.h> +#include <shared/mem.h> +#include <shared/printf.h> +#include <stdio.h> + +int sprintf(char *restrict s, const char *restrict fmt, ...) { + int ret; + va_list argp; + va_start(argp, fmt); + ret = vsnprintf(s, ~0, fmt, argp); + va_end(argp); + return ret; +} + +int vsprintf(char *restrict s, const char *restrict fmt, va_list ap) { + return vsnprintf(s, ~0, fmt, ap); +} + +int _klogf(const char *fmt, ...) { + char buf[256]; + int ret; + va_list argp; + va_start(argp, fmt); + ret = vsnprintf(buf, sizeof buf, fmt, argp); + va_end(argp); + _sys_debug_klog(buf, ret); + return ret; +} |