When reading and writing the same file, you must seek on Windows...

John Arbash Meinel john at arbash-meinel.com
Tue Mar 13 23:07:19 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ugh... I just found a nice crappy behavior from the Windows MSDN.

It seems that when you open a file in something like "rb+" mode, you
*are* able to read and write to it, but you must flush or seek on the
file when switching between reading and writing.

I found this out at link:
http://msdn2.microsoft.com/en-us/library/yeby3zcb(vs.71).aspx

To Quote:


When the "r+", "w+", or "a+" access type is specified, both reading and
writing are allowed (the file is said to be open for "update"). However,
when you switch between reading and writing, there must be an
intervening fflush, fsetpos, fseek, or rewind operation. The current
position can be specified for the fsetpos or fseek operation, if desired.


I found a link that python used to just silently fail. Now it just
raises IOError, with an errno == 0. Not the most helpful, but I guess it
at least is raise *an* error.

Anyway, I'm not sure how to handle this exactly, other than to look
through the code, and makes sure that we call fseek() whenever we are
about to write to the file, and maybe when we are about to read the file.

Anyway, chalk one more into the "Win32 is on crack" column.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9y6nJdeBCYSNAAMRAt3mAJ9oh0NUGD1U+/+B2FBykE04UURnVwCfeVuO
xN5Uwl/9gf9jrjZOyd5WjsQ=
=v1wA
-----END PGP SIGNATURE-----



More information about the bazaar mailing list