diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/libc/printf.c | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/libc/printf.c')
-rw-r--r-- | src/libc/printf.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libc/printf.c b/src/libc/printf.c new file mode 100644 index 0000000..ad1fd06 --- /dev/null +++ b/src/libc/printf.c @@ -0,0 +1,56 @@ +#include <camellia/syscalls.h> +#include <shared/printf.h> +#include <stdio.h> +#include <string.h> + + +static void backend_file(void *arg, const char *buf, size_t len) { + fwrite(buf, 1, len, arg); +} + +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 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 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 vprintf(const char *restrict fmt, va_list ap) { + return vfprintf(stdout, 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; +} |