diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-28 15:49:58 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-28 15:49:58 +0200 |
commit | 86b25977265727217ec3360c3dc19b74f2bd448f (patch) | |
tree | eefc1440e2ae18faaab0e5409dac58bfef893813 /src/ft_b_cd.c | |
parent | Nice functional cd (diff) | |
download | 42-minishell-86b25977265727217ec3360c3dc19b74f2bd448f.tar.gz 42-minishell-86b25977265727217ec3360c3dc19b74f2bd448f.tar.bz2 42-minishell-86b25977265727217ec3360c3dc19b74f2bd448f.tar.xz 42-minishell-86b25977265727217ec3360c3dc19b74f2bd448f.tar.zst 42-minishell-86b25977265727217ec3360c3dc19b74f2bd448f.zip |
exit is fine
Diffstat (limited to '')
-rw-r--r-- | src/ft_b_cd.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/ft_b_cd.c b/src/ft_b_cd.c index 54dc92e..fbd0282 100644 --- a/src/ft_b_cd.c +++ b/src/ft_b_cd.c @@ -20,11 +20,31 @@ #include "ft_u_utils.h" #include "ft_u_vars.h" +static void + ft_set_path(char **path, + char *args[], + t_msh *msh) +{ + if (!(*path = ft_strdup(*args))) + { + ft_s_destroy(msh); + ft_fail_alloc(msh); + } + if (!ft_strncmp("~/", *path, 2) || !ft_strncmp("~", *path, 2)) + { + if (!(*path = ft_strsubst(*path, + "~", ft_subst_var_value("$HOME", msh)))) + { + ft_s_destroy(msh); + ft_fail_alloc(msh); + } + } +} + uint8_t ft_b_cd(char *args[], t_msh *msh) { - /* TODO: norme */ const uint64_t argc = ft_get_argc((const char**)args); char *path; @@ -39,21 +59,7 @@ uint8_t return (1); } else - { - if (!(path = ft_strdup(*args))) - { - ft_s_destroy(msh); - ft_fail_alloc(msh); - } - if (!ft_strncmp("~/", path, 2) || !ft_strncmp("~", path, 2)) - { - if (!(path = ft_strsubst(path, "~", ft_subst_var_value("$HOME", msh)))) - { - ft_s_destroy(msh); - ft_fail_alloc(msh); - } - } - } + ft_set_path(&path, args, msh); if (chdir(path) != 0) { ft_fail_chd("cd", path, msh); |