Commit 15c25385 authored by Max Kellermann's avatar Max Kellermann

ArchiveLookup: move code to FindSlash()

parent fd9dd934
...@@ -30,6 +30,17 @@ ...@@ -30,6 +30,17 @@
#include <errno.h> #include <errno.h>
gcc_pure 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 * static const char *
FindSuffix(const char *p, size_t i) FindSuffix(const char *p, size_t i)
{ {
...@@ -88,14 +99,14 @@ archive_lookup(char *pathname, const char **archive, ...@@ -88,14 +99,14 @@ archive_lookup(char *pathname, const char **archive,
break; break;
} }
} }
//find one dir up //find one dir up
while (idx > 0) { char *slash = FindSlash(pathdupe, idx);
if (pathdupe[idx] == '/') { if (slash == nullptr)
pathdupe[idx] = 0; break;
break;
} *slash = 0;
idx--; idx = slash - pathdupe;
}
} }
g_free(pathdupe); g_free(pathdupe);
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment