mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c (ruby_setenv): Fix TestEnv#test_aset failure on Solaris 9.
When name contains '=', ruby_setenv raises Errno::EINVAL. That is the same behavior as Solaris 10. NULL check for malloc return value is also added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
813ad48975
commit
90b1b2e607
2 changed files with 28 additions and 5 deletions
|
@ -1,3 +1,10 @@
|
|||
Thu Jul 10 23:51:36 2014 Naohisa Goto <ngotogenome@gmail.com>
|
||||
|
||||
* hash.c (ruby_setenv): Fix TestEnv#test_aset failure on Solaris 9.
|
||||
When name contains '=', ruby_setenv raises Errno::EINVAL.
|
||||
That is the same behavior as Solaris 10.
|
||||
NULL check for malloc return value is also added.
|
||||
|
||||
Thu Jul 10 15:02:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack
|
||||
|
|
26
hash.c
26
hash.c
|
@ -2729,6 +2729,10 @@ getenvblocksize()
|
|||
{
|
||||
return (rb_w32_osver() >= 5) ? 32767 : 5120;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || \
|
||||
(defined(__sun) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV)))
|
||||
|
||||
NORETURN(static void invalid_envname(const char *name));
|
||||
|
||||
|
@ -2798,10 +2802,22 @@ ruby_setenv(const char *name, const char *value)
|
|||
#endif
|
||||
}
|
||||
#elif defined __sun
|
||||
size_t len;
|
||||
char **env_ptr, *str;
|
||||
/* Solaris 9 (or earlier) does not have setenv(3C) and unsetenv(3C). */
|
||||
/* The below code was tested on Solaris 10 by:
|
||||
% ./configure ac_cv_func_setenv=no ac_cv_func_unsetenv=no
|
||||
*/
|
||||
size_t len, mem_size;
|
||||
char **env_ptr, *str, *mem_ptr;
|
||||
|
||||
check_envname(name);
|
||||
len = strlen(name);
|
||||
if (value) {
|
||||
mem_size = len + strlen(value) + 2;
|
||||
mem_ptr = malloc(mem_size);
|
||||
if (mem_ptr == NULL)
|
||||
rb_sys_fail_str(rb_sprintf("malloc("PRIuSIZE")", mem_size));
|
||||
snprintf(mem_ptr, mem_size, "%s=%s", name, value);
|
||||
}
|
||||
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);
|
||||
|
@ -2810,11 +2826,11 @@ ruby_setenv(const char *name, const char *value)
|
|||
}
|
||||
}
|
||||
if (value) {
|
||||
str = malloc(len += strlen(value) + 2);
|
||||
snprintf(str, len, "%s=%s", name, value);
|
||||
if (putenv(str))
|
||||
if (putenv(mem_ptr)) {
|
||||
free(mem_ptr);
|
||||
rb_sys_fail_str(rb_sprintf("putenv(%s)", name));
|
||||
}
|
||||
}
|
||||
#else /* WIN32 */
|
||||
size_t len;
|
||||
int i;
|
||||
|
|
Loading…
Reference in a new issue