From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/stdlib/atoi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/stdlib/atoi.c (limited to 'src/stdlib/atoi.c') 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 +#include + +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; +} -- cgit v1.2.1