All pastes #259138 Raw Edit

Miscellany

public text v1 · immutable
#259138 ·published 2006-11-27 03:38 UTC
rendered paste body
#define BUFF_SIZE 40
#define READ_SIZE 40

char            *get_next_line(const int fd)
{
  static char   *buff_read;
  static int    repeat;
  static char   *suite;
  char          *retour;
  int           i;
  int           j;
  int           k;

  k = 0;
  j = 0;
  suite = (char *)malloc(sizeof(buff_read) * BUFF_SIZE * 2);
  retour = (char *)malloc(sizeof(buff_read) * BUFF_SIZE);
  buff_read = (char *)malloc(sizeof(buff_read) * BUFF_SIZE);
  if (BUFF_SIZE < READ_SIZE)
    return ("BUFF SIZE cannot be shorter than READ SIZE.");
  i = 0;
  repeat = read(fd, buff_read, READ_SIZE);
  while (suite[k] && suite[k] != '\n')
    {
      retour[k] = suite[k];
      k++;
    }
  free (suite);
  while (buff_read[i] != '\n' && buff_read[i] != '\0' && BUFF_SIZE >= i && READ_SIZE >= i)
    {
      retour[i + k] = buff_read[i];
      i++;
    }
  if ((buff_read[i] == '/n') ||(buff_read[i] == '\0'))
    {
      suite[0] = '\0';
      free (buff_read);
      return (retour);
    }
  else
    {
      i++;
      while (buff_read[i] != '\n' && buff_read[i] != '\0')
        {
          suite[j] = buff_read[i];
          i++;
        }
    }
  free (buff_read);
  return (retour);
}