Separate interface from implementation so that zlib.h can be

included without the other, private header files.  Only zlib.h
should be installed in /usr/include; all others are private.
The Makefile has a "test" rule to verify that minigzip.c can
be compiled using only zlib.h (and that it actually works).
Note: This file has extensive modifications.
This commit is contained in:
gwr 1996-09-12 19:33:53 +00:00
parent 4222075279
commit de831ea222
3 changed files with 112 additions and 144 deletions

26
lib/libz/Makefile Normal file
View File

@ -0,0 +1,26 @@
# $NetBSD: Makefile,v 1.1 1996/09/12 19:33:53 gwr Exp $
#
LIB= z
SRCS= adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \
zutil.c inflate.c infblock.c inftrees.c infcodes.c infutil.c inffast.c
CFLAGS+= -D_ZLIB_PRIVATE -I${.CURDIR}
NOMAN=
includes:
-cd ${.CURDIR}; cmp -s zlib.h ${DESTDIR}/usr/include/zlib.h > \
/dev/null 2>&1 || \
install -c -o ${BINOWN} -g ${BINGRP} -m 444 zlib.h \
${DESTDIR}/usr/include
.include <bsd.lib.mk>
test: minigzip
echo hello world | ./minigzip | ./minigzip -d
# Note: CFLAGS ommitted by intention!
# This is to verify that zlib.h works standalone.
minigzip : minigzip.c libz.a
$(CC) -o minigzip minigzip.c libz.a

View File

@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* $Id: zconf.h,v 1.1.1.1 1996/09/12 15:33:10 gwr Exp $ */
/* $Id: zconf.h,v 1.2 1996/09/12 19:33:53 gwr Exp $ */
#ifndef _ZCONF_H
#define _ZCONF_H
@ -46,16 +46,9 @@
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#ifndef __32BIT__
/* Don't be alarmed; this just means we have at least 32-bits */
# define __32BIT__
#endif
/*
@ -65,19 +58,19 @@
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
#ifdef MSDOS /* XXX - Yuck! */
/* XXX: Are there machines where we should define this? m68k? */
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
/* XXX: Look out - this is used in zutil.h and elsewhere... */
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# ifndef const
# define const
# endif
#endif
@ -114,71 +107,24 @@
for small objects.
*/
/* Type declarations */
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
#define OF(args) __P(args)
#define FAR
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR __far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR __far
# endif
#endif
#ifndef FAR
# define FAR
#endif
typedef u_char Byte; /* 8 bits */
typedef u_int uInt; /* 16 bits or more */
typedef u_long uLong; /* 32 bits or more */
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
/* Borland C/C++ ignores FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef Byte FAR Bytef;
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#define voidpf void *
#define voidp void *
/* Compile with -DZLIB_DLL for Windows DLL support */
#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
# include <windows.h>
# define EXPORT WINAPI
#else
# define EXPORT
#endif
#define EXPORT
#endif /* _ZCONF_H */

View File

