%putenv() function

The %putenv() function makes the value of the environment variable name equal to the value designated by str, by altering an existing variable or by creating a new one.


result = %putenv(str)


result Returns nonzero if the variable is added successfully to the environment, or 0 if an error occurred.
str String of the form name=value.


The environment contains a pointer to str, making it a mistake to use a FlashBASIC variable as str (FlashBASIC variables are essentially volatile). Proper use requires using %malloc() to obtain non-FlashBASIC space, using %strcpy() to copy the FlashBASIC variable into it, and passing the space allocated by %malloc() to %putenv, as in the example below.


Add the string port=current port.number to the host environment of the process. After this program has been executed, the TCL env command displays the port number of the process. The TCL environ command performs this kind of environment setting.

* Build the string
* get workspace (+1 for terminating NULL)
* Put the string into the allocated buff
%strcpy((char*)ptr, string)
* Add it to the environment