Skip to content

Commit a5c9d95

Browse files
committed
* Use fill_pathname_basedir where possible
* Move static variable to only function where it's used * Change signature of file_path.c function
1 parent e0f09f6 commit a5c9d95

10 files changed

+65
-69
lines changed

disk_index_file.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,9 @@ bool disk_index_file_init(
226226
/* > Get disk index file directory */
227227
if (!string_is_empty(dir_savefile))
228228
strlcpy(disk_index_file_dir, dir_savefile, sizeof(disk_index_file_dir));
229-
else
230-
{
231-
/* Use content directory */
232-
strlcpy(disk_index_file_dir, content_path, sizeof(disk_index_file_dir));
233-
path_basedir(disk_index_file_dir);
234-
}
229+
else /* Use content directory */
230+
fill_pathname_basedir(disk_index_file_dir, content_path,
231+
sizeof(disk_index_file_dir));
235232

236233
/* > Create directory, if required */
237234
if ( !path_is_directory(disk_index_file_dir)

gfx/video_shader_parse.c

+17-18
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,6 @@ struct wildcard_token
8686
char token_name[24];
8787
};
8888

89-
static struct wildcard_token wildcard_tokens[SHADER_NUM_WILDCARDS] = {
90-
{RARCH_WILDCARD_CONTENT_DIR, "$CONTENT-DIR$"},
91-
{RARCH_WILDCARD_CORE, "$CORE$"},
92-
{RARCH_WILDCARD_GAME, "$GAME$"},
93-
{RARCH_WILDCARD_VIDEO_DRIVER, "$VID-DRV$"},
94-
{RARCH_WILDCARD_VIDEO_DRIVER_PRESET_EXT, "$VID-DRV-PRESET-EXT$"},
95-
{RARCH_WILDCARD_VIDEO_DRIVER_SHADER_EXT, "$VID-DRV-SHADER-EXT$"},
96-
{RARCH_WILDCARD_CORE_REQUESTED_ROTATION, "$CORE-REQ-ROT$"},
97-
{RARCH_WILDCARD_VIDEO_ALLOW_CORE_ROTATION, "$VID-ALLOW-CORE-ROT$"},
98-
{RARCH_WILDCARD_VIDEO_USER_ROTATION, "$VID-USER-ROT$"},
99-
{RARCH_WILDCARD_VIDEO_FINAL_ROTATION, "$VID-FINAL-ROT$"},
100-
{RARCH_WILDCARD_SCREEN_ORIENTATION, "$SCREEN-ORIENT$"},
101-
{RARCH_WILDCARD_VIEWPORT_ASPECT_ORIENTATION, "$VIEW-ASPECT-ORIENT$"},
102-
{RARCH_WILDCARD_CORE_ASPECT_ORIENTATION, "$CORE-ASPECT-ORIENT$"},
103-
{RARCH_WILDCARD_PRESET_DIR, "$PRESET-DIR$"},
104-
{RARCH_WILDCARD_PRESET, "$PRESET$"},
105-
};
106-
10789
/* TODO/FIXME - global state - perhaps move outside this file */
10890
static path_change_data_t *file_change_data = NULL;
10991

@@ -231,6 +213,23 @@ static void video_shader_replace_wildcards(char *s, size_t len, char *in_preset_
231213
{
232214
int i = 0;
233215
char replaced_path[PATH_MAX_LENGTH];
216+
static struct wildcard_token wildcard_tokens[SHADER_NUM_WILDCARDS] = {
217+
{RARCH_WILDCARD_CONTENT_DIR, "$CONTENT-DIR$"},
218+
{RARCH_WILDCARD_CORE, "$CORE$"},
219+
{RARCH_WILDCARD_GAME, "$GAME$"},
220+
{RARCH_WILDCARD_VIDEO_DRIVER, "$VID-DRV$"},
221+
{RARCH_WILDCARD_VIDEO_DRIVER_PRESET_EXT, "$VID-DRV-PRESET-EXT$"},
222+
{RARCH_WILDCARD_VIDEO_DRIVER_SHADER_EXT, "$VID-DRV-SHADER-EXT$"},
223+
{RARCH_WILDCARD_CORE_REQUESTED_ROTATION, "$CORE-REQ-ROT$"},
224+
{RARCH_WILDCARD_VIDEO_ALLOW_CORE_ROTATION, "$VID-ALLOW-CORE-ROT$"},
225+
{RARCH_WILDCARD_VIDEO_USER_ROTATION, "$VID-USER-ROT$"},
226+
{RARCH_WILDCARD_VIDEO_FINAL_ROTATION, "$VID-FINAL-ROT$"},
227+
{RARCH_WILDCARD_SCREEN_ORIENTATION, "$SCREEN-ORIENT$"},
228+
{RARCH_WILDCARD_VIEWPORT_ASPECT_ORIENTATION, "$VIEW-ASPECT-ORIENT$"},
229+
{RARCH_WILDCARD_CORE_ASPECT_ORIENTATION, "$CORE-ASPECT-ORIENT$"},
230+
{RARCH_WILDCARD_PRESET_DIR, "$PRESET-DIR$"},
231+
{RARCH_WILDCARD_PRESET, "$PRESET$"},
232+
};
234233

235234
if (!strstr(s, RARCH_WILDCARD_DELIMITER))
236235
return;

libretro-common/file/file_path.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -597,21 +597,18 @@ size_t path_basedir(char *s)
597597
char *last_slash = NULL;
598598
if (!s || s[0] == '\0' || s[1] == '\0')
599599
return (s && s[0] != '\0') ? 1 : 0;
600-
slash = strrchr(s, '/');
601-
backslash = strrchr(s, '\\');
602-
last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
600+
slash = strrchr(s, '/');
601+
backslash = strrchr(s, '\\');
602+
last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
603603
if (last_slash)
604604
{
605-
last_slash[1] = '\0';
605+
last_slash[1] = '\0';
606606
return last_slash + 1 - s;
607607
}
608-
else
609-
{
610-
s[0] = '.';
611-
s[1] = PATH_DEFAULT_SLASH_C();
612-
s[2] = '\0';
613-
return 2;
614-
}
608+
s[0] = '.';
609+
s[1] = PATH_DEFAULT_SLASH_C();
610+
s[2] = '\0';
611+
return 2;
615612
}
616613

617614
/**
@@ -1446,13 +1443,13 @@ size_t fill_pathname_application_path(char *s, size_t len)
14461443
return 0;
14471444
}
14481445

1449-
void fill_pathname_application_dir(char *s, size_t len)
1446+
size_t fill_pathname_application_dir(char *s, size_t len)
14501447
{
14511448
#ifdef __WINRT__
1452-
strlcpy(s, uwp_dir_install, len);
1449+
return strlcpy(s, uwp_dir_install, len);
14531450
#else
14541451
fill_pathname_application_path(s, len);
1455-
path_basedir(s);
1452+
return path_basedir(s);
14561453
#endif
14571454
}
14581455

libretro-common/include/file/file_path.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ size_t fill_pathname_slash(char *path, size_t size);
636636

637637
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
638638
size_t fill_pathname_application_path(char *buf, size_t size);
639-
void fill_pathname_application_dir(char *buf, size_t size);
639+
size_t fill_pathname_application_dir(char *buf, size_t size);
640640
size_t fill_pathname_home_dir(char *buf, size_t size);
641641
#endif
642642

menu/cbs/menu_cbs_ok.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1377,10 +1377,12 @@ int generic_action_ok_displaylist_push(
13771377
{
13781378
filebrowser_clear_type();
13791379
if (content_get_subsystem_rom_id() > 0)
1380-
strlcpy(tmp, content_get_subsystem_rom(content_get_subsystem_rom_id() - 1), sizeof(tmp));
1380+
fill_pathname_basedir(tmp,
1381+
content_get_subsystem_rom(content_get_subsystem_rom_id() - 1),
1382+
sizeof(tmp));
13811383
else
1382-
strlcpy(tmp, path_get(RARCH_PATH_CONTENT), sizeof(tmp));
1383-
path_basedir(tmp);
1384+
fill_pathname_basedir(tmp,
1385+
path_get(RARCH_PATH_CONTENT), sizeof(tmp));
13841386

13851387
if (content_get_subsystem() != (int)type - MENU_SETTINGS_SUBSYSTEM_ADD)
13861388
content_clear_subsystem();

menu/menu_displaylist.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ static int filebrowser_parse(
500500
if (str_list->size <= 0)
501501
{
502502
char dir[DIR_MAX_LENGTH];
503-
fill_pathname_application_dir(dir, sizeof(dir));
503+
size_t _len = fill_pathname_application_dir(dir, sizeof(dir));
504504
if (string_ends_with(full_path, "/") && !string_ends_with(dir, "/"))
505-
strlcat(dir, "/", sizeof(dir));
505+
strlcpy(dir + _len, "/", sizeof(dir) - _len);
506506
if (string_is_equal(dir, full_path))
507507
allow_parent_directory = false;
508508
else
@@ -5139,13 +5139,21 @@ static unsigned menu_displaylist_parse_content_information(
51395139
if ( !string_is_empty(content_label)
51405140
&& !string_is_empty(db_name))
51415141
{
5142+
char *last;
51425143
char db_path[PATH_MAX_LENGTH];
51435144
fill_pathname_join_special(db_path,
51445145
settings->paths.path_content_database,
51455146
db_name,
51465147
sizeof(db_path));
5147-
path_remove_extension(db_path);
5148-
strlcat(db_path, ".rdb", sizeof(db_path));
5148+
last = (char*)strrchr(path_basename(db_path), '.');
5149+
if (*last)
5150+
{
5151+
last[0] = '.';
5152+
last[1] = 'r';
5153+
last[2] = 'd';
5154+
last[3] = 'b';
5155+
last[4] = '\0';
5156+
}
51495157

51505158
if (path_is_valid(db_path))
51515159
if (menu_entries_append(info_list,

menu/menu_driver.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -2985,16 +2985,12 @@ static bool menu_shader_manager_save_preset_internal(
29852985
fill_pathname_join(buffer, target_dirs[i],
29862986
fullname, sizeof(buffer));
29872987

2988-
strlcpy(basedir, buffer, sizeof(basedir));
2989-
path_basedir(basedir);
2988+
fill_pathname_basedir(basedir, buffer, sizeof(basedir));
29902989

2991-
if (!path_is_directory(basedir))
2990+
if (!path_is_directory(basedir) && !(ret = path_mkdir(basedir)))
29922991
{
2993-
if (!(ret = path_mkdir(basedir)))
2994-
{
2995-
RARCH_WARN("[Shaders]: Failed to create preset directory \"%s\".\n", basedir);
2996-
continue;
2997-
}
2992+
RARCH_WARN("[Shaders]: Failed to create preset directory \"%s\".\n", basedir);
2993+
continue;
29982994
}
29992995

30002996
preset_path = buffer;

runloop.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -7928,10 +7928,10 @@ void runloop_path_set_redirect(settings_t *settings,
79287928
if ( string_is_empty(intermediate_savefile_dir)
79297929
|| savefiles_in_content_dir)
79307930
{
7931-
strlcpy(intermediate_savefile_dir,
7932-
runloop_st->runtime_content_path_basename,
7933-
sizeof(intermediate_savefile_dir));
7934-
path_basedir(intermediate_savefile_dir);
7931+
fill_pathname_basedir(
7932+
intermediate_savefile_dir,
7933+
runloop_st->runtime_content_path_basename,
7934+
sizeof(intermediate_savefile_dir));
79357935

79367936
if (string_is_empty(intermediate_savefile_dir))
79377937
RARCH_LOG("Cannot resolve save file path.\n");
@@ -7941,10 +7941,9 @@ void runloop_path_set_redirect(settings_t *settings,
79417941
if ( string_is_empty(intermediate_savestate_dir)
79427942
|| savestates_in_content_dir)
79437943
{
7944-
strlcpy(intermediate_savestate_dir,
7945-
runloop_st->runtime_content_path_basename,
7946-
sizeof(intermediate_savestate_dir));
7947-
path_basedir(intermediate_savestate_dir);
7944+
fill_pathname_basedir(intermediate_savestate_dir,
7945+
runloop_st->runtime_content_path_basename,
7946+
sizeof(intermediate_savestate_dir));
79487947

79497948
if (string_is_empty(intermediate_savestate_dir))
79507949
RARCH_LOG("Cannot resolve save state file path.\n");

tasks/task_content.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ static bool content_file_list_set_info(
556556
{
557557
char archive_path[PATH_MAX_LENGTH];
558558
size_t _len = 0;
559+
560+
file_info->file_in_archive = true;
561+
559562
/* Extract path of parent archive */
560563
if ((_len = (size_t)(1 + archive_delim - path))
561564
>= PATH_MAX_LENGTH)
@@ -582,9 +585,6 @@ static bool content_file_list_set_info(
582585
* this is the basename of the archive file without
583586
* extension */
584587
fill_pathname_base(name, archive_path, sizeof(name));
585-
path_remove_extension(name);
586-
587-
file_info->file_in_archive = true;
588588
}
589589
else
590590
{
@@ -596,8 +596,8 @@ static bool content_file_list_set_info(
596596
* is the basename of the content file, without
597597
* extension */
598598
fill_pathname_base(name, path, sizeof(name));
599-
path_remove_extension(name);
600599
}
600+
path_remove_extension(name);
601601

602602
if (!string_is_empty(dir))
603603
{

tasks/task_translation.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ static const char *ai_service_get_str(enum translation_lang id)
780780
bool run_translation_service(settings_t *settings, bool paused)
781781
{
782782
struct video_viewport vp;
783-
uint8_t header[54];
784783
size_t pitch;
785784
unsigned width, height;
786785
const void *data = NULL;
@@ -947,11 +946,10 @@ bool run_translation_service(settings_t *settings, bool paused)
947946
the BMP header as bytes, and then covert that to a
948947
b64 encoded array for transport in JSON.
949948
*/
950-
form_bmp_header(header, width, height, false);
951949
if (!(bmp_buffer = (uint8_t*)malloc(width * height * 3 + 54)))
952950
goto finish;
953951

954-
memcpy(bmp_buffer, header, 54 * sizeof(uint8_t));
952+
form_bmp_header(bmp_buffer, width, height, false);
955953
memcpy(bmp_buffer + 54,
956954
bit24_image,
957955
width * height * 3 * sizeof(uint8_t));

0 commit comments

Comments
 (0)