-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
15 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: juligonz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2020/08/15 17:54:31 by juligonz #+# #+# */ | ||
/* Updated: 2020/09/14 18:08:37 by juligonz ### ########.fr */ | ||
/* Updated: 2020/09/16 16:31:03 by juligonz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -44,7 +44,7 @@ typedef struct s_shell | |
{ | ||
char *name; | ||
t_environment env; | ||
char cwd[PATH_MAX + 3]; | ||
char *cwd; | ||
int status; | ||
int running; | ||
} t_shell; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: juligonz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2020/08/23 13:40:40 by hwinston #+# #+# */ | ||
/* Updated: 2020/09/11 02:14:14 by juligonz ### ########.fr */ | ||
/* Updated: 2020/09/16 16:31:28 by juligonz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -25,13 +25,17 @@ static int has_only_slashes(char *str) | |
|
||
static void do_cd(char *path) | ||
{ | ||
char *tmp; | ||
|
||
set_environment_variable_value("OLDPWD", g_sh.cwd); | ||
getcwd(g_sh.cwd, sizeof(g_sh.cwd)); | ||
free(g_sh.cwd); | ||
g_sh.cwd = getcwd(NULL, 0); | ||
if ((!strncmp(path, "//", 2) && !has_only_slashes(path)) | ||
|| !strcmp(path, "//")) | ||
{ | ||
ft_memmove(g_sh.cwd + 1, g_sh.cwd, ft_strlen(g_sh.cwd) + 1); | ||
g_sh.cwd[0] = '/'; | ||
ft_asprintf(&tmp, "/%s", g_sh.cwd); | ||
free(g_sh.cwd); | ||
g_sh.cwd = tmp; | ||
} | ||
set_environment_variable_value("PWD", g_sh.cwd); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: juligonz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2020/08/19 15:10:55 by juligonz #+# #+# */ | ||
/* Updated: 2020/09/14 17:06:54 by juligonz ### ########.fr */ | ||
/* Updated: 2020/09/14 21:24:12 by juligonz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -51,7 +51,7 @@ const char *get_environment_variable_value(char *name) | |
if (!variable) | ||
return (NULL); | ||
value = ft_strchr(variable, '='); | ||
if (*value == '=') | ||
if (*value == '=' && value[1]) | ||
return (value + 1); | ||
return (NULL); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: juligonz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2020/08/15 17:52:21 by juligonz #+# #+# */ | ||
/* Updated: 2020/09/09 02:30:53 by juligonz ### ########.fr */ | ||
/* Updated: 2020/09/16 16:19:05 by juligonz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -24,7 +24,7 @@ t_shell create_shell(const char *name, t_environment envp) | |
result.running = 42; | ||
signal(SIGINT, sigint_handler); | ||
signal(SIGQUIT, sigquit_handler); | ||
getcwd(result.cwd, sizeof(result.cwd)); | ||
result.cwd = getcwd(NULL, 0); | ||
return (result); | ||
} | ||
|
||
|
@@ -42,6 +42,7 @@ void destroy_shell(t_shell to_destroy) | |
{ | ||
free_environment(to_destroy.env); | ||
free(to_destroy.name); | ||
free(to_destroy.cwd); | ||
} | ||
|
||
void free_shell(t_shell *to_free) | ||
|