+ 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')
+ {
+ struct name *np;
+ struct tar_stat_info subdir;
+ int subfd;
+
+ if (allocated_length <= name_length + string_length)
+ {
+ do
+ {
+ allocated_length *= 2;
+ if (! allocated_length)
+ xalloc_die ();
+ }
+ while (allocated_length <= name_length + string_length);
+
+ namebuf = xrealloc (namebuf, allocated_length + 1);
+ }
+ strcpy (namebuf + name_length, string + 1);
+ np = addname (namebuf, change_dir, false, name);
+ if (!child_head)
+ child_head = np;
+ else
+ child_tail->sibling = np;
+ child_tail = np;
+
+ tar_stat_init (&subdir);
+ subdir.parent = st;
+ if (st->fd < 0)
+ {
+ subfd = -1;
+ errno = - st->fd;
+ }
+ else
+ subfd = subfile_open (st, string + 1,
+ open_read_flags | O_DIRECTORY);
+ if (subfd < 0)
+ open_diag (namebuf);
+ else
+ {
+ subdir.fd = subfd;
+ if (fstat (subfd, &subdir.stat) != 0)
+ stat_diag (namebuf);
+ else if (! (O_DIRECTORY || S_ISDIR (subdir.stat.st_mode)))
+ {
+ errno = ENOTDIR;
+ open_diag (namebuf);
+ }
+ else
+ {
+ subdir.orig_file_name = xstrdup (namebuf);
+ add_hierarchy_to_namelist (&subdir, np);
+ restore_parent_fd (&subdir);
+ }
+ }
+
+ tar_stat_destroy (&subdir);
+ }
+ }
+
+ free (namebuf);
+ name->child = child_head;
+ }