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

Nick Treleaven nick.treleaven at xxxxx
Wed Nov 10 13:25:56 UTC 2010

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.


      errno = 0;

      n_written = fwrite (contents, 1, length, file);

      if (n_written < length)
	  save_errno = errno;
 	  g_set_error (err,
		       g_file_error_from_errno (save_errno),
		       _("Failed to write file '%s': fwrite() failed: %
s"), display_name,
		       g_strerror (save_errno));

	  fclose (file);

Although this is better than Geany because at least the error is
reported even if errno is not set.

> > > But since we don't write the file line-by-line or
> > > something, _why_ do we use buffered I/O in the first place?..
> > 
> > I don't know. But changing implementation often introduces bugs, so
> > I'm reluctant to do so (besides fixing fclose failure).
> Well the current implementation is not exactly bug-free. :)

OK, so we do need a fix so that failed writing is reported to the user,
can't rely on errno.


More information about the Devel mailing list