Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
simplify exit builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
mcombeau committed Oct 5, 2022
1 parent 76137e0 commit bb90105
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions sources/builtins/exit_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/17 18:32:33 by mcombeau #+# #+# */
/* Updated: 2022/10/05 17:58:35 by mcombeau ### ########.fr */
/* Updated: 2022/10/05 18:59:03 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -121,6 +121,8 @@ int exit_builtin(t_data *data, char **args)

quiet = is_quiet_mode(data);
error = false;
if (!quiet && data->interactive)
ft_putendl_fd("exit", 2);
if (!args || !args[1] || args[1][0] == '\0')
exit_code = g_last_exit_code;
else
Expand All @@ -130,11 +132,7 @@ int exit_builtin(t_data *data, char **args)
exit_code = errmsg_cmd("exit", args[1], "numeric argument required", 2);
else if (args[2])
return (errmsg_cmd("exit", NULL, "too many arguments", 1));
if (data->cmd && data->cmd->io_fds)
restore_io(data->cmd->io_fds);
}
if (!quiet && data->interactive)
printf("exit\n");
exit_shell(data, exit_code);
return (2);
}
2 changes: 1 addition & 1 deletion sources/execution/execute_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/17 17:12:08 by mcombeau #+# #+# */
/* Updated: 2022/10/05 17:46:15 by mcombeau ### ########.fr */
/* Updated: 2022/10/05 19:00:17 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
4 changes: 1 addition & 3 deletions sources/redirections/file_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/17 17:51:46 by mcombeau #+# #+# */
/* Updated: 2022/09/26 19:53:56 by mcombeau ### ########.fr */
/* Updated: 2022/10/05 19:00:10 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

// TODO : heredoc functions.

/* restore_io:
* Restores the original standard input and standard output
* to their original fds of 0 and 1. Used to clear the input/output
Expand Down

0 comments on commit bb90105

Please sign in to comment.