path.c
/**
 * add_path - append path to the command
 * @tokens: token pointer
 * @env: pointer to env variables
 * Return: return 0 if success
 */
append path to the command
@tokens: token pointer
@env: pointer to env variables
Return: return 0 if success
append path to the command @tokens : token pointer @env : pointer to env variables Return : return 0 if success
int add_path(char ***tokens, char **env)
{
	char *env_path, *tkn, *new_cmd = NULL;
	int len_dir, len_cmd;
	struct stat st;
	path_node *path_n, *copy_list;
	st.st_mode = 0;
	env_path = _strdup(_getenv("PATH", env));
	tkn = strtok(env_path, ":");
	while (tkn != NULL)
	{
		create_path_list(tkn, &path_n);
		tkn = strtok(NULL, ":");
	}
	copy_list = path_n;
	len_cmd = _strlen((*tokens)[0]);
	while (path_n != NULL)
	{
		len_dir = _strlen(path_n->path);
		new_cmd = malloc(sizeof(char) * (len_dir + len_cmd + 2));
		new_cmd[0] = '\0';
		_strcat(new_cmd, path_n->path);
		_strcat(new_cmd, "/");
		_strcat(new_cmd, (*tokens)[0]);
		stat(new_cmd, &st);
		if ((access(new_cmd, F_OK | X_OK) == 0) &&
				((st.st_mode & S_IFMT) == S_IFREG))
		{
			(*tokens)[0] = new_cmd;
			return (0);
		}
		else 
			perror("Error: ");
		free(new_cmd);
		new_cmd = NULL;
		path_n = path_n->next;
	}
	free_list(copy_list);
	return (0);
}
int add_path ( char * * * tokens , char * * env ) { char * env_path , * tkn , * new_cmd = NULL ; int len_dir , len_cmd ; struct stat st ; path_node * path_n , * copy_list ; st . st_mode = 0 ; env_path = _strdup ( _getenv ( " " , env ) ) ; tkn = strtok ( env_path , " " ) ; while ( tkn != NULL ) { create_path_list ( tkn , & path_n ) ; tkn = strtok ( NULL , " " ) ; } copy_list = path_n ; len_cmd = _strlen ( ( * tokens ) [ 0 ] ) ; while ( path_n != NULL ) { len_dir = _strlen ( path_n -> path ) ; new_cmd = malloc ( sizeof ( char ) * ( len_dir + len_cmd + 2 ) ) ; new_cmd [ 0 ] = ' \0 ' ; _strcat ( new_cmd , path_n -> path ) ; _strcat ( new_cmd , " " ) ; _strcat ( new_cmd , ( * tokens ) [ 0 ] ) ; stat ( new_cmd , & st ) ; if ( ( access ( new_cmd , F_OK | X_OK ) == 0 ) && ( ( st . st_mode & S_IFMT ) == S_IFREG ) ) { ( * tokens ) [ 0 ] = new_cmd ; return ( 0 ) ; } else perror ( " " ) ; free ( new_cmd ) ; new_cmd = NULL ; path_n = path_n -> next ; } free_list ( copy_list ) ; return ( 0 ) ; }
add_path - append path to the command
 @tokens: token pointer
 @env: pointer to env variables
 Return: return 0 if success
add_path - append path to the command @tokens : token pointer @env : pointer to env variables Return : return 0 if success
/*This part is broken*/