aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/include/stdlib.h4
-rw-r--r--libc/stdlib.c15
2 files changed, 19 insertions, 0 deletions
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
new file mode 100644
index 0000000..146b4b8
--- /dev/null
+++ b/libc/include/stdlib.h
@@ -0,0 +1,4 @@
+/* this is by no means standards-compliant... but who cares? :P */
+
+/* NOT reentrant! */
+char* itoa(int val, int base);
diff --git a/libc/stdlib.c b/libc/stdlib.c
new file mode 100644
index 0000000..356fc33
--- /dev/null
+++ b/libc/stdlib.c
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+
+/* adapted from <http://www.strudel.org.uk/itoa/> */
+char* itoa(int val, int base)
+{
+ static char buf[32] = {0};
+
+ int i = 30;
+
+ for(; val && i ; --i, val /= base)
+
+ buf[i] = "0123456789abcdef"[val % base];
+
+ return &buf[i+1];
+}