static void find(char *arg) { char * arglist[2]; FTS *p; FTSENT *ent; state.starting_path_length = strlen(arg); inside_dir(AT_FDCWD); arglist[0] = arg; arglist[1] = NULL; switch (options.symlink_handling) { case SYMLINK_ALWAYS_DEREF: ftsoptions |= FTS_COMFOLLOW|FTS_LOGICAL; break; case SYMLINK_DEREF_ARGSONLY: ftsoptions |= FTS_COMFOLLOW|FTS_PHYSICAL; break; case SYMLINK_NEVER_DEREF: ftsoptions |= FTS_PHYSICAL; break; } if (options.stay_on_filesystem) ftsoptions |= FTS_XDEV; p = fts_open(arglist, ftsoptions, NULL); if (NULL == p) { error (0, errno, _("cannot search %s"), safely_quote_err_filename(0, arg)); } else { while ( (ent=fts_read(p)) != NULL ) { state.have_stat = false; state.have_type = false; state.type = 0; consider_visiting(p, ent); } fts_close(p); p = NULL; } }
static bool find (char *arg) { char * arglist[2]; FTS *p; FTSENT *ent; state.starting_path_length = strlen (arg); inside_dir (AT_FDCWD); arglist[0] = arg; arglist[1] = NULL; switch (options.symlink_handling) { case SYMLINK_ALWAYS_DEREF: ftsoptions |= FTS_COMFOLLOW|FTS_LOGICAL; break; case SYMLINK_DEREF_ARGSONLY: ftsoptions |= FTS_COMFOLLOW|FTS_PHYSICAL; break; case SYMLINK_NEVER_DEREF: ftsoptions |= FTS_PHYSICAL; break; } if (options.stay_on_filesystem) ftsoptions |= FTS_XDEV; p = fts_open (arglist, ftsoptions, NULL); if (NULL == p) { error (0, errno, _("cannot search %s"), safely_quote_err_filename (0, arg)); error_severity (EXIT_FAILURE); } else { int level = INT_MIN; while ( (errno=0, ent=fts_read (p)) != NULL ) { if (state.execdirs_outstanding) { /* If we changed level, perform any outstanding * execdirs. If we see a sequence of directory entries * like this: fffdfffdfff, we could build a command line * of 9 files, but this simple-minded implementation * builds a command line for only 3 files at a time * (since fts descends into the directories). */ if ((int)ent->fts_level != level) { show_outstanding_execdirs (stderr); complete_pending_execdirs (); } } level = (int)ent->fts_level; state.already_issued_stat_error_msg = false; state.have_stat = false; state.have_type = !!ent->fts_statp->st_mode; 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 * are going to skip the rest of the start points, and return with * nonzero exit status. Hence we need to issue a diagnostic on * stderr. */ error (0, errno, _("failed to restore working directory after searching %s"), arg); error_severity (EXIT_FAILURE); return false; } p = NULL; } return true; }