Create write_empty_file helper function in file_path.c

This commit is contained in:
twinaphex 2014-09-15 05:49:48 +02:00
parent 5e43f375c6
commit cbce0c7b8a
4 changed files with 24 additions and 13 deletions

View File

@ -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)

View File

@ -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
{

View File

@ -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;

View File

@ -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)