diff --git a/fcntl/fcntl.py b/fcntl/fcntl.py new file mode 100644 index 00000000..b36879c6 --- /dev/null +++ b/fcntl/fcntl.py @@ -0,0 +1,23 @@ +import ffi + + +libc = ffi.open("libc.so.6") + +fcntl_l = libc.func("i", "fcntl", "iil") +fcntl_s = libc.func("i", "fcntl", "iis") +ioctl_l = libc.func("i", "ioctl", "iil") +ioctl_s = libc.func("i", "ioctl", "iis") + + +def fcntl(fd, op, arg): + if type(arg) is int: + return fcntl_l(fd, op, arg) + else: + raise NotImplementedError + + +def ioctl(fd, op, arg): + if type(arg) is int: + return ioctl_l(fd, op, arg) + else: + raise NotImplementedError diff --git a/os/os.py b/os/os.py new file mode 100644 index 00000000..5d240ca1 --- /dev/null +++ b/os/os.py @@ -0,0 +1,14 @@ +import ffi + + +libc = ffi.open("libc.so.6") + +errno = libc.var("i", "errno") +mkdir_ = libc.func("i", "mkdir", "si") + + +def mkdir(name, mode=0o777): + e = mkdir_(name, mode) + if not e: + return + raise OSError(errno.get())