builtins/pwd.c \
builtins/env.c \
builtins/export.c \
+ builtins/unset.c \
SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
int pwd(void);
int ft_env(int argc, t_execution_env *env);
int export(int argc, char **argv, t_execution_env *env);
+int unset(int argc, char **argv, t_execution_env *env);
+
+void unset_single(const char *var_name, t_execution_env *env);
#endif // BUILTINS_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/23 09:40:38 by ljiriste #+# #+# */
-/* Updated: 2024/08/26 11:44:35 by ljiriste ### ########.fr */
+/* Updated: 2024/08/26 11:47:56 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_structs.h"
#include <stdlib.h>
-static void unset_single(const char *name, t_execution_env *env)
-{
- ssize_t index;
-
- index = get_var_index(&env->vars->other, name);
- if (index >= 0)
- ft_vec_erase(&env->vars->other, index, free_str);
- index = get_var_index(&env->vars->exported, name);
- if (index >= 0)
- ft_vec_erase(&env->vars->exported, index, free_str);
- return ;
-}
-
static int export_single(const char *var, t_execution_env *env)
{
char *name;
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* unset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/08/26 08:18:30 by ljiriste #+# #+# */
+/* Updated: 2024/08/26 11:47:56 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "builtins.h"
+#include "minishell_structs.h"
+
+void unset_single(const char *name, t_execution_env *env)
+{
+ ssize_t index;
+
+ index = get_var_index(&env->vars->other, name);
+ if (index >= 0)
+ ft_vec_erase(&env->vars->other, index, free_str);
+ index = get_var_index(&env->vars->exported, name);
+ if (index >= 0)
+ ft_vec_erase(&env->vars->exported, index, free_str);
+ return ;
+}
+
+int unset(__attribute__((unused)) int argc, char **argv, t_execution_env *env)
+{
+ size_t i;
+
+ i = 1;
+ while (argv[i])
+ {
+ unset_single(argv[i], env);
+ ++i;
+ }
+ return (0);
+}
return (1);
if (!ft_strcmp(str, "export"))
return (1);
+ if (!ft_strcmp(str, "unset"))
+ return (1);
return (0);
}
env->ret_val = ft_env(count_fields(fields), env);
else if (!ft_strcmp(fields[0], "export"))
env->ret_val = export(count_fields(fields), fields, env);
+ else if (!ft_strcmp(fields[0], "unset"))
+ env->ret_val = unset(count_fields(fields), fields, env);
else
return (-1);
return (0);