gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/internal/poll/fd_opendir_darwin.go (about) 1 // Copyright 2018 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 package poll 6 7 import ( 8 "syscall" 9 _ "unsafe" // for go:linkname 10 ) 11 12 // OpenDir returns a pointer to a DIR structure suitable for 13 // ReadDir. In case of an error, the name of the failed 14 // syscall is returned along with a syscall.Errno. 15 func (fd *FD) OpenDir() (uintptr, string, error) { 16 // fdopendir(3) takes control of the file descriptor, 17 // so use a dup. 18 fd2, call, err := fd.Dup() 19 if err != nil { 20 return 0, call, err 21 } 22 var dir uintptr 23 for { 24 dir, err = fdopendir(fd2) 25 if err != syscall.EINTR { 26 break 27 } 28 } 29 if err != nil { 30 syscall.Close(fd2) 31 return 0, "fdopendir", err 32 } 33 return dir, "", nil 34 } 35 36 // Implemented in syscall/syscall_darwin.go. 37 //go:linkname fdopendir syscall.fdopendir 38 func fdopendir(fd int) (dir uintptr, err error)