- fgets(linebuf, sizeof linebuf, f);
- if (feof(f)) return NULL;
+ fgets(linebuf, buflen, f);
+ if (feof(f) || ferror(f)) return 0;
+ if (!strchr(linebuf, '\n')) {
+ if (fseeko(f, -(off_t)strlen(linebuf), SEEK_CUR))
+ fscanf(f, "%*[^\n]%*[\n]");
+ errno = ERANGE;
+ return 0;
+ }