RISC-V: fix zcmp popretz [PR113715]
[official-gcc.git] / libgo / go / runtime / env_posix.go
blob9bb34a897680afb63ccefb54da53c37040e0a66c
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build aix || darwin || dragonfly || freebsd || hurd || (js && wasm) || linux || netbsd || openbsd || solaris || windows || plan9
7 package runtime
9 func gogetenv(key string) string {
10 env := environ()
11 if env == nil {
12 throw("getenv before env init")
14 for _, s := range env {
15 if len(s) > len(key) && s[len(key)] == '=' && envKeyEqual(s[:len(key)], key) {
16 return s[len(key)+1:]
19 return ""
22 // envKeyEqual reports whether a == b, with ASCII-only case insensitivity
23 // on Windows. The two strings must have the same length.
24 func envKeyEqual(a, b string) bool {
25 if GOOS == "windows" { // case insensitive
26 for i := 0; i < len(a); i++ {
27 ca, cb := a[i], b[i]
28 if ca == cb || lowerASCII(ca) == lowerASCII(cb) {
29 continue
31 return false
33 return true
35 return a == b
38 func lowerASCII(c byte) byte {
39 if 'A' <= c && c <= 'Z' {
40 return c + ('a' - 'A')
42 return c