From 4b178c0feb4c415be36be0e4c0def8c447ed42af Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 22 Nov 2019 22:17:54 +0100 Subject: Added the most awesome c lib --- src/mlibc/stdlib/htoa.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/mlibc/stdlib/htoa.c (limited to 'src/mlibc/stdlib/htoa.c') diff --git a/src/mlibc/stdlib/htoa.c b/src/mlibc/stdlib/htoa.c new file mode 100644 index 0000000..5290c74 --- /dev/null +++ b/src/mlibc/stdlib/htoa.c @@ -0,0 +1,29 @@ +#include +#include +#include + +static const char __HTOA_TABLE[] = "0123456789ABCDEF"; + +char *htoa(uint32_t n) { + char *ret = kmalloc(10); + + int i = 0; + while (n) { + ret[i++] = __HTOA_TABLE[n & 0xF]; + n >>= 4; + } + + if (!i) { + ret[0] = '0'; + i++; + } + + for (; i <= 9; i++) ret[i] = 0; + + char *aux = strdup(ret); + kfree(ret); + ret = aux; + + strinv(ret); + return ret; +} \ No newline at end of file -- cgit v1.2.3