mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 08:18:45 +02:00
「🏗️」 wip: CD reworked
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 15:07:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/25 11:22:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/25 13:47:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,7 +19,7 @@ char *__get_parent_directory(char *pwd)
|
||||
{
|
||||
char *tmp;
|
||||
char *dir;
|
||||
char *parent;
|
||||
//char *parent;
|
||||
|
||||
tmp = pwd;
|
||||
while (*tmp)
|
||||
@ -28,9 +28,27 @@ char *__get_parent_directory(char *pwd)
|
||||
dir = tmp;
|
||||
tmp++;
|
||||
}
|
||||
parent = ft_calloc(dir - pwd + 1, sizeof(char));
|
||||
ft_strlcpy(parent, pwd, dir - pwd + 1);
|
||||
return (parent);
|
||||
//parent = ft_calloc(dir - pwd + 1, sizeof(char));
|
||||
ft_strlcpy(pwd, pwd, dir - pwd + 1);
|
||||
return (pwd);
|
||||
}
|
||||
|
||||
char *__relative_path(char *args, char *pwd)
|
||||
{
|
||||
char **path;
|
||||
char **tmp;
|
||||
char *new_path;
|
||||
|
||||
path = ft_split(args, '/');
|
||||
tmp = path;
|
||||
new_path = pwd;
|
||||
while (*tmp)
|
||||
{
|
||||
if (is_str(*tmp, ".."))
|
||||
new_path = __get_parent_directory(new_path);
|
||||
tmp++;
|
||||
}
|
||||
return (new_path);
|
||||
}
|
||||
|
||||
void ft_cd(t_env *env, char *args)
|
||||
@ -47,7 +65,7 @@ void ft_cd(t_env *env, char *args)
|
||||
new_pwd = env_get_value("HOME", env);
|
||||
else if (args[0] == '/')
|
||||
new_pwd = ft_strdup(args);
|
||||
else if (is_str(args, ".."))
|
||||
else
|
||||
new_pwd = __get_parent_directory(pwd);
|
||||
ft_putendl_fd(new_pwd, STDOUT_FILENO);
|
||||
ret = chdir(new_pwd);
|
||||
|
Reference in New Issue
Block a user