feat(redirection): print path of redirection target on redirection error

This commit is contained in:
Khaïs COLIN 2025-04-22 16:21:10 +02:00
parent b6e97ac2c7
commit 9db47dc96d
2 changed files with 25 additions and 2 deletions

View file

@ -6,12 +6,23 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:14:40 by khais #+# #+# */
/* Updated: 2025/04/17 11:15:44 by khais ### ########.fr */
/* Updated: 2025/04/24 13:41:23 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "handle_redirections.h"
#include <stdio.h>
#include <errno.h>
static void *redirection_error(char *filename)
{
int errno_save;
errno_save = errno;
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", filename,
strerror(errno_save));
return (NULL);
}
static t_redirect *do_redirection(t_redirect *redirection)
{
@ -24,7 +35,7 @@ static t_redirect *do_redirection(t_redirect *redirection)
fd = open(redirection->redirectee.filename->word,
redirection->open_flags, redirection->c_flags);
if (fd < 0)
return (perror("minishell: open"), NULL);
return (redirection_error(redirection->redirectee.filename->word));
}
if (dup2(fd, redirection->source) < 0)
return (perror("minishell: dup2"), NULL);
@ -56,7 +67,10 @@ t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app)
while (redirections != NULL)
{
if (do_redirection(redirections) == NULL)
{
app->last_return_value = 1;
return (NULL);
}
redirections = redirections->next;
}
return (cmd);