https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64064
Bug ID: 64064 Summary: basic_filebuf seekoff return value is unusable for files opened in text mode on Windows Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lukeallardyce at gmail dot com Discussion here https://gcc.gnu.org/ml/libstdc++/2014-11/msg00145.html #include <fstream> #include <iostream> int main(int, char* argv[]) { using traits = std::filebuf::traits_type; using int_type = std::filebuf::int_type; std::filebuf fb; fb.open(argv[1], std::ios::in); while (!traits::eq_int_type(fb.sbumpc(), traits::eof())) std::cout << fb.pubseekoff(0, std::ios::cur, std::ios::in) << ' '; std::cout << '\n'; fb.close(); fb.pubsetbuf(nullptr, 0); fb.open(argv[1], std::ios::in); while (!traits::eq_int_type(fb.sbumpc(), traits::eof())) std::cout << fb.pubseekoff(0, std::ios::cur, std::ios::in) << ' '; } With the following 3-line Windows-style text file: hello world Produces the following: 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 7 8 9 10 11 12 14 16 On a buffered stream, the value returned by pubseekoff cannot be used to seek back to that point due to the way Windows implements the POSIX read and lseek64 functions (i.e. read performs end of line conversion, lseek64 doesn't). The value is off by one for each unconsumed end of line in the buffer. It is still unclear whether this should be fixed, if possible, by libstdc++ or mingw-w64.