From eed77bd2970a00d1394ed027ceca5b646e4671ce Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 17 Jun 2020 18:31:46 +0200 Subject: Started rewrite --- src/userspace/libc/stdlib/itoa.c | 43 ---------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/userspace/libc/stdlib/itoa.c (limited to 'src/userspace/libc/stdlib/itoa.c') diff --git a/src/userspace/libc/stdlib/itoa.c b/src/userspace/libc/stdlib/itoa.c deleted file mode 100644 index b960796..0000000 --- a/src/userspace/libc/stdlib/itoa.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include - -static const char ITOA_TABLE[] = "0123456789"; - -char *itoa(int n) -{ - if (!n) { - char *ret = (char *)malloc(2); - ret[0] = '0'; - ret[1] = 0; - return ret; - } - u32 negative = (u32)(n < 0); - if (negative) - n *= -1; - - int sz; - for (sz = 0; n % pow(10, sz) != n; sz++) { - } - - char *ret = (char *)malloc((u32)(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 = (char *)malloc((u32)(sz + 2)); - strcpy(aux, ret); - aux[sz] = '-'; - aux[sz + 1] = 0; - free(ret); - ret = aux; - } - - strinv(ret); - return ret; -} \ No newline at end of file -- cgit v1.2.3