summaryrefslogtreecommitdiffstats
path: root/src/ft_b_cd.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_b_cd.c38
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);