3 | | I got tst-fseek.c from the latest glibc. After disabling all the stats-related tests (stat64 stuff missing), one fread test fails. Without my patch, four fseek tests also fail. |
| 3 | Yes, I was wrong about why it worked. I think I've figured it out now. |
| 4 | |
| 5 | The main read area starts at _IO_buf_base (see _IO_switch_to_get_mode). The put-back read area actually exists elsewhere in memory and isn't contiguous with the main read area. When the two areas are switched between, _IO_read_base is moved. After an ungetc(), _IO_read_base points to the put-back area, so any subsequent call to fseek() seeks in there, which it shouldn't. |
| 6 | |
| 7 | Given that fseek() should ignore put-back characters, it makes sense to seek relative to the position of the normal read buffer, which is _IO_buf_base. |