simpler parentPath() function from the uclinux branch (well-tested)

git-svn-id: https://svn.musicpd.org/mpd/trunk@3163 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2005-03-28 12:21:12 +00:00
parent 4a3d74bcf6
commit f814dd22ab

View File

@ -230,21 +230,18 @@ char * rpp2app(char * relativePath) {
char * parentPath(char * path) {
static char parentPath[MAXPATHLEN+1];
int i;
char * c;
memset(parentPath,0,MAXPATHLEN+1);
strncpy(parentPath,path,MAXPATHLEN);
while(strlen(parentPath) && parentPath[strlen(parentPath)-1]=='/') {
parentPath[strlen(parentPath)-1] = '\0';
}
for(i=strlen(parentPath);i>=0;i--) {
if(parentPath[i]=='/') break;
parentPath[i] = '\0';
}
while(strlen(parentPath) && parentPath[strlen(parentPath)-1]=='/') {
parentPath[strlen(parentPath)-1] = '\0';
}
c = strrchr(parentPath,'/');
if (c == NULL)
parentPath[0] = '\0';
else {
while ((parentPath <= c) && *(--c) == '/') /* nothing */;
c[1] = '\0';
}
return parentPath;
}