Re: getenv, putenv
- From: floyd@xxxxxxxxxx (Floyd L. Davidson)
- Date: Wed, 30 Jan 2008 11:25:35 -0900
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.
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@xxxxxxxxxx
.
- Follow-Ups:
- Re: getenv, putenv
- From: Rainer Weikusat
- Re: getenv, putenv
- From: Måns Rullgård
- Re: getenv, putenv
- References:
- getenv, putenv
- From: Bhawna
- Re: getenv, putenv
- From: Floyd L. Davidson
- Re: getenv, putenv
- From: Rainer Weikusat
- getenv, putenv
- Prev by Date: Re: getenv, putenv
- Next by Date: How many App Types R there?
- Previous by thread: Re: getenv, putenv
- Next by thread: Re: getenv, putenv
- Index(es):
Relevant Pages
|