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

ruby-changes:36563

From: nobu <ko1@a...>
Date: Sat, 29 Nov 2014 10:49:36 +0900 (JST)
Subject: [ruby-changes:36563] nobu:r48644 (trunk): win32.c: convert by Win32 API

nobu	2014-11-29 10:49:26 +0900 (Sat, 29 Nov 2014)

  New Revision: 48644

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

  Log:
    win32.c: convert by Win32 API
    
    * win32/win32.c (win32_direct_conv, rb_w32_readdir): convert UTF-8
      and filesystem code page by using Win32 API directly.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48643)
+++ ChangeLog	(revision 48644)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov 29 10:49:23 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (win32_direct_conv, rb_w32_readdir): convert UTF-8
+	  and filesystem code page by using Win32 API directly.
+
 Sat Nov 29 09:37:10 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (syserr_initialize): simplify message building and get
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 48643)
+++ win32/win32.c	(revision 48644)
@@ -2033,9 +2033,10 @@ move_to_next_entry(DIR *dirp) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2033
 //
 /* License: Ruby's */
 static BOOL
-win32_direct_conv(const WCHAR *file, struct direct *entry, rb_encoding *dummy)
+win32_direct_conv(const WCHAR *file, struct direct *entry, const void *enc)
 {
-    if (!(entry->d_name = wstr_to_filecp(file, &entry->d_namlen)))
+    UINT cp = *((UINT *)enc);
+    if (!(entry->d_name = wstr_to_mbstr(cp, file, -1, &entry->d_namlen)))
 	return FALSE;
     return TRUE;
 }
@@ -2088,7 +2089,7 @@ rb_w32_conv_from_wstr(const WCHAR *wstr, https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2089
 
 /* License: Ruby's */
 static BOOL
-ruby_direct_conv(const WCHAR *file, struct direct *entry, rb_encoding *enc)
+ruby_direct_conv(const WCHAR *file, struct direct *entry, const void *enc)
 {
     if (!(entry->d_name = rb_w32_conv_from_wstr(file, &entry->d_namlen, enc)))
 	return FALSE;
@@ -2097,7 +2098,7 @@ ruby_direct_conv(const WCHAR *file, stru https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2098
 
 /* License: Artistic or GPL */
 static struct direct *
-readdir_internal(DIR *dirp, BOOL (*conv)(const WCHAR *, struct direct *, rb_encoding *), rb_encoding *enc)
+readdir_internal(DIR *dirp, BOOL (*conv)(const WCHAR *, struct direct *, const void *), const void *enc)
 {
     static int dummy = 0;
 
@@ -2138,8 +2139,14 @@ readdir_internal(DIR *dirp, BOOL (*conv) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2139
 struct direct  *
 rb_w32_readdir(DIR *dirp, rb_encoding *enc)
 {
-    if (!enc || enc == rb_ascii8bit_encoding())
-	return readdir_internal(dirp, win32_direct_conv, NULL);
+    if (!enc || enc == rb_ascii8bit_encoding()) {
+	const UINT cp = filecp();
+	return readdir_internal(dirp, win32_direct_conv, &cp);
+    }
+    else if (enc == rb_utf8_encoding()) {
+	const UINT cp = CP_UTF8;
+	return readdir_internal(dirp, win32_direct_conv, &cp);
+    }
     else
 	return readdir_internal(dirp, ruby_direct_conv, enc);
 }

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

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