fik leak redirection
This commit is contained in:
parent
f0ec3de703
commit
53b6ba7967
2
Makefile
2
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/03/06 12:50:24 by apommier #+# #+# #
|
# Created: 2022/03/06 12:50:24 by apommier #+# #+# #
|
||||||
# Updated: 2022/04/20 04:44:00 by apommier ### ########.fr #
|
# Updated: 2022/04/20 15:53:50 by apommier ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/20 04:44:53 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 16:52:50 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ char **ft_dup_double(char **env);
|
|||||||
void execute(t_cmd *cmd);
|
void execute(t_cmd *cmd);
|
||||||
|
|
||||||
//set_cmd.c
|
//set_cmd.c
|
||||||
int error_parsing(void);
|
char *error_parsing(void);
|
||||||
t_cmd *set_cmd(char *input, char **path, int nb);
|
t_cmd *set_cmd(char *input, char **path, int nb);
|
||||||
|
|
||||||
//exec_utils.c
|
//exec_utils.c
|
||||||
|
|||||||
@ -6,13 +6,13 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/04/19 16:53:13 by apommier #+# #+# */
|
/* Created: 2022/04/19 16:53:13 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/19 18:27:58 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 16:51:05 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/minishell.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int error_parsing(void)
|
char *error_parsing(void)
|
||||||
{
|
{
|
||||||
ft_putstr_fd("Minishell: error while parsing command\n", 2);
|
ft_putstr_fd("Minishell: error while parsing command\n", 2);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/20 15:22:35 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 16:49:33 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ int set_redirect_in(t_s_cmd *cmd, char **line, int *i, int index)
|
|||||||
{
|
{
|
||||||
*line = ft_input(*line, cmd, *i);
|
*line = ft_input(*line, cmd, *i);
|
||||||
if (!(*line))
|
if (!(*line))
|
||||||
return (error_parsing());
|
return (0);
|
||||||
if (cmd->in_type == 1)
|
if (cmd->in_type == 1)
|
||||||
{
|
{
|
||||||
if (wait_prompt(cmd, index, 0, 0) == -1)
|
if (wait_prompt(cmd, index, 0, 0) == -1)
|
||||||
@ -110,7 +110,7 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index, int i)
|
|||||||
if (!is_in_quote(line, i))
|
if (!is_in_quote(line, i))
|
||||||
{
|
{
|
||||||
line = ft_output(line, cmd, i);
|
line = ft_output(line, cmd, i);
|
||||||
if (!set_file(cmd->outfile, cmd->in_type))
|
if (!line || !set_file(cmd->outfile, cmd->in_type))
|
||||||
return (0);
|
return (0);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/04/19 14:44:22 by apommier #+# #+# */
|
/* Created: 2022/04/19 14:44:22 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/19 18:20:56 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 16:50:37 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -46,10 +46,10 @@ char *set_input(char *line, t_s_cmd *cmd, int index)
|
|||||||
free(cmd->infile);
|
free(cmd->infile);
|
||||||
cmd->infile = get_word(line, index);
|
cmd->infile = get_word(line, index);
|
||||||
cmd->infile = set_var(cmd->big_cmd, cmd->infile);
|
cmd->infile = set_var(cmd->big_cmd, cmd->infile);
|
||||||
if (cmd->in_type == 0)
|
if (cmd->in_type == 0 && !check_access_input(cmd))
|
||||||
{
|
{
|
||||||
if (!check_access_input(cmd))
|
free(line);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
line = cut_str(line, index, i);
|
line = cut_str(line, index, i);
|
||||||
return (line);
|
return (line);
|
||||||
@ -70,7 +70,7 @@ char *ft_input(char *line, t_s_cmd *cmd, int index)
|
|||||||
else
|
else
|
||||||
cmd->in_type = 0;
|
cmd->in_type = 0;
|
||||||
if (next == '<' || next == '>' || !next)
|
if (next == '<' || next == '>' || !next)
|
||||||
return (0);
|
return (error_parsing());
|
||||||
line = set_input(line, cmd, i);
|
line = set_input(line, cmd, i);
|
||||||
if (!line)
|
if (!line)
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@ -6,12 +6,29 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/04/19 14:45:10 by apommier #+# #+# */
|
/* Created: 2022/04/19 14:45:10 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/20 14:09:57 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 16:45:06 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/minishell.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
|
int check_access_output(t_s_cmd *cmd)
|
||||||
|
{
|
||||||
|
if (access(cmd->outfile, W_OK))
|
||||||
|
{
|
||||||
|
ft_putstr_fd("Minishell: ", 2);
|
||||||
|
ft_putstr_fd(cmd->outfile, 2);
|
||||||
|
if (access(cmd->outfile, F_OK))
|
||||||
|
ft_putstr_fd(": no such file\n", 2);
|
||||||
|
else
|
||||||
|
ft_putstr_fd(": Permission denied\n", 2);
|
||||||
|
free(cmd->outfile);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *set_output(char *line, t_s_cmd *cmd, int index)
|
char *set_output(char *line, t_s_cmd *cmd, int index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -31,6 +48,11 @@ char *set_output(char *line, t_s_cmd *cmd, int index)
|
|||||||
free(cmd->outfile);
|
free(cmd->outfile);
|
||||||
cmd->outfile = get_word(line, index);
|
cmd->outfile = get_word(line, index);
|
||||||
cmd->outfile = set_var(cmd->big_cmd, cmd->outfile);
|
cmd->outfile = set_var(cmd->big_cmd, cmd->outfile);
|
||||||
|
if (!check_access_output(cmd))
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
line = cut_str(line, index, i);
|
line = cut_str(line, index, i);
|
||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user