ruby-changes:21790
From: kosaki <ko1@a...>
Date: Fri, 25 Nov 2011 11:46:02 +0900 (JST)
Subject: [ruby-changes:21790] kosaki:r33839 (trunk): * io.c (ioctl_narg_len, linux_iocparm_len): reinstantiate linux
kosaki 2011-11-25 11:45:50 +0900 (Fri, 25 Nov 2011) New Revision: 33839 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33839 Log: * io.c (ioctl_narg_len, linux_iocparm_len): reinstantiate linux specific narg length calculation. * test/ruby/test_io.rb (test_ioctl_linux2): add new test for old and unstructured ioctl. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33838) +++ ChangeLog (revision 33839) @@ -1,3 +1,10 @@ +Fri Nov 25 11:37:07 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (ioctl_narg_len, linux_iocparm_len): reinstantiate linux + specific narg length calculation. + * test/ruby/test_io.rb (test_ioctl_linux2): add new test for old and + unstructured ioctl. + Fri Nov 25 10:39:14 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * Makefile.in (EXTLDFLAGS): export it. Index: io.c =================================================================== --- io.c (revision 33838) +++ io.c (revision 33839) @@ -7966,7 +7966,30 @@ return retval; } +#define DEFULT_IOCTL_NARG_LEN (256) + +#ifdef __linux__ static long +linux_iocparm_len(ioctl_req_t cmd) +{ + long len; + + if ((cmd & 0xFFFF0000) == 0) { + /* legacy and unstructured ioctl number. */ + return DEFULT_IOCTL_NARG_LEN; + } + + len = _IOC_SIZE(cmd); + + /* paranoia check for silly drivers which don't keep ioctl convention */ + if (len < DEFULT_IOCTL_NARG_LEN) + len = DEFULT_IOCTL_NARG_LEN; + + return len; +} +#endif + +static long ioctl_narg_len(ioctl_req_t cmd) { long len; @@ -7978,8 +8001,11 @@ #endif #ifdef IOCPARM_LEN len = IOCPARM_LEN(cmd); /* on BSDish systems we're safe */ +#elif defined(__linux__) + len = linux_iocparm_len(cmd); #else - len = 256; /* otherwise guess at what's safe */ + /* otherwise guess at what's safe */ + len = DEFULT_IOCTL_NARG_LEN; #endif return len; Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 33838) +++ test/ruby/test_io.rb (revision 33839) @@ -2123,6 +2123,19 @@ assert_equal(File.size(__FILE__), buf.unpack('i!')[0]) end + def test_ioctl_linux2 + return if /linux/ !~ RUBY_PLATFORM + return if /^i?86|^x86_64/ !~ RUBY_PLATFORM + + File.open('/dev/tty') { |f| + tiocgwinsz=0x5413 + winsize="" + assert_nothing_raised { + f.ioctl(tiocgwinsz, winsize) + } + } + end + def test_setpos mkcdtmpdir { File.open("tmp.txt", "w") {|f| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/