ruby-changes:2109
From: ko1@a...
Date: 2 Oct 2007 21:19:03 +0900
Subject: [ruby-changes:2109] usa - Ruby:r13601 (ruby_1_8): * win32/win32.c (init_env): initialize HOME and USER environment
usa 2007-10-02 21:18:35 +0900 (Tue, 02 Oct 2007) New Revision: 13601 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/configure.in branches/ruby_1_8/version.h branches/ruby_1_8/win32/Makefile.sub branches/ruby_1_8/win32/win32.c Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/configure.in?r1=13601&r2=13600 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13601&r2=13600 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/win32/Makefile.sub?r1=13601&r2=13600 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/win32/win32.c?r1=13601&r2=13600 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=13601&r2=13600 Index: ruby_1_8/configure.in =================================================================== --- ruby_1_8/configure.in (revision 13600) +++ ruby_1_8/configure.in (revision 13601) @@ -382,6 +382,7 @@ 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 Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 13600) +++ ruby_1_8/ChangeLog (revision 13601) @@ -1,3 +1,13 @@ +Tue Oct 2 20:35:24 2007 NAKAMURA Usaku <usa@r...> + + * 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 <matz@r...> * gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS. Index: ruby_1_8/version.h =================================================================== --- ruby_1_8/version.h (revision 13600) +++ ruby_1_8/version.h (revision 13601) @@ -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[]; Index: ruby_1_8/win32/win32.c =================================================================== --- ruby_1_8/win32/win32.c (revision 13600) +++ ruby_1_8/win32/win32.c (revision 13601) @@ -25,6 +25,7 @@ #include <windows.h> #include <winbase.h> #include <wincon.h> +#include <shlobj.h> #ifdef __MINGW32__ #include <mswsock.h> #include <mbstring.h> @@ -383,6 +384,60 @@ } } +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 // @@ -411,6 +466,8 @@ tzset(); + init_env(); + init_stdhandle(); atexit(exit_handler); @@ -427,21 +484,6 @@ 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; } @@ -1064,10 +1106,9 @@ 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 @@ 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 @@ 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"); } } Index: ruby_1_8/win32/Makefile.sub =================================================================== --- ruby_1_8/win32/Makefile.sub (revision 13600) +++ ruby_1_8/win32/Makefile.sub (revision 13601) @@ -130,11 +130,13 @@ !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: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml