From a2162f794781ba8be06c1a01bc2d23ee2c11c081 Mon Sep 17 00:00:00 2001 From: Lilia-42 Date: Fri, 23 Aug 2024 16:09:37 +0200 Subject: [PATCH] Modified: function pwd updated to return current path with or without arguments --- inc/execution.h | 2 +- src/builtins/pwd.c | 11 +++-------- src/execution.c | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/inc/execution.h b/inc/execution.h index 8a0f7ad..6fc5f3d 100644 --- a/inc/execution.h +++ b/inc/execution.h @@ -19,7 +19,7 @@ int set_env_var_value(t_execution_env *env, const char *var_name, const char *new_value); int cd(int argc, char **argv, t_execution_env *env); int echo(int argc, char **argv); -int pwd(int argc); +int pwd(void); int ft_env(int argc, t_execution_env *env); #endif // EXECUTION_H diff --git a/src/builtins/pwd.c b/src/builtins/pwd.c index ebfafda..7176bec 100644 --- a/src/builtins/pwd.c +++ b/src/builtins/pwd.c @@ -3,16 +3,11 @@ #include "minishell.h" #include "execution.h" -int pwd(int argc) +int pwd(void) { char cwd[256]; - if (argc > 1) - { - ft_putstr_fd("pwd: too many arguments\n", 1); - return (1); - } - else if (getcwd(cwd, sizeof(cwd)) == NULL) + if (getcwd(cwd, sizeof(cwd)) == NULL) perror("getcwd() error"); else { @@ -20,4 +15,4 @@ int pwd(int argc) ft_putstr_fd("\n", 1); } return (0); -} \ No newline at end of file +} diff --git a/src/execution.c b/src/execution.c index bd8d367..2832e07 100644 --- a/src/execution.c +++ b/src/execution.c @@ -800,7 +800,7 @@ int ex_builtin(char **fields, __attribute__((unused)) t_vec *assignments, __attr else if (!ft_strcmp(fields[0], "echo")) env->ret_val = echo(count_fields(fields), fields); else if (!ft_strcmp(fields[0], "pwd")) - env->ret_val = pwd(count_fields(fields)); + env->ret_val = pwd(); else if (!ft_strcmp(fields[0], "env")) env->ret_val = ft_env(count_fields(fields), env); else -- 2.30.2