1
2
3
4
5 package unix
6
7 import (
8 "syscall"
9 "unsafe"
10 )
11
12 const (
13 _CTL_KERN = 1
14
15 _KERN_ARND = 81
16 )
17
18 func Arandom(p []byte) error {
19 mib := [2]uint32{_CTL_KERN, _KERN_ARND}
20 n := uintptr(len(p))
21 _, _, errno := syscall.Syscall6(
22 syscall.SYS___SYSCTL,
23 uintptr(unsafe.Pointer(&mib[0])),
24 uintptr(len(mib)),
25 uintptr(unsafe.Pointer(&p[0])),
26 uintptr(unsafe.Pointer(&n)),
27 uintptr(unsafe.Pointer(nil)),
28 0)
29 if errno != 0 {
30 return syscall.Errno(errno)
31 }
32 if n != uintptr(len(p)) {
33 return syscall.EINVAL
34 }
35 return nil
36 }
37
View as plain text