From 3564532564c8c7f1d88e43cabd547e0507d92613 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 19 Sep 2015 00:34:24 +0200 Subject: [PATCH] Create retro_write_file --- content.c | 7 ++++--- file_ops.c | 23 ----------------------- libretro-common/file/file_extract.c | 19 +++---------------- libretro-common/file/retro_file.c | 23 +++++++++++++++++++++++ libretro-common/include/retro_file.h | 2 ++ tasks/task_http.c | 3 ++- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/content.c b/content.c index 60c777be1b..b96a023ae0 100644 --- a/content.c +++ b/content.c @@ -33,6 +33,7 @@ #include #include #include +#include #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)); diff --git a/file_ops.c b/file_ops.c index 9f16ef260c..f2a6afb456 100644 --- a/file_ops.c +++ b/file_ops.c @@ -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 diff --git a/libretro-common/file/file_extract.c b/libretro-common/file/file_extract.c index ab53cdee49..cf4063e90c 100644 --- a/libretro-common/file/file_extract.c +++ b/libretro-common/file/file_extract.c @@ -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 #include @@ -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; diff --git a/libretro-common/file/retro_file.c b/libretro-common/file/retro_file.c index 0b82a54d10..ae135e7f35 100644 --- a/libretro-common/file/retro_file.c +++ b/libretro-common/file/retro_file.c @@ -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); +} diff --git a/libretro-common/include/retro_file.h b/libretro-common/include/retro_file.h index 1bc83e501a..f2968a42ed 100644 --- a/libretro-common/include/retro_file.h +++ b/libretro-common/include/retro_file.h @@ -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 diff --git a/tasks/task_http.c b/tasks/task_http.c index 267a7ad7f6..f081ed3b12 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -21,6 +21,7 @@ #include #include #include +#include #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.",