+ int err = 0;
+
+ if (e != &root_entry) {
+ int pathlen = strlen(pathbuf);
+ printf("%06o %s %s ",
+ e->mode, entry_type(e), entry_hex(e));
+ write_name_quoted(pathbuf, pathlen, e->name,
+ line_termination, stdout);
+ putchar(line_termination);
+ }
+
+ if (e->directory) {
+ /* If this is a directory, we have the following cases:
+ * (1) This is the top-level request (explicit path from the
+ * command line, or "root" if there is no command line).
+ * a. Without any flag. We show direct children. We do not
+ * recurse into them.
+ * b. With -r. We do recurse into children.
+ * c. With -d. We do not recurse into children.
+ * (2) We came here because our caller is either (1-a) or
+ * (1-b).
+ * a. Without any flag. We do not show our children (which
+ * are grandchildren for the original request).
+ * b. With -r. We continue to recurse into our children.
+ * c. With -d. We should not have come here to begin with.
+ */
+ if (level == 0 && !(ls_options & LS_TREE_ONLY))
+ /* case (1)-a and (1)-b */
+ err = err | show_children(e, level+1, pathbuf);
+ else if (level && ls_options & LS_RECURSIVE)
+ /* case (2)-b */
+ err = err | show_children(e, level+1, pathbuf);
+ }
+ return err;