about summary refs log tree commit diff
path: root/src/stdlib/atoi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/atoi.c')
-rw-r--r--src/stdlib/atoi.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c
new file mode 100644
index 00000000..648b154f
--- /dev/null
+++ b/src/stdlib/atoi.c
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+#include <ctype.h>
+
+int atoi(const char *s)
+{
+	int n=0, neg=0;
+	while (isspace(*s)) s++;
+	switch (*s) {
+	case '-': neg=1;
+	case '+': s++;
+	}
+	while (isdigit(*s))
+		n = 10*n + *s++ - '0';
+	return neg ? -n : n;
+}