Now that `find_a_program` and `find_a_file` have been separated, we don't need a mode parameter, because one is always doing `R_OK`, and the other is always doing `X_OK`.
This change also proves that some of the code I removed from `find_a_file` in the previous commit is actually dead. gcc/ChangeLog: * gcc.cc (find_a_file): No more mode parameter. (read_specs): Remove mode from find_a_file call. (struct file_at_path_info): NO more mode field. (file_at_path): Remove mode from find_a_file call. (program_at_path): Hardcode X_OK mode choice (find_a_program): Don't set removed mode field. (end_going_arg): Remove mode from find_a_file call. (find_file): Remove mode from find_a_file call. (driver::set_up_specs): Remove mode from find_a_file call. (include_spec_function): Remove mode from find_a_file call. Signed-off-by: John Ericson <g...@johnericson.me> --- gcc/gcc.cc | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 3e1e4bbd866..ca73aea90bd 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -387,7 +387,7 @@ static void xputenv (const char *); static void putenv_from_prefixes (const struct path_prefix *, const char *, bool); static int access_check (const char *, int); -static char *find_a_file (const struct path_prefix *, const char *, int, bool); +static char *find_a_file (const struct path_prefix *, const char *, bool); static char *find_a_program (const char *); static void add_prefix (struct path_prefix *, const char *, const char *, int, int, int); @@ -2424,7 +2424,7 @@ read_specs (const char *filename, bool main_p, bool user_p) "%td characters", p1 - buffer + 1); p[-2] = '\0'; - new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); + new_filename = find_a_file (&startfile_prefixes, p1, true); read_specs (new_filename ? new_filename : p1, false, user_p); continue; } @@ -2444,7 +2444,7 @@ read_specs (const char *filename, bool main_p, bool user_p) "%td characters", p1 - buffer + 1); p[-2] = '\0'; - new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); + new_filename = find_a_file (&startfile_prefixes, p1, true); if (new_filename) read_specs (new_filename, false, user_p); else if (verbose_flag) @@ -3031,7 +3031,6 @@ struct file_at_path_info { const char *suffix; int name_len; int suffix_len; - int mode; }; static void * @@ -3044,7 +3043,7 @@ file_at_path (char *path, void *data) len += info->name_len; path[len] = '\0'; - if (access_check (path, info->mode) == 0) + if (access_check (path, R_OK) == 0) return path; return NULL; @@ -3056,7 +3055,7 @@ file_at_path (char *path, void *data) Return 0 if not found, otherwise return its name, allocated with malloc. */ static char * -find_a_file (const struct path_prefix *pprefix, const char *name, int mode, +find_a_file (const struct path_prefix *pprefix, const char *name, bool do_multi) { struct file_at_path_info info; @@ -3065,7 +3064,7 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, if (IS_ABSOLUTE_PATH (name)) { - if (access (name, mode) == 0) + if (access (name, R_OK) == 0) return xstrdup (name); return NULL; @@ -3075,7 +3074,6 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, info.suffix = ""; info.name_len = strlen (info.name); info.suffix_len = 0; - info.mode = mode; return (char*) for_each_path (pprefix, do_multi, info.name_len, @@ -3100,12 +3098,12 @@ program_at_path (char *path, void *data) if (info->suffix_len) { memcpy (path + len, info->suffix, info->suffix_len + 1); - if (access_check (path, info->mode) == 0) + if (access_check (path, X_OK) == 0) return path; } path[len] = '\0'; - if (access_check (path, info->mode) == 0) + if (access_check (path, X_OK) == 0) return path; return NULL; @@ -3150,7 +3148,6 @@ find_a_program (const char *name) info.suffix = HOST_EXECUTABLE_SUFFIX; info.name_len = strlen (info.name); info.suffix_len = strlen (info.suffix); - info.mode = X_OK; return (char*) for_each_path ( &exec_prefixes, false, @@ -5802,7 +5799,7 @@ end_going_arg (void) string = find_file (string); if (this_is_linker_script) { - char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true); + char * full_script_path = find_a_file (&startfile_prefixes, string, true); if (full_script_path == NULL) { @@ -8109,7 +8106,7 @@ out: static const char * find_file (const char *name) { - char *newname = find_a_file (&startfile_prefixes, name, R_OK, true); + char *newname = find_a_file (&startfile_prefixes, name, true); return newname ? newname : name; } @@ -8535,7 +8532,7 @@ driver::set_up_specs () const accel_dir_suffix, dir_separator_str, NULL); just_machine_suffix = concat (spec_machine, dir_separator_str, NULL); - specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true); + specs_file = find_a_file (&startfile_prefixes, "specs", true); /* Read the specs file unless it is a default one. */ if (specs_file != 0 && strcmp (specs_file, "specs")) read_specs (specs_file, true, false); @@ -8679,7 +8676,7 @@ driver::set_up_specs () const for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next) { char *filename = find_a_file (&startfile_prefixes, uptr->filename, - R_OK, true); + true); read_specs (filename ? filename : uptr->filename, false, true); } @@ -9304,7 +9301,7 @@ driver::maybe_run_linker (const char *argv0) const #endif { char *temp_spec = find_a_file (&exec_prefixes, - LTOPLUGINSONAME, R_OK, + LTOPLUGINSONAME, false); if (!temp_spec) fatal_error (input_location, @@ -10791,7 +10788,7 @@ include_spec_function (int argc, const char **argv) if (argc != 1) abort (); - file = find_a_file (&startfile_prefixes, argv[0], R_OK, true); + file = find_a_file (&startfile_prefixes, argv[0], true); read_specs (file ? file : argv[0], false, false); return NULL; @@ -11228,12 +11225,12 @@ find_fortran_preinclude_file (int argc, const char **argv) NULL, 0, 0, 0); #endif - const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false); + const char *path = find_a_file (&include_prefixes, argv[1], false); if (path != NULL) result = concat (argv[0], path, NULL); else { - path = find_a_file (&prefixes, argv[1], R_OK, false); + path = find_a_file (&prefixes, argv[1], false); if (path != NULL) result = concat (argv[0], path, NULL); } -- 2.49.0