Exemplo n.º 1
0
static int	ft_gnl_deleg(char **save, char **buffer, char **line)
{
	size_t		size;
	char		*next;

	if (*save != NULL)
		*save = ft_strfjoin(save, buffer, 1);
	else
		*save = ft_strdup(*buffer);
	if ((int)ft_strcchr(*save, '\n') != -1)
	{
		size = ft_strcchr(*save, '\n');
		if (size < ft_strlen(*save))
		{
			next = ft_strsub(*save, 0, size);
			*line = ft_strfjoin(line, &next, 3);
			*save = ft_strfsub(save, size + 1, ft_strlen(*save) - size, 1);
		}
		else
			*line = ft_strfjoin(line, save, 3);
		free(*buffer);
		return (1);
	}
	else
		*line = ft_strfjoin(line, save, 3);
	return (0);
}
Exemplo n.º 2
0
static int	ft_fill_line(char **line, char **buf, int ret)
{
	int		n;

	if (ret == -1)
		*buf = NULL;
	if (ret == -1)
		return (-1);
	if (ret == 0 && *buf[0] == '\0')
	{
		*buf = NULL;
		*line = ft_strdup("\0");
		return (0);
	}
	n = ft_strcchr(*buf, '\n');
	if (n > -1)
	{
		*line = ft_strndup(*buf, n);
		*buf += n + 1;
		return (1);
	}
	else
	{
		*line = ft_strndup(*buf, ft_strlen(*buf));
		ft_strclr(*buf);
		return (1);
	}
}
Exemplo n.º 3
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));
}
Exemplo n.º 4
0
char	*ft_strcdup(const char *s1, int c)
{
	int		len;
	char	*s2;

	len = ft_strcchr(s1, c);
	len = (len == -1) ? (int)ft_strlen(s1) : len;
	s2 = (char *)malloc(sizeof(char) * (len + 1));
	if (s2 == NULL)
		return (NULL);
	ft_strncpy(s2, (char *)s1, len);
	*(s2 + len) = '\0';
	return (s2);
}
Exemplo n.º 5
0
Arquivo: gnlv.c Projeto: jbplop/rt
int			gnlv(char *src, char **line)
{
	static size_t		i = 0;
	size_t		endl;

	endl = ft_strcchr(src + i, '\n');
	if ((int)endl == -1)
	{
		*line = ft_strnew(ft_strlen(src + i));
		*line = ft_strcpy(*line, src + i);
		return (-1);
	}
	endl += i;
	*line = ft_strnew(endl);
	*line = ft_strncpy(*line, src + i, endl);
	i = endl + 1;
	return (endl);
}