summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-27 10:33:09 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-27 10:33:09 +0000
commit79798ff5f30dea7419f360e197763abb3b46259a (patch)
treefc06addfd06c88337ccaca1ee79bda6809cf9cfd /apps/tree.c
parent194174a371b16dfc24960d1e33371c0a7ef1c2c2 (diff)
downloadrockbox-79798ff5f30dea7419f360e197763abb3b46259a.tar.gz
rockbox-79798ff5f30dea7419f360e197763abb3b46259a.zip
Make getcwd match the posix variant, make get_current_file() behave similar to it and add a few sanity checks.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27903 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 5e841e4dae..4d915ca3b8 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -511,17 +511,17 @@ void resume_directory(const char *dir)
511 511
512/* Returns the current working directory and also writes cwd to buf if 512/* Returns the current working directory and also writes cwd to buf if
513 non-NULL. In case of error, returns NULL. */ 513 non-NULL. In case of error, returns NULL. */
514char *getcwd(char *buf, int size) 514char *getcwd(char *buf, size_t size)
515{ 515{
516 if (!buf) 516 if (!buf)
517 return tc.currdir; 517 return tc.currdir;
518 else if (size > 0) 518 else if (size)
519 { 519 {
520 strlcpy(buf, tc.currdir, size); 520 if (strlcpy(buf, tc.currdir, size) < size)
521 return buf; 521 return buf;
522 } 522 }
523 else 523 /* size == 0, or truncation in strlcpy */
524 return NULL; 524 return NULL;
525} 525}
526 526
527/* Force a reload of the directory next time directory browser is called */ 527/* Force a reload of the directory next time directory browser is called */
@@ -530,19 +530,28 @@ void reload_directory(void)
530 reload_dir = true; 530 reload_dir = true;
531} 531}
532 532
533void get_current_file(char* buffer, int buffer_len) 533char* get_current_file(char* buffer, size_t buffer_len)
534{ 534{
535#ifdef HAVE_TAGCACHE 535#ifdef HAVE_TAGCACHE
536 /* in ID3DB mode it is a bad idea to call this function */ 536 /* in ID3DB mode it is a bad idea to call this function */
537 /* (only happens with `follow playlist') */ 537 /* (only happens with `follow playlist') */
538 if( *tc.dirfilter == SHOW_ID3DB ) 538 if( *tc.dirfilter == SHOW_ID3DB )
539 return; 539 return NULL;
540#endif 540#endif
541 541
542 struct entry* dc = tc.dircache; 542 struct entry* dc = tc.dircache;
543 struct entry* e = &dc[tc.selected_item]; 543 struct entry* e = &dc[tc.selected_item];
544 snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0), 544 if (getcwd(buffer, buffer_len))
545 tc.dirlength ? e->name : ""); 545 {
546 if (tc.dirlength)
547 {
548 strlcat(buffer, "/", buffer_len);
549 if (strlcat(buffer, e->name, buffer_len) >= buffer_len)
550 return NULL;
551 }
552 return buffer;
553 }
554 return NULL;
546} 555}
547 556
548/* Allow apps to change our dirfilter directly (required for sub browsers) 557/* Allow apps to change our dirfilter directly (required for sub browsers)