summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-25 08:36:45 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-25 08:36:45 +0000
commita898f0fb4b8e31d86a372f7d1438823195015249 (patch)
tree2099267d4614d080825666365567b074f4e5e6ef /win32
parent3540727af57ee166993da274d924b278a0bd0d9a (diff)
* io.c (sysopen_func, rb_sysopen_internal, rb_sysopen): open file
by UTF-16'ed filename on Windows. * io.c (rb_file_open_generic, rb_io_s_sysopen, rb_io_reopen, argf_next_argv): follow above change. * io.c (rb_scan_open_args): no longer need to convert filepath here on Windows. * win32/wio32.c (rb_w32_wopen): new function to open file by UTF-16'ed filename. * win32/win32.c (rb_w32_open): call rb_w32_open(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 3bd857253a..9c1a92a55c 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4151,6 +4151,37 @@ rb_w32_getppid(void)
int
rb_w32_open(const char *file, int oflag, ...)
{
+ UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+ int len;
+ WCHAR *wfile;
+ int pmode;
+
+ va_list arg;
+ va_start(arg, oflag);
+ pmode = va_arg(arg, int);
+ va_end(arg);
+
+ if ((oflag & O_TEXT) || !(oflag & ~O_BINARY)) {
+ return _open(file, oflag, pmode);
+ }
+
+ len = MultiByteToWideChar(cp, 0, file, -1, NULL, 0);
+ if (len <= 0) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ wfile = ALLOCA_N(WCHAR, len);
+ MultiByteToWideChar(cp, 0, file, -1, wfile, len);
+ if (len <= 0) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ return rb_w32_wopen(wfile, oflag, pmode);
+}
+
+int
+rb_w32_wopen(const WCHAR *file, int oflag, ...)
+{
char flags = 0;
int fd;
DWORD access;
@@ -4165,7 +4196,7 @@ rb_w32_open(const char *file, int oflag, ...)
va_start(arg, oflag);
pmode = va_arg(arg, int);
va_end(arg);
- return _open(file, oflag, pmode);
+ return _wopen(file, oflag, pmode);
}
sec.nLength = sizeof(sec);
@@ -4281,8 +4312,8 @@ rb_w32_open(const char *file, int oflag, ...)
/* open with FILE_FLAG_OVERLAPPED if have CancelIo */
if (cancel_io)
attr |= FILE_FLAG_OVERLAPPED;
- h = CreateFile(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
- create, attr, NULL);
+ h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
+ create, attr, NULL);
if (h == INVALID_HANDLE_VALUE) {
errno = map_errno(GetLastError());
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));