| | @@ -1175,18 +1175,24 @@ |
| 1175 | 1175 | return (n = LEN(name)) and (s[n] = '='); |
| 1176 | 1176 | end; |
| 1177 | 1177 | |
| 1178 | | -(* The value of the environment variable name; "" if it isn't set. *) |
| 1178 | +(* The value of the environment variable name; "" if it isn't set. |
| 1179 | + Every program calls it, from Rt, so it reads the environment itself |
| 1180 | + rather than through environment and named, which would add their |
| 1181 | + code to every executable. *) |
| 1179 | 1182 | proc env*(name: []U8): []U8; |
| 1180 | | -var e: ^^U8; s: ^U8; i, m: INT; |
| 1183 | +var e: ^^U8; s: ^U8; i, n, m: INT; |
| 1181 | 1184 | begin |
| 1182 | | - e := environment(); |
| 1185 | + e := envp; |
| 1186 | + if e = nil then e := ARGV() + (ARGC() + 1); end; |
| 1183 | 1187 | i := 0; |
| 1184 | 1188 | while e[i] # nil do |
| 1185 | | - if named(e[i], name) then |
| 1186 | | - s := e[i]; |
| 1187 | | - m := LEN(name) + 1; |
| 1189 | + s := e[i]; |
| 1190 | + n := 0; |
| 1191 | + while (n < LEN(name)) and (s[n] = name[n]) do INC(n); end; |
| 1192 | + if (n = LEN(name)) and (s[n] = '=') then |
| 1193 | + m := n + 1; |
| 1188 | 1194 | while s[m] # 0 do INC(m); end; |
| 1189 | | - return s[LEN(name) + 1..m]; |
| 1195 | + return s[n + 1..m]; |
| 1190 | 1196 | end; |
| 1191 | 1197 | INC(i); |
| 1192 | 1198 | end; |