int main(int argc, char *argv[]) { //On initialise la locale pour recuperer les erreurs de errno dans la langue adéquate */ locale = newlocale(LC_CTYPE_MASK|LC_NUMERIC_MASK|LC_TIME_MASK| LC_COLLATE_MASK|LC_MONETARY_MASK|LC_MESSAGES_MASK, "",(locale_t)0); if (locale == (locale_t)0) { return EXIT_FAILURE; } program_name = argv[0]; current_level = 0; stop_at_current_level = false; mindepth = -1; maxdepth = -1; sort = false; //On parse tous les arguments bool path = parse(argv, argc); //Si le chemin n'est pas donné on execute le programme sur le repertoire courant if(!path) process_top_path("."); else process_top_path(argv[1]); //On libere la memoire free_predicates(); freelocale(locale); return EXIT_SUCCESS; }
/* CAUTION: this is the entry point for the oldfind executable, which is not the binary that * will actually get installed. See ftsfind.c. */ int main (int argc, char **argv) { int i; int end_of_leading_options = 0; /* First arg after any -H/-L etc. */ struct predicate *eval_tree; if (argv[0]) set_program_name (argv[0]); else set_program_name ("find"); state.exit_status = 0; if (fd_leak_check_is_enabled ()) { remember_non_cloexec_fds (); } record_initial_cwd (); state.already_issued_stat_error_msg = false; state.shared_files = sharefile_init ("w"); if (NULL == state.shared_files) { error (EXIT_FAILURE, errno, _("Failed to initialize shared-file hash table")); } /* Set the option defaults before we do the locale * initialisation as check_nofollow () needs to be executed in the * POSIX locale. */ set_option_defaults (&options); #ifdef HAVE_SETLOCALE setlocale (LC_ALL, ""); #endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); if (atexit (close_stdin)) { error (EXIT_FAILURE, errno, _("The atexit library function failed")); } /* Check for -P, -H or -L options. */ end_of_leading_options = process_leading_options (argc, argv); if (options.debug_options & DebugStat) options.xstat = debug_stat; #ifdef DEBUG fprintf (stderr, "cur_day_start = %s", ctime (&options.cur_day_start)); #endif /* DEBUG */ /* state.cwd_dir_fd has to be initialized before we call build_expression_tree () * because command-line parsing may lead us to stat some files. */ state.cwd_dir_fd = AT_FDCWD; /* We are now processing the part of the "find" command line * after the -H/-L options (if any). */ eval_tree = build_expression_tree (argc, argv, end_of_leading_options); /* safely_chdir () needs to check that it has ended up in the right place. * To avoid bailing out when something gets automounted, it checks if * the target directory appears to have had a directory mounted on it as * we chdir ()ed. The problem with this is that in order to notice that * a file system was mounted, we would need to lstat () all the mount points. * That strategy loses if our machine is a client of a dead NFS server. * * Hence if safely_chdir () and wd_sanity_check () can manage without needing * to know the mounted device list, we do that. */ if (!options.open_nofollow_available) { #ifdef STAT_MOUNTPOINTS init_mounted_dev_list (0); #endif } set_stat_placeholders (&starting_stat_buf); if ((*options.xstat) (".", &starting_stat_buf) != 0) error (EXIT_FAILURE, errno, _("cannot stat current directory")); /* If no paths are given, default to ".". */ for (i = end_of_leading_options; i < argc && !looks_like_expression (argv[i], true); i++) { process_top_path (argv[i], 0, starting_stat_buf.st_ino); } /* If there were no path arguments, default to ".". */ if (i == end_of_leading_options) { /* * We use a temporary variable here because some actions modify * the path temporarily. Hence if we use a string constant, * we get a coredump. The best example of this is if we say * "find -printf %H" (note, not "find . -printf %H"). */ char defaultpath[2] = "."; process_top_path (defaultpath, 0, starting_stat_buf.st_ino); } /* If "-exec ... {} +" has been used, there may be some * partially-full command lines which have been built, * but which are not yet complete. Execute those now. */ show_success_rates (eval_tree); cleanup (); return state.exit_status; }