int get_next_line(int const fd, char **line) { static t_list *toplist = NULL; t_env *env; if (line) *line = NULL; if (fd < 0 || line == NULL || BUFF_SIZE == 0) return (-1); if (!(env = (t_env*)get_fdlist(fd, &toplist)->content)) return (-1); if (env->index) { if (ft_concat(line, &env)) return (1); } while ((env->ret = read(env->fd, env->buf, BUFF_SIZE))) { if (env->ret == -1) return (-1); if (ft_concat(line, &env)) return (1); } ft_freefdlist(fd, &toplist); return (0); }
int get_next_line(const int fd, char **line) { char buff[BUFF_SIZE + 1]; int ret; static t_stock *list = NULL; char **str; str = multi_fd(fd, &list); if (fd < 0 || !line || read(fd, buff, 0) < 0) return (-1); if (*str == NULL) { *str = ft_strdup("\0"); } while ((ret = read(fd, buff, BUFF_SIZE)) > 0) { *str = (ft_concat(buff, ret, *str)); if (ft_strstr(*str, "\n") != NULL) break ; } *str = malloc_str(*str, line); if (*str == NULL && ft_strcmp(*line, "\0") == 0) return (0); return (1); }
char *ft_read_stdin(void) { long size; int readed; char *buffer; char *result; size = 0; result = 0; if (!(buffer = malloc(sizeof(*buffer) * BUFF_SIZE))) return (0); while ((readed = read(0, buffer, BUFF_SIZE - 1)) > 0) { buffer[readed] = 0; result = ft_concat(result, buffer, size, readed); size += readed; } free(buffer); return (result); }
char *ft_readfile(void) { int fd; char *buff; char *str; str = NULL; fd = 0; if (!(buff = ft_strnew(BUFF_SIZE))) ft_error('M'); while (read(fd, buff, BUFF_SIZE) > 0) { if (!(str = ft_concat(str, buff))) ft_error('M'); if (buff) free(buff); if (!(buff = ft_strnew(BUFF_SIZE))) ft_error('M'); } if (!str) ft_error('V'); return (str); }