Re: getenv, putenv
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 11:18:04 +0100
floyd@xxxxxxxxxx (Floyd L. Davidson) writes:
Rainer Weikusat <rweikusat@xxxxxxxxxxx> wrote:
floyd@xxxxxxxxxx (Floyd L. Davidson) writes:
Bhawna <bvnbhati@xxxxxxxxx> wrote:
Hi,
I am running a multithreaded application in which I am trying to set
an environment variable using putenv. The string I am using as
argument to putenv was created as
char *str=strdup(<local var>);
1) Don't use an auto variable.
This doesn't matter. The string needs to be alive for as it is still
part of the environment, not some random pointer to it.
In particular, this string becomes part of the
environment; changing it later will change the
environment. (Thus, it is an error is to call
putenv() with an automatic variable as the
argument, then return from the calling function
while string is still part of the environment.)
That, once again, is directly from the man page for
the GNU putenv(3). The string may well be alive, but
that random pointer to it is what is part of the
environment, and it will not be valid.
To maybe add some clarification here: The 'automatic variable' above
refers to an array of characters with automatic storage duration, not
to a pointer to an array of characters.
.
- References:
- getenv, putenv
- From: Bhawna
- Re: getenv, putenv
- From: Floyd L. Davidson
- Re: getenv, putenv
- From: Rainer Weikusat
- Re: getenv, putenv
- From: Floyd L. Davidson
- getenv, putenv
- Prev by Date: How to test packet loss rate ?
- Next by Date: true singleton among shared objects
- Previous by thread: Re: getenv, putenv
- Next by thread: gdb
- Index(es):
Relevant Pages
|
|