summaryrefslogtreecommitdiff
path: root/src/runtime/env_posix.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2018-11-02 15:47:40 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-11-02 17:05:38 +0000
commitf08352bd16e03555112154781afe84c3b5d6e0c8 (patch)
tree3e6661f77113ae6bd3b51da28faa56c3df97531d /src/runtime/env_posix.go
parent85525c56ab5fdb214fee70b4b4cce8700344258b (diff)
downloadgo-git-f08352bd16e03555112154781afe84c3b5d6e0c8.tar.gz
runtime: look up runtime env variables case insensitively on Windows
Fixes #28557 Change-Id: Ifca958b78e8c62fbc66515e693f528d799e8e84b Reviewed-on: https://go-review.googlesource.com/c/147039 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/env_posix.go')
-rw-r--r--src/runtime/env_posix.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/runtime/env_posix.go b/src/runtime/env_posix.go
index a2daeb7f27..03208c7c10 100644
--- a/src/runtime/env_posix.go
+++ b/src/runtime/env_posix.go
@@ -14,13 +14,36 @@ func gogetenv(key string) string {
throw("getenv before env init")
}
for _, s := range env {
- if len(s) > len(key) && s[len(key)] == '=' && s[:len(key)] == key {
+ if len(s) > len(key) && s[len(key)] == '=' && envKeyEqual(s[:len(key)], key) {
return s[len(key)+1:]
}
}
return ""
}
+// envKeyEqual reports whether a == b, with ASCII-only case insensitivity
+// on Windows. The two strings must have the same length.
+func envKeyEqual(a, b string) bool {
+ if GOOS == "windows" { // case insensitive
+ for i := 0; i < len(a); i++ {
+ ca, cb := a[i], b[i]
+ if ca == cb || lowerASCII(ca) == lowerASCII(cb) {
+ continue
+ }
+ return false
+ }
+ return true
+ }
+ return a == b
+}
+
+func lowerASCII(c byte) byte {
+ if 'A' <= c && c <= 'Z' {
+ return c + ('a' - 'A')
+ }
+ return c
+}
+
var _cgo_setenv unsafe.Pointer // pointer to C function
var _cgo_unsetenv unsafe.Pointer // pointer to C function