diff options
author | Max Kellermann <max@duempel.org> | 2013-10-17 00:35:46 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-17 00:38:26 +0200 |
commit | fd9dd9343b88e709fae5a6f46dadf2e570d0fc4f (patch) | |
tree | f8819b5c87d2fc13423ce654207ed76e8b57c7c4 /src | |
parent | 1b8a1d4140c58030bc71665eef4dc3485812817e (diff) | |
download | mpd-fd9dd9343b88e709fae5a6f46dadf2e570d0fc4f.tar.gz mpd-fd9dd9343b88e709fae5a6f46dadf2e570d0fc4f.tar.xz mpd-fd9dd9343b88e709fae5a6f46dadf2e570d0fc4f.zip |
ArchiveLookup: move code to FindSuffix()
Diffstat (limited to 'src')
-rw-r--r-- | src/ArchiveLookup.cxx | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/ArchiveLookup.cxx b/src/ArchiveLookup.cxx index 7cea655fd..ea7449486 100644 --- a/src/ArchiveLookup.cxx +++ b/src/ArchiveLookup.cxx @@ -29,6 +29,18 @@ #include <unistd.h> #include <errno.h> +gcc_pure +static const char * +FindSuffix(const char *p, size_t i) +{ + for (; i > 0; --i) { + if (p[i] == '.') + return p + i + 1; + } + + return nullptr; +} + bool archive_lookup(char *pathname, const char **archive, const char **inpath, const char **suffix) @@ -67,14 +79,7 @@ archive_lookup(char *pathname, const char **archive, *inpath = pathname + idx+1; //try to get suffix - *suffix = NULL; - while (idx > 0) { - if (pathname[idx] == '.') { - *suffix = pathname + idx + 1; - break; - } - idx--; - } + *suffix = FindSuffix(pathname, idx); break; } else { FormatError(archive_domain, |