1754144 Members
4048 Online
108811 Solutions
New Discussion юеВ

Re: getenv

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor
Solution

Re: getenv

>can you give suggestion for how to allows put in environment more than one variable .

As I said, just call strdup(3) then putenv(3). And ignore the fact that you may leak if you are setting the same variable with putenv(3).

You'll leak if you call MSP_ListParamByEntity with the same paramElmArray[i].param_name.

If you want to solve Clay's "Chapter Two", you can create an STL map. Where the key is .param_name and the value is the result of strdup. If you find the name in your map and strlen of previous value is >= new value, you can just overwrite it and not call putenv. If not, strdup and putenv, the free the old space and update your map. (You could store the length in the map too.)
Dennis Handly
Acclaimed Contributor

Re: getenv

Oops, I mistakenly assumed that you were using C++. If not, ignore the mention of STL. You would have to invent your own data structure to keep track of leaks.

Re: getenv

Hi Dennis,

A lot of thanks for your help.
Regards,
Subrat