public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: globals: make __progname an alias of program_invocation_short_name Date: Thu, 1 Feb 2024 11:40:00 +0000 (GMT) [thread overview] Message-ID: <20240201114001.02F8538582B0@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b2476bc5232246278bc6a40e812785270bccb668 commit b2476bc5232246278bc6a40e812785270bccb668 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Wed Jan 31 15:21:31 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Wed Jan 31 20:11:58 2024 +0100 Cygwin: globals: make __progname an alias of program_invocation_short_name 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. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> 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 (); - /* Set up __progname for getopt error call. */ - if (__argv[0] && (__progname = strrchr (__argv[0], '/'))) - ++__progname; - else - __progname = __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 = __argv[0]; - program_invocation_short_name = __progname; - if (__progname) + if (__argv[0] && (program_invocation_short_name = strrchr (__argv[0], '/'))) + ++program_invocation_short_name; + else + program_invocation_short_name = __argv[0]; + if (program_invocation_short_name) { - char *cp = strchr (__progname, '\0') - 4; - if (cp > __progname && ascii_strcasematch (cp, ".exe")) + char *cp = strchr (program_invocation_short_name, '\0') - 4; + if (cp > program_invocation_short_name && ascii_strcasematch (cp, ".exe")) *cp = '\0'; } SetThreadName (GetCurrentThreadId (), program_invocation_short_name); diff --git a/winsup/cygwin/fhandler/serial.cc b/winsup/cygwin/fhandler/serial.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) 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 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 = {/* initial_sp */ 0, /* magic_biscuit */ 0, @@ -195,3 +195,5 @@ extern "C" { }; int NO_COPY __api_fatal_exit_val = 1; + +EXPORT_ALIAS (program_invocation_short_name, __progname) diff --git a/winsup/cygwin/scripts/mkglobals_h b/winsup/cygwin/scripts/mkglobals_h index 2d185f2e8abd..7521a03bfbd3 100755 --- a/winsup/cygwin/scripts/mkglobals_h +++ b/winsup/cygwin/scripts/mkglobals_h @@ -4,6 +4,7 @@ $_ = 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 char *infmt, va_list ap) { PWCHAR pn = NULL; WCHAR progname[NAME_MAX]; - if (cygwin_finished_initializing && __progname) + if (cygwin_finished_initializing && program_invocation_short_name) { - char *p = strrchr (__progname, '/'); + char *p = strrchr (program_invocation_short_name, '/'); if (p) ++p; else - p = __progname; + p = program_invocation_short_name; char *pe = strrchr (p, '.'); if (!pe || !ascii_strcasematch (pe, ".exe")) pe = strrchr (p, '\0');
reply other threads:[~2024-02-01 11:40 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240201114001.02F8538582B0@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).