示例#1
0
int				get_next_line(int const fd, char **line)
{
	static t_info	*list;
	t_info			*cur;
	int				result;
	int				len;
	int				ret;

	len = -1;
	if (line == NULL || ft_match_fd(&list, &cur, fd))
		return (-1);
	if (cur->offset != 0)
	{
		if ((result = ft_read_buf(line, cur, &len)) != 0)
			return (result);
	}
	while ((ret = read(fd, cur->buf, BUFF_SIZE)) > 0)
	{
		cur->offset = ret;
		cur->start = cur->buf;
		if ((result = ft_read_buf(line, cur, &len)) != 0)
			return (result);
	}
	ft_del_fd(&list, cur);
	if (ret == -1)
		return (-1);
	return (len != -1);
}
示例#2
0
int			get_next_line(int const fd, char **line)
{
	int			ret;
	char		*buf;
	char		*str;
	static char	*rest;

	ret = 1;
	str = ft_strnew(BUFF_SIZE);
	if (str == NULL)
		return (-1);
	while (ret > 0)
	{
		if (ft_read_buf(fd, &buf, &ret) == -1)
			return (-1);
		if (ft_test_rest(&rest, &str, &buf) == -1)
			return (-1);
		if (ft_strchr(str, '\n') != NULL)
			return (ft_check_n(&rest, str, line));
		ft_memdel((void **)&buf);
	}
	*line = str;
	if (*line != NULL && **line != '\0')
		return (1);
	return (0);
}