borzieri@KING.ICO.OLIVETTI.COM (ivan borzieri) (02/15/91)
Hi, I URGENTLY need this information : I wrote two c modules called by a fortran main. 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 value returned by getenv() is NULL, id est, that variable doesn't exist. Now my question is : is this right ? I know that in C-Shell scripts, when you set variables you loose them as you exit the script. Is it the same or this is a operating system bug ? The system is SCO Unix System V 3.2 Thanks, Ivan Borzieri
cpcahil@virtech.uucp (Conor P. Cahill) (02/15/91)
borzieri@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
pizzi@esacs.UUCP (Riccardo Pizzi) (02/21/91)
In article <50356@olivea.atc.olivetti.com> borzieri@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. Make sure you are not using an automatic variable for putenv(). To be safe, explicitly malloc() the space for the data you want to putenv(). This should work. Rick -- Riccardo Pizzi @ ESA Software, Rimini, ITALY e-mail: pizzi%esacs@relay.EU.net -or- root@xtc.sublink.org Public Access Unix @ +39-541-27858 (Telebit) << Object Oriented is an Opaque Disease >>