+static int
+compare_names_found (struct name const *n1, struct name const *n2)
+{
+ int found_diff = WASFOUND (n2) - WASFOUND (n1);
+ return found_diff ? found_diff : strcmp (n1->name, n2->name);
+}
+
+/* Simple comparison by names. */
+static int
+compare_names (struct name const *n1, struct name const *n2)
+{
+ return strcmp (n1->name, n2->name);
+}
+
+\f
+/* Add all the dirs under ST to the namelist NAME, descending the
+ directory hierarchy recursively. */
+
+static void
+add_hierarchy_to_namelist (struct tar_stat_info *st, struct name *name)
+{
+ const char *buffer;
+
+ name->directory = scan_directory (st);
+ buffer = directory_contents (name->directory);
+ if (buffer)
+ {
+ struct name *child_head = NULL, *child_tail = NULL;
+ size_t name_length = name->length;
+ size_t allocated_length = (name_length >= NAME_FIELD_SIZE
+ ? name_length + NAME_FIELD_SIZE
+ : NAME_FIELD_SIZE);
+ char *namebuf = xmalloc (allocated_length + 1);
+ /* FIXME: + 2 above? */
+ const char *string;
+ size_t string_length;
+ int change_dir = name->change_dir;
+
+ strcpy (namebuf, name->name);
+ if (! ISSLASH (namebuf[name_length - 1]))
+ {
+ namebuf[name_length++] = '/';
+ namebuf[name_length] = '\0';
+ }
+
+ for (string = buffer; *string; string += string_length + 1)
+ {
+ string_length = strlen (string);
+ if (*string == 'D')