PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
strtol.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
15long strtol(const char *s, char **endptr, int base)
16{
17 char *v3;
18 int v6;
19 int v7;
20 int v9;
21 int v10;
22 char v11;
23 int v12;
24 char *v13;
25
26 v3 = (char *)s;
27 v6 = 1;
28 v7 = 0;
29 if (!s)
30 {
31 return 0;
32 }
33 while (isspace(*v3) != 0)
34 {
35 v3 += 1;
36 }
37 for (; *v3 == 45; v6 = -v6)
38 {
39 v3 += 1;
40 }
41 if ((unsigned int)(base - 2) >= 0x23)
42 base = 0;
43 if (!base)
44 base = 10;
45 v9 = *v3;
46 if (v9 != 48)
47 {
48 if (toupper(v9) == 79)
49 {
50 v3 += 1;
51 base = 8;
52 }
53 goto LABEL_22;
54 }
55 v10 = *++v3;
56 if (v10 == 88)
57 {
58 goto LABEL_18;
59 }
60 if (v10 < 89)
61 {
62 if (v10 != 66)
63 {
64 goto LABEL_22;
65 }
66 goto LABEL_19;
67 }
68 if (v10 == 98)
69 {
70LABEL_19:
71 v3 += 1;
72 base = 2;
73 goto LABEL_22;
74 }
75 if (v10 == 120)
76 {
77LABEL_18:
78 v3 += 1;
79 base = 16;
80 }
81LABEL_22:
82 while (1)
83 {
84 v11 = *v3++;
85 v12 = sysclib_determine_base(v11);
86 if (v12 >= base)
87 {
88 break;
89 }
90 v7 = v7 * base + v12;
91 }
92 v13 = v3 - 1;
93 if (endptr)
94 {
95 *endptr = v13;
96 }
97 return v7 * v6;
98}