libstdc++: Fix std::char_traits<C>::move [PR113200]
[official-gcc.git] / libgo / runtime / env_posix.c
blobb254ee4009dc7029b4eae2073b06dec2ddbc45b4
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 hurd 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;