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. 4 5 package runtime 6 7 import "unsafe" 8 9 var tracebackbuf [128]byte 10 11 func gogetenv(key string) string { 12 var file [128]byte 13 if len(key) > len(file)-6 { 14 return "" 15 } 16 17 copy(file[:], "/env/") 18 copy(file[5:], key) 19 20 fd := open(&file[0], _OREAD, 0) 21 if fd < 0 { 22 return "" 23 } 24 n := seek(fd, 0, 2) 25 if n <= 0 { 26 closefd(fd) 27 return "" 28 } 29 30 p := make([]byte, n) 31 32 r := pread(fd, unsafe.Pointer(&p[0]), int32(n), 0) 33 closefd(fd) 34 if r < 0 { 35 return "" 36 } 37 38 if p[r-1] == 0 { 39 r-- 40 } 41 42 var s string 43 sp := (*_string)(unsafe.Pointer(&s)) 44 sp.str = &p[0] 45 sp.len = int(r) 46 return s 47 } 48 49 var _cgo_setenv unsafe.Pointer // pointer to C function 50 var _cgo_unsetenv unsafe.Pointer // pointer to C function 51