Logo Search packages:      
Sourcecode: agedu version File versions  Download package

fgetline.c

/*
 * fgetline.c: implementation of fgetline.h.
 */

#include "agedu.h"
#include "alloc.h"
#include "fgetline.h"

char *fgetline(FILE *fp)
{
    char *ret = snewn(512, char);
    int size = 512, len = 0;
    while (fgets(ret + len, size - len, fp)) {
      len += strlen(ret + len);
      if (ret[len-1] == '\n')
          break;               /* got a newline, we're done */
      size = len + 512;
      ret = sresize(ret, size, char);
    }
    if (len == 0) {                  /* first fgets returned NULL */
      sfree(ret);
      return NULL;
    }
    ret[len] = '\0';
    return ret;
}

Generated by  Doxygen 1.6.0   Back to index