Importing Upstream version 4.8.2
[platform/upstream/gcc48.git] / libgo / runtime / env_posix.c
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 freebsd linux netbsd openbsd windows
6
7 #include "runtime.h"
8 #include "array.h"
9
10 extern Slice syscall_Envs __asm__ (GOSYM_PREFIX "syscall.Envs");
11
12 const byte*
13 runtime_getenv(const char *s)
14 {
15         int32 i, j, len;
16         const byte *v, *bs;
17         String* envv;
18         int32 envc;
19
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:;
35         }
36         return nil;
37 }