2013-02-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
[official-gcc.git] / libgo / runtime / env_posix.c
blob7f3fa0d8e0f2265b73914d001c95ca0ee0a2bdb7
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 freebsd linux netbsd openbsd windows
7 #include "runtime.h"
8 #include "array.h"
10 extern Slice syscall_Envs __asm__ (GOSYM_PREFIX "syscall.Envs");
12 const byte*
13 runtime_getenv(const char *s)
15 int32 i, j, len;
16 const byte *v, *bs;
17 String* envv;
18 int32 envc;
20 bs = (const byte*)s;
21 len = runtime_findnull(bs);
22 envv = (String*)syscall_Envs.__values;
23 envc = syscall_Envs.__count;
24 for(i=0; i<envc; i++){
25 if(envv[i].len <= len)
26 continue;
27 v = (const byte*)envv[i].str;
28 for(j=0; j<len; j++)
29 if(bs[j] != v[j])
30 goto nomatch;
31 if(v[len] != '=')
32 goto nomatch;
33 return v+len+1;
34 nomatch:;
36 return nil;