]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows port: Added strtoll() needed by large object support.
authorserassio <>
Tue, 14 Aug 2007 22:12:40 +0000 (22:12 +0000)
committerserassio <>
Tue, 14 Aug 2007 22:12:40 +0000 (22:12 +0000)
Forward port of 2.6 code.

include/squid_mswin.h
include/util.h
lib/win32lib.c
src/squid.h

index 6fffc31b35c873ad57e4288b40594d505f85503d..bd8991c24517e0202688456f93ccf988b94dce5c 100755 (executable)
@@ -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 <tolsty@tushino.com>
  * AUTHOR: Guido Serassio <serassio@squid-cache.org>
@@ -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);
index 688b14408abd25baae3dce3e168052dfd96faa65..6491d5723ae49e5d388007c62d51a5f899b94cbe 100644 (file)
@@ -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 */
index b2b8f972b8da6bada94d25f3783e823c4178aca0..a6f7916b1e58f32ab199c92a173ad84f99c2d115 100755 (executable)
@@ -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 <serassio@squid-cache.org>
@@ -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 
index b564e12f05a5731a3c543ef1fdde9d189a3aafac..59f661ecbeeb01920c8ff969b48dacb417e5210c 100644 (file)
@@ -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