Small cleanups - conventionalize char *s, size_t parameter usage

This commit is contained in:
LibretroAdmin 2024-12-30 09:44:40 +01:00
parent e07028e892
commit 56c63b8c19
4 changed files with 54 additions and 52 deletions

View File

@ -694,12 +694,14 @@ bool command_show_osd_msg(command_t *cmd, const char* arg)
bool command_load_state_slot(command_t *cmd, const char *arg) bool command_load_state_slot(command_t *cmd, const char *arg)
{ {
char state_path[16384]; char state_path[16384];
size_t _len = 0;
char reply[128] = ""; char reply[128] = "";
unsigned int slot = (unsigned int)strtoul(arg, NULL, 10); unsigned int slot = (unsigned int)strtoul(arg, NULL, 10);
bool savestates_enabled = core_info_current_supports_savestate(); bool savestates_enabled = core_info_current_supports_savestate();
bool ret = false; bool ret = false;
state_path[0] = '\0'; state_path[0] = '\0';
snprintf(reply, sizeof(reply) - 1, "LOAD_STATE_SLOT %d", slot); _len = strlcpy(reply, "LOAD_STATE_SLOT ", sizeof(reply));
_len += snprintf(reply + _len, sizeof(reply) - _len, "%d", slot);
if (savestates_enabled) if (savestates_enabled)
{ {
size_t info_size; size_t info_size;
@ -716,7 +718,7 @@ bool command_load_state_slot(command_t *cmd, const char *arg)
else else
ret = false; ret = false;
cmd->replier(cmd, reply, strlen(reply)); cmd->replier(cmd, reply, _len);
return ret; return ret;
} }
@ -1449,6 +1451,7 @@ static void scan_states(settings_t *settings,
for (i = 0; i < dir_list->size; i++) for (i = 0; i < dir_list->size; i++)
{ {
unsigned idx; unsigned idx;
size_t _len;
char elem_base[128]; char elem_base[128];
const char *ext = NULL; const char *ext = NULL;
const char *end = NULL; const char *end = NULL;
@ -1457,7 +1460,7 @@ static void scan_states(settings_t *settings,
if (string_is_empty(dir_elem)) if (string_is_empty(dir_elem))
continue; continue;
fill_pathname_base(elem_base, dir_elem, sizeof(elem_base)); _len = fill_pathname_base(elem_base, dir_elem, sizeof(elem_base));
/* Only consider files with a '.state' extension /* Only consider files with a '.state' extension
* > i.e. Ignore '.state.auto', '.state.bak', etc. */ * > i.e. Ignore '.state.auto', '.state.bak', etc. */
@ -1476,11 +1479,11 @@ static void scan_states(settings_t *settings,
if (savefile_root_length == 0) if (savefile_root_length == 0)
{ {
savefile_root = dir_elem; savefile_root = dir_elem;
savefile_root_length = strlen(dir_elem); savefile_root_length = _len;
} }
/* Decode the savestate index */ /* Decode the savestate index */
end = dir_elem + strlen(dir_elem); end = dir_elem + _len;
while ((end > dir_elem) && ISDIGIT((int)end[-1])) while ((end > dir_elem) && ISDIGIT((int)end[-1]))
{ {
end--; end--;
@ -1700,13 +1703,12 @@ void command_event_set_replay_auto_index(settings_t *settings)
char elem_base[128] = {0}; char elem_base[128] = {0};
const char *end = NULL; const char *end = NULL;
const char *dir_elem = dir_list->elems[i].data; const char *dir_elem = dir_list->elems[i].data;
size_t _len = fill_pathname_base(elem_base, dir_elem, sizeof(elem_base));
fill_pathname_base(elem_base, dir_elem, sizeof(elem_base));
if (strstr(elem_base, state_base) != elem_base) if (strstr(elem_base, state_base) != elem_base)
continue; continue;
end = dir_elem + strlen(dir_elem); end = dir_elem + _len;
while ((end > dir_elem) && ISDIGIT((int)end[-1])) while ((end > dir_elem) && ISDIGIT((int)end[-1]))
end--; end--;
@ -1756,6 +1758,7 @@ void command_event_set_replay_garbage_collect(
for (i = 0; i < dir_list->size; i++) for (i = 0; i < dir_list->size; i++)
{ {
unsigned idx; unsigned idx;
size_t _len;
char elem_base[128]; char elem_base[128];
const char *ext = NULL; const char *ext = NULL;
const char *end = NULL; const char *end = NULL;
@ -1764,7 +1767,7 @@ void command_event_set_replay_garbage_collect(
if (string_is_empty(dir_elem)) if (string_is_empty(dir_elem))
continue; continue;
fill_pathname_base(elem_base, dir_elem, sizeof(elem_base)); _len = fill_pathname_base(elem_base, dir_elem, sizeof(elem_base));
/* Only consider files with a '.replayXX' extension /* Only consider files with a '.replayXX' extension
* > i.e. Ignore '.replay.auto', '.replay.bak', etc. */ * > i.e. Ignore '.replay.auto', '.replay.bak', etc. */
@ -1782,7 +1785,7 @@ void command_event_set_replay_garbage_collect(
cnt++; cnt++;
/* > Get index */ /* > Get index */
end = dir_elem + strlen(dir_elem); end = dir_elem + _len;
while ((end > dir_elem) && ISDIGIT((int)end[-1])) while ((end > dir_elem) && ISDIGIT((int)end[-1]))
end--; end--;

View File

@ -201,7 +201,7 @@ static int task_database_iterate_start(retro_task_t *task,
return 0; return 0;
} }
static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_len, const char *filename) static int intfstream_get_serial(intfstream_t *fd, char *s, size_t len, const char *filename)
{ {
const char *system_name = NULL; const char *system_name = NULL;
if (detect_system(fd, &system_name, filename) >= 1) if (detect_system(fd, &system_name, filename) >= 1)
@ -212,19 +212,19 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_l
if (STRLEN_CONST("Sony - PlayStation Portable") == system_len && if (STRLEN_CONST("Sony - PlayStation Portable") == system_len &&
string_is_equal_fast(system_name, "Sony - PlayStation Portable", system_len)) string_is_equal_fast(system_name, "Sony - PlayStation Portable", system_len))
{ {
if (detect_psp_game(fd, serial, serial_len, filename) != 0) if (detect_psp_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
else if (STRLEN_CONST("Sony - PlayStation") == system_len && else if (STRLEN_CONST("Sony - PlayStation") == system_len &&
string_is_equal_fast(system_name, "Sony - PlayStation", system_len)) string_is_equal_fast(system_name, "Sony - PlayStation", system_len))
{ {
if (detect_ps1_game(fd, serial, serial_len, filename) != 0) if (detect_ps1_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
else if (STRLEN_CONST("Sony - PlayStation 2") == system_len && else if (STRLEN_CONST("Sony - PlayStation 2") == system_len &&
string_is_equal_fast(system_name, "Sony - PlayStation 2", system_len)) string_is_equal_fast(system_name, "Sony - PlayStation 2", system_len))
{ {
if (detect_ps2_game(fd, serial, serial_len, filename) != 0) if (detect_ps2_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
} }
@ -233,13 +233,13 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_l
if (STRLEN_CONST("Nintendo - GameCube") == system_len && if (STRLEN_CONST("Nintendo - GameCube") == system_len &&
string_is_equal_fast(system_name, "Nintendo - GameCube", system_len)) string_is_equal_fast(system_name, "Nintendo - GameCube", system_len))
{ {
if (detect_gc_game(fd, serial, serial_len, filename) != 0) if (detect_gc_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
else if (STRLEN_CONST("Nintendo - Wii") == system_len && else if (STRLEN_CONST("Nintendo - Wii") == system_len &&
string_is_equal_fast(system_name, "Nintendo - Wii", system_len)) string_is_equal_fast(system_name, "Nintendo - Wii", system_len))
{ {
if (detect_wii_game(fd, serial, serial_len, filename) != 0) if (detect_wii_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
} }
@ -248,19 +248,19 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_l
if (STRLEN_CONST("Sega - Mega-CD - Sega CD") == system_len && if (STRLEN_CONST("Sega - Mega-CD - Sega CD") == system_len &&
string_is_equal_fast(system_name, "Sega - Mega-CD - Sega CD", system_len)) string_is_equal_fast(system_name, "Sega - Mega-CD - Sega CD", system_len))
{ {
if (detect_scd_game(fd, serial, serial_len, filename) != 0) if (detect_scd_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
else if (STRLEN_CONST("Sega - Saturn") == system_len && else if (STRLEN_CONST("Sega - Saturn") == system_len &&
string_is_equal_fast(system_name, "Sega - Saturn", system_len)) string_is_equal_fast(system_name, "Sega - Saturn", system_len))
{ {
if (detect_sat_game(fd, serial, serial_len, filename) != 0) if (detect_sat_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
else if (STRLEN_CONST("Sega - Dreamcast") == system_len && else if (STRLEN_CONST("Sega - Dreamcast") == system_len &&
string_is_equal_fast(system_name, "Sega - Dreamcast", system_len)) string_is_equal_fast(system_name, "Sega - Dreamcast", system_len))
{ {
if (detect_dc_game(fd, serial, serial_len, filename) != 0) if (detect_dc_game(fd, s, len, filename) != 0)
return 1; return 1;
} }
} }
@ -269,7 +269,7 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_l
} }
static bool intfstream_file_get_serial(const char *name, static bool intfstream_file_get_serial(const char *name,
uint64_t offset, size_t size, char *serial, size_t serial_len) uint64_t offset, size_t size, char *s, size_t len)
{ {
int rv; int rv;
uint8_t *data = NULL; uint8_t *data = NULL;
@ -315,7 +315,7 @@ static bool intfstream_file_get_serial(const char *name,
} }
} }
rv = intfstream_get_serial(fd, serial, serial_len, name); rv = intfstream_get_serial(fd, s, len, name);
intfstream_close(fd); intfstream_close(fd);
free(fd); free(fd);
free(data); free(data);
@ -327,7 +327,7 @@ error:
return 0; return 0;
} }
static int task_database_cue_get_serial(const char *name, char* serial, size_t serial_len) static int task_database_cue_get_serial(const char *name, char *s, size_t len)
{ {
char track_path[PATH_MAX_LENGTH]; char track_path[PATH_MAX_LENGTH];
uint64_t offset = 0; uint64_t offset = 0;
@ -335,8 +335,8 @@ static int task_database_cue_get_serial(const char *name, char* serial, size_t s
track_path[0] = '\0'; track_path[0] = '\0';
if (cue_find_track(name, true, &offset, &size, track_path, if (cue_find_track(name, true, &offset, &size,
sizeof(track_path)) < 0) track_path, sizeof(track_path)) < 0)
{ {
#ifdef DEBUG #ifdef DEBUG
RARCH_LOG("%s\n", RARCH_LOG("%s\n",
@ -345,10 +345,10 @@ static int task_database_cue_get_serial(const char *name, char* serial, size_t s
return 0; return 0;
} }
return intfstream_file_get_serial(track_path, offset, size, serial, serial_len); return intfstream_file_get_serial(track_path, offset, size, s, len);
} }
static int task_database_gdi_get_serial(const char *name, char* serial, size_t serial_len) static int task_database_gdi_get_serial(const char *name, char *s, size_t len)
{ {
char track_path[PATH_MAX_LENGTH]; char track_path[PATH_MAX_LENGTH];
@ -364,10 +364,10 @@ static int task_database_gdi_get_serial(const char *name, char* serial, size_t s
return 0; return 0;
} }
return intfstream_file_get_serial(track_path, 0, SIZE_MAX, serial, serial_len); return intfstream_file_get_serial(track_path, 0, SIZE_MAX, s, len);
} }
static int task_database_chd_get_serial(const char *name, char* serial, size_t serial_len) static int task_database_chd_get_serial(const char *name, char *serial, size_t len)
{ {
int result; int result;
intfstream_t *fd = intfstream_open_chd_track( intfstream_t *fd = intfstream_open_chd_track(
@ -378,7 +378,7 @@ static int task_database_chd_get_serial(const char *name, char* serial, size_t s
if (!fd) if (!fd)
return 0; return 0;
result = intfstream_get_serial(fd, serial, serial_len, name); result = intfstream_get_serial(fd, serial, len, name);
intfstream_close(fd); intfstream_close(fd);
free(fd); free(fd);
return result; return result;

View File

@ -1110,7 +1110,7 @@ static bool update_cand(int64_t *cand_index, int64_t *last_index,
} }
int cue_find_track(const char *cue_path, bool first, int cue_find_track(const char *cue_path, bool first,
uint64_t *offset, size_t *size, char *track_path, uint64_t max_len) uint64_t *offset, size_t *size, char *s, size_t len)
{ {
int rv; int rv;
intfstream_info_t info; intfstream_info_t info;
@ -1162,7 +1162,7 @@ int cue_find_track(const char *cue_path, bool first,
/* We're changing files since the candidate, update it */ /* We're changing files since the candidate, update it */
if (update_cand(&cand_index, &last_index, if (update_cand(&cand_index, &last_index,
&largest, last_file, offset, &largest, last_file, offset,
size, track_path, (size_t)max_len)) size, s, len))
{ {
rv = 0; rv = 0;
if (first) if (first)
@ -1187,11 +1187,11 @@ int cue_find_track(const char *cue_path, bool first,
} }
else if (string_is_equal_noncase(tmp_token, "INDEX")) else if (string_is_equal_noncase(tmp_token, "INDEX"))
{ {
int m, s, f; int _m, _s, _f;
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3) if (sscanf(tmp_token, "%02d:%02d:%02d", &_m, &_s, &_f) < 3)
{ {
#ifdef DEBUG #ifdef DEBUG
RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token); RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token);
@ -1199,14 +1199,14 @@ int cue_find_track(const char *cue_path, bool first,
goto error; goto error;
} }
last_index = (size_t) (((m * 60 + s) * 75) + f) * 2352; last_index = (size_t)(((_m * 60 + _s) * 75) + _f) * 2352;
/* If we've changed tracks since the candidate, update it */ /* If we've changed tracks since the candidate, update it */
if ( (cand_track != -1) if ( (cand_track != -1)
&& (track != cand_track) && (track != cand_track)
&& update_cand(&cand_index, &last_index, &largest, && update_cand(&cand_index, &last_index, &largest,
last_file, offset, last_file, offset,
size, track_path, (size_t)max_len)) size, s, len))
{ {
rv = 0; rv = 0;
if (first) if (first)
@ -1229,7 +1229,7 @@ int cue_find_track(const char *cue_path, bool first,
if (update_cand(&cand_index, &last_index, if (update_cand(&cand_index, &last_index,
&largest, last_file, offset, &largest, last_file, offset,
size, track_path, (size_t)max_len)) size, s, len))
rv = 0; rv = 0;
clean: clean:
@ -1268,8 +1268,7 @@ bool cue_next_file(intfstream_t *fd,
return false; return false;
} }
int gdi_find_track(const char *gdi_path, bool first, int gdi_find_track(const char *gdi_path, bool first, char *s, uint64_t len)
char *track_path, uint64_t max_len)
{ {
intfstream_info_t info; intfstream_info_t info;
char tmp_token[MAX_TOKEN_LEN]; char tmp_token[MAX_TOKEN_LEN];
@ -1341,7 +1340,7 @@ int gdi_find_track(const char *gdi_path, bool first,
if ((uint64_t)file_size > largest) if ((uint64_t)file_size > largest)
{ {
strlcpy(track_path, last_file, (size_t)max_len); strlcpy(s, last_file, len);
rv = 0; rv = 0;
largest = file_size; largest = file_size;
@ -1370,8 +1369,8 @@ error:
return -1; return -1;
} }
bool gdi_next_file(intfstream_t *fd, const char *gdi_path, size_t gdi_next_file(intfstream_t *fd, const char *gdi_path,
char *path, uint64_t max_len) char *s, size_t len)
{ {
char tmp_token[MAX_TOKEN_LEN]; char tmp_token[MAX_TOKEN_LEN];
@ -1389,15 +1388,15 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
/* File name */ /* File name */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0) if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
{ {
size_t _len;
char gdi_dir[DIR_MAX_LENGTH]; char gdi_dir[DIR_MAX_LENGTH];
fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir)); fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir));
fill_pathname_join_special(path, gdi_dir, tmp_token, (size_t)max_len); _len = fill_pathname_join_special(s, gdi_dir, tmp_token, len);
/* Disc offset */ /* Disc offset */
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
return true; return _len;
} }
return false; return 0;
} }

View File

@ -45,13 +45,13 @@ size_t detect_wii_game(intfstream_t *fd, char *s, size_t len,
int detect_system(intfstream_t *fd, const char **system_name, int detect_system(intfstream_t *fd, const char **system_name,
const char * filename); const char * filename);
int cue_find_track(const char *cue_path, bool first, uint64_t *offset, int cue_find_track(const char *cue_path, bool first, uint64_t *offset,
size_t *size, char *track_path, uint64_t max_len); size_t *size, char *s, size_t len);
bool cue_next_file(intfstream_t *fd, const char *cue_path, bool cue_next_file(intfstream_t *fd, const char *cue_path,
char *s, uint64_t len); char *s, uint64_t len);
int gdi_find_track(const char *gdi_path, bool first, char *track_path, int gdi_find_track(const char *gdi_path, bool first, char *s,
uint64_t max_len); size_t len);
bool gdi_next_file(intfstream_t *fd, const char *gdi_path, char *path, size_t gdi_next_file(intfstream_t *fd, const char *gdi_path, char *s,
uint64_t max_len); size_t len);
RETRO_END_DECLS RETRO_END_DECLS