Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.9 KiB

  1. /*
  2. ** buffers.h - Function prototypes and global variables used to manipulate
  3. ** buffers used in I/O and expansion.
  4. **
  5. ** Author: DavidDi
  6. */
  7. // Constants
  8. /////////////
  9. // N.b., rgbyteInBuf[] allocated with one extra byte for UnreadByte().
  10. #define MAX_IN_BUF_SIZE 32768U // maximum size of input buffer
  11. #define MAX_OUT_BUF_SIZE 32768U // maximum size of output buffer
  12. #define IN_BUF_STEP 1024U // decrement sizes used in I/O buffer
  13. #define OUT_BUF_STEP 1024U // allocation in InitBuffers()
  14. #define FLUSH_BYTE ((BYTE) 'F') // dummy character used to flush
  15. // rgbyteOutBuf[] to output file
  16. #define END_OF_INPUT 500 // ReadInBuf() EOF flag for input file
  17. // DOS file handle flag indicating that the compression savings should be
  18. // computed, but no output file written.
  19. #define NO_DOSH (-2)
  20. #define READ_IT TRUE // GetIOHandle() bRead flag values
  21. #define WRITE_IT FALSE
  22. // Macros
  23. //////////
  24. // Read a byte (buffered) from input file. Stores byte read in argument.
  25. // Returns TRUE if successful, or one of ReadInBuf()'s error codes if
  26. // unsuccessful.
  27. //-protect-
  28. #define ReadByte(byte) ((pLZI->pbyteInBuf < pLZI->pbyteInBufEnd) ? \
  29. ((byte = *pLZI->pbyteInBuf++), TRUE) : \
  30. ReadInBuf((BYTE ARG_PTR *)&byte, doshSource, pLZI))
  31. // Put at most one byte back into the buffered input. N.b., may be used at
  32. // most (pbyteInBuf - &rgbyteInBuf[1]) times. E.g., may be used only once at
  33. // beginning of buffer. Return value is always TRUE.
  34. //-protect-
  35. #define UnreadByte() ((pLZI->pbyteInBuf == &pLZI->rgbyteInBuf[1]) ? \
  36. (pLZI->bLastUsed = TRUE) : \
  37. (--pLZI->pbyteInBuf, TRUE))
  38. // Write a byte (buffered) to output file. Returns TRUE if successful, or
  39. // one of WriteOutBuf()'s error codes if unsuccessful. ALWAYS increments
  40. // cblOutSize.
  41. #define WriteByte(byte) ((pLZI->pbyteOutBuf < pLZI->pbyteOutBufEnd) ? \
  42. ((*pLZI->pbyteOutBuf++ = byte), pLZI->cblOutSize++, TRUE) : \
  43. (pLZI->cblOutSize++, WriteOutBuf(byte, doshDest, pLZI)))
  44. // Flush output buffer. DOES NOT increment cblOutSize. N.b., you cannot
  45. // perform a valid UnreadByte() immediately after FlushOutputBuffer() because
  46. // the byte kept will be the bogus FLUSH_BYTE.
  47. #define FlushOutputBuffer(dosh, pLZI) WriteOutBuf(FLUSH_BYTE, dosh, pLZI)
  48. // Reset buffer pointers to empty buffer state.
  49. //-protect-
  50. #define ResetBuffers() { pLZI->pbyteInBufEnd = &pLZI->rgbyteInBuf[1] + pLZI->ucbInBufLen; \
  51. pLZI->pbyteInBuf = &pLZI->rgbyteInBuf[1] + pLZI->ucbInBufLen; \
  52. pLZI->bLastUsed = FALSE; \
  53. pLZI->pbyteOutBufEnd = pLZI->rgbyteOutBuf + pLZI->ucbOutBufLen; \
  54. pLZI->pbyteOutBuf = pLZI->rgbyteOutBuf; \
  55. pLZI->cblOutSize = 0L; \
  56. }
  57. // The buffer pointers are initialized to NULL to indicate the buffers have
  58. // not yet been allocated. init.c!InitGlobalBuffers() allocates the buffers
  59. // and sets the buffers' base pointers. buffers.h!ResetBufferPointers() sets
  60. // the buffers' current position and end position pointers.
  61. // Prototypes
  62. //////////////
  63. // buffers.c
  64. extern INT ReadInBuf(BYTE ARG_PTR *pbyte, INT doshSource, PLZINFO pLZI);
  65. extern INT WriteOutBuf(BYTE byteNext, INT doshDest, PLZINFO pLZI);
  66. // init.c
  67. extern PLZINFO InitGlobalBuffers(DWORD dwOutBufSize, DWORD dwRingBufSize, DWORD dwInBufSize);
  68. extern PLZINFO InitGlobalBuffersEx();
  69. extern VOID FreeGlobalBuffers(PLZINFO);
  70. extern INT GetIOHandle(CHAR ARG_PTR *pszFileName, BOOL bRead, INT ARG_PTR *pdosh,
  71. LONG *pcblInSize);
  72.