bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] [PATCH 2/2] tar: set stdin/stdout to binary mode correctly wit


From: KO Myung-Hun
Subject: [Bug-tar] [PATCH 2/2] tar: set stdin/stdout to binary mode correctly with binary-io
Date: Fri, 29 May 2015 14:25:22 +0900

* gnulib.modules: Add binary-io.
* src/buffer.c (_open_archive): Ensure that stdin is binary mode
before check_compressed_archive(). Set stdout to binary mode if
writing archives to stdout.
* src/common.h: Include binary-io.h
* src/extract.c (extract_file): Set stdout to binary mode if
writing to stdout.
* src/misc.c (xpipe): Set pipes to binary mode
* src/system.c (sys_child_open_for_compress): Set stdout to binary
mode.
(sys_child_open_for_uncompress): Set stdin to binary mode.
---
 gnulib.modules |  1 +
 src/buffer.c   |  6 ++++--
 src/common.h   |  1 +
 src/extract.c  |  5 ++++-
 src/misc.c     |  3 +++
 src/system.c   | 10 ++++++++--
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gnulib.modules b/gnulib.modules
index 0d2e76c..889a0f0 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -24,6 +24,7 @@ argmatch
 argp
 argp-version-etc
 backupfile
+binary-io
 closeout
 configmake
 dirname
diff --git a/src/buffer.c b/src/buffer.c
index 1a96595..85dbe27 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -751,6 +751,7 @@ _open_archive (enum access_mode wanted_access)
             enum compress_type type;
 
             archive = STDIN_FILENO;
+            SET_BINARY (archive);
             type = check_compressed_archive (&shortfile);
             if (type != ct_tar && type != ct_none)
               FATAL_ERROR ((0, 0,
@@ -770,6 +771,7 @@ _open_archive (enum access_mode wanted_access)
         case ACCESS_UPDATE:
           archive = STDIN_FILENO;
           write_archive_to_stdout = true;
+          SET_BINARY (STDOUT_FILENO);
           record_end = record_start; /* set up for 1st record = # 0 */
           if (!index_file_name)
             stdlis = stderr;
@@ -830,7 +832,7 @@ _open_archive (enum access_mode wanted_access)
 
   sys_detect_dev_null_output ();
   sys_save_archive_dev_ino ();
-  SET_BINARY_MODE (archive);
+  SET_BINARY (archive);
 
   switch (wanted_access)
     {
@@ -1356,7 +1358,7 @@ new_volume (enum access_mode mode)
       goto tryagain;
     }
 
-  SET_BINARY_MODE (archive);
+  SET_BINARY (archive);
 
   return true;
 }
diff --git a/src/common.h b/src/common.h
index 2904183..431dac8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -51,6 +51,7 @@
 
 #include "arith.h"
 #include <backupfile.h>
+#include <binary-io.h>
 #include <exclude.h>
 #include <full-write.h>
 #include <modechange.h>
diff --git a/src/extract.c b/src/extract.c
index 5aaeb1b..6cb6d1a 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -1104,7 +1104,10 @@ extract_file (char *file_name, int typeflag)
   mode_t current_mode_mask = 0;
 
   if (to_stdout_option)
-    fd = STDOUT_FILENO;
+    {
+      fd = STDOUT_FILENO;
+      SET_BINARY (fd);
+    }
   else if (to_command_option)
     {
       fd = sys_exec_command (file_name, 'f', &current_stat_info);
diff --git a/src/misc.c b/src/misc.c
index d263c07..f880205 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1134,6 +1134,9 @@ xpipe (int fd[2])
 {
   if (pipe (fd) < 0)
     call_arg_fatal ("pipe", _("interprocess channel"));
+
+  SET_BINARY (fd[0]);
+  SET_BINARY (fd[1]);
 }
 
 /* Return PTR, aligned upward to the next multiple of ALIGNMENT.
diff --git a/src/system.c b/src/system.c
index 9414233..402fa7a 100644
--- a/src/system.c
+++ b/src/system.c
@@ -405,7 +405,10 @@ sys_child_open_for_compress (void)
   xclose (child_pipe[PWRITE]);
 
   if (strcmp (archive_name_array[0], "-") == 0)
-    archive = STDOUT_FILENO;
+    {
+      archive = STDOUT_FILENO;
+      SET_BINARY (archive);
+    }
   else
     {
       archive = rmtcreat (archive_name_array[0], MODE_RW, rsh_command_option);
@@ -575,7 +578,10 @@ sys_child_open_for_uncompress (void)
   xclose (child_pipe[PREAD]);
 
   if (strcmp (archive_name_array[0], "-") == 0)
-    archive = STDIN_FILENO;
+    {
+      archive = STDIN_FILENO;
+      SET_BINARY (archive);
+    }
   else
     archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
                       MODE_RW, rsh_command_option);
-- 
1.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]