summaryrefslogtreecommitdiff
path: root/src/du.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-10-04 17:01:13 +0000
committerJim Meyering <jim@meyering.net>2003-10-04 17:01:13 +0000
commite2d3450c72aec89ff1f2df577457e8ad0cb95f4b (patch)
treefa1e5964388b667f595595b699e3e7731226d7fb /src/du.c
parent2190e5a5d887c7938315e86bccf6317cb02b1335 (diff)
downloadcoreutils-e2d3450c72aec89ff1f2df577457e8ad0cb95f4b.tar.xz
(du_files): Give better diagnostics for failed fts_open.
Diffstat (limited to 'src/du.c')
-rw-r--r--src/du.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/du.c b/src/du.c
index e792d6fc8..b9d9f4d95 100644
--- a/src/du.c
+++ b/src/du.c
@@ -463,8 +463,9 @@ process_file (FTS *fts, FTSENT *ent)
/* Recursively print the sizes of the directories (and, if selected, files)
named in FILES, the last entry of which is NULL.
- FTS_FLAGS controls how fts works.
- Return nonzero upon error. */
+ BIT_FLAGS controls how fts works.
+ If the fts_open call fails, exit nonzero.
+ Otherwise, return nonzero upon error. */
static int
du_files (char **files, int bit_flags)
@@ -474,9 +475,23 @@ du_files (char **files, int bit_flags)
FTS *fts = fts_open (files, bit_flags, NULL);
if (fts == NULL)
{
- /* FIXME */
- error (0, errno, "FIXME");
- return 1;
+ /* This can fail in three ways: out of memory, invalid bit_flags,
+ and one of the FILES is an empty string.
+ We could try to decipher that errno==EINVAL means invalid
+ bit_flags and errno==ENOENT, but that seems wrong. Ideally
+ fts_open would return a proper error indicator. For now,
+ we'll presume that the bit_flags are valid and just check for
+ empty strings. */
+ bool invalid_arg = false;
+ for (; *files; ++files)
+ {
+ if (**files == '\0')
+ invalid_arg = true;
+ }
+ if (invalid_arg)
+ error (EXIT_FAILURE, 0, _("invalid argument: %s"), quote (""));
+ else
+ xalloc_die ();
}
while (1)