Create retro_write_file

This commit is contained in:
twinaphex 2015-09-19 00:34:24 +02:00
parent a6e0b2f22d
commit 3564532564
6 changed files with 34 additions and 43 deletions

View File

@ -33,6 +33,7 @@
#include <compat/strl.h>
#include <file/file_path.h>
#include <file/file_extract.h>
#include <retro_file.h>
#include "msg_hash.h"
#include "content.h"
@ -118,7 +119,7 @@ static void dump_to_file_desperate(const void *data,
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
strlcat(path, timebuf, sizeof(path));
if (write_file(path, data, size))
if (retro_write_file(path, data, size))
RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path);
else
goto error;
@ -169,7 +170,7 @@ bool save_state(const char *path)
ret = pretro_serialize(data, size);
if (ret)
ret = write_file(path, data, size);
ret = retro_write_file(path, data, size);
if (!ret)
RARCH_ERR("%s \"%s\".\n",
@ -332,7 +333,7 @@ void save_ram_file(const char *path, int type)
if (size <= 0)
return;
if (!write_file(path, data, size))
if (!retro_write_file(path, data, size))
{
RARCH_ERR("%s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));

View File

@ -621,29 +621,6 @@ error:
#endif
/**
* write_file:
* @path : path to file.
* @data : contents to write to the file.
* @size : size of the contents.
*
* Writes data to a file.
*
* Returns: true (1) on success, false (0) otherwise.
*/
bool write_file(const char *path, const void *data, ssize_t size)
{
ssize_t ret = 0;
RFILE *file = retro_fopen(path, RFILE_MODE_WRITE, -1);
if (!file)
return false;
ret = retro_fwrite(file, data, size);
retro_fclose(file);
return (ret == size);
}
#ifdef HAVE_COMPRESSION
/* Generic compressed file loader.
* Extracts to buf, unless optional_filename != 0

View File

@ -54,19 +54,6 @@ struct zlib_file_backend
#define END_OF_CENTRAL_DIR_SIGNATURE 0x06054b50
#endif
static bool zlib_write_file(const char *path, const void *data, ssize_t size)
{
ssize_t ret = 0;
FILE *file = fopen(path, "wb");
if (!file)
return false;
ret = fwrite(data, 1, size, file);
fclose(file);
return (ret == size);
}
#ifdef HAVE_MMAP
#include <sys/mman.h>
#include <sys/stat.h>
@ -422,7 +409,7 @@ int zlib_inflate_data_to_file(zlib_file_handle_t *handle,
}
#endif
if (!zlib_write_file(path, handle->data, size))
if (!retro_write_file(path, handle->data, size))
GOTO_END_ERROR();
end:
@ -664,7 +651,7 @@ static int zip_extract_cb(const char *name, const char *valid_exts,
switch (cmode)
{
case ZLIB_MODE_UNCOMPRESSED:
data->found_content = zlib_write_file(new_path, cdata, size);
data->found_content = retro_write_file(new_path, cdata, size);
return false;
case ZLIB_MODE_DEFLATE:
{
@ -830,7 +817,7 @@ bool zlib_perform_mode(const char *path, const char *valid_exts,
switch (cmode)
{
case 0: /* Uncompressed */
if (!zlib_write_file(path, cdata, size))
if (!retro_write_file(path, cdata, size))
return false;
break;

View File

@ -318,3 +318,26 @@ error:
*buf = NULL;
return 0;
}
/**
* retro_write_file:
* @path : path to file.
* @data : contents to write to the file.
* @size : size of the contents.
*
* Writes data to a file.
*
* Returns: true (1) on success, false (0) otherwise.
*/
bool retro_write_file(const char *path, const void *data, ssize_t size)
{
ssize_t ret = 0;
RFILE *file = retro_fopen(path, RFILE_MODE_WRITE, -1);
if (!file)
return false;
ret = retro_fwrite(file, data, size);
retro_fclose(file);
return (ret == size);
}

View File

@ -61,6 +61,8 @@ bool retro_fmemcpy(const char *path, char *s, size_t len, ssize_t *bytes_written
int retro_fmemcpy_alloc(const char *path, void **buf, ssize_t *len);
bool retro_write_file(const char *path, const void *data, ssize_t size);
int retro_get_fd(RFILE *stream);
#ifdef __cplusplus

View File

@ -21,6 +21,7 @@
#include <file/file_path.h>
#include <file/file_extract.h>
#include <net/net_compat.h>
#include <retro_file.h>
#include "../file_ops.h"
#include "../general.h"
@ -119,7 +120,7 @@ static int cb_generic_download(void *data, size_t len,
fill_pathname_join(output_path, dir_path,
core_updater_path, sizeof(output_path));
if (!write_file(output_path, data, len))
if (!retro_write_file(output_path, data, len))
return -1;
snprintf(msg, sizeof(msg), "%s: %s.",