Skip to content

glib: Win32 does not accept "wb+" mode for fopen().

Jehan requested to merge Jehan/glib:wip/Jehan/fopen-modes into master

Nevertheless it accepts "w+b". When checking the Win32 documentation of fopen()/_wfopen(), it clearly states:

In addition to the earlier values, the following characters can be appended to mode to specify the translation mode for newline characters.

This implementation expects 'b' or 't' to be appended, and therefore "wb+" ends up with an error, whereas the alias "w+b" works perfectly while it is exactly the same thing. So let's just have glib "translate" the mode when it can to have it working transparently the same way on every platform.

Additional note: this is at least the second time we have such a bug in GIMP for Windows because we opened a file with "wb+" not thinking twice. These are meant to be aliases but Windows only accepts the "w+b" variant. So glib abstraction is not perfect since we are forced to care about the underlining implementation. Well sometimes, there are no other choices, but clearly here there is one, and glib can try to be a bit more clever. Hence this patch. :-)

Merge request reports