This commit is contained in:
bumbread 2023-02-15 21:11:22 +11:00
parent 7d43887438
commit 01394ae39a
1 changed files with 11 additions and 9 deletions

View File

@ -69,7 +69,7 @@ static void _file_untrack(FILE *stream) {
// Multithreaded access // Multithreaded access
static inline void _file_lock_init(FILE *stream) { static inline void _file_lock_init(FILE *stream) {
mtx_init(&stream->lock, mtx_recursive); mtx_init(&stream->lock, mtx_plain);
} }
static inline void _file_lock_destroy(FILE *stream) { static inline void _file_lock_destroy(FILE *stream) {
@ -345,15 +345,17 @@ int fflush(FILE *stream) {
_file_lock(stream); _file_lock(stream);
int res = 0; int res = 0;
FileBuffer *buffer = &stream->buffer; FileBuffer *buffer = &stream->buffer;
void *data = buffer->data; if(buffer->written != 0) {
size_t size = buffer->written; size_t size = buffer->written;
DWORD bytes_written; void *data = buffer->data;
BOOL ok = WriteFile(stream->handle, data, size, &bytes_written, NULL); DWORD bytes_written;
if(!ok) { BOOL ok = WriteFile(stream->handle, data, size, &bytes_written, NULL);
res = EOF; if(!ok) {
stream->eof = 1; res = EOF;
stream->eof = 1;
}
buffer->written = 0;
} }
buffer->written = 0;
_file_unlock(stream); _file_unlock(stream);
return res; return res;
} }