diff options
author | Marvin Borner | 2020-05-28 23:02:51 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-28 23:02:51 +0200 |
commit | f600c79559892b73b019102478af501cf71fe6a4 (patch) | |
tree | db5bca15169c9990e3c6ab52568d526d1e25bac5 /src/kernel/lib/stdlib | |
parent | 731ea56513bd199597a905eb1937e67cbd762b32 (diff) |
Added vsprintf support for serial connections
Diffstat (limited to 'src/kernel/lib/stdlib')
-rw-r--r-- | src/kernel/lib/stdlib/itoa.c | 29 |
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 |