jit: document union types
[official-gcc.git] / libgo / runtime / env_posix.c
blobee3e4514554fb4df900996b50a072f7f25807dcf
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 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
7 #include "runtime.h"
8 #include "array.h"
9 #include "arch.h"
10 #include "malloc.h"
12 extern Slice envs;
14 const byte*
15 runtime_getenv(const char *s)
17 int32 i, j;
18 intgo len;
19 const byte *v, *bs;
20 String* envv;
21 int32 envc;
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:;
39 return nil;