From cd52246e9cba4d6300a07ea5e2158d390460697a Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Fri, 4 Jul 2025 18:23:15 -0400 Subject: [PATCH] Link MSL_C/file_io --- configure.py | 2 +- src/static/MSL_C.PPCEABI.bare.H/file_io.c | 78 +++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/static/MSL_C.PPCEABI.bare.H/file_io.c diff --git a/configure.py b/configure.py index 7da229e6..463f52a3 100644 --- a/configure.py +++ b/configure.py @@ -829,7 +829,7 @@ config.libs = [ Object(Matching, "MSL_C.PPCEABI.bare.H/e_atan2.c"), Object(Matching, "MSL_C.PPCEABI.bare.H/e_rem_pio2.c"), Object(Matching, "MSL_C.PPCEABI.bare.H/errno.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/file_io.c"), + Object(Matching, "MSL_C.PPCEABI.bare.H/file_io.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/FILE_POS.C"), Object(Matching, "MSL_C.PPCEABI.bare.H/float.c"), Object(Matching, "MSL_C.PPCEABI.bare.H/k_cos.c"), diff --git a/src/static/MSL_C.PPCEABI.bare.H/file_io.c b/src/static/MSL_C.PPCEABI.bare.H/file_io.c new file mode 100644 index 00000000..f3daf18a --- /dev/null +++ b/src/static/MSL_C.PPCEABI.bare.H/file_io.c @@ -0,0 +1,78 @@ +#include "MSL_C/ansi_files.h" + + +/** + * @note Address: 0x800C6748 + * @note Size: 0x1BC + */ +int fclose(FILE* file) +{ + int flush_result, close_result; + + if (file == NULL) + return (-1); + if (file->file_mode.file_kind == __closed_file) + return (0); + + flush_result = fflush(file); + + close_result = (*file->close_fn)(file->handle); + + file->file_mode.file_kind = __closed_file; + file->handle = 0; + + if (file->file_state.free_buffer) + free(file->buffer); + return ((flush_result || close_result) ? -1 : 0); +} + +/** + * @note Address: 0x800C6610 + * @note Size: 0x138 + */ +int fflush(FILE* file) +{ + int pos; + + if (file == NULL) { + return __flush_all(); + } + + if (file->file_state.error != 0 || file->file_mode.file_kind == __closed_file) { + return -1; + } + + if (file->file_mode.io_mode == 1) { + return 0; + } + + if (file->file_state.io_state >= __rereading) { + file->file_state.io_state = __reading; + } + + if (file->file_state.io_state == __reading) { + file->buffer_length = 0; + } + + if (file->file_state.io_state != __writing) { + file->file_state.io_state = __neutral; + return 0; + } + + if (file->file_mode.file_kind != __disk_file) { + pos = 0; + } else { + pos = ftell(file); + } + + if (__flush_buffer(file, 0) != 0) { + file->file_state.error = 1; + file->buffer_length = 0; + return -1; + } + + file->file_state.io_state = __neutral; + file->position = pos; + file->buffer_length = 0; + return 0; +}