1
0
Fork 0
forked from len0rd/rockbox

using a pointer instead of array dereferencing saves ~250 bytes

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5529 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jörg Hohensohn 2005-01-03 20:23:42 +00:00
parent 49efa8dc2b
commit dcdffe828c

View file

@ -74,13 +74,19 @@ DIR* opendir(const char* name)
char* end; char* end;
struct fat_direntry entry; struct fat_direntry entry;
int dd; int dd;
DIR* pdir = opendirs;
#ifdef HAVE_MULTIVOLUME #ifdef HAVE_MULTIVOLUME
int volume; int volume;
#endif #endif
if ( name[0] != '/' ) {
DEBUGF("Only absolute paths supported right now\n");
return NULL;
}
/* find a free dir descriptor */ /* find a free dir descriptor */
for ( dd=0; dd<MAX_OPEN_DIRS; dd++ ) for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
if ( !opendirs[dd].busy ) if ( !pdir->busy )
break; break;
if ( dd == MAX_OPEN_DIRS ) { if ( dd == MAX_OPEN_DIRS ) {
@ -89,26 +95,20 @@ DIR* opendir(const char* name)
return NULL; return NULL;
} }
opendirs[dd].busy = true; pdir->busy = true;
if ( name[0] != '/' ) {
DEBUGF("Only absolute paths supported right now\n");
opendirs[dd].busy = false;
return NULL;
}
#ifdef HAVE_MULTIVOLUME #ifdef HAVE_MULTIVOLUME
/* try to extract a heading volume name, if present */ /* try to extract a heading volume name, if present */
volume = strip_volume(name, namecopy); volume = strip_volume(name, namecopy);
opendirs[dd].volumecounter = 0; pdir->volumecounter = 0;
#else #else
strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ strncpy(namecopy,name,sizeof(namecopy)); /* just copy */
namecopy[sizeof(namecopy)-1] = '\0'; namecopy[sizeof(namecopy)-1] = '\0';
#endif #endif
if ( fat_opendir(IF_MV2(volume,) &(opendirs[dd].fatdir), 0, NULL) < 0 ) { if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) {
DEBUGF("Failed opening root dir\n"); DEBUGF("Failed opening root dir\n");
opendirs[dd].busy = false; pdir->busy = false;
return NULL; return NULL;
} }
@ -116,32 +116,32 @@ DIR* opendir(const char* name)
part = strtok_r(NULL, "/", &end)) { part = strtok_r(NULL, "/", &end)) {
/* scan dir for name */ /* scan dir for name */
while (1) { while (1) {
if ((fat_getnext(&(opendirs[dd].fatdir),&entry) < 0) || if ((fat_getnext(&pdir->fatdir,&entry) < 0) ||
(!entry.name[0])) { (!entry.name[0])) {
opendirs[dd].busy = false; pdir->busy = false;
return NULL; return NULL;
} }
if ( (entry.attr & FAT_ATTR_DIRECTORY) && if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
(!strcasecmp(part, entry.name)) ) { (!strcasecmp(part, entry.name)) ) {
opendirs[dd].parent_dir = opendirs[dd].fatdir; pdir->parent_dir = pdir->fatdir;
if ( fat_opendir(IF_MV2(volume,) if ( fat_opendir(IF_MV2(volume,)
&(opendirs[dd].fatdir), &pdir->fatdir,
entry.firstcluster, entry.firstcluster,
&(opendirs[dd].parent_dir)) < 0 ) { &pdir->parent_dir) < 0 ) {
DEBUGF("Failed opening dir '%s' (%d)\n", DEBUGF("Failed opening dir '%s' (%d)\n",
part, entry.firstcluster); part, entry.firstcluster);
opendirs[dd].busy = false; pdir->busy = false;
return NULL; return NULL;
} }
#ifdef HAVE_MULTIVOLUME #ifdef HAVE_MULTIVOLUME
opendirs[dd].volumecounter = -1; /* n.a. to subdirs */ pdir->volumecounter = -1; /* n.a. to subdirs */
#endif #endif
break; break;
} }
} }
} }
return &opendirs[dd]; return pdir;
} }
int closedir(DIR* dir) int closedir(DIR* dir)