diff options
author | Jim Meyering <jim@meyering.net> | 2004-03-25 17:34:11 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-03-25 17:34:11 +0000 |
commit | ac6954ac17bdec16439594c9bdc6859b27d03021 (patch) | |
tree | 1a6db8dc0338d087fce673a3bfc69bcc20db97bd /src | |
parent | 98529c8bfce16811a4edadcc8b956d79ca10ffd9 (diff) | |
download | coreutils-ac6954ac17bdec16439594c9bdc6859b27d03021.tar.xz |
(main): Filter out file names of length zero before
invoking fts, so that they don't cause fatal errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/du.c | 49 |
1 files changed, 30 insertions, 19 deletions
@@ -737,7 +737,6 @@ main (int argc, char **argv) { FILE *istream; size_t i; - bool valid = true; /* When using --files0-from=F, you may not specify any files on the command-line. */ @@ -757,23 +756,6 @@ main (int argc, char **argv) error (EXIT_FAILURE, 0, _("cannot read file names from %s"), quote (files_from)); - /* Fail if any name has length zero. */ - for (i = 0; i < tok.n_tok; i++) - { - if (tok.tok_len[i] == 0) - { - /* Using the standard `filename:line-number:' prefix here is - not totally appropriate, since NUL is the separator, not NL, - but it might be better than nothing. */ - error (0, 0, _("%s:%lu: invalid zero-length file name"), - quotearg_colon (files_from), (unsigned long) i + 1); - valid = false; - } - } - - if (! valid) - exit (EXIT_FAILURE); - files = tok.tok; } else @@ -784,7 +766,36 @@ main (int argc, char **argv) /* Initialize the hash structure for inode numbers. */ hash_init (); - fail = du_files (files, bit_flags); + /* Report and filter out any empty file names before invoking fts. + This works around a glitch in fts, which fails immediately + (without looking at the other file names) when given an empty + file name. */ + { + size_t i = 0; + size_t j; + + for (j = 0; (files[i] = files[j]); j++) + if (files[i][0]) + i++; + else + { + if (files_from) + { + /* Using the standard `filename:line-number:' prefix here is + not totally appropriate, since NUL is the separator, not NL, + but it might be better than nothing. */ + unsigned long int file_number = j + 1; + error (0, 0, "%s:%lu: %s", quotearg_colon (files_from), + file_number, _("invalid zero-length file name")); + } + else + error (0, 0, "%s", _("invalid zero-length file name")); + } + + fail = (i != j); + } + + fail |= du_files (files, bit_flags); /* This isn't really necessary, but it does ensure we exercise this function. */ |