コード例 #1
0
ファイル: get_next_line.c プロジェクト: NicolasC27/Minishell2
char		*get_next_line(const int fd)
{
  static char	buff[BUFF_SIZE];
  static int	len;
  static int	a;
  char		*str;
  int		n;

  n = 0;
  if ((read_gnl(fd, &len, &a, buff)) == 0)
    return (NULL);
  if ((str = malloc(sizeof(char) * (BUFF_SIZE + 1))) == NULL)
    return (NULL);
  my_memset(str, 0, BUFF_SIZE + 1);
  while (buff[a] && buff[a] != '\n')
    {
      str[n++] = buff[a++];
      if (n >= BUFF_SIZE)
	str = my_realloc(str, 1);
      if ((read_gnl(fd, &len, &a, buff)) == 0)
	  return (str);
    }
  a++;
  str[n] = '\0';
  return (str);
}
コード例 #2
0
ファイル: gnl_querat_g.c プロジェクト: budocay/corewar
char	*gnl_querat_g(const int fd)
{
  static char	buffer[BUFF];
  static int	j;
  static int	lus;
  char		*line;

  line = NULL;
  if (BUFF < 1)
    return (NULL);
  while (42)
    {
      if (fd < 0)
	return (NULL);
      if (!(read_gnl(&j, &lus, &fd, buffer)))
	return (line);
      if (!(line = mallocat(line, buffer, &j, lus)))
	return (NULL);
      if (buffer[j] == '\n')
	{
	  j++;
	  return (line);
	}
    }
  return (line);
}
コード例 #3
0
ファイル: get_next_line.c プロジェクト: Xiangua/fdf
int					get_next_line(const int fd, char **line)
{
	static t_gnl	*rec = NULL;
	t_gnl			*rest;
	char			*buff;
	int				read_ret;

	if (line)
		*line = NULL;
	rest = manage_static_struct(&rec, fd);
	read_ret = rest->read_ret;
	buff = ft_strdup(rest->rest);
	search_backline(&buff, rest, read_ret);
	if (buff && line)
		*line = buff;
	while (line && (read_ret > 0 || read_ret == -2) && rest->line == 0)
		read_ret = read_gnl(rest, fd, line);
	if (read_ret == -1 || !line)
		return (-1);
	if (check_end_gnl(rest))
		return (0);
	return (1);
}