From 6475d0ca5494ef23b5eb03681223b818edb99406 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Mon, 11 Jul 2022 19:12:14 +0200 Subject: [PATCH] Make code identical for last_played_strftime and strftime_am_pm - see opportunity here to cutdown on duplication and make this a public function --- menu/menu_driver.c | 8 ++++---- runtime_file.c | 29 +++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index de102baaeb..f7ac980690 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -638,7 +638,7 @@ bool menu_entries_list_search(const char *needle, size_t *idx) /* Time format strings with AM-PM designation require special * handling due to platform dependence */ -static void strftime_am_pm(char* ptr, size_t maxsize, const char* format, +static void strftime_am_pm(char *s, size_t len, const char* format, const struct tm* timeptr) { char *local = NULL; @@ -647,12 +647,12 @@ static void strftime_am_pm(char* ptr, size_t maxsize, const char* format, * > Required for localised AM/PM strings */ setlocale(LC_TIME, ""); - strftime(ptr, maxsize, format, timeptr); + strftime(s, len, format, timeptr); #if !(defined(__linux__) && !defined(ANDROID)) - local = local_to_utf8_string_alloc(ptr); + local = local_to_utf8_string_alloc(s); if (!string_is_empty(local)) - strlcpy(ptr, local, maxsize); + strlcpy(s, local, len); if (local) { diff --git a/runtime_file.c b/runtime_file.c index 2fcdffbe1b..3580a689f2 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -625,30 +625,21 @@ void runtime_log_get_last_played_time(runtime_log_t *runtime_log, mktime(time_info); } -static void last_played_strftime(runtime_log_t *runtime_log, - char *str, size_t len, const char *format) +static void last_played_strftime(char *s, size_t len, const char *format, + const struct tm *timeptr) { - struct tm time_info; char *local = NULL; - if (!runtime_log) - return; - - /* Get time */ - runtime_log_get_last_played_time(runtime_log, &time_info); - /* Ensure correct locale is set */ setlocale(LC_TIME, ""); /* Generate string */ -#if defined(__linux__) && !defined(ANDROID) - strftime(str, len, format, &time_info); -#else - strftime(str, len, format, &time_info); - local = local_to_utf8_string_alloc(str); + strftime(s, len, format, timeptr); +#if !(defined(__linux__) && !defined(ANDROID)) + local = local_to_utf8_string_alloc(s); if (!string_is_empty(local)) - strlcpy(str, local, len); + strlcpy(s, local, len); if (local) { @@ -860,7 +851,13 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log, if (has_am_pm) { - last_played_strftime(runtime_log, tmp, sizeof(tmp), format_str); + if (runtime_log) + { + /* Get time */ + struct tm time_info; + runtime_log_get_last_played_time(runtime_log, &time_info); + last_played_strftime(tmp, sizeof(tmp), format_str, &time_info); + } snprintf(str, len, "%s%s", msg_hash_to_str( MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),