summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-11 22:25:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-11 22:25:22 +0000
commit772acb9f1d17d603030cde5660b2ff8773297be5 (patch)
tree2ea11fba7b60b477cf348ffc6311cea2e1b23db0 /win32
parentd6191738bce48d9a7cee17f7033a2d1a8568ca73 (diff)
* 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
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 268c3c7480..46a2ce5016 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -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
}