1370b324cSopenharmony_ci// OffsetStream.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci#include "OffsetStream.h"
6370b324cSopenharmony_ci
7370b324cSopenharmony_ciHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)
8370b324cSopenharmony_ci{
9370b324cSopenharmony_ci  _offset = offset;
10370b324cSopenharmony_ci  _stream = stream;
11370b324cSopenharmony_ci  return _stream->Seek((Int64)offset, STREAM_SEEK_SET, NULL);
12370b324cSopenharmony_ci}
13370b324cSopenharmony_ci
14370b324cSopenharmony_ciZ7_COM7F_IMF(COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize))
15370b324cSopenharmony_ci{
16370b324cSopenharmony_ci  return _stream->Write(data, size, processedSize);
17370b324cSopenharmony_ci}
18370b324cSopenharmony_ci
19370b324cSopenharmony_ciZ7_COM7F_IMF(COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
20370b324cSopenharmony_ci{
21370b324cSopenharmony_ci  if (seekOrigin == STREAM_SEEK_SET)
22370b324cSopenharmony_ci  {
23370b324cSopenharmony_ci    if (offset < 0)
24370b324cSopenharmony_ci      return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
25370b324cSopenharmony_ci    offset += _offset;
26370b324cSopenharmony_ci  }
27370b324cSopenharmony_ci  UInt64 absoluteNewPosition = 0; // =0 for gcc-10
28370b324cSopenharmony_ci  const HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
29370b324cSopenharmony_ci  if (newPosition)
30370b324cSopenharmony_ci    *newPosition = absoluteNewPosition - _offset;
31370b324cSopenharmony_ci  return result;
32370b324cSopenharmony_ci}
33370b324cSopenharmony_ci
34370b324cSopenharmony_ciZ7_COM7F_IMF(COffsetOutStream::SetSize(UInt64 newSize))
35370b324cSopenharmony_ci{
36370b324cSopenharmony_ci  return _stream->SetSize(_offset + newSize);
37370b324cSopenharmony_ci}
38