os.Sysctl
This commit is contained in:
32
c/os/os.go
32
c/os/os.go
@@ -328,3 +328,35 @@ func Getrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
|||||||
func Setrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
func Setrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Upon successful completion, the value 0 is returned; otherwise the value -1
|
||||||
|
// is returned and the global variable errno is set to indicate the error.
|
||||||
|
//
|
||||||
|
//go:linkname Sysctl C.sysctl
|
||||||
|
func Sysctl(
|
||||||
|
name *c.Int, namelen c.Uint,
|
||||||
|
oldp c.Pointer, oldlenp *uintptr,
|
||||||
|
newp c.Pointer, newlen uintptr) c.Int
|
||||||
|
|
||||||
|
//go:linkname Sysctlbyname C.sysctlbyname
|
||||||
|
func Sysctlbyname(
|
||||||
|
name *c.Char, oldp c.Pointer, oldlenp *uintptr,
|
||||||
|
newp c.Pointer, newlen uintptr) c.Int
|
||||||
|
|
||||||
|
// The sysctlnametomib() function accepts an ASCII representation of the
|
||||||
|
// name, looks up the integer name vector, and returns the numeric repre-
|
||||||
|
// sentation in the mib array pointed to by mibp. The number of elements
|
||||||
|
// in the mib array is given by the location specified by sizep before the
|
||||||
|
// call, and that location gives the number of entries copied after a suc-
|
||||||
|
// cessful call. The resulting mib and size may be used in subsequent
|
||||||
|
// sysctl() calls to get the data associated with the requested ASCII
|
||||||
|
// name. This interface is intended for use by applications that want to
|
||||||
|
// repeatedly request the same variable (the sysctl() function runs in
|
||||||
|
// about a third the time as the same request made via the sysctlbyname()
|
||||||
|
// function). The sysctlnametomib() function is also useful for fetching
|
||||||
|
// mib prefixes and then adding a final component.
|
||||||
|
//
|
||||||
|
//go:linkname Sysctlnametomib C.sysctlnametomib
|
||||||
|
func Sysctlnametomib(name *c.Char, mibp *c.Int, sizep *uintptr) c.Int
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,7 +13,10 @@
|
|||||||
package syscall
|
package syscall
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
|
"github.com/goplus/llgo/c/os"
|
||||||
"github.com/goplus/llgo/c/syscall"
|
"github.com/goplus/llgo/c/syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -456,11 +459,16 @@ func SysctlUint32(name string) (value uint32, err error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if n != 4 {
|
if n != 4 {
|
||||||
return 0, EIO
|
return 0, Errno(syscall.EIO)
|
||||||
}
|
}
|
||||||
return *(*uint32)(unsafe.Pointer(&buf[0])), nil
|
return *(*uint32)(unsafe.Pointer(&buf[0])), nil
|
||||||
*/
|
*/
|
||||||
panic("todo: syscall.SysctlUint32")
|
n := uintptr(4)
|
||||||
|
ret := os.Sysctlbyname(c.AllocaCStr(name), unsafe.Pointer(&value), &n, nil, 0)
|
||||||
|
if ret != 0 {
|
||||||
|
err = Errno(os.Errno)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user