Example #1
0
int	create_last(char **buf, char **last, char **line)
{
	int		i;
	char	*tmp;
	char	*tmp2;

	if (ft_strchr(*buf, '\n') != NULL)
	{
		i = 0;
		while ((*buf)[i] != '\n')
			i++;
		tmp2 = ft_strsub(*buf, 0, i);
		tmp = ft_strjoin(*line, tmp2);
		free(*line);
		free(tmp2);
		*line = tmp;
		*last = ft_strdup((*buf) + i + 1);
		free(*buf);
		if (check_ma(-2, line, last) == -1 || check_ma(-2, last, line) == -1)
			return (-1);
		return (1);
		if (*last != NULL && *last[0] == '\0')
			free(*last);
	}
	return (0);
}
Example #2
0
int	check_last(char **line, char **last, int i)
{
	char	*tmp;

	if (*last == NULL)
		return (!(*line = ft_strnew(0)) ? -1 : 0);
	if (ft_strchr(*last, '\n') != NULL)
	{
		while ((*last)[i] != '\n')
			i++;
		if (!(*line = ft_strsub(*last, 0, i)) || check_ma(-2, line, last) == -1)
			return (-1);
		if (i < (int)ft_strlen(*last))
		{
			if (!(tmp = ft_strdup((*last) + i + 1)))
				return (check_ma(-1, last, line));
			free(*last);
			*last = tmp;
		}
		else
			free(*last);
		return (1);
	}
	*line = ft_strdup(*last);
	check_ma(-1, last, NULL);
	return (!(*line) ? -1 : 0);
}
Example #3
0
int	fill_line(char **buf, int fd, char **line, int ret)
{
	char	*tmp;

	if (ret == 0)
	{
		check_ma(-1, buf, NULL);
		if ((*line)[0] == '\0')
			return (0);
		else
			return (1);
	}
	while (*buf && ft_strchr(*buf, '\n') == NULL && ret != 0)
	{
		tmp = ft_strjoin(*line, *buf);
		if (check_ma(-2, &tmp, buf) == -1)
			return (-1);
		free(*line);
		*line = tmp;
		ft_bzero(*buf, BUFF_SIZE);
		ret = read(fd, *buf, BUFF_SIZE);
		if (check_ma(ret, buf, line) == -1)
			return (-1);
	}
	if (ret == 0)
		check_ma(-1, buf, NULL);
	return (ret == 0 ? 1 : ret);
}
Example #4
0
int	get_next_line(const int fd, char **line)
{
	char		*buf;
	int			ret;
	static char	*last = NULL;
	int			i;

	i = 0;
	if (!line || fd < 0 || BUFF_SIZE <= 0 || BUFF_SIZE > 2147483647 ||
			(-1 == (ret = check_last(line, &last, i))))
		return (-1);
	if (ret == 1)
		return (1);
	buf = ft_strnew(BUFF_SIZE);
	if (check_ma(-2, &buf, line) == -1)
		return (-1);
	ret = read(fd, buf, BUFF_SIZE);
	if (check_ma(ret, &buf, line) == -1)
		return (-1);
	if (-1 == (ret = fill_line(&buf, fd, line, ret)))
		return (-1);
	if (ret == 1 || ret == 0)
		return (ret);
	return (create_last(&buf, &last, line) != 1 ? -1 : 1);
}
static void timer_interrupt(unsigned long data)
{
	struct quadd_hrt_ctx *hrt_ctx = (struct quadd_hrt_ctx *)data;
	struct timer_list *timer = &hrt_ctx->ma_timer;

	if (!atomic_read(&hrt_ctx->active))
		return;

	check_ma(hrt_ctx);

	timer->expires = jiffies + msecs_to_jiffies(hrt_ctx->ma_period);
	add_timer(timer);
}