estrtol.c 430 B

12345678910111213141516171819202122232425262728
  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "util.h"
  6. long
  7. estrtol(const char *s, int base)
  8. {
  9. char *end;
  10. long n;
  11. errno = 0;
  12. n = strtol(s, &end, base);
  13. if (*end != '\0') {
  14. if (base == 0)
  15. eprintf("%s: not an integer\n", s);
  16. else
  17. eprintf("%s: not a base %d integer\n", s, base);
  18. }
  19. if (errno != 0)
  20. eprintf("%s:", s);
  21. return n;
  22. }