OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [syscall/] [env_windows.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2010 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
// Windows environment variables.
6
 
7
package syscall
8
 
9
import (
10
        "unicode/utf16"
11
        "unsafe"
12
)
13
 
14
func Getenv(key string) (value string, found bool) {
15
        b := make([]uint16, 100)
16
        n, e := GetEnvironmentVariable(StringToUTF16Ptr(key), &b[0], uint32(len(b)))
17
        if n == 0 && e == ERROR_ENVVAR_NOT_FOUND {
18
                return "", false
19
        }
20
        if n > uint32(len(b)) {
21
                b = make([]uint16, n)
22
                n, e = GetEnvironmentVariable(StringToUTF16Ptr(key), &b[0], uint32(len(b)))
23
                if n > uint32(len(b)) {
24
                        n = 0
25
                }
26
        }
27
        if n == 0 {
28
                return "", false
29
        }
30
        return string(utf16.Decode(b[0:n])), true
31
}
32
 
33
func Setenv(key, value string) error {
34
        var v *uint16
35
        if len(value) > 0 {
36
                v = StringToUTF16Ptr(value)
37
        }
38
        e := SetEnvironmentVariable(StringToUTF16Ptr(key), v)
39
        if e != nil {
40
                return e
41
        }
42
        return nil
43
}
44
 
45
func Clearenv() {
46
        for _, s := range Environ() {
47
                // Environment variables can begin with =
48
                // so start looking for the separator = at j=1.
49
                // http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx
50
                for j := 1; j < len(s); j++ {
51
                        if s[j] == '=' {
52
                                Setenv(s[0:j], "")
53
                                break
54
                        }
55
                }
56
        }
57
}
58
 
59
func Environ() []string {
60
        s, e := GetEnvironmentStrings()
61
        if e != nil {
62
                return nil
63
        }
64
        defer FreeEnvironmentStrings(s)
65
        r := make([]string, 0, 50) // Empty with room to grow.
66
        for from, i, p := 0, 0, (*[1 << 24]uint16)(unsafe.Pointer(s)); true; i++ {
67
                if p[i] == 0 {
68
                        // empty string marks the end
69
                        if i <= from {
70
                                break
71
                        }
72
                        r = append(r, string(utf16.Decode(p[from:i])))
73
                        from = i + 1
74
                }
75
        }
76
        return r
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.