PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
strtoul.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#define SYSCLIB_DISABLE_BUILTINS
12#include <sysclib.h>
13#include "sysclib_determine_base.h"
14
15unsigned long strtoul(const char *s, char **endptr, int base)
16{
17 char *v3;
18 unsigned int v6;
19 int v7;
20 int v8;
21 char v9;
22 int v10;
23 char *v11;
24
25 v3 = (char *)s;
26 v6 = 0;
27 if (!s)
28 {
29 return v6;
30 }
31 while (isspace(*v3) != 0)
32 {
33 v3 += 1;
34 }
35 if ((unsigned int)(base - 2) >= 0x23)
36 {
37 base = 0;
38 }
39 if (!base)
40 {
41 base = 10;
42 }
43 v7 = *v3;
44 if (v7 != 48)
45 {
46 if (toupper(v7) == 79)
47 {
48 v3 += 1;
49 base = 8;
50 }
51 goto LABEL_19;
52 }
53 v8 = *++v3;
54 if (v8 == 88)
55 {
56 goto LABEL_15;
57 }
58 if (v8 < 89)
59 {
60 if (v8 != 66)
61 {
62 goto LABEL_19;
63 }
64 goto LABEL_16;
65 }
66 if (v8 == 98)
67 {
68LABEL_16:
69 v3 += 1;
70 base = 2;
71 goto LABEL_19;
72 }
73 if (v8 == 120)
74 {
75LABEL_15:
76 v3 += 1;
77 base = 16;
78 }
79LABEL_19:
80 while (1)
81 {
82 v9 = *v3++;
83 v10 = sysclib_determine_base(v9);
84 if (v10 >= base)
85 {
86 break;
87 }
88 v6 = v6 * base + v10;
89 }
90 v11 = v3 - 1;
91 if (endptr)
92 {
93 *endptr = v11;
94 }
95 return v6;
96}