You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strtoull.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>
  3. * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdlib.h>
  21. #include <ctype.h>
  22. /*
  23. * Despite being exactly the same as strtoul() except the long long instead of
  24. * long it ends up being much bigger so provide a separate implementation in a
  25. * separate object so that it won't be linked in if not used.
  26. */
  27. unsigned long long strtoull ( const char *p, char **endp, int base ) {
  28. unsigned long long ret = 0;
  29. unsigned int charval;
  30. base = strtoul_base ( &p, base );
  31. while ( 1 ) {
  32. charval = strtoul_charval ( *p );
  33. if ( charval >= ( unsigned int ) base )
  34. break;
  35. ret = ( ( ret * base ) + charval );
  36. p++;
  37. }
  38. if ( endp )
  39. *endp = ( char * ) p;
  40. return ( ret );
  41. }