summaryrefslogtreecommitdiffstats
path: root/bin/ls
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2004-06-08 09:30:10 +0000
committerdas <das@FreeBSD.org>2004-06-08 09:30:10 +0000
commit89c138dcf08ea624d3c1a707ff03f725d1b76f88 (patch)
tree0d308a0f1ce5a5cc19a0694658eac588c1f05184 /bin/ls
parent03b595604e8ecb0df9c45b98ff40642cb6b3cf93 (diff)
downloadFreeBSD-src-89c138dcf08ea624d3c1a707ff03f725d1b76f88.zip
FreeBSD-src-89c138dcf08ea624d3c1a707ff03f725d1b76f88.tar.gz
If we are asked to print the total number of blocks, do so even if we
have no entries to print (either due to an empty directory or an error). This makes the -l and -s options more consistent, like Solaris and (Debian) Linux. To make this happen, tweak two optimizations on the second call to display(): - Don't skip display() altogether, even if list == NULL. - Don't skip the call to the printfn in display() if we need to print the total. PR: 45723
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/ls.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index fa48096..123084a 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -452,7 +452,13 @@ traverse(int argc, char *argv[], int options)
fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
err(1, "fts_open");
- display(NULL, fts_children(ftsp, 0), options);
+ /*
+ * We ignore errors from fts_children here since they will be
+ * replicated and signalled on the next call to fts_read() below.
+ */
+ chp = fts_children(ftsp, 0);
+ if (chp != NULL)
+ display(NULL, chp, options);
if (f_listdir)
return;
@@ -533,16 +539,6 @@ display(const FTSENT *p, FTSENT *list, int options)
char ngroup[STRBUF_SIZEOF(uid_t) + 1];
char nuser[STRBUF_SIZEOF(gid_t) + 1];
- /*
- * If list is NULL there are two possibilities: that the parent
- * directory p has no children, or that fts_children() returned an
- * error. We ignore the error case since it will be replicated
- * on the next call to fts_read() on the post-order visit to the
- * directory p, and will be signaled in traverse().
- */
- if (list == NULL)
- return;
-
needstats = f_inode || f_longform || f_size;
flen = 0;
btotal = 0;
@@ -784,7 +780,13 @@ label_out:
++entries;
}
- if (!entries)
+ /*
+ * If there are no entries to display, we normally stop right
+ * here. However, we must continue if we have to display the
+ * total block count. In this case, we display the total only
+ * on the second (p != NULL) pass.
+ */
+ if (!entries && (!(f_longform || f_size) || p == NULL))
return;
d.list = list;
OpenPOWER on IntegriCloud