os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtoll.c
Update contrib.
4 * Source code for the "strtoll" library procedure.
6 * Copyright (c) 1988 The Regents of the University of California.
7 * Copyright (c) 1994 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * RCS: @(#) $Id: strtoll.c,v 1.5 2002/02/24 02:53:25 dgp Exp $
19 #define TCL_WIDEINT_MAX (((Tcl_WideUInt)Tcl_LongAsWide(-1))>>1)
23 *----------------------------------------------------------------------
27 * Convert an ASCII string into an integer.
30 * The return value is the integer equivalent of string. If endPtr
31 * is non-NULL, then *endPtr is filled in with the character
32 * after the last one that was part of the integer. If string
33 * doesn't contain a valid integer value, then zero is returned
34 * and *endPtr is set to string.
39 *----------------------------------------------------------------------
42 #if TCL_WIDE_INT_IS_LONG
47 strtoll(string, endPtr, base)
48 CONST char *string; /* String of ASCII digits, possibly
49 * preceded by white space. For bases
50 * greater than 10, either lower- or
51 * upper-case digits may be used.
53 char **endPtr; /* Where to store address of terminating
54 * character, or NULL. */
55 int base; /* Base for conversion. Must be less
56 * than 37. If 0, then the base is chosen
57 * from the leading characters of string:
58 * "0x" means hex, "0" means octal, anything
62 register CONST char *p;
63 Tcl_WideInt result = Tcl_LongAsWide(0);
64 Tcl_WideUInt uwResult;
67 * Skip any leading blanks.
71 while (isspace(UCHAR(*p))) {
82 uwResult = strtoull(p, endPtr, base);
83 if (errno != ERANGE) {
84 if (uwResult > TCL_WIDEINT_MAX+1) {
86 return Tcl_LongAsWide(-1);
87 } else if (uwResult > TCL_WIDEINT_MAX) {
88 return ~((Tcl_WideInt)TCL_WIDEINT_MAX);
90 result = -((Tcl_WideInt) uwResult);
97 uwResult = strtoull(p, endPtr, base);
98 if (errno != ERANGE) {
99 if (uwResult > TCL_WIDEINT_MAX) {
101 return Tcl_LongAsWide(-1);
107 if ((result == 0) && (endPtr != 0) && (*endPtr == p)) {
108 *endPtr = (char *) string;