Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
atol.c
Go to the documentation of this file.
1 #include <ctype.h>
2 #include <stdbool.h>
3 #include <stdlib.h>
4 
5 long atol(const char* str)
6 {
7  long val = 0;
8  bool neg = false;
9 
10  while(isspace(*str))
11  {
12  str++;
13  }
14 
15  switch(*str)
16  {
17  case '-':
18  neg = true;
19  // intentional fallthrough
20  case '+':
21  str++;
22  }
23 
24  while(isdigit(*str))
25  {
26  val = (10 * val) + (*str++ - '0');
27  }
28 
29  return neg ? -val : val;
30 }
long atol(const char *str)
Interprets a Long value in a byte string pointed to by str.
Definition: atol.c:5
int isspace(int ch)
Checks if the given character is a whitespace character.
Definition: isspace.c:5
int isdigit(int ch)
Checks if the given character is a numeric character.
Definition: isdigit.c:5