--------------------- PatchSet 6561 Date: 2005/03/28 09:34:20 Author: serassio Branch: nt-2_5 Tag: (none) Log: strtoll() may be not available on native Windows, this adds an own strtoll() used when needed Members: include/util.h:1.10.14.7->1.10.14.8 lib/win32lib.c:1.1.32.15->1.1.32.16 src/squid.h:1.13.6.2.4.10->1.13.6.2.4.11 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.10.14.7 retrieving revision 1.10.14.8 diff -u -r1.10.14.7 -r1.10.14.8 --- squid/include/util.h 17 Aug 2003 12:28:43 -0000 1.10.14.7 +++ squid/include/util.h 28 Mar 2005 09:34:20 -0000 1.10.14.8 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.10.14.7 2003/08/17 12:28:43 serassio Exp $ + * $Id: util.h,v 1.10.14.8 2005/03/28 09:34:20 serassio Exp $ * * AUTHOR: Harvest Derived * @@ -136,6 +136,9 @@ /* CygWin & Windows NT Port */ /* win32lib.c */ #ifdef _SQUID_MSWIN_ +#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ +int64_t WIN32_strtoll(const char *nptr, char **endptr, int base); +#endif extern int chroot (const char *); extern int ftruncate(int, off_t); extern int gettimeofday(struct timeval * ,struct timezone *); Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.32.15 retrieving revision 1.1.32.16 diff -u -r1.1.32.15 -r1.1.32.16 --- squid/lib/win32lib.c 6 Jun 2004 08:38:22 -0000 1.1.32.15 +++ squid/lib/win32lib.c 28 Mar 2005 09:34:20 -0000 1.1.32.16 @@ -1,5 +1,5 @@ /* - * $Id: win32lib.c,v 1.1.32.15 2004/06/06 08:38:22 serassio Exp $ + * $Id: win32lib.c,v 1.1.32.16 2005/03/28 09:34:20 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -95,6 +95,91 @@ { return 4096; } + +int64_t WIN32_strtoll(const char *nptr, char **endptr, int base) +{ + const char *s; + int64_t acc; + int64_t val; + int neg, any; + char c; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) { + errno = EINVAL; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return acc; + } + + /* The classic bsd implementation requires div/mod operators + * to compute a cutoff. Benchmarking proves that is very, very + * evil to some 32 bit processors. Instead, look for underflow + * in both the mult and add/sub operation. Unlike the bsd impl, + * we also work strictly in a signed int64 word as we haven't + * implemented the unsigned type in win32. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + val = 0; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + val *= base; + if ( (any < 0) /* already noted an over/under flow - short circuit */ + || (neg && (val > acc || (val -= c) > acc)) /* underflow */ + || (!neg && (val < acc || (val += c) < acc))) { /* overflow */ + any = -1; /* once noted, over/underflows never go away */ + } else { + acc = val; + any = 1; + } + } + + if (any < 0) { + acc = neg ? INT64_MIN : INT64_MAX; + errno = ERANGE; + } else if (!any) { + errno = EINVAL; + } + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} #endif uid_t geteuid(void) Index: squid/src/squid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/squid.h,v retrieving revision 1.13.6.2.4.10 retrieving revision 1.13.6.2.4.11 diff -u -r1.13.6.2.4.10 -r1.13.6.2.4.11 --- squid/src/squid.h 26 Mar 2005 09:48:41 -0000 1.13.6.2.4.10 +++ squid/src/squid.h 28 Mar 2005 09:34:20 -0000 1.13.6.2.4.11 @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.13.6.2.4.10 2005/03/26 09:48:41 serassio Exp $ + * $Id: squid.h,v 1.13.6.2.4.11 2005/03/28 09:34:20 serassio Exp $ * * AUTHOR: Duane Wessels * @@ -494,6 +494,9 @@ #ifndef getpagesize extern size_t getpagesize(void); #endif +#ifndef strtoll +#define strtoll WIN32_strtoll +#endif #endif /* _SQUID_MSWIN_ */ /*