diff --git a/src/pkg/os/getwd.go b/src/pkg/os/getwd.go index 1326e15259..8c5ff7fca5 100644 --- a/src/pkg/os/getwd.go +++ b/src/pkg/os/getwd.go @@ -14,6 +14,10 @@ var getwdCache struct { dir string } +// useSyscallwd determines whether to use the return value of +// syscall.Getwd based on its error. +var useSyscallwd = func(error) bool { return true } + // Getwd returns a rooted path name corresponding to the // current directory. If the current directory can be // reached via multiple paths (due to symbolic links), @@ -22,7 +26,7 @@ func Getwd() (pwd string, err error) { // If the operating system provides a Getwd call, use it. if syscall.ImplementsGetwd { s, e := syscall.Getwd() - if e != syscall.ENOTSUP { + if useSyscallwd(e) { return s, NewSyscallError("getwd", e) } } diff --git a/src/pkg/os/getwd_darwin.go b/src/pkg/os/getwd_darwin.go new file mode 100644 index 0000000000..e51ffcd5e7 --- /dev/null +++ b/src/pkg/os/getwd_darwin.go @@ -0,0 +1,15 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os + +import "syscall" + +func init() { + useSyscallwd = useSyscallwdDarwin +} + +func useSyscallwdDarwin(err error) bool { + return err != syscall.ENOTSUP +}