diff --git a/ChangeLog b/ChangeLog index 149cfacfbb..cd96cbf69e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Nov 14 16:43:24 2009 Nobuyoshi Nakada + + * hash.c (ruby_setenv): get rid of crash in Solaris 8 and 10. + [ruby-core:26668] + Sat Nov 14 09:16:54 2009 Marc-Andre Lafortune * ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons diff --git a/hash.c b/hash.c index 2ae9a7dd2f..497eda918b 100644 --- a/hash.c +++ b/hash.c @@ -2011,7 +2011,18 @@ rb_env_path_tainted(void) return path_tainted; } -#if !defined(_WIN32) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV)) +#if defined(_WIN32) || (defined(HAVE_SETENV) && defined(HAVE_UNSETENV)) +#elif defined __sun__ +static int +in_origenv(const char *str) +{ + char **env; + for (env = origenviron; *env; ++env) { + if (*env == str) return 1; + } + return 0; +} +#else static int envix(const char *nam) { @@ -2057,6 +2068,21 @@ ruby_setenv(const char *name, const char *value) setenv(name,value,1); else unsetenv(name); +#elif defined __sun__ + size_t len = strlen(name); + char **env_ptr, *str; + for (env_ptr = GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) { + if (!strncmp(str, name, len) && str[len] == '=') { + if (!in_origenv(str)) free(str); + while ((env_ptr[0] = env_ptr[1]) != 0) env_ptr++; + break; + } + } + if (value) { + str = malloc(len += strlen(value) + 2); + snprintf(str, len, "%s=%s", name, value); + putenv(str); + } #else /* WIN32 */ size_t len; int i=envix(name); /* where does it go? */