|
|
|
@ -26,17 +26,17 @@ size_t scan_8longn(const char *src,size_t n,unsigned long *dest) {
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
unsigned long i;
|
|
|
|
|
assert(scan_8longn("1234",100,&i)==4 && i==01234);
|
|
|
|
|
assert(scan_8longn("12345678",100,&i)==7 && i==01234567);
|
|
|
|
|
assert(scan_8longn("1234\0""67890",10,&i)==4 && i==01234);
|
|
|
|
|
assert(scan_8longn("12345678",9,&i)==7 && i==01234567);
|
|
|
|
|
if (sizeof(long)==sizeof(int)) {
|
|
|
|
|
assert(scan_8longn("37777777777",100,&i)==11 && i==0xffffffff);
|
|
|
|
|
assert(scan_8longn("40000000000",100,&i)==10 && i==04000000000);
|
|
|
|
|
assert(scan_8longn("37777777777",12,&i)==11 && i==0xffffffff);
|
|
|
|
|
assert(scan_8longn("40000000000",12,&i)==10 && i==04000000000);
|
|
|
|
|
} else if (sizeof(long)==sizeof(long long)) {
|
|
|
|
|
assert(scan_8longn("1777777777777777777777",100,&i)==22 && i==0xffffffffffffffffull);
|
|
|
|
|
assert(scan_8longn("2000000000000000000000",100,&i)==21 && i==0200000000000000000000ull);
|
|
|
|
|
assert(scan_8longn("1777777777777777777777",23,&i)==22 && i==0xffffffffffffffffull);
|
|
|
|
|
assert(scan_8longn("2000000000000000000000",23,&i)==21 && i==0200000000000000000000ull);
|
|
|
|
|
}
|
|
|
|
|
assert(scan_8longn("-4",100,&i)==0 && i==0);
|
|
|
|
|
assert(scan_8longn("01234",100,&i)==5 && i==01234);
|
|
|
|
|
assert(scan_8longn("-4",3,&i)==0 && i==0);
|
|
|
|
|
assert(scan_8longn("01234",6,&i)==5 && i==01234);
|
|
|
|
|
assert(scan_8longn("1234",2,&i)==2 && i==012);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|