+ last = next;
+ }
+ active_nr = last;
+}
+
+/*
+ * If the glob starts with a subdirectory, append it to
+ * the prefix instead, for more efficient operation.
+ *
+ * But we do not update the "prefix_offset", which tells
+ * how much of the name to ignore at printout.
+ */
+static void extend_prefix(void)
+{
+ const char *p, *slash;
+ char c;
+
+ p = glob;
+ slash = NULL;
+ while ((c = *p++) != '\0') {
+ if (c == '*')
+ break;
+ if (c == '/')
+ slash = p;
+ }
+ if (slash) {
+ int len = slash - glob;
+ char *newprefix = xmalloc(len + prefix_len + 1);
+ memcpy(newprefix, prefix, prefix_len);
+ memcpy(newprefix + prefix_len, glob, len);
+ prefix_len += len;
+ newprefix[prefix_len] = 0;
+ prefix = newprefix;
+ glob = *slash ? slash : NULL;