blob: 683fdd06522a49814db0de8ead3e7385e889ed40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* b_export_next.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#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 + 1) * sizeof(char))) == NULL)
f_fail_alloc_and_destroy(msh);
var[FT_VAR_NAME][0] = '$';
ft_strlcpy(var[FT_VAR_NAME] + 1, 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)
{
char **var;
var = b_get_var(arg, msh);
ft_printf("[%s] - [%s]\n", var[FT_VAR_NAME], var[FT_VAR_VAL]);
ft_delwords(var);
}
|