ref: 23fb0e7753804d86fff53f1bc1fbc3e286f60c7c
parent: f4bd45e7b967980782663f4eb27e5006528283d3
author: Simon Tatham <[email protected]>
date: Tue Nov 4 18:02:07 EST 2008
Check return values from fwrite when saving files. [originally from svn r8278]
--- a/gtk.c
+++ b/gtk.c
@@ -1328,10 +1328,16 @@
return fe->filesel_name;
}
+struct savefile_write_ctx {
+ FILE *fp;
+ int error;
+};
+
static void savefile_write(void *wctx, void *buf, int len)
{
- FILE *fp = (FILE *)wctx;
- fwrite(buf, 1, len, fp);
+ struct savefile_write_ctx *ctx = (struct savefile_write_ctx *)wctx;
+ if (fwrite(buf, 1, len, ctx->fp) < len)
+ ctx->error = 1;
}
static int savefile_read(void *wctx, void *buf, int len)
@@ -1373,9 +1379,18 @@
return;
}
- midend_serialise(fe->me, savefile_write, fp);
+ {
+ struct savefile_write_ctx ctx;
+ ctx.fp = fp;
+ ctx.error = 0;
+ midend_serialise(fe->me, savefile_write, &ctx);
+ fclose(fp);
+ if (ctx.error) {
+ error_box(fe->window, "Error writing save file");
+ return;
+ }
+ }
- fclose(fp);
}
}