diff options
author | Ian Moffett <ian@osmora.org> | 2025-06-13 19:03:22 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-06-13 19:03:22 -0400 |
commit | 48b7c43ed1bad98200c3bdfed37d2b68ccf531ca (patch) | |
tree | c0c15582de3d1db22cabdd318785a5d12215d53f | |
parent | f97ef6c0683fd6030e73466d32df9df03fe2be62 (diff) |
usr: libc: Add printf()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | lib/libc/include/stdio.h | 2 | ||||
-rw-r--r-- | lib/libc/src/stdio/snprintf.c | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/libc/include/stdio.h b/lib/libc/include/stdio.h index d94990b..88e66f6 100644 --- a/lib/libc/include/stdio.h +++ b/lib/libc/include/stdio.h @@ -77,6 +77,8 @@ size_t fwrite(const void *__restrict ptr, size_t size, size_t n, FILE *__restric int vsnprintf(char *s, size_t size, const char *fmt, va_list ap); int snprintf(char *s, size_t size, const char *fmt, ...); + +int printf(const char *__restrict fmt, ...); int fputc(int c, FILE *stream); int putchar(int c); diff --git a/lib/libc/src/stdio/snprintf.c b/lib/libc/src/stdio/snprintf.c index e343b77..2387950 100644 --- a/lib/libc/src/stdio/snprintf.c +++ b/lib/libc/src/stdio/snprintf.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <stdio.h> #include <stddef.h> +#include <unistd.h> /* TODO FIXME: Use stdarg.h */ #define __va_start(ap, fmt) __builtin_va_start(ap, fmt) @@ -46,3 +47,17 @@ snprintf(char *s, size_t size, const char *fmt, ...) __va_end(ap); return ret; } + +int +printf(const char *__restrict fmt, ...) +{ + char buf[512]; + va_list ap; + int ret; + + __va_start(ap, fmt); + ret = vsnprintf(buf, sizeof(buf), fmt, ap); + write(stdout->fd, buf, ret); + __va_end(ap); + return ret; +} |