github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/runtime/env_posix.c (about) 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 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows 6 7 #include "runtime.h" 8 #include "array.h" 9 #include "arch.h" 10 #include "malloc.h" 11 12 extern Slice envs; 13 14 String 15 runtime_getenv(const char *s) 16 { 17 int32 i, j; 18 intgo len; 19 const byte *v, *bs; 20 String* envv; 21 int32 envc; 22 String ret; 23 24 bs = (const byte*)s; 25 len = runtime_findnull(bs); 26 envv = (String*)envs.__values; 27 envc = envs.__count; 28 for(i=0; i<envc; i++){ 29 if(envv[i].len <= len) 30 continue; 31 v = (const byte*)envv[i].str; 32 for(j=0; j<len; j++) 33 if(bs[j] != v[j]) 34 goto nomatch; 35 if(v[len] != '=') 36 goto nomatch; 37 ret.str = v+len+1; 38 ret.len = envv[i].len-len-1; 39 return ret; 40 nomatch:; 41 } 42 ret.str = nil; 43 ret.len = 0; 44 return ret; 45 }