Annotation of pgp/src/zfile_io.c, revision 1.1.1.4

1.1.1.4 ! root        1: /*---------------------------------------------------------------------------
        !             2: 
        !             3:   file_io.c
        !             4: 
        !             5:   This file contains routines for doing direct input/output, file-related
        !             6:   sorts of things.  Most of the system-specific code for unzip is contained
        !             7:   here, including the non-echoing password code for decryption (bottom).
        !             8: 
        !             9:   Modified: 24 Jun 92 - HAJK
        !            10:   Fix VMS support
        !            11:   ---------------------------------------------------------------------------*/
        !            12: 
        !            13: 
        !            14: #include "zunzip.h"
        !            15: 
        !            16: #if 0
        !            17: /****************************/
        !            18: /* Function FillBitBuffer() */
        !            19: /****************************/
        !            20: 
        !            21: int FillBitBuffer()
        !            22: {
        !            23:     /*
        !            24:      * Fill bitbuf, which is 32 bits.  This function is only used by the
        !            25:      * READBIT and PEEKBIT macros (which are used by all of the uncompression
        !            26:      * routines).
        !            27:      */
        !            28:     UWORD temp;
        !            29: 
        !            30:     zipeof = 1;
        !            31:     while (bits_left < 25 && ReadByte(&temp) == 8)
        !            32:     {
        !            33:       bitbuf |= (ULONG)temp << bits_left;
        !            34:       bits_left += 8;
        !            35:       zipeof = 0;
        !            36:     }
        !            37:     return 0;
        !            38: }
        !            39: 
        !            40: /***********************/
        !            41: /* Function ReadByte() */
        !            42: /***********************/
        !            43: 
        !            44: int ReadByte(x)
        !            45: UWORD *x;
        !            46: {
        !            47:     /*
        !            48:      * read a byte; return 8 if byte available, 0 if not
        !            49:      */
        !            50: 
        !            51: 
        !            52:     if (csize-- <= 0)
        !            53:        return 0;
        !            54: 
        !            55:     if (incnt == 0) {
        !            56:        if ((incnt = read(zipfd, (char *) inbuf, INBUFSIZ)) <= 0)
        !            57:            return 0;
        !            58:        /* buffer ALWAYS starts on a block boundary:  */
        !            59:        inptr = inbuf;
        !            60:     }
        !            61:     *x = *inptr++;
        !            62:     --incnt;
        !            63:     return 8;
        !            64: }
        !            65: 
        !            66: #else
        !            67: /*
        !            68:  * This function is used only by the NEEDBYTE macro in inflate.c.
        !            69:  * It fills the buffer and resets the count and pointers for the
        !            70:  * macro to resume processing.  The count is set to the number of bytes
        !            71:  * read in minus one, while the pointer is set to the beginning of the
        !            72:  * buffer.  This is all to make the macro more efficient.
        !            73:  *
        !            74:  * In exceptional circumstances, zinflate can read a byte or two past the
        !            75:  * end of input, so we allow this for a little bit before returning
        !            76:  * an error.  zinflate doesn't actually use the bytes, so the value
        !            77:  * is irrelevant.
        !            78:  *
        !            79:  * Returns 0 on success, non-zero on error.
        !            80:  */
        !            81: int FillInBuf()
        !            82: {
        !            83:        static int eofonce = 0;
        !            84: 
        !            85:        incnt = read(zipfd, (char *)inbuf, INBUFSIZ);
        !            86: 
        !            87:        if (incnt > 0) {        /* Read went okay */
        !            88:                inptr = inbuf;
        !            89:                --incnt;
        !            90:                return 0;
        !            91:        } else if (incnt == 0 && !eofonce) {    /* Special fudge case */
        !            92:                eofonce++;
        !            93:                incnt = 2;
        !            94:                inptr = inbuf;
        !            95:                return 0;
        !            96:        } else {                /* Error */
        !            97:                return 1;
        !            98:        }
        !            99: }
        !           100: #endif
        !           101: 
        !           102: /**************************/
        !           103: /* Function FlushOutput() */
        !           104: /**************************/
        !           105: 
        !           106: int FlushOutput()
        !           107: {
        !           108:     /*
        !           109:      * flush contents of output buffer; return PK-type error code
        !           110:      */
        !           111:     int len;
        !           112: 
        !           113:     if (outcnt) {
        !           114:                        len = outcnt;
        !           115:            if (write(outfd, (char *) outout, len) != len)
        !           116: #ifdef MINIX
        !           117:                 if (errno == EFBIG)
        !           118:                     if (write(fd, outout, len/2) != len/2  ||
        !           119:                         write(fd, outout+len/2, len/2) != len/2)
        !           120: #endif /* MINIX */
        !           121:                 {
        !           122:                     return 50;    /* 50:  disk full */
        !           123:                 }
        !           124:         outpos += outcnt;
        !           125:         outcnt = 0;
        !           126:         outptr = outbuf;
        !           127:     }
        !           128:     return (0);                 /* 0:  no error */
        !           129: }

unix.superglobalmegacorp.com

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