Xref: utzoo comp.unix.microport:2856 comp.unix.wizards:14739 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!diamond.bbn.com!mlandau From: mlandau@bbn.com (Matt Landau) Newsgroups: comp.unix.microport,comp.unix.wizards Subject: Re: bug in putenv()! Keywords: bug putenv Message-ID: <12649@jade.BBN.COM> Date: 17 Feb 89 16:22:03 GMT References: <204@tree.UUCP> Reply-To: mlandau@bbn.com (Matt Landau) Organization: BBN Systems and Technologies Corporation, Cambridge, MA Lines: 24 In comp.unix.wizards, asmodeus@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@bbn.com in all this blood and thunder