diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2011-01-12 11:48:15 +1100 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2011-01-12 11:48:15 +1100 |
| commit | a41d85498eed6b606d261e3da84c760538d71b4f (patch) | |
| tree | de37126515b85312a9bd61c1db4601ff291fe8f6 /src/pkg/runtime/runtime.c | |
| parent | 217693e93c23fed2f3224dfaf1eb730d8e5256bb (diff) | |
| download | go-a41d85498eed6b606d261e3da84c760538d71b4f.tar.xz | |
runtime: revert 6974:1f3c3696babb
I missed that environment is used during runtime setup,
well before go init() functions run. Implemented os-dependent
runtime.goenvs functions to allow for different unix, plan9 and
windows versions of environment discovery.
R=rsc, paulzhol
CC=golang-dev
https://golang.org/cl/3787046
Diffstat (limited to 'src/pkg/runtime/runtime.c')
| -rw-r--r-- | src/pkg/runtime/runtime.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index dbdc0f2ac6..9d3efe966d 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -152,34 +152,36 @@ int32 runtime·isplan9; void runtime·goargs(void) { - String *gargv; - String *genvv; - int32 i, envc; + String *s; + int32 i; // for windows implementation see "os" package if(Windows) return; - if(runtime·isplan9) - envc=0; - else - for(envc=0; argv[argc+1+envc] != 0; envc++) - ; - - gargv = runtime·malloc(argc*sizeof gargv[0]); - genvv = runtime·malloc(envc*sizeof genvv[0]); - + s = runtime·malloc(argc*sizeof s[0]); for(i=0; i<argc; i++) - gargv[i] = runtime·gostringnocopy(argv[i]); - os·Args.array = (byte*)gargv; + s[i] = runtime·gostringnocopy(argv[i]); + os·Args.array = (byte*)s; os·Args.len = argc; os·Args.cap = argc; +} + +void +runtime·goenvs_unix(void) +{ + String *s; + int32 i, n; + + for(n=0; argv[argc+1+n] != 0; n++) + ; - for(i=0; i<envc; i++) - genvv[i] = runtime·gostringnocopy(argv[argc+1+i]); - os·Envs.array = (byte*)genvv; - os·Envs.len = envc; - os·Envs.cap = envc; + s = runtime·malloc(n*sizeof s[0]); + for(i=0; i<n; i++) + s[i] = runtime·gostringnocopy(argv[argc+1+i]); + os·Envs.array = (byte*)s; + os·Envs.len = n; + os·Envs.cap = n; } // Atomic add and return new value. |
