+}
+
+/*
+ * Determines whether a path matches a wildcard pattern.
+ *
+ * @path
+ * The path to match. Assumptions: All path separators must be @path_sep,
+ * there cannot be consecutive path separators, there cannot be a trailing
+ * path separator, and there must be exactly one leading path separator.
+ *
+ * @path_nchars
+ * Number of characters in @path.
+ *
+ * @wildcard
+ * The wildcard pattern to match. It can contain the wildcard characters
+ * '*' and '?'. The former matches zero or more characters except
+ * @path_sep, and the latter matches any character except @path_sep. All
+ * path separators in the pattern must be @path_sep, and there cannot be
+ * consecutive path separators, and there cannot be a trailing path
+ * separator. If there is a leading path separator, the match is attempted
+ * with the filename only; otherwise, the match is attempted with the whole
+ * path.
+ *
+ * @path_sep
+ * Path separator character used in @path and @wildcard.
+ *
+ * @prefix_ok
+ * If %true, allow a prefix of @path, terminated by a path separator, to
+ * match the pattern, in addition to @path itself. In other words, return
+ * %true if the pattern actually matches one of the ancestor directories of
+ * @path.
+ *
+ * Returns %true if there was a match; %false if there was not.
+ */
+bool
+match_path(const tchar *path, size_t path_nchars,
+ const tchar *wildcard, tchar path_sep, bool prefix_ok)
+{
+ if (*wildcard != path_sep) {
+ /* Pattern doesn't begin with path separator. Try to match the
+ * file name only. */
+ return match_wildcard(path_basename_with_len(path, path_nchars),
+ wildcard, tstrlen(wildcard),
+ default_ignore_case);
+ } else {
+ /* Pattern begins with path separator. Try to match the whole
+ * path. */
+ do {
+ if (!*wildcard) {
+ /* Path has more components than pattern */
+ return prefix_ok;
+ }
+
+ size_t path_component_len = 0;
+ size_t wildcard_component_len = 0;
+
+ do {
+ path_component_len++;
+ } while (path[path_component_len] != path_sep &&
+ path[path_component_len] != T('\0'));
+ do {
+ wildcard_component_len++;
+ } while (wildcard[wildcard_component_len] != path_sep &&
+ wildcard[wildcard_component_len] != T('\0'));
+ if (!do_match_wildcard(path, path_component_len,
+ wildcard, wildcard_component_len,
+ default_ignore_case))
+ return false;
+ path += path_component_len;
+ wildcard += wildcard_component_len;
+ } while (*path);
+
+ return (*wildcard == '\0');
+ }