github.com/charlievieth/fastwalk@v1.0.3/zsyscall_getdirentries_darwin.go (about)

     1  //go:build !nogetdirentries && darwin && go1.12
     2  // +build !nogetdirentries,darwin,go1.12
     3  
     4  package fastwalk
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  // Implemented in the runtime package (runtime/sys_darwin.go)
    12  func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
    13  
    14  //go:linkname syscall_syscall6 syscall.syscall6
    15  
    16  // Single-word zero for use when we need a valid pointer to 0 bytes.
    17  var _zero uintptr
    18  
    19  func getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
    20  	var _p0 unsafe.Pointer
    21  	if len(buf) > 0 {
    22  		_p0 = unsafe.Pointer(&buf[0])
    23  	} else {
    24  		_p0 = unsafe.Pointer(&_zero)
    25  	}
    26  	r0, _, e1 := syscall_syscall6(libc___getdirentries64_trampoline_addr,
    27  		uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)),
    28  		0, 0)
    29  	n = int(r0)
    30  	if e1 != 0 {
    31  		err = errnoErr(e1)
    32  	} else if n < 0 {
    33  		err = errnoErr(syscall.EINVAL)
    34  	}
    35  	return
    36  }
    37  
    38  var libc___getdirentries64_trampoline_addr uintptr
    39  
    40  //go:cgo_import_dynamic libc___getdirentries64 __getdirentries64 "/usr/lib/libSystem.B.dylib"