Skip to content

Commit f213f50

Browse files
committed
win32.c: fallback to WCHAR-version in MSVCRT
* win32/win32.c (rb_w32_open): should not fallback to ANSI-version in MSVCRT, fallback to WCHAR-version in rb_w32_wopen instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 0e84f98 commit f213f50

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

win32/win32.c

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5975,19 +5975,7 @@ check_if_wdir(const WCHAR *wfile)
59755975
return TRUE;
59765976
}
59775977

5978-
/* License: Ruby's */
5979-
static int
5980-
check_if_dir(const char *file)
5981-
{
5982-
WCHAR *wfile;
5983-
int ret;
5984-
5985-
if (!(wfile = filecp_to_wstr(file, NULL)))
5986-
return FALSE;
5987-
ret = check_if_wdir(wfile);
5988-
free(wfile);
5989-
return ret;
5990-
}
5978+
static int w32_wopen(const WCHAR *file, int oflag, int perm);
59915979

59925980
/* License: Ruby's */
59935981
int
@@ -6002,23 +5990,31 @@ rb_w32_open(const char *file, int oflag, ...)
60025990
pmode = va_arg(arg, int);
60035991
va_end(arg);
60045992

6005-
if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
6006-
oflag &= ~O_SHARE_DELETE;
6007-
ret = _open(file, oflag, pmode);
6008-
if (ret == -1 && errno == EACCES) check_if_dir(file);
6009-
return ret;
6010-
}
6011-
60125993
if (!(wfile = filecp_to_wstr(file, NULL)))
60135994
return -1;
6014-
ret = rb_w32_wopen(wfile, oflag, pmode);
5995+
ret = w32_wopen(wfile, oflag, pmode);
60155996
free(wfile);
60165997
return ret;
60175998
}
60185999

60196000
/* License: Ruby's */
60206001
int
60216002
rb_w32_wopen(const WCHAR *file, int oflag, ...)
6003+
{
6004+
int pmode = 0;
6005+
6006+
if (oflag & O_CREAT) {
6007+
va_list arg;
6008+
va_start(arg, oflag);
6009+
pmode = va_arg(arg, int);
6010+
va_end(arg);
6011+
}
6012+
6013+
return w32_wopen(file, oflag, pmode);
6014+
}
6015+
6016+
static int
6017+
w32_wopen(const WCHAR *file, int oflag, int pmode)
60226018
{
60236019
char flags = 0;
60246020
int fd;
@@ -6032,11 +6028,6 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
60326028
share_delete = oflag & O_SHARE_DELETE ? FILE_SHARE_DELETE : 0;
60336029
oflag &= ~O_SHARE_DELETE;
60346030
if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
6035-
va_list arg;
6036-
int pmode;
6037-
va_start(arg, oflag);
6038-
pmode = va_arg(arg, int);
6039-
va_end(arg);
60406031
fd = _wopen(file, oflag, pmode);
60416032
if (fd == -1) {
60426033
switch (errno) {
@@ -6105,11 +6096,6 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
61056096
return -1;
61066097
}
61076098
if (oflag & O_CREAT) {
6108-
va_list arg;
6109-
int pmode;
6110-
va_start(arg, oflag);
6111-
pmode = va_arg(arg, int);
6112-
va_end(arg);
61136099
/* TODO: we need to check umask here, but it's not exported... */
61146100
if (!(pmode & S_IWRITE))
61156101
attr = FILE_ATTRIBUTE_READONLY;

0 commit comments

Comments
 (0)