-static int common_prefix(const char **pathspec)
-{
- const char *path, *slash, *next;
- int prefix;
-
- if (!pathspec)
- return 0;
-
- path = *pathspec;
- slash = strrchr(path, '/');
- if (!slash)
- return 0;
-
- prefix = slash - path + 1;
- while ((next = *++pathspec) != NULL) {
- int len = strlen(next);
- if (len >= prefix && !memcmp(path, next, len))
- continue;
- for (;;) {
- if (!len)
- return 0;
- if (next[--len] != '/')
- continue;
- if (memcmp(path, next, len+1))
- continue;
- prefix = len + 1;
- break;
- }
- }
- return prefix;
-}
-
-static int match(const char **pathspec, const char *name, int namelen, int prefix)
-{
- const char *match;
-
- name += prefix;
- namelen -= prefix;
-
- while ((match = *pathspec++) != NULL) {
- int matchlen;
-
- match += prefix;
- matchlen = strlen(match);
- if (!matchlen)
- return 1;
- if (!strncmp(match, name, matchlen)) {
- if (match[matchlen-1] == '/')
- return 1;
- switch (name[matchlen]) {
- case '/': case '\0':
- return 1;
- }
- }
- if (!fnmatch(match, name, 0))
- return 1;
- }
- return 0;
-}
-