]> sourceware.org Git - newlib-cygwin.git/commitdiff
* dcrt0.cc (dll_crt0_1): Copy argv before passing to main().
authorChristopher Faylor <me@cgf.cx>
Mon, 17 Oct 2011 18:25:04 +0000 (18:25 +0000)
committerChristopher Faylor <me@cgf.cx>
Mon, 17 Oct 2011 18:25:04 +0000 (18:25 +0000)
winsup/cygwin/ChangeLog
winsup/cygwin/dcrt0.cc

index d250182dc301b9b739104363518bc2d579b2fdc4..786c74258958708dc893ef7b06c67fbf6e2d9eff 100644 (file)
@@ -1,3 +1,7 @@
+2011-10-17  Christopher Faylor  <me.cygwin2011@cgf.cx>
+
+       * dcrt0.cc (dll_crt0_1): Copy argv before passing to main().
+
 2011-10-17  Christopher Faylor  <me.cygwin2011@cgf.cx>
 
        * sigproc.cc (proc_terminate): Avoid setting ppid to 1 if we're execing.
index f0980913f2e749c6b81263c95abc5e86aa0dcb76..dd3ff021c2cf466df2c17d3b9c7649698ec1ca68 100644 (file)
@@ -894,7 +894,18 @@ dll_crt0_1 (void *)
   _setlocale_r (_REENT, LC_CTYPE, "C");
 
   if (user_data->main)
-    cygwin_exit (user_data->main (__argc, __argv, *user_data->envptr));
+    {
+      /* Create a copy of Cygwin's version of __argv so that, if the user makes
+        a change to an element of argv[] it does not affect Cygwin's argv.
+        Changing the the contents of what argv[n] points to will still
+        affect Cygwin.  This is similar (but not exactly like) Linux. */
+      char *newargv[__argc + 1];
+      char **nav = newargv;
+      char **oav = __argv;
+      while ((*nav++ = *oav++) != NULL)
+       continue;
+      cygwin_exit (user_data->main (__argc, newargv, *user_data->envptr));
+    }
   __asm__ ("                           \n\
        .global __cygwin_exit_return    \n\
 __cygwin_exit_return:                  \n\
This page took 0.038306 seconds and 5 git commands to generate.