minishell
ft_atoi_strict.c File Reference
#include "../ft_is/ft_is.h"
#include "../ft_math/ft_math.h"
#include <stddef.h>
Include dependency graph for ft_atoi_strict.c:

Go to the source code of this file.

Functions

static bool set_value (char c, int *value, int sign)
 
bool ft_atoi_strict (const char *str, const char **endptr, int *dst)
 

Function Documentation

◆ ft_atoi_strict()

bool ft_atoi_strict ( const char *  str,
const char **  endptr,
int *  dst 
)

Definition at line 32 of file ft_atoi_strict.c.

33 {
34  int sign;
35 
36  if (str == NULL || dst == NULL)
37  return (false);
38  if (*endptr != NULL)
39  *endptr = str;
40  sign = 1;
41  if (*str == '-')
42  sign = -1;
43  if (*str == '-' || *str == '+')
44  str++;
45  if (*endptr != NULL)
46  *endptr = str;
47  if (!ft_isdigit(*str))
48  return (false);
49  *dst = 0;
50  while (set_value(*str, dst, sign))
51  str++;
52  if (*endptr != NULL)
53  *endptr = str;
54  return (true);
55 }
static bool set_value(char c, int *value, int sign)
int ft_isdigit(int c)
Definition: ft_isdigit.c:15
Here is the call graph for this function:

◆ set_value()

static bool set_value ( char  c,
int *  value,
int  sign 
)
static

Definition at line 19 of file ft_atoi_strict.c.

20 {
21  int c_value;
22 
23  if (!ft_isdigit(c))
24  return (false);
25  c_value = (c - '0') * sign;
26  if (!can_mul(*value, 10) || !can_add(*value * 10, c_value))
27  return (false);
28  *value = (*value * 10) + c_value;
29  return (true);
30 }
bool can_add(int a, int b)
Definition: can_add.c:18
bool can_mul(int a, int b)
Definition: can_mul.c:18
Here is the call graph for this function:
Here is the caller graph for this function: