summaryrefslogtreecommitdiff
path: root/libgo/go/os/getwd.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/getwd.go')
-rw-r--r--libgo/go/os/getwd.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/libgo/go/os/getwd.go b/libgo/go/os/getwd.go
index a72edeaee6e..d5da53b34bf 100644
--- a/libgo/go/os/getwd.go
+++ b/libgo/go/os/getwd.go
@@ -5,6 +5,7 @@
package os
import (
+ "runtime"
"sync"
"syscall"
)
@@ -23,22 +24,16 @@ var useSyscallwd = func(error) bool { return true }
// reached via multiple paths (due to symbolic links),
// Getwd may return any one of them.
func Getwd() (dir string, err error) {
- // If the operating system provides a Getwd call, use it.
- if syscall.ImplementsGetwd {
- s, e := syscall.Getwd()
- if useSyscallwd(e) {
- return s, NewSyscallError("getwd", e)
- }
+ if runtime.GOOS == "windows" {
+ return syscall.Getwd()
}
- // Otherwise, we're trying to find our way back to ".".
+ // Clumsy but widespread kludge:
+ // if $PWD is set and matches ".", use it.
dot, err := Stat(".")
if err != nil {
return "", err
}
-
- // Clumsy but widespread kludge:
- // if $PWD is set and matches ".", use it.
dir = Getenv("PWD")
if len(dir) > 0 && dir[0] == '/' {
d, err := Stat(dir)
@@ -47,6 +42,15 @@ func Getwd() (dir string, err error) {
}
}
+ // If the operating system provides a Getwd call, use it.
+ // Otherwise, we're trying to find our way back to ".".
+ if syscall.ImplementsGetwd {
+ s, e := syscall.Getwd()
+ if useSyscallwd(e) {
+ return s, NewSyscallError("getwd", e)
+ }
+ }
+
// Apply same kludge but to cached dir instead of $PWD.
getwdCache.Lock()
dir = getwdCache.dir