PR target/60017
[official-gcc.git] / libgo / runtime / env_posix.c
blob3219550af99d7ca945cb08299ec654ef6cd542d6
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 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;
16 intgo len;
17 const byte *v, *bs;
18 String* envv;
19 int32 envc;
21 bs = (const byte*)s;
22 len = runtime_findnull(bs);
23 envv = (String*)syscall_Envs.__values;
24 envc = syscall_Envs.__count;
25 for(i=0; i<envc; i++){
26 if(envv[i].len <= len)
27 continue;
28 v = (const byte*)envv[i].str;
29 for(j=0; j<len; j++)
30 if(bs[j] != v[j])
31 goto nomatch;
32 if(v[len] != '=')
33 goto nomatch;
34 return v+len+1;
35 nomatch:;
37 return nil;