github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/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, len, n, r;
    12  	byte file[128];
    13  	byte *p;
    14  
    15  	len = runtime·findnull((byte*)s);
    16  	if(len > sizeof file-6)
    17  		return nil;
    18  
    19  	runtime·memclr(file, sizeof file);
    20  	runtime·memmove((void*)file, (void*)"/env/", 5);
    21  	runtime·memmove((void*)(file+5), (void*)s, len);
    22  
    23  	fd = runtime·open((int8*)file, OREAD, 0);
    24  	if(fd < 0)
    25  		return nil;
    26  	n = runtime·seek(fd, 0, 2);
    27  	p = runtime·malloc(n+1);
    28  	r = runtime·pread(fd, p, n, 0);
    29  	runtime·close(fd);
    30  	if(r < 0)
    31  		return nil;
    32  	return p;
    33  }