Date: Mon, 9 Aug 1999 23:29:30 +0900 (JST) From: toshi@jp.freebsd.org To: FreeBSD-gnats-submit@freebsd.org Subject: bin/13043: minigzip -c option support. Message-ID: <199908091429.XAA68208@castle.jp.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 13043 >Category: bin >Synopsis: minigzip -c option support. >Confidential: yes >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Aug 9 07:40:00 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Toshihiko ARAI >Release: FreeBSD 3.2-RELEASE i386 >Organization: >Environment: FreeBSD 3.2-RELEASE PC/AT Install floppies. >Description: /stand/zcat foo.gz uncompressed original file to foo. (i.e. same as gunzip -d foo.gz) >How-To-Repeat: ln -s /usr/bin/minigzip zcat zcat foo.gz >Fix: Implement minigzip -c option. --- ../../lib/libz/minigzip.c.orig Sun Jan 10 18:53:50 1999 +++ ../../lib/libz/minigzip.c Mon Aug 9 00:30:12 1999 @@ -122,7 +122,6 @@ if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); } fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); } #ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */ @@ -157,7 +156,6 @@ munmap(buf, buf_len); fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); return Z_OK; } #endif /* USE_MMAP */ @@ -182,7 +180,6 @@ error("failed fwrite"); } } - if (fclose(out)) error("failed fclose"); if (gzclose(in) != Z_OK) error("failed gzclose"); } @@ -215,6 +212,7 @@ } gz_compress(in, out); + if (gzclose(out) != Z_OK) error("failed gzclose"); unlink(file); } @@ -255,12 +253,14 @@ gz_uncompress(in, out); + if (fclose(out)) error("failed fclose"); unlink(infile); } /* =========================================================================== - * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] + * Usage: minigzip [-c] [-d] [-f] [-h] [-1 to -9] [files...] + * -c : standart output * -d : decompress * -f : compress with Z_FILTERED * -h : compress with Z_HUFFMAN_ONLY @@ -271,6 +271,7 @@ int argc; char *argv[]; { + int copyout = 0; int uncompr = 0; gzFile file; char *bname, outmode[20]; @@ -285,12 +286,14 @@ bname = argv[0]; argc--, argv++; - if (!strcmp(bname, "gunzip") || !strcmp(bname, "zcat")) + if (!strcmp(bname, "gunzip")) uncompr = 1; + else if (!strcmp(bname, "zcat")) + copyout = uncompr = 1; while (argc > 0) { if (strcmp(*argv, "-c") == 0) - ; /* Just for compatability with gzip */ + copyout = 1; /* Just for compatability with gzip */ else if (strcmp(*argv, "-d") == 0) uncompr = 1; else if (strcmp(*argv, "-f") == 0) @@ -315,15 +318,39 @@ file = gzdopen(fileno(stdout), outmode); if (file == NULL) error("can't gzdopen stdout"); gz_compress(stdin, file); + if (gzclose(file) != Z_OK) error("failed gzclose"); } } else { + if (copyout) { + SET_BINARY_MODE(stdout); + if (!uncompr) { + file = gzdopen(fileno(stdout), outmode); + if (file == NULL) error("can't gzdopen stdout"); + } + } do { if (uncompr) { - file_uncompress(*argv); + if (copyout) { + file = gzopen(*argv, "rb"); + if (file == NULL) + fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); + else + gz_uncompress(file, stdout); + } else + file_uncompress(*argv); } else { - file_compress(*argv, outmode); + if (copyout) { + FILE * in = fopen(*argv, "rb"); + if (in == NULL) + perror(*argv); + else + gz_compress(in, file); + } else + file_compress(*argv, outmode); } } while (argv++, --argc); + if (copyout && !uncompr) + if (gzclose(file) != Z_OK) error("failed gzclose"); } exit(0); return 0; /* to avoid warning */ --- minigzip.1.orig Mon Jan 5 16:14:54 1998 +++ minigzip.1 Mon Aug 9 00:07:49 1999 @@ -32,6 +32,7 @@ .Nd minimal implementation of the 'gzip' compression tool .Sh SYNOPSIS .Nm minigzip +.Op Fl c .Op Fl d .Op Ar file ... .Sh DESCRIPTION @@ -63,6 +64,10 @@ .Nm reads from standard input and writes the results of the operation to standard output. +.Pp +If the +.Fl c +option is specified, write results to standard output. .Sh SEE ALSO .Xr gzip 1 .Sh AUTHORS >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908091429.XAA68208>