From 0e342181c3f96890506aa8720ac2d680b97c12e4 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Thu, 9 Jan 2003 00:18:47 +0000 Subject: Remove bogus dirs from beginning of playlist file path. Patch by Hardeep Sidhu. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3039 a1c6a512-1295-4272-9138-f99709370657 --- apps/playlist.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'apps/playlist.c') diff --git a/apps/playlist.c b/apps/playlist.c index ce812c7c67..38eca09fc9 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -192,7 +192,6 @@ char* playlist_peek(int steps) if('/' == buf[0]) { strcpy(now_playing, &buf[0]); - return now_playing; } else { strncpy(dir_buf, playlist.filename, playlist.dirlen-1); @@ -201,7 +200,6 @@ char* playlist_peek(int steps) /* handle dos style drive letter */ if ( ':' == buf[1] ) { strcpy(now_playing, &buf[2]); - return now_playing; } else if ( '.' == buf[0] && '.' == buf[1] && '/' == buf[2] ) { /* handle relative paths */ @@ -218,17 +216,35 @@ char* playlist_peek(int steps) break; } snprintf(now_playing, MAX_PATH+1, "%s/%s", dir_buf, &buf[seek]); - return now_playing; } else if ( '.' == buf[0] && '/' == buf[1] ) { snprintf(now_playing, MAX_PATH+1, "%s/%s", dir_buf, &buf[2]); - return now_playing; } else { snprintf(now_playing, MAX_PATH+1, "%s/%s", dir_buf, buf); - return now_playing; } } + + buf = now_playing; + + /* remove bogus dirs from beginning of path + (workaround for buggy playlist creation tools) */ + while (buf) + { + fd = open(buf, O_RDONLY); + if (fd > 0) + { + close(fd); + break; + } + + buf = strchr(buf+1, '/'); + } + + if (buf) + return buf; + + return now_playing; } /* -- cgit v1.2.3