aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdlib/itoa.c
diff options
context:
space:
mode:
authorMarvin Borner2020-06-17 18:31:46 +0200
committerMarvin Borner2020-06-17 18:31:46 +0200
commiteed77bd2970a00d1394ed027ceca5b646e4671ce (patch)
treec44643d98aed2b6818f2b33417c0dea9c5853094 /src/kernel/lib/stdlib/itoa.c
parent49dfa1f4021026bf7c4d77817959c8aa24067016 (diff)
Started rewrite
Diffstat (limited to 'src/kernel/lib/stdlib/itoa.c')
-rw-r--r--src/kernel/lib/stdlib/itoa.c73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
deleted file mode 100644
index b15befd..0000000
--- a/src/kernel/lib/stdlib/itoa.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <lib/math.h>
-#include <lib/string.h>
-#include <memory/alloc.h>
-#include <memory/paging.h>
-#include <stdint.h>
-
-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;
- }
- u8 negative = (u8)(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;
-}
-
-// TODO: Rename itoa_base
-char *itoa_base(int value, char *result, int base, int is_signed)
-{
- if (base < 2 || base > 36) {
- *result = '\0';
- return result;
- }
-
- char *ptr = result, *ptr1 = result, tmp_char;
- int tmp_value;
-
- do {
- tmp_value = value;
- value /= base;
- *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
- [35 + (tmp_value - value * base)];
- } while (value);
-
- if (is_signed && tmp_value < 0)
- *ptr++ = '-';
- *ptr-- = '\0';
- while (ptr1 < ptr) {
- tmp_char = *ptr;
- *ptr-- = *ptr1;
- *ptr1++ = tmp_char;
- }
- return result;
-} \ No newline at end of file