mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
redirection parsing: detect malformed redirection
This commit is contained in:
parent
06dd3c3e83
commit
5df876bba3
4 changed files with 26 additions and 8 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:40:46 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 15:38:54 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/10 16:56:52 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,6 +51,8 @@ char *ft_strerror(t_errno errno)
|
|||
[FT_EINVAL] = "Invalid argument",
|
||||
[FT_EBADID] = "Bad identifier",
|
||||
[FT_EUNEXPECTED_PIPE] = "minishell: syntax error near unexpected token `|'",
|
||||
[FT_EMALFORMED_REDIRECTION] = "minishell: malformed redirection (perhaps a \
|
||||
missing filename)",
|
||||
};
|
||||
|
||||
if (errno >= 0 && errno < FT_EMAXERRNO)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:40:58 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 15:37:56 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/10 16:38:28 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,7 @@ typedef enum e_errno
|
|||
FT_EINVAL,
|
||||
FT_EBADID,
|
||||
FT_EUNEXPECTED_PIPE,
|
||||
FT_EMALFORMED_REDIRECTION,
|
||||
FT_EMAXERRNO,
|
||||
} t_errno;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 12:30:04 by khais #+# #+# */
|
||||
/* Updated: 2025/03/10 16:11:46 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/10 16:40:17 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
#include "redirection_list.h"
|
||||
#include <stdlib.h>
|
||||
#include "redirection_type.h"
|
||||
#include "../../ft_errno.h"
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
|
|
@ -53,6 +54,8 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
|
|||
{
|
||||
wordlist_destroy_idx(&cmd->words, i);
|
||||
marker = wordlist_pop_idx(&cmd->words, i);
|
||||
if (marker == NULL)
|
||||
return (ft_errno(FT_EMALFORMED_REDIRECTION), NULL);
|
||||
redirection = redirection_create(type, marker);
|
||||
if (redirection == NULL)
|
||||
return (NULL);
|
||||
|
|
@ -60,8 +63,7 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
|
|||
if (cmd->redirections == NULL)
|
||||
return (redirection_destroy(redirection), NULL);
|
||||
}
|
||||
else
|
||||
i++;
|
||||
i++;
|
||||
}
|
||||
return (cmd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue