Browse Source

[mod] setenv: add new var at the end of the chart.

Moul 2 years ago
parent
commit
4d9a5bf5c3
1 changed files with 5 additions and 5 deletions
  1. 5 5
      src/tabenv.c

+ 5 - 5
src/tabenv.c

@@ -22,12 +22,12 @@ void	add_env(t_e *e, char *nenv)
 	char	**env;
 
 	env = (char **)malloc(sizeof(char *) * (ft_tabsize(e->env) + 2));
-	env[0] = ft_strdup(nenv);
-	i = 0;
+	i = -1;
 	if (e->env != NULL)
-		while (e->env[++i - 1] != NULL)
-			env[i] = e->env[i - 1];
-	env[i] = NULL;
+		while (e->env[++i] != NULL)
+			env[i] = e->env[i];
+	env[i] = ft_strdup(nenv);
+	env[++i] = NULL;
 	free(e->env);
 	e->env = env;
 }