(libretro-common) Some functions now return len

This commit is contained in:
libretroadmin 2024-06-15 12:47:51 +02:00
parent 9e71a566cc
commit 827e631903
7 changed files with 38 additions and 37 deletions

View File

@ -71,27 +71,27 @@
/* 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,
size_t strftime_am_pm(char *s, size_t len, const char* format,
const void *ptr)
{
size_t _len = 0;
char *local = NULL;
const struct tm *timeptr = (const struct tm*)ptr;
/* Ensure correct locale is set
* > Required for localised AM/PM strings */
setlocale(LC_TIME, "");
strftime(s, len, format, timeptr);
_len = 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);
_len = strlcpy(s, local, len);
free(local);
local = NULL;
}
#endif
return _len;
}
/**
@ -1422,7 +1422,7 @@ void fill_pathname_application_dir(char *s, size_t len)
#endif
}
void fill_pathname_home_dir(char *s, size_t len)
size_t fill_pathname_home_dir(char *s, size_t len)
{
#ifdef __WINRT__
const char *home = uwp_dir_data;
@ -1430,9 +1430,9 @@ void fill_pathname_home_dir(char *s, size_t len)
const char *home = getenv("HOME");
#endif
if (home)
strlcpy(s, home, len);
else
return strlcpy(s, home, len);
*s = 0;
return 0;
}
#endif

View File

@ -630,7 +630,7 @@ size_t fill_pathname_slash(char *path, size_t size);
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
void fill_pathname_application_path(char *buf, size_t size);
void fill_pathname_application_dir(char *buf, size_t size);
void fill_pathname_home_dir(char *buf, size_t size);
size_t fill_pathname_home_dir(char *buf, size_t size);
#endif
/**
@ -663,8 +663,10 @@ bool path_mkdir(const char *dir);
bool path_is_directory(const char *path);
/* 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,
* handling due to platform dependence
* @return Length of the string written to @s
*/
size_t strftime_am_pm(char *s, size_t len, const char* format,
const void* timeptr);
bool path_is_character_special(const char *path);

View File

@ -5874,7 +5874,7 @@ static void materialui_render_header(
if (!string_is_equal(timedate_str, mui->sys_bar_cache.timedate_str))
{
/* Cache new string */
strlcpy(mui->sys_bar_cache.timedate_str, timedate_str,
size_t _len = strlcpy(mui->sys_bar_cache.timedate_str, timedate_str,
MUI_TIMEDATE_MAX_LENGTH * sizeof(char));
/* Cache width */
@ -5882,7 +5882,7 @@ static void materialui_render_header(
= font_driver_get_message_width(
mui->font_data.hint.font,
mui->sys_bar_cache.timedate_str,
strlen(mui->sys_bar_cache.timedate_str),
_len,
1.0f);
}

View File

@ -10488,9 +10488,7 @@ static void ozone_draw_header(
if (timedate_enable)
{
gfx_display_ctx_datetime_t datetime;
char timedate[255];
timedate[0] = '\0';
char timedate[256];
datetime.s = timedate;
datetime.time_mode = settings->uints.menu_timedate_style;

View File

@ -6127,7 +6127,8 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
if (timedate_enable)
{
gfx_display_ctx_datetime_t datetime;
char timedate[255];
char timedate[256];
size_t _len = 0;
size_t x_pos = 0;
if (percent_width)
@ -6169,10 +6170,10 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
datetime.time_mode = settings->uints.menu_timedate_style;
datetime.date_separator = settings->uints.menu_timedate_date_separator;
menu_display_timedate(&datetime);
_len = menu_display_timedate(&datetime);
title_header_max_width = x_pos + font_driver_get_message_width(
xmb->font, timedate, strlen(timedate), 1.0f);
xmb->font, timedate, _len, 1.0f);
xmb_draw_text(shadows_enable, xmb, settings, timedate,
video_width - xmb->margins_title_left - xmb->icon_size / 4 - x_pos,

View File

@ -640,7 +640,7 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
/* Display the date and time - time_mode will influence how
* the time representation will look like.
* */
void menu_display_timedate(gfx_display_ctx_datetime_t *datetime)
size_t menu_display_timedate(gfx_display_ctx_datetime_t *datetime)
{
struct menu_state *menu_st = &menu_driver_state;
@ -1008,7 +1008,7 @@ void menu_display_timedate(gfx_display_ctx_datetime_t *datetime)
/* Copy cached datetime string to input
* menu_display_ctx_datetime_t struct */
strlcpy(datetime->s, menu_st->datetime_cache, datetime->len);
return strlcpy(datetime->s, menu_st->datetime_cache, datetime->len);
}
/* Display current (battery) power state */

View File

@ -627,7 +627,7 @@ bool menu_driver_init(bool video_is_threaded);
retro_time_t menu_driver_get_current_time(void);
void menu_display_timedate(gfx_display_ctx_datetime_t *datetime);
size_t menu_display_timedate(gfx_display_ctx_datetime_t *datetime);
void menu_display_powerstate(gfx_display_ctx_powerstate_t *powerstate);