summaryrefslogtreecommitdiffstats
path: root/src/ft_b_cd.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 21:34:39 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 21:34:39 +0200
commit9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1 (patch)
tree61dffc8459616c029984a803f2edf2573cc6ae6e /src/ft_b_cd.c
parentOn the way (diff)
download42-minishell-9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1.tar.gz
42-minishell-9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1.tar.bz2
42-minishell-9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1.tar.xz
42-minishell-9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1.tar.zst
42-minishell-9ae0c7294c4fb7eaeec6feca76327939ee8cd8e1.zip
Good work so far
Diffstat (limited to '')
-rw-r--r--src/ft_b_cd.c38
1 files changed, 32 insertions, 6 deletions
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 <libft.h>
#include <stdint.h>
#include <unistd.h>
#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);
}