home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / os2 / pgp263.arj / PGP263I.SRC / PGP263II.ZIP / src / zfile_io.c < prev    next >
C/C++ Source or Header  |  1995-09-27  |  3KB  |  136 lines

  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. #ifdef MACTC5
  82. int eofonce = 0;
  83. #endif
  84.  
  85. int FillInBuf()
  86. {
  87. #ifndef MACTC5
  88.     static int eofonce = 0;
  89. #endif
  90.  
  91.     incnt = read(zipfd, (char *)inbuf, INBUFSIZ);
  92.  
  93.     if (incnt > 0) {    /* Read went okay */
  94.         inptr = inbuf;
  95.         --incnt;
  96.         return 0;
  97.     } else if (incnt == 0 && !eofonce) {    /* Special fudge case */
  98.         eofonce++;
  99.         incnt = 2;
  100.         inptr = inbuf;
  101.         return 0;
  102.     } else {        /* Error */
  103.         return 1;
  104.     }
  105. }
  106. #endif
  107.  
  108. /**************************/
  109. /* Function FlushOutput() */
  110. /**************************/
  111.  
  112. int FlushOutput()
  113. {
  114.     /*
  115.      * flush contents of output buffer; return PK-type error code
  116.      */
  117.     int len;
  118.  
  119.     if (outcnt) {
  120.             len = outcnt;
  121.         if (write(outfd, (char *) outout, len) != len)
  122. #ifdef MINIX
  123.                 if (errno == EFBIG)
  124.                     if (write(fd, outout, len/2) != len/2  ||
  125.                         write(fd, outout+len/2, len/2) != len/2)
  126. #endif /* MINIX */
  127.                 {
  128.                     return 50;    /* 50:  disk full */
  129.                 }
  130.         outpos += outcnt;
  131.         outcnt = 0;
  132.         outptr = outbuf;
  133.     }
  134.     return (0);                 /* 0:  no error */
  135. }
  136.