2014-04-02 16:04:43 +00:00
|
|
|
import ffi
|
2014-12-25 18:41:45 +00:00
|
|
|
import os
|
2014-06-21 11:52:03 +00:00
|
|
|
import _libc
|
2014-04-02 16:04:43 +00:00
|
|
|
|
|
|
|
|
2014-06-21 11:52:03 +00:00
|
|
|
libc = _libc.get()
|
2014-04-02 16:04:43 +00:00
|
|
|
|
|
|
|
fcntl_l = libc.func("i", "fcntl", "iil")
|
2014-04-21 21:39:21 +00:00
|
|
|
fcntl_s = libc.func("i", "fcntl", "iip")
|
2014-04-02 16:04:43 +00:00
|
|
|
ioctl_l = libc.func("i", "ioctl", "iil")
|
2014-04-21 21:39:21 +00:00
|
|
|
ioctl_s = libc.func("i", "ioctl", "iip")
|
2014-04-02 16:04:43 +00:00
|
|
|
|
|
|
|
|
2014-12-24 15:58:02 +00:00
|
|
|
def fcntl(fd, op, arg=0):
|
2014-04-02 16:04:43 +00:00
|
|
|
if type(arg) is int:
|
2014-12-25 18:41:45 +00:00
|
|
|
r = fcntl_l(fd, op, arg)
|
|
|
|
os.check_error(r)
|
|
|
|
return r
|
2014-04-02 16:04:43 +00:00
|
|
|
else:
|
2014-12-25 18:41:45 +00:00
|
|
|
r = fcntl_s(fd, op, arg)
|
|
|
|
os.check_error(r)
|
|
|
|
# TODO: Not compliant. CPython says that arg should be immutable,
|
|
|
|
# and possibly mutated buffer is returned.
|
|
|
|
return r
|
2014-04-02 16:04:43 +00:00
|
|
|
|
|
|
|
|
2014-12-25 18:41:45 +00:00
|
|
|
def ioctl(fd, op, arg=0, mut=False):
|
2014-04-02 16:04:43 +00:00
|
|
|
if type(arg) is int:
|
2014-12-25 18:41:45 +00:00
|
|
|
r = ioctl_l(fd, op, arg)
|
|
|
|
os.check_error(r)
|
|
|
|
return r
|
2014-04-02 16:04:43 +00:00
|
|
|
else:
|
2014-12-25 18:41:45 +00:00
|
|
|
# TODO
|
|
|
|
assert mut
|
|
|
|
r = ioctl_s(fd, op, arg)
|
|
|
|
os.check_error(r)
|
|
|
|
return r
|