Rename printk() to printf().
[pintos-anon] / src / lib / stdlib.c
1 #include <ctype.h>
2 #include <stdlib.h>
3 #include <stdbool.h>
4
5 /* Converts a string representation of a signed decimal integer
6    in S into an `int', which is returned. */
7 int
8 atoi (const char *s) 
9 {
10   bool negative;
11   int value;
12
13   /* Skip white space. */
14   while (isspace (*s))
15     s++;
16
17   /* Parse sign. */
18   negative = false;
19   if (*s == '+')
20     s++;
21   else if (*s == '-')
22     {
23       negative = true;
24       s++;
25     }
26
27   /* Parse digits.  We always initially parse the value as
28      negative, and then make it positive later, because the
29      negative range of an int is bigger than the positive range
30      on a 2's complement system. */
31   for (value = 0; isdigit (*s); s++)
32     value = value * 10 - (*s - '0');
33   if (!negative)
34     value = -value;
35
36   return value;
37 }