Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Delta Between Two Patch Sets: src/pkg/runtime/env_plan9.go

Issue 160200044: [dev.power64] code review 160200044: build: merge default into dev.power64 (Closed)
Left Patch Set: diff -r be0c14f62257b42485019e9e1db23cf40d2e249f https://code.google.com/p/go Created 10 years, 4 months ago
Right Patch Set: diff -r be0c14f62257b42485019e9e1db23cf40d2e249f https://code.google.com/p/go Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/env_plan9.c ('k') | src/pkg/runtime/env_posix.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 package runtime
6
7 import "unsafe"
8
9 func getenv(s *byte) *byte {
10 val := gogetenv(gostringnocopy(s))
11 if val == "" {
12 return nil
13 }
14 // Strings found in environment are NUL-terminated.
15 return &bytes(val)[0]
16 }
17
18 var tracebackbuf [128]byte
19
20 func gogetenv(key string) string {
21 var file [128]byte
22 if len(key) > len(file)-6 {
23 return ""
24 }
25
26 copy(file[:], "/env/")
27 copy(file[5:], key)
28
29 fd := open(&file[0], _OREAD, 0)
30 if fd < 0 {
31 return ""
32 }
33 n := seek(fd, 0, 2) - 1
34 if n <= 0 {
35 close(fd)
36 return ""
37 }
38
39 p := make([]byte, n)
40
41 r := pread(fd, unsafe.Pointer(&p[0]), int32(n), 0)
42 close(fd)
43 if r < 0 {
44 return ""
45 }
46
47 var s string
48 sp := (*_string)(unsafe.Pointer(&s))
49 sp.str = &p[0]
50 sp.len = int(r)
51 return s
52 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b