// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || windows || plan9

package runtime

import 

func gogetenv( string) string {
	 := environ()
	if  == nil {
		throw("getenv before env init")
	}
	for ,  := range  {
		if len() > len() && [len()] == '=' && envKeyEqual([:len()], ) {
			return [len()+1:]
		}
	}
	return ""
}

// envKeyEqual reports whether a == b, with ASCII-only case insensitivity
// on Windows. The two strings must have the same length.
func envKeyEqual(,  string) bool {
	if GOOS == "windows" { // case insensitive
		for  := 0;  < len(); ++ {
			,  := [], []
			if  ==  || lowerASCII() == lowerASCII() {
				continue
			}
			return false
		}
		return true
	}
	return  == 
}

func lowerASCII( byte) byte {
	if 'A' <=  &&  <= 'Z' {
		return  + ('a' - 'A')
	}
	return 
}

var _cgo_setenv unsafe.Pointer   // pointer to C function
var _cgo_unsetenv unsafe.Pointer // pointer to C function

// Update the C environment if cgo is loaded.
// Called from syscall.Setenv.
//go:linkname syscall_setenv_c syscall.setenv_c
func syscall_setenv_c( string,  string) {
	if _cgo_setenv == nil {
		return
	}
	 := [2]unsafe.Pointer{cstring(), cstring()}
	asmcgocall(_cgo_setenv, unsafe.Pointer(&))
}

// Update the C environment if cgo is loaded.
// Called from syscall.unsetenv.
//go:linkname syscall_unsetenv_c syscall.unsetenv_c
func syscall_unsetenv_c( string) {
	if _cgo_unsetenv == nil {
		return
	}
	 := [1]unsafe.Pointer{cstring()}
	asmcgocall(_cgo_unsetenv, unsafe.Pointer(&))
}

func cstring( string) unsafe.Pointer {
	 := make([]byte, len()+1)
	copy(, )
	return unsafe.Pointer(&[0])
}