inflate.c (3784) | inflate.c (7840) |
---|---|
1/* 2 * Most parts of this file are not covered by: 3 * ---------------------------------------------------------------------------- 4 * "THE BEER-WARE LICENSE" (Revision 42): 5 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you 6 * can do whatever you want with this stuff. If we meet some day, and you think 7 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 8 * ---------------------------------------------------------------------------- 9 * | 1/* 2 * Most parts of this file are not covered by: 3 * ---------------------------------------------------------------------------- 4 * "THE BEER-WARE LICENSE" (Revision 42): 5 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you 6 * can do whatever you want with this stuff. If we meet some day, and you think 7 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 8 * ---------------------------------------------------------------------------- 9 * |
10 * $Id: inflate.c,v 1.3 1994/10/11 11:29:11 csgr Exp $ | 10 * $Id: inflate.c,v 1.4 1994/10/22 11:40:28 phk Exp $ |
11 * 12 * 13 */ 14 15#include <sys/param.h> 16#include <sys/inflate.h> | 11 * 12 * 13 */ 14 15#include <sys/param.h> 16#include <sys/inflate.h> |
17#ifdef KERNEL |
|
17#include <sys/systm.h> | 18#include <sys/systm.h> |
19#endif |
|
18#include <sys/mman.h> 19#include <sys/malloc.h> 20 | 20#include <sys/mman.h> 21#include <sys/malloc.h> 22 |
23#ifdef KERNEL |
|
21#include <vm/vm.h> 22#include <vm/vm_kern.h> | 24#include <vm/vm.h> 25#include <vm/vm_kern.h> |
26#endif |
|
23 24/* needed to make inflate() work */ 25#define uch u_char 26#define ush u_short 27#define ulg u_long 28 29/* Stuff to make inflate() work */ | 27 28/* needed to make inflate() work */ 29#define uch u_char 30#define ush u_short 31#define ulg u_long 32 33/* Stuff to make inflate() work */ |
34#ifdef KERNEL |
|
30#define memzero(dest,len) bzero(dest,len) | 35#define memzero(dest,len) bzero(dest,len) |
36#endif |
|
31#define NOMEMCPY | 37#define NOMEMCPY |
38#ifdef KERNEL |
|
32#define FPRINTF printf | 39#define FPRINTF printf |
40#else 41extern void putstr (char *); 42#define FPRINTF putstr 43#endif |
|
33 34#define FLUSH(x,y) { \ 35 int foo = (*x->gz_output)(x->gz_private,x->gz_slide,y); \ 36 if (foo) \ 37 return foo; \ 38 } 39 40static const int qflag = 0; 41 | 44 45#define FLUSH(x,y) { \ 46 int foo = (*x->gz_output)(x->gz_private,x->gz_slide,y); \ 47 if (foo) \ 48 return foo; \ 49 } 50 51static const int qflag = 0; 52 |
53#ifndef KERNEL /* want to use this file in kzip also */ 54extern unsigned char *malloc (int, int, int); 55extern void free (void*, int); 56#endif 57 |
|
42/* 43 * This came from unzip-5.12. I have changed it the flow to pass 44 * a structure pointer around, thus hopefully making it re-entrant. 45 * Poul-Henning 46 */ 47 48/* inflate.c -- put in the public domain by Mark Adler 49 version c14o, 23 August 1994 */ --- 375 unchanged lines hidden (view full) --- 425 register int w; /* bits before this table == (l * h) */ 426 unsigned x[BMAX + 1]; /* bit offsets, then code stack */ 427 unsigned *xp; /* pointer into x */ 428 int y; /* number of dummy codes added */ 429 unsigned z; /* number of entries in current table */ 430 431 /* Generate counts for each bit length */ 432 el = n > 256 ? b[256] : BMAX; /* set length of EOB code, if any */ | 58/* 59 * This came from unzip-5.12. I have changed it the flow to pass 60 * a structure pointer around, thus hopefully making it re-entrant. 61 * Poul-Henning 62 */ 63 64/* inflate.c -- put in the public domain by Mark Adler 65 version c14o, 23 August 1994 */ --- 375 unchanged lines hidden (view full) --- 441 register int w; /* bits before this table == (l * h) */ 442 unsigned x[BMAX + 1]; /* bit offsets, then code stack */ 443 unsigned *xp; /* pointer into x */ 444 int y; /* number of dummy codes added */ 445 unsigned z; /* number of entries in current table */ 446 447 /* Generate counts for each bit length */ 448 el = n > 256 ? b[256] : BMAX; /* set length of EOB code, if any */ |
449#ifdef KERNEL |
|
433 memzero((char *) c, sizeof(c)); | 450 memzero((char *) c, sizeof(c)); |
451#else 452 for (i = 0; i < BMAX+1; i++) 453 c [i] = 0; 454#endif |
|
434 p = b; 435 i = n; 436 do { 437 c[*p]++; 438 p++; /* assume all entries <= BMAX */ 439 } while (--i); 440 if (c[0] == n) { /* null input--all zero length codes */ 441 *t = (struct huft *) NULL; --- 400 unchanged lines hidden (view full) --- 842 nb = 4 + ((unsigned) b & 0xf); /* number of bit length codes */ 843 DUMPBITS(4) 844#ifdef PKZIP_BUG_WORKAROUND 845 if (nl > 288 || nd > 32) 846#else 847 if (nl > 286 || nd > 30) 848#endif 849 return 1; /* bad lengths */ | 455 p = b; 456 i = n; 457 do { 458 c[*p]++; 459 p++; /* assume all entries <= BMAX */ 460 } while (--i); 461 if (c[0] == n) { /* null input--all zero length codes */ 462 *t = (struct huft *) NULL; --- 400 unchanged lines hidden (view full) --- 863 nb = 4 + ((unsigned) b & 0xf); /* number of bit length codes */ 864 DUMPBITS(4) 865#ifdef PKZIP_BUG_WORKAROUND 866 if (nl > 288 || nd > 32) 867#else 868 if (nl > 286 || nd > 30) 869#endif 870 return 1; /* bad lengths */ |
850 | |
851 /* read in bit-length-code lengths */ 852 for (j = 0; j < nb; j++) { 853 NEEDBITS(glbl, 3) 854 ll[border[j]] = (unsigned) b & 7; 855 DUMPBITS(3) 856 } 857 for (; j < 19; j++) 858 ll[border[j]] = 0; --- 115 unchanged lines hidden (view full) --- 974 975 /* inflate that block type */ 976 if (t == 2) 977 return inflate_dynamic(glbl); 978 if (t == 0) 979 return inflate_stored(glbl); 980 if (t == 1) 981 return inflate_fixed(glbl); | 871 /* read in bit-length-code lengths */ 872 for (j = 0; j < nb; j++) { 873 NEEDBITS(glbl, 3) 874 ll[border[j]] = (unsigned) b & 7; 875 DUMPBITS(3) 876 } 877 for (; j < 19; j++) 878 ll[border[j]] = 0; --- 115 unchanged lines hidden (view full) --- 994 995 /* inflate that block type */ 996 if (t == 2) 997 return inflate_dynamic(glbl); 998 if (t == 0) 999 return inflate_stored(glbl); 1000 if (t == 1) 1001 return inflate_fixed(glbl); |
982 | |
983 /* bad block type */ 984 return 2; 985} 986 987 988 989/* decompress an inflated entry */ 990static int --- 23 unchanged lines hidden (view full) --- 1014 1015 /* flush out slide */ 1016 FLUSH(glbl, glbl->gz_wp); 1017 1018 /* return success */ 1019 return 0; 1020} 1021 | 1002 /* bad block type */ 1003 return 2; 1004} 1005 1006 1007 1008/* decompress an inflated entry */ 1009static int --- 23 unchanged lines hidden (view full) --- 1033 1034 /* flush out slide */ 1035 FLUSH(glbl, glbl->gz_wp); 1036 1037 /* return success */ 1038 return 0; 1039} 1040 |
1022 | |
1023/* Nobody uses this - why not? */ 1024int 1025inflate(glbl) 1026 struct inflate *glbl; 1027{ 1028 int i; | 1041/* Nobody uses this - why not? */ 1042int 1043inflate(glbl) 1044 struct inflate *glbl; 1045{ 1046 int i; |
1047#ifdef KERNEL |
|
1029 u_char *p = NULL; 1030 1031 if (!glbl->gz_slide) 1032 p = glbl->gz_slide = malloc(GZ_WSIZE, M_GZIP, M_WAITOK); | 1048 u_char *p = NULL; 1049 1050 if (!glbl->gz_slide) 1051 p = glbl->gz_slide = malloc(GZ_WSIZE, M_GZIP, M_WAITOK); |
1033 | 1052#endif |
1034 if (!glbl->gz_slide) | 1053 if (!glbl->gz_slide) |
1054#ifdef KERNEL |
|
1035 return(ENOMEM); | 1055 return(ENOMEM); |
1036 | 1056#else 1057 return 3; /* kzip expects 3 */ 1058#endif |
1037 i = xinflate(glbl); 1038 1039 if (glbl->gz_fixed_td != (struct huft *) NULL) { 1040 huft_free(glbl, glbl->gz_fixed_td); 1041 glbl->gz_fixed_td = (struct huft *) NULL; 1042 } 1043 if (glbl->gz_fixed_tl != (struct huft *) NULL) { 1044 huft_free(glbl, glbl->gz_fixed_tl); 1045 glbl->gz_fixed_tl = (struct huft *) NULL; 1046 } | 1059 i = xinflate(glbl); 1060 1061 if (glbl->gz_fixed_td != (struct huft *) NULL) { 1062 huft_free(glbl, glbl->gz_fixed_td); 1063 glbl->gz_fixed_td = (struct huft *) NULL; 1064 } 1065 if (glbl->gz_fixed_tl != (struct huft *) NULL) { 1066 huft_free(glbl, glbl->gz_fixed_tl); 1067 glbl->gz_fixed_tl = (struct huft *) NULL; 1068 } |
1069#ifdef KERNEL |
|
1047 if (p == glbl->gz_slide) { 1048 free(glbl->gz_slide, M_GZIP); 1049 glbl->gz_slide = NULL; 1050 } | 1070 if (p == glbl->gz_slide) { 1071 free(glbl->gz_slide, M_GZIP); 1072 glbl->gz_slide = NULL; 1073 } |
1051 | 1074#endif |
1052 return i; 1053} 1054/* ----------------------- END INFLATE.C */ | 1075 return i; 1076} 1077/* ----------------------- END INFLATE.C */ |