minishell/src/expander/expander_get_variable.c
whaffman ab72bd5bbb malloc_safe
- add freelist to minishell
- add t_minishell *minishell to all function calling malloc_free
- substituted all malloc calls but the first to malloc_safe
2025-02-25 14:54:17 +01:00

31 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* expander_get_variable.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 13:59:03 by qmennen #+# #+# */
/* Updated: 2025/02/25 13:47:55 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_environment *expander_get_var(const char *s, int idx, t_minishell *minishell)
{
int i;
t_environment *env;
char *name;
i = 0;
while (expander_character_valid(s[idx + i]))
i++;
name = ft_substr(s, idx, i);
if (!name || !*name)
return (NULL);
env = environment_get(minishell, name);
free(name);
return (env);
}