Robert Kausch
2013-May-05 23:26 UTC
[flac-dev] Bug fix and compatibility patches for 1.3.0pre4
Timothy B. Terriberry wrote:> Instead I've attached a patch that uses fgetpos/fsetpos. This is > totally untested (I haven't even checked it compiles), but the idea > should work.MSDN says "The pos value is stored in an internal format and is intended for use only by *fgetpos* and *fsetpos*." (http://msdn.microsoft.com/en-us/library/70hdhh4t%28v=vs.80%29.aspx), so I don't think it's a good idea to use it this way even if tests suggested it works. I'll write a test program tomorrow to try the fflush+_lseeki64 approach. Another solution - although a bit ugly - might be to disable buffering on Windows using setvbuf.
Timothy B. Terriberry
2013-May-05 23:34 UTC
[flac-dev] Bug fix and compatibility patches for 1.3.0pre4
Robert Kausch wrote:> MSDN says "The pos value is stored in an internal format and is intended > for use only by *fgetpos* and *fsetpos*." > (http://msdn.microsoft.com/en-us/library/70hdhh4t%28v=vs.80%29.aspx), so > I don't think it's a good idea to use it this way even if tests > suggested it works.FWIW, I verified that this is the approach used by mingw32 to implement fseeko/ftello.
Robert Kausch
2013-May-06 23:28 UTC
[flac-dev] Bug fix and compatibility patches for 1.3.0pre4
Timothy B. Terriberry wrote:>> "The pos value is stored in an internal format and is intended >> for use only by *fgetpos* and *fsetpos*." > FWIW, I verified that this is the approach used by mingw32 to implement > fseeko/ftello. >Yes, they do - I also had a look at the libmingwex source. But still, with that sentence Microsoft basically reserves the right to change the behaviour of fgetpos/fsetpos at any time without notice... I wrote a small test program in the meantime and verified that fgetpos/fsetpos indeed work, even back to Windows 98. _lseeki64 on the other hand totally messes up with buffered streams and cannot be used here. Calling fflush beforehand doesn't help and even fflush alone breaks the stream (i.e. with 4kB buffers, fopen()->fread()->fflush()->fread() will start at byte #4096 with the second read, so don't use fflush for reading). However, as Janne already pointed out, libFLAC is statically linked by default, so there's no real problem with _fseeki64/_ftelli64 indeed. I'll still have to decide whether to link statically or use your fgetpos/fsetpos patch for my build, but no need to change anything in the official FLAC code. In any case, please disregard my _lseeki64 patch.