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
This commit is contained in:
Jens Arnold 2009-07-08 23:29:41 +00:00
parent 408213f263
commit 96f2a9dad1

View file

@ -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);