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

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

unix.superglobalmegacorp.com

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