From: Jan Beulich Date: Fri, 4 Apr 2025 08:20:31 +0000 (+0200) Subject: ar/objcopy: harmonize .exe suffix stripping X-Git-Tag: binutils-2_45~970 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc0693d394692261e03651325c9ae986ae579296;p=thirdparty%2Fbinutils-gdb.git 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 --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)