Skip to content

Commit db1b0ef

Browse files
committed
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().
1 parent 76efae4 commit db1b0ef

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

os/os/__init__.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import ffi
22
import array
33
import ustruct as struct
4-
import errno
4+
import errno as errno_
55
import stat as stat_
66
import ffilib
7-
try:
8-
from uos import *
9-
except:
10-
pass
7+
import uos
118

129
R_OK = const(4)
1310
W_OK = const(2)
@@ -35,21 +32,6 @@
3532

3633
libc = ffilib.libc()
3734

38-
try:
39-
errno__ = libc.var("i", "errno")
40-
def errno_(val=None):
41-
if val is None:
42-
return errno__.get()
43-
errno__.set(val)
44-
except OSError:
45-
__errno = libc.func("p", "__errno", "")
46-
def errno_(val=None):
47-
if val is None:
48-
p = __errno()
49-
buf = ffi.as_bytearray(p, 4)
50-
return int.from_bytes(buf)
51-
raise NotImplementedError
52-
5335
chdir_ = libc.func("i", "chdir", "s")
5436
mkdir_ = libc.func("i", "mkdir", "si")
5537
rename_ = libc.func("i", "rename", "ss")
@@ -79,13 +61,13 @@ def check_error(ret):
7961
# Return True is error was EINTR (which usually means that OS call
8062
# should be restarted).
8163
if ret == -1:
82-
e = errno_()
83-
if e == errno.EINTR:
64+
e = uos.errno()
65+
if e == errno_.EINTR:
8466
return True
8567
raise OSError(e)
8668

8769
def raise_error():
88-
raise OSError(errno_.get())
70+
raise OSError(uos.errno())
8971

9072

9173
def getcwd():
@@ -113,14 +95,14 @@ def makedirs(name, mode=0o777, exist_ok=False):
11395
if exists:
11496
if exist_ok:
11597
return
116-
raise OSError(errno.EEXIST)
98+
raise OSError(errno_.EEXIST)
11799
s = ""
118100
for c in name.split("/"):
119101
s += c + "/"
120102
try:
121103
mkdir(s)
122104
except OSError as e:
123-
if e.args[0] != errno.EEXIST:
105+
if e.args[0] != errno_.EEXIST:
124106
raise
125107

126108
def ilistdir(path="."):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy