#include <limits.h>
#include "ft_string.h"
Go to the source code of this file.
|
| static int | get_36based_value (char c) |
| |
| static int | set_value (char c, long *p_value, int sign, int base) |
| |
| static int | get_base (const char **p_str, const int base) |
| |
| long | ft_strtol (const char *str, char **endptr, int base) |
| |
◆ ft_strtol()
| long ft_strtol |
( |
const char * |
str, |
|
|
char ** |
endptr, |
|
|
int |
base |
|
) |
| |
Definition at line 69 of file ft_strtol.c.
77 *endptr = (
char *)str;
78 if (!((2 <= base && base <= 36) || base == 0))
80 while (((9 <= *str && *str <= 13) || *str ==
' ') && *str !=
'\0')
84 else if (*str !=
'+' && !((
'a' <= *str && *str <=
'z')
85 || (
'A' <= *str && *str <=
'Z') || (
'0' <= *str && *str <=
'9')))
87 if (*str ==
'+' || *str ==
'-')
90 while (
set_value(*str, &value, sign, base))
93 *endptr = (
char *)str;
static int get_base(const char **p_str, const int base)
static int set_value(char c, long *p_value, int sign, int base)
◆ get_36based_value()
| static int get_36based_value |
( |
char |
c | ) |
|
|
static |
Definition at line 16 of file ft_strtol.c.
18 if (
'0' <= c && c <=
'9')
20 else if (
'a' <= c && c <=
'z')
21 return (c -
'a' + 10);
22 else if (
'A' <= c && c <=
'Z')
23 return (c -
'A' + 10);
◆ get_base()
| static int get_base |
( |
const char ** |
p_str, |
|
|
const int |
base |
|
) |
| |
|
static |
Definition at line 52 of file ft_strtol.c.
56 if ((*p_str)[0] ==
'0')
58 if ((*p_str)[1] ==
'x')
◆ set_value()
| static int set_value |
( |
char |
c, |
|
|
long * |
p_value, |
|
|
int |
sign, |
|
|
int |
base |
|
) |
| |
|
static |
Definition at line 28 of file ft_strtol.c.
34 if (num_value < 0 || base <= num_value)
37 value_tmp = (*p_value) * base;
38 if (sign > 0 && (((LONG_MAX / base) < *p_value)
39 || ((LONG_MAX - value_tmp) < num_value)))
41 else if (sign < 0 && (((LONG_MIN / base) > *p_value)
42 || ((LONG_MIN - value_tmp) > num_value)))
46 *p_value = value_tmp + num_value;
static int get_36based_value(char c)