Esempio n. 1
0
static int			ft_print(int n, t_read **tab, t_read **s, char **l)
{
	char			*tmpstr;
	int				index;

	if (!tab[0])
		return (-1);
	index = (tab[0])->index;
	if (n == -1 || !(tmpstr = (char *)malloc(sizeof(char) * (n + 1))))
		return (-1);
	*l = tmpstr;
	while (n--)
	{
		*tmpstr++ = (tab[0])->read[index++];
		if (index == (tab[0])->size)
		{
			tab[0] = ft_freeread(tab[0], tab[1], s);
			index = 0;
		}
	}
	*tmpstr = 0;
	if (!tab[0] || (index == tab[0]->size && tab[0]->size < BUFF_SIZE))
		return (0);
	tab[0]->index = index + 1;
	if (tab[0]->index == tab[0]->size)
		tab[0] = ft_freeread(tab[0], tab[1], s);
	return (1);
}
static	int			ft_print(int n, t_read *r, t_read *p, t_read **s, char** l)
{
	char			*tmpstr;
	int				index;

	if (!r)
		return (-1);
	index = r->index;
	if (n == -1 || !(tmpstr = (char *)malloc(sizeof (char) * (n + 1))))
		return (-1);
	*l = tmpstr;
	while (n--)
	{
		*tmpstr++ = r->read[index++];
		if (index == r->size)
		{
			r = ft_freeread(r, p, s);
			index = 0;
		}
	}
	*tmpstr = 0;
	if (!r || (index == r->size && r->size < BUFF_SIZE))
		return (0);
	r->index = index + 1;
	if (r->index == r->size)
		r = ft_freeread(r, p, s);
	return (1);
}