Retro68/gcc/libgo/runtime/env_posix.c

46 lines
887 B
C
Raw Normal View History

2014-09-21 17:33:12 +00:00
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2015-08-28 15:33:40 +00:00
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
2014-09-21 17:33:12 +00:00
#include "runtime.h"
#include "array.h"
2015-08-28 15:33:40 +00:00
#include "arch.h"
#include "malloc.h"
2014-09-21 17:33:12 +00:00
2015-08-28 15:33:40 +00:00
extern Slice envs;
2014-09-21 17:33:12 +00:00
2017-04-10 11:32:00 +00:00
String
2014-09-21 17:33:12 +00:00
runtime_getenv(const char *s)
{
int32 i, j;
intgo len;
const byte *v, *bs;
String* envv;
int32 envc;
2017-04-10 11:32:00 +00:00
String ret;
2014-09-21 17:33:12 +00:00
bs = (const byte*)s;
len = runtime_findnull(bs);
2015-08-28 15:33:40 +00:00
envv = (String*)envs.__values;
envc = envs.__count;
2014-09-21 17:33:12 +00:00
for(i=0; i<envc; i++){
if(envv[i].len <= len)
continue;
v = (const byte*)envv[i].str;
for(j=0; j<len; j++)
if(bs[j] != v[j])
goto nomatch;
if(v[len] != '=')
goto nomatch;
2017-04-10 11:32:00 +00:00
ret.str = v+len+1;
ret.len = envv[i].len-len-1;
return ret;
2014-09-21 17:33:12 +00:00
nomatch:;
}
2017-04-10 11:32:00 +00:00
ret.str = nil;
ret.len = 0;
return ret;
2014-09-21 17:33:12 +00:00
}