PatchworkOS
Loading...
Searching...
No Matches
atoll.c
Go to the documentation of this file.
1#include <ctype.h>
2#include <stdbool.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include "common/digits.h"
7
8long long int atoll(const char* nptr)
9{
10 long long int result = 0;
11 bool isNegative = false;
12
13 while (isspace((unsigned char)*nptr))
14 {
15 nptr++;
16 }
17
18 if (*nptr == '+')
19 {
20 nptr++;
21 }
22 else if (*nptr == '-')
23 {
24 nptr++;
25 isNegative = true;
26 }
27
28 const char* x;
29 while ((x = (const char*)memchr(_digits, tolower((unsigned char)*(nptr++)), 10)) != NULL)
30 {
31 result = result * 10 + (x - _digits);
32 }
33
34 return isNegative ? -result : result;
35}
long long int atoll(const char *nptr)
Definition atoll.c:8
_PUBLIC int tolower(int c)
Definition tolower.c:5
_PUBLIC int isspace(int c)
Definition isspace.c:5
const char _digits[]
Definition digits.c:3
#define NULL
Pointer error value.
Definition NULL.h:23
int64_t x
Definition main.c:152
_PUBLIC void * memchr(const void *s, int c, size_t n)
Definition memchr.c:3