Beispiel #1
0
int					get_next_line(int fd, char **line)
{
	static char		*save = NULL;
	char			buff[BUFF_SIZE + 1];
	char			*tmp;
	int				ret;

	ret = 0;
	if (fd == -1 || BUFF_SIZE <= 0)
		return (ft_err(&save));
	if (save == NULL)
		save = ft_strnew(BUFF_SIZE + 1);
	while (save != NULL
			&& ft_strchr(save, '\n') == NULL
			&& ((ret = read(fd, buff, BUFF_SIZE)) > 0))
	{
		buff[ret] = '\0';
		tmp = save;
		save = ft_strjoin(tmp, buff);
		free(tmp);
	}
	if (ret == -1)
		return (-1);
	if (ret == 0 && ft_strchr(save, '\n') == NULL)
		return ((ft_end(line, &save)));
	ft_ret(line, &(save));
	return (1);
}
Beispiel #2
0
char			*ft_strtrim(char const *s)
{
	char	*scpy;
	int		i;
	int		j;

	i = 0;
	j = 0;
	while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
		i++;
	while (s[i] != '\0')
	{
		i++;
		j++;
	}
	i--;
	while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && i != 0)
	{
		i--;
		j--;
	}
	i = 0;
	while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
		i++;
	if ((scpy = ft_strnew(j)))
		ft_strncpy(scpy, (char *)(s + i), j);
	return (ft_ret(scpy));
}