diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-22 06:55:20 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-22 06:55:20 +0000 |
commit | a3e8d63a758dd32c01159f2ca8a980223ada300e (patch) | |
tree | eaca70426fccf74f58aa13e2cb118381d0fcd8bf | |
parent | 7e4ca5266944acabab84283fab88f35cfcfeb56e (diff) | |
download | ruby-a3e8d63a758dd32c01159f2ca8a980223ada300e.tar.gz |
* include/ruby/win32.h, win32/win32.c (rb_w32_is_valid_fd): new function
to validate fd.
* io.c (rb_io_initialize): check fd with above function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | include/ruby/win32.h | 1 | ||||
-rw-r--r-- | io.c | 6 | ||||
-rw-r--r-- | win32/win32.c | 9 |
4 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Thu Jan 22 15:54:02 2009 NAKAMURA Usaku <usa@ruby-lang.org> + + * include/ruby/win32.h, win32/win32.c (rb_w32_is_valid_fd): new function + to validate fd. + + * io.c (rb_io_initialize): check fd with above function. + Thu Jan 22 14:53:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * test/ruby/test_process.rb (MANDATORY_ENVS): needs RUBYLIB to run diff --git a/include/ruby/win32.h b/include/ruby/win32.h index 46388a3ae2..1bbe69e69c 100644 --- a/include/ruby/win32.h +++ b/include/ruby/win32.h @@ -214,6 +214,7 @@ extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int); extern void rb_w32_fdset(int, fd_set*); extern void rb_w32_fdclr(int, fd_set*); extern int rb_w32_fdisset(int, fd_set*); +extern int rb_w32_is_valid_fd(int); extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *); extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *); @@ -5971,13 +5971,15 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io) fd = NUM2INT(fnum); if (fstat(fd, &st) == -1) rb_sys_fail(0); UPDATE_MAXFD(fd); - if (NIL_P(vmode)) { #if defined(HAVE_FCNTL) && defined(F_GETFL) + if (NIL_P(vmode)) { oflags = fcntl(fd, F_GETFL); if (oflags == -1) rb_sys_fail(0); fmode = rb_io_oflags_fmode(oflags); -#endif } +#elif defined(_WIN32) + if (rb_w32_is_valid_fd(fd)) rb_sys_fail(0); +#endif MakeOpenFile(io, fp); fp->fd = fd; fp->mode = fmode; diff --git a/win32/win32.c b/win32/win32.c index b948fe0d77..ba8a96e82c 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1836,6 +1836,15 @@ rb_w32_open_osfhandle(intptr_t osfhandle, int flags) } #endif +int +rb_w32_is_valid_fd(int fd) +{ + if (_get_osfhandle(fd) == -1) + return -1; + else + return 0; +} + #undef getsockopt static int |