Skip to content

Commit 1737fbf

Browse files
committed
refactor: update ft_execvp to use t_env for environment variable access
1 parent d2467bb commit 1737fbf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/executor/executor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: pchung <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/04 16:30:00 by jidler #+# #+# */
9-
/* Updated: 2025/03/08 20:43:31 by pchung ### ########.fr */
9+
/* Updated: 2025/03/08 21:18:22 by pchung ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -54,7 +54,7 @@ int set_filedirectories(t_cmd *cmd, int *fd_in, int *fd_out);
5454
/* Path Resolution */
5555
char *find_executable_in_path(const char *cmd, t_env *env_list);
5656
int has_slash(const char *str);
57-
int ft_execvp(const char *file, char *const argv[], char **envp);
57+
int ft_execvp(const char *file, char *const argv[], char **envp, t_env *env_list);
5858

5959
/* Utility Functions */
6060
char **convert_list_to_arr(t_list *lst);

src/executor/executor_command_execution.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ char *ft_strjoin2(const char *path, const char *cmd) {
151151
return full_path;
152152
}
153153

154-
int ft_execvp(const char *file, char *const argv[], char **envp) {
155-
char *path_env = getenv("PATH");
154+
int ft_execvp(const char *file, char *const argv[], char **envp,t_env *env_list)
155+
{
156+
char *path_env = get_env_value(env_list, "PATH");
156157
char **paths = NULL;
157158
char *cmd_path;
158159
int i = 0;
@@ -196,7 +197,6 @@ int ft_execvp(const char *file, char *const argv[], char **envp) {
196197
return -1;
197198
}
198199

199-
200200
int exec_cmd_external(t_cmd *cmd, t_command_group *command_group, t_env *env_list, char **envp)
201201
{
202202
char **tokens = convert_list_to_arr(cmd->tokens);
@@ -208,8 +208,8 @@ int exec_cmd_external(t_cmd *cmd, t_command_group *command_group, t_env *env_lis
208208
pid = fork();
209209

210210
if (pid == 0) { // Child process
211-
ft_execvp(tokens[0], tokens, envp);
212-
211+
ft_execvp(tokens[0], tokens, envp, env_list);
212+
213213
// If execvp fails, print debugging information
214214
perror("Execvp failed");
215215

0 commit comments

Comments
 (0)