Module Name: src
Committed By: christos
Date: Sun Jun 19 01:52:28 UTC 2011
Modified Files:
src/usr.bin/gzip: unxz.c
Log Message:
- remove unused call
- read headers separately
- print error id.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/gzip/unxz.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.1 src/usr.bin/gzip/unxz.c:1.2
--- src/usr.bin/gzip/unxz.c:1.1 Sat Jun 18 20:43:54 2011
+++ src/usr.bin/gzip/unxz.c Sat Jun 18 21:52:28 2011
@@ -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);
}
}
}