From 27ec4eb7003993dd329923c50517d70c51e4f865 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 2 Apr 2014 19:04:43 +0300 Subject: [PATCH] Add very basic implementation of os and fcntl modules for unix port. Using ffi module. Both offer just 1-2 initial functions so far. --- fcntl/fcntl.py | 23 +++++++++++++++++++++++ os/os.py | 14 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 fcntl/fcntl.py create mode 100644 os/os.py 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())