From 628ad1b2866aa9c2c83f721bb594d12332e17358 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Tue, 30 Jan 2018 00:27:38 +0000 Subject: [PATCH] Do all I/O as binary This is necessary for Windows. I'm not sure why it wasn't done before; without it, Windows simply won't work correctly, without an extra layer of checking the platform encoding. --- src/main.c | 2 ++ src/mixed.c | 4 ++-- src/task.c | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index ba8d64e..12c2b1b 100644 --- a/src/main.c +++ b/src/main.c @@ -30,6 +30,7 @@ #include #include "getopt.h" +#include "xbinary-io.h" /* Variables. */ @@ -833,6 +834,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), if (asprintf (&output_name, "%s/recode-XXXXXX.tmp", output_dir) == -1) error (EXIT_FAILURE, errno, "asprintf"); int fd = mkstemps (output_name, 4); + xset_binary_mode (fd, O_BINARY); if (fd == -1) error (EXIT_FAILURE, errno, "mkstemps (%s)", output_name); diff --git a/src/mixed.c b/src/mixed.c index 01869e5..3340531 100644 --- a/src/mixed.c +++ b/src/mixed.c @@ -47,7 +47,7 @@ open_mixed (struct mixed *mixed, RECODE_TASK task) if (!*(task->input.name)) task->input.file = stdin; - else if (task->input.file = fopen (mixed->input_name, "r"), + else if (task->input.file = fopen (mixed->input_name, "rb"), !task->input.file) { recode_perror (NULL, "fopen (%s)", task->input.name); @@ -57,7 +57,7 @@ open_mixed (struct mixed *mixed, RECODE_TASK task) if (!*(task->output.name)) task->output.file = stdout; - else if (task->output.file = fopen (mixed->output_name, "w"), + else if (task->output.file = fopen (mixed->output_name, "wb"), !task->output.file) { recode_perror (NULL, "fopen (%s)", task->output.name); diff --git a/src/task.c b/src/task.c index 57a54a9..fe0493b 100644 --- a/src/task.c +++ b/src/task.c @@ -246,7 +246,7 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy) { if (!*subtask->input.name) subtask->input.file = stdin; - else if (subtask->input.file = fopen (subtask->input.name, "r"), + else if (subtask->input.file = fopen (subtask->input.name, "rb"), subtask->input.file == NULL) { recode_perror (NULL, "fopen (%s)", subtask->input.name); @@ -313,7 +313,7 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy) recode_perror (NULL, "close ()"); recode_if_nogo (RECODE_SYSTEM_ERROR, subtask); } - if (subtask->output.file = fdopen (pipe_pair[1], "w"), + if (subtask->output.file = fdopen (pipe_pair[1], "wb"), subtask->output.file == NULL) { recode_perror (NULL, "fdopen ()"); @@ -357,7 +357,7 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy) { if (!*subtask->output.name) subtask->output.file = stdout; - else if (subtask->output.file = fopen (subtask->output.name, "w"), + else if (subtask->output.file = fopen (subtask->output.name, "wb"), subtask->output.file == NULL) { recode_perror (NULL, "fopen (%s)", subtask->output.name); -- 2.50.0