]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: globals: make __progname an alias of program_invocation_short_name
authorCorinna Vinschen <corinna@vinschen.de>
Wed, 31 Jan 2024 14:21:31 +0000 (15:21 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 31 Jan 2024 19:11:58 +0000 (20:11 +0100)
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>
winsup/cygwin/dcrt0.cc
winsup/cygwin/fhandler/serial.cc
winsup/cygwin/globals.cc
winsup/cygwin/scripts/mkglobals_h
winsup/cygwin/strace.cc

index fc1eec76a4a5ffbf02c1600b439e232799d4121f..a40129c222328568a909a22ff5fe26def12a0746 100644 (file)
@@ -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);
index e04f8f26321765f7f898f0d106d4f630fc7b6960..1f8db5a831a5d88745203a46120014b3023af62e 100644 (file)
@@ -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);
index a94aa5694e2d68728342d60a94192b7b75eed603..654b836c289038ae5a48659717c8297641ceb287 100644 (file)
@@ -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)
index 2d185f2e8abd3ffc8a3a6f50a014484c64edc7bb..7521a03bfbd313930ad696c93d9ac3c8d355520f 100755 (executable)
@@ -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;
index a1a55d1ecdba69aeae2e819b39fe971d360962c0..0010a17c74a0d2b49bec88a2e8e943eafc431797 100644 (file)
@@ -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');
This page took 0.039647 seconds and 5 git commands to generate.