Subversion Repositories shark

Rev

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