[binutils-gdb] ar/objcopy: harmonize .exe suffix stripping

Jan Beulich jbeulich@sourceware.org
Fri Apr 4 08:22:28 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cc0693d394692261e03651325c9ae986ae579296

commit cc0693d394692261e03651325c9ae986ae579296
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Apr 4 10:20:31 2025 +0200

    ar/objcopy: harmonize .exe suffix stripping
    
    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.

Diff:
---
 binutils/ar.c      | 17 +++++++++++------
 binutils/objcopy.c |  3 ++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/binutils/ar.c b/binutils/ar.c
index a61d572c0e0..de41c9e3dd1 100644
--- 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
 
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 1cc4fe4876f..5b4fa7c6110 100644
--- 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-cvs mailing list