Rev 1619 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
1621 | fabio | 22 | #include <arch/i386/stdlib.h> |
23 | #include <arch/i386/string.h> |
||
24 | #include <arch/i386/limits.h> |
||
25 | #include <arch/stdarg.h> |
||
26 | #include <arch/ctype.h> |
||
27 | #include <arch/math.h> |
||
2 | pj | 28 | |
29 | FILE(strtoi); |
||
30 | |||
31 | long int strtoi(char *s,int base,char **scan_end) |
||
32 | { |
||
33 | int sign,value,overflow = 0; |
||
34 | long int result = 0,oldresult; |
||
35 | /* Evaluate sign */ |
||
36 | if (*s == '-') { |
||
37 | sign = -1; |
||
38 | s++; |
||
39 | } else if (*s == '+') { |
||
40 | sign = 1; |
||
41 | s++; |
||
42 | } |
||
43 | else sign = 1; |
||
44 | /* Skip trailing zeros */ |
||
45 | while (*s == '0') s++; |
||
46 | /* Convert number */ |
||
47 | while (isnumber(*s,base)) { |
||
48 | value = tonumber(*s++); |
||
49 | if (value > base || value < 0) return(0); |
||
50 | oldresult = result; |
||
51 | result *= base; |
||
52 | result += value; |
||
53 | /* Detect overflow */ |
||
54 | if (oldresult > result) overflow = 1; |
||
55 | } |
||
56 | if (scan_end != 0L) *scan_end = s; |
||
57 | if (overflow) result = INT_MAX; |
||
58 | result *= sign; |
||
59 | return(result); |
||
60 | } |