Attached is a patch that implements sb-posix:ioctl and makes some
improvements to sb-posix:open.
In its manpage, ioctl() is declared with a variable argument list. I
couldn't find a decent way to define such a foreign function, but
luckily POSIX says in the section on ioctl():
The arg argument represents additional information that is needed by this
specific STREAMS device to perform the requested function. The type of arg
depends upon the particular control request, but it shall be either an
integer or a pointer to a device-specific data structure.
I'm not sure what a STREAMS device is, but it's good to know that it
takes only two types of arguments to ioctl calls. Furthermore, the
ioctl_list man page on Linux lists only ioctl commands with pointer,
int or void arguments, so I took the rather low-tech approach of
defining three foreign calls and one wrapper function. I hope this
doesn't meet too much disapproval.
Then there's the ioctl commands. It would be nice to have all of them
available. `All' turns out to be rather a lot, so some automated means
of achieving this is perferable. Extracting a list from POSIX would be
an option, except that I can only find ioctl commands for STREAMS
devices (I_*). I don't think those are used very often, at least not by
There's also the option of extracting a list from /usr/include/*. I've
tried writing a script that does that. Needless to say that it is not a
complete solution, and it doesn't extract the `device specific data
structures' anyway. I don't think this is the way to go, but in case
you're interested (in the script itself, or for instance in a rough
estimate of the number of ioctl commands your system has), it is
attached as list-ioctls.sh.
So I'm afraid manually adding the commands and structures on an as-needed
basis (possibly using the output of some variation of list-ioctls.sh) is
the best solution.
Tests for ioctl would be nice too, but I think it's quite hard to come up
with any that are portable.
* A similar approach as the one with sb-posix:ioctl is used to make the
mode argument optional.
* Added the flags O_RDONLY, O_WRONLY and O_RDWR (one of these is
required in each call to open).
* Added O_DSYNC and O_RSYNC (found in POSIX).
* Added two tests.