os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtoll.c
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtoll.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,111 @@
1.4 +/*
1.5 + * strtoll.c --
1.6 + *
1.7 + * Source code for the "strtoll" library procedure.
1.8 + *
1.9 + * Copyright (c) 1988 The Regents of the University of California.
1.10 + * Copyright (c) 1994 Sun Microsystems, Inc.
1.11 + *
1.12 + * See the file "license.terms" for information on usage and redistribution
1.13 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.14 + *
1.15 + * RCS: @(#) $Id: strtoll.c,v 1.5 2002/02/24 02:53:25 dgp Exp $
1.16 + */
1.17 +
1.18 +#include "tcl.h"
1.19 +#include "tclPort.h"
1.20 +#include <ctype.h>
1.21 +
1.22 +#define TCL_WIDEINT_MAX (((Tcl_WideUInt)Tcl_LongAsWide(-1))>>1)
1.23 +
1.24 +
1.25 +/*
1.26 + *----------------------------------------------------------------------
1.27 + *
1.28 + * strtoll --
1.29 + *
1.30 + * Convert an ASCII string into an integer.
1.31 + *
1.32 + * Results:
1.33 + * The return value is the integer equivalent of string. If endPtr
1.34 + * is non-NULL, then *endPtr is filled in with the character
1.35 + * after the last one that was part of the integer. If string
1.36 + * doesn't contain a valid integer value, then zero is returned
1.37 + * and *endPtr is set to string.
1.38 + *
1.39 + * Side effects:
1.40 + * None.
1.41 + *
1.42 + *----------------------------------------------------------------------
1.43 + */
1.44 +
1.45 +#if TCL_WIDE_INT_IS_LONG
1.46 +long long
1.47 +#else
1.48 +Tcl_WideInt
1.49 +#endif
1.50 +strtoll(string, endPtr, base)
1.51 + CONST char *string; /* String of ASCII digits, possibly
1.52 + * preceded by white space. For bases
1.53 + * greater than 10, either lower- or
1.54 + * upper-case digits may be used.
1.55 + */
1.56 + char **endPtr; /* Where to store address of terminating
1.57 + * character, or NULL. */
1.58 + int base; /* Base for conversion. Must be less
1.59 + * than 37. If 0, then the base is chosen
1.60 + * from the leading characters of string:
1.61 + * "0x" means hex, "0" means octal, anything
1.62 + * else means decimal.
1.63 + */
1.64 +{
1.65 + register CONST char *p;
1.66 + Tcl_WideInt result = Tcl_LongAsWide(0);
1.67 + Tcl_WideUInt uwResult;
1.68 +
1.69 + /*
1.70 + * Skip any leading blanks.
1.71 + */
1.72 +
1.73 + p = string;
1.74 + while (isspace(UCHAR(*p))) {
1.75 + p += 1;
1.76 + }
1.77 +
1.78 + /*
1.79 + * Check for a sign.
1.80 + */
1.81 +
1.82 + errno = 0;
1.83 + if (*p == '-') {
1.84 + p += 1;
1.85 + uwResult = strtoull(p, endPtr, base);
1.86 + if (errno != ERANGE) {
1.87 + if (uwResult > TCL_WIDEINT_MAX+1) {
1.88 + errno = ERANGE;
1.89 + return Tcl_LongAsWide(-1);
1.90 + } else if (uwResult > TCL_WIDEINT_MAX) {
1.91 + return ~((Tcl_WideInt)TCL_WIDEINT_MAX);
1.92 + } else {
1.93 + result = -((Tcl_WideInt) uwResult);
1.94 + }
1.95 + }
1.96 + } else {
1.97 + if (*p == '+') {
1.98 + p += 1;
1.99 + }
1.100 + uwResult = strtoull(p, endPtr, base);
1.101 + if (errno != ERANGE) {
1.102 + if (uwResult > TCL_WIDEINT_MAX) {
1.103 + errno = ERANGE;
1.104 + return Tcl_LongAsWide(-1);
1.105 + } else {
1.106 + result = uwResult;
1.107 + }
1.108 + }
1.109 + }
1.110 + if ((result == 0) && (endPtr != 0) && (*endPtr == p)) {
1.111 + *endPtr = (char *) string;
1.112 + }
1.113 + return result;
1.114 +}