+static char *fgetslong(char **aLinePtr, FILE *stream)
+{
+ char *linebuf;
+ size_t bufsize = MAX_LENGTH;
+ int eolpos = 0;
+
+ if (feof(stream)) return *aLinePtr = 0;
+ if (!(linebuf = malloc(bufsize))) {
+ perror("fgetslong: malloc");
+ exit(1);
+ }
+ linebuf[0] = '\0';
+ while (fgets(linebuf + eolpos, MAX_LENGTH, stream)) {
+ eolpos += strlen(linebuf + eolpos);
+ if (linebuf[eolpos - 1] == '\n') return *aLinePtr = linebuf;
+ bufsize += MAX_LENGTH;
+ if (!(linebuf = realloc(linebuf, bufsize))) {
+ perror("fgetslong: realloc");
+ exit(1);
+ }
+ }
+ return *aLinePtr = linebuf[0] ? linebuf : 0;
+}