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

Side by Side Diff: src/runtime/env_posix.go

Issue 148370043: code review 148370043: os, syscall: add Unsetenv (Closed)
Patch Set: diff -r 3042795874453efa7be0a082f3f85118b9d06432 https://go.googlecode.com/hg/ Created 10 years, 5 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:
View unified diff | Download patch
« no previous file with comments | « src/runtime/cgo/setenv.c ('k') | src/runtime/thunk.s » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows 5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
6 6
7 package runtime 7 package runtime
8 8
9 import "unsafe" 9 import "unsafe"
10 10
(...skipping 14 matching lines...) Expand all
25 gothrow("getenv before env init") 25 gothrow("getenv before env init")
26 } 26 }
27 for _, s := range environ() { 27 for _, s := range environ() {
28 if len(s) > len(key) && s[len(key)] == '=' && s[:len(key)] == ke y { 28 if len(s) > len(key) && s[len(key)] == '=' && s[:len(key)] == ke y {
29 return s[len(key)+1:] 29 return s[len(key)+1:]
30 } 30 }
31 } 31 }
32 return "" 32 return ""
33 } 33 }
34 34
35 var _cgo_setenv uintptr // pointer to C function 35 var _cgo_setenv uintptr // pointer to C function
36 var _cgo_unsetenv uintptr // pointer to C function
36 37
37 // Update the C environment if cgo is loaded. 38 // Update the C environment if cgo is loaded.
38 // Called from syscall.Setenv. 39 // Called from syscall.Setenv.
39 func syscall_setenv_c(k string, v string) { 40 func syscall_setenv_c(k string, v string) {
40 if _cgo_setenv == 0 { 41 if _cgo_setenv == 0 {
41 return 42 return
42 } 43 }
43 arg := [2]unsafe.Pointer{cstring(k), cstring(v)} 44 arg := [2]unsafe.Pointer{cstring(k), cstring(v)}
44 asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg)) 45 asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg))
45 } 46 }
46 47
48 // Update the C environment if cgo is loaded.
49 // Called from syscall.unsetenv.
50 func syscall_unsetenv_c(k string) {
51 if _cgo_unsetenv == 0 {
52 return
53 }
54 arg := [1]unsafe.Pointer{cstring(k)}
55 asmcgocall(unsafe.Pointer(_cgo_unsetenv), unsafe.Pointer(&arg))
56 }
57
47 func cstring(s string) unsafe.Pointer { 58 func cstring(s string) unsafe.Pointer {
48 p := make([]byte, len(s)+1) 59 p := make([]byte, len(s)+1)
49 sp := (*_string)(unsafe.Pointer(&s)) 60 sp := (*_string)(unsafe.Pointer(&s))
50 memmove(unsafe.Pointer(&p[0]), unsafe.Pointer(sp.str), uintptr(len(s))) 61 memmove(unsafe.Pointer(&p[0]), unsafe.Pointer(sp.str), uintptr(len(s)))
51 return unsafe.Pointer(&p[0]) 62 return unsafe.Pointer(&p[0])
52 } 63 }
OLDNEW
« no previous file with comments | « src/runtime/cgo/setenv.c ('k') | src/runtime/thunk.s » ('j') | no next file with comments »

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