Source code of Windows XP (NT5)
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.

141 lines
3.0 KiB

  1. /*
  2. ** copylz.c - CopyLZFile() and buffer management functions.
  3. **
  4. ** Author: DavidDi
  5. **
  6. ** This module is compiled twice - once with LZA_DLL defined for the Windows
  7. ** DLL, and once without LZDLL defined for static DOS library.
  8. */
  9. // Headers
  10. ///////////
  11. #include <basedll.h>
  12. #define LZA_DLL
  13. #include "lz_common.h"
  14. #include "lz_buffers.h"
  15. #include "lz_header.h"
  16. #include "lzpriv.h"
  17. /*
  18. ** int APIENTRY LZStart(void);
  19. **
  20. ** If the global buffers are not already initialized, allocates buffers in
  21. ** preparation for calls to CopyLZFile(). Increments the global buffer lock
  22. ** count. Sets the global buffers' base pointers and lengths.
  23. **
  24. ** Arguments: void
  25. **
  26. ** Returns: int - TRUE if successful. LZERROR_GLOBALLOC if unsuccessful.
  27. **
  28. ** Globals: none
  29. */
  30. INT APIENTRY LZStart(VOID)
  31. {
  32. return(TRUE);
  33. }
  34. /*
  35. ** VOID APIENTRY LZDone(void);
  36. **
  37. ** If any of the global buffers have not already been freed, frees them and
  38. ** resets the buffers' base array pointers to NULL. Decrements the global
  39. ** buffer lock count.
  40. **
  41. ** Arguments: void
  42. **
  43. ** Returns: VOID
  44. **
  45. ** Globals: none
  46. */
  47. VOID APIENTRY LZDone(VOID)
  48. {
  49. return;
  50. }
  51. /*
  52. ** CopyLZFile()
  53. **
  54. ** Alias for LZCopy(). Originally, LZCopy() and
  55. ** CopyLZFile() were intended for different purposes, but they were confused
  56. ** and misused so much they were made identical.
  57. */
  58. LONG APIENTRY CopyLZFile(HFILE doshSource, HFILE doshDest)
  59. {
  60. return(LZCopy(doshSource, doshDest));
  61. }
  62. /*
  63. ** LZCopy()
  64. **
  65. ** Expand a compressed file, or copy an uncompressed file.
  66. **
  67. ** Arguments: doshSource - source DOS file handle
  68. ** doshDest - destination DOS file handle
  69. **
  70. ** Returns: LONG - Number of bytes written if copy was successful.
  71. ** One of the LZERROR_ codes if unsuccessful.
  72. **
  73. ** Globals: none
  74. */
  75. LONG APIENTRY LZCopy(HFILE doshSource, HFILE doshDest)
  76. {
  77. INT f;
  78. LONG lRetVal;
  79. PLZINFO pLZI;
  80. // If it's a compressed file handle, translate to a DOS handle.
  81. if (doshSource >= LZ_TABLE_BIAS)
  82. {
  83. LZFile *lpLZ; // pointer to LZFile struct
  84. HANDLE hLZFile; // handle to LZFile struct
  85. if ((hLZFile = rghLZFileTable[doshSource - LZ_TABLE_BIAS]) == NULL)
  86. {
  87. return(LZERROR_BADINHANDLE);
  88. }
  89. if ((lpLZ = (LZFile *)GlobalLock(hLZFile)) == NULL)
  90. {
  91. return(LZERROR_GLOBLOCK);
  92. }
  93. doshSource = lpLZ->dosh;
  94. doshDest = ConvertDosFHToWin32(doshDest);
  95. GlobalUnlock(hLZFile);
  96. }
  97. else {
  98. doshDest = ConvertDosFHToWin32(doshDest);
  99. doshSource = ConvertDosFHToWin32(doshSource);
  100. }
  101. // Initialize buffers
  102. pLZI = InitGlobalBuffersEx();
  103. if (!pLZI) {
  104. return(LZERROR_GLOBALLOC);
  105. }
  106. ResetBuffers();
  107. // Expand / copy file.
  108. if ((f = ExpandOrCopyFile(doshSource, doshDest, pLZI)) != TRUE) {
  109. // Expansion / copy failed.
  110. lRetVal = (LONG)f;
  111. } else {
  112. // Expansion / copy successful - return number of bytes written.
  113. lRetVal = pLZI->cblOutSize;
  114. }
  115. // Free global buffers.
  116. FreeGlobalBuffers(pLZI);
  117. return(lRetVal);
  118. }
  119.