From b5aaf376b0d78253ef510ea3438c7babf4b9a71d Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 2 Oct 2007 12:18:35 +0000 Subject: * 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@13601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 +++++++ configure.in | 1 + version.h | 6 ++-- win32/Makefile.sub | 6 ++-- win32/win32.c | 80 ++++++++++++++++++++++++++++++++++++++++-------------- 5 files changed, 78 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b1c5a099e..d9851014a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Oct 2 20:35:24 2007 NAKAMURA Usaku + + * 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. + Mon Oct 1 12:50:59 2007 Yukihiro Matsumoto * gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS. diff --git a/configure.in b/configure.in index f3d3d9b109..c99d846cd9 100644 --- a/configure.in +++ b/configure.in @@ -382,6 +382,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 aaba689870..b87fe31340 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.6" -#define RUBY_RELEASE_DATE "2007-10-01" +#define RUBY_RELEASE_DATE "2007-10-02" #define RUBY_VERSION_CODE 186 -#define RUBY_RELEASE_CODE 20071001 +#define RUBY_RELEASE_CODE 20071002 #define RUBY_PATCHLEVEL 5000 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 1 +#define RUBY_RELEASE_DAY 2 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; diff --git a/win32/Makefile.sub b/win32/Makefile.sub index e555399b2c..a6df99dd1f 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 98fb96e908..5dd3583e8a 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __MINGW32__ #include #include @@ -383,6 +384,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 = ""; + return; + } + } + NTLoginName = strdup(env); +} + // // Initialization stuff // @@ -411,6 +466,8 @@ NtInitialize(int *argc, char ***argv) tzset(); + init_env(); + init_stdhandle(); atexit(exit_handler); @@ -427,21 +484,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 = ""; - } - } return NTLoginName; } @@ -1064,10 +1106,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; @@ -1384,8 +1425,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; @@ -1870,7 +1910,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"); } } -- cgit v1.2.3