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

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

unix.superglobalmegacorp.com

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