wip builtins: env, exit
This commit is contained in:
21
srcs/builtins/env.c
Normal file
21
srcs/builtins/env.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/10 05:01:26 by lperrey #+# #+# */
|
||||
/* Updated: 2021/10/10 07:37:29 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int builtin_env(int argc, char *argv[], t_all *c) // WIP
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
ft_putendl_arr_fd(c->envp, 1);
|
||||
return (0);
|
||||
}
|
||||
46
srcs/builtins/exit.c
Normal file
46
srcs/builtins/exit.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/10 05:01:22 by lperrey #+# #+# */
|
||||
/* Updated: 2021/10/10 08:50:37 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int builtin_exit(int argc, char *argv[], t_all *c) // WIP
|
||||
{
|
||||
unsigned char status;
|
||||
int i;
|
||||
|
||||
status = 0;
|
||||
if (argc > 2)
|
||||
return (ft_reti_print(1, "exit: too many arguments\n", 2));
|
||||
if (argc == 2)
|
||||
{
|
||||
i = 0;
|
||||
while (argv[1][i])
|
||||
{
|
||||
if ((argv[1][0] == '-' || argv[1][0] == '+') && argv[1][1] != '\0')
|
||||
i++;
|
||||
while (ft_isdigit(argv[1][i]))
|
||||
i++;
|
||||
if (argv[1][i] != '\0')
|
||||
{
|
||||
ft_putstr_fd("exit: ", 2);
|
||||
ft_putstr_fd(argv[1], 2);
|
||||
return (ft_reti_print(2, " numeric argument required\n", 2));
|
||||
}
|
||||
}
|
||||
status = ft_atoi(argv[1]);
|
||||
}
|
||||
// TODO : remplacer exit(status) par
|
||||
(void)c;
|
||||
exit(status);
|
||||
return (0);
|
||||
// return (free_exit(&c, status));
|
||||
}
|
||||
Reference in New Issue
Block a user