Match COutputStream::DoPut (Thanks HeartPiece!)

This commit is contained in:
Phillip Stephens 2022-10-11 21:44:08 -07:00
parent 08e0d97ba3
commit 26d6394bb1
4 changed files with 27 additions and 24 deletions

View File

@ -883,7 +883,7 @@ LIBS = [
"Runtime/e_pow", "Runtime/e_pow",
["Runtime/e_rem_pio2", True], ["Runtime/e_rem_pio2", True],
["Runtime/k_cos", True], ["Runtime/k_cos", True],
"Runtime/k_rem_pio2", ["Runtime/k_rem_pio2", True],
["Runtime/k_sin", True], ["Runtime/k_sin", True],
["Runtime/k_tan", True], ["Runtime/k_tan", True],
"Runtime/s_atan", "Runtime/s_atan",

View File

@ -760,7 +760,7 @@ MSL_COMMON_MATH :=\
$(BUILD_DIR)/asm/Runtime/e_pow.o\ $(BUILD_DIR)/asm/Runtime/e_pow.o\
$(BUILD_DIR)/src/Runtime/e_rem_pio2.o\ $(BUILD_DIR)/src/Runtime/e_rem_pio2.o\
$(BUILD_DIR)/src/Runtime/k_cos.o\ $(BUILD_DIR)/src/Runtime/k_cos.o\
$(BUILD_DIR)/asm/Runtime/k_rem_pio2.o\ $(BUILD_DIR)/src/Runtime/k_rem_pio2.o\
$(BUILD_DIR)/src/Runtime/k_sin.o\ $(BUILD_DIR)/src/Runtime/k_sin.o\
$(BUILD_DIR)/src/Runtime/k_tan.o\ $(BUILD_DIR)/src/Runtime/k_tan.o\
$(BUILD_DIR)/asm/Runtime/s_atan.o\ $(BUILD_DIR)/asm/Runtime/s_atan.o\

View File

@ -21,30 +21,34 @@ COutputStream::~COutputStream() {
} }
void COutputStream::DoPut(const void* ptr, size_t len) { void COutputStream::DoPut(const void* ptr, size_t len) {
if (len == 0) { uint offset;
uchar* offsetPtr;
uint tempLen = len;
if (tempLen != 0) {
mNumWrites += tempLen;
if (tempLen + mUnwrittenLen <= mBufLen) {
memcpy((uchar*)mBufPtr + mUnwrittenLen, ptr, tempLen);
mUnwrittenLen += tempLen;
return; return;
} }
mNumWrites += len; offsetPtr = (uchar*)ptr + tempLen;
if (mBufLen <= len + mUnwrittenLen) { while (tempLen != 0) {
memcpy((uchar*)mBufPtr + mUnwrittenLen, ptr, len);
mUnwrittenLen += len;
return;
}
while (len != 0) {
uint count = mBufLen - mUnwrittenLen; uint count = mBufLen - mUnwrittenLen;
uint offset = len; offset = count;
if (count < len) { if (tempLen < count) {
len = count; offset = tempLen;
} }
if (count != 0) { if (offset != 0) {
memcpy((uchar*)mBufPtr + mUnwrittenLen, (uchar*)ptr + offset, len); memcpy((uchar*)mBufPtr + mUnwrittenLen, (offsetPtr - tempLen), offset);
mUnwrittenLen += len;
len -= len; tempLen -= offset;
mUnwrittenLen += offset;
} else { } else {
DoFlush(); DoFlush();
} }
} }
}
} }
void COutputStream::Flush() { void COutputStream::Flush() {

View File

@ -56,7 +56,6 @@
*/ */
#include "fdlibm.h" #include "fdlibm.h"
#ifdef __STDC__ #ifdef __STDC__
static const double static const double
#else #else