github.com/charlievieth/fastwalk@v1.0.3/zsyscall_nogetdirentries_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_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
    13  func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
    14  
    15  //go:linkname syscall_syscall syscall.syscall
    16  //go:linkname syscall_syscallPtr syscall.syscallPtr
    17  
    18  func closedir(dir uintptr) (err error) {
    19  	_, _, e1 := syscall_syscall(libc_closedir_trampoline_addr, dir, 0, 0)
    20  	if e1 != 0 {
    21  		err = errnoErr(e1)
    22  	}
    23  	return
    24  }
    25  
    26  var libc_closedir_trampoline_addr uintptr
    27  
    28  //go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
    29  
    30  func readdir_r(dir uintptr, entry *syscall.Dirent, result **syscall.Dirent) syscall.Errno {
    31  	res, _, _ := syscall_syscall(libc_readdir_r_trampoline_addr, dir, uintptr(unsafe.Pointer(entry)), uintptr(unsafe.Pointer(result)))
    32  	return syscall.Errno(res)
    33  }
    34  
    35  var libc_readdir_r_trampoline_addr uintptr
    36  
    37  //go:cgo_import_dynamic libc_readdir_r readdir_r "/usr/lib/libSystem.B.dylib"
    38  
    39  func opendir(path string) (dir uintptr, err error) {
    40  	// We implent opendir so that we don't have to open a file, duplicate
    41  	// it's FD, then call fdopendir with it.
    42  	p, err := syscall.BytePtrFromString(path)
    43  	if err != nil {
    44  		return 0, err
    45  	}
    46  	r0, _, e1 := syscall_syscallPtr(libc_opendir_trampoline_addr, uintptr(unsafe.Pointer(p)), 0, 0)
    47  	if e1 != 0 {
    48  		err = errnoErr(e1)
    49  	}
    50  	return r0, err
    51  }
    52  
    53  var libc_opendir_trampoline_addr uintptr
    54  
    55  //go:cgo_import_dynamic libc_opendir opendir "/usr/lib/libSystem.B.dylib"