error_MSG in builtin_cd/exit

This commit is contained in:
whaffman 2025-03-01 14:11:46 +01:00
parent ededbc98f4
commit f9062d4385
3 changed files with 39 additions and 40 deletions

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:33:07 by whaffman #+# #+# */
/* Updated: 2025/02/26 15:45:55 by whaffman ######## odam.nl */
/* Updated: 2025/03/01 14:00:52 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ int builtin_cd(t_minishell *msh, t_command *cmd)
env = environment_get(msh, "HOME");
if (env == NULL || env->value == NULL)
{
ft_putendl_fd("minishell: cd: HOME not set", STDERR_FILENO);
error_msg(NULL, NULL);
return (FAILURE);
}
path = env->value;
@ -31,10 +31,7 @@ int builtin_cd(t_minishell *msh, t_command *cmd)
path = cmd->args[1];
if (chdir(path) == -1)
{
ft_putstr_fd("minishell: cd: ", STDERR_FILENO);
ft_putstr_fd(path, STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO);
ft_putendl_fd(strerror(errno), STDERR_FILENO);
error_msg("cd", path);
return (FAILURE);
}
return (SUCCESS);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */
/* Updated: 2025/02/26 15:47:14 by whaffman ######## odam.nl */
/* Updated: 2025/03/01 12:54:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -37,6 +37,7 @@ int builtin_exit(t_minishell *msh, t_command *cmd)
exit_status = ft_atoi(cmd->args[1]);
}
free_minishell(&msh);
ft_putendl_fd("exit", STDERR_FILENO); //TODO stderr?
rl_clear_history();
exit(exit_status);
return (FAILURE);

View File

@ -6,19 +6,20 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */
/* Updated: 2025/02/20 17:59:36 by whaffman ######## odam.nl */
/* Updated: 2025/03/01 14:11:16 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define SHELL_NAME "minishell"
void error_msg(char *func, char *msg)
{
if (errno)
perror(RED BOLD "minishell" RESET);
perror(RED BOLD SHELL_NAME RESET);
else
{
ft_putstr_fd(RED BOLD "minishell" RESET ": ", 2);
ft_putstr_fd(RED BOLD SHELL_NAME RESET ": ", 2);
if (func != NULL)
{
ft_putstr_fd(func, 2);