When looking for \0, use clen which may be optimized.
Also, return EINVAL when returned string is empty.
This makes it similar to how it is implemented in *bsd and solaris.
Change-Id: I3e37ed25f47110eafd12c80291f7746de9db7b23
Reviewed-on: https://go-review.googlesource.com/c/go/+/606902
TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
b := make([]byte, len)
err := getcwd(&b[0], len)
if err == nil {
- i := 0
- for b[i] != 0 {
- i++
+ n := clen(b[:])
+ if n < 1 {
+ return "", EINVAL
}
- return string(b[0:i]), nil
+ return string(b[:n]), nil
}
if err != ERANGE {
return "", err