Skip to content

Commit

Permalink
* win32/win32.c (init_env): get rid of alloca() for outer string.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 11, 2010
1 parent d619173 commit 772acb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Mar 12 07:25:16 2010 Nobuyoshi Nakada <[email protected]>

* win32/win32.c (init_env): get rid of alloca() for outer string.

Fri Mar 12 07:17:15 2010 Nobuyoshi Nakada <[email protected]>

* ext/racc/cparse/cparse.c: suppressed warnings for shortening on
Expand Down
27 changes: 16 additions & 11 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}

Expand All @@ -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"));

Expand All @@ -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
}


Expand Down

0 comments on commit 772acb9

Please sign in to comment.