1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Thomas Martitz 2010-08-27 10:33:09 +00:00
parent 194174a371
commit 79798ff5f3
3 changed files with 26 additions and 13 deletions

View file

@ -252,7 +252,11 @@ static int browser(void* param)
switch ((intptr_t)param) switch ((intptr_t)param)
{ {
case GO_TO_FILEBROWSER: 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; break;
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
case GO_TO_DBBROWSER: case GO_TO_DBBROWSER:

View file

@ -511,16 +511,16 @@ void resume_directory(const char *dir)
/* Returns the current working directory and also writes cwd to buf if /* Returns the current working directory and also writes cwd to buf if
non-NULL. In case of error, returns NULL. */ non-NULL. In case of error, returns NULL. */
char *getcwd(char *buf, int size) char *getcwd(char *buf, size_t size)
{ {
if (!buf) if (!buf)
return tc.currdir; return tc.currdir;
else if (size > 0) else if (size)
{ {
strlcpy(buf, tc.currdir, size); if (strlcpy(buf, tc.currdir, size) < size)
return buf; return buf;
} }
else /* size == 0, or truncation in strlcpy */
return NULL; return NULL;
} }
@ -530,19 +530,28 @@ void reload_directory(void)
reload_dir = true; 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 #ifdef HAVE_TAGCACHE
/* in ID3DB mode it is a bad idea to call this function */ /* in ID3DB mode it is a bad idea to call this function */
/* (only happens with `follow playlist') */ /* (only happens with `follow playlist') */
if( *tc.dirfilter == SHOW_ID3DB ) if( *tc.dirfilter == SHOW_ID3DB )
return; return NULL;
#endif #endif
struct entry* dc = tc.dircache; struct entry* dc = tc.dircache;
struct entry* e = &dc[tc.selected_item]; struct entry* e = &dc[tc.selected_item];
snprintf(buffer, buffer_len, "%s/%s", getcwd(NULL,0), if (getcwd(buffer, buffer_len))
tc.dirlength ? e->name : ""); {
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) /* Allow apps to change our dirfilter directly (required for sub browsers)

View file

@ -73,13 +73,13 @@ struct tree_context {
void tree_drawlists(void); void tree_drawlists(void);
void tree_mem_init(void) INIT_ATTR; void tree_mem_init(void) INIT_ATTR;
void tree_gui_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_dirfilter(int l_dirfilter);
void set_current_file(char *path); void set_current_file(char *path);
int rockbox_browse(const char *root, int dirfilter); int rockbox_browse(const char *root, int dirfilter);
bool create_playlist(void); bool create_playlist(void);
void resume_directory(const char *dir); void resume_directory(const char *dir);
char *getcwd(char *buf, int size); char *getcwd(char *buf, size_t size);
void reload_directory(void); void reload_directory(void);
bool check_rockboxdir(void); bool check_rockboxdir(void);
struct tree_context* tree_get_context(void); struct tree_context* tree_get_context(void);