On Tuesday 06 January 2004 17:11, Craig McLean wrote:
> This is more of a best practices question.
>
> I'm working with environment variables.  In UNIX environment variables are
> made available directly via the
>
> extern char **environ
>
> construct.  Which is an array of pointers to strings, each string
> containing the key value pairs of environment variables inherited from the
> parent process.
>
> What I'm doing is taking those environment variables and modifying some and
> adding a few more.  This means I need to create a new char * array.  Since
> I'm adding some new key value pairs I need to grow the array, the
> documentation I have is pretty explicit about you not been able to realloc
> the existing array of char*s.  So I create a new one that has enough space
> to hold pointers to all of the existing strings of key value pairs, plus
> the number of additional pointers as required.  I then simply assign this
> new array to the environ variable.
>

There are functions available in stdlib.h that allow you to add, remove, and 
modify environment variables.  You shouldn't attempt to mess around with the 
**environ variable.

man getenv
man setenv
man putenv

Those functions will do everything you mentioned.

cheers,

Andy




_______________________________________________
clug-talk mailing list
[EMAIL PROTECTED]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca

Reply via email to