30 ft_putstr_fd(
"minishell: cd: HOME not set\n", STDERR_FILENO);
50 if (!args[1] || ft_strncmp(args[1],
"--", 3) == 0)
52 if (args[1] && args[2] && args[3])
53 return (*err = 1, NULL);
54 if (args[1] && args[2])
59 return (*err = 1, NULL);
60 if (ft_strncmp(args[1],
"-", 2) == 0)
64 ft_putstr_fd(
"minishell: cd: OLDPWD not set\n", STDERR_FILENO);
66 ft_putendl_fd(path, STDOUT_FILENO);
82 if (old_pwd && old_pwd[0])
84 if (getcwd(cwd, PATH_MAX))
104 char old_pwd[PATH_MAX];
107 if (!getcwd(old_pwd, PATH_MAX))
111 return (ft_putstr_fd(
"minishell: cd: too many arguments\n", 2), 1);
114 if (chdir(path) == -1)
116 ft_putstr_fd(
"minishell: cd: ", STDERR_FILENO);
static void update_pwd_vars(t_env **env, char *old_pwd)
Update OLDPWD and PWD environment variables after cd.
int builtin_cd(char **args, t_env **env)
Implement the cd command.
static char * get_cd_path(char **args, t_env *env, int *err)
Get the target path for cd.
static char * get_home_path(t_env *env)
Get the HOME value from environment.
Shell builtin commands prototypes.
Environment variable management prototypes.
int set_env_value(t_env **env_list, char *key, char *value)
Set or create an environment variable.
char * get_env_value(t_env *env_list, char *key)
Look up an environment variable's value by its key.
Environment variable (doubly linked list)