diff options
author | Christopher Faylor <me+cygwin@cgf.cx> | 2005-11-28 01:17:59 +0000 |
---|---|---|
committer | Christopher Faylor <me+cygwin@cgf.cx> | 2005-11-28 01:17:59 +0000 |
commit | 8efc5725eb84b670b83d0d1b1c954d1b205cf018 (patch) | |
tree | c805fc3a786e27dca6e5bf252a51007e8f855518 /gdb/windows-nat.c | |
parent | dae0677673a4b077e57051bdb7d705419e1d062b (diff) | |
download | gdb-8efc5725eb84b670b83d0d1b1c954d1b205cf018.zip gdb-8efc5725eb84b670b83d0d1b1c954d1b205cf018.tar.gz gdb-8efc5725eb84b670b83d0d1b1c954d1b205cf018.tar.bz2 |
* 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.
Diffstat (limited to 'gdb/windows-nat.c')
-rw-r--r-- | gdb/windows-nat.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 81c115f..ee40a7e 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -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) { |