summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-05 03:26:21 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-05 03:26:21 +0000
commite6717679c09420842d7450dd60a55751e231e8d9 (patch)
tree3066a7333a9b6c3ea459af3f2e2645997ee67fa8
parent545ebecb30dce3fbb63c319a553c78cfb44a20a1 (diff)
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
-rw-r--r--ChangeLog10
-rw-r--r--configure.in1
-rw-r--r--version.h2
-rw-r--r--win32/Makefile.sub6
-rw-r--r--win32/win32.c80
5 files changed, 76 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b7dcfae6f..12deb418df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Thu Jun 5 12:24:25 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * 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.
+
Thu Jun 5 12:21:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS.
diff --git a/configure.in b/configure.in
index 4b9e25e668..3dbb527849 100644
--- a/configure.in
+++ b/configure.in
@@ -346,6 +346,7 @@ mingw*) if test "$with_winsock2" = yes; then
else
LIBS="-lwsock32 $LIBS"
fi
+ LIBS="-lshell32 $LIBS"
ac_cv_header_a_out_h=no
ac_cv_header_pwd_h=no
ac_cv_header_utime_h=no
diff --git a/version.h b/version.h
index d9f6a703fe..34628dcd8b 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-05"
#define RUBY_VERSION_CODE 185
#define RUBY_RELEASE_CODE 20080605
-#define RUBY_PATCHLEVEL 127
+#define RUBY_PATCHLEVEL 128
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index db737332c2..4abfa76433 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -130,11 +130,13 @@ RFLAGS = -r
!if !defined(EXTLIBS)
EXTLIBS =
!endif
+LIBS = oldnames.lib user32.lib advapi32.lib shell32.lib
!if !defined(USE_WINSOCK2)
-LIBS = oldnames.lib user32.lib advapi32.lib wsock32.lib $(EXTLIBS)
+LIBS = $(LIBS) wsock32.lib
!else
-LIBS = oldnames.lib user32.lib advapi32.lib ws2_32.lib $(EXTLIBS)
+LIBS = $(LIBS) ws2_32.lib
!endif
+LIBS = $(LIBS) $(EXTLIBS)
MISSING = acosh.obj crypt.obj erf.obj win32.obj
ARFLAGS = -machine:$(MACHINE) -out:
diff --git a/win32/win32.c b/win32/win32.c
index 784d9eccfe..3fae1e594c 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -25,6 +25,7 @@
#include <windows.h>
#include <winbase.h>
#include <wincon.h>
+#include <shlobj.h>
#ifdef __MINGW32__
#include <mswsock.h>
#include <mbstring.h>
@@ -385,6 +386,60 @@ exit_handler(void)
}
}
+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)) {
+ if (GetEnvironmentVariable("USERNAME", env, sizeof env) ||
+ GetUserName(env, (len = sizeof env, &len))) {
+ SetEnvironmentVariable("USER", env);
+ }
+ else {
+ NTLoginName = "<Unknown>";
+ return;
+ }
+ }
+ NTLoginName = strdup(env);
+}
+
//
// Initialization stuff
//
@@ -413,6 +468,8 @@ NtInitialize(int *argc, char ***argv)
tzset();
+ init_env();
+
init_stdhandle();
atexit(exit_handler);
@@ -429,21 +486,6 @@ NtInitialize(int *argc, char ***argv)
char *
getlogin()
{
- char buffer[200];
- DWORD len = 200;
- extern char *NTLoginName;
-
- if (NTLoginName == NULL) {
- if (GetUserName(buffer, &len)) {
- NTLoginName = (char *)malloc(len+1);
- if (!NTLoginName) return NULL;
- strncpy(NTLoginName, buffer, len);
- NTLoginName[len] = '\0';
- }
- else {
- NTLoginName = "<Unknown>";
- }
- }
return NTLoginName;
}
@@ -1086,10 +1128,9 @@ insert(const char *path, VALUE vinfo)
if (!tmpcurr) return -1;
MEMZERO(tmpcurr, NtCmdLineElement, 1);
tmpcurr->len = strlen(path);
- tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
+ tmpcurr->str = strdup(path);
if (!tmpcurr->str) return -1;
tmpcurr->flags |= NTMALLOC;
- strcpy(tmpcurr->str, path);
**tail = tmpcurr;
*tail = &tmpcurr->next;
@@ -1406,8 +1447,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
ptr = buffer + (elements+1) * sizeof(char *);
while (curr = cmdhead) {
- strncpy (ptr, curr->str, curr->len);
- ptr[curr->len] = '\0';
+ memcpy(ptr, curr->str, curr->len + 1);
*vptr++ = ptr;
ptr += curr->len + 1;
cmdhead = curr->next;
@@ -1859,7 +1899,7 @@ rb_w32_strerror(int e)
e = GetLastError();
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
- buffer, 512, NULL) == 0) {
+ buffer, sizeof(buffer), NULL) == 0) {
strcpy(buffer, "Unknown Error");
}
}