9 typedef struct Biobuf Biobuf;
18 static int header(Biobuf*);
19 static int trailer(Biobuf*, Biobuf*);
20 static int getc(void*);
21 static ulong offset(Biobuf*);
22 static int crcwrite(void *out, void *buf, int n);
23 static ulong get4(Biobuf *b);
24 static ulong Boffset(Biobuf *bp);
34 GZCRCPOLY = 0xedb88320UL,
41 gunzip(uchar *out, int outn, uchar *in, int inn)
47 crctab = mkcrctab(GZCRCPOLY);
50 print("inflateinit failed: %s\n", flateerr(err));
54 bout.bp = bout.p = out;
61 err = inflate(&bout, crcwrite, &bin, getc);
63 print("inflate failed: %s\n", flateerr(err));
65 err = trailer(&bout, &bin);
69 return Boffset(&bout);
77 if(getc(bin) != 0x1f || getc(bin) != 0x8b){
79 return FlateCorrupted;
82 print("unknown compression type\n");
83 return FlateCorrupted;
98 for(i=getc(bin); i>0; i--)
103 while(getc(bin) != 0)
108 while(getc(bin) != 0)
121 trailer(Biobuf *bout, Biobuf *bin)
128 print("crc mismatch %lux %lux\n", crc, x);
129 return FlateCorrupted;
133 if(get4(bin) != Boffset(bout)){
134 print("bad output len\n");
135 return FlateCorrupted;
147 for(i = 0; i < 4; i++){
159 if((bp->p - bp->bp) % 10000 == 0)
169 return bp->p - bp->bp;
173 crcwrite(void *out, void *buf, int n)
177 crc = blockcrc(crctab, crc, buf, n);
181 memmove(bp->p, buf, n);
189 static ulong ibrkp = ~0;
197 ibrkp = ((ulong)end)+1024*1024;