2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / runtime / env_posix.c
blobff4bf0c5b1fd7db6d0c11f741c7f7aaf87c8d134
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 syscall_Envs __asm__ (GOSYM_PREFIX "syscall.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*)syscall_Envs.__values;
26 envc = syscall_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;