diff --git a/build/source_files.mk b/build/source_files.mk index bf01ab90..078fe66c 100644 --- a/build/source_files.mk +++ b/build/source_files.mk @@ -6,7 +6,7 @@ # By: ldulling +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/03/19 16:15:33 by ldulling #+# #+# # -# Updated: 2024/04/04 23:25:38 by ldulling ### ########.fr # +# Updated: 2024/06/07 07:25:14 by ldulling ### ########.fr # # # # **************************************************************************** # @@ -76,7 +76,7 @@ SRC += $(addprefix $(DIR), \ io_file.c \ pipe.c \ pipe_utils.c \ - stdio_bind.c \ + stdio_redirect.c \ ) # Debug: diff --git a/include/executor.h b/include/executor.h index 25484e9c..5fabb5a5 100644 --- a/include/executor.h +++ b/include/executor.h @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/26 15:05:16 by lyeh #+# #+# */ -/* Updated: 2024/04/04 23:42:17 by ldulling ### ########.fr */ +/* Updated: 2024/06/07 07:25:53 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,7 @@ bool restore_std_io(int saved_std_io[2]); bool save_std_io(int saved_std_io[2]); bool redirect_scmd_io(t_sh *shell, int *read_fd, int *write_fd); int redirect_subshell_io(t_sh *shell, t_ct *cmd_table); -int handle_io_redirect( +int open_io_files( t_sh *shell, int *read_fd, int *write_fd, t_list *io_red_list); /* Redirection - Pipe */ diff --git a/source/backend/executor/builtin_cmd.c b/source/backend/executor/builtin_cmd.c index 425dffa1..4318e570 100644 --- a/source/backend/executor/builtin_cmd.c +++ b/source/backend/executor/builtin_cmd.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/09 01:10:43 by lyeh #+# #+# */ -/* Updated: 2024/03/21 17:44:04 by lyeh ### ########.fr */ +/* Updated: 2024/06/07 07:23:48 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ void handle_builtin(t_sh *shell, t_list_d **cmd_table_node) int ret; cmd_table = (*cmd_table_node)->content; - ret = handle_io_redirect(shell, + ret = open_io_files(shell, &shell->final_cmd_table->read_fd, &shell->final_cmd_table->write_fd, cmd_table->io_red_list); if (ret == MALLOC_ERROR) @@ -79,7 +79,7 @@ static void redirect_io_and_exec_builtin(t_sh *shell) if (!redirect_scmd_io(shell, &shell->final_cmd_table->read_fd, &shell->final_cmd_table->write_fd)) raise_error_to_own_subprocess( - shell, GENERAL_ERROR, "fd bind failed"); + shell, GENERAL_ERROR, "fd redirect failed"); exec_builtin_cmd(shell); } diff --git a/source/backend/executor/external_cmd.c b/source/backend/executor/external_cmd.c index 536eb075..448b875c 100644 --- a/source/backend/executor/external_cmd.c +++ b/source/backend/executor/external_cmd.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/19 15:17:06 by lyeh #+# #+# */ -/* Updated: 2024/06/01 11:51:52 by ldulling ### ########.fr */ +/* Updated: 2024/06/07 07:17:29 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ void handle_external_cmd(t_sh *shell, t_ct *cmd_table) int ret; final_cmd_table = shell->final_cmd_table; - ret = handle_io_redirect(shell, + ret = open_io_files(shell, &final_cmd_table->read_fd, &final_cmd_table->write_fd, cmd_table->io_red_list); if (ret == MALLOC_ERROR) diff --git a/source/backend/redirection/io_file.c b/source/backend/redirection/io_file.c index bbe4756f..066a66b8 100644 --- a/source/backend/redirection/io_file.c +++ b/source/backend/redirection/io_file.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* io_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/01 19:32:18 by lyeh #+# #+# */ -/* Updated: 2024/03/21 17:46:56 by lyeh ### ########.fr */ +/* Updated: 2024/06/07 07:28:14 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,11 @@ #include "clean.h" static int expand_filename(t_sh *shell, char **filename); -static bool handle_redirect_by_type( - int *read_fd, int *write_fd, t_io_red *io_red); -static bool handle_red_in(int *read_fd, char *filename); -static bool handle_red_out(int *write_fd, char *filename, int o_flags); +static bool open_io_file_by_type(int *read_fd, int *write_fd, t_io_red *io_red); +static bool open_in_file(int *read_fd, char *filename); +static bool open_out_file(int *write_fd, char *filename, int o_flags); -int handle_io_redirect( +int open_io_files( t_sh *shell, int *read_fd, int *write_fd, t_list *io_red_list) { t_io_red *io_red; @@ -38,7 +37,7 @@ int handle_io_redirect( if (ret != SUCCESS) return (ret); } - if (!handle_redirect_by_type(read_fd, write_fd, io_red_list->content)) + if (!open_io_file_by_type(read_fd, write_fd, io_red_list->content)) return (GENERAL_ERROR); io_red_list = io_red_list->next; } @@ -69,21 +68,20 @@ static int expand_filename(t_sh *shell, char **filename) return (SUCCESS); } -static bool handle_redirect_by_type( - int *read_fd, int *write_fd, t_io_red *io_red) +static bool open_io_file_by_type(int *read_fd, int *write_fd, t_io_red *io_red) { if (io_red->type == T_RED_IN || io_red->type == T_HERE_DOC) - return (handle_red_in(read_fd, io_red->filename)); + return (open_in_file(read_fd, io_red->filename)); else if (io_red->type == T_RED_OUT) - return (handle_red_out(write_fd, + return (open_out_file(write_fd, io_red->filename, O_CREAT | O_RDWR | O_TRUNC)); else if (io_red->type == T_APPEND) - return (handle_red_out(write_fd, + return (open_out_file(write_fd, io_red->filename, O_CREAT | O_RDWR | O_APPEND)); return (true); } -static bool handle_red_in(int *read_fd, char *filename) +static bool open_in_file(int *read_fd, char *filename) { int fd; @@ -97,7 +95,7 @@ static bool handle_red_in(int *read_fd, char *filename) return (true); } -static bool handle_red_out(int *write_fd, char *filename, int o_flags) +static bool open_out_file(int *write_fd, char *filename, int o_flags) { int fd; diff --git a/source/backend/redirection/stdio_bind.c b/source/backend/redirection/stdio_redirect.c similarity index 88% rename from source/backend/redirection/stdio_bind.c rename to source/backend/redirection/stdio_redirect.c index 373bbf54..2df9d0e6 100644 --- a/source/backend/redirection/stdio_bind.c +++ b/source/backend/redirection/stdio_redirect.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* stdio_bind.c :+: :+: :+: */ +/* stdio_redirect.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/19 15:09:45 by lyeh #+# #+# */ -/* Updated: 2024/05/03 17:18:22 by lyeh ### ########.fr */ +/* Updated: 2024/06/07 07:37:45 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,8 +57,7 @@ int redirect_subshell_io(t_sh *shell, t_ct *cmd_table) read_fd = -1; write_fd = -1; - ret = handle_io_redirect( - shell, &read_fd, &write_fd, cmd_table->io_red_list); + ret = open_io_files(shell, &read_fd, &write_fd, cmd_table->io_red_list); if (ret == SUCCESS && \ ((read_fd != -1 && dup2(read_fd, STDIN_FILENO) == -1) || \ (write_fd != -1 && dup2(write_fd, STDOUT_FILENO) == -1)))