diff --git a/file_path.c b/file_path.c index 2c2f61a11e..245be4b23c 100644 --- a/file_path.c +++ b/file_path.c @@ -80,6 +80,17 @@ bool write_file(const char *path, const void *data, size_t size) return ret; } +bool write_empty_file(const char *path) +{ + FILE *file = fopen(path, "w"); + if (!file) + return false; + + fclose(file); + + return true; +} + /* Generic compressed file loader. */ #ifdef HAVE_COMPRESSION long read_compressed_file(const char * path, void **buf) diff --git a/file_path.h b/file_path.h index bb10e4c6bc..cd5f9123a7 100644 --- a/file_path.h +++ b/file_path.h @@ -46,6 +46,7 @@ long read_compressed_file(const char * path, void **buf); long read_file(const char *path, void **buf); bool read_file_string(const char *path, char **buf); bool write_file(const char *path, const void *buf, size_t size); +bool write_empty_file(const char *path); union string_list_elem_attr { diff --git a/playlist.c b/playlist.c index e89dd0a1ac..b953399bca 100644 --- a/playlist.c +++ b/playlist.c @@ -235,13 +235,6 @@ end: return true; } -static void playlist_create_new(const char *path) -{ - FILE *file = fopen(path, "w"); - if (file) - fclose(file); -} - content_playlist_t *content_playlist_init(const char *path, size_t size) { RARCH_LOG("Opening playlist: %s.\n", path); @@ -260,9 +253,6 @@ content_playlist_t *content_playlist_init(const char *path, size_t size) playlist->cap = size; - if (!path_file_exists(path)) - playlist_create_new(path); - if (!content_playlist_read_file(playlist, path)) goto error; diff --git a/retroarch.c b/retroarch.c index 5217ff7c0c..a2d2d86674 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3479,9 +3479,18 @@ void rarch_main_command(unsigned cmd) break; case RARCH_CMD_HISTORY_INIT: if (!g_extern.history) - g_extern.history = content_playlist_init( - g_settings.content_history_path, - g_settings.content_history_size); + { + bool init_history = true; + + if (!path_file_exists(g_settings.content_history_path)) + init_history = write_empty_file( + g_settings.content_history_path); + + if (init_history) + g_extern.history = content_playlist_init( + g_settings.content_history_path, + g_settings.content_history_size); + } break; case RARCH_CMD_HISTORY_DEINIT: if (g_extern.history)