summaryrefslogtreecommitdiff
path: root/src/lib/os/os_env.go
blob: 8559373ac1d7288fad8cf3d5a0aaf9be9ef0acd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 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
}