summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-14 02:46:50 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-14 02:46:50 +0000
commitd4ad42a6f1fba9899b5e4cc2a286d959d1584a9d (patch)
tree67bc0fec1e85501b2c264d34ef8eabc7b2229ab0 /hash.c
parent25c243bf2f5e01e91a1e3ccf17fdeb1897623488 (diff)
merge revision(s) 25766:
* hash.c (ruby_setenv): get rid of crash in Solaris 8 and 10. [ruby-core:26668] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@26087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 5574476ff1..8086e22ef7 100644
--- a/hash.c
+++ b/hash.c
@@ -1947,7 +1947,19 @@ rb_env_path_tainted()
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;
@@ -2002,6 +2014,21 @@ ruby_setenv(name, 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? */