From: Earnie Boyd
[mailto:earnie_boyd-/[email protected]]
> Sam Steingold wrote:
>> This is confusing.
>> Are you saying that each process has two sets of environment variables?
>> Actually, MSDN does not document getenv() at all.
>>
>> Could you please elaborate?
>
> [...]
>
To simplify a little:
The OS maintains a process environment, which is maintained by the API
calls
{Get,Set}EnvironmentVariable[AW]. This is the fundamental level of program
environment in Windows.
However, the C runtime (MSVCRT) attempts to support the Unix style
environment
manipulation routines getenv/putenv. If it was this simple, there would be
no
duplication. However, Unix allows access to the environment via the envp
argument to main() and the environ global variable. In order to support
this
usage (in such a way that getenv/putenv see changes to environ/envp as is
required for Unix semantics) the C runtime takes a *copy* at process
startup
of the OS environment, and stores it in environ/envp. It is this copy that
getenv/putenv manipulate.
Hence, yes. There are 2 sets of environment variables.
Things are, I believe, made mildly more confusing by attempts to keep the 2
in sync if possible, but as it's not always possible, this may do more harm
than good. The basic rule is not to mix Windows API access to the
environment
and standard C/Unix compatibility access unless you are very sure you know
what you are doing.
[Disclaimer - this is a simplification, and it's from memory. Don't sue me
if
I got some points wrong :-)]
Hope this helps,
Paul.
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
MinGW-users mailing list
[email protected]
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users