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
This commit is contained in:
William Wilgus 2024-03-31 22:08:55 -04:00
parent 47784a777e
commit 1dc22c7241
7 changed files with 23 additions and 22 deletions

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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);