ruby-changes:13960
From: nobu <ko1@a...>
Date: Sat, 14 Nov 2009 16:43:48 +0900 (JST)
Subject: [ruby-changes:13960] Ruby:r25766 (ruby_1_8, trunk): * hash.c (ruby_setenv): get rid of crash in Solaris 8 and 10.
nobu 2009-11-14 16:43:26 +0900 (Sat, 14 Nov 2009) New Revision: 25766 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25766 Log: * hash.c (ruby_setenv): get rid of crash in Solaris 8 and 10. [ruby-core:26668] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/hash.c trunk/ChangeLog trunk/hash.c Index: ChangeLog =================================================================== --- ChangeLog (revision 25765) +++ ChangeLog (revision 25766) @@ -1,3 +1,8 @@ +Sat Nov 14 16:43:24 2009 Nobuyoshi Nakada <nobu@r...> + + * 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 <ruby-core@m...> * ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons Index: hash.c =================================================================== --- hash.c (revision 25765) +++ hash.c (revision 25766) @@ -2011,8 +2011,19 @@ 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) { register int i, len = strlen(nam); @@ -2057,6 +2068,21 @@ 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? */ Index: ruby_1_8/hash.c =================================================================== --- ruby_1_8/hash.c (revision 25765) +++ ruby_1_8/hash.c (revision 25766) @@ -2001,8 +2001,20 @@ 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(str) + const char *str; +{ + char **env; + for (env = origenviron; *env; ++env) { + if (*env == str) return 1; + } + return 0; +} +#else +static int envix(nam) const char *nam; { @@ -2050,6 +2062,21 @@ 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? */ Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 25765) +++ ruby_1_8/ChangeLog (revision 25766) @@ -1,3 +1,8 @@ +Sat Nov 14 16:43:24 2009 Nobuyoshi Nakada <nobu@r...> + + * hash.c (ruby_setenv): get rid of crash in Solaris 8 and 10. + [ruby-core:26668] + Sat Nov 14 04:07:06 2009 Hidetoshi NAGAI <nagai@a...> * ext/tk/lib/tk/variable.rb (TkVariable::coerce): fix bug on a -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/