[前][次][番号順一覧][スレッド一覧]

ruby-changes:43187

From: nobu <ko1@a...>
Date: Thu, 2 Jun 2016 21:18:18 +0900 (JST)
Subject: [ruby-changes:43187] nobu:r55261 (trunk): win32.c: use SHGetPathFromIDListEx

nobu	2016-06-02 21:18:12 +0900 (Thu, 02 Jun 2016)

  New Revision: 55261

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55261

  Log:
    win32.c: use SHGetPathFromIDListEx
    
    * win32/win32.c (get_special_folder): use SHGetPathFromIDListEx if
      available instead of old SHGetPathFromIDListW, to check the
      buffer size.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55260)
+++ ChangeLog	(revision 55261)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun  2 21:18:10 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (get_special_folder): use SHGetPathFromIDListEx if
+	  available instead of old SHGetPathFromIDListW, to check the
+	  buffer size.
+
 Thu Jun  2 17:05:19 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* ruby.c (ruby_init_loadpath_safe): remove MAXPATHLEN restriction
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 55260)
+++ win32/win32.c	(revision 55261)
@@ -115,6 +115,7 @@ static int wstati64(const WCHAR *path, s https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L115
 static int wlstati64(const WCHAR *path, struct stati64 *st);
 VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
 int ruby_brace_glob_with_enc(const char *str, int flags, ruby_glob_func *func, VALUE arg, rb_encoding *enc);
+static FARPROC get_proc_address(const char *module, const char *func, HANDLE *mh);
 
 #define RUBY_CRITICAL if (0) {} else /* just remark */
 
@@ -420,13 +421,26 @@ translate_char(char *p, int from, int to https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L421
 
 /* License: Ruby's */
 static BOOL
-get_special_folder(int n, WCHAR *env)
+get_special_folder(int n, WCHAR *buf, size_t len)
 {
     LPITEMIDLIST pidl;
     LPMALLOC alloc;
     BOOL f = FALSE;
+    typedef BOOL (*get_path_func)(LPITEMIDLIST, WCHAR*, DWORD, int);
+    static get_path_func func = (get_path_func)-1;
+
+    if (func = (get_path_func)-1) {
+	func = (get_path_func)
+	    get_proc_address("shell32", "SHGetPathFromIDListEx", NULL);
+    }
+
     if (SHGetSpecialFolderLocation(NULL, n, &pidl) == 0) {
-	f = SHGetPathFromIDListW(pidl, env);
+	if (func) {
+	    f = func(pidl, buf, len, 0);
+	}
+	else if (len >= 260) {
+	    f = SHGetPathFromIDListW(pidl, buf);
+	}
 	SHGetMalloc(&alloc);
 	alloc->lpVtbl->Free(alloc, pidl);
 	alloc->lpVtbl->Release(alloc);
@@ -475,7 +489,7 @@ rb_w32_special_folder(int type) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L489
 {
     WCHAR path[_MAX_PATH];
 
-    if (!get_special_folder(type, path)) return Qnil;
+    if (!get_special_folder(type, path, numberof(path))) return Qnil;
     regulate_path(path);
     return rb_w32_conv_from_wchar(path, rb_filesystem_encoding());
 }
@@ -487,7 +501,7 @@ rb_w32_system_tmpdir(WCHAR *path, UINT l https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L501
     static const WCHAR temp[] = L"temp";
     WCHAR *p;
 
-    if (!get_special_folder(CSIDL_LOCAL_APPDATA, path)) {
+    if (!get_special_folder(CSIDL_LOCAL_APPDATA, path, len)) {
 	if (GetSystemWindowsDirectoryW(path, len)) return 0;
     }
     p = translate_wchar(path, L'\\', L'/');
@@ -527,10 +541,10 @@ init_env(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L541
 	else if (GetEnvironmentVariableW(L"USERPROFILE", env, numberof(env))) {
 	    f = TRUE;
 	}
-	else if (get_special_folder(CSIDL_PROFILE, env)) {
+	else if (get_special_folder(CSIDL_PROFILE, env, numberof(env))) {
 	    f = TRUE;
 	}
-	else if (get_special_folder(CSIDL_PERSONAL, env)) {
+	else if (get_special_folder(CSIDL_PERSONAL, env, numberof(env))) {
 	    f = TRUE;
 	}
 	if (f) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]