Skip to content

Commit e671767

Browse files
committed
merge revision(s) 13601:
* win32/win32.c (init_env): initialize HOME and USER environment variables unless set. [ruby-core:12328] (merge from trunk) * win32/win32.c (NtInitialize, getlogin): ditto. * configure.in, win32/Makefile.sub (LIBS): need to link shell32 library for SH* functions on mswin32 and mingw32. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@16829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 545ebec commit e671767

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Thu Jun 5 12:24:25 2008 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* win32/win32.c (init_env): initialize HOME and USER environment
4+
variables unless set. [ruby-core:12328] (merge from trunk)
5+
6+
* win32/win32.c (NtInitialize, getlogin): ditto.
7+
8+
* configure.in, win32/Makefile.sub (LIBS): need to link shell32
9+
library for SH* functions on mswin32 and mingw32.
10+
111
Thu Jun 5 12:21:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
212

313
* gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS.

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ mingw*) if test "$with_winsock2" = yes; then
346346
else
347347
LIBS="-lwsock32 $LIBS"
348348
fi
349+
LIBS="-lshell32 $LIBS"
349350
ac_cv_header_a_out_h=no
350351
ac_cv_header_pwd_h=no
351352
ac_cv_header_utime_h=no

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2008-06-05"
33
#define RUBY_VERSION_CODE 185
44
#define RUBY_RELEASE_CODE 20080605
5-
#define RUBY_PATCHLEVEL 127
5+
#define RUBY_PATCHLEVEL 128
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

win32/Makefile.sub

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ RFLAGS = -r
130130
!if !defined(EXTLIBS)
131131
EXTLIBS =
132132
!endif
133+
LIBS = oldnames.lib user32.lib advapi32.lib shell32.lib
133134
!if !defined(USE_WINSOCK2)
134-
LIBS = oldnames.lib user32.lib advapi32.lib wsock32.lib $(EXTLIBS)
135+
LIBS = $(LIBS) wsock32.lib
135136
!else
136-
LIBS = oldnames.lib user32.lib advapi32.lib ws2_32.lib $(EXTLIBS)
137+
LIBS = $(LIBS) ws2_32.lib
137138
!endif
139+
LIBS = $(LIBS) $(EXTLIBS)
138140
MISSING = acosh.obj crypt.obj erf.obj win32.obj
139141

140142
ARFLAGS = -machine:$(MACHINE) -out:

win32/win32.c

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <windows.h>
2626
#include <winbase.h>
2727
#include <wincon.h>
28+
#include <shlobj.h>
2829
#ifdef __MINGW32__
2930
#include <mswsock.h>
3031
#include <mbstring.h>
@@ -385,6 +386,60 @@ exit_handler(void)
385386
}
386387
}
387388

389+
static void
390+
init_env(void)
391+
{
392+
char env[_MAX_PATH];
393+
DWORD len;
394+
BOOL f;
395+
LPITEMIDLIST pidl;
396+
397+
if (!GetEnvironmentVariable("HOME", env, sizeof(env))) {
398+
f = FALSE;
399+
if (GetEnvironmentVariable("HOMEDRIVE", env, sizeof(env)))
400+
len = strlen(env);
401+
else
402+
len = 0;
403+
if (GetEnvironmentVariable("HOMEPATH", env + len, sizeof(env) - len) || len) {
404+
f = TRUE;
405+
}
406+
else if (GetEnvironmentVariable("USERPROFILE", env, sizeof(env))) {
407+
f = TRUE;
408+
}
409+
else if (SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl) == 0) {
410+
LPMALLOC alloc;
411+
f = SHGetPathFromIDList(pidl, env);
412+
SHGetMalloc(&alloc);
413+
alloc->lpVtbl->Free(alloc, pidl);
414+
alloc->lpVtbl->Release(alloc);
415+
}
416+
if (f) {
417+
char *p = env;
418+
while (*p) {
419+
if (*p == '\\') *p = '/';
420+
p = CharNext(p);
421+
}
422+
if (p - env == 2 && env[1] == ':') {
423+
*p++ = '/';
424+
*p = 0;
425+
}
426+
SetEnvironmentVariable("HOME", env);
427+
}
428+
}
429+
430+
if (!GetEnvironmentVariable("USER", env, sizeof env)) {
431+
if (GetEnvironmentVariable("USERNAME", env, sizeof env) ||
432+
GetUserName(env, (len = sizeof env, &len))) {
433+
SetEnvironmentVariable("USER", env);
434+
}
435+
else {
436+
NTLoginName = "<Unknown>";
437+
return;
438+
}
439+
}
440+
NTLoginName = strdup(env);
441+
}
442+
388443
//
389444
// Initialization stuff
390445
//
@@ -413,6 +468,8 @@ NtInitialize(int *argc, char ***argv)
413468

414469
tzset();
415470

471+
init_env();
472+
416473
init_stdhandle();
417474

418475
atexit(exit_handler);
@@ -429,21 +486,6 @@ NtInitialize(int *argc, char ***argv)
429486
char *
430487
getlogin()
431488
{
432-
char buffer[200];
433-
DWORD len = 200;
434-
extern char *NTLoginName;
435-
436-
if (NTLoginName == NULL) {
437-
if (GetUserName(buffer, &len)) {
438-
NTLoginName = (char *)malloc(len+1);
439-
if (!NTLoginName) return NULL;
440-
strncpy(NTLoginName, buffer, len);
441-
NTLoginName[len] = '\0';
442-
}
443-
else {
444-
NTLoginName = "<Unknown>";
445-
}
446-
}
447489
return NTLoginName;
448490
}
449491

@@ -1086,10 +1128,9 @@ insert(const char *path, VALUE vinfo)
10861128
if (!tmpcurr) return -1;
10871129
MEMZERO(tmpcurr, NtCmdLineElement, 1);
10881130
tmpcurr->len = strlen(path);
1089-
tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
1131+
tmpcurr->str = strdup(path);
10901132
if (!tmpcurr->str) return -1;
10911133
tmpcurr->flags |= NTMALLOC;
1092-
strcpy(tmpcurr->str, path);
10931134
**tail = tmpcurr;
10941135
*tail = &tmpcurr->next;
10951136

@@ -1406,8 +1447,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
14061447
ptr = buffer + (elements+1) * sizeof(char *);
14071448

14081449
while (curr = cmdhead) {
1409-
strncpy (ptr, curr->str, curr->len);
1410-
ptr[curr->len] = '\0';
1450+
memcpy(ptr, curr->str, curr->len + 1);
14111451
*vptr++ = ptr;
14121452
ptr += curr->len + 1;
14131453
cmdhead = curr->next;
@@ -1859,7 +1899,7 @@ rb_w32_strerror(int e)
18591899
e = GetLastError();
18601900
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
18611901
FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
1862-
buffer, 512, NULL) == 0) {
1902+
buffer, sizeof(buffer), NULL) == 0) {
18631903
strcpy(buffer, "Unknown Error");
18641904
}
18651905
}

0 commit comments

Comments
 (0)