syscall.Wait4

This commit is contained in:
xushiwei
2024-07-18 17:08:24 +08:00
parent daf0a9dc9a
commit db8cc8eb7b
5 changed files with 255 additions and 205 deletions

View File

@@ -78,13 +78,21 @@ func Getpid() (pid int) {
}
func Kill(pid int, signum Signal) (err error) {
ret := os.Kill(c.Int(pid), c.Int(signum))
ret := os.Kill(os.PidT(pid), c.Int(signum))
if ret == 0 {
return nil
}
return Errno(ret)
}
func wait4(pid int, wstatus *c.Int, options int, rusage *syscall.Rusage) (wpid int, err error) {
ret := os.Wait4(os.PidT(pid), wstatus, c.Int(options), rusage)
if ret >= 0 {
return int(ret), nil
}
return 0, Errno(os.Errno)
}
func Open(path string, mode int, perm uint32) (fd int, err error) {
ret := os.Open(c.AllocaCStr(path), c.Int(mode), os.ModeT(perm))
if ret >= 0 {
@@ -109,6 +117,14 @@ func Read(fd int, p []byte) (n int, err error) {
return 0, Errno(os.Errno)
}
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
ret := os.Read(c.Int(fd), unsafe.Pointer(buf), uintptr(nbuf))
if ret >= 0 {
return ret, nil // TODO(xsw): confirm err == nil (not io.EOF) when ret == 0
}
return 0, Errno(os.Errno)
}
func Close(fd int) (err error) {
ret := os.Close(c.Int(fd))
if ret == 0 {