int ft_get_next_line(int const fd, char **line) { static t_list *lst; char buf[BUFF_SIZE + 1]; int retour_read; t_file *file; if (fd == -1 || !line || BUFF_SIZE <= 0 || !(file = ft_search_fd(&lst, fd))) return (-1); if (!(retour_read = ft_save_line(file, line))) { while ((retour_read = read(fd, buf, BUFF_SIZE))) { if (retour_read < 0) return (-1); buf[retour_read] = '\0'; if ((retour_read = ft_readnextline(buf, line, file))) return (retour_read); } if (**line) return (1); return (0); } return (retour_read); }
void ft_save_map(int ac, char **av, t_gen *gen) { int fd; char *line; int i; i = 0; if (ac != 2) ft_error_files(ac); if ((fd = open(av[1], O_RDONLY)) < 0 || !ft_isfile(av[1]) || ft_isdir(av[1])) ft_error_pass(); gen->filename = ft_strdup(av[1]); ft_check_file(gen); gen->map = malloc(sizeof(t_point**) * gen->y); gen->y = 0; while (get_next_line(fd, &line)) { ft_save_line(line, gen); free(line); gen->y++; } close(fd); }