From a55835a7adf8fcfc7a3906a223061e27d4c3bc38 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Tue, 23 Jan 2018 10:02:43 +0000 Subject: Fix failure of non-incremental document saving. An earlier commit changed the mode used to open a file for saving so that it could also be read from. The mode used was rb+ independently of whether the saving mode was incremental or not. Doing so neglected that for non-incemental saves the file may not already exist in which case opening rb+ will fail. This commit arranges that wb+ is used in the non-incremental case. --- source/fitz/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/fitz/output.c b/source/fitz/output.c index 18791603..a8301a1e 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -205,7 +205,7 @@ fz_new_output_with_path(fz_context *ctx, const char *filename, int append) if (errno != ENOENT) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot remove file '%s': %s", filename, strerror(errno)); } - file = fz_fopen_utf8(filename, "rb+"); + file = fz_fopen_utf8(filename, append ? "rb+" : "wb+"); #else /* Ensure we create a brand new file. We don't want to clobber our old file. */ if (!append) @@ -214,7 +214,7 @@ fz_new_output_with_path(fz_context *ctx, const char *filename, int append) if (errno != ENOENT) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot remove file '%s': %s", filename, strerror(errno)); } - file = fopen(filename, "rb+"); + file = fopen(filename, append ? "rb+" : "wb+"); #endif if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); -- cgit v1.2.3