summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorHardeep Sidhu <dyp@pobox.com>2004-03-21 22:27:56 +0000
committerHardeep Sidhu <dyp@pobox.com>2004-03-21 22:27:56 +0000
commit53d82534709393fb2e0aec356f14dbb8c0a4695c (patch)
treebc97d2b300e1ce96ce5e14ce59fc18212eca586a /apps
parentbe21ab8abf08cabb23bdac3bd38689a62a84f66e (diff)
Use same path buffer when recursively creating playlist
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4427 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/tree.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 2a630fd4fc..d56dacc130 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -1440,10 +1440,9 @@ static bool dirbrowse(char *root, int *dirfilter)
}
static int plsize = 0;
-static bool add_dir(char* dirname, int fd)
+static bool add_dir(char* dirname, int len, int fd)
{
bool abort = false;
- char buf[MAX_PATH/2]; /* saving a little stack... */
DIR* dir;
/* check for user abort */
@@ -1465,14 +1464,21 @@ static bool add_dir(char* dirname, int fd)
if (!entry)
break;
if (entry->attribute & ATTR_DIRECTORY) {
+ int dirlen = strlen(dirname);
+ bool result;
+
if (!strcmp(entry->d_name, ".") ||
!strcmp(entry->d_name, ".."))
continue;
+
if (dirname[1])
- snprintf(buf, sizeof buf, "%s/%s", dirname, entry->d_name);
+ snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
else
- snprintf(buf, sizeof buf, "/%s", entry->d_name);
- if (add_dir(buf,fd)) {
+ snprintf(dirname, len, "/%s", entry->d_name);
+
+ result = add_dir(dirname, len, fd);
+ dirname[dirlen] = '\0';
+ if (result) {
abort = true;
break;
}
@@ -1483,6 +1489,7 @@ static bool add_dir(char* dirname, int fd)
(!strcasecmp(&entry->d_name[x-4], ".mp2")) ||
(!strcasecmp(&entry->d_name[x-4], ".mpa")))
{
+ char buf[8];
write(fd, dirname, strlen(dirname));
write(fd, "/", 1);
write(fd, entry->d_name, x);
@@ -1532,8 +1539,9 @@ bool create_playlist(void)
if (fd < 0)
return false;
+ snprintf(filename, sizeof(filename), "%s", currdir[1] ? currdir : "/");
plsize = 0;
- add_dir(currdir[1] ? currdir : "/", fd);
+ add_dir(filename, sizeof(filename), fd);
close(fd);
sleep(HZ);