From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- 42sh/src/builtins/unset.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 42sh/src/builtins/unset.c (limited to '42sh/src/builtins/unset.c') diff --git a/42sh/src/builtins/unset.c b/42sh/src/builtins/unset.c new file mode 100644 index 0000000..77b323a --- /dev/null +++ b/42sh/src/builtins/unset.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include "builtins.h" +#include "utils/env.h" + +int unset(struct string **args) +{ + size_t i = 0; + int var = 0; + int fun = 0; + while (args[i] != NULL && args[i]->data[0] == '-') + { + if (args[i]->data[1] == 'v') + { + var = 1; + i += 1; + } + else if (args[i]->data[1] == 'f') + { + fun = 1; + i += 1; + } + else + { + break; + } + } + if (var == 0 && fun == 0) + { + var = 1; + fun = 1; + } + // TODO unset with flag -f + while (args[i] != NULL) + { + env_unset(args[i]->data); + i += 1; + } + fflush(stdout); + return 0; +} -- cgit v1.2.3