/arch/powerpc/boot/stdlib.c

http://github.com/mirrors/linux · C · 42 lines · 25 code · 8 blank · 9 comment · 12 complexity · eaeded2148f3372d0c1b9d208f7c63c1 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * stdlib functions
  4. *
  5. * Author: Scott Wood <scottwood@freescale.com>
  6. *
  7. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  8. */
  9. #include "stdlib.h"
  10. /* Not currently supported: leading whitespace, sign, 0x prefix, zero base */
  11. unsigned long long int strtoull(const char *ptr, char **end, int base)
  12. {
  13. unsigned long long ret = 0;
  14. if (base > 36)
  15. goto out;
  16. while (*ptr) {
  17. int digit;
  18. if (*ptr >= '0' && *ptr <= '9' && *ptr < '0' + base)
  19. digit = *ptr - '0';
  20. else if (*ptr >= 'A' && *ptr < 'A' + base - 10)
  21. digit = *ptr - 'A' + 10;
  22. else if (*ptr >= 'a' && *ptr < 'a' + base - 10)
  23. digit = *ptr - 'a' + 10;
  24. else
  25. break;
  26. ret *= base;
  27. ret += digit;
  28. ptr++;
  29. }
  30. out:
  31. if (end)
  32. *end = (char *)ptr;
  33. return ret;
  34. }