summaryrefslogtreecommitdiffstats
path: root/bin/ls/print.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2020-10-07 21:03:09 +0000
committermillert <millert@openbsd.org>2020-10-07 21:03:09 +0000
commitbc2593c5afc2fbdaea8c85b3fa17064984d9da09 (patch)
tree537139949675ab49e69fdfd3a4d5d4aca7722ef0 /bin/ls/print.c
parentsys_getitimer(), sys_setitimer(): style(9), misc. cleanup (diff)
downloadwireguard-openbsd-bc2593c5afc2fbdaea8c85b3fa17064984d9da09.tar.xz
wireguard-openbsd-bc2593c5afc2fbdaea8c85b3fa17064984d9da09.zip
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, and matches the behavior of AT&T and GNU ls. From FreeBSD (das). OK kn@
Diffstat (limited to 'bin/ls/print.c')
-rw-r--r--bin/ls/print.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 959282c61a2..646b4277b81 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.38 2019/02/05 02:17:32 deraadt Exp $ */
+/* $OpenBSD: print.c,v 1.39 2020/10/07 21:03:09 millert Exp $ */
/* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */
/*
@@ -87,7 +87,8 @@ printlong(DISPLAY *dp)
NAMES *np;
char buf[20];
- if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
+ if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
+ (f_longform || f_size))
(void)printf("total %llu\n", howmany(dp->btotal, blocksize));
for (p = dp->list; p; p = p->fts_link) {
@@ -198,7 +199,8 @@ printcol(DISPLAY *dp)
if (num % numcols)
++numrows;
- if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
+ if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
+ (f_longform || f_size))
(void)printf("total %llu\n", howmany(dp->btotal, blocksize));
for (row = 0; row < numrows; ++row) {
for (base = row, col = 0;;) {
@@ -271,7 +273,8 @@ printacol(DISPLAY *dp)
if ( (colwidth = compute_columns(dp, &numcols)) == 0)
return;
- if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
+ if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
+ (f_longform || f_size))
(void)printf("total %llu\n", howmany(dp->btotal, blocksize));
col = 0;
for (p = dp->list; p; p = p->fts_link) {