/* ************************************************************************** */ /* */ /* :::::::: */ /* builtin_cd.c :+: :+: */ /* +:+ */ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/20 11:33:07 by whaffman #+# #+# */ /* Updated: 2025/03/03 14:43:09 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" int builtin_cd(t_minishell *msh, t_command *cmd) { t_environment *env; char *path; if (cmd->args[1] == NULL) { env = environment_get(msh, "HOME"); if (env == NULL || env->value == NULL) { error_msg(NULL, NULL); return (EXIT_FAILURE); } path = env->value; } else path = cmd->args[1]; if (chdir(path) == -1) { error_msg("cd", path); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }