archrelease: copy trunk to extra-x86_64
[arch-packages.git] / enca / trunk / enca-bad-file-descriptor.patch
blob2f6ad911bede2ec6c0bbddab936b55627e71480b
1 --- a/src/convert_recode.c
2 +++ b/src/convert_recode.c
3 @@ -101,7 +101,8 @@ convert_recode(File *file,
4 return ERR_IOFAIL;
5 file->buffer->pos = 0;
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) {
11 file_free(tempfile);
12 return ERR_IOFAIL;
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);
25 + return ERR_IOFAIL;
26 + }
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);
31 + return ERR_IOFAIL;
32 + }
34 /* Now run conversion original -> temporary file. */
35 success = recode_perform_task(task);