aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-05 20:59:33 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-05 20:59:33 -0500
commite63e7123cdaac69f5b7216319681eea97e7aeb64 (patch)
tree19393f7a88bda8e226c91a7530b6e1d958e22c11 /libc
parent601080812f292e8f007592d621d417693b526c6e (diff)
downloadkappa-e63e7123cdaac69f5b7216319681eea97e7aeb64.zip
kappa-e63e7123cdaac69f5b7216319681eea97e7aeb64.tar.gz
kappa-e63e7123cdaac69f5b7216319681eea97e7aeb64.tar.bz2
kappa-e63e7123cdaac69f5b7216319681eea97e7aeb64.tar.xz
add stdlib
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];
+}