basic.%putenv
Assigns value to environment variable.
Syntax
result=%putenv(string)
Description
makes the value of the environment variable name equal to the value designated by 'string', by altering an existing variable or by creating a new one.
'string' String of the form name=value.
'result' Non-zero if the variable is added successfully to the environment, or 0 (zero) if an error occurred.
The environment contains a pointer to 'string', making it a mistake to use a Pick/BASIC variable as 'string' (Pick/BASIC variables are essentially volatile). Proper use requires using '%malloc()' to obtain non-Pick/BASIC space, use '%strcpy()' to copy the Pick/BASIC variable into it, and pass the malloced space to '%putenv', as in the example below.
Example
Add the string 'port=current port.number' to the Unix environment of
the process. After this small program has been executed, the TCL command
'env' now shows the port.number of the process. The TCL command
'environ' does this kind of environment setting.
* Build the string
string='PORT_NUMBER=':system(22)
* get workspace (+1 for terminating NULL)
ptr=(char*)%malloc( 1+len(string) )
* Put the string into the allocated buff
%strcpy( (char*)ptr, string )
* Add it to the environment
%putenv( (char*)ptr )
See Also
User Comments
What do you think?
Share your experience or ask a question by using the form below.
Login to leave your comments.
