Rev 3 | 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 | |||
22 | #include <ll/i386/stdlib.h> |
||
23 | #include <ll/i386/string.h> |
||
24 | #include <ll/i386/limits.h> |
||
25 | #include <ll/stdarg.h> |
||
26 | #include <ll/ctype.h> |
||
27 | |||
28 | FILE(strtou); |
||
29 | |||
30 | long unsigned strtou(char *s,int base,char **scan_end) |
||
31 | { |
||
32 | int value,overflow = 0; |
||
33 | long unsigned result = 0,oldresult; |
||
34 | /* Skip trailing zeros */ |
||
35 | while (*s == '0') s++; |
||
36 | if (*s == 'x' && base == 16) { |
||
37 | s++; |
||
38 | while (*s == '0') s++; |
||
39 | } |
||
40 | /* Convert number */ |
||
41 | while (isnumber(*s,base)) { |
||
42 | value = tonumber(*s++); |
||
43 | if (value > base || value < 0) return(0); |
||
44 | oldresult = result; |
||
45 | result *= base; |
||
46 | result += value; |
||
47 | /* Detect overflow */ |
||
48 | if (oldresult > result) overflow = 1; |
||
49 | } |
||
50 | if (scan_end != 0L) *scan_end = s; |
||
51 | if (overflow) result = INT_MAX; |
||
52 | return(result); |
||
53 | } |
||
54 | |||
55 |