From 1994399448a298d3fc5474b3ca6272e1c699c7df Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 1 Nov 2019 13:13:40 +0100 Subject: Fixed VGA buffer logging --- src/kernel/lib/lib.h | 8 ++++++++ src/kernel/lib/string.c | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/kernel/lib') diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index 420dd5b..5cc3d1f 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -32,6 +32,14 @@ void strcat(char *dest, const char *src); */ void strcpy(char *dest, const char *src); +/** + * Convert an integer to a char array (string) + * @param i The integer + * @param b The char array + * @return The char pointer + */ +char *itoa(int i, char b[]); + /** * Copy n data from src to dest * @param dest The destination array pointer diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c index c171439..12b4b06 100644 --- a/src/kernel/lib/string.c +++ b/src/kernel/lib/string.c @@ -10,7 +10,7 @@ size_t strlen(const char *str) { size_t strcmp(const char *s1, const char *s2) { size_t s_a = strlen(s1); - for (size_t i = 0; i < s_a; i++) + for (size_t i = 0; i < s_a; i++) if (s1[i] != s2[i]) return 1; return 0; @@ -30,3 +30,23 @@ void strcpy(char *dest, const char *src) { for (size_t i = 0; i < s_orig; i++) dest[i] = src[i]; dest[s_orig] = 0; } + +char *itoa(int i, char b[]) { + char const digit[] = "0123456789"; + char *p = b; + if (i < 0) { + *p++ = '-'; + i *= -1; + } + int shifter = i; + do { + ++p; + shifter = shifter / 10; + } while (shifter); + *p = '\0'; + do { + *--p = digit[i % 10]; + i = i / 10; + } while (i); + return b; +} \ No newline at end of file -- cgit v1.2.3