Path: utzoo!bnr-vpa!bnr-fos!bmers58!mlord From: mlord@bmers58.UUCP (Mark Lord) Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C PUTENV/GETENV Message-ID: <569@bmers58.UUCP> Date: 29 Nov 89 12:43:37 GMT References: <2572998E.2456@maccs.dcss.mcmaster.ca> Reply-To: mlord@bmers58.UUCP (Mark Lord) Organization: Bell-Northern Research, Ottawa, Canada Lines: 39 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 environment you get passed from DOS is always the smallest multiple of 16 bytes that can hold all of the existing environment variables at the time your program is invoked. Thus, even if the COMMAND.COM environment size was, say, 256 bytes, your program will be allocated with a much smaller environment if there are only a few variables defined. 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. I don't have my DOS references here, but somewhere in the psp is the pointer to your environment, that both DOS and TURBOC use (offset 16?). A pointer to your psp is in _PSP, a predefined turbo-c variable that you can use. The current size is stored in the MCB (memory control block) which immediately preceeds it in memory (again.. no books = no offset for now..). Just retrieve the size, add the amount you need for new stuff, use malloc to get a new block, use a for-loop or something to copy the old env to the new block (based on the old size for how much to copy), change the _PSP+?? pointer to point at the new one, and then deallocate the old one. -- +----------------------------------------+----------------------------+ | Mark S. Lord | Hey, It's only MY opinion. | | ..!utgpu!bnr-vpa!bnr-fos!mlord%bmers58 | Feel free to have your own.| +----------------------------------------+----------------------------+ -- +----------------------------------------+----------------------------+ | Mark S. Lord | Hey, It's only MY opinion. | | ..!utgpu!bnr-vpa!bnr-fos!mlord%bmers58 | Feel free to have your own.| +----------------------------------------+----------------------------+