return s;
offset = ch - s - 1;
}
- else if (feof (fp))
- {
- /* The last line of fp isn't \n terminated */
- (*line)++;
- return s;
- }
else
{
- /* There wasn't room for the line -- increase ``s'' */
- offset = *size - 1; /* overwrite the terminating 0 */
- *size += STRING;
- safe_realloc ((void **) &s, *size);
+ int c;
+ c = getc (fp); /* This is kind of a hack. We want to know if the
+ char at the current point in the input stream is EOF.
+ feof() will only tell us if we've already hit EOF, not
+ if the next character is EOF. So, we need to read in
+ the next character and manually check if it is EOF. */
+ if (c == EOF)
+ {
+ /* The last line of fp isn't \n terminated */
+ (*line)++;
+ return s;
+ }
+ else
+ {
+ ungetc (c, fp); /* undo our dammage */
+ /* There wasn't room for the line -- increase ``s'' */
+ offset = *size - 1; /* overwrite the terminating 0 */
+ *size += STRING;
+ safe_realloc ((void **) &s, *size);
+ }
}
}
}