diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-11-13 08:32:19 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-11-13 08:32:19 +0000 |
commit | 462ad8f0bf87c53383ddeffa08e1aa8146b388da (patch) | |
tree | d33cfc49b781aad50ab1b32b95318d94b4e95636 /hash.c | |
parent | e4d7dbf5a35c8e4ea0de3d50c331c0753a421b32 (diff) |
* hash.c (envix): merge from 1.7: 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): merge from 1.7: use static buffer.
* win32/win32.c, win32/win32.h (win32_get_environ): merge from 1.7:
get environment variables list.
* win32/win32.c, win32/win32.h (win32_free_environ): merge from 1.7:
free environment variables list.
* win32/Makefile.sub: merge from 1.7: add -DLIBRUBY_SO to CPPFLAGS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 76 |
1 files changed, 56 insertions, 20 deletions
@@ -853,10 +853,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) @@ -965,17 +973,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; } @@ -1150,7 +1161,7 @@ env_keys() char **env; VALUE ary = rb_ary_new(); - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { @@ -1158,6 +1169,7 @@ env_keys() } env++; } + FREE_ENVIRON(environ); return ary; } @@ -1167,7 +1179,7 @@ env_each_key(hash) { char **env; - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { @@ -1175,6 +1187,7 @@ env_each_key(hash) } env++; } + FREE_ENVIRON(environ); return Qnil; } @@ -1184,7 +1197,7 @@ env_values() char **env; VALUE ary = rb_ary_new(); - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { @@ -1192,6 +1205,7 @@ env_values() } env++; } + FREE_ENVIRON(environ); return ary; } @@ -1201,7 +1215,7 @@ env_each_value(hash) { char **env; - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { @@ -1209,6 +1223,7 @@ env_each_value(hash) } env++; } + FREE_ENVIRON(environ); return Qnil; } @@ -1218,7 +1233,7 @@ env_each(hash) { char **env; - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { @@ -1227,6 +1242,7 @@ env_each(hash) } env++; } + FREE_ENVIRON(environ); return Qnil; } @@ -1276,7 +1292,7 @@ env_inspect() VALUE str = rb_str_new2("{"); VALUE i; - env = environ; + env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); @@ -1292,6 +1308,7 @@ env_inspect() } env++; } + FREE_ENVIRON(environ); rb_str_cat2(str, "}"); OBJ_TAINT(str); @@ -1304,7 +1321,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) { @@ -1313,6 +1330,7 @@ env_to_a() } env++; } + FREE_ENVIRON(environ); return ary; } @@ -1326,16 +1344,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; } @@ -1355,15 +1383,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; } @@ -1372,18 +1403,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; } @@ -1418,7 +1453,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) { @@ -1427,6 +1462,7 @@ env_to_hash() } env++; } + FREE_ENVIRON(environ); return hash; } |