aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/stdlib/itoa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/lib/stdlib/itoa.c')
-rw-r--r--src/kernel/lib/stdlib/itoa.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
index 2020ca6..2d2243a 100644
--- a/src/kernel/lib/stdlib/itoa.c
+++ b/src/kernel/lib/stdlib/itoa.c
@@ -41,4 +41,33 @@ char *itoa(int n)
strinv(ret);
return ret;
+}
+
+// TODO: Rename itoa_base
+char *itoa_base(int value, char *result, int base)
+{
+ 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 (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