Ejemplo n.º 1
0
int			get_next_line(int const fd, char **line)
{
	static char *buf;
	char		*pos;
	int			result;

	if (BUFF_SIZE < 1 || !line)
		return (-1);
	if (!buf)
		if (!(buf = (char*)malloc(sizeof(char) * (BUFF_SIZE + 1))))
			return (-1);
	pos = ft_strchr(buf, '\n');
	if (pos)
	{
		*pos = 0;
		*line = ft_strdup(buf);
		ft_strcpy(buf, pos + 1);
		return (*line ? 1 : -1);
	}
	else
		result = ft_read_line(fd, &buf, line, NULL);
	if (result == 0 && ft_strlen(*line) == 0)
		free(buf);
	if (result == -1)
		return (-1);
	return (result ? 1 : ft_strlen(*line) != 0);
}
Ejemplo n.º 2
0
int		get_next_line(int const fd, char **line)
{
	int			ret;
	char		*buf;
	char		*ptr;
	int			retour;

	ptr = malloc(sizeof(char) * BUF_SIZE + 1);
	buf = malloc(sizeof(char) * BUF_SIZE + 1);
	ret = read(fd, buf, BUF_SIZE);
	buf[ret] = '\0';
	ptr = ft_strjoin(ptr, buf);
	while (ret)
	{
		ret = read(fd, buf, BUF_SIZE);
		buf[ret] = '\0';
		ptr = ft_strjoin(ptr, buf);
	}
	*line = ft_read_line(ptr, &retour);
 	return (retour);
}