unix: add SysctlClockinfo on dragonfly and freebsd
Change-Id: I0d439b5c59c79594c6ecfebe0375971e1344cc09
Reviewed-on: https://go-review.googlesource.com/c/sys/+/213400
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/unix/syscall_bsd.go b/unix/syscall_bsd.go
index c704054..68605db 100644
--- a/unix/syscall_bsd.go
+++ b/unix/syscall_bsd.go
@@ -510,6 +510,23 @@
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 b552324..f8ec9d1 100644
--- a/unix/syscall_bsd_test.go
+++ b/unix/syscall_bsd_test.go
@@ -64,3 +64,12 @@
}
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 3440c52..9a5a6ee 100644
--- a/unix/syscall_darwin.go
+++ b/unix/syscall_darwin.go
@@ -155,23 +155,6 @@
//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 4a9b50c..65691d5 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 @@
}
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 e8224c7..45b50a6 100644
--- a/unix/syscall_netbsd.go
+++ b/unix/syscall_netbsd.go
@@ -106,23 +106,6 @@
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 3292cbd..2316d26 100644
--- a/unix/syscall_netbsd_test.go
+++ b/unix/syscall_netbsd_test.go
@@ -27,15 +27,6 @@
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 5628a68..2629a32 100644
--- a/unix/syscall_openbsd.go
+++ b/unix/syscall_openbsd.go
@@ -55,23 +55,6 @@
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 7bf75ee..b95f334 100644
--- a/unix/syscall_openbsd_test.go
+++ b/unix/syscall_openbsd_test.go
@@ -40,15 +40,6 @@
}
}
-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 3365dd7..6574f6b 100644
--- a/unix/types_dragonfly.go
+++ b/unix/types_dragonfly.go
@@ -261,3 +261,9 @@
// 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 a121dc3..c6fde42 100644
--- a/unix/types_freebsd.go
+++ b/unix/types_freebsd.go
@@ -398,3 +398,9 @@
// 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 c206f2b..71ea1d6 100644
--- a/unix/ztypes_dragonfly_amd64.go
+++ b/unix/ztypes_dragonfly_amd64.go
@@ -467,3 +467,13 @@
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 7312e95..cd16bc5 100644
--- a/unix/ztypes_freebsd_386.go
+++ b/unix/ztypes_freebsd_386.go
@@ -698,3 +698,13 @@
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 29ba2f5..4eb6ae3 100644
--- a/unix/ztypes_freebsd_amd64.go
+++ b/unix/ztypes_freebsd_amd64.go
@@ -704,3 +704,13 @@
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 b4090ef..a1d4aaf 100644
--- a/unix/ztypes_freebsd_arm.go
+++ b/unix/ztypes_freebsd_arm.go
@@ -681,3 +681,13 @@
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 c681d7d..1d27d6f 100644
--- a/unix/ztypes_freebsd_arm64.go
+++ b/unix/ztypes_freebsd_arm64.go
@@ -682,3 +682,13 @@
Version [256]byte
Machine [256]byte
}
+
+const SizeofClockinfo = 0x14
+
+type Clockinfo struct {
+ Hz int32
+ Tick int32
+ Spare int32
+ Stathz int32
+ Profhz int32
+}