mirror of
https://github.com/zeldaret/st
synced 2026-07-08 14:26:24 -04:00
c98c03de39
* 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
40 lines
749 B
C
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;
|
|
}
|