Create write_empty_file helper function in file_path.c
This commit is contained in:
parent
5e43f375c6
commit
cbce0c7b8a
11
file_path.c
11
file_path.c
|
@ -80,6 +80,17 @@ bool write_file(const char *path, const void *data, size_t size)
|
||||||
return ret;
|
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. */
|
/* Generic compressed file loader. */
|
||||||
#ifdef HAVE_COMPRESSION
|
#ifdef HAVE_COMPRESSION
|
||||||
long read_compressed_file(const char * path, void **buf)
|
long read_compressed_file(const char * path, void **buf)
|
||||||
|
|
|
@ -46,6 +46,7 @@ long read_compressed_file(const char * path, void **buf);
|
||||||
long read_file(const char *path, void **buf);
|
long read_file(const char *path, void **buf);
|
||||||
bool read_file_string(const char *path, char **buf);
|
bool read_file_string(const char *path, char **buf);
|
||||||
bool write_file(const char *path, const void *buf, size_t size);
|
bool write_file(const char *path, const void *buf, size_t size);
|
||||||
|
bool write_empty_file(const char *path);
|
||||||
|
|
||||||
union string_list_elem_attr
|
union string_list_elem_attr
|
||||||
{
|
{
|
||||||
|
|
10
playlist.c
10
playlist.c
|
@ -235,13 +235,6 @@ end:
|
||||||
return true;
|
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)
|
content_playlist_t *content_playlist_init(const char *path, size_t size)
|
||||||
{
|
{
|
||||||
RARCH_LOG("Opening playlist: %s.\n", path);
|
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;
|
playlist->cap = size;
|
||||||
|
|
||||||
if (!path_file_exists(path))
|
|
||||||
playlist_create_new(path);
|
|
||||||
|
|
||||||
if (!content_playlist_read_file(playlist, path))
|
if (!content_playlist_read_file(playlist, path))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
15
retroarch.c
15
retroarch.c
|
@ -3479,9 +3479,18 @@ void rarch_main_command(unsigned cmd)
|
||||||
break;
|
break;
|
||||||
case RARCH_CMD_HISTORY_INIT:
|
case RARCH_CMD_HISTORY_INIT:
|
||||||
if (!g_extern.history)
|
if (!g_extern.history)
|
||||||
g_extern.history = content_playlist_init(
|
{
|
||||||
g_settings.content_history_path,
|
bool init_history = true;
|
||||||
g_settings.content_history_size);
|
|
||||||
|
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;
|
break;
|
||||||
case RARCH_CMD_HISTORY_DEINIT:
|
case RARCH_CMD_HISTORY_DEINIT:
|
||||||
if (g_extern.history)
|
if (g_extern.history)
|
||||||
|
|
Loading…
Reference in New Issue