I would like to add this to the trunk. This would allow an image running on linux to read an envVar that points to a central directory of sources files (see thread [1]).<br>On other platforms the environment dictionary is just empty. <br>
This could be easily changed in the future when the VMs on all platforms might offer a primitive to access the os envVars.<br><br>Alex<br><br>[1] <a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2010-December/155994.html">http://lists.squeakfoundation.org/pipermail/squeak-dev/2010-December/155994.html</a><br>
<br><div class="gmail_quote">2011/2/22 <span dir="ltr"><<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Alexander Lazarevi&#263; uploaded a new version of System to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/System-laza.423.mcz" target="_blank">http://source.squeak.org/inbox/System-laza.423.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: System-laza.423<br>
Author: laza<br>
Time: 22 February 2011, 11:31:19.136 am<br>
UUID: 2c296259-64d4-499d-b4b5-9a4046d737fa<br>
Ancestors: System-ul.422<br>
<br>
Add support for accessing OS environment variables (on linux at first)<br>
<br>
=============== Diff against System-ul.422 ===============<br>
<br>
Item was added:<br>
+ ----- Method: SmalltalkImage>>environ (in category 'os') -----<br>
+ environ<br>
+ "Smalltalk os environ"<br>
+ | env c in match out name |<br>
+ env := IdentityDictionary new.<br>
+ self os osVersion = 'linux' ifFalse: [^env]. "Currently only supported on linux"<br>
+ in := FileStream oldFileOrNoneNamed: '/proc/self/environ'.<br>
+ in ifNil: [^env].<br>
+ out := WriteStream on: String new.<br>
+ match := $=.<br>
+ [(c := in next) isNil] whileFalse: [<br>
+ c = match<br>
+ ifTrue: [<br>
+ c = $= ifTrue: [name := out contents. match := 0 asCharacter].<br>
+ c = 0 asCharacter ifTrue: [env at: name asSymbol put: out contents. match := $=].<br>
+ out reset]<br>
+ ifFalse: [out nextPut: c]].<br>
+ ^env!<br>
<br>
Item was added:<br>
+ ----- Method: SmalltalkImage>>getEnv: (in category 'os') -----<br>
+ getEnv: name<br>
+ "Smalltalk os getEnv: 'HOME'"<br>
+ ^self os environ at: name asSymbol ifAbsent: [nil]<br>
+ !<br>
<br>
<br>
</blockquote></div><br>