os: Rely on uos.errno() to manipulate errno.

FFI implementation is pretty hacky and not portable/scalable. So, just
have hard requirement on uos.errno().
pull/65/merge
Paul Sokolovsky 2015-12-16 19:31:28 +02:00
rodzic 76efae4aaa
commit db1b0ef816
1 zmienionych plików z 7 dodań i 25 usunięć

Wyświetl plik

@ -1,13 +1,10 @@
import ffi import ffi
import array import array
import ustruct as struct import ustruct as struct
import errno import errno as errno_
import stat as stat_ import stat as stat_
import ffilib import ffilib
try: import uos
from uos import *
except:
pass
R_OK = const(4) R_OK = const(4)
W_OK = const(2) W_OK = const(2)
@ -35,21 +32,6 @@ environ = {"WARNING": "NOT_IMPLEMENTED"}
libc = ffilib.libc() libc = ffilib.libc()
try:
errno__ = libc.var("i", "errno")
def errno_(val=None):
if val is None:
return errno__.get()
errno__.set(val)
except OSError:
__errno = libc.func("p", "__errno", "")
def errno_(val=None):
if val is None:
p = __errno()
buf = ffi.as_bytearray(p, 4)
return int.from_bytes(buf)
raise NotImplementedError
chdir_ = libc.func("i", "chdir", "s") chdir_ = libc.func("i", "chdir", "s")
mkdir_ = libc.func("i", "mkdir", "si") mkdir_ = libc.func("i", "mkdir", "si")
rename_ = libc.func("i", "rename", "ss") rename_ = libc.func("i", "rename", "ss")
@ -79,13 +61,13 @@ def check_error(ret):
# Return True is error was EINTR (which usually means that OS call # Return True is error was EINTR (which usually means that OS call
# should be restarted). # should be restarted).
if ret == -1: if ret == -1:
e = errno_() e = uos.errno()
if e == errno.EINTR: if e == errno_.EINTR:
return True return True
raise OSError(e) raise OSError(e)
def raise_error(): def raise_error():
raise OSError(errno_.get()) raise OSError(uos.errno())
def getcwd(): def getcwd():
@ -113,14 +95,14 @@ def makedirs(name, mode=0o777, exist_ok=False):
if exists: if exists:
if exist_ok: if exist_ok:
return return
raise OSError(errno.EEXIST) raise OSError(errno_.EEXIST)
s = "" s = ""
for c in name.split("/"): for c in name.split("/"):
s += c + "/" s += c + "/"
try: try:
mkdir(s) mkdir(s)
except OSError as e: except OSError as e:
if e.args[0] != errno.EEXIST: if e.args[0] != errno_.EEXIST:
raise raise
def ilistdir(path="."): def ilistdir(path="."):