Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.
 
 
 
 

32 lines
880 B

  1. #include "scan.h"
  2. #ifdef UNITTEST
  3. #undef UNITTEST
  4. #include "scan_8longn.c"
  5. #define UNITTEST
  6. #endif
  7. size_t scan_8long(const char *src,unsigned long *dest) {
  8. return scan_8longn(src,((size_t)-1)/2,dest);
  9. }
  10. #ifdef UNITTEST
  11. #include <assert.h>
  12. int main() {
  13. unsigned long i;
  14. assert(scan_8long("1234",&i)==4 && i==01234);
  15. assert(scan_8long("12345678",&i)==7 && i==01234567);
  16. if (sizeof(long)==sizeof(int)) {
  17. assert(scan_8long("37777777777",&i)==11 && i==0xffffffff);
  18. assert(scan_8long("40000000000",&i)==10 && i==04000000000);
  19. } else if (sizeof(long)==sizeof(long long)) {
  20. assert(scan_8long("1777777777777777777777",&i)==22 && i==0xffffffffffffffffull);
  21. assert(scan_8long("2000000000000000000000",&i)==21 && i==0200000000000000000000ull);
  22. }
  23. assert(scan_8long("-4",&i)==0 && i==0);
  24. assert(scan_8long("01234",&i)==5 && i==01234);
  25. return 0;
  26. }
  27. #endif