Revision: 5453 http://geany.svn.sourceforge.net/geany/?rev=5453&view=rev Author: ntrel Date: 2010-11-30 18:18:24 +0000 (Tue, 30 Nov 2010)
Log Message: ----------- Check result of fclose() for utils_write_file().
Modified Paths: -------------- trunk/ChangeLog trunk/src/utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-11-30 18:12:15 UTC (rev 5452) +++ trunk/ChangeLog 2010-11-30 18:18:24 UTC (rev 5453) @@ -1,3 +1,9 @@ +2010-11-30 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/utils.c: + Check result of fclose() for utils_write_file(). + + 2010-11-28 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* win32-config.h:
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2010-11-30 18:12:15 UTC (rev 5452) +++ trunk/src/utils.c 2010-11-30 18:18:24 UTC (rev 5453) @@ -246,30 +246,35 @@ { FILE *fp; gint bytes_written, len; + gboolean fail = FALSE;
if (filename == NULL) return ENOENT;
len = strlen(text); + errno = 0; fp = g_fopen(filename, "w"); - if (fp != NULL) + if (fp == NULL) + fail = TRUE; + else { - bytes_written = fwrite(text, sizeof (gchar), len, fp); - fclose(fp); + bytes_written = fwrite(text, sizeof(gchar), len, fp);
if (len != bytes_written) { + fail = TRUE; geany_debug( "utils_write_file(): written only %d bytes, had to write %d bytes to %s", bytes_written, len, filename); - return EIO; } + if (fclose(fp) != 0) + fail = TRUE; } - else + if (fail) { geany_debug("utils_write_file(): could not write to file %s (%s)", filename, g_strerror(errno)); - return errno; + return NVL(errno, EIO); } } return 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.