Example #1
0
static int	ft_get_next_line(int const fd, char **line)
{
	int				ret;
	static t_struct *gnl = NULL;

	init_buf(&gnl, line);
	while (gnl->buf2 || (ret = read(fd, gnl->buf, BUFF_SIZE)))
	{
		if (gnl->buf2)
		{
			*line = ft_fill_line(gnl->buf2 + 1, *line);
			if ((gnl->buf2 = ft_strchr(gnl->buf2 + 1, '\n')) == NULL)
			{
				if ((ret = read(fd, gnl->buf, BUFF_SIZE)) == 0)
					return (0);
			}
			else
				return (1);
		}
		if (ret == -1)
			return (-1);
		gnl->buf[ret] = '\0';
		*line = ft_fill_line(gnl->buf, *line);
		if ((gnl->buf2 = ft_strchr(gnl->buf, '\n')) != NULL)
			return (1);
	}
	return ((ret || **line) ? 1 : 0);
}
Example #2
0
int			get_next_line(int const fd, char **line)
{
	static char	*buf[256];
	char		tmp[BUFF_SIZE + 1];
	int			is_n;
	int			ret;
	size_t		size;

	ret = 1;
	if (buf[fd] == NULL && line != NULL)
		buf[fd] = (char *)ft_memalloc(sizeof(char) * BUFF_SIZE + 1);
	if (buf[fd] == NULL || fd < 0 || *line == NULL)
		return (-1);
	size = 1 + ft_strlen(buf[fd]);
	while ((is_n = ft_strcchr(buf[fd], '\n')) == -1 && ret > 0)
	{
		if ((ret = read(fd, tmp, BUFF_SIZE)))
		{
			tmp[ret] = '\0';
			size += BUFF_SIZE;
			if ((buf[fd] = (char *)ft_realloc(buf[fd], size)) == NULL)
				return (-1);
			ft_strcat(buf[fd], tmp);
		}
	}
	return (ft_fill_line(line, &buf[fd], ret));
}
Example #3
0
int			get_next_line(int const fd, char **line)
{
	char		buf[BUFF_SIZE + 1];
	int			ret;
	int			res;
	static t_fd	*files = NULL;

	res = -1;
	if (fd < 0 || fd == 1 || fd == 2 || !line)
		return (-1);
	ret = read(fd, buf, BUFF_SIZE);
	if (ret == -1 || (ret == 0 && (!ft_checkfiles(fd, files))))
		return (ret);
	buf[ret] = '\0';
	if (ret > 0)
		if (!(res = ft_checkbuf((char*)buf, &files, fd)))
			get_next_line(fd, line);
	if (((ret > 0 && res == 1) || ret == 0) && ft_checkfiles(fd, files))
		ft_fill_line(ft_checkfiles(fd, files), line, fd, &files);
	return (1);
}