Kaydet (Commit) cba09d5e authored tarafından Nick Treleaven's avatar Nick Treleaven

Check result of fclose() for utils_write_file().


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5453 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 58cc67a8
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:
......
......@@ -246,30 +246,35 @@ gint utils_write_file(const gchar *filename, const gchar *text)
{
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment