49 lines
1.6 KiB
C
49 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* exit.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
|
/* Updated: 2023/02/28 14:28:18 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../minishell.h"
|
|
|
|
static int error(int err, char *reason, char *problem, int fd)
|
|
{
|
|
ft_putstr_fd("minishell: exit ", fd);
|
|
if (problem != NULL)
|
|
{
|
|
ft_putstr_fd(problem, fd);
|
|
write(fd, ": ", 2);
|
|
}
|
|
ft_putstr_fd(reason, fd);
|
|
write(fd, "\n", 1);
|
|
return (err);
|
|
}
|
|
|
|
int ft_exit(char **args, int fd)
|
|
{
|
|
int err;
|
|
|
|
if (args[0] == NULL)
|
|
return (0);
|
|
err = ft_atoi_check(args[0]);
|
|
if (err == 1)
|
|
return (error(err, "numeric argument required", args[0], fd));
|
|
if (args[1] != NULL)
|
|
return (error(-1, "too many arguments", NULL, fd));
|
|
if (error > 0)
|
|
error(err, "numeric argument required", args[0], fd);
|
|
return (ft_atoi(args[0]) % 256);
|
|
}
|
|
|
|
/* int main(int argc, char *argv[]) */
|
|
/* { */
|
|
/* (void)argc; */
|
|
/* return(ft_exit(argv + 1, 1)); */
|
|
/* } */
|