summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-13 03:59:20 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-13 03:59:20 +0000
commitc5ca1bc929a933daefabab9f1be18c5653c7927d (patch)
treec55e138e7bee2e44f31c2499257a1376a812d2ed /hash.c
parent8fed738ffa538c10c424664466cb8b66ccf5ce1e (diff)
* hash.c (envix): use GET_ENVIRON and FREE_ENVIRON to get environment
variables list. * hash.c (env_keys): ditto. * hash.c (env_each_key): ditto. * hash.c (env_values): ditto. * hash.c (env_keys): ditto. * hash.c (env_each_value): ditto. * hash.c (env_each): ditto. * hash.c (env_inspect): ditto. * hash.c (env_to_a): ditto. * hash.c (env_size): ditto. * hash.c (env_empty_p): ditto. * hash.c (env_has_value): ditto. * hash.c (env_index): ditto. * hash.c (env_to_hash): ditto. * win32/win32.c (win32_getenv): use static buffer. * win32/win32.c, win32/win32.h (win32_get_environ): get environment variables list. [new] * win32/win32.c, win32/win32.h (win32_free_environ): free environment variables list. [new] * win32/win32.c (do_spawn): use CreateChild() instead of calling CreateProcess() directly. Original patches comes from Patrick Cheng. * win32/win32.c (mypopen): ditto. * win32/win32.c (mypclose): use rb_syswait() instead of waiting in this function. * win32/win32.c (waitpid): use wait_child() instead of _cwait(). * win32/win32.c (CreateChild): added. [new] * win32/win32.c (wait_child): added. [new] * win32/win32.c (FindFirstChildSlot): added. [new] * win32/win32.c (FindChildSlot): added. [new] * win32/win32.c (FindPipedChildSlot): added. [new] * win32/win32.c (CloseChildHandle): added. [new] * win32/win32.c (FindFreeChildSlot): added. [new] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c76
1 files changed, 56 insertions, 20 deletions
diff --git a/hash.c b/hash.c
index 7eb519b8b2..3ca5f88927 100644
--- a/hash.c
+++ b/hash.c
@@ -843,10 +843,18 @@ rb_hash_update(hash1, hash2)
static int path_tainted = -1;
-#ifndef NT
+static char **origenviron;
+#ifdef NT
+#define GET_ENVIRON(e) (e = win32_get_environ())
+#define FREE_ENVIRON(e) win32_free_environ(e)
+static char **my_environ;
+#undef environ
+#define environ my_environ
+#else
extern char **environ;
+#define GET_ENVIRON(e) (e)
+#define FREE_ENVIRON(e)
#endif
-static char **origenviron;
static VALUE
env_delete(obj, name)
@@ -955,17 +963,20 @@ envix(nam)
char *nam;
{
register int i, len = strlen(nam);
+ char **env;
- for (i = 0; environ[i]; i++) {
+ env = GET_ENVIRON(environ);
+ for (i = 0; env[i]; i++) {
if (
#ifdef WIN32
- strnicmp(environ[i],nam,len) == 0
+ strnicmp(env[i],nam,len) == 0
#else
- memcmp(environ[i],nam,len) == 0
+ memcmp(env[i],nam,len) == 0
#endif
- && environ[i][len] == '=')
+ && env[i][len] == '=')
break; /* memcmp must come first to avoid */
} /* potential SEGV's */
+ FREE_ENVIRON(environ);
return i;
}
@@ -1141,7 +1152,7 @@ env_keys()
char **env;
VALUE ary = rb_ary_new();
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1149,6 +1160,7 @@ env_keys()
}
env++;
}
+ FREE_ENVIRON(environ);
return ary;
}
@@ -1158,7 +1170,7 @@ env_each_key(hash)
{
char **env;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1166,6 +1178,7 @@ env_each_key(hash)
}
env++;
}
+ FREE_ENVIRON(environ);
return Qnil;
}
@@ -1175,7 +1188,7 @@ env_values()
char **env;
VALUE ary = rb_ary_new();
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1183,6 +1196,7 @@ env_values()
}
env++;
}
+ FREE_ENVIRON(environ);
return ary;
}
@@ -1192,7 +1206,7 @@ env_each_value(hash)
{
char **env;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1200,6 +1214,7 @@ env_each_value(hash)
}
env++;
}
+ FREE_ENVIRON(environ);
return Qnil;
}
@@ -1209,7 +1224,7 @@ env_each(hash)
{
char **env;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1218,6 +1233,7 @@ env_each(hash)
}
env++;
}
+ FREE_ENVIRON(environ);
return Qnil;
}
@@ -1267,7 +1283,7 @@ env_inspect()
VALUE str = rb_str_buf_new2("{");
VALUE i;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -1283,6 +1299,7 @@ env_inspect()
}
env++;
}
+ FREE_ENVIRON(environ);
rb_str_buf_cat2(str, "}");
OBJ_TAINT(str);
@@ -1295,7 +1312,7 @@ env_to_a()
char **env;
VALUE ary = rb_ary_new();
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1304,6 +1321,7 @@ env_to_a()
}
env++;
}
+ FREE_ENVIRON(environ);
return ary;
}
@@ -1317,16 +1335,26 @@ static VALUE
env_size()
{
int i;
+ char **env;
- for(i=0; environ[i]; i++)
+ env = GET_ENVIRON(environ);
+ for(i=0; env[i]; i++)
;
+ FREE_ENVIRON(environ);
return INT2FIX(i);
}
static VALUE
env_empty_p()
{
- if (environ[0] == 0) return Qtrue;
+ char **env;
+
+ env = GET_ENVIRON(environ);
+ if (env[0] == 0) {
+ FREE_ENVIRON(environ);
+ return Qtrue;
+ }
+ FREE_ENVIRON(environ);
return Qfalse;
}
@@ -1350,15 +1378,18 @@ env_has_value(dmy, value)
char **env;
if (TYPE(value) != T_STRING) return Qfalse;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=')+1;
if (s) {
- if (strncmp(s, RSTRING(value)->ptr, strlen(s)) == 0)
+ if (strncmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
+ FREE_ENVIRON(environ);
return Qtrue;
+ }
}
env++;
}
+ FREE_ENVIRON(environ);
return Qfalse;
}
@@ -1367,18 +1398,22 @@ env_index(dmy, value)
VALUE dmy, value;
{
char **env;
+ VALUE str;
if (TYPE(value) != T_STRING) return Qnil;
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=')+1;
if (s) {
if (strncmp(s, RSTRING(value)->ptr, strlen(s)) == 0) {
- return rb_tainted_str_new(*env, s-*env-1);
+ str = rb_tainted_str_new(*env, s-*env-1);
+ FREE_ENVIRON(environ);
+ return str;
}
}
env++;
}
+ FREE_ENVIRON(environ);
return Qnil;
}
@@ -1413,7 +1448,7 @@ env_to_hash()
char **env;
VALUE hash = rb_hash_new();
- env = environ;
+ env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s) {
@@ -1422,6 +1457,7 @@ env_to_hash()
}
env++;
}
+ FREE_ENVIRON(environ);
return hash;
}