]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
strtoll() is not available on any platform, this add an own implementation.
authorserassio <>
Sat, 18 Aug 2007 00:56:24 +0000 (00:56 +0000)
committerserassio <>
Sat, 18 Aug 2007 00:56:24 +0000 (00:56 +0000)
configure.in
include/strtoll.h [new file with mode: 0755]
lib/Makefile.am
lib/strtoll.c [new file with mode: 0755]
lib/win32lib.c
src/squid.h

index 672adcab6111dc87a75474920b208913849503ba..941d838a8942b1a7bb36b57949e7897946181bb1 100644 (file)
@@ -1,7 +1,7 @@
 
 dnl  Configuration input file for Squid
 dnl
-dnl  $Id: configure.in,v 1.463 2007/08/11 13:27:27 serassio Exp $
+dnl  $Id: configure.in,v 1.464 2007/08/17 18:56:24 serassio Exp $
 dnl
 dnl
 dnl
@@ -11,7 +11,7 @@ AM_CONFIG_HEADER(include/autoconf.h)
 AC_CONFIG_AUX_DIR(cfgaux)
 AC_CONFIG_SRCDIR([src/main.cc])
 AM_INIT_AUTOMAKE([tar-ustar])
-AC_REVISION($Revision: 1.463 $)dnl
+AC_REVISION($Revision: 1.464 $)dnl
 AC_PREFIX_DEFAULT(/usr/local/squid)
 AM_MAINTAINER_MODE
 
