diff --git a/src/main.c b/src/main.c index 0182151..9dcc9e0 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */ -/* Updated: 2024/05/01 11:35:54 by mcolonna ### ########.fr */ +/* Updated: 2024/05/02 15:20:41 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,10 +18,10 @@ t_memclass g_mc; static void close_fds(const t_command *command) { if (command->input_fd != 0) - if (close(command->input_fd) != -1) + if (close(command->input_fd) == -1) minishell_error("errno"); if (command->output_fd != 1) - if (close(command->output_fd) != -1) + if (close(command->output_fd) == -1) minishell_error("errno"); } diff --git a/src/parse_command.c b/src/parse_command.c index 310cc71..271a47e 100644 --- a/src/parse_command.c +++ b/src/parse_command.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */ -/* Updated: 2024/04/30 16:22:08 by mcolonna ### ########.fr */ +/* Updated: 2024/05/02 15:15:36 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -133,16 +133,24 @@ static int get_inputfile(t_parsing_args *args, const char *stop_charset) static int get_outputfile(t_parsing_args *args, const char *stop_charset) { const char *str; + int flag; if (args->r.output_fd != 1) return (parse_error("several output files")); if (!stream_read(&args->stream)) return (parse_error("EOF unexpected")); + flag = O_TRUNC; + if (stream_read(&args->stream) == '>') + { + stream_pop(&args->stream); + flag = O_APPEND; + } + skip_blank(&args->stream); str = get_string(args, stop_charset); if (!str) return (parse_error("EOF unexpected")); args->r.output_fd = open( - str, O_WRONLY | O_CREAT | O_TRUNC, 0666); + str, O_WRONLY | O_CREAT | flag, 0666); if (args->r.output_fd == -1) return (perror(str), errno); return (0);