putenv
int putenv ( const char * envvar ); | stdlib.h |
cplusplus.com |
Create or modify environment variable.
Adds the specified string variable to the environment of the current process.
Because environment accepts only one variable per name, this function
can also be used to modify or delete existing environment variables.
putenv can only modify the environment variables for this process and
any process created from this, not the operating system level. Once this process ends
the environment variables of the parent process will not be changed by this call.
Parameters.
Return Value.
0 if successful.
-1 in case of error.
Portability.
Not defined in ANSI-C. Supported by many compilers.
Example.
/* putenv example */
#include <stdio.h>
#include <stdlib.h>
main ()
{
char * buffer ;
buffer = getenv ("RESOURCES");
if (buffer==NULL)
{
putenv ("RESOURCES=www.cplusplus.com");
puts ("environment variable successfully set");
}
else puts ("environment variable already existed");
return 0;
}
See also.
getenv