Skip to content

Commit 5d21b33

Browse files
committed
unix-ffi/os: Add uos shim, process constants, setpgid, fix walk mode.
Prepend the python-stdlib os shim (from uos import *, path import) so the unix-ffi os module re-exports built-in uos functions. Add WNOHANG, SIGKILL, SIGTERM constants and setpgid() for process management. Fix walk() to use the raw st_mode from ilistdir instead of left-shifting it by 12 bits. Made-with: Cursor
1 parent 328ae63 commit 5d21b33

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

unix-ffi/os/os/__init__.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Replace built-in os module.
2+
from uos import *
3+
4+
# Provide optional dependencies (which may be installed separately).
5+
try:
6+
from . import path
7+
except ImportError:
8+
pass
9+
10+
11+
112
import array
213
import struct
314
import errno as errno_
@@ -10,17 +21,22 @@
1021
X_OK = const(1)
1122
F_OK = const(0)
1223

13-
O_ACCMODE = 0o0000003
14-
O_RDONLY = 0o0000000
15-
O_WRONLY = 0o0000001
16-
O_RDWR = 0o0000002
17-
O_CREAT = 0o0000100
18-
O_EXCL = 0o0000200
19-
O_NOCTTY = 0o0000400
20-
O_TRUNC = 0o0001000
21-
O_APPEND = 0o0002000
24+
O_ACCMODE = 0o0000003
25+
O_RDONLY = 0o0000000
26+
O_WRONLY = 0o0000001
27+
O_RDWR = 0o0000002
28+
O_CREAT = 0o0000100
29+
O_EXCL = 0o0000200
30+
O_NOCTTY = 0o0000400
31+
O_TRUNC = 0o0001000
32+
O_APPEND = 0o0002000
2233
O_NONBLOCK = 0o0004000
2334

35+
WNOHANG = 0x00000001
36+
37+
SIGKILL = 9
38+
SIGTERM = 15
39+
2440
error = OSError
2541
name = "posix"
2642
sep = "/"
@@ -55,6 +71,8 @@
5571
execvp_ = libc.func("i", "execvp", "PP")
5672
kill_ = libc.func("i", "kill", "ii")
5773
getenv_ = libc.func("s", "getenv", "P")
74+
setpgid_ = libc.func("i", "setpgid", "ii")
75+
5876

5977

6078
def check_error(ret):
@@ -162,7 +180,7 @@ def walk(top, topdown=True):
162180
files = []
163181
dirs = []
164182
for dirent in ilistdir(top):
165-
mode = dirent[1] << 12
183+
mode = dirent[1]
166184
fname = fsdecode(dirent[0])
167185
if stat_.S_ISDIR(mode):
168186
if fname != "." and fname != "..":
@@ -261,6 +279,10 @@ def kill(pid, sig):
261279
r = kill_(pid, sig)
262280
check_error(r)
263281

282+
def setpgid(pid, pgid):
283+
r = setpgid_(pid, pgid)
284+
check_error(r)
285+
return r
264286

265287
def system(command):
266288
r = system_(command)

0 commit comments

Comments
 (0)