diff options
| author | Rob Pike <r@golang.org> | 2009-06-26 20:28:41 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2009-06-26 20:28:41 -0700 |
| commit | d330c712c12397f50261ca30666b5cb35383a33d (patch) | |
| tree | 2e0686297383ebaa5c2d998726a235075bb2c593 /src/pkg | |
| parent | ac7f2152eb21cf605e291c3b06199751a0f1d5d2 (diff) | |
| download | go-d330c712c12397f50261ca30666b5cb35383a33d.tar.xz | |
Getenv: almost no one wants the error, so make it return a string that may be empty.
Getenverror is the new name for the old routine that returns an error too.
R=rsc
DELTA=35 (7 added, 7 deleted, 21 changed)
OCL=30818
CL=30821
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/exec/exec.go | 7 | ||||
| -rw-r--r-- | src/pkg/os/env.go | 11 | ||||
| -rw-r--r-- | src/pkg/os/getwd.go | 2 | ||||
| -rw-r--r-- | src/pkg/time/zoneinfo.go | 2 |
4 files changed, 12 insertions, 10 deletions
diff --git a/src/pkg/exec/exec.go b/src/pkg/exec/exec.go index 7ddb98b508..a50f9dc13a 100644 --- a/src/pkg/exec/exec.go +++ b/src/pkg/exec/exec.go @@ -208,12 +208,7 @@ func LookPath(file string) (string, os.Error) { } return "", os.ENOENT; } - pathenv, err := os.Getenv("PATH"); - if err != nil { - // Unix shell semantics: no $PATH means assume PATH="" - // (equivalent to PATH="."). - pathenv = ""; - } + pathenv := os.Getenv("PATH"); for i, dir := range strings.Split(pathenv, ":", 0) { if dir == "" { // Unix shell semantics: path element "" means "." diff --git a/src/pkg/os/env.go b/src/pkg/os/env.go index 4dbc2a4883..3bd0fa9fea 100644 --- a/src/pkg/os/env.go +++ b/src/pkg/os/env.go @@ -29,9 +29,9 @@ func copyenv() { } } -// Getenv retrieves the value of the environment variable named by the key. +// Getenverror retrieves the value of the environment variable named by the key. // It returns the value and an error, if any. -func Getenv(key string) (value string, err Error) { +func Getenverror(key string) (value string, err Error) { once.Do(copyenv); if len(key) == 0 { @@ -44,6 +44,13 @@ func Getenv(key string) (value string, err Error) { return v, nil; } +// Getenv retrieves the value of the environment variable named by the key. +// It returns the value, which will be empty if the variable is not present. +func Getenv(key string) string { + v, _ := Getenverror(key); + return v; +} + // Setenv sets the value of the environment variable named by the key. // It returns an Error, if any. func Setenv(key, value string) Error { diff --git a/src/pkg/os/getwd.go b/src/pkg/os/getwd.go index cbc6134a7d..5b1b4e2e28 100644 --- a/src/pkg/os/getwd.go +++ b/src/pkg/os/getwd.go @@ -28,7 +28,7 @@ func Getwd() (string, Error) { // Clumsy but widespread kludge: // if $PWD is set and matches ".", use it. - pwd, _ := Getenv("PWD"); + pwd:= Getenv("PWD"); if len(pwd) > 0 && pwd[0] == '/' { d, err := Stat(pwd); if err == nil && d.Dev == dot.Dev && d.Ino == dot.Ino { diff --git a/src/pkg/time/zoneinfo.go b/src/pkg/time/zoneinfo.go index e2102f1ded..a4717c445c 100644 --- a/src/pkg/time/zoneinfo.go +++ b/src/pkg/time/zoneinfo.go @@ -212,7 +212,7 @@ func setupZone() { // $TZ="" means use UTC. // $TZ="foo" means use /usr/share/zoneinfo/foo. - tz, err := os.Getenv("TZ"); + tz, err := os.Getenverror("TZ"); var ok bool; switch { case err == os.ENOENV: |
