1 /* $NetBSD: zcat.c,v 1.2 1996/09/24 20:40:11 gwr Exp $ */
3 /* mini zcat.c -- a minimal zcat using the zlib compression library
4 * Copyright (C) 1995-1996 Jean-loup Gailly.
5 * For conditions of distribution and use, see copyright notice in zlib.h
10 * This program is a reduced version of the minigzip.c
11 * program originally written by Jean-loup Gailly.
12 * This reduction is the work of Gordon Ross.
25 void error
__P((const char *msg
));
26 void gz_uncompress
__P((gzFile in
, FILE *out
));
27 int main
__P((int argc
, char *argv
[]));
29 /* ===========================================================================
30 * Display error message and exit
35 fprintf(stderr
, "%s: %s\n", prog
, msg
);
39 /* ===========================================================================
40 * Uncompress input to output then close both files.
42 void gz_uncompress(in
, out
)
51 len
= gzread(in
, buf
, sizeof(buf
));
52 if (len
< 0) error (gzerror(in
, &err
));
55 if ((int)fwrite(buf
, 1, (unsigned)len
, out
) != len
) {
56 error("failed fwrite");
59 if (fclose(out
)) error("failed fclose");
61 if (gzclose(in
) != Z_OK
) error("failed gzclose");
65 /* ===========================================================================
66 * Usage: zcat [files...]
75 /* save program name and skip */
79 /* ignore any switches */
80 while (*argv
&& (**argv
== '-')) {
85 zfp
= gzdopen(fileno(stdin
), "rb");
87 error("can't gzdopen stdin");
88 gz_uncompress(zfp
, stdout
);
93 /* file_uncompress(*argv); */
94 zfp
= gzopen(*argv
, "rb");
96 fprintf(stderr
, "%s: can't gzopen %s\n", prog
, *argv
);
99 gz_uncompress(zfp
, stdout
);
100 } while (argv
++, --argc
);
101 return 0; /* to avoid warning */
106 * XXX: hacks to keep gzio.c from pulling in deflate stuff
109 int deflateInit2_ (z_streamp strm
, int level
, int method
,
110 int windowBits
, int memLevel
, int strategy
,
111 const char *version
, int stream_size
)
116 int deflate (z_streamp strm
, int flush
)
121 int deflateEnd (z_streamp strm
)
126 int deflateParams (z_streamp strm
, int level
, int strategy
)
128 return(Z_STREAM_ERROR
);