tabenv.c 586 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "sh.h"
  2. void add_env(char *nenv)
  3. {
  4. int i;
  5. char **env;
  6. env = (char **)malloc(sizeof(char *) * (ft_tabsize(g_tenv) + 2));
  7. env[0] = nenv;
  8. i = 0;
  9. if (g_tenv != NULL)
  10. while (g_tenv[++i - 1] != NULL)
  11. env[i] = g_tenv[i - 1];
  12. env[i] = NULL;
  13. g_tenv = env;
  14. }
  15. void del_env(char *old_env)
  16. {
  17. int i;
  18. char **env;
  19. env = (char **)malloc(sizeof(char *) * ft_tabsize(g_tenv));
  20. i = -1;
  21. while (g_tenv[++i] != NULL && ft_strcmp(g_tenv[i], old_env) != 61)
  22. env[i] = g_tenv[i];
  23. while (g_tenv[i] != NULL)
  24. {
  25. env[i] = g_tenv[i + 1];
  26. i++;
  27. }
  28. env[i] = NULL;
  29. g_tenv = env;
  30. }