From 09e6dc97e3e0159117650457ad18c9cb08edb448 Mon Sep 17 00:00:00 2001 From: leitner Date: Sun, 4 May 2003 16:19:48 +0000 Subject: [PATCH] add long long scanning support --- scan/scan_longlong.c | 12 ++++++++++++ scan/scan_ulonglong.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 scan/scan_longlong.c create mode 100644 scan/scan_ulonglong.c diff --git a/scan/scan_longlong.c b/scan/scan_longlong.c new file mode 100644 index 0000000..393d1b6 --- /dev/null +++ b/scan/scan_longlong.c @@ -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; +} diff --git a/scan/scan_ulonglong.c b/scan/scan_ulonglong.c new file mode 100644 index 0000000..77e87d1 --- /dev/null +++ b/scan/scan_ulonglong.c @@ -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; +}