missing/strtol.c


DEFINITIONS

This source file includes following functions.
  1. strtol


   1  /* public domain rewrite of strtol(3) */
   2  
   3  #include <ctype.h>
   4  
   5  long
   6  strtol(nptr, endptr, base)
   7      char *nptr;
   8      char **endptr;
   9      int base;
  10  {
  11      long result;
  12      char *p = nptr;
  13  
  14      while (isspace(*p)) {
  15          p++;
  16      }
  17      if (*p == '-') {
  18          p++;
  19          result = -strtoul(p, endptr, base);
  20      }
  21      else {
  22          if (*p == '+') p++;
  23          result = strtoul(p, endptr, base);
  24      }
  25      if (endptr != 0 && *endptr == p) {
  26          *endptr = nptr;
  27      }
  28      return result;
  29  }