basic.%putenv

C Function/BASIC Program, Releases: AP/Unix

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

Command Name Type Description
basic.cfunction Definition Declare a list of C functions.
basic.%getenv C Function Gets Unix environment variable.
basic.%malloc C Function Allocates memory.
basic.system Function Displays status of system-controlled variables.
tcl.environ Verb: Access Manipulates Unix shell environment variables from TCL.
tcl.env Verb: Access Displays environment variables

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.