kopia lustrzana https://github.com/micropython/micropython-lib
os: Add access().
rodzic
d75ad4867d
commit
b5a6cbb4ae
|
@ -12,12 +12,18 @@ readdir_ = libc.func("P", "readdir", "P")
|
||||||
read_ = libc.func("i", "read", "ipi")
|
read_ = libc.func("i", "read", "ipi")
|
||||||
write_ = libc.func("i", "write", "iPi")
|
write_ = libc.func("i", "write", "iPi")
|
||||||
close_ = libc.func("i", "close", "i")
|
close_ = libc.func("i", "close", "i")
|
||||||
|
access_ = libc.func("i", "access", "si")
|
||||||
fork_ = libc.func("i", "fork", "")
|
fork_ = libc.func("i", "fork", "")
|
||||||
pipe_ = libc.func("i", "pipe", "p")
|
pipe_ = libc.func("i", "pipe", "p")
|
||||||
_exit_ = libc.func("v", "_exit", "i")
|
_exit_ = libc.func("v", "_exit", "i")
|
||||||
getpid_ = libc.func("i", "getpid", "")
|
getpid_ = libc.func("i", "getpid", "")
|
||||||
waitpid_ = libc.func("i", "waitpid", "ipi")
|
waitpid_ = libc.func("i", "waitpid", "ipi")
|
||||||
|
|
||||||
|
R_OK = const(4)
|
||||||
|
W_OK = const(2)
|
||||||
|
X_OK = const(1)
|
||||||
|
F_OK = const(0)
|
||||||
|
|
||||||
|
|
||||||
def check_error(ret):
|
def check_error(ret):
|
||||||
if ret == -1:
|
if ret == -1:
|
||||||
|
@ -61,6 +67,8 @@ def close(fd):
|
||||||
check_error(r)
|
check_error(r)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def access(path, mode):
|
||||||
|
return access_(path, mode) == 0
|
||||||
|
|
||||||
def fork():
|
def fork():
|
||||||
r = fork_()
|
r = fork_()
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
assert os.access("test_filestat.py", os.F_OK) == True
|
||||||
|
assert os.access("test_filestat.py-not", os.F_OK) == False
|
Ładowanie…
Reference in New Issue