ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/OptIO/src/rzipunzip.c
Revision: 1.2
Committed: Tue Feb 24 20:13:57 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.1: +122 -17 lines
Log Message:
Added lzma

File Contents

# User Rev Content
1 loizides 1.2 // $Id: rzipunzip.c,v 1.1 2009/02/24 11:56:44 loizides Exp $
2 loizides 1.1
3     #include "MitCommon/OptIO/src/rzipunzip.h"
4     #include "MitCommon/OptIO/src/zlib.h"
5     #include "MitCommon/OptIO/src/bzlib.h"
6     #include "MitCommon/OptIO/src/lzo/lzo1x.h"
7     #include "MitCommon/OptIO/src/rle.h"
8 loizides 1.2 #include "MitCommon/OptIO/src/LzmaEnc.h"
9     #include "MitCommon/OptIO/src/LzmaDec.h"
10 loizides 1.1
11     #include <stdio.h>
12     #include <stdlib.h>
13     #include <string.h>
14    
15     #ifndef HDRSIZE
16     #define HDRSIZE 9
17     #else
18     #error "HDRSIZE already defined."
19     #endif
20    
21     #ifndef MYSIZE
22     #define MYSIZE 5*1024*1024
23     #else
24     #error "MYSIZE already defined."
25     #endif
26    
27     typedef unsigned char uch; /* code assumes unsigned bytes; these type- */
28    
29     extern int R__ZipMode;
30     char mymem[MYSIZE];
31     char *myptr = mymem;
32    
33     // the following can be changed using the OptInt interface
34     double lzipfrac = 1;
35     double gzipfrac = 1;
36     double bzipfrac = 1;
37 loizides 1.2 double lzmafrac = 1;
38 loizides 1.1 int myverbose = 0;
39     int mystaticm = 0;
40    
41     //--------------------------------------------------------------------------------------------------
42     void *mymalloc(size_t size)
43     {
44     if(!mystaticm || size>MYSIZE)
45     return malloc(size);
46    
47     if(myptr-mymem>MYSIZE-size) {
48     myptr=mymem;
49     }
50    
51     void *v=(void*)myptr;
52     myptr+=size;
53     return v;
54     }
55    
56     //--------------------------------------------------------------------------------------------------
57 loizides 1.2 void mymfree(void *ptr)
58 loizides 1.1 {
59     if (mystaticm && (char*)ptr>=mymem && (char*)ptr<mymem+MYSIZE)
60     return;
61     free(ptr);
62     }
63    
64 loizides 1.2 // memory handle functions
65     static void *SzAlloc(void *p, size_t size) { p = p; return mymalloc(size); }
66     static void SzFree(void *p, void *address) { p = p; mymfree(address); }
67     static ISzAlloc g_Alloc = { SzAlloc, SzFree };
68    
69 loizides 1.1 //--------------------------------------------------------------------------------------------------
70     void R__zip(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep)
71     /* int cxlevel; compression level */
72     /* int *srcsize, *tgtsize, *irep; source and target sizes, replay */
73     /* char *tgt, *src; source and target buffers */
74     {
75     int err = 0;
76     int method = 0;
77     unsigned int in_size = 0;
78     unsigned int out_size = 0;
79    
80     if (*tgtsize <= HDRSIZE) {
81     R__error("target buffer too small");
82     return;
83     }
84     if (*srcsize > 0xffffff) {
85     R__error("source buffer too big");
86     return;
87     }
88    
89     *irep = 0;
90     in_size = (unsigned)(*srcsize); /* decompressed size */
91     char *tgtptr = tgt+HDRSIZE; /* compress data */
92    
93 loizides 1.2 if (R__ZipMode == 99) { /*determine best of all methods*/
94 loizides 1.1 int cont = 1;
95     int msize = -1;
96     int zmode = -1;
97     int tgtlen = 2*in_size+64*1024;
98     char *mptr1 = mymalloc(tgtlen);
99     char *mptr2 = mymalloc(tgtlen);
100     char *mptr = 0;
101     char *mdum = 0;
102    
103     if (cont) {
104     zmode = 4;
105     msize = RLE_Compress(src, mptr1, in_size);
106     mptr = mptr1;
107     mdum = mptr2;
108     }
109    
110     if (cont && lzipfrac>0) {
111     err = lzo_init();
112     if ( err == LZO_E_OK) {
113     lzo_uint outlen = tgtlen;
114     char *lwmem = mymalloc(LZO1X_999_MEM_COMPRESS);
115     err = lzo1x_999_compress(src,in_size,mdum,&outlen,lwmem);
116     if (err == LZO_E_OK) {
117     if (outlen<lzipfrac*msize) {
118     msize = outlen;
119     zmode = 3;
120     char *tmp = mptr;
121     mptr = mdum;
122     mdum = tmp;
123     }
124     }
125 loizides 1.2 mymfree(lwmem);
126 loizides 1.1 }
127     }
128    
129     if (cont && gzipfrac>0) {
130 loizides 1.2 int outlen = *tgtsize;
131 loizides 1.1 z_stream stream;
132     stream.next_in = (Bytef*)src;
133     stream.avail_in = (uInt)(in_size);
134     stream.next_out = (Bytef*)(mdum);
135 loizides 1.2 stream.avail_out = (uInt)(outlen);
136 loizides 1.1 stream.zalloc = (alloc_func)0;
137     stream.zfree = (free_func)0;
138     stream.opaque = (voidpf)0;
139    
140     err = deflateInit(&stream, cxlevel);
141     if (err == Z_OK) {
142     err = deflate(&stream, Z_FINISH);
143     if (err == Z_STREAM_END) {
144     err = deflateEnd(&stream);
145     int outlen = stream.total_out;
146     if (outlen<gzipfrac*msize) {
147     msize = outlen;
148     zmode = 1;
149     char *tmp = mptr;
150     mptr = mdum;
151     mdum = tmp;
152     }
153     }
154     }
155     }
156    
157     if (cont && bzipfrac>0) {
158 loizides 1.2 int outlen = *tgtsize;
159 loizides 1.1 bz_stream stream;
160     stream.next_in = src;
161     stream.avail_in = (uInt)(in_size);
162     stream.next_out = mdum;
163 loizides 1.2 stream.avail_out = (uInt)(outlen);
164 loizides 1.1 stream.bzalloc = 0;
165     stream.bzfree = 0;
166     stream.opaque = 0;
167    
168     err = BZ2_bzCompressInit(&stream, 9, 0, 1);
169     if (err == BZ_OK) {
170     err = BZ2_bzCompress(&stream, BZ_FINISH);
171     if (err == BZ_STREAM_END) {
172     BZ2_bzCompressEnd(&stream);
173     }
174     int outlen = stream.total_out_lo32;
175     if (outlen<bzipfrac*msize) {
176     msize = outlen;
177     zmode = 2;
178     char *tmp = mptr;
179     mptr = mdum;
180     mdum = tmp;
181     }
182     }
183     }
184 loizides 1.2 if (cont && lzmafrac>0) {
185     CLzmaEncHandle enc = LzmaEnc_Create(&g_Alloc);
186     if (enc) {
187     CLzmaEncProps props;
188     LzmaEncProps_Init(&props);
189     props.level = cxlevel;
190     props.dictSize = (1<<16);
191     SRes res = LzmaEnc_SetProps(enc, &props);
192     if (res == SZ_OK) {
193     SizeT outlen = *tgtsize;
194     res = LzmaEnc_MemEncode(enc, tgtptr, &outlen, src, in_size,
195     0, NULL, &g_Alloc, &g_Alloc);
196     if (res == SZ_OK) {
197     LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
198     if (outlen<lzmafrac*msize) {
199     msize = outlen;
200     zmode = 5;
201     char *tmp = mptr;
202     mptr = mdum;
203     mdum = tmp;
204     }
205     }
206     }
207     }
208     }
209 loizides 1.1
210 loizides 1.2 // determine best candidate
211 loizides 1.1 if (msize>=in_size) {
212     out_size = in_size;
213     memcpy(tgtptr,src,out_size);
214     tgt[0] = 'X'; /* signature xx */
215     tgt[1] = 'X';
216     method = 0;
217     } else {
218     switch (zmode) {
219     case 1:
220     tgt[0] = 'Z'; /* signature zlib */
221     tgt[1] = 'L';
222     method = Z_DEFLATED; //==8
223     break;
224     case 2:
225     tgt[0] = 'B'; /* signature bzlib */
226     tgt[1] = 'Z';
227     method = 2;
228     break;
229     case 3:
230     tgt[0] = 'L'; /* signature lzolib */
231     tgt[1] = 'O';
232     method = 19;
233     break;
234     case 4:
235     tgt[0] = 'R'; /* signature rlelib */
236     tgt[1] = 'E';
237     method = 4;
238 loizides 1.2 case 5:
239     tgt[0] = 'L'; /* signature lzma */
240     tgt[1] = 'M';
241     method = 3;
242 loizides 1.1 break;
243     }
244     out_size = msize;
245     memcpy(tgtptr,mptr,out_size);
246     }
247 loizides 1.2 mymfree(mptr1);
248     mymfree(mptr2);
249     } else if (R__ZipMode == 5) { /*lzma*/
250     CLzmaEncHandle enc = LzmaEnc_Create(&g_Alloc);
251     if (enc == 0) {
252     printf("error %d - LzmaEnc_Create()\n", SZ_ERROR_MEM);
253     return;
254     }
255     CLzmaEncProps props;
256     LzmaEncProps_Init(&props);
257     props.level = cxlevel;
258     props.dictSize = (1<<16);
259     SRes res = LzmaEnc_SetProps(enc, &props);
260     if (res != SZ_OK) {
261     printf("error %d - LzmaEnc_SetProps()\n", res);
262     return;
263     }
264     res = LzmaEnc_MemEncode(enc, tgtptr, tgtsize, src, in_size,
265     0, NULL, &g_Alloc, &g_Alloc);
266     if (res != SZ_OK) {
267     printf("error %d - LzmaEnc_MemEncode", res);
268     return;
269     }
270     LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
271     out_size = *tgtsize; /* compressed size */
272     if (out_size>=lzmafrac*in_size) {
273     out_size = in_size;
274     memcpy(tgtptr,src,out_size);
275     tgt[0] = 'X'; /* signature xx */
276     tgt[1] = 'X';
277     method = 0;
278     } else {
279     tgt[0] = 'L'; /* signature lzma */
280     tgt[1] = 'M';
281     method = 3;
282     }
283 loizides 1.1 } else if (R__ZipMode == 4) { /*rle*/
284     int tgtlen = 2*in_size+1;
285     char *lmem1 = mymalloc(tgtlen);
286    
287     out_size = RLE_Compress(src, lmem1, in_size);
288     if (out_size>=in_size) {
289     out_size = in_size;
290     memcpy(tgtptr,src,out_size);
291     tgt[0] = 'X'; /* signature xx */
292     tgt[1] = 'X';
293     method = 0;
294     } else {
295     memcpy(tgtptr,lmem1,out_size);
296     tgt[0] = 'R'; /* signature rlelib */
297     tgt[1] = 'E';
298     method = 4;
299     }
300 loizides 1.2 mymfree(lmem1);
301 loizides 1.1 } else if (R__ZipMode == 3) { /*lzo*/
302     err = lzo_init();
303     if ( err != LZO_E_OK) {
304     printf("error %d - lzo_init()\n", err);
305 loizides 1.2 return;
306 loizides 1.1 }
307    
308     lzo_uint tgtlen = 2*in_size+64*1024;
309     char *lmem1 = mymalloc(tgtlen);
310     char *lmem2 = 0;
311     if (cxlevel<=1) {
312     lmem2 = mymalloc(LZO1X_1_11_MEM_COMPRESS);
313     err = lzo1x_1_11_compress(src,in_size,lmem1,&tgtlen,lmem2);
314     method = 11;
315     } else if (cxlevel==2) {
316     lmem2 = mymalloc(LZO1X_1_12_MEM_COMPRESS);
317     err = lzo1x_1_12_compress(src,in_size,lmem1,&tgtlen,lmem2);
318     method = 12;
319     } else if (cxlevel<=5) {
320     lmem2 = mymalloc(LZO1X_1_15_MEM_COMPRESS);
321     err = lzo1x_1_15_compress(src,in_size,lmem1,&tgtlen,lmem2);
322     method = 15;
323     } else {
324     lmem2 = mymalloc(LZO1X_999_MEM_COMPRESS);
325     err = lzo1x_999_compress(src,in_size,lmem1,&tgtlen,lmem2);
326     method = 19;
327     }
328     if (err != LZO_E_OK) {
329 loizides 1.2 mymfree(lmem1);
330     mymfree(lmem2);
331 loizides 1.1 return;
332     }
333    
334     if (tgtlen>=lzipfrac*in_size) {
335     out_size = in_size;
336     memcpy(tgtptr,src,out_size);
337     tgt[0] = 'X'; /* signature xx */
338     tgt[1] = 'X';
339     method = 0;
340     } else {
341     out_size = tgtlen; /* compressed size */
342     memcpy(tgtptr,lmem1,out_size);
343     tgt[0] = 'L'; /* signature lzolib */
344     tgt[1] = 'O';
345     }
346 loizides 1.2 mymfree(lmem1);
347     mymfree(lmem2);
348 loizides 1.1 } else if (R__ZipMode == 2) { /*bzip*/
349     bz_stream stream;
350     stream.next_in = src;
351     stream.avail_in = (uInt)(in_size);
352     stream.next_out = tgtptr;
353     stream.avail_out = (uInt)(*tgtsize);
354     stream.bzalloc = 0;
355     stream.bzfree = 0;
356     stream.opaque = 0;
357    
358     err = BZ2_bzCompressInit(&stream, 9, 0, 1+(9-cxlevel)*25);
359     if (err != BZ_OK) {
360     printf("error %d in BZ2_bzCompressInit (bzlib)\n",err);
361     return;
362     }
363     err = BZ2_bzCompress(&stream, BZ_FINISH);
364     if (err != BZ_STREAM_END) {
365     BZ2_bzCompressEnd(&stream);
366     //printf("error %d in BZ2_bzCompress (bzlib) is not = %d\n",err,BZ_STREAM_END);
367     return;
368     }
369     err = BZ2_bzCompressEnd(&stream);
370    
371     out_size = stream.total_out_lo32; /* compressed size */
372     if (out_size>=bzipfrac*in_size) {
373     out_size = in_size;
374     memcpy(tgtptr,src,out_size);
375     tgt[0] = 'X'; /* signature xx */
376     tgt[1] = 'X';
377     method = 0;
378     } else {
379     tgt[0] = 'B'; /* signature bzlib */
380     tgt[1] = 'Z';
381     method = 2;
382     }
383     } else if (R__ZipMode == 1) { /*zip*/
384     z_stream stream;
385     stream.next_in = (Bytef*)src;
386     stream.avail_in = (uInt)(in_size);
387     stream.next_out = (Bytef*)(tgtptr);
388     stream.avail_out = (uInt)(*tgtsize);
389     stream.zalloc = (alloc_func)0;
390     stream.zfree = (free_func)0;
391     stream.opaque = (voidpf)0;
392    
393     err = deflateInit(&stream, cxlevel);
394     if (err != Z_OK) {
395     printf("error %d in deflateInit (zlib)\n",err);
396     return;
397     }
398     err = deflate(&stream, Z_FINISH);
399     if (err != Z_STREAM_END) {
400     deflateEnd(&stream);
401     //printf("error %d in deflate (zlib) is not = %d\n",err,Z_STREAM_END);
402     return;
403     }
404     err = deflateEnd(&stream);
405    
406     out_size = stream.total_out; /* compressed size */
407     if (out_size>=gzipfrac*in_size) {
408     out_size = in_size;
409     memcpy(tgtptr,src,out_size);
410     tgt[0] = 'X'; /* signature xx */
411     tgt[1] = 'X';
412     method = 0;
413     } else {
414     tgt[0] = 'Z'; /* signature zlib */
415     tgt[1] = 'L';
416     method = Z_DEFLATED;
417     }
418     } else if (R__ZipMode == 0) {
419     printf("error: Old zip method not supported in this patch.");
420     return;
421     }
422    
423     // fill rest of header
424     tgt[2] = (char)method;
425     tgt[3] = (char)(out_size & 0xff);
426     tgt[4] = (char)((out_size >> 8) & 0xff);
427     tgt[5] = (char)((out_size >> 16) & 0xff);
428     tgt[6] = (char)(in_size & 0xff);
429     tgt[7] = (char)((in_size >> 8) & 0xff);
430     tgt[8] = (char)((in_size >> 16) & 0xff);
431     *irep = out_size + HDRSIZE;
432    
433     if (myverbose==1||myverbose>9) {
434     printf("R__zip:: zm=%d m=%d cl=%d: %c%c compressed %lu bytes into %lu bytes -> %.3f%%\n",
435     R__ZipMode, method, cxlevel, tgt[0], tgt[1],
436     (unsigned long)in_size, (unsigned long)out_size, (double)out_size/in_size*100.);
437     }
438     }
439    
440     //--------------------------------------------------------------------------------------------------
441     void R__unzip(int *srcsize, uch *src, int *tgtsize, uch *tgt, int *irep)
442     /* Input: scrsize - size of input buffer */
443     /* src - input buffer */
444     /* tgtsize - size of target buffer */
445     /* Output: tgt - target buffer (decompressed) */
446     /* irep - size of decompressed data */
447     /* 0 - if error */
448     {
449     unsigned int osize = 0;
450     unsigned int ibufcnt = 0, obufcnt = 0;
451     uch *ibufptr = 0, *obufptr = 0;
452     *irep = 0L;
453    
454     /* C H E C K H E A D E R */
455     if (*srcsize < HDRSIZE) {
456     fprintf(stderr,"R__unzip: too small source\n");
457     return;
458     }
459    
460     char method = src[2];
461 loizides 1.2 if (method!=0 && method!= 2 && method!= 3 && method!= 4 && method!=Z_DEFLATED &&
462     method!=11 && method!=12 && method!=15 && method!=19) {
463 loizides 1.1 fprintf(stderr,"R__unzip: error in header -> unknown method %d\n", method);
464     return;
465     }
466    
467     if ((method==0 && (src[0] != 'X' || src[1] != 'X')) ||
468     (method==2 && (src[0] != 'B' || src[1] != 'Z')) ||
469 loizides 1.2 (method==3 && (src[0] != 'L' || src[1] != 'M')) ||
470 loizides 1.1 (method==4 && (src[0] != 'R' || src[1] != 'E')) ||
471     (method==Z_DEFLATED && ((src[0] != 'C' || src[1] != 'S') &&
472     (src[0] != 'Z' || src[1] != 'L'))) ||
473     ((method==11 || method==12 || method==15 || method==19) &&
474     (src[0] != 'L' || src[1] != 'O'))) {
475     fprintf(stderr,"R__unzip: error in header -> m=%d with %c%c\n",
476     method, src[0], src[1]);
477     return;
478     }
479    
480     ibufptr = src + HDRSIZE;
481     ibufcnt = (unsigned int)src[3] | ((unsigned int)src[4] << 8) | ((unsigned int)src[5] << 16);
482     osize = (unsigned int)src[6] | ((unsigned int)src[7] << 8) | ((unsigned int)src[8] << 16);
483     obufptr = tgt;
484     obufcnt = *tgtsize;
485    
486     if (obufcnt < osize) {
487     fprintf(stderr,"R__unzip: too small target\n");
488     return;
489     }
490    
491     if (ibufcnt + HDRSIZE != *srcsize) {
492     fprintf(stderr,"R__unzip: discrepancy in source length\n");
493     return;
494     }
495    
496     if (myverbose==2 || myverbose>9) {
497     printf("R__unzip:: zm=%d m=%d: %c%c uncompressed %lu bytes from %lu bytes (%.3f%%)\n",
498     R__ZipMode, method, src[0], src[1], osize, ibufcnt, (double)ibufcnt/osize*100.);
499     }
500    
501     if (method==0) { // apparently this is not reached since underlying ROOT code catches this
502     if (ibufcnt!=osize) {
503     fprintf(stderr,"R__unzip: error in header -> input should be output %d!=%d\n",
504     ibufcnt, osize);
505     return;
506     }
507     memcpy(obufptr,ibufptr,osize);
508     *irep = obufcnt;
509     return;
510     }
511    
512     /* D E C O M P R E S S D A T A */
513 loizides 1.2
514     if (src[0] == 'L' && src[1] == 'M') { /* lzma format */
515     CLzmaEncHandle enc = LzmaEnc_Create(&g_Alloc);
516     if (enc == 0) {
517     printf("error %d - LzmaEnc_Create()\n", SZ_ERROR_MEM);
518     return;
519     }
520     CLzmaEncProps props;
521     LzmaEncProps_Init(&props);
522     //props.level = cxlevel;
523     props.dictSize = (1<<16);
524     SRes res = LzmaEnc_SetProps(enc, &props);
525     if (res != SZ_OK) {
526     printf("error %d - LzmaEnc_SetProps()\n", res);
527     return;
528     }
529     size_t hsize = LZMA_PROPS_SIZE;
530     char *hptr = mymalloc(hsize);
531     res = LzmaEnc_WriteProperties(enc, hptr, &hsize);
532     if (res != SZ_OK) {
533     printf("error %d - LzmaEnc_WriteProperties()\n", res);
534     return;
535     }
536    
537     SizeT new_len = obufcnt;
538     ELzmaStatus status;
539     res = LzmaDecode(obufptr, &obufcnt, ibufptr, &new_len, hptr, hsize,
540     LZMA_FINISH_END, &status, &g_Alloc);
541     mymfree(hptr);
542     *irep = obufcnt;
543     } else if (src[0] == 'R' && src[1] == 'E') { /* rle format */
544 loizides 1.1 RLE_Uncompress(ibufptr, obufptr, ibufcnt);
545     *irep = obufcnt;
546     return;
547     } else if (src[0] == 'L' && src[1] == 'O') { /* lolib format */
548    
549     int err = lzo_init();
550     if ( err != LZO_E_OK) {
551     fprintf(stderr,"R__unzip: error %d in lzo_init (lzolib)\n",err);
552     return;
553     }
554     lzo_uint new_len = obufcnt;
555     err = lzo1x_decompress(ibufptr,ibufcnt,obufptr,&new_len, NULL);
556     if ((err != LZO_E_OK) || (new_len!=osize)) {
557     fprintf(stderr,"R__unzip: error %d (%d,%d) in lzo1x_decompress (lzolib)\n",
558     err, new_len, osize);
559     return;
560     }
561     *irep = obufcnt;
562     return;
563     } else if (src[0] == 'B' && src[1] == 'Z') { /* bzlib format */
564     bz_stream stream; /* decompression stream */
565     stream.next_in = ibufptr;
566     stream.avail_in = ibufcnt;
567     stream.next_out = obufptr;
568     stream.avail_out = obufcnt;
569     stream.bzalloc = 0;//my_balloc;
570     stream.bzfree = 0;//my_bfree;
571     stream.opaque = 0;
572    
573     int err = BZ2_bzDecompressInit(&stream,0,0);
574     if (err != BZ_OK) {
575     fprintf(stderr,"R__unzip: error %d in BZ2_bzDecompressInit (bzlib)\n",err);
576     return;
577     }
578     err = BZ2_bzDecompress(&stream);
579     if (err != BZ_STREAM_END) {
580     fprintf(stderr,"R__unzip: error %d inBZ2_bzDecompress (bzlib)\n",err);
581     BZ2_bzDecompressEnd(&stream);
582     return;
583     }
584     BZ2_bzDecompressEnd(&stream);
585     *irep = stream.total_out_lo32;
586     return;
587     } else if (src[0] == 'Z' && src[1] == 'L') { /* zlib format */
588     z_stream stream; /* decompression stream */
589     stream.next_in = (Bytef*)(&src[HDRSIZE]);
590     stream.avail_in = (uInt)(*srcsize);
591     stream.next_out = (Bytef*)tgt;
592     stream.avail_out = (uInt)(*tgtsize);
593     stream.zalloc = 0; // my_zalloc;
594     stream.zfree = 0; //my_zfree;
595     stream.opaque = (voidpf)0;
596    
597     int err = inflateInit(&stream);
598     if (err != Z_OK) {
599     fprintf(stderr,"R__unzip: error %d in inflateInit (zlib)\n",err);
600     return;
601     }
602     err = inflate(&stream, Z_FINISH);
603     if (err != Z_STREAM_END) {
604     inflateEnd(&stream);
605     fprintf(stderr,"R__unzip: error %d in inflate (zlib)\n",err);
606     return;
607     }
608     inflateEnd(&stream);
609     *irep = stream.total_out;
610     return;
611     } else if (src[0] == 'C' && src[1] == 'S') { /* old zlib format */
612     if (R__Inflate(&ibufptr, &ibufcnt, &obufptr, &obufcnt)) {
613     fprintf(stderr,"R__unzip: error during decompression\n");
614     return;
615     }
616    
617     /* if (obufptr - tgt != osize) {
618     There are some rare cases when a few more bytes are required */
619     if (obufptr - tgt > *tgtsize) {
620     fprintf(stderr,"R__unzip: discrepancy (%ld) with initial size: %ld, tgtsize=%d\n",
621     (long)(obufptr - tgt),osize,*tgtsize);
622     *irep = obufptr - tgt;
623     return;
624     }
625     *irep = osize;
626     } else {
627     fprintf(stderr,"R__unzip: Format not supported -> m=%d with %d%d", method, src[0], src[1]);
628     return;
629     }
630     }