Revision: 5449 http://geany.svn.sourceforge.net/geany/?rev=5449&view=rev Author: ntrel Date: 2010-11-29 17:52:38 +0000 (Mon, 29 Nov 2010)
Log Message: ----------- Fix not always reporting an error message when saving a document fails. Check result of fclose(). Set errno to 0 before doing disk I/O.
Modified Paths: -------------- branches/Geany-0_19_2/ChangeLog branches/Geany-0_19_2/src/document.c
Modified: branches/Geany-0_19_2/ChangeLog =================================================================== --- branches/Geany-0_19_2/ChangeLog 2010-11-29 13:21:35 UTC (rev 5448) +++ branches/Geany-0_19_2/ChangeLog 2010-11-29 17:52:38 UTC (rev 5449) @@ -1,3 +1,12 @@ +2010-11-29 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/document.c: + Fix not always reporting an error message when saving a document + fails. + Check result of fclose(). + Set errno to 0 before doing disk I/O. + + 2010-08-16 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* scintilla/LexMarkdown.cxx:
Modified: branches/Geany-0_19_2/src/document.c =================================================================== --- branches/Geany-0_19_2/src/document.c 2010-11-29 13:21:35 UTC (rev 5448) +++ branches/Geany-0_19_2/src/document.c 2010-11-29 17:52:38 UTC (rev 5449) @@ -1690,9 +1690,6 @@ static gchar *write_data_to_disk(GeanyDocument *doc, const gchar *locale_filename, const gchar *data, gint len) { - FILE *fp; - gint bytes_written; - gint err = 0; GError *error = NULL;
g_return_val_if_fail(doc != NULL, g_strdup(g_strerror(EINVAL))); @@ -1700,19 +1697,30 @@
if (! file_prefs.use_safe_file_saving) { + FILE *fp; + gint bytes_written; + gboolean fail = FALSE; + + /* Use POSIX API to preserve file metadata */ + errno = 0; fp = g_fopen(locale_filename, "wb"); - if (G_UNLIKELY(fp == NULL)) - return g_strdup(g_strerror(errno)); + if (fp == NULL) + fail = TRUE; + else + { + errno = 0; + bytes_written = fwrite(data, sizeof(gchar), len, fp);
- bytes_written = fwrite(data, sizeof(gchar), len, fp); + if (len != bytes_written) + fail = TRUE;
- if (G_UNLIKELY(len != bytes_written)) - err = errno; - - fclose(fp); - - if (err != 0) - return g_strdup(g_strerror(err)); + if (fclose(fp) != 0) + fail = TRUE; + } + if (fail) + { + return g_strdup(g_strerror(errno)); + } } else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.