error_MSG in builtin_cd/exit
This commit is contained in:
parent
ededbc98f4
commit
f9062d4385
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/20 11:33:07 by whaffman #+# #+# */
|
/* 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");
|
env = environment_get(msh, "HOME");
|
||||||
if (env == NULL || env->value == NULL)
|
if (env == NULL || env->value == NULL)
|
||||||
{
|
{
|
||||||
ft_putendl_fd("minishell: cd: HOME not set", STDERR_FILENO);
|
error_msg(NULL, NULL);
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
}
|
}
|
||||||
path = env->value;
|
path = env->value;
|
||||||
@ -31,10 +31,7 @@ int builtin_cd(t_minishell *msh, t_command *cmd)
|
|||||||
path = cmd->args[1];
|
path = cmd->args[1];
|
||||||
if (chdir(path) == -1)
|
if (chdir(path) == -1)
|
||||||
{
|
{
|
||||||
ft_putstr_fd("minishell: cd: ", STDERR_FILENO);
|
error_msg("cd", path);
|
||||||
ft_putstr_fd(path, STDERR_FILENO);
|
|
||||||
ft_putstr_fd(": ", STDERR_FILENO);
|
|
||||||
ft_putendl_fd(strerror(errno), STDERR_FILENO);
|
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
}
|
}
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */
|
/* 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]);
|
exit_status = ft_atoi(cmd->args[1]);
|
||||||
}
|
}
|
||||||
free_minishell(&msh);
|
free_minishell(&msh);
|
||||||
|
ft_putendl_fd("exit", STDERR_FILENO); //TODO stderr?
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
exit(exit_status);
|
exit(exit_status);
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
|
|||||||
@ -6,19 +6,20 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */
|
/* 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"
|
#include "minishell.h"
|
||||||
|
#define SHELL_NAME "minishell"
|
||||||
|
|
||||||
void error_msg(char *func, char *msg)
|
void error_msg(char *func, char *msg)
|
||||||
{
|
{
|
||||||
if (errno)
|
if (errno)
|
||||||
perror(RED BOLD "minishell" RESET);
|
perror(RED BOLD SHELL_NAME RESET);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putstr_fd(RED BOLD "minishell" RESET ": ", 2);
|
ft_putstr_fd(RED BOLD SHELL_NAME RESET ": ", 2);
|
||||||
if (func != NULL)
|
if (func != NULL)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(func, 2);
|
ft_putstr_fd(func, 2);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user