summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-01-31 13:35:25 +0000
committerJim Meyering <jim@meyering.net>2003-01-31 13:35:25 +0000
commit4bee27ae43e6aa07aa0069ae39cb1c8a2b2cfcfd (patch)
tree4f94506adb9c3ac79e8bd593e64304af458bc399 /src
parentaaf8697ee95c179e8a20baf3b47691063b4c9b2b (diff)
downloadcoreutils-4bee27ae43e6aa07aa0069ae39cb1c8a2b2cfcfd.tar.xz
(main): Upon processing a bad --exclude-from or --max-depth
option argument, don't exit right away, in case there are others. Rather record the failure and exit after processing other options.
Diffstat (limited to 'src')
-rw-r--r--src/du.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/du.c b/src/du.c
index 56b0e1668..c132ae7ea 100644
--- a/src/du.c
+++ b/src/du.c
@@ -538,6 +538,7 @@ main (int argc, char **argv)
char *cwd_only[2];
int max_depth_specified = 0;
char **files;
+ int fail;
/* Bit flags that control how nftw works. */
int ftw_flags = FTW_DEPTH | FTW_PHYS | FTW_CHDIR;
@@ -560,6 +561,7 @@ main (int argc, char **argv)
human_output_opts = human_options (getenv ("DU_BLOCK_SIZE"), false,
&output_block_size);
+ fail = 0;
while ((c = getopt_long (argc, argv, "abchHklmsxB:DLSX:", long_options, NULL))
!= -1)
{
@@ -598,15 +600,18 @@ main (int argc, char **argv)
break;
case MAX_DEPTH_OPTION: /* --max-depth=N */
- /* FIXME: merely set `fail' here, in case there are
- additional invalid options */
- if (xstrtol (optarg, NULL, 0, &tmp_long, NULL) != LONGINT_OK
- || tmp_long < 0 || tmp_long > INT_MAX)
- error (EXIT_FAILURE, 0, _("invalid maximum depth %s"),
- quote (optarg));
-
- max_depth_specified = 1;
- max_depth = (int) tmp_long;
+ if (xstrtol (optarg, NULL, 0, &tmp_long, NULL) == LONGINT_OK
+ && 0 <= tmp_long && tmp_long <= INT_MAX)
+ {
+ max_depth_specified = 1;
+ max_depth = (int) tmp_long;
+ }
+ else
+ {
+ error (0, 0, _("invalid maximum depth %s"),
+ quote (optarg));
+ fail = 1;
+ }
break;
case 'm': /* obsolescent */
@@ -643,11 +648,12 @@ main (int argc, char **argv)
break;
case 'X':
- /* FIXME: merely set `fail' here, in case there are
- additional invalid options */
if (add_exclude_file (add_exclude, exclude, optarg,
EXCLUDE_WILDCARDS, '\n'))
- error (EXIT_FAILURE, errno, "%s", quotearg_colon (optarg));
+ {
+ error (0, errno, "%s", quotearg_colon (optarg));
+ fail = 1;
+ }
break;
case EXCLUDE_OPTION:
@@ -663,6 +669,9 @@ main (int argc, char **argv)
}
}
+ if (fail)
+ exit (EXIT_FAILURE);
+
if (opt_all && opt_summarize_only)
{
error (0, 0, _("cannot both summarize and show all entries"));