kopia lustrzana https://github.com/micropython/micropython-lib
os: Implement few file and process functions.
rodzic
3e8cd1de1b
commit
5ec9531764
25
os/os.py
25
os/os.py
|
@ -1,4 +1,5 @@
|
|||
import ffi
|
||||
import array
|
||||
|
||||
|
||||
libc = ffi.open("libc.so.6")
|
||||
|
@ -7,6 +8,10 @@ errno = libc.var("i", "errno")
|
|||
mkdir_ = libc.func("i", "mkdir", "si")
|
||||
read_ = libc.func("i", "read", "ipi")
|
||||
write_ = libc.func("i", "write", "iPi")
|
||||
close_ = libc.func("i", "close", "i")
|
||||
fork_ = libc.func("i", "fork", "")
|
||||
pipe_ = libc.func("i", "pipe", "p")
|
||||
_exit_ = libc.func("v", "_exit", "i")
|
||||
|
||||
|
||||
def check_error(ret):
|
||||
|
@ -28,3 +33,23 @@ def write(fd, buf):
|
|||
r = write_(fd, buf, len(buf))
|
||||
check_error(r)
|
||||
return r
|
||||
|
||||
def close(fd):
|
||||
r = close_(fd)
|
||||
check_error(r)
|
||||
return r
|
||||
|
||||
|
||||
def fork():
|
||||
r = fork_()
|
||||
check_error(r)
|
||||
return r
|
||||
|
||||
def pipe():
|
||||
a = array.array('i', [0, 0])
|
||||
r = pipe_(a)
|
||||
check_error(r)
|
||||
return a[0], a[1]
|
||||
|
||||
def _exit(n):
|
||||
_exit_(n)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from distutils.core import setup
|
||||
|
||||
setup(name='micropython-os',
|
||||
version='0.0.2',
|
||||
version='0.0.3',
|
||||
description='os module for MicroPython',
|
||||
url='https://github.com/micropython/micropython/issues/405',
|
||||
author='MicroPython Developers',
|
||||
|
|
Ładowanie…
Reference in New Issue