]> granicus.if.org Git - recode/commitdiff
Do all I/O as binary
authorReuben Thomas <rrt@sc3d.org>
Tue, 30 Jan 2018 00:27:38 +0000 (00:27 +0000)
committerReuben Thomas <rrt@sc3d.org>
Tue, 30 Jan 2018 02:10:25 +0000 (02:10 +0000)
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
src/mixed.c
src/task.c

index ba8d64e701b806fa6659a2cd13076d33b9498272..12c2b1b0dacd5420c1fce528c93ffda0c27e28da 100644 (file)
@@ -30,6 +30,7 @@
 #include <locale.h>
 
 #include "getopt.h"
+#include "xbinary-io.h"
 \f
 /* 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);
 
index 01869e5c41e0d93311af8cbcfddc0c40dd802b60..3340531bd45addf6dab52ce1bfadab7cec610c44 100644 (file)
@@ -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);
index 57a54a9b66c79bac38ab74613725412a3bb943c9..fe0493b6f4c15c2b171b58bb35985e177c5c349d 100644 (file)
@@ -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);