GNOME Bugzilla – Bug 725514
W32: gfileutils does not preserve errno correctly
Last modified: 2017-10-05 13:01:54 UTC
g_fopen() sets errno, but then the caller from gfileutils invokes set_file_error with a _("") gettexted argument, which calls glib gettext, which resets errno to zero. Instead errno should be passed as an argument to set_file_error() and format_error_message(). It also must go _after_ format message, because "errno" expands into a function call on W32, and arguments are evaluated from right to left. With this fixed, the glib/tests/fileutils passes again.
Created attachment 270714 [details] [review] Save errno and pass it along to make sure gettext does not change it
Review of attachment 270714 [details] [review]: ::: glib/gfileutils.c @@ +863,3 @@ filename, + _("Failed to open file '%s': %s"), + errno); This is insufficient. The compiler is free to evaluate the arguments in whichever order it wants. You should have a separate gint saved_errno = errno; above the function call and pass the saved_errno variable in.
Created attachment 274825 [details] [review] Save errno and pass it along to make sure gettext does not change it v2: put errno into its own stack variable and use that, as suggested
Review of attachment 274825 [details] [review]: Anyway this now looks good to me. go ahead
Attachment 274825 [details] pushed as 6680ff1 - Save errno and pass it along to make sure gettext does not change it
*** Bug 731305 has been marked as a duplicate of this bug. ***