int get_next_line(int fd, char **line) { static char *save; char buff[BUF_SIZE + 1]; char *ret; static int i = 1; if (i) ret = (save) ? ft_strdup(save) : ft_strnew(BUF_SIZE); else return (ft_end_line(&save, line)); while (!ft_strchr(ret, '\n')) { if ((i = read(fd, buff, BUF_SIZE)) > 0) { buff[i] = '\0'; ret = ft_strjoin(ret, buff); } else return (i); } if (!(*line = (char *)malloc(sizeof(char) * ft_strlento(ret) + 1))) return (-1); save = ft_strdup(ft_strcpyto(*line, ret)); free(ret); return (1); }
int get_next_line(const int fd, char **line) { static char *stock = ""; int ret; char *str; ret = 1; if (!line || fd < 0 || (stock[0] == '\0' && (!(stock = ft_strnew(0))))) return (-1); while (ret > 0) { if ((str = ft_strchr(stock, '\n')) != NULL) { *str = '\0'; if (!(*line = ft_strdup(stock))) return (-1); ft_memmove(stock, str + 1, ft_strlen(str + 1) + 1); return (1); } if (!(stock = ft_read(fd, stock, &ret))) return (-1); } ft_strdel(&str); if (ret == 0 && ft_strlen(stock)) ret = ft_end_line(&(*line), &stock); return (ret); }
void ft_put_3d_tab(t_env env, t_3dpos **tab, t_img img, t_pos max) { int x; int y; y = 0; while (y < (max.y - 1)) { x = 0; while (x < (max.x - 1)) { ft_3d_line(env, tab[y][x], tab[y][x + 1], img); ft_3d_line(env, tab[y][x], tab[y + 1][x], img); x++; } y++; } ft_end_line(env, tab, img, max); }