1#include <ctype.h>2#include <stdlib.h>34#include "../libc.h"56#undef atoi78int9atoi(const char *s)10{11 int n, d, sign = -1;1213 while (isspace(*s))14 ++s;1516 switch (*s) {17 case '-':18 sign = 1;19 case '+':20 ++s;21 }2223 /* Compute n as a negative number to avoid overflow on INT_MIN */24 for (n = 0; (d = _dtoi(*s)) < 10; ++s)25 n = n*10 - d;2627 return sign * n;28}