xref: /onnv-gate/usr/src/common/openssl/crypto/comp/c_zlib.c (revision 2139:6243c3338933)
10Sstevel@tonic-gate #include <stdio.h>
20Sstevel@tonic-gate #include <stdlib.h>
30Sstevel@tonic-gate #include <string.h>
40Sstevel@tonic-gate #include <openssl/objects.h>
50Sstevel@tonic-gate #include <openssl/comp.h>
6*2139Sjp161948 #include <openssl/err.h>
70Sstevel@tonic-gate 
80Sstevel@tonic-gate COMP_METHOD *COMP_zlib(void );
90Sstevel@tonic-gate 
100Sstevel@tonic-gate static COMP_METHOD zlib_method_nozlib={
110Sstevel@tonic-gate 	NID_undef,
120Sstevel@tonic-gate 	"(undef)",
130Sstevel@tonic-gate 	NULL,
140Sstevel@tonic-gate 	NULL,
150Sstevel@tonic-gate 	NULL,
160Sstevel@tonic-gate 	NULL,
170Sstevel@tonic-gate 	NULL,
180Sstevel@tonic-gate 	NULL,
190Sstevel@tonic-gate 	};
200Sstevel@tonic-gate 
210Sstevel@tonic-gate #ifndef ZLIB
220Sstevel@tonic-gate #undef ZLIB_SHARED
230Sstevel@tonic-gate #else
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #include <zlib.h>
260Sstevel@tonic-gate 
27*2139Sjp161948 static int zlib_stateful_init(COMP_CTX *ctx);
28*2139Sjp161948 static void zlib_stateful_finish(COMP_CTX *ctx);
29*2139Sjp161948 static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
30*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen);
31*2139Sjp161948 static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
32*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen);
33*2139Sjp161948 
34*2139Sjp161948 #if 0
350Sstevel@tonic-gate static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
360Sstevel@tonic-gate 	unsigned int olen, unsigned char *in, unsigned int ilen);
370Sstevel@tonic-gate static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
380Sstevel@tonic-gate 	unsigned int olen, unsigned char *in, unsigned int ilen);
390Sstevel@tonic-gate 
400Sstevel@tonic-gate static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
410Sstevel@tonic-gate 	uLong sourceLen);
420Sstevel@tonic-gate 
43*2139Sjp161948 static COMP_METHOD zlib_stateless_method={
440Sstevel@tonic-gate 	NID_zlib_compression,
450Sstevel@tonic-gate 	LN_zlib_compression,
460Sstevel@tonic-gate 	NULL,
470Sstevel@tonic-gate 	NULL,
480Sstevel@tonic-gate 	zlib_compress_block,
490Sstevel@tonic-gate 	zlib_expand_block,
500Sstevel@tonic-gate 	NULL,
510Sstevel@tonic-gate 	NULL,
520Sstevel@tonic-gate 	};
53*2139Sjp161948 #endif
54*2139Sjp161948 
55*2139Sjp161948 static COMP_METHOD zlib_stateful_method={
56*2139Sjp161948 	NID_zlib_compression,
57*2139Sjp161948 	LN_zlib_compression,
58*2139Sjp161948 	zlib_stateful_init,
59*2139Sjp161948 	zlib_stateful_finish,
60*2139Sjp161948 	zlib_stateful_compress_block,
61*2139Sjp161948 	zlib_stateful_expand_block,
62*2139Sjp161948 	NULL,
63*2139Sjp161948 	NULL,
64*2139Sjp161948 	};
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * When OpenSSL is built on Windows, we do not want to require that
680Sstevel@tonic-gate  * the ZLIB.DLL be available in order for the OpenSSL DLLs to
690Sstevel@tonic-gate  * work.  Therefore, all ZLIB routines are loaded at run time
700Sstevel@tonic-gate  * and we do not link to a .LIB file.
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
730Sstevel@tonic-gate # include <windows.h>
740Sstevel@tonic-gate 
750Sstevel@tonic-gate # define Z_CALLCONV _stdcall
76*2139Sjp161948 # ifndef ZLIB_SHARED
77*2139Sjp161948 #  define ZLIB_SHARED
78*2139Sjp161948 # endif
790Sstevel@tonic-gate #else
800Sstevel@tonic-gate # define Z_CALLCONV
810Sstevel@tonic-gate #endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #ifdef ZLIB_SHARED
840Sstevel@tonic-gate #include <openssl/dso.h>
850Sstevel@tonic-gate 
860Sstevel@tonic-gate /* Prototypes for built in stubs */
87*2139Sjp161948 #if 0
880Sstevel@tonic-gate static int stub_compress(Bytef *dest,uLongf *destLen,
890Sstevel@tonic-gate 	const Bytef *source, uLong sourceLen);
90*2139Sjp161948 #endif
910Sstevel@tonic-gate static int stub_inflateEnd(z_streamp strm);
920Sstevel@tonic-gate static int stub_inflate(z_streamp strm, int flush);
930Sstevel@tonic-gate static int stub_inflateInit_(z_streamp strm, const char * version,
940Sstevel@tonic-gate 	int stream_size);
95*2139Sjp161948 static int stub_deflateEnd(z_streamp strm);
96*2139Sjp161948 static int stub_deflate(z_streamp strm, int flush);
97*2139Sjp161948 static int stub_deflateInit_(z_streamp strm, int level,
98*2139Sjp161948 	const char * version, int stream_size);
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /* Function pointers */
1010Sstevel@tonic-gate typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
1020Sstevel@tonic-gate 	const Bytef *source, uLong sourceLen);
1030Sstevel@tonic-gate typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
1040Sstevel@tonic-gate typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
1050Sstevel@tonic-gate typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
1060Sstevel@tonic-gate 	const char * version, int stream_size);
107*2139Sjp161948 typedef int (Z_CALLCONV *deflateEnd_ft)(z_streamp strm);
108*2139Sjp161948 typedef int (Z_CALLCONV *deflate_ft)(z_streamp strm, int flush);
109*2139Sjp161948 typedef int (Z_CALLCONV *deflateInit__ft)(z_streamp strm, int level,
110*2139Sjp161948 	const char * version, int stream_size);
1110Sstevel@tonic-gate static compress_ft	p_compress=NULL;
1120Sstevel@tonic-gate static inflateEnd_ft	p_inflateEnd=NULL;
1130Sstevel@tonic-gate static inflate_ft	p_inflate=NULL;
1140Sstevel@tonic-gate static inflateInit__ft	p_inflateInit_=NULL;
115*2139Sjp161948 static deflateEnd_ft	p_deflateEnd=NULL;
116*2139Sjp161948 static deflate_ft	p_deflate=NULL;
117*2139Sjp161948 static deflateInit__ft	p_deflateInit_=NULL;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate static int zlib_loaded = 0;     /* only attempt to init func pts once */
1200Sstevel@tonic-gate static DSO *zlib_dso = NULL;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate #define compress                stub_compress
1230Sstevel@tonic-gate #define inflateEnd              stub_inflateEnd
1240Sstevel@tonic-gate #define inflate                 stub_inflate
1250Sstevel@tonic-gate #define inflateInit_            stub_inflateInit_
126*2139Sjp161948 #define deflateEnd              stub_deflateEnd
127*2139Sjp161948 #define deflate                 stub_deflate
128*2139Sjp161948 #define deflateInit_            stub_deflateInit_
1290Sstevel@tonic-gate #endif /* ZLIB_SHARED */
1300Sstevel@tonic-gate 
131*2139Sjp161948 struct zlib_state
132*2139Sjp161948 	{
133*2139Sjp161948 	z_stream istream;
134*2139Sjp161948 	z_stream ostream;
135*2139Sjp161948 	};
136*2139Sjp161948 
137*2139Sjp161948 static int zlib_stateful_ex_idx = -1;
138*2139Sjp161948 
zlib_stateful_free_ex_data(void * obj,void * item,CRYPTO_EX_DATA * ad,int ind,long argl,void * argp)139*2139Sjp161948 static void zlib_stateful_free_ex_data(void *obj, void *item,
140*2139Sjp161948 	CRYPTO_EX_DATA *ad, int ind,long argl, void *argp)
141*2139Sjp161948 	{
142*2139Sjp161948 	struct zlib_state *state = (struct zlib_state *)item;
143*2139Sjp161948 	inflateEnd(&state->istream);
144*2139Sjp161948 	deflateEnd(&state->ostream);
145*2139Sjp161948 	OPENSSL_free(state);
146*2139Sjp161948 	}
147*2139Sjp161948 
zlib_stateful_init(COMP_CTX * ctx)148*2139Sjp161948 static int zlib_stateful_init(COMP_CTX *ctx)
149*2139Sjp161948 	{
150*2139Sjp161948 	int err;
151*2139Sjp161948 	struct zlib_state *state =
152*2139Sjp161948 		(struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));
153*2139Sjp161948 
154*2139Sjp161948 	if (state == NULL)
155*2139Sjp161948 		goto err;
156*2139Sjp161948 
157*2139Sjp161948 	state->istream.zalloc = Z_NULL;
158*2139Sjp161948 	state->istream.zfree = Z_NULL;
159*2139Sjp161948 	state->istream.opaque = Z_NULL;
160*2139Sjp161948 	state->istream.next_in = Z_NULL;
161*2139Sjp161948 	state->istream.next_out = Z_NULL;
162*2139Sjp161948 	state->istream.avail_in = 0;
163*2139Sjp161948 	state->istream.avail_out = 0;
164*2139Sjp161948 	err = inflateInit_(&state->istream,
165*2139Sjp161948 		ZLIB_VERSION, sizeof(z_stream));
166*2139Sjp161948 	if (err != Z_OK)
167*2139Sjp161948 		goto err;
168*2139Sjp161948 
169*2139Sjp161948 	state->ostream.zalloc = Z_NULL;
170*2139Sjp161948 	state->ostream.zfree = Z_NULL;
171*2139Sjp161948 	state->ostream.opaque = Z_NULL;
172*2139Sjp161948 	state->ostream.next_in = Z_NULL;
173*2139Sjp161948 	state->ostream.next_out = Z_NULL;
174*2139Sjp161948 	state->ostream.avail_in = 0;
175*2139Sjp161948 	state->ostream.avail_out = 0;
176*2139Sjp161948 	err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION,
177*2139Sjp161948 		ZLIB_VERSION, sizeof(z_stream));
178*2139Sjp161948 	if (err != Z_OK)
179*2139Sjp161948 		goto err;
180*2139Sjp161948 
181*2139Sjp161948 	CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
182*2139Sjp161948 	if (zlib_stateful_ex_idx == -1)
183*2139Sjp161948 		{
184*2139Sjp161948 		CRYPTO_w_lock(CRYPTO_LOCK_COMP);
185*2139Sjp161948 		if (zlib_stateful_ex_idx == -1)
186*2139Sjp161948 			zlib_stateful_ex_idx =
187*2139Sjp161948 				CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
188*2139Sjp161948 					0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
189*2139Sjp161948 		CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
190*2139Sjp161948 		if (zlib_stateful_ex_idx == -1)
191*2139Sjp161948 			goto err;
192*2139Sjp161948 		}
193*2139Sjp161948 	CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state);
194*2139Sjp161948 	return 1;
195*2139Sjp161948  err:
196*2139Sjp161948 	if (state) OPENSSL_free(state);
197*2139Sjp161948 	return 0;
198*2139Sjp161948 	}
199*2139Sjp161948 
zlib_stateful_finish(COMP_CTX * ctx)200*2139Sjp161948 static void zlib_stateful_finish(COMP_CTX *ctx)
201*2139Sjp161948 	{
202*2139Sjp161948 	CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
203*2139Sjp161948 	}
204*2139Sjp161948 
zlib_stateful_compress_block(COMP_CTX * ctx,unsigned char * out,unsigned int olen,unsigned char * in,unsigned int ilen)205*2139Sjp161948 static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
206*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen)
207*2139Sjp161948 	{
208*2139Sjp161948 	int err = Z_OK;
209*2139Sjp161948 	struct zlib_state *state =
210*2139Sjp161948 		(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
211*2139Sjp161948 			zlib_stateful_ex_idx);
212*2139Sjp161948 
213*2139Sjp161948 	if (state == NULL)
214*2139Sjp161948 		return -1;
215*2139Sjp161948 
216*2139Sjp161948 	state->ostream.next_in = in;
217*2139Sjp161948 	state->ostream.avail_in = ilen;
218*2139Sjp161948 	state->ostream.next_out = out;
219*2139Sjp161948 	state->ostream.avail_out = olen;
220*2139Sjp161948 	if (ilen > 0)
221*2139Sjp161948 		err = deflate(&state->ostream, Z_SYNC_FLUSH);
222*2139Sjp161948 	if (err != Z_OK)
223*2139Sjp161948 		return -1;
224*2139Sjp161948 #ifdef DEBUG_ZLIB
225*2139Sjp161948 	fprintf(stderr,"compress(%4d)->%4d %s\n",
226*2139Sjp161948 		ilen,olen - state->ostream.avail_out,
227*2139Sjp161948 		(ilen != olen - state->ostream.avail_out)?"zlib":"clear");
228*2139Sjp161948 #endif
229*2139Sjp161948 	return olen - state->ostream.avail_out;
230*2139Sjp161948 	}
231*2139Sjp161948 
zlib_stateful_expand_block(COMP_CTX * ctx,unsigned char * out,unsigned int olen,unsigned char * in,unsigned int ilen)232*2139Sjp161948 static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
233*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen)
234*2139Sjp161948 	{
235*2139Sjp161948 	int err = Z_OK;
236*2139Sjp161948 
237*2139Sjp161948 	struct zlib_state *state =
238*2139Sjp161948 		(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
239*2139Sjp161948 			zlib_stateful_ex_idx);
240*2139Sjp161948 
241*2139Sjp161948 	if (state == NULL)
242*2139Sjp161948 		return 0;
243*2139Sjp161948 
244*2139Sjp161948 	state->istream.next_in = in;
245*2139Sjp161948 	state->istream.avail_in = ilen;
246*2139Sjp161948 	state->istream.next_out = out;
247*2139Sjp161948 	state->istream.avail_out = olen;
248*2139Sjp161948 	if (ilen > 0)
249*2139Sjp161948 		err = inflate(&state->istream, Z_SYNC_FLUSH);
250*2139Sjp161948 	if (err != Z_OK)
251*2139Sjp161948 		return -1;
252*2139Sjp161948 #ifdef DEBUG_ZLIB
253*2139Sjp161948 	fprintf(stderr,"expand(%4d)->%4d %s\n",
254*2139Sjp161948 		ilen,olen - state->istream.avail_out,
255*2139Sjp161948 		(ilen != olen - state->istream.avail_out)?"zlib":"clear");
256*2139Sjp161948 #endif
257*2139Sjp161948 	return olen - state->istream.avail_out;
258*2139Sjp161948 	}
259*2139Sjp161948 
260*2139Sjp161948 #if 0
2610Sstevel@tonic-gate static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
262*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen)
2630Sstevel@tonic-gate 	{
2640Sstevel@tonic-gate 	unsigned long l;
2650Sstevel@tonic-gate 	int i;
2660Sstevel@tonic-gate 	int clear=1;
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	if (ilen > 128)
2690Sstevel@tonic-gate 		{
2700Sstevel@tonic-gate 		out[0]=1;
2710Sstevel@tonic-gate 		l=olen-1;
2720Sstevel@tonic-gate 		i=compress(&(out[1]),&l,in,(unsigned long)ilen);
2730Sstevel@tonic-gate 		if (i != Z_OK)
2740Sstevel@tonic-gate 			return(-1);
2750Sstevel@tonic-gate 		if (ilen > l)
2760Sstevel@tonic-gate 			{
2770Sstevel@tonic-gate 			clear=0;
2780Sstevel@tonic-gate 			l++;
2790Sstevel@tonic-gate 			}
2800Sstevel@tonic-gate 		}
2810Sstevel@tonic-gate 	if (clear)
2820Sstevel@tonic-gate 		{
2830Sstevel@tonic-gate 		out[0]=0;
2840Sstevel@tonic-gate 		memcpy(&(out[1]),in,ilen);
2850Sstevel@tonic-gate 		l=ilen+1;
2860Sstevel@tonic-gate 		}
2870Sstevel@tonic-gate #ifdef DEBUG_ZLIB
2880Sstevel@tonic-gate 	fprintf(stderr,"compress(%4d)->%4d %s\n",
2890Sstevel@tonic-gate 		ilen,(int)l,(clear)?"clear":"zlib");
2900Sstevel@tonic-gate #endif
2910Sstevel@tonic-gate 	return((int)l);
2920Sstevel@tonic-gate 	}
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
295*2139Sjp161948 	unsigned int olen, unsigned char *in, unsigned int ilen)
2960Sstevel@tonic-gate 	{
2970Sstevel@tonic-gate 	unsigned long l;
2980Sstevel@tonic-gate 	int i;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	if (in[0])
3010Sstevel@tonic-gate 		{
3020Sstevel@tonic-gate 		l=olen;
3030Sstevel@tonic-gate 		i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
3040Sstevel@tonic-gate 		if (i != Z_OK)
3050Sstevel@tonic-gate 			return(-1);
3060Sstevel@tonic-gate 		}
3070Sstevel@tonic-gate 	else
3080Sstevel@tonic-gate 		{
3090Sstevel@tonic-gate 		memcpy(out,&(in[1]),ilen-1);
3100Sstevel@tonic-gate 		l=ilen-1;
3110Sstevel@tonic-gate 		}
3120Sstevel@tonic-gate #ifdef DEBUG_ZLIB
3130Sstevel@tonic-gate         fprintf(stderr,"expand  (%4d)->%4d %s\n",
3140Sstevel@tonic-gate 		ilen,(int)l,in[0]?"zlib":"clear");
3150Sstevel@tonic-gate #endif
3160Sstevel@tonic-gate 	return((int)l);
3170Sstevel@tonic-gate 	}
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
3200Sstevel@tonic-gate 	     uLong sourceLen)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate     z_stream stream;
3230Sstevel@tonic-gate     int err;
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate     stream.next_in = (Bytef*)source;
3260Sstevel@tonic-gate     stream.avail_in = (uInt)sourceLen;
3270Sstevel@tonic-gate     /* Check for source > 64K on 16-bit machine: */
3280Sstevel@tonic-gate     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate     stream.next_out = dest;
3310Sstevel@tonic-gate     stream.avail_out = (uInt)*destLen;
3320Sstevel@tonic-gate     if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate     stream.zalloc = (alloc_func)0;
3350Sstevel@tonic-gate     stream.zfree = (free_func)0;
3360Sstevel@tonic-gate 
337*2139Sjp161948     err = inflateInit_(&stream,
338*2139Sjp161948 	    ZLIB_VERSION, sizeof(z_stream));
3390Sstevel@tonic-gate     if (err != Z_OK) return err;
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate     err = inflate(&stream, Z_FINISH);
3420Sstevel@tonic-gate     if (err != Z_STREAM_END) {
3430Sstevel@tonic-gate         inflateEnd(&stream);
3440Sstevel@tonic-gate         return err;
3450Sstevel@tonic-gate     }
3460Sstevel@tonic-gate     *destLen = stream.total_out;
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate     err = inflateEnd(&stream);
3490Sstevel@tonic-gate     return err;
3500Sstevel@tonic-gate }
351*2139Sjp161948 #endif
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate #endif
3540Sstevel@tonic-gate 
COMP_zlib(void)3550Sstevel@tonic-gate COMP_METHOD *COMP_zlib(void)
3560Sstevel@tonic-gate 	{
3570Sstevel@tonic-gate 	COMP_METHOD *meth = &zlib_method_nozlib;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate #ifdef ZLIB_SHARED
3600Sstevel@tonic-gate 	if (!zlib_loaded)
3610Sstevel@tonic-gate 		{
3620Sstevel@tonic-gate #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
363*2139Sjp161948 		zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
364*2139Sjp161948 		if (!zlib_dso)
365*2139Sjp161948 			{
366*2139Sjp161948 			zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
367*2139Sjp161948 			if (zlib_dso)
368*2139Sjp161948 				{
369*2139Sjp161948 				/* Clear the errors from the first failed
370*2139Sjp161948 				   DSO_load() */
371*2139Sjp161948 				ERR_clear_error();
372*2139Sjp161948 				}
373*2139Sjp161948 			}
3740Sstevel@tonic-gate #else
3750Sstevel@tonic-gate 		zlib_dso = DSO_load(NULL, "z", NULL, 0);
3760Sstevel@tonic-gate #endif
3770Sstevel@tonic-gate 		if (zlib_dso != NULL)
3780Sstevel@tonic-gate 			{
3790Sstevel@tonic-gate 			p_compress
3800Sstevel@tonic-gate 				= (compress_ft) DSO_bind_func(zlib_dso,
3810Sstevel@tonic-gate 					"compress");
3820Sstevel@tonic-gate 			p_inflateEnd
3830Sstevel@tonic-gate 				= (inflateEnd_ft) DSO_bind_func(zlib_dso,
3840Sstevel@tonic-gate 					"inflateEnd");
3850Sstevel@tonic-gate 			p_inflate
3860Sstevel@tonic-gate 				= (inflate_ft) DSO_bind_func(zlib_dso,
3870Sstevel@tonic-gate 					"inflate");
3880Sstevel@tonic-gate 			p_inflateInit_
3890Sstevel@tonic-gate 				= (inflateInit__ft) DSO_bind_func(zlib_dso,
3900Sstevel@tonic-gate 					"inflateInit_");
391*2139Sjp161948 			p_deflateEnd
392*2139Sjp161948 				= (deflateEnd_ft) DSO_bind_func(zlib_dso,
393*2139Sjp161948 					"deflateEnd");
394*2139Sjp161948 			p_deflate
395*2139Sjp161948 				= (deflate_ft) DSO_bind_func(zlib_dso,
396*2139Sjp161948 					"deflate");
397*2139Sjp161948 			p_deflateInit_
398*2139Sjp161948 				= (deflateInit__ft) DSO_bind_func(zlib_dso,
399*2139Sjp161948 					"deflateInit_");
4000Sstevel@tonic-gate 			zlib_loaded++;
4010Sstevel@tonic-gate 			}
4020Sstevel@tonic-gate 		}
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate #endif
4050Sstevel@tonic-gate #if defined(ZLIB) || defined(ZLIB_SHARED)
406*2139Sjp161948 	meth = &zlib_stateful_method;
4070Sstevel@tonic-gate #endif
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	return(meth);
4100Sstevel@tonic-gate 	}
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate #ifdef ZLIB_SHARED
413*2139Sjp161948 #if 0
4140Sstevel@tonic-gate /* Stubs for each function to be dynamicly loaded */
4150Sstevel@tonic-gate static int
4160Sstevel@tonic-gate stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
4170Sstevel@tonic-gate 	{
4180Sstevel@tonic-gate 	if (p_compress)
4190Sstevel@tonic-gate 		return(p_compress(dest,destLen,source,sourceLen));
4200Sstevel@tonic-gate 	else
4210Sstevel@tonic-gate 		return(Z_MEM_ERROR);
4220Sstevel@tonic-gate 	}
423*2139Sjp161948 #endif
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate static int
stub_inflateEnd(z_streamp strm)4260Sstevel@tonic-gate stub_inflateEnd(z_streamp strm)
4270Sstevel@tonic-gate 	{
4280Sstevel@tonic-gate 	if ( p_inflateEnd )
4290Sstevel@tonic-gate 		return(p_inflateEnd(strm));
4300Sstevel@tonic-gate 	else
4310Sstevel@tonic-gate 		return(Z_MEM_ERROR);
4320Sstevel@tonic-gate 	}
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate static int
stub_inflate(z_streamp strm,int flush)4350Sstevel@tonic-gate stub_inflate(z_streamp strm, int flush)
4360Sstevel@tonic-gate 	{
4370Sstevel@tonic-gate 	if ( p_inflate )
4380Sstevel@tonic-gate 		return(p_inflate(strm,flush));
4390Sstevel@tonic-gate 	else
4400Sstevel@tonic-gate 		return(Z_MEM_ERROR);
4410Sstevel@tonic-gate 	}
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate static int
stub_inflateInit_(z_streamp strm,const char * version,int stream_size)4440Sstevel@tonic-gate stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
4450Sstevel@tonic-gate 	{
4460Sstevel@tonic-gate 	if ( p_inflateInit_ )
4470Sstevel@tonic-gate 		return(p_inflateInit_(strm,version,stream_size));
4480Sstevel@tonic-gate 	else
4490Sstevel@tonic-gate 		return(Z_MEM_ERROR);
4500Sstevel@tonic-gate 	}
4510Sstevel@tonic-gate 
452*2139Sjp161948 static int
stub_deflateEnd(z_streamp strm)453*2139Sjp161948 stub_deflateEnd(z_streamp strm)
454*2139Sjp161948 	{
455*2139Sjp161948 	if ( p_deflateEnd )
456*2139Sjp161948 		return(p_deflateEnd(strm));
457*2139Sjp161948 	else
458*2139Sjp161948 		return(Z_MEM_ERROR);
459*2139Sjp161948 	}
460*2139Sjp161948 
461*2139Sjp161948 static int
stub_deflate(z_streamp strm,int flush)462*2139Sjp161948 stub_deflate(z_streamp strm, int flush)
463*2139Sjp161948 	{
464*2139Sjp161948 	if ( p_deflate )
465*2139Sjp161948 		return(p_deflate(strm,flush));
466*2139Sjp161948 	else
467*2139Sjp161948 		return(Z_MEM_ERROR);
468*2139Sjp161948 	}
469*2139Sjp161948 
470*2139Sjp161948 static int
stub_deflateInit_(z_streamp strm,int level,const char * version,int stream_size)471*2139Sjp161948 stub_deflateInit_(z_streamp strm, int level,
472*2139Sjp161948 	const char * version, int stream_size)
473*2139Sjp161948 	{
474*2139Sjp161948 	if ( p_deflateInit_ )
475*2139Sjp161948 		return(p_deflateInit_(strm,level,version,stream_size));
476*2139Sjp161948 	else
477*2139Sjp161948 		return(Z_MEM_ERROR);
478*2139Sjp161948 	}
479*2139Sjp161948 
4800Sstevel@tonic-gate #endif /* ZLIB_SHARED */
481