mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (init_env): keeps wide chars as wide chars.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
033bed37c8
commit
a8c4a7e44c
2 changed files with 41 additions and 20 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Mon Mar 2 12:22:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (init_env): keeps wide chars as wide chars.
|
||||||
|
|
||||||
Mon Mar 2 11:01:45 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Mar 2 11:01:45 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/dl/dl.h (dlerror): fixed on Windows.
|
* ext/dl/dl.h (dlerror): fixed on Windows.
|
||||||
|
|
|
@ -350,6 +350,16 @@ flock(int fd, int oper)
|
||||||
(DWORD)-1);
|
(DWORD)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline WCHAR *
|
||||||
|
translate_wchar(WCHAR *p, int from, int to)
|
||||||
|
{
|
||||||
|
for (; *p; p++) {
|
||||||
|
if (*p == from)
|
||||||
|
*p = to;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
static inline char *
|
static inline char *
|
||||||
translate_char(char *p, int from, int to)
|
translate_char(char *p, int from, int to)
|
||||||
{
|
{
|
||||||
|
@ -366,13 +376,13 @@ translate_char(char *p, int from, int to)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
get_special_folder(int n, char *env)
|
get_special_folder(int n, WCHAR *env)
|
||||||
{
|
{
|
||||||
LPITEMIDLIST pidl;
|
LPITEMIDLIST pidl;
|
||||||
LPMALLOC alloc;
|
LPMALLOC alloc;
|
||||||
BOOL f = FALSE;
|
BOOL f = FALSE;
|
||||||
if (SHGetSpecialFolderLocation(NULL, n, &pidl) == 0) {
|
if (SHGetSpecialFolderLocation(NULL, n, &pidl) == 0) {
|
||||||
f = SHGetPathFromIDList(pidl, env);
|
f = SHGetPathFromIDListW(pidl, env);
|
||||||
SHGetMalloc(&alloc);
|
SHGetMalloc(&alloc);
|
||||||
alloc->lpVtbl->Free(alloc, pidl);
|
alloc->lpVtbl->Free(alloc, pidl);
|
||||||
alloc->lpVtbl->Release(alloc);
|
alloc->lpVtbl->Release(alloc);
|
||||||
|
@ -380,23 +390,35 @@ get_special_folder(int n, char *env)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
regulate_path(WCHAR *path)
|
||||||
|
{
|
||||||
|
WCHAR *p = translate_wchar(path, L'\\', L'/');
|
||||||
|
if (p - path == 2 && path[1] == L':') {
|
||||||
|
*p++ = L'/';
|
||||||
|
*p = L'\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define numberof(array) (sizeof(array) / sizeof(*array))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_env(void)
|
init_env(void)
|
||||||
{
|
{
|
||||||
char env[_MAX_PATH];
|
WCHAR env[_MAX_PATH];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
BOOL f;
|
BOOL f;
|
||||||
|
|
||||||
if (!GetEnvironmentVariable("HOME", env, sizeof(env))) {
|
if (!GetEnvironmentVariableW(L"HOME", env, numberof(env))) {
|
||||||
f = FALSE;
|
f = FALSE;
|
||||||
if (GetEnvironmentVariable("HOMEDRIVE", env, sizeof(env)))
|
if (GetEnvironmentVariableW(L"HOMEDRIVE", env, numberof(env)))
|
||||||
len = strlen(env);
|
len = lstrlenW(env);
|
||||||
else
|
else
|
||||||
len = 0;
|
len = 0;
|
||||||
if (GetEnvironmentVariable("HOMEPATH", env + len, sizeof(env) - len) || len) {
|
if (GetEnvironmentVariableW(L"HOMEPATH", env + len, numberof(env) - len) || len) {
|
||||||
f = TRUE;
|
f = TRUE;
|
||||||
}
|
}
|
||||||
else if (GetEnvironmentVariable("USERPROFILE", env, sizeof(env))) {
|
else if (GetEnvironmentVariableW(L"USERPROFILE", env, numberof(env))) {
|
||||||
f = TRUE;
|
f = TRUE;
|
||||||
}
|
}
|
||||||
else if (get_special_folder(CSIDL_PROFILE, env)) {
|
else if (get_special_folder(CSIDL_PROFILE, env)) {
|
||||||
|
@ -406,25 +428,20 @@ init_env(void)
|
||||||
f = TRUE;
|
f = TRUE;
|
||||||
}
|
}
|
||||||
if (f) {
|
if (f) {
|
||||||
char *p = translate_char(env, '\\', '/');
|
regulate_path(env);
|
||||||
if (p - env == 2 && env[1] == ':') {
|
SetEnvironmentVariableW(L"HOME", env);
|
||||||
*p++ = '/';
|
|
||||||
*p = 0;
|
|
||||||
}
|
|
||||||
SetEnvironmentVariable("HOME", env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetEnvironmentVariable("USER", env, sizeof env)) {
|
if (!GetEnvironmentVariableW(L"USER", env, numberof(env))) {
|
||||||
if (GetEnvironmentVariable("USERNAME", env, sizeof env)) {
|
if (!GetEnvironmentVariableW(L"USERNAME", env, numberof(env)) &&
|
||||||
SetEnvironmentVariable("USER", env);
|
!GetUserNameW(env, (len = numberof(env), &len))) {
|
||||||
}
|
|
||||||
else if (!GetUserName(env, (len = sizeof env, &len))) {
|
|
||||||
NTLoginName = "<Unknown>";
|
NTLoginName = "<Unknown>";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
SetEnvironmentVariableW(L"USER", env);
|
||||||
}
|
}
|
||||||
NTLoginName = strdup(env);
|
NTLoginName = strdup(rb_w32_getenv("USER"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue