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.zip
rockbox-79798ff5f30dea7419f360e197763abb3b46259a.tar.gz
rockbox-79798ff5f30dea7419f360e197763abb3b46259a.tar.bz2
rockbox-79798ff5f30dea7419f360e197763abb3b46259a.tar.xz
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 7965673..7f882cd 100644
--- a/apps/root_menu.c
+++ b/apps/root_menu.c
@@ -252,7 +252,11 @@ static int browser(void* param)
switch ((intptr_t)param)
{
case GO_TO_FILEBROWSER:
- get_current_file(last_folder, MAX_PATH);
+ if (!get_current_file(last_folder, MAX_PATH))
+ {
+ last_folder[0] = '/';
+ last_folder[1] = '\0';
+ }
break;
#ifdef HAVE_TAGCACHE
case GO_TO_DBBROWSER:
diff --git a/apps/tree.c b/apps/tree.c
index 5e841e4..4d915ca 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -511,17 +511,17 @@ void resume_directory(const char *dir)
/* Returns the current working directory and also writes cwd to buf if
non-NULL. In case of error, returns NULL. */
-char *getcwd(char *buf, int size)
+char *getcwd(char *buf, size_t size)
{
if (!buf)
return tc.currdir;
- else if (size > 0)
+ else if (size)
{
- strlcpy(buf, tc.currdir, size);
- return buf;
+ if (strlcpy(buf, tc.currdir, size) < size)
+ return buf;
}
- else
- return NULL;
+ /* size == 0, or truncation in strlcpy */
+ return NULL;
}
/* Force a reload of the directory next time directory browser is called */
@@ -530,19 +530,28 @@ void reload_directory(void)
reload_dir = true;
}
-void get_current_file(char* buffer, int buffer_len)
+char* get_current_file(char* buffer, size_t buffer_len)
{
#ifdef HAVE_TAGCACHE
/* in ID3DB mode it is a bad idea to call this function */
/* (only happens with `follow playlist') */
if( *tc.dirfilter == SHOW_ID3DB )
- return;
+ return NULL;
#endif
struct entry* dc = tc.dircache;
struct entry* e = &dc[tc.selected_item];
- snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0),
- tc.dirlength ? e->name : "");
+ if (getcwd(buffer, buffer_len))
+ {
+ if (tc.dirlength)
+ {
+ strlcat(buffer, "/", buffer_len);
+ if (strlcat(buffer, e->name, buffer_len) >= buffer_len)
+ return NULL;
+ }
+ return buffer;
+ }
+ return NULL;
}
/* Allow apps to change our dirfilter directly (required for sub browsers)
diff --git a/apps/tree.h b/apps/tree.h
index f3057e8..e33fee0 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -73,13 +73,13 @@ struct tree_context {
void tree_drawlists(void);
void tree_mem_init(void) INIT_ATTR;
void tree_gui_init(void) INIT_ATTR;
-void get_current_file(char* buffer, int buffer_len);
+char* get_current_file(char* buffer, size_t buffer_len);
void set_dirfilter(int l_dirfilter);
void set_current_file(char *path);
int rockbox_browse(const char *root, int dirfilter);
bool create_playlist(void);
void resume_directory(const char *dir);
-char *getcwd(char *buf, int size);
+char *getcwd(char *buf, size_t size);
void reload_directory(void);
bool check_rockboxdir(void);
struct tree_context* tree_get_context(void);