summaryrefslogtreecommitdiffstats
path: root/src/b_cd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/b_cd.c')
-rw-r--r--src/b_cd.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/b_cd.c b/src/b_cd.c
index d82ab9c..daf839d 100644
--- a/src/b_cd.c
+++ b/src/b_cd.c
@@ -73,7 +73,7 @@ static void
{
if (ft_strncmp(splited[i], "..", 3) == 0)
{
- j = ft_strlen(repath);
+ j = (repath[0] == '\0') ? (0) : (ft_strlen(repath));
while (repath[j] != '/' && j > 0)
j--;
repath[j] = '\0';
@@ -94,27 +94,28 @@ static void
static void
b_upgrade_pwd(const char path[], t_msh *msh)
{
- char *tmp;
char **splited;
char repath[262144];
char fmt[262144];
b_set_oldpwd(msh);
+ splited = NULL;
repath[0] = '\0';
if (path[0] != '/')
- ft_memcpy(repath, msh->cwd, ft_strlen(msh->cwd));
- if ((splited = ft_split(path, '/')) == NULL)
+ ft_memcpy(repath, msh->cwd, (ft_strlen(msh->cwd) + 1) * sizeof(char));
+ if (path[0] == '/' && path[1] == '\0')
+ ft_memcpy(repath, "/", 2 * sizeof(char));
+ else if ((splited = ft_split(path, '/')) == NULL)
f_alloc_and_destroy_msh(msh);
- b_fill_repath(repath, splited);
- repath[0] = (repath[0] == '\0') ? '/' : repath[0];
- ft_delwords(splited);
- if ((tmp = u_get_var_value("$PWD", msh)) != NULL)
- u_subst_var_value("$PWD", repath, msh);
- else
+ if (splited != NULL)
{
- ft_sprintf(fmt, "%s=%s", "PWD", repath);
- b_export_with_equals(fmt, msh);
+ b_fill_repath(repath, splited);
+ ft_delwords(splited);
}
+ repath[0] = (repath[0] == '\0') ? '/' : repath[0];
+ ft_printf("[%s]\n", repath);
+ ft_sprintf(fmt, "%s=%s", "PWD", repath);
+ b_export_with_equals(fmt, msh);
ft_memdel((void*)&msh->cwd);
if ((msh->cwd = ft_strdup(repath)) == NULL)
f_alloc_and_destroy_msh(msh);