🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #7789

Re: Turbo C PUTENV/GETENV

#7789
From: Richard Brittain
Date: Thu, 30 Nov 1989 01:54
26 lines
2156 bytes
In article <569@bmers58.UUCP> mlord@bmers58.UUCP (Mark Lord) writes:
>In article <2572998E.2456@maccs.dcss.mcmaster.ca> cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes:
>>   I'm writing a program under Turbo C 2.0 which has to be able to maniuplate
>>its own environment (I'm not talking about updating the previous shell's
>>copy of the enviornment, just its own) and I'd like to be able to pass
>>this environment along to child processes.  The problems I've discovered are:
>>...
>
>The problem here is that you need room to grow.. so you have to allocate a new
>environment for yourself, and copy the old one to it (for initialization),
>and then get rid of the old one.
>...
 The standard Turbo-C startup code (at least in version 2) copies the entire
environment somewhere (I'm not sure if it the stack or malloced memory), and
putenv() will expand it as needed - the programmer doesn't have to.  When you
shell out to a child program, spawn() and system() seem to do the right thing
and create a genuine environment block for the child process using the modified
environment.  The real problem here (I think) is the re-use of the character
pointers used for putenv() - that is a big no-no in my experience and it isn't
explained in the manuals.  It seems that putenv() makes a copy of it's argument
(i.e. the pointer), not the string it points to.

Richard Brittain,                   School of Elect. Eng.,  Upson Hall   
                                    Cornell University, Ithaca, NY 14853
ARPA: richard@calvin.spp.cornell.edu	
UUCP: {uunet,uw-beaver,rochester,cmcl2}!cornell!calvin!richard
Technical Details
Message-ID: <2509@calvin.EE.CORNELL.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!calvin!richard
References: <2572998E.2456@maccs.dcss.mcmaster.ca> <569@bmers58.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!calvin!richard
From: richard@calvin.EE.CORNELL.EDU (Richard Brittain)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Turbo C PUTENV/GETENV
Message-ID: <2509@calvin.EE.CORNELL.EDU>
Date: 30 Nov 89 01:54:36 GMT
References: <2572998E.2456@maccs.dcss.mcmaster.ca> <569@bmers58.UUCP>
Reply-To: richard@calvin.spp.cornell.edu (Richard Brittain)
Organization: Cornell Space Plasma Physics Group
Lines: 26
Summary: TC copies the environment in the startup code