OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "../../cmd/ld/textflag.h" | 7 #include "../../cmd/ld/textflag.h" |
8 | 8 |
9 enum { | 9 enum { |
10 maxround = sizeof(uintptr), | 10 maxround = sizeof(uintptr), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return nil; | 69 return nil; |
70 } | 70 } |
71 | 71 |
72 static int32 argc; | 72 static int32 argc; |
73 static uint8** argv; | 73 static uint8** argv; |
74 | 74 |
75 Slice os·Args; | 75 Slice os·Args; |
76 Slice syscall·envs; | 76 Slice syscall·envs; |
77 | 77 |
78 void (*runtime·sysargs)(int32, uint8**); | 78 void (*runtime·sysargs)(int32, uint8**); |
| 79 uint8** (*_cgo_getenviron)(void); |
79 | 80 |
80 void | 81 void |
81 runtime·args(int32 c, uint8 **v) | 82 runtime·args(int32 c, uint8 **v) |
82 { | 83 { |
83 argc = c; | 84 argc = c; |
84 argv = v; | 85 argv = v; |
85 if(runtime·sysargs != nil) | 86 if(runtime·sysargs != nil) |
86 runtime·sysargs(c, v); | 87 runtime·sysargs(c, v); |
87 } | 88 } |
88 | 89 |
(...skipping 21 matching lines...) Expand all Loading... |
110 os·Args.array = (byte*)s; | 111 os·Args.array = (byte*)s; |
111 os·Args.len = argc; | 112 os·Args.len = argc; |
112 os·Args.cap = argc; | 113 os·Args.cap = argc; |
113 } | 114 } |
114 | 115 |
115 void | 116 void |
116 runtime·goenvs_unix(void) | 117 runtime·goenvs_unix(void) |
117 { | 118 { |
118 String *s; | 119 String *s; |
119 int32 i, n; | 120 int32 i, n; |
| 121 uint8** environ; |
120 | 122 |
121 » for(n=0; argv[argc+1+n] != 0; n++) | 123 » environ = nil; |
| 124 » if(argc > 0) { |
| 125 » » environ = argv + argc + 1; |
| 126 » } else if(_cgo_getenviron != nil) { |
| 127 » » environ = _cgo_getenviron(); |
| 128 » } else |
| 129 » » runtime·throw("argc is 0"); |
| 130 |
| 131 » for(n=0; environ[n] != nil; n++) |
122 ; | 132 ; |
123 | 133 |
124 s = runtime·malloc(n*sizeof s[0]); | 134 s = runtime·malloc(n*sizeof s[0]); |
125 for(i=0; i<n; i++) | 135 for(i=0; i<n; i++) |
126 » » s[i] = runtime·gostringnocopy(argv[argc+1+i]); | 136 » » s[i] = runtime·gostringnocopy(environ[i]); |
127 syscall·envs.array = (byte*)s; | 137 syscall·envs.array = (byte*)s; |
128 syscall·envs.len = n; | 138 syscall·envs.len = n; |
129 syscall·envs.cap = n; | 139 syscall·envs.cap = n; |
130 } | 140 } |
131 | 141 |
132 void | 142 void |
133 runtime·getgoroot(String out) | 143 runtime·getgoroot(String out) |
134 { | 144 { |
135 byte *p; | 145 byte *p; |
136 | 146 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 for(bit = 30; bit >= 0; bit--) { | 443 for(bit = 30; bit >= 0; bit--) { |
434 if(v >= ((int64)div<<bit)) { | 444 if(v >= ((int64)div<<bit)) { |
435 v = v - ((int64)div<<bit); | 445 v = v - ((int64)div<<bit); |
436 res += 1<<bit; | 446 res += 1<<bit; |
437 } | 447 } |
438 } | 448 } |
439 if(rem != nil) | 449 if(rem != nil) |
440 *rem = v; | 450 *rem = v; |
441 return res; | 451 return res; |
442 } | 452 } |
OLD | NEW |