Re: getenv, putenv
- From: Måns Rullgård <mans@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 20:42:53 +0000
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.
Sorry, but you're wrong this time. The pointer *value* remains valid
even after the pointer *variable* goes out of scope. Passing the
address of a local variable to a function that stored it for later use
would be wrong, but that's not happening here.
--
Måns Rullgård
mans@xxxxxxxxx
.
- 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 many App Types R there?
- Next by Date: Re: getenv, putenv
- Previous by thread: Re: getenv, putenv
- Next by thread: Re: getenv, putenv
- Index(es):
Relevant Pages
|