forked from len0rd/rockbox
tree.c remove strlcat in favor of strmemccpy
moved a conditional for reload_dir vs strcmp Change-Id: I1635014fbbc6b9b0905abc3f9c60bbd2a1d08762
This commit is contained in:
parent
9ebfb3fa5c
commit
e6313e4b8e
1 changed files with 16 additions and 7 deletions
23
apps/tree.c
23
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue