1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-14 08:18:45 +02:00

」 feat: CD working

This commit is contained in:
2024-06-25 11:23:25 +02:00
parent 5710f193d7
commit 1ddd5534c8
3 changed files with 35 additions and 13 deletions

View File

@ -6,13 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 15:07:24 by adjoly #+# #+# */
/* Updated: 2024/06/24 18:48:11 by adjoly ### ########.fr */
/* Updated: 2024/06/25 11:22:08 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "env.h"
#include "libft.h"
#include "builtins.h"
char *__get_parent_directory(char *pwd)
{
@ -29,34 +30,31 @@ char *__get_parent_directory(char *pwd)
}
parent = ft_calloc(dir - pwd + 1, sizeof(char));
ft_strlcpy(parent, pwd, dir - pwd + 1);
free(pwd);
return (parent);
}
char *ret_cwd(void)
{
}
void ft_cd(t_env *env, char *args)
{
char *pwd;
char *new_pwd;
int ret;
new_pwd = NULL;
pwd = getcwd();
pwd = ret_cwd();
ft_putendl_fd(args, STDOUT_FILENO);
ft_putendl_fd(env_get_value("PWD", env), STDOUT_FILENO);
ft_putendl_fd(pwd, STDOUT_FILENO);
if (!args)
new_pwd = env_get_value("HOME", env);
else if (args[0] == '/')
new_pwd = ft_strdup(args);
else if (is_str(args, ".."))
new_pwd = __get_parent_directory(env_get_value("PWD", env));
new_pwd = __get_parent_directory(pwd);
ft_putendl_fd(new_pwd, STDOUT_FILENO);
ret = chdir(new_pwd);
if (ret == -1)
{
return ;
}
env_edit("PWD", new_pwd, env);
free(args);
ft_putendl_fd(new_pwd, STDOUT_FILENO);
}