After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 725514 - W32: gfileutils does not preserve errno correctly
W32: gfileutils does not preserve errno correctly
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: win32
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-win32 maintainers
: 731305 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-03-02 19:15 UTC by LRN
Modified: 2017-10-05 13:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Save errno and pass it along to make sure gettext does not change it (5.52 KB, patch)
2014-03-02 19:15 UTC, LRN
needs-work Details | Review
Save errno and pass it along to make sure gettext does not change it (6.36 KB, patch)
2014-04-21 17:32 UTC, LRN
committed Details | Review

Description LRN 2014-03-02 19:15:02 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.
Comment 1 LRN 2014-03-02 19:15:06 UTC
Created attachment 270714 [details] [review]
Save errno and pass it along to make sure gettext does not change it
Comment 2 Allison Karlitskaya (desrt) 2014-04-21 13:30:02 UTC
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.
Comment 3 LRN 2014-04-21 17:32:02 UTC
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
Comment 4 Paolo Borelli 2014-08-02 08:34:43 UTC
Review of attachment 274825 [details] [review]:

Anyway this now looks good to me. go ahead
Comment 5 LRN 2014-08-02 11:00:21 UTC
Attachment 274825 [details] pushed as 6680ff1 - Save errno and pass it along to make sure gettext does not change it
Comment 6 Philip Withnall 2017-10-05 13:01:54 UTC
*** Bug 731305 has been marked as a duplicate of this bug. ***