diff --git a/configure.py b/configure.py index 2af8b877..5f46e7cb 100644 --- a/configure.py +++ b/configure.py @@ -819,7 +819,7 @@ config.libs = [ "src_dir": "src/static", "objects": [ Object(Matching, "MSL_C.PPCEABI.bare.H/abort_exit.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_files.c"), + Object(Matching, "MSL_C.PPCEABI.bare.H/ansi_files.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_fp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/arith.c"), Object(Matching, "MSL_C.PPCEABI.bare.H/buffer_io.c"), diff --git a/include/MSL_C/ansi_files.h b/include/MSL_C/ansi_files.h index edb76aad..98899389 100644 --- a/include/MSL_C/ansi_files.h +++ b/include/MSL_C/ansi_files.h @@ -28,7 +28,7 @@ enum __file_kinds { __disk_file, __console_file, __string_file, - __unavailable_file, + __unavailable_file = 3, // TODO: figure out which one of these file kinds is not present }; enum __file_orientation { diff --git a/src/static/MSL_C.PPCEABI.bare.H/ansi_files.c b/src/static/MSL_C.PPCEABI.bare.H/ansi_files.c index 80ba8089..374b5c29 100644 --- a/src/static/MSL_C.PPCEABI.bare.H/ansi_files.c +++ b/src/static/MSL_C.PPCEABI.bare.H/ansi_files.c @@ -1,8 +1,8 @@ #include "MSL_C/ansi_files.h" -char stderr_buff[0x100]; -char stdout_buff[0x100]; char stdin_buff[0x100]; +char stdout_buff[0x100]; +char stderr_buff[0x100]; extern int __close_console(__file_handle file); extern int __write_console(__file_handle file, unsigned char* buf, size_t* count, __idle_proc idle_fn); @@ -104,28 +104,40 @@ extern files __files = { }, }; -unsigned int __flush_all(void) { -} - void __close_all(void) { - FILE* file = &__files._stdin; + FILE* p = &__files._stdin; + FILE* plast; - while (file) { - FILE* curr; + while(p != NULL) + { + if (p->file_mode.file_kind != __closed_file) + { + fclose(p); + } - if (file->file_mode.file_kind & 0x3) - fclose(file); - - curr = file->next; - file = file->next; - if (curr->char_buffer) { - free(curr); - continue; - } - - file->file_mode.file_kind = 3; - - if (file && file->char_buffer) - curr->next = NULL; - } + plast = p; + p = (FILE*)p->next; + if (plast->char_buffer) + free(plast); + else + { + plast->file_mode.file_kind = __unavailable_file; + if ((p != NULL) && p->char_buffer) + plast->next = NULL; + } + } +} + +unsigned int __flush_all(void) +{ + unsigned int retval = 0; + FILE* __stream; + __stream = &__files._stdin; + while (__stream) { + if ((__stream->file_mode.file_kind) && (fflush(__stream))) { + retval = -1; + } + __stream = (FILE*)__stream->next; + }; + return retval; }