# HG changeset patch # User Isaac Dunham # Date 1374100034 18000 # Node ID 1cf9c28012a76dd30cd1a7fcba8251b189d7df5a # Parent 13916d161ec07caf7a87fffc539c86b7ce971031 make xzcat use loopfiles(), thereby allowing regular usage. diff -r 13916d161ec0 -r 1cf9c28012a7 toys/pending/xzcat.c --- a/toys/pending/xzcat.c Wed Jul 17 17:25:07 2013 -0500 +++ b/toys/pending/xzcat.c Wed Jul 17 17:27:14 2013 -0500 @@ -12,9 +12,9 @@ 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 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 @@ 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 @@ 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_exit("%s", msg); } +void xzcat_main(void) +{ + loopfiles(toys.optargs, do_xzcat); +} + // BEGIN xz_private.h