[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: |
Sat, 7 Oct 2017 18:38:53 +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 f190387..de99c23 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 6f96c2f..ceb17e7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -764,6 +764,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,
@@ -783,6 +784,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;
@@ -843,7 +845,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)
{
@@ -1396,7 +1398,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 99a1dd8..e363971 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 6f5ba08..e744159 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -1136,7 +1136,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', ¤t_stat_info);
diff --git a/src/misc.c b/src/misc.c
index 632de29..e1d8b97 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1129,6 +1129,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 b4f6985..db4b4d0 100644
--- a/src/system.c
+++ b/src/system.c
@@ -408,7 +408,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);
@@ -578,7 +581,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);
--
2.13.3