Indirectly fflush(3) from fshutdown(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2014-08-03 21:44:12 +02:00
parent 97e1551c81
commit 8570f46734
4 changed files with 6 additions and 2 deletions

View File

@ -86,6 +86,7 @@ struct FILE
void (*free_func)(void* free_user, struct FILE* fp);
/* Application writers shouldn't use anything beyond this point. */
pthread_mutex_t file_lock;
int (*fflush_indirect)(FILE*);
void (*buffer_free_indirect)(void*);
struct FILE* prev;
struct FILE* next;

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library.
@ -26,6 +26,8 @@
extern "C" int fclose(FILE* fp)
{
flockfile(fp);
funlockfile(fp);
int ret = fshutdown(fp);
fdeletefile(fp);
return ret;

View File

@ -27,7 +27,7 @@
extern "C" int fshutdown(FILE* fp)
{
int ret = fflush(fp);
int ret = fp->fflush_indirect ? fp->fflush_indirect(fp) : 0;
if ( ret )
{
/* TODO: How to report errors here? fclose may need us to return its

View File

@ -35,6 +35,7 @@ extern "C" int setvbuf_unlocked(FILE* fp, char* buf, int mode, size_t size)
fp->buffer = (unsigned char*) buf;
fp->buffersize = size;
fp->flags |= _FILE_BUFFER_MODE_SET;
fp->fflush_indirect = fflush;
}
return 0;
}