1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
usa 2001-11-13 08:32:19 +00:00
parent e4d7dbf5a3
commit 462ad8f0bf
5 changed files with 140 additions and 27 deletions

View file

@ -1,3 +1,44 @@
Tue Nov 13 17:25:44 2001 Usaku Nakamura <usa@ruby-lang.org>
* 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.
Tue Nov 13 14:39:11 2001 WATANABE Tetsuya <tetsu@jpn.hp.com>
* signal.c (sighandle): should not re-register sighandler if

78
hash.c
View file

@ -853,10 +853,18 @@ rb_hash_update(hash1, hash2)
static int path_tainted = -1;
#ifndef NT
extern char **environ;
#endif
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 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;
}

View file

@ -38,7 +38,7 @@ AUTOCONF = autoconf
prefix = /usr
CFLAGS = -nologo -DNT=1 -Zi -MD -O2b2xg- -G5
CPPFLAGS = -I$(srcdir) -I$(srcdir)/missing
CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/missing -DLIBRUBY_SO=\"$(LIBRUBY_SO)\"
LDFLAGS = $(CFLAGS) -Fm
XLDFLAGS =
#EXTLIBS =

View file

@ -2524,14 +2524,16 @@ wait()
char *
win32_getenv(const char *name)
{
char *curitem = NULL; /* XXX threadead */
DWORD curlen = 0; /* XXX threadead */
static char *curitem = NULL;
static DWORD curlen = 0;
DWORD needlen;
curlen = 512;
curitem = ALLOC_N(char, curlen);
if (curitem == NULL || curlen == 0) {
curlen = 512;
curitem = ALLOC_N(char, curlen);
}
needlen = GetEnvironmentVariable(name,curitem,curlen);
needlen = GetEnvironmentVariable(name, curitem, curlen);
if (needlen != 0) {
while (needlen > curlen) {
REALLOC_N(curitem, char, needlen);
@ -2961,3 +2963,35 @@ VALUE win32_asynchronize(asynchronous_func_t func,
return val;
}
char **win32_get_environ(void)
{
char *envtop, *env;
char **myenvtop, **myenv;
int num;
envtop = GetEnvironmentStrings();
for (env = envtop, num = 0; *env; env += strlen(env) + 1)
if (*env != '=') num++;
myenvtop = ALLOC_N(char*, num + 1);
for (env = envtop, myenv = myenvtop; *env; env += strlen(env) + 1) {
if (*env != '=') {
*myenv = ALLOC_N(char, strlen(env) + 1);
strcpy(*myenv, env);
myenv++;
}
}
*myenv = NULL;
FreeEnvironmentStrings(envtop);
return myenvtop;
}
void win32_free_environ(char **env)
{
char **t = env;
while (*t) free(*t++);
free(env);
}

View file

@ -214,6 +214,8 @@ extern struct servent * mygetservbyname(char *, char *);
extern struct servent * mygetservbyport(int, char *);
extern char *win32_getenv(const char *);
extern int myrename(const char *, const char *);
extern char **win32_get_environ(void);
extern void win32_free_environ(char **);
extern int chown(const char *, int, int);
extern int link(char *, char *);