mirror of
https://github.com/holub/mame
synced 2025-04-22 00:11:58 +03:00
Added a core_fopen_ram_copy() call, similar to core_fopen_ram() except that it
copies the memory
This commit is contained in:
parent
c0b1419a96
commit
f1d5b2a1ec
@ -133,11 +133,12 @@ file_error core_fopen(const char *filename, UINT32 openflags, core_file **file)
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
core_fopen_ram - open a RAM-based buffer for
|
||||
file-like access and return an error code
|
||||
core_fopen_ram_internal - open a RAM-based buffer
|
||||
for file-like access, possibly copying the data,
|
||||
and return an error code
|
||||
-------------------------------------------------*/
|
||||
|
||||
file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file)
|
||||
static file_error core_fopen_ram_internal(const void *data, size_t length, int copy_buffer, UINT32 openflags, core_file **file)
|
||||
{
|
||||
/* can only do this for read access */
|
||||
if ((openflags & OPEN_FLAG_WRITE) != 0)
|
||||
@ -146,11 +147,19 @@ file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, cor
|
||||
return FILERR_INVALID_ACCESS;
|
||||
|
||||
/* allocate the file itself */
|
||||
*file = malloc(sizeof(**file));
|
||||
*file = malloc(sizeof(**file) + (copy_buffer ? length : 0));
|
||||
if (*file == NULL)
|
||||
return FILERR_OUT_OF_MEMORY;
|
||||
memset(*file, 0, sizeof(**file));
|
||||
|
||||
/* copy the buffer, if we're asked to */
|
||||
if (copy_buffer)
|
||||
{
|
||||
void *dest = ((UINT8 *) *file) + sizeof(**file);
|
||||
memcpy(dest, data, length);
|
||||
data = dest;
|
||||
}
|
||||
|
||||
/* claim the buffer */
|
||||
(*file)->data = (UINT8 *)data;
|
||||
(*file)->length = length;
|
||||
@ -160,6 +169,28 @@ file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, cor
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
core_fopen_ram - open a RAM-based buffer for
|
||||
file-like access and return an error code
|
||||
-------------------------------------------------*/
|
||||
|
||||
file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file)
|
||||
{
|
||||
return core_fopen_ram_internal(data, length, FALSE, openflags, file);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
core_fopen_ram_copy - open a copy of a RAM-based
|
||||
buffer for file-like access and return an error code
|
||||
-------------------------------------------------*/
|
||||
|
||||
file_error core_fopen_ram_copy(const void *data, size_t length, UINT32 openflags, core_file **file)
|
||||
{
|
||||
return core_fopen_ram_internal(data, length, TRUE, openflags, file);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
core_fclose - closes a file
|
||||
-------------------------------------------------*/
|
||||
|
@ -49,6 +49,9 @@ file_error core_fopen(const char *filename, UINT32 openflags, core_file **file);
|
||||
/* open a RAM-based "file" using the given data and length (read-only) */
|
||||
file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file);
|
||||
|
||||
/* open a RAM-based "file" using the given data and length (read-only), copying the data */
|
||||
file_error core_fopen_ram_copy(const void *data, size_t length, UINT32 openflags, core_file **file);
|
||||
|
||||
/* close an open file */
|
||||
void core_fclose(core_file *file);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user