1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:34:39 -07:00

os: treat Getwd result of EINVAL/ERANGE the same as ENAMETOOLONG

At least Darwin and OpenBSD seem to return EINVAL if the resulting
name would be too long. Solaris seems to return ERANGE.

Fixes #69233
Fixes #69234

Change-Id: I9b51d41461e9576c633bf2fc0e96ca3e4d986255
Reviewed-on: https://go-review.googlesource.com/c/go/+/609579
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ian Lance Taylor 2024-09-03 11:28:42 -07:00 committed by Gopher Robot
parent 8eefc3b8f0
commit 57f4cf2099
3 changed files with 6 additions and 1 deletions

View File

@ -11,3 +11,4 @@ import "syscall"
type syscallErrorType = syscall.Errno
const errENOSYS = syscall.ENOSYS
const errERANGE = syscall.ERANGE

View File

@ -9,3 +9,4 @@ import "syscall"
type syscallErrorType = syscall.ErrorString
var errENOSYS = syscall.NewError("function not implemented")
var errERANGE = syscall.NewError("out of range")

View File

@ -59,7 +59,10 @@ func Getwd() (dir string, err error) {
break
}
}
if err != syscall.ENAMETOOLONG {
// Linux returns ENAMETOOLONG if the result is too long.
// BSD systems appear to return EINVAL.
// Solaris appears to use ERANGE.
if err != syscall.ENAMETOOLONG && err != syscall.EINVAL && err != errERANGE {
return dir, NewSyscallError("getwd", err)
}
}