summaryrefslogtreecommitdiff
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
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
-rw-r--r--apps/root_menu.c6
-rw-r--r--apps/tree.c29
-rw-r--r--apps/tree.h4
3 files changed, 26 insertions, 13 deletions
diff --git a/apps/root_menu.c b/apps/root_menu.c
index 7965673b67..7f882cdba3 100644
--- a/apps/root_menu.c
+++ b/apps/root_menu.c
@@ -252,7 +252,11 @@ static int browser(void* param)
252 switch ((intptr_t)param) 252 switch ((intptr_t)param)
253 { 253 {
254 case GO_TO_FILEBROWSER: 254 case GO_TO_FILEBROWSER:
255 get_current_file(last_folder, MAX_PATH); 255 if (!get_current_file(last_folder, MAX_PATH))
256 {
257 last_folder[0] = '/';
258 last_folder[1] = '\0';
259 }
256 break; 260 break;
257#ifdef HAVE_TAGCACHE 261#ifdef HAVE_TAGCACHE
258 case GO_TO_DBBROWSER: 262 case GO_TO_DBBROWSER:
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)
diff --git a/apps/tree.h b/apps/tree.h
index f3057e81e4..e33fee00d7 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -73,13 +73,13 @@ struct tree_context {
73void tree_drawlists(void); 73void tree_drawlists(void);
74void tree_mem_init(void) INIT_ATTR; 74void tree_mem_init(void) INIT_ATTR;
75void tree_gui_init(void) INIT_ATTR; 75void tree_gui_init(void) INIT_ATTR;
76void get_current_file(char* buffer, int buffer_len); 76char* get_current_file(char* buffer, size_t buffer_len);
77void set_dirfilter(int l_dirfilter); 77void set_dirfilter(int l_dirfilter);
78void set_current_file(char *path); 78void set_current_file(char *path);
79int rockbox_browse(const char *root, int dirfilter); 79int rockbox_browse(const char *root, int dirfilter);
80bool create_playlist(void); 80bool create_playlist(void);
81void resume_directory(const char *dir); 81void resume_directory(const char *dir);
82char *getcwd(char *buf, int size); 82char *getcwd(char *buf, size_t size);
83void reload_directory(void); 83void reload_directory(void);
84bool check_rockboxdir(void); 84bool check_rockboxdir(void);
85struct tree_context* tree_get_context(void); 85struct tree_context* tree_get_context(void);