From owner-freebsd-bugs Sun Sep 30 23:31:56 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from air.linkclub.or.jp (air.linkclub.or.jp [210.250.19.40]) by hub.freebsd.org (Postfix) with ESMTP id 2E4C137B40D; Sun, 30 Sep 2001 23:31:47 -0700 (PDT) Received: from localhost.jp.FreeBSD.org (1Cust45.tnt1.hanno.jp.da.uu.net [63.12.195.45]) by air.linkclub.or.jp (8.11.4/8.11.4) with ESMTP id f916QVW52671; Mon, 1 Oct 2001 15:26:34 +0900 (JST) (envelope-from toshi@jp.FreeBSD.org) Date: Mon, 1 Oct 2001 13:43:19 +0900 (JST) Message-Id: <200110010443.f914hJU97082.toshi@jp.FreeBSD.org> From: Toshihiko ARAI To: gnats-admin@FreeBSD.org, freebsd-bugs@FreeBSD.org Cc: toshi@jp.FreeBSD.org Subject: Re: bin/13043: minigzip -c option support. In-Reply-To: <199908091440.HAA13909@freefall.freebsd.org> References: <199908091429.XAA68208@castle.jp.freebsd.org> <199908091440.HAA13909@freefall.freebsd.org> X-Mailer: VM 5.96 (beta) / Mule 2.3 (SUETSUMUHANA) based on 19.34.1 Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >> Category: bin >> Responsible: freebsd-bugs >> Synopsis: minigzip -c option support. >> Arrival-Date: Mon Aug 9 07:40:00 PDT 1999 I updated these patches. This is for 4-stable, but it can be applied for 5-current too. Because I attach two patches to the following, I want you to check it. I use it with PicoBSD which I customized for oneself. And installation floppy includes minigzip, but probably it will not be a problem because it hardly influences binary size. A patch for src/lib/libz/ directory as follows. Index: minigzip.c =================================================================== RCS file: /home/ncvs/src/lib/libz/minigzip.c,v retrieving revision 1.6.2.2 diff -u -r1.6.2.2 minigzip.c --- minigzip.c 2001/03/05 06:32:25 1.6.2.2 +++ minigzip.c 2001/10/01 02:24:05 @@ -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 */ @@ -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"); } @@ -201,7 +198,7 @@ gzFile out; if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { - fprintf(stderr, "%s: nilename too long\n", prog); + fprintf(stderr, "%s: filename too long\n", prog); exit(1); } @@ -220,6 +217,7 @@ } gz_compress(in, out); + if (gzclose(out) != Z_OK) error("failed gzclose"); unlink(file); } @@ -265,12 +263,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 @@ -281,6 +281,7 @@ int argc; char *argv[]; { + int copyout = 0; int uncompr = 0; gzFile file; char *bname, outmode[20]; @@ -295,12 +296,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 compatibility with gzip */ + copyout = 1; /* Just for compatibility with gzip */ else if (strcmp(*argv, "-d") == 0) uncompr = 1; else if (strcmp(*argv, "-f") == 0) @@ -325,15 +328,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 */ --------------- A patch for src/usr.bin/minigzip/ directory as follows. Index: minigzip.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/minigzip/minigzip.1,v retrieving revision 1.3.2.3 diff -u -r1.3.2.3 minigzip.1 --- minigzip.1 2001/07/22 12:40:26 1.3.2.3 +++ minigzip.1 2001/10/01 02:42:06 @@ -32,6 +32,7 @@ .Nd minimal implementation of the 'gzip' compression tool .Sh SYNOPSIS .Nm +.Op Fl c .Op Fl d .Op Ar .Sh DESCRIPTION @@ -56,6 +57,10 @@ suffix. Decompression will remove a .Pa .gz suffix if one is present. +.Pp +If the +.Fl c +option is specified, a result is written to standard output. .Pp If no .Ar file -- Toshihiko ARAI To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message