diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-03-31 22:08:55 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2024-04-01 07:35:53 -0400 |
commit | 1dc22c7241e7a4560bc2ba5e920721df27c39778 (patch) | |
tree | 92005f1c98456b2db0cf78d30df9f0f648f75faf | |
parent | 47784a777eca6cae3c4a6643f4bca5338373951f (diff) | |
download | rockbox-1dc22c7241.tar.gz rockbox-1dc22c7241.zip |
use path_append for setting directories is several settings
sprintf, strcpy, memccpy can all just go thru path_append
with the added benefit of some path sanitizing too
Change-Id: I33510b56a364b8b3a0b06f2ff14b76491f6e3870
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 2 | ||||
-rw-r--r-- | apps/menus/recording_menu.c | 4 | ||||
-rw-r--r-- | apps/menus/settings_menu.c | 3 | ||||
-rw-r--r-- | apps/onplay.c | 14 | ||||
-rw-r--r-- | apps/playlist_catalog.c | 13 | ||||
-rw-r--r-- | firmware/target/hosted/filesystem-app.c | 4 | ||||
-rw-r--r-- | firmware/target/hosted/rolo.c | 5 |
7 files changed, 23 insertions, 22 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 4d1526fcbc..9f6f61895a 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -305,7 +305,7 @@ static int get_image_id(int c) void get_image_filename(const char *start, const char* bmpdir, char *buf, int buf_size) { - snprintf(buf, buf_size, "%s/%s", bmpdir, start); + path_append(buf, bmpdir, start, buf_size); } static int parse_image_display(struct skin_element *element, diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index d47a315d87..9ef0eb6bac 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -63,6 +63,7 @@ #include "list.h" #include "viewport.h" #include "exported_menus.h" +#include "pathfuncs.h" static bool no_source_in_menu = false; static int recmenu_callback(int action, @@ -305,7 +306,8 @@ MENUITEM_SETTING(rec_prerecord_time, &global_settings.rec_prerecord_time, NULL); static int clear_rec_directory(void) { - strcpy(global_settings.rec_directory, REC_BASE_DIR); + path_append(global_settings.rec_directory, REC_BASE_DIR, + PA_SEP_HARD, sizeof(global_settings.rec_directory)); settings_save(); splash(HZ, ID2P(LANG_RESET_DONE_CLEAR)); return false; diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index bfb69a9942..a71245cf80 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -193,7 +193,8 @@ MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL); MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL); static int clear_start_directory(void) { - strcpy(global_settings.start_directory, "/"); + path_append(global_settings.start_directory, PATH_ROOTSTR, + PA_SEP_HARD, sizeof(global_settings.start_directory)); settings_save(); splash(HZ, ID2P(LANG_RESET_DONE_CLEAR)); return false; diff --git a/apps/onplay.c b/apps/onplay.c index ba06d13183..ccebee402e 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -1349,8 +1349,8 @@ MENUITEM_FUNCTION(add_to_faves_item, 0, ID2P(LANG_ADD_TO_FAVES), #if LCD_DEPTH > 1 static bool set_backdrop(void) { - strmemccpy(global_settings.backdrop_file, selected_file, - sizeof(global_settings.backdrop_file)); + path_append(global_settings.backdrop_file, selected_file, + PA_SEP_HARD, sizeof(global_settings.backdrop_file)); settings_save(); skin_backdrop_load_setting(); skin_backdrop_show(sb_get_backdrop(SCREEN_MAIN)); @@ -1362,8 +1362,8 @@ MENUITEM_FUNCTION(set_backdrop_item, 0, ID2P(LANG_SET_AS_BACKDROP), #ifdef HAVE_RECORDING static bool set_recdir(void) { - strmemccpy(global_settings.rec_directory, selected_file, - sizeof(global_settings.rec_directory)); + path_append(global_settings.rec_directory, selected_file, + PA_SEP_HARD, sizeof(global_settings.rec_directory)); settings_save(); return false; } @@ -1372,9 +1372,9 @@ MENUITEM_FUNCTION(set_recdir_item, 0, ID2P(LANG_RECORDING_DIR), #endif static bool set_startdir(void) { - snprintf(global_settings.start_directory, - sizeof(global_settings.start_directory), - "%s/", selected_file); + path_append(global_settings.start_directory, selected_file, + PA_SEP_HARD, sizeof(global_settings.start_directory)); + settings_save(); return false; } diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index bcca406494..69bcc54209 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -78,10 +78,7 @@ static size_t get_directory(char* dirbuf, size_t dirbuf_sz) pl_dir = global_settings.playlist_catalog_dir; } - /* remove duplicate leading '/' */ - path_strip_leading_separators(pl_dir, &pl_dir); - - return strlcpy(dirbuf, pl_dir, dirbuf_sz); + return path_append(dirbuf, pl_dir, PA_SEP_SOFT, dirbuf_sz); } /* Retrieve playlist directory from config file and verify it exists @@ -127,8 +124,8 @@ void catalog_set_directory(const char* directory) } else { - strmemccpy(global_settings.playlist_catalog_dir, - directory, sizeof(global_settings.playlist_catalog_dir)); + path_append(global_settings.playlist_catalog_dir, directory, + PA_SEP_SOFT, sizeof(global_settings.playlist_catalog_dir)); } initialize_catalog(); } @@ -204,8 +201,8 @@ restart: { if (strcmp(most_recent_playlist, selected_playlist)) /* isn't most recent one */ { - strmemccpy(most_recent_playlist, selected_playlist, - sizeof(most_recent_playlist)); + path_append(most_recent_playlist, selected_playlist, + PA_SEP_SOFT, sizeof(most_recent_playlist)); most_recent_selection = 0; reopen_last_playlist = false; } diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c index 09b3365a9e..b36f04a0fe 100644 --- a/firmware/target/hosted/filesystem-app.c +++ b/firmware/target/hosted/filesystem-app.c @@ -211,7 +211,7 @@ const char * handle_special_dirs(const char *dir, unsigned flags, { const char *p = dir + HOME_DIR_LEN; while (*p == '/') p++; - snprintf(buf, bufsize, "%s/%s", rbhome, p); + path_append(buf, rbhome, p, bufsize); dir = buf; } else if (!strncmp(ROCKBOX_DIR, dir, ROCKBOX_DIR_LEN)) @@ -232,7 +232,7 @@ const char * handle_special_dirs(const char *dir, unsigned flags, #endif ) { - snprintf(buf, bufsize, "%s/%s", PIVOT_ROOT, dir); + path_append(buf, PIVOT_ROOT, dir, bufsize); dir = buf; } #endif diff --git a/firmware/target/hosted/rolo.c b/firmware/target/hosted/rolo.c index dfe483c964..87b7340198 100644 --- a/firmware/target/hosted/rolo.c +++ b/firmware/target/hosted/rolo.c @@ -33,6 +33,7 @@ #include "storage.h" #include "rolo.h" #include "rbpaths.h" +#include "pathfuncs.h" //#define LOGF_ENABLE #include "logf.h" @@ -94,9 +95,9 @@ int rolo_load(const char* filename) logf("system: %s", buf); system(buf); - snprintf(buf, sizeof(buf), "%s/%s", EXECDIR, BOOTFILE); + path_append(buf, EXECDIR, BOOTFILE, sizeof(buf)); #else - snprintf(buf, sizeof(buf), "%s/%s", EXECDIR, filename); + path_append(buf, EXECDIR, filename, sizeof(buf)); #endif logf("execl: %s", buf); |