Files
st/libs/c/src/file_io.c
T
Yanis c98c03de39 Match MSL_C (#8)
* match wstring.c

* match math_api.c, mbstring.c, mem.c and mem_funcs.c

* more progress

* build issues

* fix non-matching issues

* reorganise files

* match fdlibm (+ libc progress)

* fix jp build

* solved some non-matchings and progress

* removed types.h usage in libc

* match data and add missing delinks for jp
2025-12-17 14:08:53 +01:00

40 lines
749 B
C

#include <stdio.h>
int fflush(FILE *file) {
if (file == NULL) {
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 (__flush_buffer(file, 0) != 0) {
file->state.error = 1;
file->buffer_len = 0;
return -1;
}
file->state.io_state = 0;
file->position = 0;
file->buffer_len = 0;
return 0;
}