diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/pkg/os/getwd.go | |
parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
download | golang-8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1.tar.gz |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/pkg/os/getwd.go')
-rw-r--r-- | src/pkg/os/getwd.go | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/pkg/os/getwd.go b/src/pkg/os/getwd.go index 8c5ff7fca..a72edeaee 100644 --- a/src/pkg/os/getwd.go +++ b/src/pkg/os/getwd.go @@ -22,7 +22,7 @@ var useSyscallwd = func(error) bool { return true } // current directory. If the current directory can be // reached via multiple paths (due to symbolic links), // Getwd may return any one of them. -func Getwd() (pwd string, err error) { +func Getwd() (dir string, err error) { // If the operating system provides a Getwd call, use it. if syscall.ImplementsGetwd { s, e := syscall.Getwd() @@ -39,22 +39,22 @@ func Getwd() (pwd string, err error) { // Clumsy but widespread kludge: // if $PWD is set and matches ".", use it. - pwd = Getenv("PWD") - if len(pwd) > 0 && pwd[0] == '/' { - d, err := Stat(pwd) + dir = Getenv("PWD") + if len(dir) > 0 && dir[0] == '/' { + d, err := Stat(dir) if err == nil && SameFile(dot, d) { - return pwd, nil + return dir, nil } } // Apply same kludge but to cached dir instead of $PWD. getwdCache.Lock() - pwd = getwdCache.dir + dir = getwdCache.dir getwdCache.Unlock() - if len(pwd) > 0 { - d, err := Stat(pwd) + if len(dir) > 0 { + d, err := Stat(dir) if err == nil && SameFile(dot, d) { - return pwd, nil + return dir, nil } } @@ -71,8 +71,8 @@ func Getwd() (pwd string, err error) { // General algorithm: find name in parent // and then find name of parent. Each iteration - // adds /name to the beginning of pwd. - pwd = "" + // adds /name to the beginning of dir. + dir = "" for parent := ".."; ; parent = "../" + parent { if len(parent) >= 1024 { // Sanity check return "", syscall.ENAMETOOLONG @@ -91,7 +91,7 @@ func Getwd() (pwd string, err error) { for _, name := range names { d, _ := Lstat(parent + "/" + name) if SameFile(d, dot) { - pwd = "/" + name + pwd + dir = "/" + name + dir goto Found } } @@ -112,8 +112,8 @@ func Getwd() (pwd string, err error) { // Save answer as hint to avoid the expensive path next time. getwdCache.Lock() - getwdCache.dir = pwd + getwdCache.dir = dir getwdCache.Unlock() - return pwd, nil + return dir, nil } |