Re: getenv, putenv
- From: floyd@xxxxxxxxxx (Floyd L. Davidson)
- Date: Wed, 30 Jan 2008 07:30:28 -0900
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.
2) The symbol "str" violates the implemenation's
name space if you have also included <strings.h>.
static char *my_env_var;
void foo(void)
{
char local_var[BUFSIZ];
... /* code that sets localvar to some specific value */
my_env_var = strdup(local_var);
putevn(my_env_var);
}
When I try to invoke same environment variable using another thread
within same process using getenv, I am not able to access the value of
env variable.
Can Anyone please let me know, what could be the probable reason for
this problem.
From the GNU man page:
The libc4 and libc5 and glibc 2.1.2 versions conform
to SUSv2: the pointer string given to putenv() is
used. 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.)
--
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
- References:
- getenv, putenv
- From: Bhawna
- getenv, putenv
- Prev by Date: Re: longjump && re-entrancy
- Next by Date: Re: getenv, putenv
- Previous by thread: Re: getenv, putenv
- Next by thread: Re: getenv, putenv
- Index(es):
Relevant Pages
|