diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-05-02 12:38:13 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-05-02 12:38:13 -0700 |
| commit | 623e7de1871c627ab976113dec4bccf5a807eb74 (patch) | |
| tree | a8794d53eed3b6e3136490d912caf8a15776f7dc /src/pkg/runtime | |
| parent | f985638b94bb72c80e5e27c284d37eabe7d09aea (diff) | |
| download | go-623e7de1871c627ab976113dec4bccf5a807eb74.tar.xz | |
os: make Setenv update C environment variables
Fixes #1569
R=rsc, bradfitzwork
CC=golang-dev
https://golang.org/cl/4456045
Diffstat (limited to 'src/pkg/runtime')
| -rw-r--r-- | src/pkg/runtime/cgo/util.c | 11 | ||||
| -rw-r--r-- | src/pkg/runtime/proc.c | 23 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/pkg/runtime/cgo/util.c b/src/pkg/runtime/cgo/util.c index 0eff19aa6d..ba6e0ca9c3 100644 --- a/src/pkg/runtime/cgo/util.c +++ b/src/pkg/runtime/cgo/util.c @@ -4,6 +4,8 @@ #include "libcgo.h" +#include <stdlib.h> + /* Stub for calling malloc from Go */ static void x_cgo_malloc(void *p) @@ -49,3 +51,12 @@ xlibcgo_thread_start(ThreadStart *arg) } void (*libcgo_thread_start)(ThreadStart*) = xlibcgo_thread_start; + +/* Stub for calling setenv */ +static void +xlibcgo_setenv(char **arg) +{ + setenv(arg[0], arg[1], 1); +} + +void (*libcgo_setenv)(char**) = xlibcgo_setenv; diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 52784854fd..61faa15594 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -1343,3 +1343,26 @@ runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz) if(hz != 0) runtime·resetcpuprofiler(hz); } + +void (*libcgo_setenv)(byte**); + +void +os·setenv_c(String k, String v) +{ + byte *arg[2]; + + if(libcgo_setenv == nil) + return; + + arg[0] = runtime·malloc(k.len + 1); + runtime·mcpy(arg[0], k.str, k.len); + arg[0][k.len] = 0; + + arg[1] = runtime·malloc(v.len + 1); + runtime·mcpy(arg[1], v.str, v.len); + arg[1][v.len] = 0; + + runtime·asmcgocall(libcgo_setenv, arg); + runtime·free(arg[0]); + runtime·free(arg[1]); +} |
