Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

putenv parameter and usage

3 views
Skip to first unread message

dhoke

unread,
Oct 11, 2007, 10:29:41 AM10/11/07
to
using bds2006...

reading the downloaded bcb6 help...
"Note that the string given to putenv must be static or global.
Unpredictable results will occur if a local or dynamic string given to
putenv is used after the string memory is released."

wondering, do you have to use a DIFFERENT static/global variable for EACH
environment variable that you may wish to set/modify in the environment, and
leave them untouched for the 'put'ted items to remain valid????


Thomas Maeder [TeamB]

unread,
Oct 11, 2007, 11:40:27 AM10/11/07
to
"dhoke" <dhoke....@east-shore.com> writes:

> "Note that the string given to putenv must be static or
> global. Unpredictable results will occur if a local or dynamic
> string given to putenv is used after the string memory is released."
>
> wondering, do you have to use a DIFFERENT static/global variable for
> EACH environment variable that you may wish to set/modify in the
> environment, and leave them untouched for the 'put'ted items to
> remain valid????

Yes.

The putenv man page on my Linux box contains this paragraph:

The putenv() function adds or changes the value of environment vari-
ables. The argument string is of the form name=value. If name does
not already exist in the environment, then string is added to the
environment. If name does exist, then the value of name in the envi-
ronment is changed to value. The string pointed to by string becomes
part of the environment, so altering the string changes the environ-
ment.

Note the last sentence.

Peter Strömberg

unread,
Oct 12, 2007, 6:58:59 AM10/12/07
to
mae...@glue.ch (Thomas Maeder [TeamB]) wrote in
news:m2sl4hy...@glue.ch:

> The putenv man page on my Linux box contains this paragraph:

Don't trust other implementations too much ;-)
Even if the standard* says the same, it's not necessarily true everywhere,
e.g. all the *BSD's works differently.

* http://www.opengroup.org/onlinepubs/009695399/functions/putenv.html

Thomas Maeder [TeamB]

unread,
Oct 12, 2007, 11:56:37 AM10/12/07
to
"Peter Strömberg" <wilf...@spamcop.net> writes:

>> The putenv man page on my Linux box contains this paragraph:
>
> Don't trust other implementations too much ;-)

True.

On the other hand, putenv() is part of the POSIX Standard, i.e. it can
be used in portable code if the client code doesn't make wrong
assumptions.


> Even if the standard* says the same, it's not necessarily true everywhere,
> e.g. all the *BSD's works differently.
>
> * http://www.opengroup.org/onlinepubs/009695399/functions/putenv.html

Not regarding the OP's question:

"the string pointed to by string shall become part of the environment,
so altering the string shall change the environment"

0 new messages