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

Commit

Permalink
ast: fix errors on redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknamemohaji committed Apr 5, 2024
1 parent fa125e9 commit f32723a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
15 changes: 12 additions & 3 deletions codes/builtins/builtin_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:41 by nicknamemoh #+# #+# */
/* Updated: 2024/04/05 12:07:11 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 12:21:17 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -52,10 +52,19 @@ static t_bool check_digit(const char *c)

static t_bool check_argumen_count(const char *args[])
{
if (args[2] != NULL)
int count;

count = 0;
while (*args != NULL)
{
count++;
args++;
}
if (count > 2)
{
printf("exit: too many arguments\n");
return (FALSE);
}
return (TRUE);
else
return (TRUE);
}
5 changes: 2 additions & 3 deletions codes/loader/ldpre_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 11:20:45 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:08:00 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 12:20:01 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -91,8 +91,7 @@ int ldpre_ast(t_ast_node *ast, t_ld_map_env *env,
int fd[2];

start.next = NULL;
// TODO make pipe subshell (`exit 1 | unset A | export A=1 | echo $A`)


// prepare pipe
if (pipe(fd) < 0)
do_exit("ldpre_ast.pipe");
Expand Down
6 changes: 3 additions & 3 deletions codes/loader/ldpre_ast_redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ldpre_ast_redir.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dogwak <dogwak@student.42.fr> +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 18:41:08 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:12:10 by dogwak ### ########.fr */
/* Updated: 2024/04/05 12:19:56 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,7 +28,7 @@ t_bool ldpre_ast_redir_outfile(char *filename, enum e_node_type mode)
if (!access(filename, F_OK) && access(filename, F_OK | W_OK) != 0)
return (ld_errno_file("ldpre_ast_redir_outfile.access", filename));
close(STDOUT_FD);
if (mode == EXP_PRE_RWRITE)
if (mode == EXP_IN_RWRITE)
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
else
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
Expand Down

0 comments on commit f32723a

Please sign in to comment.