gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/atoi.c
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <types.h>
4 #include <ctype.h>
5
6 inline bool _isdigit(char c) {
7 return ((uint8_t)((uint8_t)c - '0') < 10u) ? true : false;
8 }
9
10 int atoi(const char *s) NONBANKED
11 {
12 bool sign = false;
13 int n;
14
15 const uint8_t * pc = (const uint8_t *)s;
16
17 for(; ((*pc == ' ') || (*pc == '\t') || (*pc == '\n')); ++pc);
18
19 switch(*pc) {
20 case '-':
21 sign = true;
22 /* and fall through */
23 case '+':
24 ++pc;
25 break;
26 }
27
28 for(n = 0; _isdigit(*pc); ++pc) n = 10 * n + (*pc - '0');
29
30 return (sign == 0 ? n : -n);
31 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.