Revert "Move strftime_am_pm to libretro-common rtime.c, remove duplicate"

This reverts commit 99186b1056b7e71d876bb868348059d2eec98ee8.
This commit is contained in:
libretroadmin 2022-07-12 03:31:42 +02:00
parent 99186b1056
commit 06e1b6a68f
4 changed files with 58 additions and 40 deletions

View File

@ -40,11 +40,6 @@ void rtime_init(void);
/* Must be called upon program termination */ /* Must be called upon program termination */
void rtime_deinit(void); void rtime_deinit(void);
/* Time format strings with AM-PM designation require special
* handling due to platform dependence */
void strftime_am_pm(char *s, size_t len, const char* format,
const struct tm* timeptr);
/* Thread-safe wrapper for localtime() */ /* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result); struct tm *rtime_localtime(const time_t *timep, struct tm *result);

View File

@ -27,13 +27,7 @@
#endif #endif
#include <string.h> #include <string.h>
#include <locale.h>
#include <time/rtime.h> #include <time/rtime.h>
#include <string/stdstring.h>
#if !(defined(__linux__) && !defined(ANDROID))
#include <encodings/utf.h>
#endif
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
/* TODO/FIXME - global */ /* TODO/FIXME - global */
@ -85,27 +79,3 @@ struct tm *rtime_localtime(const time_t *timep, struct tm *result)
return result; return result;
} }
/* Time format strings with AM-PM designation require special
* handling due to platform dependence */
void strftime_am_pm(char *s, size_t len, const char* format,
const struct tm* timeptr)
{
char *local = NULL;
/* Ensure correct locale is set
* > Required for localised AM/PM strings */
setlocale(LC_TIME, "");
strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID))
if ((local = local_to_utf8_string_alloc(s)))
{
if (!string_is_empty(local))
strlcpy(s, local, len);
free(local);
local = NULL;
}
#endif
}

View File

@ -636,6 +636,32 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
return match_found; return match_found;
} }
/* Time format strings with AM-PM designation require special
* handling due to platform dependence */
static void strftime_am_pm(char *s, size_t len, const char* format,
const struct tm* timeptr)
{
char *local = NULL;
/* Ensure correct locale is set
* > Required for localised AM/PM strings */
setlocale(LC_TIME, "");
strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID))
local = local_to_utf8_string_alloc(s);
if (local)
{
if (!string_is_empty(local))
strlcpy(s, local, len);
free(local);
local = NULL;
}
#endif
}
/* Display the date and time - time_mode will influence how /* Display the date and time - time_mode will influence how
* the time representation will look like. * the time representation will look like.
* */ * */

View File

@ -62,9 +62,11 @@ static bool RtlJSONObjectMemberHandler(void *ctx, const char *s, size_t len)
{ {
RtlJSONContext *p_ctx = (RtlJSONContext*)ctx; RtlJSONContext *p_ctx = (RtlJSONContext*)ctx;
/* something went wrong */
if (p_ctx->current_entry_val) if (p_ctx->current_entry_val)
{
/* something went wrong */
return false; return false;
}
if (len) if (len)
{ {
@ -127,7 +129,8 @@ static void runtime_log_read_file(runtime_log_t *runtime_log)
} }
/* Initialise JSON parser */ /* Initialise JSON parser */
if (!(parser = rjson_open_rfile(file))) parser = rjson_open_rfile(file);
if (!parser)
{ {
RARCH_ERR("Failed to create JSON parser.\n"); RARCH_ERR("Failed to create JSON parser.\n");
goto end; goto end;
@ -374,8 +377,9 @@ runtime_log_t *runtime_log_init(
/* Phew... If we get this far then all is well. /* Phew... If we get this far then all is well.
* > Create 'runtime_log' object */ * > Create 'runtime_log' object */
if (!(runtime_log = (runtime_log_t*) runtime_log = (runtime_log_t*)
malloc(sizeof(*runtime_log)))) malloc(sizeof(*runtime_log));
if (!runtime_log)
return NULL; return NULL;
/* > Populate default values */ /* > Populate default values */
@ -621,6 +625,29 @@ void runtime_log_get_last_played_time(runtime_log_t *runtime_log,
mktime(time_info); mktime(time_info);
} }
static void last_played_strftime(char *s, size_t len, const char *format,
const struct tm *timeptr)
{
char *local = NULL;
/* Ensure correct locale is set */
setlocale(LC_TIME, "");
/* Generate string */
strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID))
local = local_to_utf8_string_alloc(s);
if (local)
{
if (!string_is_empty(local))
strlcpy(s, local, len);
free(local);
local = NULL;
}
#endif
}
static void last_played_human(runtime_log_t *runtime_log, static void last_played_human(runtime_log_t *runtime_log,
char *str, size_t len) char *str, size_t len)
{ {
@ -828,7 +855,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
/* Get time */ /* Get time */
struct tm time_info; struct tm time_info;
runtime_log_get_last_played_time(runtime_log, &time_info); runtime_log_get_last_played_time(runtime_log, &time_info);
strftime_am_pm(tmp, sizeof(tmp), format_str, &time_info); last_played_strftime(tmp, sizeof(tmp), format_str, &time_info);
} }
snprintf(str, len, "%s%s", snprintf(str, len, "%s%s",
msg_hash_to_str( msg_hash_to_str(