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.

157 lines
3.7 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: stgutil.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 6/3/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "headers.hxx"
  18. #pragma hdrstop
  19. #include <afxconv.h>
  20. #include "stgutil.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. //____________________________________________________________________________
  27. //
  28. // Member: CIStream::Read
  29. //
  30. // Synopsis: Reads cb count of bytes from the stream passed into the
  31. // buffer, pv. Insures the count read equals the count
  32. // requested.
  33. //
  34. // Arguments: [pv] -- buffer to read into.
  35. // [cb] -- read request byte count.
  36. //
  37. // Returns: void
  38. //
  39. // Notes: Throws CFileException(IStream error value) if the read fails,
  40. // or CFileException(E_FAIL) if <bytes read != bytes expected>.
  41. //____________________________________________________________________________
  42. void
  43. CIStream::Read(VOID * pv, ULONG cb)
  44. {
  45. ASSERT(m_pstm != NULL);
  46. ASSERT(pv != NULL);
  47. ULONG cbRead = 0;
  48. HRESULT hr = m_pstm->Read(pv, cb, &cbRead);
  49. if (FAILED(hr))
  50. {
  51. CHECK_HRESULT(hr);
  52. THROW_FILE_ERROR( hr );
  53. }
  54. else if (cb != cbRead)
  55. {
  56. CHECK_HRESULT(E_FAIL);
  57. THROW_FILE_ERROR( E_FAIL );
  58. }
  59. }
  60. //____________________________________________________________________________
  61. //
  62. // Member: CIStream::Write
  63. //
  64. // Synopsis: Writes cb count of bytes from the stream passed from the
  65. // buffer, pv. Insures the count written equals the count
  66. // specified.
  67. //
  68. // Arguments: [pv] -- buffer to write from.
  69. // [cb] -- write request byte count.
  70. //
  71. // Returns: void
  72. //
  73. // Notes: Throws CFileException(IStream error value) if the read fails,
  74. // or CFileException(E_FAIL) if <bytes written != bytes expected>.
  75. //____________________________________________________________________________
  76. void
  77. CIStream::Write(
  78. const VOID * pv,
  79. ULONG cb)
  80. {
  81. ASSERT(m_pstm != NULL);
  82. ASSERT(pv != NULL);
  83. ULONG cbWritten = 0;
  84. HRESULT hr = m_pstm->Write(pv, cb, &cbWritten);
  85. if (FAILED(hr))
  86. {
  87. CHECK_HRESULT(hr);
  88. THROW_FILE_ERROR( hr );
  89. }
  90. else if (cb != cbWritten)
  91. {
  92. CHECK_HRESULT(E_FAIL);
  93. THROW_FILE_ERROR( E_FAIL );
  94. }
  95. }
  96. //____________________________________________________________________________
  97. //
  98. // Member: CIStream::CopyTo
  99. //
  100. // Synopsis: Copies cb number of bytes from the current seek pointer in
  101. // the stream to the current seek pointer in another stream
  102. //
  103. // Arguments: [pstm] -- Points to the destination stream
  104. // [cb] -- Specifies the number of bytes to copy
  105. //
  106. // Returns: void
  107. //
  108. // Notes: Throws CFileException(IStream error value) if the read fails,
  109. // or CFileException(E_FAIL) if <bytes read != bytes written>.
  110. //____________________________________________________________________________
  111. void
  112. CIStream::CopyTo(
  113. IStream * pstm,
  114. ULARGE_INTEGER cb)
  115. {
  116. ASSERT(m_pstm != NULL);
  117. ASSERT(pstm != NULL);
  118. ULARGE_INTEGER cbRead = {0};
  119. ULARGE_INTEGER cbWritten = {0};
  120. HRESULT hr = m_pstm->CopyTo(pstm, cb, &cbRead, &cbWritten);
  121. if (FAILED(hr))
  122. {
  123. CHECK_HRESULT(hr);
  124. THROW_FILE_ERROR( hr );
  125. }
  126. else if (cbWritten.LowPart != cbRead.LowPart ||
  127. cbWritten.HighPart != cbRead.HighPart )
  128. {
  129. CHECK_HRESULT(E_FAIL);
  130. THROW_FILE_ERROR( E_FAIL );
  131. }
  132. }