summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-25 02:45:50 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-25 02:45:50 +0000
commitaa23f6b9fdecbf3be3e21b0f6b40e2b22f125090 (patch)
treefcdd938f347b4c1fb5c75639e334f6b7fec60771 /io.c
parent0996ae361a62db5094eb3d8cc59c7d002170c285 (diff)
downloadruby-aa23f6b9fdecbf3be3e21b0f6b40e2b22f125090.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c28
1 files changed, 27 insertions, 1 deletions
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;