Skip to content

Commit

Permalink
fix: redirections outputs messages
Browse files Browse the repository at this point in the history
  • Loading branch information
0bvim committed Feb 21, 2024
1 parent 5d02f4e commit 1d04cd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ COMP = Compiling

# debug and normal flags #
DFLAGS = -Wall -Wextra -Werror -g3 # TO DEBBUG
CFLAGS = -Wall -Werror -Wextra -pedantic -flto -MD -MP # FOR DEPENDENCIES
CFLAGS = -Wall -Werror -Wextra -g3 -pedantic -flto -MD -MP # FOR DEPENDENCIES
LFLAGS = -march=native # TO OPTIMIZE FOR SPECIFIC ARCHITECTURE
FFLAGS = -lreadline # FLAGS THAT ONLY WORK AT THE END OF LINE (AFTER OBJECTS)

Expand Down
11 changes: 8 additions & 3 deletions src/exec/handling_redirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* handling_redirs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */
/* By: vde-frei <vde-frei@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/26 15:26:07 by vde-frei #+# #+# */
/* Updated: 2024/02/19 21:23:09 by bmoretti ### ########.fr */
/* Updated: 2024/02/20 19:55:49y vde-frei ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -46,6 +46,8 @@ static void handle_outfile(t_ast *node)
node->fd = open(token->str, TRUN, 0666);
else if (node->type == APPEND)
node->fd = open(token->str, APEN, 0666);
if ((node->fd == -1) && last_exit_status(-1))
last_exit_status(0);
open_file_error(token->str);
}

Expand All @@ -65,14 +67,17 @@ void handle_infile(t_ast *node)
&& token->type != DOUBLE_QUOTE)
heredoc_expansion(token);
node->fd = open(token->str, O_RDONLY);
if (node->fd == -1 && last_exit_status(-1))
last_exit_status(0);
open_file_error(token->str);
}

void open_dup_close(t_ast *node)
{
if (is_redirect(node->left->type))
open_dup_close(node->left);
if (is_redirect_out(node->type) && !last_exit_status(-1))
if (is_redirect_out(node->type)
&& ((node->fd != -1 && node->left->fd != -1) || !last_exit_status(-1)))
{
handle_outfile(node);
if (node->fd != -1)
Expand Down

0 comments on commit 1d04cd4

Please sign in to comment.