mirror of
https://github.com/libretro/RetroArch
synced 2024-12-25 18:25:21 +00:00
strftime - write directly into string instead of using intermediary copies
This commit is contained in:
parent
772620f6fa
commit
cdef3ff9f7
@ -569,20 +569,15 @@ size_t fill_str_dated_filename(char *s,
|
||||
const char *in_str, const char *ext, size_t len)
|
||||
{
|
||||
struct tm tm_;
|
||||
char format[NAME_MAX_LENGTH];
|
||||
size_t _len = 0;
|
||||
time_t cur_time = time(NULL);
|
||||
rtime_localtime(&cur_time, &tm_);
|
||||
_len = strlcpy(s, in_str, len);
|
||||
if (string_is_empty(ext))
|
||||
{
|
||||
strftime(format, sizeof(format), "-%y%m%d-%H%M%S", &tm_);
|
||||
_len += strlcpy(s + _len, format, len - _len);
|
||||
}
|
||||
_len += strftime(s + _len, len - _len, "-%y%m%d-%H%M%S", &tm_);
|
||||
else
|
||||
{
|
||||
strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", &tm_);
|
||||
_len += strlcpy(s + _len, format, len - _len);
|
||||
_len += strftime(s + _len, len - _len, "-%y%m%d-%H%M%S.", &tm_);
|
||||
_len += strlcpy(s + _len, ext, len - _len);
|
||||
}
|
||||
return _len;
|
||||
|
@ -642,6 +642,9 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
|
||||
* */
|
||||
size_t menu_display_timedate(gfx_display_ctx_datetime_t *datetime)
|
||||
{
|
||||
/* Storage container for current menu datetime
|
||||
* representation string */
|
||||
static char datetime_cache[NAME_MAX_LENGTH];
|
||||
struct menu_state *menu_st = &menu_driver_state;
|
||||
|
||||
/* Trigger an update, if required */
|
||||
@ -999,16 +1002,16 @@ size_t menu_display_timedate(gfx_display_ctx_datetime_t *datetime)
|
||||
}
|
||||
|
||||
if (has_am_pm)
|
||||
strftime_am_pm(menu_st->datetime_cache, sizeof(menu_st->datetime_cache),
|
||||
strftime_am_pm(datetime_cache, sizeof(datetime_cache),
|
||||
format_str, &tm_);
|
||||
else
|
||||
strftime(menu_st->datetime_cache, sizeof(menu_st->datetime_cache),
|
||||
strftime(datetime_cache, sizeof(datetime_cache),
|
||||
format_str, &tm_);
|
||||
}
|
||||
|
||||
/* Copy cached datetime string to input
|
||||
* menu_display_ctx_datetime_t struct */
|
||||
return strlcpy(datetime->s, menu_st->datetime_cache, datetime->len);
|
||||
return strlcpy(datetime->s, datetime_cache, datetime->len);
|
||||
}
|
||||
|
||||
/* Display current (battery) power state */
|
||||
|
10
save.c
10
save.c
@ -418,18 +418,12 @@ static bool dump_to_file_desperate(const void *data,
|
||||
size_t _len;
|
||||
time_t time_;
|
||||
struct tm tm_;
|
||||
char timebuf[256];
|
||||
timebuf [0] = '\0';
|
||||
time(&time_);
|
||||
|
||||
rtime_localtime(&time_, &tm_);
|
||||
|
||||
strftime(timebuf, 256 * sizeof(char),
|
||||
"%Y-%m-%d-%H-%M-%S", &tm_);
|
||||
|
||||
_len = strlcat(path, "/RetroArch-recovery-", sizeof(path));
|
||||
_len += snprintf(path + _len, sizeof(path) - _len, "%u", type);
|
||||
strlcpy(path + _len, timebuf, sizeof(path) - _len);
|
||||
strftime(path + _len, sizeof(path) - _len,
|
||||
"%Y-%m-%d-%H-%M-%S", &tm_);
|
||||
|
||||
/* Fallback (emergency) saves are always
|
||||
* uncompressed
|
||||
|
Loading…
Reference in New Issue
Block a user