libowfat/scan/scan_ulonglong.c

20 lines
485 B
C
Raw Normal View History

2003-05-04 16:19:48 +00:00
#include "scan.h"
2006-11-07 17:56:05 +00:00
size_t scan_ulonglong(const char *src,unsigned long long *dest) {
2003-05-04 16:19:48 +00:00
register const char *tmp=src;
register unsigned long long l=0;
register unsigned char c;
2014-03-14 02:15:38 +00:00
while ((c=(unsigned char)(*tmp-'0'))<10) {
2003-05-27 20:31:25 +00:00
unsigned long long n;
/* division is very slow on most architectures */
n=l<<3; if ((n>>3)!=l) break;
if (n+(l<<1) < n) break;
n+=l<<1;
if (n+c < n) break;
l=n+c;
2003-05-04 16:19:48 +00:00
++tmp;
}
if (tmp-src) *dest=l;
2014-03-14 01:53:08 +00:00
return (size_t)(tmp-src);
2003-05-04 16:19:48 +00:00
}