From 135579590865c4a8eaaede4719b9329d4c7311f1 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 10 Nov 2010 13:44:10 +0000 Subject: [PATCH] Fix not reporting an error message when saving a document fails. Check result of fclose(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5391 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/document.c | 27 +++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90edeff3..c32bce98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ Use LF line endings for templates internally instead of default pref because the default can change. This fixes missing line endings sometimes when changing default setting. + * src/document.c: + Fix not reporting an error message when saving a document fails. + Check result of fclose(). 2010-11-09 Nick Treleaven diff --git a/src/document.c b/src/document.c index 0c986b39..f04b6810 100644 --- a/src/document.c +++ b/src/document.c @@ -1725,24 +1725,31 @@ static gchar *write_data_to_disk(const gchar *locale_filename, G_FILE_CREATE_NONE, NULL, NULL, &error); g_object_unref(fp); #else - gint err = 0; FILE *fp; gint bytes_written; + gboolean fail = FALSE; /* Use POSIX API for unsafe saving (GVFS-unsafe) */ fp = g_fopen(locale_filename, "wb"); - if (G_UNLIKELY(fp == NULL)) - return g_strdup(g_strerror(errno)); + if (fp == NULL) + fail = TRUE; + else + { + 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) + if (fclose(fp) != 0) + fail = TRUE; + } + if (fail) + { + gint err = errno; + if (!err) + err = EIO; return g_strdup(g_strerror(err)); + } #endif } else