From d94b024b73aeca06de417e0fd3c502495312a8b2 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 7 Dec 2019 13:40:28 +0100 Subject: Added userspace libc and began userspace based shell --- src/mlibc/stdlib/itoa.c | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/mlibc/stdlib/itoa.c (limited to 'src/mlibc/stdlib/itoa.c') diff --git a/src/mlibc/stdlib/itoa.c b/src/mlibc/stdlib/itoa.c deleted file mode 100644 index 3c8ee05..0000000 --- a/src/mlibc/stdlib/itoa.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include - -static const char __ITOA_TABLE[] = "0123456789"; - -char *itoa(int n) -{ - if (paging_enabled == 0) - return "0"; // kmalloc isn't available - - if (!n) { - char *ret = kmalloc(2); - ret[0] = '0'; - ret[1] = 0; - return ret; - } - uint8_t negative = (uint8_t) (n < 0); - if (negative) n *= -1; - - int sz; - for (sz = 0; n % pow(10, sz) != n; sz++) {} - - char *ret = kmalloc(sz + 1); - - for (int i = 0; i < sz; i++) { - int digit = (n % pow(10, i + 1)) / pow(10, i); - ret[i] = __ITOA_TABLE[digit]; - } - ret[sz] = 0; - - if (negative) { - char *aux = kmalloc(sz + 2); - strcpy(aux, ret); - aux[sz] = '-'; - aux[sz + 1] = 0; - kfree(ret); - ret = aux; - } - - strinv(ret); - return ret; -} \ No newline at end of file -- cgit v1.2.3