export always 0
This commit is contained in:
parent
2c5499a72f
commit
6c5c8460b7
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/20 11:32:53 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/06 17:41:54 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/03/06 17:52:48 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
static int ft_isvalid_identifier(char *str)
|
||||
{
|
||||
if (str == NULL || *str == '\0')
|
||||
return (FALSE);
|
||||
if (ft_isalpha(*str) == FALSE && *str != '_')
|
||||
return (FALSE);
|
||||
while (*str != '\0')
|
||||
@ -24,11 +26,13 @@ static int ft_isvalid_identifier(char *str)
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
static int actually_append(t_minishell *msh, char *name, char *value)
|
||||
static int actually_append(t_minishell *msh, char *arg,
|
||||
char *name, char *value)
|
||||
{
|
||||
char *value_old;
|
||||
char *err;
|
||||
|
||||
if (name != NULL && value != NULL)
|
||||
if (ft_isvalid_identifier(name) && value != NULL)
|
||||
{
|
||||
if (environment_get(msh, name) == NULL)
|
||||
environment_update(msh, name, value);
|
||||
@ -40,6 +44,8 @@ static int actually_append(t_minishell *msh, char *name, char *value)
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
err = ft_strjoin_safe(msh, arg, ": not a valid identifier");
|
||||
error_msg("export", err);
|
||||
return (FAILURE);
|
||||
}
|
||||
|
||||
@ -57,7 +63,7 @@ static int handle_append(t_minishell *msh, char *arg)
|
||||
name = ft_substr_safe(msh, arg, 0, name_end - arg);
|
||||
value = ft_strdup_safe(msh, ft_strchr(arg, '=') + 1);
|
||||
if (name != NULL && value != NULL)
|
||||
ret = actually_append(msh, name, value);
|
||||
ret = actually_append(msh, arg, name, value);
|
||||
free_safe(msh, (void **)&name);
|
||||
free_safe(msh, (void **)&value);
|
||||
return (ret);
|
||||
@ -96,7 +102,7 @@ int builtin_export(t_minishell *msh, t_command *cmd)
|
||||
while (cmd->args[++i] != NULL)
|
||||
{
|
||||
if (!handle_argument(msh, cmd->args[i]))
|
||||
return (EXIT_FAILURE);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user