From e13e23b460787ba7d39675cf74a60de21b8db7e5 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Wed, 25 Sep 2024 14:58:39 -0400 Subject: added append chaining operator --- src/lush.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lush.c b/src/lush.c index 677ca3d..04e4a91 100644 --- a/src/lush.c +++ b/src/lush.c @@ -1071,7 +1071,7 @@ static int run_command(lua_State *L, char ***commands) { return lush_execute_command(commands[0], STDIN_FILENO, STDOUT_FILENO); } -static int run_command_redirect(lua_State *L, char ***commands) { +static int run_command_redirect(lua_State *L, char ***commands, int mode) { if (commands[2][0] == NULL) return -1; @@ -1081,7 +1081,7 @@ static int run_command_redirect(lua_State *L, char ***commands) { return -1; } - int fd = open(commands[2][0], O_WRONLY | O_CREAT | O_TRUNC, 0644); + int fd = open(commands[2][0], O_WRONLY | O_CREAT | mode, 0644); if (fd == -1) { perror("invalid fd"); close(saved_stdout); @@ -1183,9 +1183,13 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { commands += 2; continue; } else if (op_type == OP_REDIRECT_OUT) { - run_command_redirect(L, commands); + run_command_redirect(L, commands, O_TRUNC); commands += 3; // to go past fd given continue; + } else if (op_type == OP_APPEND_OUT) { + run_command_redirect(L, commands, O_APPEND); + commands += 3; + continue; } } if (commands[0] != NULL) { -- cgit v1.2.3-59-g8ed1b