summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-06-20 20:12:47 +0000
committerThomas Martitz <kugel@rockbox.org>2011-06-20 20:12:47 +0000
commit3b29aa49d3078dc94fd4d95e46e469c446f560ee (patch)
tree99b9e39d70c1c38357968c381129be8b88046621
parentaf7aaae478b5c7382ae5505abab233a97aa3e658 (diff)
downloadrockbox-3b29aa49d3078dc94fd4d95e46e469c446f560ee.zip
rockbox-3b29aa49d3078dc94fd4d95e46e469c446f560ee.tar.gz
rockbox-3b29aa49d3078dc94fd4d95e46e469c446f560ee.tar.bz2
rockbox-3b29aa49d3078dc94fd4d95e46e469c446f560ee.tar.xz
Optimize new dircache_copy_path so that the helper (strlcat) doesn't need to walk through the entire string repeatedly.
Also fix a off-by-one. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30039 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/dircache.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index bff9c2f..5d280c4 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -1077,11 +1077,12 @@ struct dirinfo* _dircache_get_entry_dirinfo(int id)
* (or, in case of truncation, the position of the nul byte */
static size_t copy_path_helper(const struct dircache_entry *entry, char *buf, size_t size)
{
+ int offset = 1;
/* has parent? */
if (entry->up)
- copy_path_helper(entry->up, buf, size);
+ offset += copy_path_helper(entry->up, buf, size);
- size_t len = strlcat(buf, entry->d_name, size);
+ size_t len = strlcpy(buf+offset, entry->d_name, size - offset) + offset;
if (len < size)
{
buf[len++] = '/';
@@ -1101,7 +1102,7 @@ size_t dircache_copy_path(int index, char *buf, size_t size)
return 0;
buf[0] = '/';
- size_t res = copy_path_helper(&dircache_root[index], buf, size);
+ size_t res = copy_path_helper(&dircache_root[index], buf, size - 1);
/* fixup trailing '/' */
buf[res] = '\0';
return res;