summaryrefslogtreecommitdiff
path: root/src/df.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2006-07-20 15:42:26 +0000
committerJim Meyering <jim@meyering.net>2006-07-20 15:42:26 +0000
commit2060c55141708d2ff09cc34d27c0a2a856a21c28 (patch)
treef47d271ec50076d9d9835c8adab3616989351274 /src/df.c
parent6ad7eac04f03b709c045914fa9374f55a0acbc80 (diff)
downloadcoreutils-2060c55141708d2ff09cc34d27c0a2a856a21c28.tar.gz
coreutils-2060c55141708d2ff09cc34d27c0a2a856a21c28.tar.bz2
coreutils-2060c55141708d2ff09cc34d27c0a2a856a21c28.zip
* src/df.c (main): Fail and don't print the headers if no
file system is processed. This makes it easy to test whether a specified directory is on a file system of a given type or types. Otherwise, applications would have had to parse df's output. E.g., is "." either ext3 or reiserfs: df -t ext3 -t reiserfs .
Diffstat (limited to 'src/df.c')
-rw-r--r--src/df.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/df.c b/src/df.c
index 2eece1b46..b69836505 100644
--- a/src/df.c
+++ b/src/df.c
@@ -68,6 +68,9 @@ static uintmax_t output_block_size;
/* If true, use the POSIX output format. */
static bool posix_format;
+/* Count the number of valid arguments. */
+unsigned int n_valid_args;
+
/* If true, invoke the `sync' system call before getting any usage data.
Using this option can make df very slow, especially with many or very
busy disks. Note that this may make a difference on some systems --
@@ -292,6 +295,8 @@ show_dev (char const *disk, char const *mount_point,
if (!selected_fstype (fstype) || excluded_fstype (fstype))
return;
+ ++n_valid_args;
+
/* If MOUNT_POINT is NULL, then the file system is not mounted, and this
program reports on the file system that the special file is on.
It would be better to report on the unmounted file system,
@@ -762,7 +767,6 @@ main (int argc, char **argv)
{
int c;
struct stat *stats IF_LINT (= 0);
- int n_valid_args = 0;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -894,10 +898,6 @@ main (int argc, char **argv)
exit_status = EXIT_FAILURE;
argv[i] = NULL;
}
- else
- {
- ++n_valid_args;
- }
}
}
@@ -941,5 +941,8 @@ main (int argc, char **argv)
show_all_entries ();
}
+ if (n_valid_args == 0)
+ error (EXIT_FAILURE, 0, _("no file systems processed"));
+
exit (exit_status);
}