42_minishell/builtins/unset.c
Camille Chauvet 9f0b0f5422 add: exit cmd
2023-02-24 13:13:11 +01:00

36 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int error(char *str, int fd)
{
write(fd, "bash: unset: `", 14);
write(fd, str, ft_strlen(str));
write(fd, "': not a valid identifier", 25);
return (1);
}
int unset(t_list **env, char **args, int fd)
{
int i;
int err;
i = -1;
err = 0;
while (args[++i])
if (delete_by_key(args[i], env))
if (!possible_key(args[i]))
err = error(args[i], fd);
return (err);
}