Ruby  1.9.3p392(2013-02-22revision39386)
strtol.c
Go to the documentation of this file.
1 /* public domain rewrite of strtol(3) */
2 
3 #include "ruby/missing.h"
4 #include <ctype.h>
5 
6 long
7 strtol(const char *nptr, char **endptr, int base)
8 {
9  long result;
10  const char *p = nptr;
11 
12  while (isspace(*p)) {
13  p++;
14  }
15  if (*p == '-') {
16  p++;
17  result = -strtoul(p, endptr, base);
18  }
19  else {
20  if (*p == '+') p++;
21  result = strtoul(p, endptr, base);
22  }
23  if (endptr != 0 && *endptr == p) {
24  *endptr = (char *)nptr;
25  }
26  return result;
27 }
28