Source File
file_unix.go
Belonging Package
os
package os
import (
)
func ( uintptr, string) *File {
:= kindNewFile
if , := unix.IsNonblock(int()); == nil && {
= kindNonBlock
}
return newFile(, , )
}
type newFileKind int
const (
kindNewFile newFileKind = iota
kindOpenFile
kindPipe
kindNonBlock
)
func ( uintptr, string, newFileKind) *File {
:= int()
if < 0 {
return nil
}
:= &File{&file{
pfd: poll.FD{
Sysfd: ,
IsStream: true,
ZeroReadIsEOF: true,
},
name: ,
stdoutOrErr: == 1 || == 2,
}}
:= == kindOpenFile || == kindPipe || == kindNonBlock
if == kindOpenFile {
switch runtime.GOOS {
case "darwin", "ios", "dragonfly", "freebsd", "netbsd", "openbsd":
var syscall.Stat_t
:= ignoringEINTR(func() error {
return syscall.Fstat(, &)
})
const DevNull = "/dev/null"
func ( string, int, FileMode) (*File, error) {
:= false
if !supportsCreateWithStickyBit && &O_CREATE != 0 && &ModeSticky != 0 {
if , := Stat(); IsNotExist() {
= true
}
}
var int
for {
var error
, = syscall.Open(, |syscall.O_CLOEXEC, syscallMode())
if == nil {
break
}
if {
setStickyBit()
}
if !supportsCloseOnExec {
syscall.CloseOnExec()
}
return newFile(uintptr(), , kindOpenFile), nil
}
func ( *file) () error {
if == nil {
return syscall.EINVAL
}
if .dirinfo != nil {
.dirinfo.close()
}
var error
if := .pfd.Close(); != nil {
if == poll.ErrFileClosing {
= ErrClosed
}
= &PathError{Op: "close", Path: .name, Err: }
}
runtime.SetFinalizer(, nil)
return
}
if runtime.GOOS == "aix" && == syscall.ERANGE {
continue
}
if != nil {
return "", &PathError{Op: "readlink", Path: , Err: }
}
if < {
return string([0:]), nil
}
}
}
type unixDirent struct {
parent string
name string
typ FileMode
info FileInfo
}
func ( *unixDirent) () string { return .name }
func ( *unixDirent) () bool { return .typ.IsDir() }
func ( *unixDirent) () FileMode { return .typ }
func ( *unixDirent) () (FileInfo, error) {
if .info != nil {
return .info, nil
}
return lstat(.parent + "/" + .name)
}
func (, string, FileMode) (DirEntry, error) {
:= &unixDirent{
parent: ,
name: ,
typ: ,
}
if != ^FileMode(0) && !testingForceReadDirLstat {
return , nil
}
, := lstat( + "/" + )
if != nil {
return nil,
}
.typ = .Mode().Type()
.info =
return , nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |