Sets an environmental variable.
Format
#include <stdlib.h>
int putenv (const char *string);
Arguments
- string
- A pointer to a name=value string.
Description
This function sets the value of an environment variable
by altering an existing variable or by creating a new one.
The string argument points to a string of the form
name=value, where name is the environment variable
and value is the new value for it.
The string pointed to by string becomes part of the
environment, so altering the string changes the environment. When
a new string-defining name is passed to putenv, the space used by
string is no longer used.
- Note
- The putenv function manipulates
the environment pointed to by the environ external variable, and
can be used with getenv. However, the third argument to the main
function (the environment pointer), is not changed.
The putenv function uses the malloc function to enlarge the
environment.
A potential error is to call putenv with an automatic variable as
the argument, then exit the calling function while string
is still part of the environment.
Return Values
0 | Indicates success. |
-1 | Indicates an error. errno is set
to ENOMEM-Not enough memory available to expand the environment
list. |
Restriction
This function cannot take a 64-bit address. See Section 1.8.
Previous Page | Next Page | Table of Contents | Index