Beispiel #1
0
int				get_next_line(int const fd, char **line)
{
	static char		*buffer = NULL;
	char			str[BUFF_SIZE + 1];
	int				read_bytes;
	int				status;
	char			*tmp;

	ft_bzero(str, BUFF_SIZE + 1);
	if (fd < 0 || !line)
		return (-1);
	if ((status = check_buffer(&buffer, line)))
		return (status);
	while ((read_bytes = read(fd, str, BUFF_SIZE)) > 0)
	{
		if ((status = find_new_line(&buffer, line, str)))
			return (status);
		tmp = buffer;
		buffer = buffer ? ft_strjoin(tmp, str) : ft_strdup(str);
		if (!buffer)
			return (-1);
		free(tmp);
		ft_bzero(str, BUFF_SIZE + 1);
	}
	return (recheck_buffer(read_bytes, &buffer, line));
}
Beispiel #2
0
int				get_next_line(const int fd, char **line)
{
    static char	*remains = 0;
    char		buff[BUFF_SIZE + 1];
    int			i_endl;
    ssize_t		size_read;

    if (!line)
        return (-1);
    size_read = 1;
    while ((i_endl = find_new_line(remains)) < 0 && size_read)
    {
        if ((size_read = read(fd, buff, BUFF_SIZE)) == -1)
            return (-1);
        if (size_read > 0)
            str_append_new(&remains, buff, size_read);
    }
    return (str_split_new(&remains, line, i_endl));
}