aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2020-01-26 14:49:22 +0200
committerLasse Collin <lasse.collin@tukaani.org>2020-01-26 14:49:22 +0200
commit815035681063d5774d3640fc20b8ede783dd574e (patch)
tree041ef371a892d20564db9d3b6d662c8c98904c3b
parentxz: Fix semi-busy-waiting in xz --flush-timeout. (diff)
downloadxz-815035681063d5774d3640fc20b8ede783dd574e.tar.xz
xz: coder.c: Make writing output a separate function.
The same code sequence repeats so it's nicer as a separate function. Note that in one case there was no test for opt_mode != MODE_TEST, but that was only because that condition would always be true, so this commit doesn't change the behavior there.
Diffstat (limited to '')
-rw-r--r--src/xz/coder.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/xz/coder.c b/src/xz/coder.c
index 3f561851..96f8e734 100644
--- a/src/xz/coder.c
+++ b/src/xz/coder.c
@@ -612,6 +612,20 @@ split_block(uint64_t *block_remaining,
}
+static bool
+coder_write_output(file_pair *pair)
+{
+ if (opt_mode != MODE_TEST) {
+ if (io_write(pair, &out_buf, IO_BUFFER_SIZE - strm.avail_out))
+ return true;
+ }
+
+ strm.next_out = out_buf.u8;
+ strm.avail_out = IO_BUFFER_SIZE;
+ return false;
+}
+
+
/// Compress or decompress using liblzma.
static bool
coder_normal(file_pair *pair)
@@ -706,12 +720,8 @@ coder_normal(file_pair *pair)
// Write out if the output buffer became full.
if (strm.avail_out == 0) {
- if (opt_mode != MODE_TEST && io_write(pair, &out_buf,
- IO_BUFFER_SIZE - strm.avail_out))
+ if (coder_write_output(pair))
break;
-
- strm.next_out = out_buf.u8;
- strm.avail_out = IO_BUFFER_SIZE;
}
if (ret == LZMA_STREAM_END && (action == LZMA_SYNC_FLUSH
@@ -720,13 +730,9 @@ coder_normal(file_pair *pair)
// Flushing completed. Write the pending data
// out immediately so that the reading side
// can decompress everything compressed so far.
- if (io_write(pair, &out_buf, IO_BUFFER_SIZE
- - strm.avail_out))
+ if (coder_write_output(pair))
break;
- strm.next_out = out_buf.u8;
- strm.avail_out = IO_BUFFER_SIZE;
-
// Set the time of the most recent flushing.
mytime_set_flush_time();
@@ -762,9 +768,7 @@ coder_normal(file_pair *pair)
// as much data as possible, which can be good
// when trying to get at least some useful
// data out of damaged files.
- if (opt_mode != MODE_TEST && io_write(pair,
- &out_buf, IO_BUFFER_SIZE
- - strm.avail_out))
+ if (coder_write_output(pair))
break;
}