Wrap is_static with COLLECT_EXPORT_LIST
[official-gcc.git] / libgo / runtime / env_posix.c
blob8cffa73d0a6a2a41ab0f6d7ee49345d8be1f9e8b
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"
11 extern Slice runtime_get_envs(void);
13 String
14 runtime_getenv(const char *s)
16 int32 i, j;
17 intgo len;
18 const byte *v, *bs;
19 Slice envs;
20 String* envv;
21 int32 envc;
22 String ret;
24 bs = (const byte*)s;
25 len = runtime_findnull(bs);
26 envs = runtime_get_envs();
27 envv = (String*)envs.__values;
28 envc = envs.__count;
29 for(i=0; i<envc; i++){
30 if(envv[i].len <= len)
31 continue;
32 v = (const byte*)envv[i].str;
33 for(j=0; j<len; j++)
34 if(bs[j] != v[j])
35 goto nomatch;
36 if(v[len] != '=')
37 goto nomatch;
38 ret.str = v+len+1;
39 ret.len = envv[i].len-len-1;
40 return ret;
41 nomatch:;
43 ret.str = nil;
44 ret.len = 0;
45 return ret;