forked from len0rd/rockbox
Clean up a bit and get switch statement out of loop in walk_path()
It's nicer to look at and it obfuscated a bug where it should have exited the loop instead of the case (you probably wouldn't observe the effect very often). Change-Id: I33f3c72c8bb7e11b9d418f66cf84efc3082a37b4
This commit is contained in:
parent
802e0110db
commit
0a66545487
1 changed files with 33 additions and 40 deletions
|
@ -498,51 +498,44 @@ walk_path(struct pathwalk *walkp, struct pathwalk_component *compp,
|
||||||
if (!(compp->attr & ATTR_DIRECTORY))
|
if (!(compp->attr & ATTR_DIRECTORY))
|
||||||
return -ENOTDIR;
|
return -ENOTDIR;
|
||||||
|
|
||||||
switch (len)
|
if (len >= MAX_NAME)
|
||||||
|
return -ENAMETOOLONG;
|
||||||
|
|
||||||
|
/* check for "." and ".." */
|
||||||
|
if (name[0] == '.')
|
||||||
{
|
{
|
||||||
case 1:
|
if (len == 1)
|
||||||
case 2:
|
continue; /* is "." */
|
||||||
/* check for "." and ".." */
|
|
||||||
if (name[0] == '.')
|
if (len == 2 && name[1] == '.')
|
||||||
{
|
{
|
||||||
if (len == 1)
|
/* is ".." */
|
||||||
break; /* is "." */
|
struct pathwalk_component *parentp = compp->nextp;
|
||||||
|
if (!parentp)
|
||||||
|
return WALK_RC_CONT_AT_ROOT;
|
||||||
|
|
||||||
if (name[1] == '.')
|
compp->nextp = freep;
|
||||||
{
|
freep = compp;
|
||||||
/* is ".." */
|
compp = parentp;
|
||||||
struct pathwalk_component *parentp = compp->nextp;
|
continue;
|
||||||
if (!parentp)
|
|
||||||
return WALK_RC_CONT_AT_ROOT;
|
|
||||||
|
|
||||||
compp->nextp = freep;
|
|
||||||
freep = compp;
|
|
||||||
compp = parentp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fallthrough */
|
|
||||||
default:
|
|
||||||
if (len >= MAX_NAME)
|
|
||||||
return -ENAMETOOLONG;
|
|
||||||
|
|
||||||
struct pathwalk_component *newp = freep;
|
|
||||||
if (!newp)
|
|
||||||
newp = pathwalk_comp_alloc(compp);
|
|
||||||
else
|
|
||||||
freep = freep->nextp;
|
|
||||||
|
|
||||||
newp->nextp = compp;
|
|
||||||
compp = newp;
|
|
||||||
|
|
||||||
compp->name = name;
|
|
||||||
compp->length = len;
|
|
||||||
|
|
||||||
rc = open_path_component(walkp, compp, stream);
|
|
||||||
if (rc < 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pathwalk_component *newp = freep;
|
||||||
|
if (!newp)
|
||||||
|
newp = pathwalk_comp_alloc(compp);
|
||||||
|
else
|
||||||
|
freep = freep->nextp;
|
||||||
|
|
||||||
|
newp->nextp = compp;
|
||||||
|
compp = newp;
|
||||||
|
|
||||||
|
compp->name = name;
|
||||||
|
compp->length = len;
|
||||||
|
|
||||||
|
rc = open_path_component(walkp, compp, stream);
|
||||||
|
if (rc < 0)
|
||||||
|
break; /* return info below */
|
||||||
}
|
}
|
||||||
|
|
||||||
return walk_open_info(walkp, compp, rc, stream);
|
return walk_open_info(walkp, compp, rc, stream);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue