diff options
author | Marvin Borner | 2019-12-07 13:40:28 +0100 |
---|---|---|
committer | Marvin Borner | 2019-12-07 13:40:28 +0100 |
commit | d94b024b73aeca06de417e0fd3c502495312a8b2 (patch) | |
tree | bff5cc1b757eeed7f58878cc13551c63464c5a31 /src/kernel/lib/stdlib/htoa.c | |
parent | 322167ceab19588473f9074e761390fdeb701790 (diff) |
Added userspace libc and began userspace based shell
Diffstat (limited to 'src/kernel/lib/stdlib/htoa.c')
-rw-r--r-- | src/kernel/lib/stdlib/htoa.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c new file mode 100644 index 0000000..85bd750 --- /dev/null +++ b/src/kernel/lib/stdlib/htoa.c @@ -0,0 +1,30 @@ +#include <stdint.h> +#include <kernel/lib/string.h> +#include <kernel/lib/stdlib.h> + +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 |