aboutsummaryrefslogtreecommitdiffstats
path: root/src/ArchiveLookup.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-17 00:44:57 +0200
committerMax Kellermann <max@duempel.org>2013-10-17 00:44:57 +0200
commit15c2538532c3f4073b8daa368d6fa1e0f43d871d (patch)
treec1b8b40c8de703de2d32a157dc2ba3158bfaf28c /src/ArchiveLookup.cxx
parentfd9dd9343b88e709fae5a6f46dadf2e570d0fc4f (diff)
downloadmpd-15c2538532c3f4073b8daa368d6fa1e0f43d871d.tar.gz
mpd-15c2538532c3f4073b8daa368d6fa1e0f43d871d.tar.xz
mpd-15c2538532c3f4073b8daa368d6fa1e0f43d871d.zip
ArchiveLookup: move code to FindSlash()
Diffstat (limited to 'src/ArchiveLookup.cxx')
-rw-r--r--src/ArchiveLookup.cxx25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/ArchiveLookup.cxx b/src/ArchiveLookup.cxx
index ea7449486..4df7eaca1 100644
--- a/src/ArchiveLookup.cxx
+++ b/src/ArchiveLookup.cxx
@@ -30,6 +30,17 @@
#include <errno.h>
gcc_pure
+static char *
+FindSlash(char *p, size_t i)
+{
+ for (; i > 0; --i)
+ if (p[i] == '/')
+ return p + i;
+
+ return nullptr;
+}
+
+gcc_pure
static const char *
FindSuffix(const char *p, size_t i)
{
@@ -88,14 +99,14 @@ archive_lookup(char *pathname, const char **archive,
break;
}
}
+
//find one dir up
- while (idx > 0) {
- if (pathdupe[idx] == '/') {
- pathdupe[idx] = 0;
- break;
- }
- idx--;
- }
+ char *slash = FindSlash(pathdupe, idx);
+ if (slash == nullptr)
+ break;
+
+ *slash = 0;
+ idx = slash - pathdupe;
}
g_free(pathdupe);
return ret;