ruby-changes:21667
From: kosaki <ko1@a...>
Date: Sat, 12 Nov 2011 11:25:01 +0900 (JST)
Subject: [ruby-changes:21667] kosaki:r33716 (trunk): * io.c (ioctl_req_t): Type of req argument of ioctl() depend on platform.
kosaki 2011-11-12 11:24:51 +0900 (Sat, 12 Nov 2011) New Revision: 33716 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33716 Log: * io.c (ioctl_req_t): Type of req argument of ioctl() depend on platform. Moreover almost all linux ioctl can't be represented by 32bit integer (i.e. MSB is 1). We need wrap ioctl argument type. [Bug #5429] [ruby-dev:44589] * io.c (struct ioctl_arg): ditto. * io.c (rb_ioctl): ditto. * test/ruby/test_io.rb (test_ioctl_linux): add a testcase for ioctl Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33715) +++ ChangeLog (revision 33716) @@ -1,3 +1,13 @@ +Sat Nov 12 11:06:02 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (ioctl_req_t): Type of req argument of ioctl() depend on platform. + Moreover almost all linux ioctl can't be represented by 32bit integer + (i.e. MSB is 1). We need wrap ioctl argument type. + [Bug #5429] [ruby-dev:44589] + * io.c (struct ioctl_arg): ditto. + * io.c (rb_ioctl): ditto. + * test/ruby/test_io.rb (test_ioctl_linux): add a testcase for ioctl + Sat Nov 12 11:00:42 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * io.c (struct io_cntl_arg): remove io_p member. Index: io.c =================================================================== --- io.c (revision 33715) +++ io.c (revision 33716) @@ -7860,9 +7860,17 @@ return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args); } +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) + typedef unsigned long ioctl_req_t; + #define NUM2IOCTLREQ(num) NUM2ULONG(num) +#else + typedef int ioctl_req_t; + #define NUM2IOCTLREQ(num) NUM2INT(num) +#endif + struct ioctl_arg { int fd; - int cmd; + ioctl_req_t cmd; long narg; }; @@ -7954,7 +7962,7 @@ static VALUE rb_ioctl(VALUE io, VALUE req, VALUE arg) { - int cmd = NUM2INT(req); + int cmd = NUM2IOCTLREQ(req); rb_io_t *fptr; long narg; int retval; Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 33715) +++ test/ruby/test_io.rb (revision 33716) @@ -2055,4 +2055,16 @@ assert(w.close_on_exec?) } end + + def test_ioctl_linux + return if /linux/ !~ RUBY_PLATFORM + + assert_nothing_raised do + File.open('/dev/urandom'){|f1| + entropy_count = "" + # get entropy count + f1.ioctl(0x80045200, entropy_count) + } + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/