summaryrefslogtreecommitdiff
path: root/storage/bdb/clib
diff options
context:
space:
mode:
Diffstat (limited to 'storage/bdb/clib')
-rw-r--r--storage/bdb/clib/getcwd.c8
-rw-r--r--storage/bdb/clib/getopt.c8
-rw-r--r--storage/bdb/clib/memcmp.c8
-rw-r--r--storage/bdb/clib/memmove.c8
-rw-r--r--storage/bdb/clib/raise.c8
-rw-r--r--storage/bdb/clib/snprintf.c131
-rw-r--r--storage/bdb/clib/strcasecmp.c6
-rw-r--r--storage/bdb/clib/strdup.c6
-rw-r--r--storage/bdb/clib/strerror.c8
-rw-r--r--storage/bdb/clib/strtol.c144
-rw-r--r--storage/bdb/clib/strtoul.c123
11 files changed, 397 insertions, 61 deletions
diff --git a/storage/bdb/clib/getcwd.c b/storage/bdb/clib/getcwd.c
index bae50dfe90c..ec28f1fb637 100644
--- a/storage/bdb/clib/getcwd.c
+++ b/storage/bdb/clib/getcwd.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2002
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
*/
/*
@@ -31,14 +31,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: getcwd.c,v 11.15 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: getcwd.c,v 11.13 2002/02/28 21:27:18 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/storage/bdb/clib/getopt.c b/storage/bdb/clib/getopt.c
index 3f6659ea6e6..527ee69678d 100644
--- a/storage/bdb/clib/getopt.c
+++ b/storage/bdb/clib/getopt.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2002
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
*/
/*
@@ -31,14 +31,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: getopt.c,v 11.9 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: getopt.c,v 11.7 2002/01/11 15:51:28 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <stdio.h>
#include <stdlib.h>
diff --git a/storage/bdb/clib/memcmp.c b/storage/bdb/clib/memcmp.c
index 979badaef30..055a2f5fa9a 100644
--- a/storage/bdb/clib/memcmp.c
+++ b/storage/bdb/clib/memcmp.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2002
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
*/
/*
@@ -31,14 +31,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: memcmp.c,v 11.9 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: memcmp.c,v 11.7 2002/01/11 15:51:28 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
diff --git a/storage/bdb/clib/memmove.c b/storage/bdb/clib/memmove.c
index 632d50788da..60ece571d64 100644
--- a/storage/bdb/clib/memmove.c
+++ b/storage/bdb/clib/memmove.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2002
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
*/
/*
@@ -31,14 +31,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: memmove.c,v 11.8 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: memmove.c,v 11.6 2002/01/11 15:51:28 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
diff --git a/storage/bdb/clib/raise.c b/storage/bdb/clib/raise.c
index fcf3bbcbd7f..2f9e8cb800e 100644
--- a/storage/bdb/clib/raise.c
+++ b/storage/bdb/clib/raise.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: raise.c,v 11.8 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: raise.c,v 11.6 2002/01/11 15:51:28 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <signal.h>
#include <unistd.h>
diff --git a/storage/bdb/clib/snprintf.c b/storage/bdb/clib/snprintf.c
index fa1a63425e8..e1bc5d11244 100644
--- a/storage/bdb/clib/snprintf.c
+++ b/storage/bdb/clib/snprintf.c
@@ -1,24 +1,30 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2002
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: snprintf.c,v 11.18 2004/09/22 03:32:43 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: snprintf.c,v 11.10 2002/01/11 15:51:28 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h> /* Declare STDERR_FILENO. */
#endif
#include "db_int.h"
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
+static void sprintf_overflow __P((void));
+static int sprintf_retcharpnt __P((void));
+#endif
+
/*
* snprintf --
* Bounded version of sprintf.
@@ -29,7 +35,7 @@ static const char revid[] = "$Id: snprintf.c,v 11.10 2002/01/11 15:51:28 bostic
*/
#ifndef HAVE_SNPRINTF
int
-#ifdef __STDC__
+#ifdef STDC_HEADERS
snprintf(char *str, size_t n, const char *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
@@ -41,9 +47,98 @@ snprintf(str, n, fmt, va_alist)
{
static int ret_charpnt = -1;
va_list ap;
- int len;
+ size_t len;
+
+ if (ret_charpnt == -1)
+ ret_charpnt = sprintf_retcharpnt();
+
+#ifdef STDC_HEADERS
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ len = (size_t)vsprintf(str, fmt, ap);
+ if (ret_charpnt)
+ len = strlen(str);
+
+ va_end(ap);
+
+ if (len >= n) {
+ sprintf_overflow();
+ /* NOTREACHED */
+ }
+ return ((int)len);
+}
+#endif
+
+/*
+ * vsnprintf --
+ * Bounded version of vsprintf.
+ *
+ * PUBLIC: #ifndef HAVE_VSNPRINTF
+ * PUBLIC: int vsnprintf __P((char *, size_t, const char *, va_list));
+ * PUBLIC: #endif
+ */
+#ifndef HAVE_VSNPRINTF
+int
+vsnprintf(str, n, fmt, ap)
+ char *str;
+ size_t n;
+ const char *fmt;
+ va_list ap;
+{
+ static int ret_charpnt = -1;
+ size_t len;
+
+ if (ret_charpnt == -1)
+ ret_charpnt = sprintf_retcharpnt();
- COMPQUIET(n, 0);
+ len = (size_t)vsprintf(str, fmt, ap);
+ if (ret_charpnt)
+ len = strlen(str);
+
+ if (len >= n) {
+ sprintf_overflow();
+ /* NOTREACHED */
+ }
+ return ((int)len);
+}
+#endif
+
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
+static void
+sprintf_overflow()
+{
+ /*
+ * !!!
+ * We're potentially manipulating strings handed us by the application,
+ * and on systems without a real snprintf() the sprintf() calls could
+ * have overflowed the buffer. We can't do anything about it now, but
+ * we don't want to return control to the application, we might have
+ * overwritten the stack with a Trojan horse. We're not trying to do
+ * anything recoverable here because systems without snprintf support
+ * are pretty rare anymore.
+ */
+#define OVERFLOW_ERROR "internal buffer overflow, process ended\n"
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+ (void)write(STDERR_FILENO, OVERFLOW_ERROR, sizeof(OVERFLOW_ERROR) - 1);
+
+ /* Be polite. */
+ exit(1);
+
+ /* But firm. */
+ abort();
+
+ /* NOTREACHED */
+}
+
+static int
+sprintf_retcharpnt()
+{
+ int ret_charpnt;
+ char buf[10];
/*
* Some old versions of sprintf return a pointer to the first argument
@@ -53,22 +148,12 @@ snprintf(str, n, fmt, va_alist)
* We do this test at run-time because it's not a test we can do in a
* cross-compilation environment.
*/
- if (ret_charpnt == -1) {
- char buf[10];
- ret_charpnt =
- sprintf(buf, "123") != 3 ||
- sprintf(buf, "123456789") != 9 ||
- sprintf(buf, "1234") != 4;
- }
+ ret_charpnt =
+ (int)sprintf(buf, "123") != 3 ||
+ (int)sprintf(buf, "123456789") != 9 ||
+ (int)sprintf(buf, "1234") != 4;
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- len = vsprintf(str, fmt, ap);
- va_end(ap);
- return (ret_charpnt ? (int)strlen(str) : len);
+ return (ret_charpnt);
}
#endif
diff --git a/storage/bdb/clib/strcasecmp.c b/storage/bdb/clib/strcasecmp.c
index d5ce6d76d5f..e8365c4519a 100644
--- a/storage/bdb/clib/strcasecmp.c
+++ b/storage/bdb/clib/strcasecmp.c
@@ -29,14 +29,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: strcasecmp.c,v 1.8 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: strcasecmp.c,v 1.7 2001/11/15 17:51:38 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <string.h>
#endif
diff --git a/storage/bdb/clib/strdup.c b/storage/bdb/clib/strdup.c
index e68623f1407..9c451d3287a 100644
--- a/storage/bdb/clib/strdup.c
+++ b/storage/bdb/clib/strdup.c
@@ -29,14 +29,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: strdup.c,v 1.6 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: strdup.c,v 1.5 2002/05/01 18:40:05 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
diff --git a/storage/bdb/clib/strerror.c b/storage/bdb/clib/strerror.c
index 06c28946b88..e0710add26c 100644
--- a/storage/bdb/clib/strerror.c
+++ b/storage/bdb/clib/strerror.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2004
* Sleepycat Software. All rights reserved.
*/
/*
@@ -31,14 +31,12 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id: strerror.c,v 11.8 2004/01/28 03:35:52 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: strerror.c,v 11.6 2002/01/11 15:51:29 bostic Exp $";
-#endif /* not lint */
-
/*
* strerror --
* Return the string associated with an errno.
diff --git a/storage/bdb/clib/strtol.c b/storage/bdb/clib/strtol.c
new file mode 100644
index 00000000000..09e952dc5f8
--- /dev/null
+++ b/storage/bdb/clib/strtol.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: strtol.c,v 1.3 2004/10/28 19:27:19 bostic Exp $
+ */
+
+#include "db_config.h"
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <limits.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#endif
+
+/*
+ * Convert a string to a long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long
+strtol(nptr, endptr, base)
+ const char * nptr;
+ char ** endptr;
+ int base;
+{
+ const char *s;
+ unsigned long acc;
+ char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
+ /*
+ * 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((unsigned char)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)
+ goto noconv;
+
+ /*
+ * Compute the cutoff value between legal numbers and illegal
+ * numbers. That is the largest legal value, divided by the
+ * base. An input number that is greater than this value, if
+ * followed by a legal input character, is too big. One that
+ * is equal to this value may be valid or not; the limit
+ * between valid and invalid numbers is then based on the last
+ * digit. For instance, if the range for longs is
+ * [-2147483648..2147483647] and the input base is 10,
+ * cutoff will be set to 214748364 and cutlim to either
+ * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
+ * a value > 214748364, or equal but the next digit is > 7 (or 8),
+ * the number is too big, and we will return a range error.
+ *
+ * Set 'any' if any `digits' consumed; make it negative to indicate
+ * overflow.
+ */
+ cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX
+ : LONG_MAX;
+ cutlim = cutoff % base;
+ cutoff /= base;
+ 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;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = neg ? LONG_MIN : LONG_MAX;
+ errno = ERANGE;
+ } else if (!any) {
+noconv:
+ errno = EINVAL;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != NULL)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/storage/bdb/clib/strtoul.c b/storage/bdb/clib/strtoul.c
new file mode 100644
index 00000000000..e4356963ba0
--- /dev/null
+++ b/storage/bdb/clib/strtoul.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: strtoul.c,v 1.3 2004/10/28 19:27:19 bostic Exp $
+ */
+
+#include "db_config.h"
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <limits.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#endif
+
+/*
+ * Convert a string to an unsigned long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long
+strtoul(nptr, endptr, base)
+ const char * nptr;
+ char ** endptr;
+ int base;
+{
+ const char *s;
+ unsigned long acc;
+ char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace((unsigned char)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)
+ goto noconv;
+
+ cutoff = ULONG_MAX / base;
+ cutlim = ULONG_MAX % base;
+ 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;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = ULONG_MAX;
+ errno = ERANGE;
+ } else if (!any) {
+noconv:
+ errno = EINVAL;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != NULL)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}