@@ -2621,6 +2621,7 @@ AC_CHECK_FUNCS(\
        srandom \
        statfs \
        strsep \
+       strtoll \
        sysconf \
        syslog \
        timegm \
@@ -2760,6 +2761,11 @@ if test "$ac_cv_func_strsep" = "no" ; then
   AM_CONDITIONAL(NEED_OWN_STRSEP, true)
 fi
 
+AM_CONDITIONAL(NEED_OWN_STRTOLL, false)
+if test "$ac_cv_func_strtoll" = "no" ; then
+  AM_CONDITIONAL(NEED_OWN_STRTOLL, true)
+fi
+
 dnl
 dnl Test for va_copy
 dnl
diff --git a/include/strtoll.h b/include/strtoll.h
new file mode 100755 (executable)
index 0000000..ba9622a
--- /dev/null
@@ -0,0 +1,19 @@
+#if HAVE_STRTOLL
+
+/*
+ * Get strtoll() declaration.
+ */
+#include <stdlib.h>
+
+#else
+
+/*
+ * Convert a string to a int64 integer.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+SQUIDCEXTERN int64_t strtoll (const char *nptr, char **endptr, int base);
+
+#endif
index ebba939287d246b5bda31ab50a45dcf677c6a7f9..9b8084be57eba89c82e7ac117bcab30d2714df0f 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 #
-#  $Id: Makefile.am,v 1.25 2007/04/24 06:30:37 wessels Exp $
+#  $Id: Makefile.am,v 1.26 2007/08/17 18:56:25 serassio Exp $
 #
 
 DIST_SUBDIRS = libTrie
@@ -28,6 +28,11 @@ STRSEPSOURCE=strsep.c
 else
 STRSEPSOURCE=
 endif
+if NEED_OWN_STRTOLL
+STRTOLLSOURCE=strtoll.c
+else
+STRTOLLSOURCE=
+endif
 if NEED_OWN_MD5
 MD5SOURCE=md5.c
 else
@@ -57,6 +62,7 @@ EXTRA_libmiscutil_a_SOURCES = \
        Profiler.c \
        snprintf.c \
        strsep.c \
+       strtoll.c \
        win32lib.c
 libmiscutil_a_SOURCES = \
        MemPool.cc \
@@ -76,6 +82,7 @@ libmiscutil_a_SOURCES = \
        $(SNPRINTFSOURCE) \
        Splay.cc \
        $(STRSEPSOURCE) \
+       $(STRTOLLSOURCE) \
        stub_memaccount.c \
        util.c \
        uudecode.c \
diff --git a/lib/strtoll.c b/lib/strtoll.c
new file mode 100755 (executable)
index 0000000..f8145bb
--- /dev/null
@@ -0,0 +1,161 @@
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the University of\r
+ *     California, Berkeley and its contributors.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+/* modified for long long <mgd@swarm.org> 1999-08-12 */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+#include <config.h>\r
+#endif\r
+#if HAVE_CTYPE_H\r
+#include <ctype.h>\r
+#endif\r
+#if HAVE_ERRNO_H\r
+#include <errno.h>\r
+#endif\r
+\r
+/* Specification.  */\r
+#include "strtoll.h"\r
+\r
+\r
+#ifndef INT64_MIN\r
+/* Native 64 bit system without strtoll() */\r
+#if defined(LONG_MIN) && (SIZEOF_LONG == 8)\r
+#define INT64_MIN LONG_MIN\r
+#else\r
+/* 32 bit system */\r
+#define INT64_MIN       -9223372036854775807L-1L\r
+#endif\r
+#endif\r
+\r
+#ifndef INT64_MAX\r
+/* Native 64 bit system without strtoll() */\r
+#if defined(LONG_MAX) && (SIZEOF_LONG == 8)\r
+#define INT64_MAX LONG_MAX\r
+#else\r
+/* 32 bit system */\r
+#define INT64_MAX       9223372036854775807L\r
+#endif\r
+#endif\r
+\r
+\r
+/*\r
+ * Convert a string to a int64 integer.\r
+ *\r
+ * Ignores `locale' stuff.  Assumes that the upper and lower case\r
+ * alphabets and digits are each contiguous.\r
+ */\r
+int64_t\r
+strtoll (const char *nptr, char **endptr, int base)\r
+{\r
+  register const char *s = nptr;\r
+  register u_int64_t acc;\r
+  register int c;\r
+  register u_int64_t cutoff;\r
+  register int neg = 0, any, cutlim;\r
+  \r
+  /*\r
+   * Skip white space and pick up leading +/- sign if any.\r
+   * If base is 0, allow 0x for hex and 0 for octal, else\r
+   * assume decimal; if base is already 16, allow 0x.\r
+   */\r
+  do\r
+    {\r
+      c = *s++;\r
+    } while (xisspace(c));\r
+  if (c == '-')\r
+    {\r
+      neg = 1;\r
+      c = *s++;\r
+    }\r
+  else if (c == '+')\r
+    c = *s++;\r
+  if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))\r
+    {\r
+      c = s[1];\r
+      s += 2;\r
+      base = 16;\r
+    }\r
+  if (base == 0)\r
+    base = c == '0' ? 8 : 10;\r
+  \r
+  /*\r
+   * Compute the cutoff value between legal numbers and illegal\r
+   * numbers.  That is the largest legal value, divided by the\r
+   * base.  An input number that is greater than this value, if\r
+   * followed by a legal input character, is too big.  One that\r
+   * is equal to this value may be valid or not; the limit\r
+   * between valid and invalid numbers is then based on the last\r
+   * digit.  For instance, if the range for longs is\r
+   * [-2147483648..2147483647] and the input base is 10,\r
+   * cutoff will be set to 214748364 and cutlim to either\r
+   * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated\r
+   * a value > 214748364, or equal but the next digit is > 7 (or 8),\r
+   * the number is too big, and we will return a range error.\r
+   *\r
+   * Set any if any `digits' consumed; make it negative to indicate\r
+   * overflow.\r
+   */\r
+  cutoff = neg ? -(u_int64_t) INT64_MIN : INT64_MAX;\r
+  cutlim = cutoff % (u_int64_t) base;\r
+  cutoff /= (u_int64_t) base;\r
+  for (acc = 0, any = 0;; c = *s++)\r
+    {\r
+      if (xisdigit(c))\r
+        c -= '0';\r
+      else if (xisalpha(c))\r
+        c -= xisupper(c) ? 'A' - 10 : 'a' - 10;\r
+      else\r
+        break;\r
+      if (c >= base)\r
+        break;\r
+      if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))\r
+        any = -1;\r
+      else\r
+        {\r
+          any = 1;\r
+          acc *= base;\r
+          acc += c;\r
+        }\r
+    }\r
+  if (any < 0)\r
+    {\r
+      acc = neg ? INT64_MIN : INT64_MAX;\r
+      errno = ERANGE;\r
+    }\r
+  else if (neg)\r
+    acc = -acc;\r
+  if (endptr != 0)\r
+    *endptr = (char *) (any ? s - 1 : nptr);\r
+  return acc;\r
+}\r
+\r
index a6f7916b1e58f32ab199c92a173ad84f99c2d115..34df1334e6850eca94aa11c9a349b036fc55403a 100755 (executable)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: win32lib.c,v 1.4 2007/08/14 16:12:40 serassio Exp $
+ * $Id: win32lib.c,v 1.5 2007/08/17 18:56:26 serassio Exp $
  *
  * Windows support
  * AUTHOR: Guido Serassio <serassio@squid-cache.org>
@@ -65,91 +65,6 @@ 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 518ce6554befbc3964dadd862ba107a6702b318d..0845b09b3ff5576d943c617eb1bdf8a897decf1a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.265 2007/08/14 19:17:45 serassio Exp $
+ * $Id: squid.h,v 1.266 2007/08/17 18:56:31 serassio Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -294,14 +294,9 @@ struct rusage
 #define getpagesize( )   sysconf(_SC_PAGE_SIZE)
 #endif
 
-#if defined(_SQUID_MSWIN_)
+#if defined(_SQUID_MSWIN_) && !defined(getpagesize) 
 /* Windows may lack getpagesize() prototype */
-#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
@@ -393,6 +388,10 @@ extern "C"
 #include "strsep.h"
 #endif
 
+#if !HAVE_STRTOLL
+#include "strtoll.h"
+#endif
+
 #if !HAVE_INITGROUPS
 #include "initgroups.h"
 #endif