minishell
Minishell Project for École 42
|
Change directory builtin function. More...
#include "minishell.h"
Functions | |
void | update_old (t_shell *shell, char *old) |
Update OLDPWD. | |
int | env_var_update (t_shell *shell, char *old, char *new) |
Update PWD after directory change. | |
int | cd_no_args (t_shell *shell) |
Handles the case when changing to a directory with no arguments. | |
int | cd (t_shell *shell, char **args) |
Handles changing the current working directory with specified arguments. | |
Change directory builtin function.
This file contains the implementation of the cd command The cd command is used to change the current working directory.
int cd | ( | t_shell * | shell, |
char ** | args | ||
) |
Handles changing the current working directory with specified arguments.
This function is called when the cd command is executed with one argument, which is the target directory to change to. It checks the number of arguments, validates the input, and attempts to change the current working directory.
[in] | shell | A pointer to the shell struct. |
[in] | args | An array of strings containing command arguments. |
int cd_no_args | ( | t_shell * | shell | ) |
Handles the case when changing to a directory with no arguments.
This function is called when the cd command is executed without any arguments. It attempts to change the current working directory to the user's home directory (retrieved from the environment variable HOME).
[in] | shell | A pointer to the shell struct. |
int env_var_update | ( | t_shell * | shell, |
char * | old, | ||
char * | new | ||
) |
Update PWD after directory change.
Updates the environment variable PWD and passes the OLDPWD to the other update function.
[in] | shell | A pointer to the shell struct. |
[in] | old | The previous working directory. |
[in] | new | The new working directory. |
void update_old | ( | t_shell * | shell, |
char * | old | ||
) |
Update OLDPWD.
Updates the OLDPWD environment variable with the value of the previous working directory before the change.
[in] | shell | A pointer to the shell struct. |
[in] | old | The previous working directory. |