コード例 #1
0
ファイル: get_next_line.c プロジェクト: iTzDyms/libft
int		ft_join_move(char **line, char *buff, char *next_line, int nbread)
{
	*next_line = '\0';
	if (!(*line = ft_join_free(line, buff)))
		return (-1);
	buff = ft_memmove(buff, &next_line[1], ft_strlen(&next_line[1]) + 1);
	if (buff == NULL)
		return (-1);
	return (nbread);
}
コード例 #2
0
ファイル: get_next_line.c プロジェクト: iTzDyms/libft
int		ft_buff_leftover(char *buff, char **line)
{
	char		*next_line;

	if ((next_line = ft_strchr(buff, '\n')))
	{
		next_line[0] = '\0';
		if (!(*line = ft_join_free(line, buff)))
			return (-1);
		buff = ft_memmove(buff, &next_line[1], (ft_strlen(&next_line[1]) + 1));
		return (1);
	}
	else
	{
		if (!(*line = ft_join_free(line, buff)))
			return (-1);
		ft_strclr(buff);
		return (0);
	}
}
コード例 #3
0
ファイル: ft_lftoa.c プロジェクト: Tolo789/Lem-in
char		*ft_lftoa(long double nbr)
{
	char		*str;

	str = ft_first((long double)((long long int)nbr));
	nbr = nbr - (long long int)nbr;
	if (nbr < 0)
		nbr *= -1;
	str = ft_join_free(str, ft_second(nbr));
	return (str);
}
コード例 #4
0
ファイル: get_next_line.c プロジェクト: ninja00/get_next_line
int							get_next_line(int const fd, char **line)
{
	static char			*str[256];
	char				*tmp;
	int					ret;

	if (BUFF_SIZE == 0)
		return (0);
	if (fd < 0 || line == NULL || fd > 256)
		return (-1);
	str[fd] = str[fd] ? str[fd] : ft_strnew(0);
	tmp = (char *)malloc(sizeof(char) * (BUFF_SIZE + 1));
	while ((ret = read(fd, tmp, BUFF_SIZE)) > 0)
	{
		tmp[ret] = '\0';
		str[fd] = ft_join_free(str[fd], tmp);
		if (ft_strchr(str[fd], '\n'))
			break ;
	}
	free(tmp);
	return (ft_find_line(ret, &str[fd], line));
}
コード例 #5
0
ファイル: get_next_line.c プロジェクト: iTzDyms/libft
int		ft_readfile(int const fd, char **line, char *buff)
{
	char		*next_line;
	ssize_t		nbread;

	while ((nbread = read(fd, (void *)buff, (size_t)BUFF_SIZE)))
	{
		if (nbread == -1)
		{
			ft_strdel(&buff);
			return (-1);
		}
		buff[nbread] = '\0';
		if (!(next_line = ft_strchr(buff, '\n')))
		{
			if (!(*line = ft_join_free(line, buff)))
				return (-1);
			ft_strclr(buff);
		}
		else
			return (ft_join_move(line, buff, next_line, nbread));
	}
	return (nbread);
}