OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [compat/] [strtol.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * strtol.c --
3
 *
4
 *      Source code for the "strtol" library procedure.
5
 *
6
 * Copyright (c) 1988 The Regents of the University of California.
7
 * Copyright (c) 1994 Sun Microsystems, Inc.
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 * RCS: @(#) $Id: strtol.c,v 1.1.1.1 2002-01-16 10:25:23 markom Exp $
13
 */
14
 
15
#include <ctype.h>
16
 
17
 
18
/*
19
 *----------------------------------------------------------------------
20
 *
21
 * strtol --
22
 *
23
 *      Convert an ASCII string into an integer.
24
 *
25
 * Results:
26
 *      The return value is the integer equivalent of string.  If endPtr
27
 *      is non-NULL, then *endPtr is filled in with the character
28
 *      after the last one that was part of the integer.  If string
29
 *      doesn't contain a valid integer value, then zero is returned
30
 *      and *endPtr is set to string.
31
 *
32
 * Side effects:
33
 *      None.
34
 *
35
 *----------------------------------------------------------------------
36
 */
37
 
38
long int
39
strtol(string, endPtr, base)
40
    char *string;               /* String of ASCII digits, possibly
41
                                 * preceded by white space.  For bases
42
                                 * greater than 10, either lower- or
43
                                 * upper-case digits may be used.
44
                                 */
45
    char **endPtr;              /* Where to store address of terminating
46
                                 * character, or NULL. */
47
    int base;                   /* Base for conversion.  Must be less
48
                                 * than 37.  If 0, then the base is chosen
49
                                 * from the leading characters of string:
50
                                 * "0x" means hex, "0" means octal, anything
51
                                 * else means decimal.
52
                                 */
53
{
54
    register char *p;
55
    int result;
56
 
57
    /*
58
     * Skip any leading blanks.
59
     */
60
 
61
    p = string;
62
    while (isspace(*p)) {
63
        p += 1;
64
    }
65
 
66
    /*
67
     * Check for a sign.
68
     */
69
 
70
    if (*p == '-') {
71
        p += 1;
72
        result = -(strtoul(p, endPtr, base));
73
    } else {
74
        if (*p == '+') {
75
            p += 1;
76
        }
77
        result = strtoul(p, endPtr, base);
78
    }
79
    if ((result == 0) && (endPtr != 0) && (*endPtr == p)) {
80
        *endPtr = string;
81
    }
82
    return result;
83
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.