Browse Source

add long long scanning support

master
Felix von Leitner 18 years ago
parent
commit
3c467361fd
2 changed files with 27 additions and 0 deletions
  1. +12
    -0
      scan/scan_longlong.c
  2. +15
    -0
      scan/scan_ulonglong.c

+ 12
- 0
scan/scan_longlong.c View File

@ -0,0 +1,12 @@
#include "scan.h"
unsigned int scan_longlong(const char* src,signed long long* dest) {
unsigned int i,o;
unsigned long long l;
char c=src[0];
o=c=='-' || c=='+';
if ((i=scan_ulonglong(src+o,&l))) {
*dest=c=='-'?-l:l;
return i+o;
} return 0;
}

+ 15
- 0
scan/scan_ulonglong.c View File

@ -0,0 +1,15 @@
#include "scan.h"
unsigned int scan_ulonglong(const char *src,unsigned long long *dest) {
register const char *tmp=src;
register unsigned long long l=0;
register unsigned char c;
while ((c=*tmp-'0')<10) {
unsigned long long m=l;
l=l*10+c;
if ((l>>3) < m) break;
++tmp;
}
*dest=l;
return tmp-src;
}

Loading…
Cancel
Save