summaryrefslogtreecommitdiff
path: root/src/journal/compress.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 21:23:53 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 22:10:54 -0400
commita6dcc7e5924f9c27d3e9c6560a448b02ec28b65f (patch)
tree694aa3c7b5b2f4e61fb8c25d5bd8d1f023cf511e /src/journal/compress.c
parentad7bcf526d5ec54838bc9411a0e09a293845a015 (diff)
Introduce loop_read_exact helper
Usually when using loop_read(), we want to read the full buffer. Add a helper that mirrors loop_write(), and returns 0 when full buffer was read, and an error otherwise. Use -ENODATA for the short read, to distinguish it from a read error.
Diffstat (limited to 'src/journal/compress.c')
-rw-r--r--src/journal/compress.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/journal/compress.c b/src/journal/compress.c
index 4232206f44..383f6a6e96 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -589,14 +589,12 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
return log_oom();
for (;;) {
- ssize_t n, m;
+ ssize_t m;
int r;
- n = read(fdf, &header, sizeof(header));
- if (n < 0)
- return -errno;
- if (n != sizeof(header))
- return errno ? -errno : -EIO;
+ r = loop_read_exact(fdf, &header, sizeof(header), false);
+ if (r < 0)
+ return r;
m = le32toh(header);
if (m == 0)
@@ -618,12 +616,9 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
if (!GREEDY_REALLOC(buf, buf_size, m))
return log_oom();
- errno = 0;
- n = loop_read(fdf, buf, m, false);
- if (n < 0)
- return n;
- if (n != m)
- return errno ? -errno : -EIO;
+ r = loop_read_exact(fdf, buf, m, false);
+ if (r < 0)
+ return r;
r = LZ4_decompress_safe_continue(&lz4_data, buf, out, m, 4*LZ4_BUFSIZE);
if (r <= 0)
@@ -636,9 +631,9 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
return -EFBIG;
}
- n = loop_write(fdt, out, r, false);
- if (n < 0)
- return n;
+ r = loop_write(fdt, out, r, false);
+ if (r < 0)
+ return r;
}
log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)",