/* find -- search for files in a directory hierarchy (fts version)
- Copyright (C) 1990, 1091, 1992, 1993, 1994, 2000, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009,
- 2010 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1091, 1992, 1993, 1994, 2000, 2003, 2004, 2005,
+ 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Dan Bernstein <brnstnd@kramden.acf.nyu.edu>.
*/
-
+/* config.h must always be included first. */
#include <config.h>
-#include "defs.h"
-
-#define USE_SAFE_CHDIR 1
-#undef STAT_MOUNTPOINTS
-
-#include <errno.h>
+/* system headers. */
#include <assert.h>
-
+#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
+#include <locale.h>
#include <sys/stat.h>
-
#include <unistd.h>
-#include "progname.h"
+/* gnulib headers. */
+#include "cloexec.h"
#include "closeout.h"
-#include "quotearg.h"
+#include "error.h"
#include "fts_.h"
+#include "gettext.h"
+#include "progname.h"
+#include "quotearg.h"
#include "save-cwd.h"
#include "xgetcwd.h"
-#include "error.h"
+
+/* find headers. */
+#include "defs.h"
#include "dircallback.h"
-#include "cloexec.h"
#include "fdleak.h"
#include "unused-result.h"
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
+#define USE_SAFE_CHDIR 1
+#undef STAT_MOUNTPOINTS
+
#if ENABLE_NLS
# include <libintl.h>
/* FTS_TIGHT_CYCLE_CHECK tries to work around Savannah bug #17877
* (but actually using it doesn't fix the bug).
*/
-static int ftsoptions = FTS_NOSTAT|FTS_TIGHT_CYCLE_CHECK|FTS_CWDFD;
+static int ftsoptions = FTS_NOSTAT|FTS_TIGHT_CYCLE_CHECK|FTS_CWDFD|FTS_VERBATIM;
static int prev_depth = INT_MIN; /* fts_level can be < 0 */
static int curr_fd = -1;
pfx = NULL;
if (pfx)
{
- int i;
+ size_t i;
const struct exec_val *execp = &p->args.exec_vec;
++seen;
fprintf (fp, "%s ", pfx);
if (execp->multiple)
fprintf (fp, "multiple ");
- fprintf (fp, "%d args: ", execp->state.cmd_argc);
+ fprintf (fp, "%" PRIuMAX " args: ", (uintmax_t) execp->state.cmd_argc);
for (i=0; i<execp->state.cmd_argc; ++i)
{
fprintf (fp, "%s ", execp->state.cmd_argv[i]);
{
int level = INT_MIN;
- while ( (ent=fts_read (p)) != NULL )
+ while ( (errno=0, ent=fts_read (p)) != NULL )
{
if (state.execdirs_outstanding)
{
state.type = state.have_type ? ent->fts_statp->st_mode : 0;
consider_visiting (p, ent);
}
+ /* fts_read returned NULL; distinguish between "finished" and "error". */
+ if (errno)
+ {
+ error (0, errno,
+ "failed to read file names from file system at or below %s",
+ safely_quote_err_filename (0, arg));
+ error_severity (EXIT_FAILURE);
+ return false;
+ }
+
if (0 != fts_close (p))
{
/* Here we break the abstraction of fts_close a bit, because we
if (NULL == state.shared_files)
{
error (EXIT_FAILURE, errno,
- _("Failed initialise shared-file hash table"));
+ _("Failed initialize shared-file hash table"));
}
/* Set the option defaults before we do the locale initialisation as
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- atexit (close_stdout);
+ if (atexit (close_stdout))
+ {
+ error (EXIT_FAILURE, errno, _("The atexit library function failed"));
+ }
/* Check for -P, -H or -L options. Also -D and -O, which are
* both GNU extensions.