diff options
author | Marvin Borner | 2021-02-11 23:05:17 +0100 |
---|---|---|
committer | Marvin Borner | 2021-02-11 23:05:17 +0100 |
commit | 2efcd435b415defb893385b01c80947bacb97aec (patch) | |
tree | 321216463326d30845891b60e16441d1f58bfa66 | |
parent | a53315d23c6ec69464a727ada0f4a442786f0918 (diff) |
Added sprintf
-rw-r--r-- | libc/inc/print.h | 1 | ||||
-rw-r--r-- | libc/print.c | 22 |
2 files changed, 17 insertions, 6 deletions
diff --git a/libc/inc/print.h b/libc/inc/print.h index 575cc5f..3e11db7 100644 --- a/libc/inc/print.h +++ b/libc/inc/print.h @@ -8,6 +8,7 @@ int printf(const char *format, ...); int vprintf(const char *format, va_list ap); +int sprintf(char *str, const char *format, ...); int vsprintf(char *str, const char *format, va_list ap); int print(const char *str); diff --git a/libc/print.c b/libc/print.c index a66692e..ffb1e69 100644 --- a/libc/print.c +++ b/libc/print.c @@ -81,6 +81,16 @@ int vsprintf(char *str, const char *format, va_list ap) return strlen(str); } +int sprintf(char *str, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int len = vsprintf(str, format, ap); + va_end(ap); + + return len; +} + #ifdef userspace #include <sys.h> @@ -88,6 +98,11 @@ int vsprintf(char *str, const char *format, va_list ap) #define PATH_LOG "/proc/self/io/log" #define PATH_ERR "/proc/self/io/err" +int vprintf(const char *format, va_list ap) +{ + return vfprintf(PATH_OUT, format, ap); +} + int vfprintf(const char *path, const char *format, va_list ap) { char buf[1024] = { 0 }; @@ -95,11 +110,6 @@ int vfprintf(const char *path, const char *format, va_list ap) return write(path, buf, 0, len); } -int vprintf(const char *format, va_list ap) -{ - return vfprintf(PATH_OUT, format, ap); -} - int fprintf(const char *path, const char *format, ...) { va_list ap; @@ -147,8 +157,8 @@ int print(const char *str) #else // The kernel prints everything into the serial console -#include <proc.h> +#include <proc.h> #define RED "\x1B[1;31m" #define GRN "\x1B[1;32m" #define YEL "\x1B[1;33m" |