summaryrefslogtreecommitdiff
path: root/src/MSL_C.PPCEABI.bare.H/file_io.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-02 17:29:19 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-03 13:27:06 -0400
commitf2eabdb6257c09cf2890dac5e9737912728542af (patch)
tree3b46f6787185d65605651a0f48776dc9779ce648 /src/MSL_C.PPCEABI.bare.H/file_io.c
parenteef1dd840b7cecac28c2e6b0574707b90a37d4e7 (diff)
global: Add rest of Dolphin SDK proper, add MSL, and MetroTRK
Finally, it links properly.
Diffstat (limited to 'src/MSL_C.PPCEABI.bare.H/file_io.c')
-rw-r--r--src/MSL_C.PPCEABI.bare.H/file_io.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/MSL_C.PPCEABI.bare.H/file_io.c b/src/MSL_C.PPCEABI.bare.H/file_io.c
new file mode 100644
index 0000000..a05a7ab
--- /dev/null
+++ b/src/MSL_C.PPCEABI.bare.H/file_io.c
@@ -0,0 +1,70 @@
+#include "ansi_files.h"
+#include "types.h"
+
+#pragma dont_inline on
+int fclose(FILE* file) {
+ int flush_result, close_result;
+
+ if (file == nullptr)
+ return (-1);
+ if (file->mode.file_kind == __closed_file)
+ return (0);
+
+ flush_result = fflush(file);
+
+ close_result = (*file->close_proc)(file->handle);
+
+ file->mode.file_kind = __closed_file;
+ file->handle = NULL;
+
+ if (file->state.free_buffer)
+ free(file->buffer);
+ return ((flush_result || close_result) ? -1 : 0);
+}
+
+int fflush(FILE* file) {
+ int pos;
+
+ if (file == nullptr) {
+ return __flush_all();
+ }
+
+ if (file->state.error != 0 || file->mode.file_kind == __closed_file) {
+ return -1;
+ }
+
+ if (file->mode.io_mode == 1) {
+ return 0;
+ }
+
+ if (file->state.io_state >= 3) {
+ file->state.io_state = 2;
+ }
+
+ if (file->state.io_state == 2) {
+ file->buffer_len = 0;
+ }
+
+ if (file->state.io_state != 1) {
+ file->state.io_state = 0;
+ return 0;
+ }
+
+ if (file->mode.file_kind != __disk_file) {
+ pos = 0;
+ } else {
+ pos = ftell(file);
+ }
+
+ if (__flush_buffer(file, 0) != 0) {
+ file->state.error = 1;
+ file->buffer_len = 0;
+ return -1;
+ }
+
+ file->state.io_state = 0;
+ file->position = pos;
+ file->buffer_len = 0;
+ return 0;
+}
+#pragma dont_inline reset