66/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
77/* +#+#+#+#+#+ +#+ */
88/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
9- /* Updated: 2024/03/06 08:42:49 by marde-vr ### ########.fr */
9+ /* Updated: 2024/03/06 10:18:53 by marde-vr ### ########.fr */
1010/* */
1111/* ************************************************************************** */
1212
1313#include "minishell.h"
14+ #include <unistd.h>
1415
1516char * * split_paths_from_env (t_env * env )
1617{
@@ -30,7 +31,7 @@ char **split_paths_from_env(t_env *env)
3031 }
3132 if (!path_in_envp )
3233 {
33- ft_printf_fd (2 , "msh : error: PATH not found\n" );
34+ ft_printf_fd (2 , "minishell : error: PATH not found\n" );
3435 return (0 );
3536 }
3637 return (ft_split (cur_env_var -> value , ':' ));
@@ -78,26 +79,32 @@ void free_paths(char **paths)
7879 free (paths );
7980}
8081
81- void get_cmd_path (t_msh * msh )
82+ void get_path (t_msh * msh , int * found )
8283{
8384 char * * paths ;
85+
86+ paths = split_paths_from_env (msh -> env );
87+ if (!paths )
88+ {
89+ free_paths (paths );
90+ ft_exit (msh , 1 );
91+ }
92+ find_cmd_path (msh , paths , found );
93+ free_paths (paths );
94+ }
95+
96+ void get_cmd_path (t_msh * msh )
97+ {
8498 int found ;
8599
86100 found = 0 ;
87- if (ft_strchr (msh -> cmds -> token , '/' )
88- && access (msh -> cmds -> token , X_OK ) != -1 )
89- found = 1 ;
90- else
101+ if (ft_strchr (msh -> cmds -> token , '/' ))
91102 {
92- paths = split_paths_from_env (msh -> env );
93- if (!paths )
94- {
95- free_paths (paths );
96- ft_exit (msh , 1 );
97- }
98- find_cmd_path (msh , paths , & found );
99- free_paths (paths );
103+ if (!file_access (msh , & found ))
104+ return ;
100105 }
106+ else
107+ get_path (msh , & found );
101108 if (!found )
102109 {
103110 ft_printf_fd (2 , "%s: command not found\n" , msh -> cmds -> token );
0 commit comments