bug in putenv()!

Matt Landau mlandau at bbn.com
Sat Feb 18 02:22:03 AEST 1989


In comp.unix.wizards, asmodeus at tree.UUCP (Jonathan Ballard) writes:
>For some reason putenv() is not setting the environment variables right
>In this example, putenv will return ok but it never sets $USERNAME.
>>	char envbuf[100];
>>
>>	sprintf(envbuf,"USERNAME=%s","hi");
>>	putenv(envbuf);

Is it possible your version of putenv doesn't actually copy the buffer
passed in, but instead maintains a pointer to the original argument
in the environment?  If that's true, you cannot pass an automatic to
putenv and expect anything reasonable to happen - you have to pass
either global or allocated storage.

The SunOS 3.5 man page on putenv, for example, says this:

  	A potential error is to call putenv with an automatic vari-
        able as the argument, then exit the calling function while
	string is still part of the environment.

Don't know if SysV/AT does the same thing or not, but it's worth a look.
--
 Matt Landau			Waiting for a flash of enlightenment
 mlandau at bbn.com			  in all this blood and thunder



More information about the Comp.unix.wizards mailing list