raz / commit 6dfa68f1

commit
6dfa68f192b02ec778216697c7fd0bb0466582cf
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
b97dee13
Sys.env reads the environment itself, as before setEnv

Every program calls it, from Rt; through environment and named it made
each executable 504 bytes bigger, now 80.

patch · log

1 file changed, +13 -7

lib/Sys.linux-x86_64.raz (history) modified +13 -7

@@ -1175,18 +1175,24 @@
11751175 return (n = LEN(name)) and (s[n] = '=');
11761176 end;
11771177
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. *)
11791182 proc env*(name: []U8): []U8;
1180-var e: ^^U8; s: ^U8; i, m: INT;
1183+var e: ^^U8; s: ^U8; i, n, m: INT;
11811184 begin
1182- e := environment();
1185+ e := envp;
1186+ if e = nil then e := ARGV() + (ARGC() + 1); end;
11831187 i := 0;
11841188 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;
11881194 while s[m] # 0 do INC(m); end;
1189- return s[LEN(name) + 1..m];
1195+ return s[n + 1..m];
11901196 end;
11911197 INC(i);
11921198 end;