mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (init_env): get rid of alloca() for outer string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d6191738bc
commit
772acb9f1d
2 changed files with 20 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
|||
Fri Mar 12 07:25:16 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32/win32.c (init_env): get rid of alloca() for outer string.
|
||||
|
||||
Fri Mar 12 07:17:15 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/racc/cparse/cparse.c: suppressed warnings for shortening on
|
||||
|
|
|
@ -434,10 +434,18 @@ static void
|
|||
init_env(void)
|
||||
{
|
||||
static const WCHAR TMPDIR[] = L"TMPDIR";
|
||||
WCHAR env[_MAX_PATH];
|
||||
WCHAR *buf;
|
||||
struct {WCHAR name[6], eq, val[_MAX_PATH];} wk;
|
||||
DWORD len;
|
||||
BOOL f;
|
||||
#define env wk.val
|
||||
#define set_env_val(vname) do { \
|
||||
typedef char namesizecheck[numberof(wk.name) < numberof(vname) - 1 ? -1 : 1]; \
|
||||
WCHAR *const buf = wk.name + numberof(wk.name) - numberof(vname); \
|
||||
MEMCPY(buf, vname, WCHAR, numberof(vname) - 1); \
|
||||
_wputenv(buf); \
|
||||
} while (0)
|
||||
|
||||
wk.eq = L'=';
|
||||
|
||||
if (!GetEnvironmentVariableW(L"HOME", env, numberof(env))) {
|
||||
f = FALSE;
|
||||
|
@ -459,9 +467,7 @@ init_env(void)
|
|||
}
|
||||
if (f) {
|
||||
regulate_path(env);
|
||||
buf = ALLOCA_N(WCHAR, 5 + lstrlenW(env) + 1);
|
||||
wsprintfW(buf, L"HOME=%s", env);
|
||||
_wputenv(buf);
|
||||
set_env_val(L"HOME");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,9 +477,7 @@ init_env(void)
|
|||
NTLoginName = "<Unknown>";
|
||||
return;
|
||||
}
|
||||
buf = ALLOCA_N(WCHAR, 5 + lstrlenW(env) + 1);
|
||||
wsprintfW(buf, L"USER=%s", env);
|
||||
_wputenv(buf);
|
||||
set_env_val(L"USER");
|
||||
}
|
||||
NTLoginName = strdup(rb_w32_getenv("USER"));
|
||||
|
||||
|
@ -487,11 +491,12 @@ init_env(void)
|
|||
if (*(p - 1) != L'/') *p++ = L'/';
|
||||
if (p - env + numberof(temp) < numberof(env)) {
|
||||
memcpy(p, temp, sizeof(temp));
|
||||
buf = ALLOCA_N(WCHAR, lstrlenW(TMPDIR) + 1 + lstrlenW(env) + 1);
|
||||
wsprintfW(buf, L"%s=%s", TMPDIR, env);
|
||||
_wputenv(buf);
|
||||
set_env_val(TMPDIR);
|
||||
}
|
||||
}
|
||||
|
||||
#undef env
|
||||
#undef set_env_val
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue