char *get_real_path(char *pwd_asked, char *act_pwd) { int i; bool next; size_t len; i = -1; next = true; while (pwd_asked[++i]) { if (pwd_asked[i] == '.') { if (pwd_asked[i + 1] == '.') modify_pwd(act_pwd); } else if (pwd_asked[i] != '/' && next) { len = next_file_len(&pwd_asked[i]); act_pwd = my_realloc(act_pwd, len); strcatnext_file(act_pwd, &pwd_asked[i]); next = false; } else if (pwd_asked[i] == '/') next = true; } return (act_pwd); }
int cd_built(char **command, t_shell *shell) { int i; char dir[128]; i = 0; if (command[1] && command[0]) ft_putendl("cd: Too many arguments."); else { if (*command && !ft_strcmp(*command, "-")) replace(command, shell); if (*command && !check_command(*command)) return (-1); modify_pwd(*command, shell); while (shell->char_env[i]) { if (!ft_strncmp(shell->char_env[i], "PWD", 3)) { free(shell->char_env[i]); shell->char_env[i] = ft_strjoin("PWD=", getcwd(dir, 128)); break ; } i++; } } return (1); }