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

ruby-changes:10190

From: usa <ko1@a...>
Date: Thu, 22 Jan 2009 15:55:39 +0900 (JST)
Subject: [ruby-changes:10190] Ruby:r21734 (trunk): * include/ruby/win32.h, win32/win32.c (rb_w32_is_valid_fd): new function

usa	2009-01-22 15:55:20 +0900 (Thu, 22 Jan 2009)

  New Revision: 21734

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

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/win32.h
    trunk/io.c
    trunk/win32/win32.c

Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 21733)
+++ include/ruby/win32.h	(revision 21734)
@@ -214,6 +214,7 @@
 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 *);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21733)
+++ ChangeLog	(revision 21734)
@@ -1,3 +1,10 @@
+Thu Jan 22 15:54:02 2009  NAKAMURA Usaku  <usa@r...>
+
+	* 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@r...>
 
 	* test/ruby/test_process.rb (MANDATORY_ENVS): needs RUBYLIB to run
Index: io.c
===================================================================
--- io.c	(revision 21733)
+++ io.c	(revision 21734)
@@ -5971,13 +5971,15 @@
     fd = NUM2INT(fnum);
     if (fstat(fd, &st) == -1) rb_sys_fail(0);
     UPDATE_MAXFD(fd);
+#if defined(HAVE_FCNTL) && defined(F_GETFL)
     if (NIL_P(vmode)) {
-#if defined(HAVE_FCNTL) && defined(F_GETFL)
         oflags = fcntl(fd, F_GETFL);
         if (oflags == -1) rb_sys_fail(0);
         fmode = rb_io_oflags_fmode(oflags);
+    }
+#elif defined(_WIN32)
+    if (rb_w32_is_valid_fd(fd)) rb_sys_fail(0);
 #endif
-    }
     MakeOpenFile(io, fp);
     fp->fd = fd;
     fp->mode = fmode;
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 21733)
+++ win32/win32.c	(revision 21734)
@@ -1836,6 +1836,15 @@
 }
 #endif
 
+int
+rb_w32_is_valid_fd(int fd)
+{
+    if (_get_osfhandle(fd) == -1)
+	return -1;
+    else
+	return 0;
+}
+
 #undef getsockopt
 
 static int

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

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