* win32/win32.c (init_env): initialize HOME and USER environment
variables unless set. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
67232b2151
commit
c41cefd492
@ -1,3 +1,8 @@
|
|||||||
|
Wed Aug 18 11:22:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (init_env): initialize HOME and USER environment
|
||||||
|
variables unless set.
|
||||||
|
|
||||||
Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com>
|
Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com>
|
||||||
|
|
||||||
* lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option
|
* lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <wincon.h>
|
#include <wincon.h>
|
||||||
|
#include <shlobj.h>
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include <mswsock.h>
|
#include <mswsock.h>
|
||||||
#endif
|
#endif
|
||||||
@ -349,6 +350,64 @@ flock(int fd, int oper)
|
|||||||
(DWORD)-1);
|
(DWORD)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void init_env(void)
|
||||||
|
{
|
||||||
|
char env[_MAX_PATH];
|
||||||
|
DWORD len;
|
||||||
|
BOOL f;
|
||||||
|
LPITEMIDLIST pidl;
|
||||||
|
|
||||||
|
if (!GetEnvironmentVariable("HOME", env, sizeof(env))) {
|
||||||
|
f = FALSE;
|
||||||
|
if (GetEnvironmentVariable("HOMEDRIVE", env, sizeof(env)))
|
||||||
|
len = strlen(env);
|
||||||
|
else
|
||||||
|
len = 0;
|
||||||
|
if (GetEnvironmentVariable("HOMEPATH", env + len, sizeof(env) - len) || len) {
|
||||||
|
f = TRUE;
|
||||||
|
}
|
||||||
|
else if (GetEnvironmentVariable("USERPROFILE", env, sizeof(env))) {
|
||||||
|
f = TRUE;
|
||||||
|
}
|
||||||
|
else if (SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl) == 0) {
|
||||||
|
LPMALLOC alloc;
|
||||||
|
f = SHGetPathFromIDList(pidl, env);
|
||||||
|
SHGetMalloc(&alloc);
|
||||||
|
alloc->lpVtbl->Free(alloc, pidl);
|
||||||
|
alloc->lpVtbl->Release(alloc);
|
||||||
|
}
|
||||||
|
if (f) {
|
||||||
|
char *p = env;
|
||||||
|
while (*p) {
|
||||||
|
if (*p == '\\') *p = '/';
|
||||||
|
p = CharNext(p);
|
||||||
|
}
|
||||||
|
if (p - env == 2 && env[1] == ':') {
|
||||||
|
*p++ = '/';
|
||||||
|
*p = 0;
|
||||||
|
}
|
||||||
|
SetEnvironmentVariable("HOME", env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (GetEnvironmentVariable("USER", env, sizeof env)) {
|
||||||
|
len = strlen(env);
|
||||||
|
}
|
||||||
|
if (GetEnvironmentVariable("USERNAME", env, sizeof env)) {
|
||||||
|
len = strlen(env);
|
||||||
|
SetEnvironmentVariable("USER", env);
|
||||||
|
}
|
||||||
|
else if (GetUserName(env, (len = sizeof env, &len))) {
|
||||||
|
SetEnvironmentVariable("USER", env);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NTLoginName = "<Unknown>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NTLoginName = ALLOC_N(char, len+1);
|
||||||
|
strncpy(NTLoginName, env, len);
|
||||||
|
NTLoginName[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialization stuff
|
// Initialization stuff
|
||||||
//
|
//
|
||||||
@ -374,6 +433,8 @@ NtInitialize(int *argc, char ***argv)
|
|||||||
|
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
|
init_env();
|
||||||
|
|
||||||
// Initialize Winsock
|
// Initialize Winsock
|
||||||
StartSockets();
|
StartSockets();
|
||||||
|
|
||||||
@ -386,20 +447,6 @@ NtInitialize(int *argc, char ***argv)
|
|||||||
char *
|
char *
|
||||||
getlogin()
|
getlogin()
|
||||||
{
|
{
|
||||||
char buffer[200];
|
|
||||||
DWORD len = 200;
|
|
||||||
extern char *NTLoginName;
|
|
||||||
|
|
||||||
if (NTLoginName == NULL) {
|
|
||||||
if (GetUserName(buffer, &len)) {
|
|
||||||
NTLoginName = ALLOC_N(char, len+1);
|
|
||||||
strncpy(NTLoginName, buffer, len);
|
|
||||||
NTLoginName[len] = '\0';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NTLoginName = "<Unknown>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NTLoginName;
|
return NTLoginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user