Migrated from GPL version 2 to GPL version 3
[findutils.git] / find / util.c
blob0ec37b3c53f648d5e51e534b0170eb586bc60e6d
1 /* util.c -- functions for initializing new tree elements, and other things.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <config.h>
19 #include "defs.h"
21 #ifdef HAVE_FCNTL_H
22 #include <fcntl.h>
23 #else
24 #include <sys/file.h>
25 #endif
26 #ifdef HAVE_SYS_UTSNAME_H
27 #include <sys/utsname.h>
28 #endif
29 #include <sys/time.h>
30 #include <ctype.h>
31 #include <string.h>
32 #include <limits.h>
33 #include <errno.h>
34 #include <assert.h>
36 #include "xalloc.h"
37 #include "quotearg.h"
38 #include "timespec.h"
39 #include "error.h"
40 #include "verify.h"
41 #include "openat.h"
43 #if ENABLE_NLS
44 # include <libintl.h>
45 # define _(Text) gettext (Text)
46 #else
47 # define _(Text) Text
48 #endif
49 #ifdef gettext_noop
50 # define N_(String) gettext_noop (String)
51 #else
52 /* See locate.c for explanation as to why not use (String) */
53 # define N_(String) String
54 #endif
57 struct debug_option_assoc
59 char *name;
60 int val;
61 char *docstring;
63 static struct debug_option_assoc debugassoc[] =
65 { "help", DebugHelp, "Explain the various -D options" },
66 { "tree", DebugExpressionTree, "Display the expression tree" },
67 { "search",DebugSearch, "Navigate the directory tree verbosely" },
68 { "stat", DebugStat, "Trace calls to stat(2) and lstat(2)" },
69 { "rates", DebugSuccessRates, "Indicate how often each predicate succeeded" },
70 { "opt", DebugExpressionTree|DebugTreeOpt, "Show diagnostic information relating to optimisation" },
71 { "exec", DebugExec, "Show diagnostic information relating to -exec, -execdir, -ok and -okdir" }
73 #define N_DEBUGASSOC (sizeof(debugassoc)/sizeof(debugassoc[0]))
78 /* Add a primary of predicate type PRED_FUNC (described by ENTRY) to the predicate input list.
80 Return a pointer to the predicate node just inserted.
82 Fills in the following cells of the new predicate node:
84 pred_func PRED_FUNC
85 args(.str) NULL
86 p_type PRIMARY_TYPE
87 p_prec NO_PREC
89 Other cells that need to be filled in are defaulted by
90 get_new_pred_chk_op, which is used to insure that the prior node is
91 either not there at all (we are the very first node) or is an
92 operator. */
94 struct predicate *
95 insert_primary_withpred (const struct parser_table *entry, PRED_FUNC pred_func)
97 struct predicate *new_pred;
99 new_pred = get_new_pred_chk_op (entry);
100 new_pred->pred_func = pred_func;
101 new_pred->p_name = entry->parser_name;
102 new_pred->args.str = NULL;
103 new_pred->p_type = PRIMARY_TYPE;
104 new_pred->p_prec = NO_PREC;
105 return new_pred;
108 /* Add a primary described by ENTRY to the predicate input list.
110 Return a pointer to the predicate node just inserted.
112 Fills in the following cells of the new predicate node:
114 pred_func PRED_FUNC
115 args(.str) NULL
116 p_type PRIMARY_TYPE
117 p_prec NO_PREC
119 Other cells that need to be filled in are defaulted by
120 get_new_pred_chk_op, which is used to insure that the prior node is
121 either not there at all (we are the very first node) or is an
122 operator. */
123 struct predicate *
124 insert_primary (const struct parser_table *entry)
126 assert (entry->pred_func != NULL);
127 return insert_primary_withpred(entry, entry->pred_func);
132 static void
133 show_valid_debug_options(FILE *fp, int full)
135 int i;
136 if (full)
138 fprintf(fp, "Valid arguments for -D:\n");
139 for (i=0; i<N_DEBUGASSOC; ++i)
141 fprintf(fp, "%-10s %s\n",
142 debugassoc[i].name,
143 debugassoc[i].docstring);
146 else
148 for (i=0; i<N_DEBUGASSOC; ++i)
150 fprintf(fp, "%s%s", (i>0 ? "|" : ""), debugassoc[i].name);
155 void
156 usage (FILE *fp, int status, char *msg)
158 if (msg)
159 fprintf (fp, "%s: %s\n", program_name, msg);
161 fprintf (fp, _("Usage: %s [-H] [-L] [-P] [-Olevel] [-D "), program_name);
162 show_valid_debug_options(fp, 0);
163 fprintf (fp, _("] [path...] [expression]\n"));
164 if (0 != status)
165 exit (status);
168 void
169 set_stat_placeholders(struct stat *p)
171 #if HAVE_STRUCT_STAT_ST_BIRTHTIME
172 p->st_birthtime = 0;
173 #endif
174 #if HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
175 p->st_birthtimensec = 0;
176 #endif
177 #if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
178 p->st_birthtimespec.tv_nsec = -1;
179 #endif
180 #if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_SEC
181 p->st_birthtimespec.tv_sec = 0;
182 #endif
186 /* Get the stat information for a file, if it is
187 * not already known.
190 get_statinfo (const char *pathname, const char *name, struct stat *p)
192 /* Set markers in fields so we have a good idea if the implementation
193 * didn't bother to set them (e.g., NetBSD st_birthtimespec for MS-DOS
194 * files)
196 if (!state.have_stat)
198 set_stat_placeholders(p);
199 if (0 == (*options.xstat) (name, p))
201 if (00000 == p->st_mode)
203 /* Savannah bug #16378. */
204 error(0, 0, _("Warning: file %s appears to have mode 0000"),
205 quotearg_n_style(0, options.err_quoting_style, name));
208 else
210 if (!options.ignore_readdir_race || (errno != ENOENT) )
212 error (0, errno, "%s",
213 safely_quote_err_filename(0, pathname));
214 state.exit_status = 1;
216 return -1;
219 state.have_stat = true;
220 state.have_type = true;
221 state.type = p->st_mode;
223 return 0;
227 /* Get the stat/type information for a file, if it is
228 * not already known.
231 get_info (const char *pathname,
232 struct stat *p,
233 struct predicate *pred_ptr)
235 boolean todo = false;
237 /* If we need the full stat info, or we need the type info but don't
238 * already have it, stat the file now.
240 if (pred_ptr->need_stat)
241 todo = true;
242 else if ((pred_ptr->need_type && (0 == state.have_type)))
243 todo = true;
245 if (todo)
246 return get_statinfo(pathname, state.rel_pathname, p);
247 else
248 return 0;
251 /* Determine if we can use O_NOFOLLOW.
253 #if defined O_NOFOLLOW
254 boolean
255 check_nofollow(void)
257 struct utsname uts;
258 float release;
260 if (0 == O_NOFOLLOW)
262 return false;
265 if (0 == uname(&uts))
267 /* POSIX requires that atof() ignore "unrecognised suffixes". */
268 release = atof(uts.release);
270 if (0 == strcmp("Linux", uts.sysname))
272 /* Linux kernels 2.1.126 and earlier ignore the O_NOFOLLOW flag. */
273 return release >= 2.2; /* close enough */
275 else if (0 == strcmp("FreeBSD", uts.sysname))
277 /* FreeBSD 3.0-CURRENT and later support it */
278 return release >= 3.1;
282 /* Well, O_NOFOLLOW was defined, so we'll try to use it. */
283 return true;
285 #endif
289 /* Examine the predicate list for instances of -execdir or -okdir
290 * which have been terminated with '+' (build argument list) rather
291 * than ';' (singles only). If there are any, run them (this will
292 * have no effect if there are no arguments waiting).
294 static void
295 do_complete_pending_execdirs(struct predicate *p, int dirfd)
297 if (NULL == p)
298 return;
300 assert (state.execdirs_outstanding);
302 do_complete_pending_execdirs(p->pred_left, dirfd);
304 if (pred_is(p, pred_execdir) || pred_is(p, pred_okdir))
306 /* It's an exec-family predicate. p->args.exec_val is valid. */
307 if (p->args.exec_vec.multiple)
309 struct exec_val *execp = &p->args.exec_vec;
311 /* This one was terminated by '+' and so might have some
312 * left... Run it if necessary.
314 if (execp->state.todo)
316 /* There are not-yet-executed arguments. */
317 launch (&execp->ctl, &execp->state);
322 do_complete_pending_execdirs(p->pred_right, dirfd);
325 void
326 complete_pending_execdirs(int dirfd)
328 if (state.execdirs_outstanding)
330 do_complete_pending_execdirs(get_eval_tree(), dirfd);
331 state.execdirs_outstanding = false;
337 /* Examine the predicate list for instances of -exec which have been
338 * terminated with '+' (build argument list) rather than ';' (singles
339 * only). If there are any, run them (this will have no effect if
340 * there are no arguments waiting).
342 void
343 complete_pending_execs(struct predicate *p)
345 if (NULL == p)
346 return;
348 complete_pending_execs(p->pred_left);
350 /* It's an exec-family predicate then p->args.exec_val is valid
351 * and we can check it.
353 /* XXX: what about pred_ok() ? */
354 if (pred_is(p, pred_exec) && p->args.exec_vec.multiple)
356 struct exec_val *execp = &p->args.exec_vec;
358 /* This one was terminated by '+' and so might have some
359 * left... Run it if necessary. Set state.exit_status if
360 * there are any problems.
362 if (execp->state.todo)
364 /* There are not-yet-executed arguments. */
365 launch (&execp->ctl, &execp->state);
369 complete_pending_execs(p->pred_right);
372 static void
373 traverse_tree(struct predicate *tree,
374 void (*callback)(struct predicate*))
376 if (tree->pred_left)
377 traverse_tree(tree->pred_left, callback);
379 callback(tree);
381 if (tree->pred_right)
382 traverse_tree(tree->pred_right, callback);
385 static void
386 flush_and_close_output_files(struct predicate *p)
388 if (pred_is(p, pred_fprint)
389 || pred_is(p, pred_fprintf)
390 || pred_is(p, pred_fls)
391 || pred_is(p, pred_fprint0))
393 FILE *f = p->args.printf_vec.stream;
394 bool failed;
396 if (f == stdout || f == stderr)
397 failed = fflush(p->args.printf_vec.stream) == EOF;
398 else
399 failed = fclose(p->args.printf_vec.stream) == EOF;
401 if (failed)
402 nonfatal_file_error(p->args.printf_vec.filename);
404 else if (pred_is(p, pred_print))
406 if (fflush(p->args.printf_vec.stream) == EOF)
408 nonfatal_file_error(p->args.printf_vec.filename);
411 else if (pred_is(p, pred_ls) || pred_is(p, pred_print0))
413 if (fflush(stdout) == EOF)
415 /* XXX: migrate to printf_vec. */
416 nonfatal_file_error("standard output");
421 /* Complete any outstanding commands.
423 void
424 cleanup(void)
426 struct predicate *eval_tree = get_eval_tree();
427 if (eval_tree)
429 traverse_tree(eval_tree, complete_pending_execs);
430 complete_pending_execdirs(get_current_dirfd());
431 traverse_tree(eval_tree, flush_and_close_output_files);
435 /* Savannah bug #16378 manifests as an assertion failure in pred_type()
436 * when an NFS server returns st_mode with value 0 (of course the stat(2)
437 * system call is itself returning 0 in this case).
439 #undef DEBUG_SV_BUG_16378
440 #if defined DEBUG_SV_BUG_16378
441 static int hook_fstatat(int fd, const char *name, struct stat *p, int flags)
443 static int warned = 0;
445 if (!warned)
447 /* No use of _() here; no point asking translators to translate a debug msg */
448 error(0, 0,
449 "Warning: some debug code is enabled for Savannah bug #16378; "
450 "this should not occur in released versions of findutils!");
451 warned = 1;
454 if (0 == strcmp(name, "./mode0file")
455 || 0 == strcmp(name, "mode0file"))
457 time_t now = time(NULL);
458 long day = 86400;
460 p->st_rdev = 0;
461 p->st_dev = 0x300;
462 p->st_ino = 0;
463 p->st_mode = 0; /* SV bug #16378 */
464 p->st_nlink = 1;
465 p->st_uid = geteuid();
466 p->st_gid = 0;
467 p->st_size = 42;
468 p->st_blksize = 32768;
469 p->st_atime = now-1*day;
470 p->st_mtime = now-2*day;
471 p->st_ctime = now-3*day;
473 return 0;
475 return fstatat(fd, name, p, flags);
478 # undef fstatat
479 # define fstatat(fd,name,p,flags) hook_fstatat((fd),(name),(p),(flags))
480 #endif
483 static int
484 fallback_stat(const char *name, struct stat *p, int prev_rv)
486 /* Our original stat() call failed. Perhaps we can't follow a
487 * symbolic link. If that might be the problem, lstat() the link.
488 * Otherwise, admit defeat.
490 switch (errno)
492 case ENOENT:
493 case ENOTDIR:
494 if (options.debug_options & DebugStat)
495 fprintf(stderr, "fallback_stat(): stat(%s) failed; falling back on lstat()\n", name);
496 return fstatat(state.cwd_dir_fd, name, p, AT_SYMLINK_NOFOLLOW);
498 case EACCES:
499 case EIO:
500 case ELOOP:
501 case ENAMETOOLONG:
502 #ifdef EOVERFLOW
503 case EOVERFLOW: /* EOVERFLOW is not #defined on UNICOS. */
504 #endif
505 default:
506 return prev_rv;
511 /* optionh_stat() implements the stat operation when the -H option is
512 * in effect.
514 * If the item to be examined is a command-line argument, we follow
515 * symbolic links. If the stat() call fails on the command-line item,
516 * we fall back on the properties of the symbolic link.
518 * If the item to be examined is not a command-line argument, we
519 * examine the link itself.
521 int
522 optionh_stat(const char *name, struct stat *p)
524 if (AT_FDCWD != state.cwd_dir_fd)
525 assert (state.cwd_dir_fd >= 0);
526 set_stat_placeholders(p);
527 if (0 == state.curdepth)
529 /* This file is from the command line; deference the link (if it
530 * is a link).
532 int rv;
533 rv = fstatat(state.cwd_dir_fd, name, p, 0);
534 if (0 == rv)
535 return 0; /* success */
536 else
537 return fallback_stat(name, p, rv);
539 else
541 /* Not a file on the command line; do not dereference the link.
543 return fstatat(state.cwd_dir_fd, name, p, AT_SYMLINK_NOFOLLOW);
547 /* optionl_stat() implements the stat operation when the -L option is
548 * in effect. That option makes us examine the thing the symbolic
549 * link points to, not the symbolic link itself.
551 int
552 optionl_stat(const char *name, struct stat *p)
554 int rv;
555 if (AT_FDCWD != state.cwd_dir_fd)
556 assert (state.cwd_dir_fd >= 0);
558 set_stat_placeholders(p);
559 rv = fstatat(state.cwd_dir_fd, name, p, 0);
560 if (0 == rv)
561 return 0; /* normal case. */
562 else
563 return fallback_stat(name, p, rv);
566 /* optionp_stat() implements the stat operation when the -P option is
567 * in effect (this is also the default). That option makes us examine
568 * the symbolic link itself, not the thing it points to.
570 int
571 optionp_stat(const char *name, struct stat *p)
573 assert ((state.cwd_dir_fd >= 0) || (state.cwd_dir_fd==AT_FDCWD));
574 set_stat_placeholders(p);
575 return fstatat(state.cwd_dir_fd, name, p, AT_SYMLINK_NOFOLLOW);
579 static uintmax_t stat_count = 0u;
582 debug_stat (const char *file, struct stat *bufp)
584 ++stat_count;
585 fprintf (stderr, "debug_stat (%s)\n", file);
587 switch (options.symlink_handling)
589 case SYMLINK_ALWAYS_DEREF:
590 return optionl_stat(file, bufp);
591 case SYMLINK_DEREF_ARGSONLY:
592 return optionh_stat(file, bufp);
593 case SYMLINK_NEVER_DEREF:
594 return optionp_stat(file, bufp);
596 /*NOTREACHED*/
597 assert (0);
598 return -1;
603 following_links(void)
605 switch (options.symlink_handling)
607 case SYMLINK_ALWAYS_DEREF:
608 return 1;
609 case SYMLINK_DEREF_ARGSONLY:
610 return (state.curdepth == 0);
611 case SYMLINK_NEVER_DEREF:
612 default:
613 return 0;
618 /* Take a "mode" indicator and fill in the files of 'state'.
621 digest_mode(mode_t mode,
622 const char *pathname,
623 const char *name,
624 struct stat *pstat,
625 boolean leaf)
627 /* If we know the type of the directory entry, and it is not a
628 * symbolic link, we may be able to avoid a stat() or lstat() call.
630 if (mode)
632 if (S_ISLNK(mode) && following_links())
634 /* mode is wrong because we should have followed the symlink. */
635 if (get_statinfo(pathname, name, pstat) != 0)
636 return 0;
637 mode = state.type = pstat->st_mode;
638 state.have_type = true;
640 else
642 state.have_type = true;
643 pstat->st_mode = state.type = mode;
646 else
648 /* Mode is not yet known; may have to stat the file unless we
649 * can deduce that it is not a directory (which is all we need to
650 * know at this stage)
652 if (leaf)
654 state.have_stat = false;
655 state.have_type = false;;
656 state.type = 0;
658 else
660 if (get_statinfo(pathname, name, pstat) != 0)
661 return 0;
663 /* If -L is in effect and we are dealing with a symlink,
664 * st_mode is the mode of the pointed-to file, while mode is
665 * the mode of the directory entry (S_IFLNK). Hence now
666 * that we have the stat information, override "mode".
668 state.type = pstat->st_mode;
669 state.have_type = true;
673 /* success. */
674 return 1;
678 /* Return true if there are no predicates with no_default_print in
679 predicate list PRED, false if there are any.
680 Returns true if default print should be performed */
682 boolean
683 default_prints (struct predicate *pred)
685 while (pred != NULL)
687 if (pred->no_default_print)
688 return (false);
689 pred = pred->pred_next;
691 return (true);
694 boolean
695 looks_like_expression(const char *arg, boolean leading)
697 switch (arg[0])
699 case '-':
700 if (arg[1]) /* "-foo" is an expression. */
701 return true;
702 else
703 return false; /* Just "-" is a filename. */
704 break;
706 case ')':
707 case ',':
708 if (arg[1])
709 return false; /* )x and ,z are not expressions */
710 else
711 return !leading; /* A leading ) or , is not either */
713 /* ( and ! are part of an expression, but (2 and !foo are
714 * filenames.
716 case '!':
717 case '(':
718 if (arg[1])
719 return false;
720 else
721 return true;
723 default:
724 return false;
728 static void
729 process_debug_options(char *arg)
731 const char *p;
732 char *token_context = NULL;
733 const char delimiters[] = ",";
734 boolean empty = true;
735 size_t i;
737 p = strtok_r(arg, delimiters, &token_context);
738 while (p)
740 empty = false;
742 for (i=0; i<N_DEBUGASSOC; ++i)
744 if (0 == strcmp(debugassoc[i].name, p))
746 options.debug_options |= debugassoc[i].val;
747 break;
750 if (i >= N_DEBUGASSOC)
752 error(0, 0, _("Ignoring unrecognised debug flag %s"),
753 quotearg_n_style(0, options.err_quoting_style, arg));
755 p = strtok_r(NULL, delimiters, &token_context);
757 if (empty)
759 error(1, 0, _("Empty argument to the -D option."));
761 else if (options.debug_options & DebugHelp)
763 show_valid_debug_options(stdout, 1);
764 exit(0);
768 static void
769 process_optimisation_option(const char *arg)
771 if (0 == arg[0])
773 error(1, 0, _("The -O option must be immediately followed by a decimal integer"));
775 else
777 unsigned long opt_level;
778 char *end;
780 if (!isdigit( (unsigned char) arg[0] ))
782 error(1, 0, _("Please specify a decimal number immediately after -O"));
784 else
786 int prev_errno = errno;
787 errno = 0;
789 opt_level = strtoul(arg, &end, 10);
790 if ( (0==opt_level) && (end==arg) )
792 error(1, 0, _("Please specify a decimal number immediately after -O"));
794 else if (*end)
796 /* unwanted trailing characters. */
797 error(1, 0, _("Invalid optimisation level %s"), arg);
799 else if ( (ULONG_MAX==opt_level) && errno)
801 error(1, errno, _("Invalid optimisation level %s"), arg);
803 else if (opt_level > USHRT_MAX)
805 /* tricky to test, as on some platforms USHORT_MAX and ULONG_MAX
806 * can have the same value, though this is unusual.
808 error(1, 0, _("Optimisation level %lu is too high. "
809 "If you want to find files very quickly, "
810 "consider using GNU locate."),
811 opt_level);
813 else
815 options.optimisation_level = opt_level;
816 errno = prev_errno;
823 process_leading_options(int argc, char *argv[])
825 int i, end_of_leading_options;
827 for (i=1; (end_of_leading_options = i) < argc; ++i)
829 if (0 == strcmp("-H", argv[i]))
831 /* Meaning: dereference symbolic links on command line, but nowhere else. */
832 set_follow_state(SYMLINK_DEREF_ARGSONLY);
834 else if (0 == strcmp("-L", argv[i]))
836 /* Meaning: dereference all symbolic links. */
837 set_follow_state(SYMLINK_ALWAYS_DEREF);
839 else if (0 == strcmp("-P", argv[i]))
841 /* Meaning: never dereference symbolic links (default). */
842 set_follow_state(SYMLINK_NEVER_DEREF);
844 else if (0 == strcmp("--", argv[i]))
846 /* -- signifies the end of options. */
847 end_of_leading_options = i+1; /* Next time start with the next option */
848 break;
850 else if (0 == strcmp("-D", argv[i]))
852 process_debug_options(argv[i+1]);
853 ++i; /* skip the argument too. */
855 else if (0 == strncmp("-O", argv[i], 2))
857 process_optimisation_option(argv[i]+2);
859 else
861 /* Hmm, must be one of
862 * (a) A path name
863 * (b) A predicate
865 end_of_leading_options = i; /* Next time start with this option */
866 break;
869 return end_of_leading_options;
872 static struct timespec
873 now(void)
875 struct timespec retval;
876 struct timeval tv;
877 time_t t;
879 if (0 == gettimeofday(&tv, NULL))
881 retval.tv_sec = tv.tv_sec;
882 retval.tv_nsec = tv.tv_usec * 1000; /* convert unit from microseconds to nanoseconds */
883 return retval;
885 t = time(NULL);
886 assert (t != (time_t)-1);
887 retval.tv_sec = t;
888 retval.tv_nsec = 0;
889 return retval;
892 void
893 set_option_defaults(struct options *p)
895 /* We call check_nofollow() before setlocale() because the numbers
896 * for which we check (in the results of uname) definitiely have "."
897 * as the decimal point indicator even under locales for which that
898 * is not normally true. Hence atof() would do the wrong thing
899 * if we call it after setlocale().
901 #ifdef O_NOFOLLOW
902 p->open_nofollow_available = check_nofollow();
903 #else
904 p->open_nofollow_available = false;
905 #endif
907 p->regex_options = RE_SYNTAX_EMACS;
909 if (isatty(0))
911 p->warnings = true;
912 p->literal_control_chars = false;
914 else
916 p->warnings = false;
917 p->literal_control_chars = false; /* may change */
921 p->do_dir_first = true;
922 p->maxdepth = p->mindepth = -1;
923 p->start_time = now();
924 p->cur_day_start = p->start_time.tv_sec - DAYSECS;
925 p->full_days = false;
926 p->stay_on_filesystem = false;
927 p->ignore_readdir_race = false;
929 if (getenv("POSIXLY_CORRECT"))
930 p->output_block_size = 512;
931 else
932 p->output_block_size = 1024;
934 p->debug_options = 0uL;
935 p->optimisation_level = 0;
937 if (getenv("FIND_BLOCK_SIZE"))
939 error (1, 0, _("The environment variable FIND_BLOCK_SIZE is not supported, the only thing that affects the block size is the POSIXLY_CORRECT environment variable"));
942 #if LEAF_OPTIMISATION
943 /* The leaf optimisation is enabled. */
944 p->no_leaf_check = false;
945 #else
946 /* The leaf optimisation is disabled. */
947 p->no_leaf_check = true;
948 #endif
950 set_follow_state(SYMLINK_NEVER_DEREF); /* The default is equivalent to -P. */
952 p->err_quoting_style = locale_quoting_style;
956 /* get_start_dirfd
958 * Returns the fd for the directory we started in.
960 int get_start_dirfd(void)
962 return starting_desc;
965 /* apply_predicate
968 boolean
969 apply_predicate(const char *pathname, struct stat *stat_buf, struct predicate *p)
971 ++p->perf.visits;
973 if (p->need_stat || p->need_type)
975 /* We may need a stat here. */
976 if (get_info(pathname, stat_buf, p) != 0)
977 return false;
979 if ((p->pred_func)(pathname, stat_buf, p))
981 ++(p->perf.successes);
982 return true;
984 else
986 return false;
991 /* safely_quote_err_filename
994 const char *
995 safely_quote_err_filename (int n, char const *arg)
997 return quotearg_n_style (n, options.err_quoting_style, arg);
1000 /* report_file_err
1002 static void
1003 report_file_err(int exitval, int errno_value, const char *name)
1005 /* It is important that the errno value is passed in as a function
1006 * argument before we call safely_quote_err_filename(), because otherwise
1007 * we might find that safely_quote_err_filename() changes errno.
1009 if (state.exit_status < 1)
1010 state.exit_status = 1;
1012 error (exitval, errno_value, "%s", safely_quote_err_filename(0, name));
1015 /* fatal_file_error
1018 void
1019 fatal_file_error(const char *name)
1021 report_file_err(1, errno, name);
1022 /*NOTREACHED*/
1023 abort();
1026 void
1027 nonfatal_file_error(const char *name)
1029 report_file_err(0, errno, name);