aboutsummaryrefslogtreecommitdiffstats
path: root/src/path.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2005-03-28 12:21:12 +0000
committerEric Wong <normalperson@yhbt.net>2005-03-28 12:21:12 +0000
commitf814dd22abe42b45f0751250a52e2fd42261ef30 (patch)
tree6b248bd2c96af5b8e15606bbed8e16f0ad25e72c /src/path.c
parent4a3d74bcf6eaab0627c0d053b3aa3a89505eea00 (diff)
downloadmpd-f814dd22abe42b45f0751250a52e2fd42261ef30.tar.gz
mpd-f814dd22abe42b45f0751250a52e2fd42261ef30.tar.xz
mpd-f814dd22abe42b45f0751250a52e2fd42261ef30.zip
simpler parentPath() function from the uclinux branch (well-tested)
git-svn-id: https://svn.musicpd.org/mpd/trunk@3163 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/path.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/path.c b/src/path.c
index dec9844b6..ad8cbfa1f 100644
--- a/src/path.c
+++ b/src/path.c
@@ -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;
}