summaryrefslogtreecommitdiff
path: root/src/df.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-05-13 17:03:58 +0000
committerJim Meyering <jim@meyering.net>2003-05-13 17:03:58 +0000
commit98e8b5e058dc0f8d93071562df5a316ac3344793 (patch)
tree20e5811a2d7b8dea72cc42bc8dc9ae2a924b75f9 /src/df.c
parent5c0abf663a5533b0425759a4c51620c4168ab4e8 (diff)
downloadcoreutils-98e8b5e058dc0f8d93071562df5a316ac3344793.tar.xz
Handle argc < optind.
Diffstat (limited to 'src/df.c')
-rw-r--r--src/df.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/df.c b/src/df.c
index eb8a01b35..06eefc9ef 100644
--- a/src/df.c
+++ b/src/df.c
@@ -867,27 +867,28 @@ main (int argc, char **argv)
exit (EXIT_FAILURE);
}
- {
- int i;
+ if (optind < argc)
+ {
+ int i;
- /* stat all the given entries to make sure they get automounted,
- if necessary, before reading the filesystem table. */
- 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", quote (argv[i]));
- exit_status = 1;
- argv[i] = NULL;
- }
- else
- {
- ++n_valid_args;
- }
- }
- }
+ /* stat all the given entries to make sure they get automounted,
+ if necessary, before reading the filesystem table. */
+ 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", quote (argv[i]));
+ exit_status = 1;
+ argv[i] = NULL;
+ }
+ else
+ {
+ ++n_valid_args;
+ }
+ }
+ }
mount_list =
read_filesystem_list ((fs_select_list != NULL
@@ -900,8 +901,8 @@ main (int argc, char **argv)
/* Couldn't read the table of mounted filesystems.
Fail if df was invoked with no file name arguments;
Otherwise, merely give a warning and proceed. */
- const char *warning = (optind == argc ? "" : _("Warning: "));
- int status = (optind == argc ? 1 : 0);
+ const char *warning = (optind < argc ? _("Warning: ") : "");
+ int status = (optind < argc ? 0 : 1);
error (status, errno,
_("%scannot read table of mounted filesystems"), warning);
}
@@ -909,12 +910,7 @@ main (int argc, char **argv)
if (require_sync)
sync ();
- if (optind == argc)
- {
- print_header ();
- show_all_entries ();
- }
- else
+ if (optind < argc)
{
int i;
@@ -928,6 +924,11 @@ main (int argc, char **argv)
if (argv[i])
show_entry (argv[i], &stats[i - optind]);
}
+ else
+ {
+ print_header ();
+ show_all_entries ();
+ }
exit (exit_status);
}