mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c (ENVMATCH, ENVNMATCH): reduced same code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
abf97237c4
commit
ab279b4085
2 changed files with 16 additions and 29 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Sep 23 16:59:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* hash.c (ENVMATCH, ENVNMATCH): reduced same code.
|
||||||
|
|
||||||
Tue Sep 23 16:55:11 2008 Koichi Sasada <ko1@atdot.net>
|
Tue Sep 23 16:55:11 2008 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* ruby.h: fix comment and rename macro HAVE_RUBY_MVM_H to
|
* ruby.h: fix comment and rename macro HAVE_RUBY_MVM_H to
|
||||||
|
|
41
hash.c
41
hash.c
|
@ -1799,6 +1799,13 @@ extern char **environ;
|
||||||
#define GET_ENVIRON(e) (e)
|
#define GET_ENVIRON(e) (e)
|
||||||
#define FREE_ENVIRON(e)
|
#define FREE_ENVIRON(e)
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENV_IGNORECASE
|
||||||
|
#define ENVMATCH(s1, s2) (STRCASECMP(s1, s2) == 0)
|
||||||
|
#define ENVNMATCH(s1, s2, n) (STRNCASECMP(s1, s2, n) == 0)
|
||||||
|
#else
|
||||||
|
#define ENVMATCH(n1, n2) (strcmp(n1, n2) == 0)
|
||||||
|
#define ENVNMATCH(s1, s2, n) (memcmp(s1, s2, n) == 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
env_str_new(const char *ptr, long len)
|
env_str_new(const char *ptr, long len)
|
||||||
|
@ -1832,12 +1839,7 @@ env_delete(VALUE obj, VALUE name)
|
||||||
VALUE value = env_str_new2(val);
|
VALUE value = env_str_new2(val);
|
||||||
|
|
||||||
ruby_setenv(nam, 0);
|
ruby_setenv(nam, 0);
|
||||||
#ifdef ENV_IGNORECASE
|
if (ENVMATCH(nam, PATH_ENV)) {
|
||||||
if (STRCASECMP(nam, PATH_ENV) == 0)
|
|
||||||
#else
|
|
||||||
if (strcmp(nam, PATH_ENV) == 0)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
path_tainted = 0;
|
path_tainted = 0;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -1868,12 +1870,7 @@ rb_f_getenv(VALUE obj, VALUE name)
|
||||||
}
|
}
|
||||||
env = getenv(nam);
|
env = getenv(nam);
|
||||||
if (env) {
|
if (env) {
|
||||||
#ifdef ENV_IGNORECASE
|
if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted()) {
|
||||||
if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
|
|
||||||
#else
|
|
||||||
if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
VALUE str = rb_str_new2(env);
|
VALUE str = rb_str_new2(env);
|
||||||
|
|
||||||
rb_obj_freeze(str);
|
rb_obj_freeze(str);
|
||||||
|
@ -1910,11 +1907,7 @@ env_fetch(int argc, VALUE *argv)
|
||||||
}
|
}
|
||||||
return if_none;
|
return if_none;
|
||||||
}
|
}
|
||||||
#ifdef ENV_IGNORECASE
|
if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted())
|
||||||
if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
|
|
||||||
#else
|
|
||||||
if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
|
|
||||||
#endif
|
|
||||||
return rb_str_new2(env);
|
return rb_str_new2(env);
|
||||||
return env_str_new2(env);
|
return env_str_new2(env);
|
||||||
}
|
}
|
||||||
|
@ -1943,13 +1936,7 @@ envix(const char *nam)
|
||||||
|
|
||||||
env = GET_ENVIRON(environ);
|
env = GET_ENVIRON(environ);
|
||||||
for (i = 0; env[i]; i++) {
|
for (i = 0; env[i]; i++) {
|
||||||
if (
|
if (ENVNMATCH(env[i],nam,len) && env[i][len] == '=')
|
||||||
#ifdef ENV_IGNORECASE
|
|
||||||
STRNCASECMP(env[i],nam,len) == 0
|
|
||||||
#else
|
|
||||||
memcmp(env[i],nam,len) == 0
|
|
||||||
#endif
|
|
||||||
&& env[i][len] == '=')
|
|
||||||
break; /* memcmp must come first to avoid */
|
break; /* memcmp must come first to avoid */
|
||||||
} /* potential SEGV's */
|
} /* potential SEGV's */
|
||||||
FREE_ENVIRON(environ);
|
FREE_ENVIRON(environ);
|
||||||
|
@ -2066,11 +2053,7 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
|
||||||
rb_raise(rb_eArgError, "bad environment variable value");
|
rb_raise(rb_eArgError, "bad environment variable value");
|
||||||
|
|
||||||
ruby_setenv(name, value);
|
ruby_setenv(name, value);
|
||||||
#ifdef ENV_IGNORECASE
|
if (ENVMATCH(name, PATH_ENV)) {
|
||||||
if (STRCASECMP(name, PATH_ENV) == 0) {
|
|
||||||
#else
|
|
||||||
if (strcmp(name, PATH_ENV) == 0) {
|
|
||||||
#endif
|
|
||||||
if (OBJ_TAINTED(val)) {
|
if (OBJ_TAINTED(val)) {
|
||||||
/* already tainted, no check */
|
/* already tainted, no check */
|
||||||
path_tainted = 1;
|
path_tainted = 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue