1
0
mirror of https://github.com/golang/go synced 2024-10-05 12:31:23 -06:00
go/src/lib/os/os_env.go
Rob Pike 4d12c0e170 add os.Getenv()
R=rsc
DELTA=51  (50 added, 0 deleted, 1 changed)
OCL=15665
CL=15667
2008-09-22 17:31:41 -07:00

29 lines
614 B
Go

// Copyright 2009 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.
// Environment variables.
// Setenv doesn't exist yet: don't have the run-time hooks yet
package os
import os "os"
export var (
ENOENV = NewError("no such environment variable");
)
export func Getenv(s string) (v string, err *Error) {
n := len(s);
if n == 0 {
return "", EINVAL
}
for i := 0; i < sys.envc(); i++ {
e := sys.envv(i);
if len(e) > n && e[n] == '=' && e[0 : n] == s {
return e[n+1 : len(e)], nil
}
}
return "", ENOENV
}