Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/gzip - remove unused call
details: https://anonhg.NetBSD.org/src/rev/dd64ae45ee05
branches: trunk
changeset: 766220:dd64ae45ee05
user: christos <christos%NetBSD.org@localhost>
date: Sun Jun 19 01:52:28 2011 +0000
description:
- remove unused call
- read headers separately
- print error id.
diffstat:
usr.bin/gzip/unxz.c | 29 ++++++++++++-----------------
1 files changed, 12 insertions(+), 17 deletions(-)
diffs (63 lines):
diff -r d3f9f16cc73c -r dd64ae45ee05 usr.bin/gzip/unxz.c
--- a/usr.bin/gzip/unxz.c Sun Jun 19 01:25:35 2011 +0000
+++ b/usr.bin/gzip/unxz.c Sun Jun 19 01:52:28 2011 +0000
@@ -9,33 +9,29 @@
unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in)
{
lzma_stream strm = LZMA_STREAM_INIT;
+ static const int flags = LZMA_TELL_UNSUPPORTED_CHECK|LZMA_CONCATENATED;
lzma_ret ret;
off_t x = 0;
-
- // Initialize the decoder
- ret = lzma_alone_decoder(&strm, UINT64_MAX);
- if (ret != LZMA_OK) {
- errno = ret == LZMA_MEM_ERROR ? ENOMEM : EINVAL;
- maybe_errx("Cannot initialize decoder");
- }
-
- // Input and output buffers
uint8_t ibuf[BUFSIZ];
uint8_t obuf[BUFSIZ];
- *bytes_in = prelen;
strm.next_in = ibuf;
+ memcpy(ibuf, pre, prelen);
strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
if (strm.avail_in == (size_t)-1)
maybe_errx("Read failed");
+ *bytes_in = prelen + strm.avail_in;
- memcpy(ibuf, pre, prelen);
- *bytes_in += strm.avail_in;
+ if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
+ maybe_errx("Can't initialize decoder (%d)", ret);
+
+ strm.next_out = NULL;
+ strm.avail_out = 0;
+ if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
+ maybe_errx("Can't read headers (%d)", ret);
strm.next_out = obuf;
strm.avail_out = sizeof(obuf);
- if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, 0)) != LZMA_OK)
- maybe_errx("Can't initialize decoder");
for (;;) {
if (strm.avail_in == 0) {
@@ -101,13 +97,12 @@
msg = "Reached memory limit";
break;
-
default:
- msg = "Internal error (bug)";
+ msg = "Unknown error (%d)";
break;
}
- maybe_errx("%s", msg);
+ maybe_errx(msg, ret);
}
}
}
Home |
Main Index |
Thread Index |
Old Index