mirror of
https://github.com/mamedev/mame.git
synced 2024-11-16 07:48:32 +01:00
Add function for flushing file buffers
This commit is contained in:
parent
a830ea7627
commit
ba960afb5f
8 changed files with 114 additions and 4 deletions
|
@ -625,6 +625,17 @@ int emu_file::puts(const char *s)
|
|||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// vfprintf - vfprintf to a text file
|
||||
//-------------------------------------------------
|
||||
|
||||
int emu_file::vprintf(const char *fmt, va_list va)
|
||||
{
|
||||
// write the data if we can
|
||||
return (m_file != nullptr) ? core_vfprintf(m_file, fmt, va) : 0;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// printf - vfprintf to a text file
|
||||
//-------------------------------------------------
|
||||
|
@ -641,13 +652,14 @@ int CLIB_DECL emu_file::printf(const char *fmt, ...)
|
|||
|
||||
|
||||
//-------------------------------------------------
|
||||
// mame_vfprintf - vfprintf to a text file
|
||||
// flush - flush file buffers
|
||||
//-------------------------------------------------
|
||||
|
||||
int emu_file::vprintf(const char *fmt, va_list va)
|
||||
void emu_file::flush()
|
||||
{
|
||||
// write the data if we can
|
||||
return (m_file != nullptr) ? core_vfprintf(m_file, fmt, va) : 0;
|
||||
// flush the buffers if we can
|
||||
if (m_file != nullptr)
|
||||
core_fflush(m_file);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -120,6 +120,8 @@ public:
|
|||
|
||||
// control
|
||||
file_error compress(int compress);
|
||||
|
||||
// position
|
||||
int seek(INT64 offset, int whence);
|
||||
UINT64 tell();
|
||||
bool eof();
|
||||
|
@ -137,6 +139,9 @@ public:
|
|||
int vprintf(const char *fmt, va_list va);
|
||||
int printf(const char *fmt, ...) ATTR_PRINTF(2,3);
|
||||
|
||||
// buffers
|
||||
void flush();
|
||||
|
||||
private:
|
||||
bool compressed_file_ready(void);
|
||||
|
||||
|
|
|
@ -898,6 +898,16 @@ file_error core_truncate(core_file *f, UINT64 offset)
|
|||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
core_truncate - flush write buffer
|
||||
-------------------------------------------------*/
|
||||
|
||||
file_error core_fflush(core_file *f)
|
||||
{
|
||||
return osd_fflush(f->file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
FILENAME UTILITIES
|
||||
|
|
|
@ -120,6 +120,9 @@ int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...) ATTR_PRINTF(2,3);
|
|||
/* file truncation */
|
||||
file_error core_truncate(core_file *f, UINT64 offset);
|
||||
|
||||
/* flush file buffers */
|
||||
file_error core_fflush(core_file *f);
|
||||
|
||||
|
||||
|
||||
/* ----- filename utilities ----- */
|
||||
|
|
|
@ -202,6 +202,21 @@ file_error osd_openpty(osd_file **file, char *name, size_t name_len);
|
|||
file_error osd_truncate(osd_file *file, UINT64 offset);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_fflus: flush file buffers
|
||||
|
||||
Parameters:
|
||||
|
||||
file - handle to a file previously opened via osd_open
|
||||
|
||||
Return value:
|
||||
|
||||
a file_error describing any error that occurred while writing to
|
||||
the file, or FILERR_NONE if no error occurred
|
||||
-----------------------------------------------------------------------------*/
|
||||
file_error osd_fflush(osd_file *file);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_rmfile: deletes a file
|
||||
|
||||
|
|
|
@ -128,6 +128,22 @@ file_error osd_truncate(osd_file *file, UINT64 offset)
|
|||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_fflush
|
||||
//============================================================
|
||||
|
||||
file_error osd_fflush(osd_file *file)
|
||||
{
|
||||
if (!file)
|
||||
return FILERR_FAILURE;
|
||||
|
||||
int result = fflush((FILE *)file);
|
||||
if (result == EOF)
|
||||
return FILERR_FAILURE;
|
||||
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_rmfile
|
||||
|
|
|
@ -369,6 +369,30 @@ file_error osd_truncate(osd_file *file, UINT64 offset)
|
|||
}
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_truncate
|
||||
//============================================================
|
||||
|
||||
file_error osd_fflush(osd_file *file)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
if (!file || !file->handle)
|
||||
return FILERR_FAILURE;
|
||||
|
||||
switch (file->type)
|
||||
{
|
||||
case SDLFILE_FILE:
|
||||
result = fflush(file->handle, offset);
|
||||
if (result == EOF)
|
||||
return error_to_file_error(errno);
|
||||
return FILERR_NONE;
|
||||
|
||||
default:
|
||||
return FILERR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_close
|
||||
|
|
|
@ -281,6 +281,31 @@ file_error osd_truncate(osd_file *file, UINT64 offset)
|
|||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_fflush
|
||||
//============================================================
|
||||
|
||||
file_error osd_fflush(osd_file *file)
|
||||
{
|
||||
if (!file || !file->handle)
|
||||
return FILERR_FAILURE;
|
||||
|
||||
switch (file->type)
|
||||
{
|
||||
case WINFILE_FILE:
|
||||
// attempt to flush file buffers
|
||||
if (!FlushFileBuffers(file->handle))
|
||||
return win_error_to_mame_file_error(GetLastError());
|
||||
break;
|
||||
case WINFILE_SOCKET:
|
||||
return FILERR_FAILURE;
|
||||
case WINFILE_PTTY:
|
||||
return FILERR_FAILURE;
|
||||
|
||||
}
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_close
|
||||
|
|
Loading…
Reference in a new issue