int ft_atoi(char *str) { int n; char sign; int c; n = 0; while (ft_isspace(*str)) ++str; sign = *str; if (sign == '+' || sign == '-') ++str; while (ft_is_numeric(*str)) { c = *str - '0'; n = n * 10 + c; ++str; } return (sign == '-' ? -n : n); }
int ft_my_sh_exit(char *line) { int exit; char **all; exit = -3; if (!(all = ft_strparse(line))) return (-1); if (!all[0]) return (-2); else if (ft_strcmp(all[0], "exit") != 0) return (-2); else if (!all[1]) exit = 0; else if (all[1] && all[2]) ft_putendl("exit: too many arguments"); else if (all[1] && !ft_is_numeric(all[1])) exit = ft_atoi(all[1]); else ft_putendl("exit: enter a numeric argument between 0 and 999999999"); return (exit % 256); }