From d5b1b257434ad23d35ff7ce7771daa7072ffa297 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 08:02:02 +0000 Subject: [PATCH 1/2] Match MSL file position helpers --- configure.py | 2 +- libs/MSL/src/MSL_Common/FILE_POS.c | 112 +++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 libs/MSL/src/MSL_Common/FILE_POS.c diff --git a/configure.py b/configure.py index a04536e2..8eb0e3c5 100644 --- a/configure.py +++ b/configure.py @@ -1951,7 +1951,7 @@ config.libs = [ Object(Matching, "MSL_Common/buffer_io.c"), Object(Matching, "MSL_Common/direct_io.c", extra_cflags=["-Cpp_exceptions on"]), Object(NonMatching, "MSL_Common/file_io.c"), - Object(NonMatching, "MSL_Common/FILE_POS.c"), + Object(Matching, "MSL_Common/FILE_POS.c"), Object(Matching, "MSL_Common/mbstring.c"), Object(Matching, "MSL_Common/mem.c"), Object(Matching, "MSL_Common/mem_funcs.c"), diff --git a/libs/MSL/src/MSL_Common/FILE_POS.c b/libs/MSL/src/MSL_Common/FILE_POS.c new file mode 100644 index 00000000..4f791074 --- /dev/null +++ b/libs/MSL/src/MSL_Common/FILE_POS.c @@ -0,0 +1,112 @@ +#include +#include +#include + +enum file_kinds { + file_closed, + file_disk, + file_console, + file_unavailable +}; + +enum io_states { + neutral, + writing, + reading, + rereading +}; + +enum io_modes { + io_read = 1, + io_write = 2, + io_append = 4 +}; + +int __flush_buffer(FILE* file, size_t* pos); + +long _ftell(FILE* file) { + int buf = 0; + int pos; + + unsigned char file_kind = file->mode.file_kind; + if (!(file_kind == file_disk || file_kind == file_console) || file->state.error) { + errno = EFPOS; + return -1; + } + + if (file->state.io_state == neutral) { + return file->pos; + } + + pos = file->buffer_pos + (file->buffer_ptr - file->buffer); + + if (file->state.io_state >= rereading) { + buf = file->state.io_state - reading; + pos -= buf; + } + + if (!file->mode.binary_io) { + int n = file->buffer_ptr - file->buffer - buf; + unsigned char* p = file->buffer; + + while (n-- != 0) { + if (*p++ == '\n') { + pos++; + } + } + } + + return pos; +} + +long ftell(FILE* stream) { + return _ftell(stream); +} + +int _fseek(FILE* file, long offset, int whence) { + if (file->mode.file_kind != file_disk || file->state.error != 0) { + errno = EFPOS; + return -1; + } + + if (file->state.io_state == writing) { + if (__flush_buffer(file, 0) != 0) { + file->state.error = 1; + file->buffer_len = 0; + errno = EFPOS; + return -1; + } + } + + if (whence == 1) { + whence = 0; + offset += _ftell(file); + } + + if ((whence != 2) && file->mode.io_mode != (io_read | io_write) && (file->state.io_state == reading || file->state.io_state == rereading)) { + if ((offset >= file->pos) || offset < file->buffer_pos) { + file->state.io_state = neutral; + } else { + file->buffer_ptr = file->buffer + (offset - file->buffer_pos); + file->buffer_len = file->pos - offset; + file->state.io_state = reading; + } + } else { + file->state.io_state = neutral; + } + + if (file->state.io_state == neutral) { + if (file->pos_proc != 0 && (*file->pos_proc)(file->handle, &offset, whence, file->ref)) { + file->state.error = 1; + file->buffer_len = 0; + errno = EFPOS; + return -1; + } + + file->state.eof = 0; + file->pos = offset; + file->buffer_len = 0; + } + + return 0; +} -- 2.49.1 From e926be458550991a6afb93ebd06a3ee73c84ea10 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 03:05:56 -0500 Subject: [PATCH 2/2] Match RVLFaceLib system unit (#166) --- libs/RVLFaceLib/src/RFL_System.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/RVLFaceLib/src/RFL_System.c b/libs/RVLFaceLib/src/RFL_System.c index 7b5533a0..f4942f1d 100644 --- a/libs/RVLFaceLib/src/RFL_System.c +++ b/libs/RVLFaceLib/src/RFL_System.c @@ -202,7 +202,7 @@ void RFLExit() { } } -RFLErrcode RFLiBootLoad() { +static inline RFLErrcode RFLiBootLoad() { RFLiBootLoadAsync(); return RFLWaitAsync(); } @@ -223,7 +223,7 @@ static void bootloadDB2Res_() { } } -RFLErrcode RFLiBootLoadAsync() { +static inline RFLErrcode RFLiBootLoadAsync() { return RFLiBootLoadDatabaseAsync(bootloadDB2Res_); } @@ -249,7 +249,7 @@ void RFLiFree(void* block) { MEMFreeToExpHeap(RFLiGetManager()->mTmpHeap, block); } -u32 RFLiGetUsedWorkSize() { +static inline u32 RFLiGetUsedWorkSize() { if (RFLAvailable()) { MEMiHeapHead* heap = RFLiGetManager()->mTmpHeap; return MEMGetAllocatableSizeForExpHeap(heap) - MEMGetTotalFreeSizeForExpHeap(heap); @@ -397,7 +397,7 @@ BOOL RFLiNeedRepairError() { return ((*list & (1 << RFLiFileBrokenType_DBBroken)) != 0) ? TRUE : FALSE; } -BOOL RFLiCriticalError() { +static inline BOOL RFLiCriticalError() { u8* list = &sRFLBrokenType; BOOL ret = FALSE; // Unused -- 2.49.1