(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 /* Time format strings with AM-PM designation require special
* handling due to platform dependence */ * 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) const void *ptr)
{ {
char *local = NULL; size_t _len = 0;
char *local = NULL;
const struct tm *timeptr = (const struct tm*)ptr; const struct tm *timeptr = (const struct tm*)ptr;
/* Ensure correct locale is set /* Ensure correct locale is set
* > Required for localised AM/PM strings */ * > Required for localised AM/PM strings */
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
_len = strftime(s, len, format, timeptr);
strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID)) #if !(defined(__linux__) && !defined(ANDROID))
if ((local = local_to_utf8_string_alloc(s))) if ((local = local_to_utf8_string_alloc(s)))
{ {
if (!string_is_empty(local)) if (!string_is_empty(local))
strlcpy(s, local, len); _len = strlcpy(s, local, len);
free(local); free(local);
local = NULL; local = NULL;
} }
#endif #endif
return _len;
} }
/** /**
@ -1422,7 +1422,7 @@ void fill_pathname_application_dir(char *s, size_t len)
#endif #endif
} }
void fill_pathname_home_dir(char *s, size_t len) size_t fill_pathname_home_dir(char *s, size_t len)
{ {
#ifdef __WINRT__ #ifdef __WINRT__
const char *home = uwp_dir_data; 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"); const char *home = getenv("HOME");
#endif #endif
if (home) if (home)
strlcpy(s, home, len); return strlcpy(s, home, len);
else *s = 0;
*s = 0; return 0;
} }
#endif #endif

View File

@ -68,7 +68,7 @@ void path_linked_list_free(struct path_linked_list *in_path_linked_list);
/** /**
* Add a node to the linked list with this path * Add a node to the linked list with this path
* If the first node's path if it's not yet set, * If the first node's path if it's not yet set,
* set this instead * set this instead
**/ **/
void path_linked_list_add_path(struct path_linked_list *in_path_linked_list, char *path); void path_linked_list_add_path(struct path_linked_list *in_path_linked_list, char *path);
@ -342,7 +342,7 @@ size_t fill_str_dated_filename(char *out_filename,
* a backslash on Windows too which takes precedence * a backslash on Windows too which takes precedence
* over regular slash. * over regular slash.
* Hidden non-leaf function cost: * Hidden non-leaf function cost:
* - calls strrchr * - calls strrchr
* *
* @return pointer to last slash/backslash found in @str. * @return pointer to last slash/backslash found in @str.
@ -468,8 +468,8 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
* Joins a directory (@dir) and path (@path) together. * Joins a directory (@dir) and path (@path) together.
* Makes sure not to get two consecutive slashes * Makes sure not to get two consecutive slashes
* between directory and path. * between directory and path.
* *
* Hidden non-leaf function cost: * Hidden non-leaf function cost:
* - calls strlcpy at least once * - calls strlcpy at least once
* - calls fill_pathname_slash() * - calls fill_pathname_slash()
* *
@ -497,7 +497,7 @@ size_t fill_pathname_join(char *out_path, const char *dir,
* Makes sure not to get two consecutive slashes * Makes sure not to get two consecutive slashes
* between directory and path. * between directory and path.
* *
* Hidden non-leaf function cost: * Hidden non-leaf function cost:
* - calls strlcpy 2x * - calls strlcpy 2x
* - calls find_last_slash() * - calls find_last_slash()
* *
@ -522,7 +522,7 @@ size_t fill_pathname_join_special_ext(char *out_path,
* Joins a directory (@dir) and path (@path) together * Joins a directory (@dir) and path (@path) together
* using the given delimiter (@delim). * using the given delimiter (@delim).
* *
* Hidden non-leaf function cost: * Hidden non-leaf function cost:
* - can call strlen * - can call strlen
* - can call strlcpy * - can call strlcpy
* - can call strlcat * - can call strlcat
@ -539,9 +539,9 @@ size_t fill_pathname_abbreviate_special(char *out_path,
/** /**
* fill_pathname_abbreviated_or_relative: * fill_pathname_abbreviated_or_relative:
* *
* Fills the supplied path with either the abbreviated path or * Fills the supplied path with either the abbreviated path or
* the relative path, which ever one has less depth / number of slashes * the relative path, which ever one has less depth / number of slashes
* *
* If lengths of abbreviated and relative paths are the same, * If lengths of abbreviated and relative paths are the same,
* the relative path will be used * the relative path will be used
* @in_path can be an absolute, relative or abbreviated path * @in_path can be an absolute, relative or abbreviated path
@ -555,10 +555,10 @@ size_t fill_pathname_abbreviated_or_relative(char *out_path,
* pathname_conform_slashes_to_os: * pathname_conform_slashes_to_os:
* *
* @path : path * @path : path
* *
* Leaf function. * Leaf function.
* *
* Changes the slashes to the correct kind for the os * Changes the slashes to the correct kind for the os
* So forward slash on linux and backslash on Windows * So forward slash on linux and backslash on Windows
**/ **/
void pathname_conform_slashes_to_os(char *path); void pathname_conform_slashes_to_os(char *path);
@ -569,7 +569,7 @@ void pathname_conform_slashes_to_os(char *path);
* *
* Leaf function. * Leaf function.
* *
* Change all slashes to forward so they are more * Change all slashes to forward so they are more
* portable between Windows and Linux * portable between Windows and Linux
**/ **/
void pathname_make_slashes_portable(char *path); void pathname_make_slashes_portable(char *path);
@ -620,7 +620,7 @@ void path_basedir_wrapper(char *path);
* Assumes path is a directory. Appends a slash * Assumes path is a directory. Appends a slash
* if not already there. * if not already there.
* Hidden non-leaf function cost: * Hidden non-leaf function cost:
* - calls find_last_slash() * - calls find_last_slash()
* - can call strlcat once if it returns false * - can call strlcat once if it returns false
* - calls strlen * - calls strlen
@ -630,7 +630,7 @@ size_t fill_pathname_slash(char *path, size_t size);
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
void fill_pathname_application_path(char *buf, size_t size); void fill_pathname_application_path(char *buf, size_t size);
void fill_pathname_application_dir(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 #endif
/** /**
@ -663,8 +663,10 @@ bool path_mkdir(const char *dir);
bool path_is_directory(const char *path); bool path_is_directory(const char *path);
/* Time format strings with AM-PM designation require special /* Time format strings with AM-PM designation require special
* handling due to platform dependence */ * handling due to platform dependence
void strftime_am_pm(char *s, size_t len, const char* format, * @return Length of the string written to @s
*/
size_t strftime_am_pm(char *s, size_t len, const char* format,
const void* timeptr); const void* timeptr);
bool path_is_character_special(const char *path); bool path_is_character_special(const char *path);

View File

@ -5859,7 +5859,7 @@ static void materialui_render_header(
gfx_display_ctx_datetime_t datetime; gfx_display_ctx_datetime_t datetime;
char timedate_str[MUI_TIMEDATE_MAX_LENGTH]; char timedate_str[MUI_TIMEDATE_MAX_LENGTH];
timedate_str[0] = '\0'; timedate_str[0] = '\0';
datetime.s = timedate_str; datetime.s = timedate_str;
datetime.len = sizeof(timedate_str); datetime.len = sizeof(timedate_str);
@ -5874,7 +5874,7 @@ static void materialui_render_header(
if (!string_is_equal(timedate_str, mui->sys_bar_cache.timedate_str)) if (!string_is_equal(timedate_str, mui->sys_bar_cache.timedate_str))
{ {
/* Cache new string */ /* 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)); MUI_TIMEDATE_MAX_LENGTH * sizeof(char));
/* Cache width */ /* Cache width */
@ -5882,7 +5882,7 @@ static void materialui_render_header(
= font_driver_get_message_width( = font_driver_get_message_width(
mui->font_data.hint.font, mui->font_data.hint.font,
mui->sys_bar_cache.timedate_str, mui->sys_bar_cache.timedate_str,
strlen(mui->sys_bar_cache.timedate_str), _len,
1.0f); 1.0f);
} }

View File

@ -10488,9 +10488,7 @@ static void ozone_draw_header(
if (timedate_enable) if (timedate_enable)
{ {
gfx_display_ctx_datetime_t datetime; gfx_display_ctx_datetime_t datetime;
char timedate[255]; char timedate[256];
timedate[0] = '\0';
datetime.s = timedate; datetime.s = timedate;
datetime.time_mode = settings->uints.menu_timedate_style; 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) if (timedate_enable)
{ {
gfx_display_ctx_datetime_t datetime; gfx_display_ctx_datetime_t datetime;
char timedate[255]; char timedate[256];
size_t _len = 0;
size_t x_pos = 0; size_t x_pos = 0;
if (percent_width) 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.time_mode = settings->uints.menu_timedate_style;
datetime.date_separator = settings->uints.menu_timedate_date_separator; 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( 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, xmb_draw_text(shadows_enable, xmb, settings, timedate,
video_width - xmb->margins_title_left - xmb->icon_size / 4 - x_pos, 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 /* Display the date and time - time_mode will influence how
* the time representation will look like. * 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; 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 /* Copy cached datetime string to input
* menu_display_ctx_datetime_t struct */ * 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 */ /* 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); 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); void menu_display_powerstate(gfx_display_ctx_powerstate_t *powerstate);