From 29991169399fababf61185710479f665c10f4bbc Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 03:53:40 +0000 Subject: [PATCH] Match MSL ansi files --- configure.py | 2 +- libs/MSL/src/MSL_Common/ansi_files.c | 123 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 libs/MSL/src/MSL_Common/ansi_files.c diff --git a/configure.py b/configure.py index 610214a7..62e6e5ca 100644 --- a/configure.py +++ b/configure.py @@ -1942,7 +1942,7 @@ config.libs = [ MSLLib("MSL_C.PPCEABI.bare.H", [ Object(NonMatching, "MSL_Common/alloc.c"), Object(Matching, "MSL_Common/errno.c"), - Object(NonMatching, "MSL_Common/ansi_files.c"), + Object(Matching, "MSL_Common/ansi_files.c"), Object(NonMatching, "MSL_Common_Embedded/ansi_fp.c"), Object(Matching, "MSL_Common/ctype.c"), Object(NonMatching, "MSL_Common/locale.c"), diff --git a/libs/MSL/src/MSL_Common/ansi_files.c b/libs/MSL/src/MSL_Common/ansi_files.c new file mode 100644 index 00000000..0533ec96 --- /dev/null +++ b/libs/MSL/src/MSL_Common/ansi_files.c @@ -0,0 +1,123 @@ +#include +#include + +extern int __read_console(unsigned long, unsigned char*, size_t*, void*); +extern int __write_console(unsigned long, unsigned char*, size_t*, void*); +extern int __close_console(unsigned long); + +#pragma exceptions on + +unsigned char stdin_buff[0x100]; +unsigned char stdout_buff[0x100]; +unsigned char stderr_buff[0x100]; + +FILE __files[4] = { + { + 0, + {0, 1, 1, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdin_buff, + 0x100, + stdin_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[1], + }, + { + 1, + {0, 2, 1, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdout_buff, + 0x100, + stdout_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[2], + }, + { + 2, + {0, 2, 0, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stderr_buff, + 0x100, + stderr_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[3], + }, + {0}, +}; + +void __close_all(void) { + FILE* file; + FILE* current; + + for (file = __files; file != 0;) { + if (file->mode.file_kind != 0) { + fclose(file); + } + + current = file; + file = file->next_file; + if (current->is_dyn_alloc != 0) { + free(current); + } else { + current->mode.file_kind = 3; + if (file != 0 && file->is_dyn_alloc != 0) { + current->next_file = 0; + } + } + } +} + +int __flush_all(void) { + int result = 0; + FILE* file; + + for (file = __files; file != 0; file = file->next_file) { + if (file->mode.file_kind != 0 && fflush(file) != 0) { + result = -1; + } + } + + return result; +} -- 2.49.1