-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_getenv.c
37 lines (34 loc) · 1.27 KB
/
ft_getenv.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_getenv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adel-cor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/10 16:38:04 by adel-cor #+# #+# */
/* Updated: 2022/04/12 10:40:12 by adel-cor ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_get_env(char *var_name, char **env)
{
int i;
char *temp;
char *temp2;
temp = ft_strjoin(var_name, "=");
temp2 = NULL;
i = 0;
while (env[i])
{
if (!ft_strncmp(env[i], temp, ft_strlen(temp)))
{
temp2 = ft_substr(env[i], ft_strlen(temp),
((ft_strlen(env[i]) - ft_strlen(temp))));
free(temp);
return (temp2);
}
i++;
}
free(temp);
return (temp2);
}