From cc3835c91554ae6c98f7a3987fa0898237ddd3c6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 17 Aug 2014 17:35:17 +0200 Subject: [PATCH] Rewrite core_info_get_custom_config --- apple/iOS/menu.m | 7 +++---- core_info.c | 18 +++++++++++------- core_info.h | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index ba08c0aaf4..5023de0fee 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -792,8 +792,9 @@ static void RunActionSheet(const char* title, const struct string_list* items, U { const core_info_t *tmp = (const core_info_t*)core_info_list_get_by_id(core.UTF8String); self.title = tmp ? BOXSTRING(tmp->display_name) : BOXSTRING(core.UTF8String); - - _pathToSave = BOXSTRING(core_info_get_custom_config(core.UTF8String, buffer, sizeof(buffer))); + + core_info_get_custom_config(core.UTF8String, buffer, sizeof(buffer)); + _pathToSave = BOXSTRING(buffer); self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteCustom)]; } else @@ -986,9 +987,7 @@ static bool copy_config(const char *src_path, const char *dst_path) if (g_defaults.config_path[0] != '\0' && path[0] != '\0') { if (!copy_config(g_defaults.config_path, path)) - { RARCH_WARN("Could not create custom config at %s.", path); - } } } diff --git a/core_info.c b/core_info.c index 94fb599f2a..7bb00609f5 100644 --- a/core_info.c +++ b/core_info.c @@ -456,22 +456,26 @@ const core_info_t *core_info_list_get_by_id(const char *core_id) return 0; } -const char *core_info_get_custom_config(const char *core_id, char *buffer, size_t buffer_length) +void core_info_get_custom_config(const char *core_id, char *buf, size_t sizeof_buf) { - if (!core_id || !buffer || !buffer_length) - return 0; + if (!core_id || !buf || !sizeof_buf) + return; - fill_pathname_join(buffer, g_defaults.menu_config_dir, path_basename(core_id), buffer_length); - fill_pathname(buffer, buffer, ".cfg", buffer_length); - return buffer; + fill_pathname_join(buf, g_defaults.menu_config_dir, path_basename(core_id), sizeof_buf); + fill_pathname(buf, buf, ".cfg", sizeof_buf); } bool core_info_has_custom_config(const char *core_id) { char path[PATH_MAX]; + if (!core_id) return false; core_info_get_custom_config(core_id, path, sizeof(path)); - return path_file_exists(path); + + if (path[0] != '\0') + return path_file_exists(path); + + return false; } diff --git a/core_info.h b/core_info.h index 933a0d0b70..0750b3102c 100644 --- a/core_info.h +++ b/core_info.h @@ -92,7 +92,7 @@ void core_info_set_core_path(void); core_info_list_t *core_info_list_get(void); const core_info_t *core_info_list_get_by_id(const char *core_id); -const char *core_info_get_custom_config(const char *core_id, char *buffer, size_t buffer_length); +void core_info_get_custom_config(const char *core_id, char *buf, size_t sizeof_buf); bool core_info_has_custom_config(const char *core_id); #ifdef __cplusplus