Skip to content

Commit a1cf086

Browse files
committed
os: Implement execvp().
1 parent fff07bd commit a1cf086

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

os/os/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def errno_(val=None):
4747
getpid_ = libc.func("i", "getpid", "")
4848
waitpid_ = libc.func("i", "waitpid", "ipi")
4949
system_ = libc.func("i", "system", "s")
50+
execvp_ = libc.func("i", "execvp", "PP")
5051
getenv_ = libc.func("s", "getenv", "P")
5152

5253
R_OK = const(4)
@@ -211,6 +212,16 @@ def pipe():
211212
def _exit(n):
212213
_exit_(n)
213214

215+
def execvp(f, args):
216+
import uctypes
217+
args_ = array.array("P", [0] * (len(args) + 1))
218+
i = 0
219+
for a in args:
220+
args_[i] = uctypes.addressof(a)
221+
i += 1
222+
r = execvp_(f, uctypes.addressof(args_))
223+
check_error(r)
224+
214225
def getpid():
215226
return getpid_()
216227

0 commit comments

Comments
 (0)