- /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
- is followed by '\r', swallow that as well. */
- if ((c == '\r' && next != '\n')
- || (c == '\n' && next != '\r'))
- ungetc (next, last_open_file);
+ if (current_line == linenum)
+ {
+ /* We have found the start of the line we seek. */
+ found = TRUE;
+
+ /* FIXME: We could skip the read-in-the-line code
+ below if we know that we already have the whole
+ line in the buffer. */
+
+ /* Advance pos2 to the newline character we have just located. */
+ pos2 += (ptr - buffer);
+
+ /* Skip the newline and, if present, the carriage return. */
+ if (ptr + 1 == buffer + size)
+ {
+ ++pos2;
+ if (fgetc (last_open_file) == '\r')
+ ++ pos2;
+ }
+ else
+ pos2 += (ptr[1] == '\r' ? 2 : 1);
+
+ /* Move the file pointer to this location. */
+ fseek (last_open_file, pos2, SEEK_SET);
+ break;
+ }
+ }