2023-02-24 06:46:02 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* exit.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
2023-02-28 08:53:56 -05:00
|
|
|
/* Updated: 2023/02/28 14:53:35 by erey-bet ### ########.fr */
|
2023-02-24 06:46:02 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "../minishell.h"
|
|
|
|
|
|
|
|
static int error(int err, char *reason, char *problem, int fd)
|
|
|
|
{
|
2023-02-28 08:40:51 -05:00
|
|
|
ft_putstr_fd("minishell: exit ", 2);
|
2023-02-24 06:46:02 -05:00
|
|
|
if (problem != NULL)
|
|
|
|
{
|
2023-02-28 08:40:51 -05:00
|
|
|
ft_putstr_fd(problem, 2);
|
2023-02-28 08:53:56 -05:00
|
|
|
write(2, ": ", 3);
|
2023-02-24 06:46:02 -05:00
|
|
|
}
|
2023-02-28 08:40:51 -05:00
|
|
|
ft_putstr_fd(reason, 2);
|
2023-02-24 06:46:02 -05:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_exit(char **args, int fd)
|
|
|
|
{
|
2023-02-28 08:25:20 -05:00
|
|
|
int err;
|
2023-02-24 06:46:02 -05:00
|
|
|
|
|
|
|
if (args[0] == NULL)
|
|
|
|
return (0);
|
2023-02-28 08:28:54 -05:00
|
|
|
err = ft_atoi_check(args[0]);
|
2023-02-28 08:25:20 -05:00
|
|
|
if (err == 1)
|
|
|
|
return (error(err, "numeric argument required", args[0], fd));
|
2023-02-24 06:46:02 -05:00
|
|
|
if (args[1] != NULL)
|
|
|
|
return (error(-1, "too many arguments", NULL, fd));
|
2023-02-28 08:40:51 -05:00
|
|
|
if (err > 0)
|
|
|
|
return(error(err, "numeric argument required", args[0], fd));
|
2023-02-28 08:51:39 -05:00
|
|
|
return ((ft_atoi(args[0]) % 256 + 256) % 256);
|
2023-02-24 06:46:02 -05:00
|
|
|
}
|
|
|
|
|
2023-02-28 08:51:39 -05:00
|
|
|
/*int main(int argc, char *argv[])
|
2023-02-28 08:40:51 -05:00
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
return(ft_exit(argv + 1, 1));
|
2023-02-28 08:51:39 -05:00
|
|
|
}*/
|