/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* exit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */ /* Updated: 2023/04/05 12:16:37 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "./builtins_private.h" static int error(int err, char *reason, char *problem) { ft_putstr_fd("minishell: exit ", 2); if (problem != NULL) { ft_putstr_fd(problem, 2); write(2, ": ", 3); } ft_putstr_fd(reason, 2); return (err); } int ft_exit(char **args, int err) { int err; if (args[0] == NULL) { write(1, "exit\n", 6); return (err); } err = ft_atoi_check(args[0]); if (err == 1) return (error(err, "exit: numeric argument required", args[0])); if (args[1] != NULL) return (error(-1, "exit: too many arguments", NULL)); if (err > 0) return (error(err, "exit: numeric argument required", args[0])); write(1, "exit\n", 6); return ((ft_atoi(args[0]) % 256 + 256) % 256); }