On Jan 31 21:24, 1998, Jamie Kowinsky of 1:129/230 wrote:
G'day Jamie,
JK> Can anyone post some sample code on how to read enviorent vars from
JK> the current enviorment, and if possible how to modify them?
Look up the getenv() putenv() functions..pretty straight forward.
Anyway here is the BC example of it.
BTW while getenv() is, putenv() isn't ANSI/ISO and may or may not be
available in your compiler.
#include
#include
#include
#include
#include
int main(void)
{
char *path, *ptr;
int i = 0;
/* get the current path environment */
ptr = getenv("PATH");
/* set up new path */
path = (char *) malloc(strlen(ptr)+15);
strcpy(path,"PATH=");
strcat(path,ptr);
strcat(path,";c:\\temp");
/* replace the current path and display current environment */
putenv(path);
while (_environ[i])
printf("%s\n",_environ[i++]);
return 0;
}
The changes are only effective until program termination, and other processes
will use the system's normal environment. IOW, if you spawn a child you have
to supply your preferred environment to it as well.
Regards, Frank. Email: fadam@sensation.net.au.
--- Msged 4.20 beta 4
---------------
* Origin: The ticking point, Melbourne, Australia. (3:635/728.21@fidonet)
|