Sets an environment variable.
Standard C Library (libc.a)
int putenv ( String)
char *String;
The putenv subroutine sets the value of an environment variable by altering an existing variable or by creating a new one. The String parameter points to a string of the form Name=Value, where Name is the environment variable and Value is the new value for it.
The memory space pointed to by the String parameter becomes part of the environment, so that altering the string effectively changes part of the environment. The space is no longer used after the value of the environment variable is changed by calling the putenv subroutine again. Also, after the putenv subroutine is called, environment variables are not necessarily in alphabetical order.
The putenv subroutine manipulates the environ external variable and can be used in conjunction with the getenv subroutine. However, the EnvironmentPointer parameter, the third parameter to the main subroutine, is not changed.
The putenv subroutine uses the malloc subroutine to enlarge the environment.
Item | Description |
---|---|
String | A pointer to the Name=Value string. |
Upon successful completion, a value of 0 is returned. If the malloc subroutine is unable to obtain sufficient space to expand the environment, then the putenv subroutine returns a nonzero value.