char *ft_alloc_n_read(int const fd, char *str, char *end) { char *buf; int cpt; buf = (char*)malloc(sizeof(char) * (BUFF_SIZE + 1)); if (buf == NULL || BUFF_SIZE == 0) { *end = -1; free(str); return (NULL); } cpt = BUFF_SIZE; while (cpt > 0 && str != NULL) { cpt = read(fd, buf, BUFF_SIZE); if (cpt == -1) return (NULL); else if (cpt != 0) { buf[cpt] = '\0'; str = ft_strjoin_gnl(str, buf, &cpt); } } free(buf); return (str); }
void ft_alloc_n_read(int const fd, char **str, int *end, int cpt) { char *buf; buf = (char*)malloc(sizeof(char) * (BUFF_SIZE + 1)); if ((buf == NULL || BUFF_SIZE < 1) && (*str) != NULL) { *end = -1; ft_strdel(str); return ; } while (cpt == BUFF_SIZE) { cpt = read(fd, buf, BUFF_SIZE); if (cpt == -1) { *end = -1; ft_strdel(str); free(buf); return ; } buf[cpt] = '\0'; *str = ft_strjoin_gnl(str, buf, &cpt); if (cpt != BUFF_SIZE && cpt != -2) *end = 0; } free(buf); }
char *ft_alloc_n_read(int const fd, char *str, int *end) { char *buf; int cpt; if (!(buf = ft_strnew(BUFF_SIZE))) { *end = -1; free(str); return (NULL); } cpt = BUFF_SIZE; while (cpt == BUFF_SIZE) { if((cpt = read(fd, buf, BUFF_SIZE)) == -1) { *end = -1; free(buf); free(str); return (NULL); } str = ft_strjoin_gnl(str, buf, &cpt); if (cpt != BUFF_SIZE && cpt != -2) *end = 0; } free (buf); return (str); }
int tt_gnl(const int fd, char **line) { char bull[BUFF_SIZE]; static char *to_red; char *mother_cutter; int ret; ret = -1; if (fd > -1 && line && !to_red && (ret = (int)read(fd, bull, BUFF_SIZE - 1)) > 1) { bull[ret] = 0; to_red = ft_strdup(bull); } if (ret == -1) return (ret); while (!ft_strchr(to_red, '\n') && (ret = (int)read(fd, bull, BUFF_SIZE - 1))) { bull[ret] = 0; ft_strjoin_gnl(&to_red, bull); } if ((mother_cutter = ft_strchr(to_red, '\n'))) return (send_cut_keep(line, &to_red, mother_cutter)); freedom(&to_red, line); return ((int)tt_slen(*line)); }
static void free_line(char **cpy, char **line, char *buff) { *cpy = *line; *line = ft_strjoin_gnl(*line, buff); free(*cpy); }