73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* env2.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/02/17 17:22:01 by erey-bet #+# #+# */
|
||
|
/* Updated: 2023/02/17 17:24:57 by erey-bet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "minishell.h"
|
||
|
|
||
|
int get_index(char *s, char c)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = -1;
|
||
|
while (s[++i])
|
||
|
if (s[i] == c)
|
||
|
return (i);
|
||
|
return (-1);
|
||
|
}
|
||
|
|
||
|
void swap_env_3(void **a, void **b, void **c)
|
||
|
{
|
||
|
void *d;
|
||
|
|
||
|
d = *a;
|
||
|
*a = *b;
|
||
|
*b = *c;
|
||
|
*c = d;
|
||
|
}
|
||
|
|
||
|
void swap_env(void **a, void **b)
|
||
|
{
|
||
|
void *c;
|
||
|
|
||
|
c = *a;
|
||
|
*a = *b;
|
||
|
*b = c;
|
||
|
}
|
||
|
|
||
|
void env_del(void *ptr)
|
||
|
{
|
||
|
t_env *content;
|
||
|
|
||
|
content = ptr;
|
||
|
free(content->key);
|
||
|
free(content->value);
|
||
|
free(content);
|
||
|
}
|
||
|
|
||
|
char **env_to_strs(t_list **head)
|
||
|
{
|
||
|
t_list *current;
|
||
|
t_env *content;
|
||
|
char **env;
|
||
|
int i;
|
||
|
|
||
|
current = *head;
|
||
|
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
|
||
|
i = 0;
|
||
|
while (current->content)
|
||
|
{
|
||
|
content = current->content;
|
||
|
env[i++] = ft_strmerger(3, content->key, "=", content->value);
|
||
|
current = current->next;
|
||
|
}
|
||
|
return (env);
|
||
|
}
|