aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/xzcat.c
diff options
context:
space:
mode:
authorIsaac Dunham <idunham@lavabit.com>2013-07-17 17:27:14 -0500
committerIsaac Dunham <idunham@lavabit.com>2013-07-17 17:27:14 -0500
commit39af4ae3e61d352c3faa7d1b87e6ac6fdb69add1 (patch)
tree9b46e4b3e6abea6d70ce00a756184abd79e33251 /toys/pending/xzcat.c
parent9641a3c6c5447c76f56cefd1844a4e545c015822 (diff)
downloadtoybox-39af4ae3e61d352c3faa7d1b87e6ac6fdb69add1.tar.gz
make xzcat use loopfiles(), thereby allowing regular usage.
Diffstat (limited to 'toys/pending/xzcat.c')
-rw-r--r--toys/pending/xzcat.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/toys/pending/xzcat.c b/toys/pending/xzcat.c
index 42d5ba37..a90a4a90 100644
--- a/toys/pending/xzcat.c
+++ b/toys/pending/xzcat.c
@@ -12,9 +12,9 @@ config XZCAT
bool "xzcat"
default n
help
- usage: xzcat < file.xz
+ usage: xzcat [filename...]
- Read xz-compressed file from stdin and write decompressed file to stdout.
+ Decompress listed files to stdout. Use stdin if no files listed.
*/
#define FOR_xzcat
@@ -224,7 +224,7 @@ static uint64_t xz_crc64_table[256];
static uint8_t in[BUFSIZ];
static uint8_t out[BUFSIZ];
-void xzcat_main(void)
+void do_xzcat(int fd, char *name)
{
struct xz_buf b;
struct xz_dec *s;
@@ -265,7 +265,7 @@ void xzcat_main(void)
for (;;) {
if (b.in_pos == b.in_size) {
- b.in_size = fread(in, 1, sizeof(in), stdin);
+ b.in_size = read(fd, in, sizeof(in));
b.in_pos = 0;
}
@@ -286,8 +286,7 @@ void xzcat_main(void)
if (ret == XZ_UNSUPPORTED_CHECK)
continue;
- if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
- || fclose(stdout)) {
+ if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
msg = "Write error\n";
goto error;
}
@@ -329,6 +328,11 @@ error:
error_exit("%s", msg);
}
+void xzcat_main(void)
+{
+ loopfiles(toys.optargs, do_xzcat);
+}
+
// BEGIN xz_private.h