[Geany-devel] Changed file saving implementation for systems with GIO

Dimitar Zhekov dimitar.zhekov at xxxxx
Wed Nov 10 18:02:53 UTC 2010


On Wed, 10 Nov 2010 13:25:56 +0000
Nick Treleaven <nick.treleaven at btinternet.com> wrote:

> On Tue, 9 Nov 2010 21:27:07 +0200
> Dimitar Zhekov <dimitar.zhekov at gmail.com> wrote:
> 
> > > > Well, g_file_set_contents() uses buffered I/O, so obviously it's
> > > > acceptable too.
> > > 
> > > Yes, it uses fwrite and then errno.
> > 
> > Probably fwrite(), fflush() and then errno?
> > fflush() is guaranteed to set errno AFAIK.
> 
> No:
> 
>       errno = 0;
> 
>       n_written = fwrite (contents, 1, length, file);
> 
>       if (n_written < length)
> 	{
> 	  save_errno = errno;
>       
>  	  g_set_error (err,
> 		       G_FILE_ERROR,
> 		       g_file_error_from_errno (save_errno),
> 		       _("Failed to write file '%s': fwrite() failed: %
> s"), display_name,
> 		       g_strerror (save_errno));
> 
> 	  fclose (file);

Ah, it sets errno = 0 first, assuming that fwrite() may fail to do so.

> I've now committed a fix so that any write failure should be reported
> to the user even if errno is 0. Please test.

It won't be 0 unless you assign it. A successful library call does not
clear errno.

Why fake 0 errno as EIO? g_file_set_contents() doesn't, and *strerror()
returns something for 0, usually "Error 0".

> fclose check is fixed now too.

If fwrite() and fclose() both fail, I'd prefer to see the errno of
fwrite(), even if 0 (g_file_set_contents() does that). Hmmm, it'll be
nice to display the filename as UTF-8 too, plus the name of the failed
function, and we have a GError ready...

Mind if I try to improve the error handling, using gfileutils.c as a
source? There will be 3 new translation strings.

-- 
E-gards: Jimmy



More information about the Devel mailing list