From 67c697622f7b1123f99f5eb12f727ba3bef57122 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 Apr 2025 10:23:32 +0200 Subject: [PATCH] Make output on Windows identical to output on Unix. * src/options.cc (Options::print_options): Drop a ".exe" suffix from the program name before printing it. --- ChangeLog | 6 ++++++ src/options.cc | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90edd83..537c27d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-04-05 Bruno Haible + + Make output on Windows identical to output on Unix. + * src/options.cc (Options::print_options): Drop a ".exe" suffix from the + program name before printing it. + 2024-11-16 Bruno Haible Avoid "-Wzero-as-null-pointer-constant" warnings on the generated code. diff --git a/src/options.cc b/src/options.cc index 065339e..82b547d 100644 --- a/src/options.cc +++ b/src/options.cc @@ -1,5 +1,5 @@ /* Handles parsing the Options provided to the user. - Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009, 2011, 2016-2018, 2022-2023 Free Software Foundation, Inc. + Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009, 2011, 2016-2018, 2022-2023, 2025 Free Software Foundation, Inc. Written by Douglas C. Schmidt and Bruno Haible . @@ -279,16 +279,28 @@ Options::print_options () const for (int i = 0; i < _argument_count; i++) { - const char *arg = _argument_vector[i]; + char *arg = _argument_vector[i]; if (i == 0) { - /* _argument_vector[0] is the program name. Print only its base name. + /* _argument_vector[0] is the program name. Print only its base name, + and also drop its ".exe" suffix on native Windows. This is useful for reproducible builds. */ - const char *p = arg + strlen (arg); - while (p > arg && ! ISSLASH (p[-1])) - p--; - arg = p; + { + char *p = arg + strlen (arg); + while (p > arg && ! ISSLASH (p[-1])) + p--; + arg = p; + } + { + char *p = arg + strlen (arg); + if (p - arg > 4 + && p[-4] == '.' + && (p[-3] == 'E' || p[-3] == 'e') + && (p[-2] == 'X' || p[-2] == 'x') + && (p[-1] == 'E' || p[-1] == 'e')) + p[-4] = '\0'; + } } /* Escape arg if it contains shell metacharacters. */