From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 02F8538582B0; Thu, 1 Feb 2024 11:40:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02F8538582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706787601; bh=fZxry+aZL1jt3xJk5zNqaWzrmv93PoW/3zPPq95dOuE=; h=From:To:Subject:Date:From; b=p5C1iVquP91P/ON2TNdedXbY/l7yYIxfkCzUiRJEw0/O5RU566bZTHkpl5tlJ9lGA KINeBuAFkeqF3wn7cdJutoZIYudg3KwvHiFRqqRvMsbVgvHXm//RPa1f0a3uD+rtrt IOP+a6nX8WRRYOAJjFClEdDDZ6jSG7QMfPIGyK+s= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: globals: make __progname an alias of program_invocation_short_name X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: bded8091c438d18e1d259864d773891a747c7576 X-Git-Newrev: b2476bc5232246278bc6a40e812785270bccb668 Message-Id: <20240201114001.02F8538582B0@sourceware.org> Date: Thu, 1 Feb 2024 11:40:00 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Db2476bc5232= 246278bc6a40e812785270bccb668 commit b2476bc5232246278bc6a40e812785270bccb668 Author: Corinna Vinschen AuthorDate: Wed Jan 31 15:21:31 2024 +0100 Commit: Corinna Vinschen CommitDate: Wed Jan 31 20:11:58 2024 +0100 Cygwin: globals: make __progname an alias of program_invocation_short_n= ame =20 On Linux, __progname and program_invocation_short_name are just different exported names of the same string. Do the same in Cygwin. This requires to tweak the mkglobals_h so as not to touch the EXPORT_ALIAS expression. Also, use the base variable program_invocation_short_name throughout. __progname is just the export for getopt. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/dcrt0.cc | 18 +++++++++--------- winsup/cygwin/fhandler/serial.cc | 8 ++++---- winsup/cygwin/globals.cc | 8 +++++--- winsup/cygwin/scripts/mkglobals_h | 1 + winsup/cygwin/strace.cc | 6 +++--- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index fc1eec76a4a5..a40129c22232 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -924,17 +924,17 @@ dll_crt0_1 (void *) /* Set up standard fds in file descriptor table. */ cygheap->fdtab.stdio_init (); =20 - /* Set up __progname for getopt error call. */ - if (__argv[0] && (__progname =3D strrchr (__argv[0], '/'))) - ++__progname; - else - __progname =3D __argv[0]; + /* Set up program_invocation_name and program_invocation_short_name. + __progname is an export alias for program_invocation_short_name. */ program_invocation_name =3D __argv[0]; - program_invocation_short_name =3D __progname; - if (__progname) + if (__argv[0] && (program_invocation_short_name =3D strrchr (__argv[0], = '/'))) + ++program_invocation_short_name; + else + program_invocation_short_name =3D __argv[0]; + if (program_invocation_short_name) { - char *cp =3D strchr (__progname, '\0') - 4; - if (cp > __progname && ascii_strcasematch (cp, ".exe")) + char *cp =3D strchr (program_invocation_short_name, '\0') - 4; + if (cp > program_invocation_short_name && ascii_strcasematch (cp, ".= exe")) *cp =3D '\0'; } SetThreadName (GetCurrentThreadId (), program_invocation_short_name); diff --git a/winsup/cygwin/fhandler/serial.cc b/winsup/cygwin/fhandler/seri= al.cc index e04f8f263217..1f8db5a831a5 100644 --- a/winsup/cygwin/fhandler/serial.cc +++ b/winsup/cygwin/fhandler/serial.cc @@ -268,11 +268,11 @@ fhandler_serial::open (int flags, mode_t mode) =20 FIXME: This should only be done when explicitly opening the com port. It should not be reset if an fd is inherited. - Using __progname in this way, to determine how far along in the - initialization we are, is really a terrible kludge and should - be fixed ASAP. + Using program_invocation_short_name in this way, to determine how far + along in the initialization we are, is really a terrible kludge and + should be fixed ASAP. */ - if (reset_com && __progname) + if (reset_com && program_invocation_short_name) { DCB state; GetCommState (get_handle (), &state); diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index a94aa5694e2d..654b836c2890 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -149,10 +149,10 @@ extern "C" { #undef _ROU =20 char **environ; - /* __progname used in getopt error message */ - char *__progname; - char *program_invocation_name; + /* __progname used in getopt error message is an alias of + program_invocation_short_name. */ char *program_invocation_short_name; + char *program_invocation_name; static MTinterface _mtinterf; struct per_process __cygwin_user_data =3D {/* initial_sp */ 0, /* magic_biscuit */ 0, @@ -195,3 +195,5 @@ extern "C" { }; =20 int NO_COPY __api_fatal_exit_val =3D 1; + +EXPORT_ALIAS (program_invocation_short_name, __progname) diff --git a/winsup/cygwin/scripts/mkglobals_h b/winsup/cygwin/scripts/mkgl= obals_h index 2d185f2e8abd..7521a03bfbd3 100755 --- a/winsup/cygwin/scripts/mkglobals_h +++ b/winsup/cygwin/scripts/mkglobals_h @@ -4,6 +4,7 @@ $_ =3D join('', <>); s/\s+\n/\n/sog; s/\n[^\n]*!globals.h[^\n]*\n/\n/sog; s%/\*.*?\*/%%sog; +s/EXPORT_ALIAS.*\n//so; s/(enum\s.*?{.*?})/munge($1)/soge; s/^(\s*)([a-zA-Z_])/$1extern $2/mog; s/extern (extern|enum)/$1/sog; diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc index a1a55d1ecdba..0010a17c74a0 100644 --- a/winsup/cygwin/strace.cc +++ b/winsup/cygwin/strace.cc @@ -157,13 +157,13 @@ strace::vsprntf (char *buf, const char *func, const c= har *infmt, va_list ap) { PWCHAR pn =3D NULL; WCHAR progname[NAME_MAX]; - if (cygwin_finished_initializing && __progname) + if (cygwin_finished_initializing && program_invocation_short_name) { - char *p =3D strrchr (__progname, '/'); + char *p =3D strrchr (program_invocation_short_name, '/'); if (p) ++p; else - p =3D __progname; + p =3D program_invocation_short_name; char *pe =3D strrchr (p, '.'); if (!pe || !ascii_strcasematch (pe, ".exe")) pe =3D strrchr (p, '\0');