Annotation of pgp/src/zunzip.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.