Skip to content

Commit

Permalink
os: treat Getwd result of EINVAL/ERANGE the same as ENAMETOOLONG
Browse files Browse the repository at this point in the history
At least Darwin and OpenBSD seem to return EINVAL if the resulting
name would be too long. Solaris seems to return ERANGE.

Fixes golang#69233
Fixes golang#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>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Sep 3, 2024
1 parent 8eefc3b commit 57f4cf2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/os/error_errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ import "syscall"
type syscallErrorType = syscall.Errno

const errENOSYS = syscall.ENOSYS
const errERANGE = syscall.ERANGE
1 change: 1 addition & 0 deletions src/os/error_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import "syscall"
type syscallErrorType = syscall.ErrorString

var errENOSYS = syscall.NewError("function not implemented")
var errERANGE = syscall.NewError("out of range")
5 changes: 4 additions & 1 deletion src/os/getwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 57f4cf2

Please sign in to comment.