atoi.c 573 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. #include <ctype.h>
  7. /* We do not use strtol here for backwards compatibility in behaviour on
  8. overflow.
  9. */
  10. int
  11. atoi(register const char *nptr)
  12. {
  13. int total = 0;
  14. int minus = 0;
  15. while (isspace(*nptr)) nptr++;
  16. if (*nptr == '+') nptr++;
  17. else if (*nptr == '-') {
  18. minus = 1;
  19. nptr++;
  20. }
  21. while (isdigit(*nptr)) {
  22. total *= 10;
  23. total += (*nptr++ - '0');
  24. }
  25. return minus ? -total : total;
  26. }