From: serassio <> Date: Tue, 14 Aug 2007 22:12:40 +0000 (+0000) Subject: Windows port: Added strtoll() needed by large object support. X-Git-Tag: SQUID_3_0_PRE7~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=304c82abbd31b0e98beb3fe4750b0dbd8788b921;p=thirdparty%2Fsquid.git Windows port: Added strtoll() needed by large object support. Forward port of 2.6 code. --- diff --git a/include/squid_mswin.h b/include/squid_mswin.h index 6fffc31b35..bd8991c245 100755 --- a/include/squid_mswin.h +++ b/include/squid_mswin.h @@ -1,5 +1,5 @@ /* - * $Id: squid_mswin.h,v 1.3 2006/12/24 14:19:28 serassio Exp $ + * $Id: squid_mswin.h,v 1.4 2007/08/14 16:12:40 serassio Exp $ * * AUTHOR: Andrey Shorin * AUTHOR: Guido Serassio @@ -727,25 +727,3 @@ struct rusage { }; #undef ACL - -SQUIDCEXTERN int chroot (const char *); -SQUIDCEXTERN int ftruncate(int, off_t); -#ifndef HAVE_GETTIMEOFDAY -SQUIDCEXTERN int gettimeofday(struct timeval * ,void *); -#endif -SQUIDCEXTERN int kill(pid_t, int); -SQUIDCEXTERN int statfs(const char *, struct statfs *); -SQUIDCEXTERN int truncate(const char *, off_t); -SQUIDCEXTERN const char * wsastrerror(int); -SQUIDCEXTERN struct passwd *getpwnam(char *); -SQUIDCEXTERN struct group *getgrnam(char *); -SQUIDCEXTERN uid_t geteuid(void); -SQUIDCEXTERN uid_t getuid(void); -SQUIDCEXTERN int setuid(uid_t); -SQUIDCEXTERN int seteuid(uid_t); -SQUIDCEXTERN gid_t getgid(void); -SQUIDCEXTERN gid_t getegid(void); -SQUIDCEXTERN int setgid(gid_t); -SQUIDCEXTERN int setegid(gid_t); -SQUIDCEXTERN const char *WIN32_strerror(int); -SQUIDCEXTERN void WIN32_maperror(unsigned long); diff --git a/include/util.h b/include/util.h index 688b14408a..6491d5723a 100644 --- a/include/util.h +++ b/include/util.h @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.75 2007/08/13 17:20:50 hno Exp $ + * $Id: util.h,v 1.76 2007/08/14 16:12:40 serassio Exp $ * * AUTHOR: Harvest Derived * @@ -162,4 +162,32 @@ extern void gb_flush(gb_t *); /* internal, do not use this */ */ int statMemoryAccounted(void); +/* Windows Port */ +/* win32lib.c */ +#ifdef _SQUID_MSWIN_ +#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ +SQUIDCEXTERN int64_t WIN32_strtoll(const char *nptr, char **endptr, int base); +#endif +SQUIDCEXTERN int chroot (const char *); +SQUIDCEXTERN int ftruncate(int, off_t); +#ifndef HAVE_GETTIMEOFDAY +SQUIDCEXTERN int gettimeofday(struct timeval * ,void *); +#endif +SQUIDCEXTERN int kill(pid_t, int); +SQUIDCEXTERN int statfs(const char *, struct statfs *); +SQUIDCEXTERN int truncate(const char *, off_t); +SQUIDCEXTERN const char * wsastrerror(int); +SQUIDCEXTERN struct passwd *getpwnam(char *); +SQUIDCEXTERN struct group *getgrnam(char *); +SQUIDCEXTERN uid_t geteuid(void); +SQUIDCEXTERN uid_t getuid(void); +SQUIDCEXTERN int setuid(uid_t); +SQUIDCEXTERN int seteuid(uid_t); +SQUIDCEXTERN gid_t getgid(void); +SQUIDCEXTERN gid_t getegid(void); +SQUIDCEXTERN int setgid(gid_t); +SQUIDCEXTERN int setegid(gid_t); +SQUIDCEXTERN const char *WIN32_strerror(int); +SQUIDCEXTERN void WIN32_maperror(unsigned long); +#endif #endif /* SQUID_UTIL_H */ diff --git a/lib/win32lib.c b/lib/win32lib.c index b2b8f972b8..a6f7916b1e 100755 --- a/lib/win32lib.c +++ b/lib/win32lib.c @@ -1,6 +1,6 @@ /* - * $Id: win32lib.c,v 1.3 2006/12/24 14:19:28 serassio Exp $ + * $Id: win32lib.c,v 1.4 2007/08/14 16:12:40 serassio Exp $ * * Windows support * AUTHOR: Guido Serassio @@ -65,6 +65,91 @@ getpagesize() { 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 (xisspace(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 diff --git a/src/squid.h b/src/squid.h index b564e12f05..59f661ecbe 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.262 2007/08/13 17:20:51 hno Exp $ + * $Id: squid.h,v 1.263 2007/08/14 16:12:41 serassio Exp $ * * AUTHOR: Duane Wessels * @@ -299,6 +299,9 @@ struct rusage #ifndef getpagesize SQUIDCEXTERN size_t getpagesize(void); #endif +#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ +#define strtoll WIN32_strtoll +#endif #endif /* _SQUID_MSWIN_ */ #ifndef BUFSIZ