github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/env_plan9.c (about)

     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  #include "runtime.h"
     6  #include "os_GOOS.h"
     7  
     8  byte*
     9  runtime·getenv(int8 *s)
    10  {
    11  	int32 fd, n, r;
    12  	intgo len;
    13  	byte file[128];
    14  	byte *p;
    15  
    16  	len = runtime·findnull((byte*)s);
    17  	if(len > sizeof file-6)
    18  		return nil;
    19  
    20  	runtime·memclr(file, sizeof file);
    21  	runtime·memmove((void*)file, (void*)"/env/", 5);
    22  	runtime·memmove((void*)(file+5), (void*)s, len);
    23  
    24  	fd = runtime·open((int8*)file, OREAD, 0);
    25  	if(fd < 0)
    26  		return nil;
    27  	n = runtime·seek(fd, 0, 2);
    28  	p = runtime·malloc(n+1);
    29  	r = runtime·pread(fd, p, n, 0);
    30  	runtime·close(fd);
    31  	if(r < 0)
    32  		return nil;
    33  	return p;
    34  }