From 9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 23 Apr 2020 21:34:39 +0200 Subject: Good work so far --- src/ft_b_cd.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/ft_b_cd.c') diff --git a/src/ft_b_cd.c b/src/ft_b_cd.c index eedb1c2..630005d 100644 --- a/src/ft_b_cd.c +++ b/src/ft_b_cd.c @@ -10,25 +10,51 @@ /* */ /* ************************************************************************** */ +#include #include #include #include "ft_s_struct.h" #include "ft_u_utils.h" +/* static void */ +/* ft_switch_env_var(char **envp) */ +/* { */ +/* char **ptr; */ +/* char *path; */ + +/* ptr = envp; */ +/* while (*ptr) */ +/* { */ +/* if (ft_strncmp("HOME", *ptr, 4) == 0) */ +/* { */ +/* path = ft_substr(*ptr, 5, ft_strlen(*ptr + 5)); */ +/* return (path); */ +/* } */ +/* ptr++; */ +/* } */ +/* return (NULL); */ +/* } */ + uint8_t ft_b_cd(char *args[], t_msh *msh) { - char *path; + const uint64_t argc = ft_get_argc((const char**)args); + char *path; - (void)msh; - if (!args) + if (argc == 0) + { + path = ft_get_home_dir(msh->envp); + } + if (chdir(path) != 0) { - path = ft_get_home_dir(msh); - chdir(); - ft_memdel((void*)&path); + /* TODO: handle cd failed */ } + /* TODO: ft_switch_env_var() */ + ft_memdel((void*)&msh->cwd); + msh->cwd = getcwd(NULL, 0); + ft_memdel((void*)&path); /* TODO: do cd */ return (0); } -- cgit v1.2.3