aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdio/sprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/lib/stdio/sprintf.c')
-rw-r--r--src/kernel/lib/stdio/sprintf.c58
1 files changed, 3 insertions, 55 deletions
diff --git a/src/kernel/lib/stdio/sprintf.c b/src/kernel/lib/stdio/sprintf.c
index 0fb6eb5..8492363 100644
--- a/src/kernel/lib/stdio/sprintf.c
+++ b/src/kernel/lib/stdio/sprintf.c
@@ -1,63 +1,11 @@
-#include <lib/stdlib.h>
+#include <lib/stdio.h>
#include <stdarg.h>
-#include <stdint.h>
-
-static void append(char *dest, char *src, int index)
-{
- for (int i = index; i < strlen(src) + index; i++)
- dest[i] = src[i - index];
- dest[index + strlen(src)] = 0;
-}
int sprintf(char *str, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
-
- u8 ready_to_format = 0;
-
- int i = 0;
- char buf = 0;
- char format_buffer[20] = "\0";
-
- for (; *fmt; fmt++) {
- if (ready_to_format) {
- ready_to_format = 0;
-
- if (*fmt == '%') {
- str[i] = '%';
- continue;
- }
-
- buf = *fmt;
- if (buf == 's') {
- char *string = va_arg(args, char *);
- append(str, string, i);
- i = strlen(str);
- } else if (buf == 'x') {
- itoa_base((u32)va_arg(args, int), format_buffer, 16);
- append(str, format_buffer, i);
- i = strlen(str);
- } else if (buf == 'd') {
- itoa_base(va_arg(args, int), format_buffer, 10);
- append(str, format_buffer, i);
- i = strlen(str);
- } else if (buf == 'c') {
- str[i] = (char)va_arg(args, int);
- i++;
- }
- } else {
- if (*fmt == '%')
- ready_to_format = 1;
- else {
- str[i] = *fmt;
- i++;
- }
- }
-
- format_buffer[0] = '\0';
- }
-
+ int ret = vsprintf(str, fmt, args);
va_end(args);
- return strlen(str);
+ return ret;
} \ No newline at end of file