summaryrefslogtreecommitdiffstats
path: root/firmware/general.c
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2009-07-08 23:29:41 +0000
committerJens Arnold <amiconn@rockbox.org>2009-07-08 23:29:41 +0000
commit96f2a9dad198eee48a7bbb0614e1e668eb21a6d3 (patch)
treed79a19926d9fa023d3fff543a94b9484051bdc99 /firmware/general.c
parent408213f2633236690ba76f9c9d76e061c3c51237 (diff)
downloadrockbox-96f2a9dad198eee48a7bbb0614e1e668eb21a6d3.tar.gz
rockbox-96f2a9dad198eee48a7bbb0614e1e668eb21a6d3.tar.bz2
rockbox-96f2a9dad198eee48a7bbb0614e1e668eb21a6d3.zip
Numbered filename creation: Make the search for pre-existing files independent of the requested number length. This way it will also increment properly if the requested number length changes or overflows (more than 99 files for numberlen == 2).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21732 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/general.c')
-rw-r--r--firmware/general.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/firmware/general.c b/firmware/general.c
index 1ff3340d27..14b2b55bf9 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -106,6 +106,7 @@ char *create_numbered_filename(char *buffer, const char *path,
int max_num;
int pathlen;
int prefixlen = strlen(prefix);
+ int suffixlen = strlen(suffix);
char fmtstring[12];
if (buffer != path)
@@ -131,10 +132,14 @@ char *create_numbered_filename(char *buffer, const char *path,
while ((entry = readdir(dir)))
{
- int curr_num;
+ int curr_num, namelen;
- if (strncasecmp((char *)entry->d_name, prefix, prefixlen)
- || strcasecmp((char *)entry->d_name + prefixlen + numberlen, suffix))
+ if (strncasecmp((char *)entry->d_name, prefix, prefixlen))
+ continue;
+
+ namelen = strlen((char *)entry->d_name);
+ if ((namelen <= prefixlen + suffixlen)
+ || strcasecmp((char *)entry->d_name + namelen - suffixlen, suffix))
continue;
curr_num = atoi((char *)entry->d_name + prefixlen);