src/utils/unix_utils.c
/**
 * Get the absolute executable path of a command.
 * 
 * @param cmd The command like 'ls' or 'grep'.
 * @param envp The environment variable pointer.
 * @return The absolute path to the cmd executable.
 */
Get the absolute executable path of a command.

@param cmd The command like 'ls' or 'grep'.
@param envp The environment variable pointer.
@return The absolute path to the cmd executable.
Get the absolute executable path of a command . @param cmd The command like ' ls ' or ' grep ' . @param envp The environment variable pointer . @return The absolute path to the cmd executable .
char	*ft_getexec(const char *cmd, char **envp)
{
	char	*path;
	char	*temp;
	char	**paths;
	t_i32	path_index;
	path_index = -1;
	paths = ft_split(ft_getvar("PATH", envp), ':');
	while (paths[++path_index])
	{
		temp = ft_strjoin(paths[path_index], "/");
		path = ft_strjoin(temp, cmd);
		free(temp);
		if (ft_access(path, F_OK & X_OK))
			break ;
		free(path);
	}
	path_index = -1;
	while (paths[++path_index])
		free(paths[path_index]);
	free(paths);
	return (path);
}
char * ft_getexec ( const char * cmd , char * * envp ) { char * path ; char * temp ; char * * paths ; t_i32 path_index ; path_index = -1 ; paths = ft_split ( ft_getvar ( " " , envp ) , ' ' ) ; while ( paths [ ++ path_index ] ) { temp = ft_strjoin ( paths [ path_index ] , " " ) ; path = ft_strjoin ( temp , cmd ) ; free ( temp ) ; if ( ft_access ( path , F_OK & X_OK ) ) break ; free ( path ) ; } path_index = -1 ; while ( paths [ ++ path_index ] ) free ( paths [ path_index ] ) ; free ( paths ) ; return ( path ) ; }
Get the absolute executable path of a command.
Get the absolute executable path of a command .