os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtol.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtol.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +/* 
     1.5 + * strtol.c --
     1.6 + *
     1.7 + *	Source code for the "strtol" 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: strtol.c,v 1.4 2002/02/25 16:23:26 dgp Exp $
    1.16 + */
    1.17 +
    1.18 +#include <ctype.h>
    1.19 +#include "tclInt.h"
    1.20 +#include "tclPort.h"
    1.21 +
    1.22 +
    1.23 +/*
    1.24 + *----------------------------------------------------------------------
    1.25 + *
    1.26 + * strtol --
    1.27 + *
    1.28 + *	Convert an ASCII string into an integer.
    1.29 + *
    1.30 + * Results:
    1.31 + *	The return value is the integer equivalent of string.  If endPtr
    1.32 + *	is non-NULL, then *endPtr is filled in with the character
    1.33 + *	after the last one that was part of the integer.  If string
    1.34 + *	doesn't contain a valid integer value, then zero is returned
    1.35 + *	and *endPtr is set to string.
    1.36 + *
    1.37 + * Side effects:
    1.38 + *	None.
    1.39 + *
    1.40 + *----------------------------------------------------------------------
    1.41 + */
    1.42 +
    1.43 +long int
    1.44 +strtol(string, endPtr, base)
    1.45 +    CONST char *string;		/* String of ASCII digits, possibly
    1.46 +				 * preceded by white space.  For bases
    1.47 +				 * greater than 10, either lower- or
    1.48 +				 * upper-case digits may be used.
    1.49 +				 */
    1.50 +    char **endPtr;		/* Where to store address of terminating
    1.51 +				 * character, or NULL. */
    1.52 +    int base;			/* Base for conversion.  Must be less
    1.53 +				 * than 37.  If 0, then the base is chosen
    1.54 +				 * from the leading characters of string:
    1.55 +				 * "0x" means hex, "0" means octal, anything
    1.56 +				 * else means decimal.
    1.57 +				 */
    1.58 +{
    1.59 +    register CONST char *p;
    1.60 +    long result;
    1.61 +
    1.62 +    /*
    1.63 +     * Skip any leading blanks.
    1.64 +     */
    1.65 +
    1.66 +    p = string;
    1.67 +    while (isspace(UCHAR(*p))) {
    1.68 +	p += 1;
    1.69 +    }
    1.70 +
    1.71 +    /*
    1.72 +     * Check for a sign.
    1.73 +     */
    1.74 +
    1.75 +    if (*p == '-') {
    1.76 +	p += 1;
    1.77 +	result = -(strtoul(p, endPtr, base));
    1.78 +    } else {
    1.79 +	if (*p == '+') {
    1.80 +	    p += 1;
    1.81 +	}
    1.82 +	result = strtoul(p, endPtr, base);
    1.83 +    }
    1.84 +    if ((result == 0) && (endPtr != 0) && (*endPtr == p)) {
    1.85 +	*endPtr = (char *) string;
    1.86 +    }
    1.87 +    return result;
    1.88 +}