summaryrefslogtreecommitdiffstats
path: root/src/b_export_next.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-03 17:26:41 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-03 17:26:41 +0200
commit1886374416e5dc436db68e3518603258ae32bac0 (patch)
tree06a7ae626521205dcbf921ef90f12dda7600cc14 /src/b_export_next.c
parentChanged function name (diff)
download42-minishell-1886374416e5dc436db68e3518603258ae32bac0.tar.gz
42-minishell-1886374416e5dc436db68e3518603258ae32bac0.tar.bz2
42-minishell-1886374416e5dc436db68e3518603258ae32bac0.tar.xz
42-minishell-1886374416e5dc436db68e3518603258ae32bac0.tar.zst
42-minishell-1886374416e5dc436db68e3518603258ae32bac0.zip
Splitted var
Diffstat (limited to 'src/b_export_next.c')
-rw-r--r--src/b_export_next.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/b_export_next.c b/src/b_export_next.c
index 2641f65..f0bb804 100644
--- a/src/b_export_next.c
+++ b/src/b_export_next.c
@@ -11,13 +11,40 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdlib.h>
+#include "b_export_next.h"
+#include "f_fail.h"
#include "s_struct.h"
+static char
+ **b_get_var(const char arg[],
+ t_msh *msh)
+{
+ size_t len;
+ char **var;
+
+ if ((var = (char**)malloc(3 * sizeof(char*))) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ len = 0;
+ while (arg[len] != '=' && arg[len] != '\0')
+ len++;
+ len += 1;
+ if ((var[FT_VAR_NAME] = (char*)malloc((len) * sizeof(char))) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ ft_strlcpy(var[FT_VAR_NAME], arg, len);
+ if ((var[FT_VAR_VAL] = ft_strdup(arg + len)) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ var[FT_VAR_NULL] = NULL;
+ return (var);
+}
+
void
b_export_with_equals(const char arg[],
t_msh *msh)
{
- (void)arg;
- (void)msh;
+ char **var;
+
+ var = b_get_var(arg, msh);
+ ft_delwords(var);
}