diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-09-25 03:58:30 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-09-26 00:38:54 -0400 |
commit | e6313e4b8ebd6314fe45c52c35ee8a12e409219b (patch) | |
tree | adf071a36e27359020610e279d355d14fecf5453 | |
parent | 9ebfb3fa5c2e5cfb3ea09843fe2f95ac54e81bfe (diff) | |
download | rockbox-e6313e4b8e.tar.gz rockbox-e6313e4b8e.zip |
tree.c remove strlcat in favor of strmemccpy
moved a conditional for reload_dir vs strcmp
Change-Id: I1635014fbbc6b9b0905abc3f9c60bbd2a1d08762
-rw-r--r-- | apps/tree.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/apps/tree.c b/apps/tree.c index 721fb8c1ef..ac82b6c2df 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -421,7 +421,7 @@ static int update_dir(void) { tc.sort_dir = global_settings.sort_dir; /* if the tc.currdir has been changed, reload it ...*/ - if (strncmp(tc.currdir, lastdir, sizeof(lastdir)) || reload_dir) + if (reload_dir || strncmp(tc.currdir, lastdir, sizeof(lastdir))) { if (ft_load(&tc, NULL) < 0) return -1; @@ -584,14 +584,23 @@ char* get_current_file(char* buffer, size_t buffer_len) struct entry *entry = tree_get_entry_at(&tc, tc.selected_item); if (entry && getcwd(buffer, buffer_len)) { - if (tc.dirlength) + if (!tc.dirlength) + return buffer; + + size_t usedlen = strlen(buffer); + + if (usedlen + 2 < buffer_len) /* ensure enough room for '/' + '\0' */ { - if (buffer[strlen(buffer)-1] != '/') - strlcat(buffer, "/", buffer_len); - if (strlcat(buffer, entry->name, buffer_len) >= buffer_len) - return NULL; + if (buffer[usedlen-1] != '/') + { + buffer[usedlen] = '/'; + /* strmemccpy will zero terminate if we run out of space after */ + usedlen++; + } + buffer_len -= usedlen; + if (strmemccpy(buffer + usedlen, entry->name, buffer_len) != NULL) + return buffer; } - return buffer; } return NULL; } |