From f814dd22abe42b45f0751250a52e2fd42261ef30 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Mar 2005 12:21:12 +0000 Subject: simpler parentPath() function from the uclinux branch (well-tested) git-svn-id: https://svn.musicpd.org/mpd/trunk@3163 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/path.c | 21 +++++++++------------ 1 file 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; } -- cgit v1.2.3