42_minishell/builtins/unset.c

36 lines
1.3 KiB
C
Raw Normal View History

2023-02-22 08:00:09 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
2023-02-23 11:19:25 -05:00
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
2023-02-22 08:00:09 -05:00
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
2023-02-24 07:13:11 -05:00
2023-02-23 11:19:25 -05:00
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);
}
2023-02-22 08:00:09 -05:00
int unset(t_list **env, char **args, int fd)
{
2023-02-23 11:19:25 -05:00
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);
2023-02-22 08:00:09 -05:00
}