Putenv() & Getenv() Bug ?

Conor P. Cahill cpcahil at virtech.uucp
Sat Feb 16 01:03:09 AEST 1991


borzieri at KING.ICO.OLIVETTI.COM (Ivan Borzieri) writes:

>in the first  c module I call the system function "putenv()" which should
>set a variable in the environment.
>In the second  c module I call the system function "getenv()" to read 
>the value of the previous set variable.

the problem is *PROBABLY* that you are using a local variable in the
call to putenv.  local data is lost when you return from the function 
and thereafter unavailable.  the putenv(3) man page states that you 
shouldn't do this.

The argument to putenv should point to a static data area or a malloc'd 
data area.

All this is predicated on the fact that both modules (the one calling
putenv and the one calling getenv) are called from the same executable.
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.wizards mailing list