github.com/bir3/gocompiler@v0.9.2202/src/internal/syscall/unix/getentropy_darwin.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build darwin && !ios
     6  
     7  package unix
     8  
     9  import (
    10  	"github.com/bir3/gocompiler/src/internal/abi"
    11  	"unsafe"
    12  )
    13  
    14  //go:cgo_import_dynamic libc_getentropy getentropy "/usr/lib/libSystem.B.dylib"
    15  
    16  func libc_getentropy_trampoline()
    17  
    18  // GetEntropy calls the macOS getentropy system call.
    19  func GetEntropy(p []byte) error {
    20  	_, _, errno := syscall_syscall(abi.FuncPCABI0(libc_getentropy_trampoline),
    21  		uintptr(unsafe.Pointer(&p[0])),
    22  		uintptr(len(p)),
    23  		0)
    24  	if errno != 0 {
    25  		return errno
    26  	}
    27  	return nil
    28  }