Modified: function pwd updated to return current path with or without arguments
authorLilia-42 <nikolovalilianenkova@gmail.com>
Fri, 23 Aug 2024 14:09:37 +0000 (16:09 +0200)
committerLilia-42 <nikolovalilianenkova@gmail.com>
Fri, 23 Aug 2024 14:09:37 +0000 (16:09 +0200)
inc/execution.h
src/builtins/pwd.c
src/execution.c

index 8a0f7ad2de63e62b414121d8b45e569b771dae06..6fc5f3da1c59c19226afe20b7958e600595d8f67 100644 (file)
@@ -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
index ebfafda7f72af9821b85c881faeea3893215aaf7..7176bec9bfb5ebb98440ff825f9fcde12df7d27c 100644 (file)
@@ -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
+}
index bd8d367784447381c06efd343ca3549ab6ff7755..2832e0754b566695ca5cc1bf2e1cd113589257f7 100644 (file)
@@ -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