Commit 4b9ab7dd authored by Shenghou Ma's avatar Shenghou Ma

os: change return variable name for Getwd to avoid confusion

changed (pwd string) to (dir string), as some think pwd means passwd.
Fixes #7811.

LGTM=iant
R=golang-codereviews, iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/89100043
parent c7d864c4
...@@ -22,7 +22,7 @@ var useSyscallwd = func(error) bool { return true } ...@@ -22,7 +22,7 @@ var useSyscallwd = func(error) bool { return true }
// current directory. If the current directory can be // current directory. If the current directory can be
// reached via multiple paths (due to symbolic links), // reached via multiple paths (due to symbolic links),
// Getwd may return any one of them. // 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 the operating system provides a Getwd call, use it.
if syscall.ImplementsGetwd { if syscall.ImplementsGetwd {
s, e := syscall.Getwd() s, e := syscall.Getwd()
...@@ -39,22 +39,22 @@ func Getwd() (pwd string, err error) { ...@@ -39,22 +39,22 @@ func Getwd() (pwd string, err error) {
// Clumsy but widespread kludge: // Clumsy but widespread kludge:
// if $PWD is set and matches ".", use it. // if $PWD is set and matches ".", use it.
pwd = Getenv("PWD") dir = Getenv("PWD")
if len(pwd) > 0 && pwd[0] == '/' { if len(dir) > 0 && dir[0] == '/' {
d, err := Stat(pwd) d, err := Stat(dir)
if err == nil && SameFile(dot, d) { if err == nil && SameFile(dot, d) {
return pwd, nil return dir, nil
} }
} }
// Apply same kludge but to cached dir instead of $PWD. // Apply same kludge but to cached dir instead of $PWD.
getwdCache.Lock() getwdCache.Lock()
pwd = getwdCache.dir dir = getwdCache.dir
getwdCache.Unlock() getwdCache.Unlock()
if len(pwd) > 0 { if len(dir) > 0 {
d, err := Stat(pwd) d, err := Stat(dir)
if err == nil && SameFile(dot, d) { if err == nil && SameFile(dot, d) {
return pwd, nil return dir, nil
} }
} }
...@@ -71,8 +71,8 @@ func Getwd() (pwd string, err error) { ...@@ -71,8 +71,8 @@ func Getwd() (pwd string, err error) {
// General algorithm: find name in parent // General algorithm: find name in parent
// and then find name of parent. Each iteration // and then find name of parent. Each iteration
// adds /name to the beginning of pwd. // adds /name to the beginning of dir.
pwd = "" dir = ""
for parent := ".."; ; parent = "../" + parent { for parent := ".."; ; parent = "../" + parent {
if len(parent) >= 1024 { // Sanity check if len(parent) >= 1024 { // Sanity check
return "", syscall.ENAMETOOLONG return "", syscall.ENAMETOOLONG
...@@ -91,7 +91,7 @@ func Getwd() (pwd string, err error) { ...@@ -91,7 +91,7 @@ func Getwd() (pwd string, err error) {
for _, name := range names { for _, name := range names {
d, _ := Lstat(parent + "/" + name) d, _ := Lstat(parent + "/" + name)
if SameFile(d, dot) { if SameFile(d, dot) {
pwd = "/" + name + pwd dir = "/" + name + dir
goto Found goto Found
} }
} }
...@@ -112,8 +112,8 @@ func Getwd() (pwd string, err error) { ...@@ -112,8 +112,8 @@ func Getwd() (pwd string, err error) {
// Save answer as hint to avoid the expensive path next time. // Save answer as hint to avoid the expensive path next time.
getwdCache.Lock() getwdCache.Lock()
getwdCache.dir = pwd getwdCache.dir = dir
getwdCache.Unlock() getwdCache.Unlock()
return pwd, nil return dir, nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment