diff options
| author | TakaRikka <38417346+TakaRikka@users.noreply.github.com> | 2025-01-19 21:05:53 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-19 22:05:53 -0700 |
| commit | e0824a15908f4e6ad70d3d0f2364efe043a98c0f (patch) | |
| tree | 3e85ea5ea5282c7ca3397a3adc1535674fc496aa /src/JSystem/JSupport/JSUMemoryStream.cpp | |
| parent | 7137f49bfc9535d95f980fb92552adf7b7c3c3ce (diff) | |
most of JHostIO / m_Do_hostIO done (#2288)
Diffstat (limited to 'src/JSystem/JSupport/JSUMemoryStream.cpp')
| -rw-r--r-- | src/JSystem/JSupport/JSUMemoryStream.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/JSystem/JSupport/JSUMemoryStream.cpp b/src/JSystem/JSupport/JSUMemoryStream.cpp index 0b5f1bc062..494c343313 100644 --- a/src/JSystem/JSupport/JSUMemoryStream.cpp +++ b/src/JSystem/JSupport/JSUMemoryStream.cpp @@ -63,4 +63,53 @@ s32 JSUMemoryInputStream::getLength() const { /* 802DC630-802DC638 2D6F70 0008+00 1/0 0/0 0/0 .text getPosition__20JSUMemoryInputStreamCFv */ s32 JSUMemoryInputStream::getPosition() const { return mPosition; -}
\ No newline at end of file +} + +void JSUMemoryOutputStream::setBuffer(void* pBuffer, s32 length) { + mBuffer = pBuffer; + mLength = length; + mPosition = 0; +} + +s32 JSUMemoryOutputStream::writeData(const void* pData, s32 length) { + if (mPosition + length > mLength) { + length = mLength - mPosition; + } + + if (length > 0) { + memcpy((void*)((s32)mBuffer + mPosition), pData, length); + mPosition += length; + } + + return length; +} + +s32 JSUMemoryOutputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) { + s32 oldPos = mPosition; + + switch (seekFrom) { + case JSUStreamSeekFrom_SET: + mPosition = pos; + break; + case JSUStreamSeekFrom_END: + mPosition = mLength - pos; + break; + case JSUStreamSeekFrom_CUR: + mPosition += pos; + break; + } + + if (mPosition < 0) { + mPosition = 0; + } + + if (mPosition > mLength) { + mPosition = mLength; + } + + return mPosition - oldPos; +} + +s32 JSUMemoryOutputStream::getLength() const { + return mLength; +} |
