[v6,3/4] for_each_path: Pass to callback whether dir is machine-disambiguated

Message ID 20260111215359.1464516-4-git@JohnEricson.me
State New
Headers
Series [v6,1/4] find_a_program: Separate from find_a_file |

Commit Message

John Ericson Jan. 11, 2026, 9:12 p.m. UTC
  We will use this in the subsequent patch to control what filenames we
search for.

gcc/ChangeLog:

	* gcc.cc (for_each_path): Pass an additional boolean argument to
	the callback specifying whether the current directly being
	searched is machine-specific, as described above.
	(build_search_list): Add unused parameter to lambda match new
	callback type.
	(find_a_file): Add unused parameter to lambda match new callback
	type.
	(find_a_program): Add unused parameter to lambda match new
	callback type.
	(spec_path::operator()): Add unused parameter to match new
	callback type.

Signed-off-by: John Ericson <git@JohnEricson.me>
---
 gcc/gcc.cc | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
  

Patch

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 038056c0722..01d423c9be1 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -2814,7 +2814,7 @@  for_each_path (const struct path_prefix *paths,
   const char *multi_suffix;
   const char *just_multi_suffix;
   char *path = NULL;
-  decltype (callback (nullptr)) ret = nullptr;
+  decltype (callback (nullptr, false)) ret = nullptr;
   bool skip_multi_dir = false;
   bool skip_multi_os_dir = false;
 
@@ -2865,7 +2865,7 @@  for_each_path (const struct path_prefix *paths,
 	  if (!skip_multi_dir)
 	    {
 	      memcpy (path + len, multi_suffix, suffix_len + 1);
-	      ret = callback (path);
+	      ret = callback (path, true);
 	      if (ret)
 		break;
 	    }
@@ -2876,7 +2876,7 @@  for_each_path (const struct path_prefix *paths,
 	      && pl->require_machine_suffix == 2)
 	    {
 	      memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
-	      ret = callback (path);
+	      ret = callback (path, true);
 	      if (ret)
 		break;
 	    }
@@ -2886,7 +2886,7 @@  for_each_path (const struct path_prefix *paths,
 	      && !pl->require_machine_suffix && multiarch_dir)
 	    {
 	      memcpy (path + len, multiarch_suffix, multiarch_len + 1);
-	      ret = callback (path);
+	      ret = callback (path, true);
 	      if (ret)
 		break;
 	    }
@@ -2914,7 +2914,7 @@  for_each_path (const struct path_prefix *paths,
 	      else
 		path[len] = '\0';
 
-	      ret = callback (path);
+	      ret = callback (path, false);
 	      if (ret)
 		break;
 	    }
@@ -2987,7 +2987,7 @@  build_search_list (const struct path_prefix *paths, const char *prefix,
   obstack_1grow (&collect_obstack, '=');
 
   /* Callback adds path to obstack being built.  */
-  for_each_path (paths, do_multi, 0, [&](char *path) -> void*
+  for_each_path (paths, do_multi, 0, [&](char *path, bool) -> void*
     {
       if (check_dir && !is_directory (path))
 	return NULL;
@@ -3061,7 +3061,7 @@  find_a_file (const struct path_prefix *pprefix, const char *name,
      to the file.  */
   return for_each_path (pprefix, do_multi,
 			name_len,
-			[=](char *path) -> char*
+			[=](char *path, bool) -> char*
     {
       memcpy (path + strlen (path), name, name_len + 1);
 
@@ -3119,7 +3119,7 @@  find_a_program (const char *name)
      to the file.  */
   return for_each_path (&exec_prefixes, false,
 			name_len + suffix_len,
-			[=](char *path) -> char*
+			[=](char *path, bool) -> char*
     {
       size_t len = strlen (path);
 
@@ -6051,11 +6051,11 @@  struct spec_path {
   bool separate_options;
   bool realpaths;
 
-  void *operator() (char *path);
+  void *operator() (char *path, bool);
 };
 
 void *
-spec_path::operator() (char *path)
+spec_path::operator() (char *path, bool)
 {
   size_t len = 0;
   char save = 0;