You cannot 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
1.1 KiB

23 years ago
#include "scan.h"
/* this is cut and paste from scan_ulong instead of calling scan_ulong
* because this way scan_ushort can abort scanning when the number would
* not fit into an unsigned short (as opposed to not fitting in an
* unsigned long) */
size_t scan_ushort(const char* src,unsigned short* dest) {
if (sizeof(unsigned short) == sizeof(unsigned int)) {
/* a good optimizing compiler should remove the else clause when not
* needed */
return scan_uint(src,(unsigned int*)dest);
} if (sizeof(unsigned short) < sizeof(unsigned long)) {
/* this is the regular case */
const char* cur;
unsigned short l;
for (cur=src,l=0; *cur>='0' && *cur<='9'; ++cur) {
unsigned long tmp=l*10ul+*cur-'0';
if ((unsigned short)tmp != tmp) break;
if (cur>src) *dest=l;
return (size_t)(cur-src);
} else {
/* the C standard says that sizeof(short) <= sizeof(unsigned int) <=
* sizeof(unsigned long); this can never happen. Provoke a compile
* error if it does */
char compileerror[sizeof(unsigned long)-sizeof(unsigned short)];
23 years ago