@ -31,12 +31,6 @@
#ifndef _ZLIB_H
#define _ZLIB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "zconf.h"
#define ZLIB_VERSION "1.0.4"
/*
@ -63,33 +57,41 @@ extern "C" {
for some forms of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
#include <sys/types.h>
#ifdef _ZLIB_PRIVATE
#include "zconf.h"
#endif
__BEGIN_DECLS
typedef void *((*alloc_func) __P((void *opaque, u_int items, u_int size)));
typedef void (*free_func) __P((void *opaque, void *address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
u_char *next_in; /* next input byte */
u_int avail_in; /* number of bytes available at next_in */
u_long total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
u_char *next_out; /* next output byte should be put there */
u_int avail_out; /* remaining free space at next_out */
u_long total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
struct internal_state *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
void *opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
u_long adler; /* adler32 value of the uncompressed data */
u_long reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
typedef z_stream *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
@ -168,7 +170,7 @@ typedef z_stream FAR *z_streamp;
/* basic functions */
extern const char * EXPORT zlibVersion OF((void));
extern __const char * zlibVersion __P((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
@ -176,7 +178,7 @@ extern const char * EXPORT zlibVersion OF((void));
*/
/*
extern int EXPORT deflateInit OF((z_streamp strm, int level));
extern int deflateInit __P((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
@ -198,7 +200,7 @@ extern int EXPORT deflateInit OF((z_streamp strm, int level));
*/
extern int EXPORT deflate OF((z_streamp strm, int flush));
extern int deflate __P((z_streamp strm, int flush));
/*
Performs one or both of the following actions:
@ -267,7 +269,7 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
*/
extern int EXPORT deflateEnd OF((z_streamp strm));
extern int deflateEnd __P((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
@ -282,7 +284,7 @@ extern int EXPORT deflateEnd OF((z_streamp strm));
/*
extern int EXPORT inflateInit OF((z_streamp strm));
extern int inflateInit __P((z_streamp strm));
Initializes the internal stream state for decompression. The fields
zalloc, zfree and opaque must be initialized before by the caller. If
@ -297,7 +299,7 @@ extern int EXPORT inflateInit OF((z_streamp strm));
*/
extern int EXPORT inflate OF((z_streamp strm, int flush));
extern int inflate __P((z_streamp strm, int flush));
/*
Performs one or both of the following actions:
@ -352,7 +354,7 @@ extern int EXPORT inflate OF((z_streamp strm, int flush));
*/
extern int EXPORT inflateEnd OF((z_streamp strm));
extern int inflateEnd __P((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
@ -370,7 +372,7 @@ extern int EXPORT inflateEnd OF((z_streamp strm));
*/
/*
extern int EXPORT deflateInit2 OF((z_streamp strm,
extern int deflateInit2 __P((z_streamp strm,
int level,
int method,
int windowBits,
@ -428,9 +430,9 @@ extern int EXPORT deflateInit2 OF((z_streamp strm,
deflate().
*/
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
extern int deflateSetDictionary __P((z_streamp strm,
__const u_char *dictionary,
u_int dictLength));
/*
Initializes the compression dictionary (history buffer) from the given
byte sequence without producing any compressed output. This function must
@ -457,7 +459,7 @@ extern int EXPORT deflateSetDictionary OF((z_streamp strm,
be done by deflate().
*/
extern int EXPORT deflateCopy OF((z_streamp dest,
extern int deflateCopy __P((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream. If
@ -480,7 +482,7 @@ extern int EXPORT deflateCopy OF((z_streamp dest,
destination.
*/
extern int EXPORT deflateReset OF((z_streamp strm));
extern int deflateReset __P((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
@ -491,7 +493,7 @@ extern int EXPORT deflateReset OF((z_streamp strm));
stream state was inconsistent (such as zalloc or state being NULL).
*/
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
extern int deflateParams __P((z_streamp strm, int level, int strategy));
/*
Dynamically update the compression level and compression strategy.
This can be used to switch between compression and straight copy of
@ -510,7 +512,7 @@ extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
*/
/*
extern int EXPORT inflateInit2 OF((z_streamp strm,
extern int inflateInit2 __P((z_streamp strm,
int windowBits));
This is another version of inflateInit with more compression options. The
@ -544,9 +546,9 @@ extern int EXPORT inflateInit2 OF((z_streamp strm,
inflate().
*/
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
extern int inflateSetDictionary __P((z_streamp strm,
__const u_char *dictionary,
u_int dictLength));
/*
Initializes the decompression dictionary (history buffer) from the given
uncompressed byte sequence. This function must be called immediately after
@ -563,7 +565,7 @@ extern int EXPORT inflateSetDictionary OF((z_streamp strm,
inflate().
*/
extern int EXPORT inflateSync OF((z_streamp strm));
extern int inflateSync __P((z_streamp strm));
/*
Skips invalid compressed data until the special marker (see deflate()
above) can be found, or until all available input is skipped. No output
@ -578,7 +580,7 @@ extern int EXPORT inflateSync OF((z_streamp strm));
until success or end of the input data.
*/
extern int EXPORT inflateReset OF((z_streamp strm));
extern int inflateReset __P((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
@ -599,8 +601,8 @@ extern int EXPORT inflateReset OF((z_streamp strm));
utility functions can easily be modified if you need special options.
*/
extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
extern int compress __P((u_char *dest, u_long *destLen,
__const u_char *source, u_long sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
@ -614,8 +616,8 @@ extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
buffer.
*/
extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
extern int uncompress __P((u_char *dest, u_long *destLen,
__const u_char *source, u_long sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
@ -633,9 +635,9 @@ extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
*/
typedef voidp gzFile;
typedef void *gzFile;
extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
extern gzFile gzopen __P((__const char *path, __const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
@ -647,7 +649,7 @@ extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
zlib error is Z_MEM_ERROR).
*/
extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
extern gzFile gzdopen __P((int fd, __const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
@ -660,7 +662,7 @@ extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
the (de)compression state.
*/
extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
extern int gzread __P((gzFile file, void *buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
@ -668,14 +670,14 @@ extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
extern int gzwrite __P((gzFile file, __const void *buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
extern int EXPORT gzflush OF((gzFile file, int flush));
extern int gzflush __P((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
@ -685,14 +687,14 @@ extern int EXPORT gzflush OF((gzFile file, int flush));
degrade compression.
*/
extern int EXPORT gzclose OF((gzFile file));
extern int gzclose __P((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
extern __const char * gzerror __P((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
@ -709,7 +711,7 @@ extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
compression library.
*/
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
extern u_long adler32 __P((u_long adler, __const u_char *buf, u_int len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
@ -718,7 +720,7 @@ extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
u_long adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
@ -726,7 +728,7 @@ extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
if (adler != original_adler) error();
*/
extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
extern u_long crc32 __P((u_long crc, __const u_char *buf, u_int len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
@ -734,7 +736,7 @@ extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
u_long crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
@ -748,15 +750,15 @@ extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
extern int EXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
extern int deflateInit_ __P((z_streamp strm, int level,
__const char *version, int stream_size));
extern int inflateInit_ __P((z_streamp strm,
__const char *version, int stream_size));
extern int deflateInit2_ __P((z_streamp strm, int level, int method,
int windowBits, int memLevel, int strategy,
const char *version, int stream_size));
extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
__const char *version, int stream_size));
extern int inflateInit2_ __P((z_streamp strm, int windowBits,
__const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
@ -767,14 +769,8 @@ extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
u_long *get_crc_table __P((void)); /* can be used by asm versions of crc32() */
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
#ifdef __cplusplus
}
#endif
__END_DECLS
#endif /* _ZLIB_H */