summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--io.c28
-rw-r--r--test/ruby/test_io.rb13
3 files changed, 47 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7cf9e981f1..3828351f83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Nov 25 11:37:07 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * 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@gmail.com>
* Makefile.in (EXTLDFLAGS): export it.
diff --git a/io.c b/io.c
index 3f35c1982c..07b38c5c40 100644
--- a/io.c
+++ b/io.c
@@ -7966,6 +7966,29 @@ do_ioctl(int fd, ioctl_req_t cmd, long narg)
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)
{
@@ -7978,8 +8001,11 @@ ioctl_narg_len(ioctl_req_t cmd)
#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;
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 8899994897..01b3e681e5 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2123,6 +2123,19 @@ End
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|