From d89210720b1a67f9a73aadd53b31650774ad302f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 11 Feb 2000 10:08:28 +0000 Subject: [PATCH] (main): Count the stat'able arguments. Print the header line only if there is at least one valid argument. Reported by Andy Longton --- src/df.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/df.c b/src/df.c index 6cf22ef..885c262 100644 --- a/src/df.c +++ b/src/df.c @@ -762,6 +762,7 @@ main (int argc, char **argv) { int c; struct stat *stats IF_LINT (= 0); + int n_valid_args = 0; program_name = argv[0]; setlocale (LC_ALL, ""); @@ -877,12 +878,18 @@ main (int argc, char **argv) stats = (struct stat *) xmalloc ((argc - optind) * sizeof (struct stat)); for (i = optind; i < argc; ++i) - if (stat (argv[i], &stats[i - optind])) - { - error (0, errno, "%s", argv[i]); - exit_status = 1; - argv[i] = NULL; - } + { + if (stat (argv[i], &stats[i - optind])) + { + error (0, errno, "%s", argv[i]); + exit_status = 1; + argv[i] = NULL; + } + else + { + ++n_valid_args; + } + } } mount_list = @@ -917,7 +924,9 @@ main (int argc, char **argv) /* Display explicitly requested empty filesystems. */ show_listed_fs = 1; - print_header (); + if (n_valid_args > 0) + print_header (); + for (i = optind; i < argc; ++i) if (argv[i]) show_entry (argv[i], &stats[i - optind]); -- 2.7.4