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/JSUOutputStream.cpp | |
| parent | 7137f49bfc9535d95f980fb92552adf7b7c3c3ce (diff) | |
most of JHostIO / m_Do_hostIO done (#2288)
Diffstat (limited to 'src/JSystem/JSupport/JSUOutputStream.cpp')
| -rw-r--r-- | src/JSystem/JSupport/JSUOutputStream.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/JSystem/JSupport/JSUOutputStream.cpp b/src/JSystem/JSupport/JSUOutputStream.cpp new file mode 100644 index 0000000000..c2eb67d174 --- /dev/null +++ b/src/JSystem/JSupport/JSUOutputStream.cpp @@ -0,0 +1,59 @@ +#include "JSystem/JSupport/JSUOutputStream.h" +#include "JSystem/JSupport/JSURandomOutputStream.h" +#include <dolphin.h> +#include <cstring.h> + +JSUOutputStream::~JSUOutputStream() { + if (!isGood()) { + OS_REPORT("JSUOutputStream: occur error.\n"); + } +} + +s32 JSUOutputStream::write(const void* buffer, s32 numBytes) { + s32 bytesWrote = writeData(buffer, numBytes); + if (bytesWrote != numBytes) { + setState(IOS_STATE_1); + } + return bytesWrote; +} + +void JSUOutputStream::write(const char* str) { + if (str == NULL) { + u16 spA = 0; + if (writeData(&spA, sizeof(spA)) != sizeof(spA)) { + setState(IOS_STATE_1); + } + } else { + int len = strlen(str); + if (len >= 0x10000) { + setState(IOS_STATE_2); + } else { + u16 sp8 = len; + if (writeData(&sp8, sizeof(sp8)) != sizeof(sp8) || writeData(str, len) != len) { + setState(IOS_STATE_1); + } + } + } +} + +s32 JSUOutputStream::skip(s32 count, s8 param_1) { + s32 skipCount = 0; + for (; skipCount < count; skipCount++) { + if (writeData(¶m_1, sizeof(param_1)) != sizeof(param_1)) { + setState(IOS_STATE_1); + break; + } + } + + return skipCount; +} + +s32 JSURandomOutputStream::seek(s32 param_0, JSUStreamSeekFrom param_1) { + s32 seekResult = seekPos(param_0, param_1); + clrState(IOS_STATE_1); + return seekResult; +} + +s32 JSURandomOutputStream::getAvailable() const { + return getLength() - getPosition(); +} |
