* win32-nat.c (env_sort): New function.
authorChristopher Faylor <me+cygwin@cgf.cx>
Mon, 28 Nov 2005 01:17:59 +0000 (01:17 +0000)
committerChristopher Faylor <me+cygwin@cgf.cx>
Mon, 28 Nov 2005 01:17:59 +0000 (01:17 +0000)
(win32_create_inferior): Rename env to in_env.  Sort environment before handing
it off to CreateProcess.
(win32_current_sos): Quiet a compiler warning.

gdb/ChangeLog
gdb/win32-nat.c
gdb/windows-nat.c

index 5b9ba2e..2246d8d 100644 (file)
@@ -1,3 +1,10 @@
+2005-11-27  Christopher Faylor  <cgf@timesys.com>
+
+       * win32-nat.c (env_sort): New function.
+       (win32_create_inferior): Rename env to in_env.  Sort environment before
+       handing it off to CreateProcess.
+       (win32_current_sos): Quiet a compiler warning.
+
 2005-11-25  Andrew Stubbs  <andrew.stubbs@st.com>
 
        * event-top.h (async_init_signals): Add SIGTERM handler.
index 81c115f..ee40a7e 100644 (file)
@@ -1697,13 +1697,22 @@ win32_open (char *arg, int from_tty)
   error (_("Use the \"run\" command to start a Unix child process."));
 }
 
+/* Function called by qsort to sort environment strings.  */
+static int
+env_sort (const void *a, const void *b)
+{     
+  const char **p = (const char **) a; 
+  const char **q = (const char **) b;
+  return strcasecmp (*p, *q);
+}
+
 /* Start an inferior win32 child process and sets inferior_ptid to its pid.
    EXEC_FILE is the file to run.
    ALLARGS is a string containing the arguments to the program.
    ENV is the environment vector to pass.  Errors reported with error().  */
 
 static void
-win32_create_inferior (char *exec_file, char *allargs, char **env,
+win32_create_inferior (char *exec_file, char *allargs, char **in_env,
                       int from_tty)
 {
   char *winenv;
@@ -1783,27 +1792,33 @@ win32_create_inferior (char *exec_file, char *allargs, char **env,
        strings (i.e. two nulls terminate the list).  */
 
     /* Get total size for env strings.  */
-    for (envlen = 0, i = 0; env[i] && *env[i]; i++)
+    for (envlen = 0, i = 0; in_env[i] && *in_env[i]; i++)
       {
        int j, len;
 
        for (j = 0; conv_path_names[j]; j++)
          {
            len = strlen (conv_path_names[j]);
-           if (strncmp (conv_path_names[j], env[i], len) == 0)
+           if (strncmp (conv_path_names[j], in_env[i], len) == 0)
              {
-               if (cygwin_posix_path_list_p (env[i] + len))
+               if (cygwin_posix_path_list_p (in_env[i] + len))
                  envlen += len
-                   + cygwin_posix_to_win32_path_list_buf_size (env[i] + len);
+                   + cygwin_posix_to_win32_path_list_buf_size (in_env[i] + len);
                else
-                 envlen += strlen (env[i]) + 1;
+                 envlen += strlen (in_env[i]) + 1;
                break;
              }
          }
        if (conv_path_names[j] == NULL)
-         envlen += strlen (env[i]) + 1;
+         envlen += strlen (in_env[i]) + 1;
       }
 
+    size_t envsize = sizeof (in_env[0]) * (i + 1);
+    char **env = (char **) alloca (envsize);
+    memcpy (env, in_env, envsize);
+    /* Windows programs expect the environment block to be sorted.  */
+    qsort (env, i, sizeof (char *), env_sort);
+
     winenv = alloca (envlen + 1);
 
     /* Copy env strings into new buffer.  */
@@ -2226,7 +2241,7 @@ win32_current_sos (void)
 {
   struct so_list *sop;
   struct so_list *start = NULL;
-  struct so_list *last;
+  struct so_list *last = NULL;
 
   if (!solib_start.next && core_bfd)
     {
index 81c115f..ee40a7e 100644 (file)
@@ -1697,13 +1697,22 @@ win32_open (char *arg, int from_tty)
   error (_("Use the \"run\" command to start a Unix child process."));
 }
 
+/* Function called by qsort to sort environment strings.  */
+static int
+env_sort (const void *a, const void *b)
+{     
+  const char **p = (const char **) a; 
+  const char **q = (const char **) b;
+  return strcasecmp (*p, *q);
+}
+
 /* Start an inferior win32 child process and sets inferior_ptid to its pid.
    EXEC_FILE is the file to run.
    ALLARGS is a string containing the arguments to the program.
    ENV is the environment vector to pass.  Errors reported with error().  */
 
 static void
-win32_create_inferior (char *exec_file, char *allargs, char **env,
+win32_create_inferior (char *exec_file, char *allargs, char **in_env,
                       int from_tty)
 {
   char *winenv;
@@ -1783,27 +1792,33 @@ win32_create_inferior (char *exec_file, char *allargs, char **env,
        strings (i.e. two nulls terminate the list).  */
 
     /* Get total size for env strings.  */
-    for (envlen = 0, i = 0; env[i] && *env[i]; i++)
+    for (envlen = 0, i = 0; in_env[i] && *in_env[i]; i++)
       {
        int j, len;
 
        for (j = 0; conv_path_names[j]; j++)
          {
            len = strlen (conv_path_names[j]);
-           if (strncmp (conv_path_names[j], env[i], len) == 0)
+           if (strncmp (conv_path_names[j], in_env[i], len) == 0)
              {
-               if (cygwin_posix_path_list_p (env[i] + len))
+               if (cygwin_posix_path_list_p (in_env[i] + len))
                  envlen += len
-                   + cygwin_posix_to_win32_path_list_buf_size (env[i] + len);
+                   + cygwin_posix_to_win32_path_list_buf_size (in_env[i] + len);
                else
-                 envlen += strlen (env[i]) + 1;
+                 envlen += strlen (in_env[i]) + 1;
                break;
              }
          }
        if (conv_path_names[j] == NULL)
-         envlen += strlen (env[i]) + 1;
+         envlen += strlen (in_env[i]) + 1;
       }
 
+    size_t envsize = sizeof (in_env[0]) * (i + 1);
+    char **env = (char **) alloca (envsize);
+    memcpy (env, in_env, envsize);
+    /* Windows programs expect the environment block to be sorted.  */
+    qsort (env, i, sizeof (char *), env_sort);
+
     winenv = alloca (envlen + 1);
 
     /* Copy env strings into new buffer.  */
@@ -2226,7 +2241,7 @@ win32_current_sos (void)
 {
   struct so_list *sop;
   struct so_list *start = NULL;
-  struct so_list *last;
+  struct so_list *last = NULL;
 
   if (!solib_start.next && core_bfd)
     {