Source File
getwd.go
Belonging Package
os
package os
import (
)
var getwdCache struct {
sync.Mutex
dir string
}
if syscall.ImplementsGetwd {
var (
string
error
)
for {
, = syscall.Getwd()
if != syscall.EINTR {
break
}
}
return , NewSyscallError("getwd", )
}
getwdCache.Lock()
= getwdCache.dir
getwdCache.Unlock()
if len() > 0 {
, := statNolog()
if == nil && SameFile(, ) {
return , nil
}
}
, := statNolog("/")
= ""
for := ".."; ; = "../" + {
if len() >= 1024 { // Sanity check
return "", syscall.ENAMETOOLONG
}
, := openFileNolog(, O_RDONLY, 0)
if != nil {
return "",
}
for {
, := .Readdirnames(100)
if != nil {
.Close()
return "",
}
for , := range {
, := lstatNolog( + "/" + )
if SameFile(, ) {
= "/" + +
goto
}
}
}
:
, := .Stat()
.Close()
if != nil {
return "",
}
if SameFile(, ) {
break
=
}
getwdCache.Lock()
getwdCache.dir =
getwdCache.Unlock()
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. |