[PATCH v2 3/3] ar/objcopy: harmonize .exe suffix stripping

Jan Beulich jbeulich@suse.com
Fri Mar 28 09:35:44 GMT 2025


With it only being the tail of the name which wants checking, using
lbasename() isn't helpful. Mirror what objcopy.c:main() does to ar.c,
merely chaning the plain int of the local variable to size_t.
---
Keying this to HAVE_DOS_BASED_FILE_SYSTEM looks questionable to me,
though: What file system we're on doesn't matter for what the
extension for executables is. $(EXEEXT) as use in the Makefile would
rather want communicating to the compiler, I think. Yet then all of this
is going to be useful only to people who bother fiddling with Makefile
to re-enable the objcopy-with-strip and ar-with-ranlib logic.
---
v2: New.

--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -740,13 +740,18 @@ main (int argc, char **argv)
 #ifndef is_ranlib
   if (is_ranlib < 0)
     {
-      const char *temp = lbasename (program_name);
+      size_t l = strlen (program_name);
 
-      if (strlen (temp) >= 6
-	  && FILENAME_CMP (temp + strlen (temp) - 6, "ranlib") == 0)
-	is_ranlib = 1;
-      else
-	is_ranlib = 0;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      /* Drop the .exe suffix, if any.  */
+      if (l > 4 && FILENAME_CMP (program_name + l - 4, ".exe") == 0)
+	{
+	  l -= 4;
+	  program_name[l] = '\0';
+	}
+#endif
+      is_ranlib = (l >= 6 &&
+		   FILENAME_CMP (program_name + l - 6, "ranlib") == 0);
     }
 #endif
 
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -6227,7 +6227,8 @@ main (int argc, char *argv[])
 #ifndef is_strip
   if (is_strip < 0)
     {
-      int i = strlen (program_name);
+      size_t i = strlen (program_name);
+
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
       /* Drop the .exe suffix, if any.  */
       if (i > 4 && FILENAME_CMP (program_name + i - 4, ".exe") == 0)



More information about the Binutils mailing list