Skip to content

Commit 7232fc3

Browse files
authored
Merge pull request #533 from xushiwei/q
library os: StartProcess/Wait/Sysctl/environ; syscall.Wait4; c/syscall: zerrors; c/os: Setrlimit/Getrlimit;
2 parents 1cf5750 + a8e1fd1 commit 7232fc3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+50147
-636
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ The currently supported libraries include:
215215
* [c/clang](https://pkg.go.dev/github.com/goplus/llgo/c/clang)
216216
* [c/llama2](https://pkg.go.dev/github.com/goplus/llgo/c/llama2)
217217
* [c/lua](https://pkg.go.dev/github.com/goplus/llgo/c/lua)
218+
* [c/neco](https://pkg.go.dev/github.com/goplus/llgo/c/neco)
218219
* [c/raylib](https://pkg.go.dev/github.com/goplus/llgo/c/raylib)
219220
* [c/sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)
220221
* [c/zlib](https://pkg.go.dev/github.com/goplus/llgo/c/zlib)

_cmptest/osproc/exec.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"runtime"
8+
)
9+
10+
func main() {
11+
ls := "ls"
12+
args := []string{ls, "-l"}
13+
if runtime.GOOS == "windows" {
14+
ls = "dir"
15+
args = []string{ls}
16+
}
17+
lspath, _ := exec.LookPath(ls)
18+
if lspath != "" {
19+
ls = lspath
20+
}
21+
proc, err := os.StartProcess(ls, args, &os.ProcAttr{
22+
Files: []*os.File{nil, os.Stdout, os.Stderr},
23+
})
24+
if err != nil {
25+
fmt.Println("os.StartProcess error:", err)
26+
return
27+
}
28+
proc.Wait()
29+
fmt.Println("proc.Wait done")
30+
}

c/os/os.go

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,49 @@ func Execve(path *c.Char, argv **c.Char, envp **c.Char) c.Int
263263
//go:linkname Execvp C.execvp
264264
func Execvp(file *c.Char, argv **c.Char) c.Int
265265

266-
//go:linkname Fork C.fork
267-
func Fork() c.Int
266+
// -----------------------------------------------------------------------------
268267

269-
//go:linkname Kill C.kill
270-
func Kill(pid c.Int, sig c.Int) c.Int
268+
type PidT c.Int
271269

272-
//go:linkname Exit C.exit
273-
func Exit(c.Int)
270+
//go:linkname Fork C.fork
271+
func Fork() PidT
274272

275273
//go:linkname Getpid C.getpid
276-
func Getpid() c.Int
274+
func Getpid() PidT
277275

278276
//go:linkname Getppid C.getppid
279-
func Getppid() c.Int
277+
func Getppid() PidT
278+
279+
//go:linkname Kill C.kill
280+
func Kill(pid PidT, sig c.Int) c.Int
281+
282+
// If wait() returns due to a stopped or terminated child process, the process ID
283+
// of the child is returned to the calling process. Otherwise, a value of -1 is
284+
// returned and errno is set to indicate the error.
285+
//
286+
//go:linkname Wait C.wait
287+
func Wait(statLoc *c.Int) PidT
288+
289+
// If wait3(), wait4(), or waitpid() returns due to a stopped or terminated child
290+
// process, the process ID of the child is returned to the calling process. If
291+
// there are no children not previously awaited, -1 is returned with errno set to
292+
// [ECHILD]. Otherwise, if WNOHANG is specified and there are no stopped or exited
293+
// children, 0 is returned. If an error is detected or a caught signal aborts the
294+
// call, a value of -1 is returned and errno is set to indicate the error.
295+
//
296+
//go:linkname Wait3 C.wait3
297+
func Wait3(statLoc *c.Int, options c.Int, rusage *syscall.Rusage) PidT
298+
299+
//go:linkname Wait4 C.wait4
300+
func Wait4(pid PidT, statLoc *c.Int, options c.Int, rusage *syscall.Rusage) PidT
301+
302+
//go:linkname Waitpid C.waitpid
303+
func Waitpid(pid PidT, statLoc *c.Int, options c.Int) PidT
304+
305+
// -----------------------------------------------------------------------------
306+
307+
//go:linkname Exit C.exit
308+
func Exit(c.Int)
280309

281310
//go:linkname Getuid C.getuid
282311
func Getuid() UidT
@@ -291,3 +320,43 @@ func Getgid() GidT
291320
func Getegid() GidT
292321

293322
// -----------------------------------------------------------------------------
323+
324+
//go:linkname Getrlimit C.getrlimit
325+
func Getrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
326+
327+
//go:linkname Setrlimit C.setrlimit
328+
func Setrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
329+
330+
// -----------------------------------------------------------------------------
331+
332+
// Upon successful completion, the value 0 is returned; otherwise the value -1
333+
// is returned and the global variable errno is set to indicate the error.
334+
//
335+
//go:linkname Sysctl C.sysctl
336+
func Sysctl(
337+
name *c.Int, namelen c.Uint,
338+
oldp c.Pointer, oldlenp *uintptr,
339+
newp c.Pointer, newlen uintptr) c.Int
340+
341+
//go:linkname Sysctlbyname C.sysctlbyname
342+
func Sysctlbyname(
343+
name *c.Char, oldp c.Pointer, oldlenp *uintptr,
344+
newp c.Pointer, newlen uintptr) c.Int
345+
346+
// The sysctlnametomib() function accepts an ASCII representation of the
347+
// name, looks up the integer name vector, and returns the numeric repre-
348+
// sentation in the mib array pointed to by mibp. The number of elements
349+
// in the mib array is given by the location specified by sizep before the
350+
// call, and that location gives the number of entries copied after a suc-
351+
// cessful call. The resulting mib and size may be used in subsequent
352+
// sysctl() calls to get the data associated with the requested ASCII
353+
// name. This interface is intended for use by applications that want to
354+
// repeatedly request the same variable (the sysctl() function runs in
355+
// about a third the time as the same request made via the sysctlbyname()
356+
// function). The sysctlnametomib() function is also useful for fetching
357+
// mib prefixes and then adding a final component.
358+
//
359+
//go:linkname Sysctlnametomib C.sysctlnametomib
360+
func Sysctlnametomib(name *c.Char, mibp *c.Int, sizep *uintptr) c.Int
361+
362+
// -----------------------------------------------------------------------------

c/syscall/syscall.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ package syscall
1919
const (
2020
LLGoPackage = "decl"
2121
)
22+
23+
type Errno = uintptr
24+
25+
// A Signal is a number describing a process signal.
26+
// It implements the os.Signal interface.
27+
type Signal = int

0 commit comments

Comments
 (0)