From 4bee27ae43e6aa07aa0069ae39cb1c8a2b2cfcfd Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 31 Jan 2003 13:35:25 +0000 Subject: (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. --- src/du.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src') 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")); -- cgit v1.2.3-70-g09d2