From fd8d9d9dceb445099aacbe75eb08246925c98527 Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 23 Nov 2011 11:24:49 +0000 Subject: * io.c (ioctl_narg_len): don't use _IOC_SIZE macro on Linux. On Linux some constants for ioctl(2) doesn't include the size of its return value and 16bit value; for example FIONREAD 0x541B. Moreover the manual, ioctl_list(2), says "Note that the size bits are very unreliable: in lots of cases they are wrong, either because of buggy macros using sizeof(sizeof(struct)), or because of legacy values." So we shouldn't use it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ io.c | 2 -- test/ruby/test_io.rb | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa72628da5..84264a6cee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Nov 23 20:03:43 2011 NARUSE, Yui + + * io.c (ioctl_narg_len): don't use _IOC_SIZE macro on Linux. + On Linux some constants for ioctl(2) doesn't include the size of + its return value and 16bit value; for example FIONREAD 0x541B. + Moreover the manual, ioctl_list(2), says "Note that the size + bits are very unreliable: in lots of cases they are wrong, + either because of buggy macros using sizeof(sizeof(struct)), + or because of legacy values." + So we shouldn't use it. + Tue Nov 22 18:07:32 2011 NAKAMURA Usaku * win32/win32.c (_pioinfo): need to declare _pioinfo() before using diff --git a/io.c b/io.c index 81da283384..0410e6339f 100644 --- a/io.c +++ b/io.c @@ -7956,8 +7956,6 @@ ioctl_narg_len(ioctl_req_t cmd) #endif #ifdef IOCPARM_LEN len = IOCPARM_LEN(cmd); /* on BSDish systems we're safe */ -#elif defined(_IOC_SIZE) - len = _IOC_SIZE(cmd); #else len = 256; /* otherwise guess at what's safe */ #endif diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f1fc3233b6..d877f5e832 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2112,5 +2112,14 @@ End f1.ioctl(0x80045200, entropy_count) } end + + buf = '' + assert_nothing_raised do + fionread = 0x541B + File.open(__FILE__){|f1| + f1.ioctl(fionread, buf) + } + end + assert_equal(File.size(__FILE__), buf.unpack('i!')[0]) end end -- cgit v1.2.3