env_posix.c 801 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
  5. #include "runtime.h"
  6. #include "array.h"
  7. #include "arch.h"
  8. #include "malloc.h"
  9. extern Slice envs;
  10. const byte*
  11. runtime_getenv(const char *s)
  12. {
  13. int32 i, j;
  14. intgo len;
  15. const byte *v, *bs;
  16. String* envv;
  17. int32 envc;
  18. bs = (const byte*)s;
  19. len = runtime_findnull(bs);
  20. envv = (String*)envs.__values;
  21. envc = envs.__count;
  22. for(i=0; i<envc; i++){
  23. if(envv[i].len <= len)
  24. continue;
  25. v = (const byte*)envv[i].str;
  26. for(j=0; j<len; j++)
  27. if(bs[j] != v[j])
  28. goto nomatch;
  29. if(v[len] != '=')
  30. goto nomatch;
  31. return v+len+1;
  32. nomatch:;
  33. }
  34. return nil;
  35. }