|
|
1.1.1.5 root 1: /*---------------------------------------------------------------------------
2:
3: unzip.c
4:
5: Highly butchered minimum unzip code for inflate.c
6:
7: ---------------------------------------------------------------------------*/
8:
9: #include "zunzip.h" /* includes, defines, and macros */
10:
11: #define VERSION "v4.20p BETA of 2-18-92"
12:
13: /**********************/
14: /* Global Variables */
15: /**********************/
16:
17: #if 0
18: longint csize; /* used by list_files(), ReadByte(): must be signed */
1.1.1.6 ! root 19: static longint ucsize; /* used by list_files(), unReduce(),
! 20: unImplode() */
1.1.1.5 root 21: #endif
22:
23: ULONG mask_bits[] =
24: {0x00000000L,
25: 0x00000001L, 0x00000003L, 0x00000007L, 0x0000000fL,
26: 0x0000001fL, 0x0000003fL, 0x0000007fL, 0x000000ffL,
27: 0x000001ffL, 0x000003ffL, 0x000007ffL, 0x00000fffL,
28: 0x00001fffL, 0x00003fffL, 0x00007fffL, 0x0000ffffL,
29: 0x0001ffffL, 0x0003ffffL, 0x0007ffffL, 0x000fffffL,
30: 0x001fffffL, 0x003fffffL, 0x007fffffL, 0x00ffffffL,
31: 0x01ffffffL, 0x03ffffffL, 0x07ffffffL, 0x0fffffffL,
32: 0x1fffffffL, 0x3fffffffL, 0x7fffffffL, 0xffffffffL};
33:
34: /*---------------------------------------------------------------------------
35: Input file variables:
36: ---------------------------------------------------------------------------*/
37:
1.1.1.6 ! root 38: byte *inbuf = NULL, *inptr; /* input buffer (any size is legal)
! 39: and pointer */
1.1.1.5 root 40: int incnt;
41:
42: ULONG bitbuf;
43: int bits_left;
44: boolean zipeof;
45:
46: int zipfd; /* zipfile file handle */
47:
48: /*---------------------------------------------------------------------------
49: Output stream variables:
50: ---------------------------------------------------------------------------*/
51:
52: byte *outbuf; /* buffer for rle look-back */
53: byte *outptr;
54: byte *outout; /* scratch pad for ASCII-native trans */
55: longint outpos; /* absolute position in outfile */
56: int outcnt; /* current position in outbuf */
57: int outfd;
58:
59: /*---------------------------------------------------------------------------
60: unzip.c static global variables (visible only within this file):
61: ---------------------------------------------------------------------------*/
62:
63: static byte *hold;
64:
65: /*******************/
66: /* Main unzip code */
67: /*******************/
68:
1.1.1.6 ! root 69: int unzip( FILE *inFile, FILE *outFile ) /* return PK-type error code
! 70: (except under VMS) */
1.1.1.5 root 71: {
72: int status = 0;
73: outfd = fileno( outFile );
74: zipfd = fileno( inFile );
75:
1.1.1.6 ! root 76: inbuf = (byte *) (malloc(INBUFSIZ + 4)); /* 4 extra for hold[]
! 77: (below) */
! 78: outbuf = (byte *) (malloc(OUTBUFSIZ + 1)); /* 1 extra for string
! 79: termination */
1.1.1.5 root 80: outout = outbuf; /* else just point to outbuf */
81:
82: if ((inbuf == NULL) || (outbuf == NULL) || (outout == NULL)) {
83: fprintf(stderr, "error: can't allocate unzip buffers\n");
84: RETURN(4); /* 4-8: insufficient memory */
85: }
1.1.1.6 ! root 86: hold = &inbuf[INBUFSIZ]; /* to check for boundary-spanning
! 87: signatures */
1.1.1.5 root 88:
89: bits_left = 0;
90: bitbuf = 0;
91: outpos = 0L;
92: outcnt = 0;
93: outptr = outbuf;
94: zipeof = 0;
95:
96: /* Set output buffer to initial value */
97: memset(outbuf, 0, OUTBUFSIZ);
98:
99: /* Go from high- to low-level I/O */
100: lseek( zipfd, ftell(inFile), SEEK_SET );
101:
102: if ((incnt = read(zipfd, (char *) inbuf,INBUFSIZ)) <= 0) {
103: fprintf(stderr, "error: unexpected end if input");
104: status = -1; /* can still do next file */
105: }
106: inptr = inbuf;
107:
108: #if 0
109: /* Read in implode information */
110: csize = 1000L; /* Dummy size just to get input bits */
111:
112: /* Get compressed, uncompressed file sizes */
113: csize = ucsize = 1000000000L; /* Make sure we can read in anything */
114: #endif
115: if (status == 0)
116: status = inflate(); /* Ftoomschk! */
117:
118: /* Flush output buffer before returning */
119: if (status == 0 && FlushOutput())
120: status = -1;
121: free(inbuf);
122: free(outbuf);
123: inbuf = outbuf = outout = NULL;
124: return(status);
125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.