diff --git a/unix/syscall_bsd.go b/unix/syscall_bsd.go index c7040549..68605db6 100644 --- a/unix/syscall_bsd.go +++ b/unix/syscall_bsd.go @@ -510,6 +510,23 @@ func SysctlRaw(name string, args ...int) ([]byte, error) { return buf[:n], nil } +func SysctlClockinfo(name string) (*Clockinfo, error) { + mib, err := sysctlmib(name) + if err != nil { + return nil, err + } + + n := uintptr(SizeofClockinfo) + var ci Clockinfo + if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { + return nil, err + } + if n != SizeofClockinfo { + return nil, EIO + } + return &ci, nil +} + //sys utimes(path string, timeval *[2]Timeval) (err error) func Utimes(path string, tv []Timeval) error { diff --git a/unix/syscall_bsd_test.go b/unix/syscall_bsd_test.go index b552324f..f8ec9d1c 100644 --- a/unix/syscall_bsd_test.go +++ b/unix/syscall_bsd_test.go @@ -64,3 +64,12 @@ func TestSysctlUint32(t *testing.T) { } t.Logf("kern.maxproc: %v", maxproc) } + +func TestSysctlClockinfo(t *testing.T) { + ci, err := unix.SysctlClockinfo("kern.clockrate") + if err != nil { + t.Fatal(err) + } + t.Logf("tick = %v, hz = %v, profhz = %v, stathz = %v", + ci.Tick, ci.Hz, ci.Profhz, ci.Stathz) +} diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 3440c52e..9a5a6ee5 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -155,23 +155,6 @@ func getAttrList(path string, attrList attrList, attrBuf []byte, options uint) ( //sys getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) -func SysctlClockinfo(name string) (*Clockinfo, error) { - mib, err := sysctlmib(name) - if err != nil { - return nil, err - } - - n := uintptr(SizeofClockinfo) - var ci Clockinfo - if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { - return nil, err - } - if n != SizeofClockinfo { - return nil, EIO - } - return &ci, nil -} - //sysnb pipe() (r int, w int, err error) func Pipe(p []int) (err error) { diff --git a/unix/syscall_darwin_test.go b/unix/syscall_darwin_test.go index 4a9b50c5..65691d5c 100644 --- a/unix/syscall_darwin_test.go +++ b/unix/syscall_darwin_test.go @@ -4,12 +4,6 @@ package unix_test -import ( - "testing" - - "golang.org/x/sys/unix" -) - // stringsFromByteSlice converts a sequence of attributes to a []string. // On Darwin, each entry is a NULL-terminated string. func stringsFromByteSlice(buf []byte) []string { @@ -23,12 +17,3 @@ func stringsFromByteSlice(buf []byte) []string { } return result } - -func TestSysctlClockinfo(t *testing.T) { - ci, err := unix.SysctlClockinfo("kern.clockrate") - if err != nil { - t.Fatal(err) - } - t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v", - ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz) -} diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index e8224c79..45b50a61 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go @@ -106,23 +106,6 @@ func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } -func SysctlClockinfo(name string) (*Clockinfo, error) { - mib, err := sysctlmib(name) - if err != nil { - return nil, err - } - - n := uintptr(SizeofClockinfo) - var ci Clockinfo - if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { - return nil, err - } - if n != SizeofClockinfo { - return nil, EIO - } - return &ci, nil -} - //sysnb pipe() (fd1 int, fd2 int, err error) func Pipe(p []int) (err error) { if len(p) != 2 { diff --git a/unix/syscall_netbsd_test.go b/unix/syscall_netbsd_test.go index 3292cbd8..2316d264 100644 --- a/unix/syscall_netbsd_test.go +++ b/unix/syscall_netbsd_test.go @@ -27,15 +27,6 @@ func stringsFromByteSlice(buf []byte) []string { return result } -func TestSysctlClockinfo(t *testing.T) { - ci, err := unix.SysctlClockinfo("kern.clockrate") - if err != nil { - t.Fatal(err) - } - t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v", - ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz) -} - func TestIoctlPtmget(t *testing.T) { fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666) if err != nil { diff --git a/unix/syscall_openbsd.go b/unix/syscall_openbsd.go index 5628a68b..2629a326 100644 --- a/unix/syscall_openbsd.go +++ b/unix/syscall_openbsd.go @@ -55,23 +55,6 @@ func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } -func SysctlClockinfo(name string) (*Clockinfo, error) { - mib, err := sysctlmib(name) - if err != nil { - return nil, err - } - - n := uintptr(SizeofClockinfo) - var ci Clockinfo - if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { - return nil, err - } - if n != SizeofClockinfo { - return nil, EIO - } - return &ci, nil -} - func SysctlUvmexp(name string) (*Uvmexp, error) { mib, err := sysctlmib(name) if err != nil { diff --git a/unix/syscall_openbsd_test.go b/unix/syscall_openbsd_test.go index 7bf75eed..b95f334e 100644 --- a/unix/syscall_openbsd_test.go +++ b/unix/syscall_openbsd_test.go @@ -40,15 +40,6 @@ func TestPpoll(t *testing.T) { } } -func TestSysctlClockinfo(t *testing.T) { - ci, err := unix.SysctlClockinfo("kern.clockrate") - if err != nil { - t.Fatal(err) - } - t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v", - ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz) -} - func TestSysctlUvmexp(t *testing.T) { uvm, err := unix.SysctlUvmexp("vm.uvmexp") if err != nil { diff --git a/unix/types_dragonfly.go b/unix/types_dragonfly.go index 3365dd79..6574f6b6 100644 --- a/unix/types_dragonfly.go +++ b/unix/types_dragonfly.go @@ -261,3 +261,9 @@ const ( // Uname type Utsname C.struct_utsname + +// Clockinfo + +const SizeofClockinfo = C.sizeof_struct_clockinfo + +type Clockinfo C.struct_clockinfo diff --git a/unix/types_freebsd.go b/unix/types_freebsd.go index a121dc33..c6fde424 100644 --- a/unix/types_freebsd.go +++ b/unix/types_freebsd.go @@ -398,3 +398,9 @@ type CapRights C.struct_cap_rights // Uname type Utsname C.struct_utsname + +// Clockinfo + +const SizeofClockinfo = C.sizeof_struct_clockinfo + +type Clockinfo C.struct_clockinfo diff --git a/unix/ztypes_dragonfly_amd64.go b/unix/ztypes_dragonfly_amd64.go index c206f2b0..71ea1d6d 100644 --- a/unix/ztypes_dragonfly_amd64.go +++ b/unix/ztypes_dragonfly_amd64.go @@ -467,3 +467,13 @@ type Utsname struct { Version [32]byte Machine [32]byte } + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Tickadj int32 + Stathz int32 + Profhz int32 +} diff --git a/unix/ztypes_freebsd_386.go b/unix/ztypes_freebsd_386.go index 7312e95f..cd16bc59 100644 --- a/unix/ztypes_freebsd_386.go +++ b/unix/ztypes_freebsd_386.go @@ -698,3 +698,13 @@ type Utsname struct { Version [256]byte Machine [256]byte } + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Spare int32 + Stathz int32 + Profhz int32 +} diff --git a/unix/ztypes_freebsd_amd64.go b/unix/ztypes_freebsd_amd64.go index 29ba2f5b..4eb6ae3c 100644 --- a/unix/ztypes_freebsd_amd64.go +++ b/unix/ztypes_freebsd_amd64.go @@ -704,3 +704,13 @@ type Utsname struct { Version [256]byte Machine [256]byte } + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Spare int32 + Stathz int32 + Profhz int32 +} diff --git a/unix/ztypes_freebsd_arm.go b/unix/ztypes_freebsd_arm.go index b4090ef3..a1d4aaf4 100644 --- a/unix/ztypes_freebsd_arm.go +++ b/unix/ztypes_freebsd_arm.go @@ -681,3 +681,13 @@ type Utsname struct { Version [256]byte Machine [256]byte } + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Spare int32 + Stathz int32 + Profhz int32 +} diff --git a/unix/ztypes_freebsd_arm64.go b/unix/ztypes_freebsd_arm64.go index c681d7db..1d27d6f8 100644 --- a/unix/ztypes_freebsd_arm64.go +++ b/unix/ztypes_freebsd_arm64.go @@ -682,3 +682,13 @@ type Utsname struct { Version [256]byte Machine [256]byte } + +const SizeofClockinfo = 0x14 + +type Clockinfo struct { + Hz int32 + Tick int32 + Spare int32 + Stathz int32 + Profhz int32 +}