From 4e62da8abc36e1d0cc689d5e423d436d5e158384 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 27 Apr 2016 07:13:52 +0300 Subject: [PATCH] Updated script [#METR-21075]. --- utils/compressor/zstd_test.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/utils/compressor/zstd_test.cpp b/utils/compressor/zstd_test.cpp index 2085f48d249..e3c9c847323 100644 --- a/utils/compressor/zstd_test.cpp +++ b/utils/compressor/zstd_test.cpp @@ -12,11 +12,18 @@ int main(int argc, char ** argv) std::vector src_buf(size); std::vector dst_buf; - ssize_t read_res = read(STDIN_FILENO, &src_buf[0], size); - if (read_res <= 0) - throw std::runtime_error("Cannot read from stdin"); + size_t pos = 0; + while (true) + { + ssize_t read_res = read(STDIN_FILENO, &src_buf[pos], size - pos); + if (read_res < 0) + throw std::runtime_error("Cannot read from stdin"); + if (read_res == 0) + break; + pos += read_res; + } - src_buf.resize(read_res); + src_buf.resize(pos); size_t zstd_res; @@ -47,9 +54,14 @@ int main(int argc, char ** argv) dst_buf.resize(zstd_res); - ssize_t write_res = write(STDOUT_FILENO, &dst_buf[0], dst_buf.size()); - if (write_res != static_cast(dst_buf.size())) - throw std::runtime_error("Cannot write to stdout"); + pos = 0; + while (pos < dst_buf.size()) + { + ssize_t write_res = write(STDOUT_FILENO, &dst_buf[pos], dst_buf.size()); + if (write_res <= 0) + throw std::runtime_error("Cannot write to stdout"); + pos += write_res; + } return 0; }