diff options
author | Jim Meyering <jim@meyering.net> | 2003-05-13 17:03:58 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-05-13 17:03:58 +0000 |
commit | 98e8b5e058dc0f8d93071562df5a316ac3344793 (patch) | |
tree | 20e5811a2d7b8dea72cc42bc8dc9ae2a924b75f9 /src | |
parent | 5c0abf663a5533b0425759a4c51620c4168ab4e8 (diff) | |
download | coreutils-98e8b5e058dc0f8d93071562df5a316ac3344793.tar.xz |
Handle argc < optind.
Diffstat (limited to 'src')
-rw-r--r-- | src/df.c | 57 |
1 files changed, 29 insertions, 28 deletions
@@ -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); } |