diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-16 06:20:23 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-16 06:20:23 +0000 |
commit | 3694f1dda70923b2acc66af6553c422ba87daddd (patch) | |
tree | 0d45296d39a940100f86a76f75a4a345312a78a7 /win32 | |
parent | 724f1f4a6e3698d1a34ca3442a6cb3e890e94a99 (diff) | |
download | ruby-3694f1dda70923b2acc66af6553c422ba87daddd.tar.gz |
* ext/tmpdir: split from lib/tmpdir.rb.
* win32/win32.c (rb_w32_system_tmpdir): extracted from init_env.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/win32/win32.c b/win32/win32.c index 8a348d849d..8216ac9918 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -430,6 +430,22 @@ get_system_directory(WCHAR *path, UINT len) #define numberof(array) (sizeof(array) / sizeof(*array)) +UINT +rb_w32_system_tmpdir(WCHAR *path, UINT len) +{ + static const WCHAR temp[] = L"temp"; + WCHAR *p; + + if (!get_special_folder(CSIDL_LOCAL_APPDATA, path)) { + if (get_system_directory(path, len)) return 0; + } + p = translate_wchar(path, L'\\', L'/'); + if (*(p - 1) != L'/') *p++ = L'/'; + if (p - path + numberof(temp) >= len) return 0; + memcpy(p, temp, sizeof(temp)); + return p - path + numberof(temp) - 1; +} + static void init_env(void) { @@ -484,15 +500,8 @@ init_env(void) if (!GetEnvironmentVariableW(TMPDIR, env, numberof(env)) && !GetEnvironmentVariableW(L"TMP", env, numberof(env)) && !GetEnvironmentVariableW(L"TEMP", env, numberof(env)) && - (get_special_folder(CSIDL_LOCAL_APPDATA, env) || - get_system_directory(env, numberof(env)))) { - static const WCHAR temp[] = L"temp"; - WCHAR *p = translate_wchar(env, L'\\', L'/'); - if (*(p - 1) != L'/') *p++ = L'/'; - if (p - env + numberof(temp) < numberof(env)) { - memcpy(p, temp, sizeof(temp)); - set_env_val(TMPDIR); - } + rb_w32_system_tmpdir(env, numberof(env))) { + set_env_val(TMPDIR); } #undef env |