github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/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  const byte*
    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  
    23  	bs = (const byte*)s;
    24  	len = runtime_findnull(bs);
    25  	envv = (String*)envs.__values;
    26  	envc = envs.__count;
    27  	for(i=0; i<envc; i++){
    28  		if(envv[i].len <= len)
    29  			continue;
    30  		v = (const byte*)envv[i].str;
    31  		for(j=0; j<len; j++)
    32  			if(bs[j] != v[j])
    33  				goto nomatch;
    34  		if(v[len] != '=')
    35  			goto nomatch;
    36  		return v+len+1;
    37  	nomatch:;
    38  	}
    39  	return nil;
    40  }