On Wed, 10 Nov 2010 18:14:04 +0000
Nick Treleaven <[email protected]> wrote:
> On Wed, 10 Nov 2010 20:02:53 +0200
> Dimitar Zhekov <[email protected]> wrote:
>
> > Why fake 0 errno as EIO? g_file_set_contents() doesn't, and *strerror()
> > returns something for 0, usually "Error 0".
>
> GLib says to use g_strerror, which says 'Success', which is confusing.
It is, but "Input/output error" usually means a failed disk. (o_O)
POSIX says "Some physical input or output error has occurred."
> > Mind if I try to improve the error handling, using gfileutils.c as a
> > source? There will be 3 new translation strings.
>
> Sure, have a go.
Here. errno 0 still displays "Success" at the end of the messages, but
at least they start "Failed to"... Well, it's identical to glib,
including the paranoid resetting of errno before each call.
Tested with writing to /boza, full disk and a fake close error.
--
E-gards: Jimmy
--- ./src/document.c.orig 2010-11-10 20:42:32.000000000 +0200
+++ ./src/document.c 2010-11-10 21:02:12.000000000 +0200
@@ -1726,32 +1726,59 @@
g_object_unref(fp);
#else
FILE *fp;
- gint bytes_written;
- gboolean fail = FALSE;
+ int save_errno;
+ gchar *display_name = g_filename_display_name(locale_filename);
/* Use POSIX API for unsafe saving (GVFS-unsafe) */
+ /* The error handling is taken from glib-2.26.0 gfileutils.c */
errno = 0;
fp = g_fopen(locale_filename, "wb");
if (fp == NULL)
- fail = TRUE;
+ {
+ save_errno = errno;
+
+ g_set_error(&error,
+ G_FILE_ERROR,
+ g_file_error_from_errno(save_errno),
+ _("Failed to open file '%s' for writing: fopen() failed: %s"),
+ display_name,
+ g_strerror(save_errno));
+ }
else
{
+ gint bytes_written;
+
errno = 0;
bytes_written = fwrite(data, sizeof(gchar), len, fp);
if (len != bytes_written)
- fail = TRUE;
+ {
+ save_errno = errno;
- if (fclose(fp) != 0)
- fail = TRUE;
- }
- if (fail)
- {
- gint err = errno;
- if (!err)
- err = EIO;
- return g_strdup(g_strerror(err));
+ g_set_error(&error,
+ G_FILE_ERROR,
+ g_file_error_from_errno(save_errno),
+ _("Failed to write file '%s': fwrite() failed: %s"),
+ display_name,
+ g_strerror(save_errno));
+ }
+
+ errno = 0;
+ /* preserve the fwrite() error if any */
+ if (fclose(fp) != 0 && error == NULL)
+ {
+ save_errno = errno;
+
+ g_set_error(&error,
+ G_FILE_ERROR,
+ g_file_error_from_errno(save_errno),
+ _("Failed to close file '%s': fclose() failed: %s"),
+ display_name,
+ g_strerror(save_errno));
+ }
}
+
+ g_free(display_name);
#endif
}
else
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel