1 --- a/src/convert_recode.c
2 +++ b/src/convert_recode.c
3 @@ -101,7 +101,8 @@ convert_recode(File *file,
7 - if ((tempfile = file_temporary(file->buffer, 1)) == NULL
8 + /* We do not unlink tempfile, because we want to reopen it later */
9 + if ((tempfile = file_temporary(file->buffer, 0)) == NULL
10 || file_seek(file, 0, SEEK_SET) != 0) {
13 @@ -112,9 +113,20 @@ convert_recode(File *file,
14 task->fail_level = enca_recode_fail_level;
15 task->abort_level = RECODE_SYSTEM_ERROR;
16 task->input.name = NULL;
17 - task->input.file = file->stream;
18 task->output.name = NULL;
19 - task->output.file = tempfile->stream;
20 + /* recode_perform_task closes given streams, so we need to duplicate them */
21 + task->input.file = fopen(file->name, "rb");
22 + if (task->input.file == NULL) {
23 + fprintf(stderr, "failed to reopen `%s'\n", file->name);
24 + file_free(tempfile);
27 + task->output.file = fopen(tempfile->name, "wb");
28 + if (task->input.file == NULL) {
29 + fprintf(stderr, "failed to reopen `%s'\n", tempfile->name);
30 + file_free(tempfile);
34 /* Now run conversion original -> temporary file. */
35 success = recode_perform_task(task);